Skip to content
Merged
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
22 changes: 20 additions & 2 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
#include "iconutils.h"

#include <QDebug>
#include <QStandardPaths>
#include <DConfig>
#include <DPinyin>
#include <DFileWatcherManager>
#include <appinfo.h>
#include <QFileInfo>
#include "appmgr.h"

DCORE_USE_NAMESPACE
Expand Down Expand Up @@ -58,7 +61,7 @@ AppsModel::AppsModel(QObject *parent)
qDebug() << rowCount();

if (AppMgr::instance()->isValid()) {
connect(AppMgr::instance(), &AppMgr::changed, this, &AppsModel::updateModelData);
connect(AppMgr::instance(), &AppMgr::changed, m_tmUpdateCache, qOverload<>(&QTimer::start));
connect(AppMgr::instance(), &AppMgr::itemDataChanged, this, [this](const QString &id) {
const auto appItem = this->appItem(id);
if (!appItem) {
Expand All @@ -68,6 +71,22 @@ AppsModel::AppsModel(QObject *parent)
updateAppItemFromAM(appItem);
});
}

m_tmUpdateCache = new QTimer(this);
m_tmUpdateCache->setInterval(1000);
m_tmUpdateCache->setSingleShot(true);

m_fwIconCache = new DFileWatcherManager(this);
const QStringList paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
const QString suffix("/icons/hicolor/icon-theme.cache");
for (const QString &path : paths) {
if (QFileInfo::exists(path + suffix))
m_fwIconCache->add(path + suffix);
}

connect(m_fwIconCache, &DFileWatcherManager::fileModified, m_tmUpdateCache, qOverload<>(&QTimer::start));
connect(m_fwIconCache, &DFileWatcherManager::fileAttributeChanged, m_tmUpdateCache, qOverload<>(&QTimer::start));
connect(m_tmUpdateCache, &QTimer::timeout, this, &AppsModel::updateModelData);
}

QList<AppItem *> AppsModel::appItems() const
Expand Down Expand Up @@ -178,7 +197,6 @@ QVariant AppsModel::data(const QModelIndex &index, int role) const

void AppsModel::updateModelData()
{
qDebug() << "changed";
// TODO release icon's cache when gtk's icon-theme.cache is updated.
IconUtils::tryUpdateIconCache();
QList<AppItem *> items(allAppInfosShouldBeShown());
Expand Down
4 changes: 4 additions & 0 deletions src/models/appsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

#include <QtQml/qqml.h>
#include <QStandardItemModel>
#include <QTimer>

namespace Dtk::Core {
class DConfig;
class DFileWatcherManager;
}

// List of applications and nothing else.
Expand Down Expand Up @@ -63,4 +65,6 @@ private slots:

Dtk::Core::DConfig * m_dconfig;
QStringList m_excludedAppIdList;
Dtk::Core::DFileWatcherManager *m_fwIconCache = nullptr;
QTimer *m_tmUpdateCache = nullptr;
};