Skip to content

Commit

Permalink
fix: little black square icon show again
Browse files Browse the repository at this point in the history
- reset model to fix black square icon
- if icon is fullpath convert to url

Issue: linuxdeepin/developer-center#8577
  • Loading branch information
kegechen committed Jun 17, 2024
1 parent 144eac7 commit fb76b05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/models/appitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "appitem.h"

#include <QFileInfo>

AppItem::AppItem(const QString &freedesktopId)
: QStandardItem()
{
Expand Down Expand Up @@ -47,7 +49,12 @@ const QString AppItem::iconName() const

void AppItem::setIconName(const QString &iconName)
{
setData(iconName.isEmpty() ? "application-x-desktop" : iconName, AppItem::IconNameRole);
QString name = iconName;
if (QFileInfo(iconName).isAbsolute()) {
name = QUrl::fromLocalFile(iconName).toString(); // path ==> file://path
}

setData(iconName.isEmpty() ? "application-x-desktop" : name, AppItem::IconNameRole);
}

const QStringList AppItem::categories() const
Expand Down
7 changes: 5 additions & 2 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,17 @@ QVariant AppsModel::data(const QModelIndex &index, int role) const

void AppsModel::updateModelData()
{
// TODO release icon's cache when gtk's icon-theme.cache is updated.
IconUtils::tryUpdateIconCache();
beginResetModel();
qDebug() << "reset model.";

QList<AppItem *> items(allAppInfosShouldBeShown());
cleanUpInvalidApps(items);
QList<AppItem *> duplicatedItems = updateItems(items);
for (AppItem * item : std::as_const(duplicatedItems)) {
delete item;
}

endResetModel();
}

// the caller manage the return values' ownership (i.e. might need to free them)
Expand Down

0 comments on commit fb76b05

Please sign in to comment.