Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "appsmodel.h"

#include "../ddeintegration/appmgr.h"
#include "iconutils.h"

Check warning on line 8 in src/models/appsmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "iconutils.h" not found.
#include "trashmonitor.h"

Check warning on line 9 in src/models/appsmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "trashmonitor.h" not found.

#include <DConfig>

Check warning on line 11 in src/models/appsmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DFileWatcherManager>

Check warning on line 12 in src/models/appsmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DFileWatcherManager> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DPinyin>
#include <QFileInfo>
#include <QLoggingCategory>
Expand Down Expand Up @@ -57,6 +58,8 @@
connect(m_iconCacheWatcher, &DFileWatcherManager::fileModified, m_iconUpdateTimer, qOverload<>(&QTimer::start));
connect(m_iconCacheWatcher, &DFileWatcherManager::fileAttributeChanged, m_iconUpdateTimer, qOverload<>(&QTimer::start));
connect(m_iconUpdateTimer, &QTimer::timeout, this, &AppsModel::updateIconData);
m_trashMonitor = new TrashMonitor(this);
connect(m_trashMonitor, &TrashMonitor::trashAttributeChanged, this, &AppsModel::onTrashAttributeChanged);
connect(AppMgr::instance(), &AppMgr::pendingAppItemReady, this, [this](const QString &desktopId) {
if (!m_sourceModel)
return;
Expand Down Expand Up @@ -175,6 +178,12 @@
case AppsModel::DDECategoryRole:
return sourceData(sourceIndex, DDECategoryRoleName);
case AppsModel::IconNameRole: {
const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
if (desktopId == QStringLiteral("dde-trash.desktop") && m_trashMonitor) {
return m_trashMonitor->trashItemCount() > 0
? QStringLiteral("user-trash-full")
: QStringLiteral("user-trash");
}
const QString iconName = sourceData(sourceIndex, IconNameRoleName).toString();
if (iconName.isEmpty())
return QStringLiteral("application-x-desktop");
Expand Down Expand Up @@ -426,3 +435,10 @@
if (rowCount() > 0)
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), { AppsModel::IconNameRole });
}

void AppsModel::onTrashAttributeChanged()
{
const QModelIndex trashIndex = indexFromDesktopId(QStringLiteral("dde-trash"));
if (trashIndex.isValid())
Q_EMIT dataChanged(trashIndex, trashIndex, { AppsModel::IconNameRole });
}
3 changes: 3 additions & 0 deletions src/models/appsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DFileWatcherManager;
}

class QTimer;
class TrashMonitor;

// Adapts dde-shell's application model to the roles and desktop IDs expected by launchpad.
class AppsModel : public QAbstractListModel
Expand Down Expand Up @@ -91,10 +92,12 @@ public Q_SLOTS:
bool acceptsSourceIndex(const QModelIndex &sourceIndex) const;
bool shouldDelaySourceIndex(const QModelIndex &sourceIndex) const;
void updateIconData();
void onTrashAttributeChanged();

QStringList m_excludedAppIdList;
Dtk::Core::DFileWatcherManager *m_iconCacheWatcher = nullptr;
QTimer *m_iconUpdateTimer = nullptr;
TrashMonitor *m_trashMonitor = nullptr;
QPointer<QAbstractItemModel> m_sourceModel;
QList<QPersistentModelIndex> m_rows;
QList<QMetaObject::Connection> m_sourceConnections;
Expand Down
Loading