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
107 changes: 54 additions & 53 deletions src/ddeintegration/appmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,60 @@ AppMgr::AppMgr(QObject *parent)
{
m_checkTimer->setInterval(3000); // 3 second interval
connect(m_checkTimer, &QTimer::timeout, this, &AppMgr::checkPendingAppItems);
initObjectManager();

connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesAdded, this,
[this](const QDBusObjectPath &objPath, ObjectInterfaceMap interfacesAndProperties) {
const QString key(objPath.path());
qCDebug(logDdeIntegration) << "InterfacesAdded by AM, path:" << key;
if (m_appItems.contains(objPath.path())) {
qWarning() << "App already exists for the path:" << key;
return;
}
m_checkCount = 0;
if (auto appItem = parseDBus2AppItem(interfacesAndProperties)) {
qCDebug(logDdeIntegration) << "App item added, desktopId" << appItem->id;
watchingAppItemAdded(key, appItem);
}
});
connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesRemoved, this,
[this](const QDBusObjectPath &objPath, const QStringList &interfaces) {
Q_UNUSED(interfaces)
const QString key(objPath.path());
qCDebug(logDdeIntegration) << "InterfacesRemoved by AM, path:" << key;
watchingAppItemRemoved(key);
});

DConfig *config = DConfig::create("org.deepin.dde.application-manager", "org.deepin.dde.am", "", this);
if (!config->isValid()) {
qCWarning(logDdeIntegration) << "DConfig is invalid when getting launched times.";
} else {
static const QString AppsLaunchedTimes(u8"appsLaunchedTimes");
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
QObject::connect(config, &DConfig::valueChanged, this, [this, config](const QString &key) {
if (key != AppsLaunchedTimes) {
qCDebug(logDdeIntegration) << "Ignoring non-appsLaunchedTimes key:" << key;
return;
}

qCInfo(logDdeIntegration) << "appsLaunchedTimes of DConfig changed, updating";
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
});
}

if (isValid()) {
fetchAppItems();
}

m_serviceWatcher = new QDBusServiceWatcher(QStringLiteral("org.desktopspec.ApplicationManager1"),
QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForRegistration,
this);
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() {
qCInfo(logDdeIntegration) << "AppManager1 service registered on bus, fetching app items";
fetchAppItems();
});
}

AppMgr::~AppMgr()
Expand Down Expand Up @@ -430,58 +483,6 @@ void AppMgr::updateAppsLaunchedTimes(const QVariantMap &appsLaunchedTimes)
}
}

void AppMgr::initObjectManager()
{
if (!isValid()) {
qCWarning(logDdeIntegration) << "Object manager is not valid, aborting initialization";
return;
}

connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesAdded, this,
[this](const QDBusObjectPath &objPath, ObjectInterfaceMap interfacesAndProperties) {
const QString key(objPath.path());
qCDebug(logDdeIntegration) << "InterfacesAdded by AM, path:" << key;
if (m_appItems.contains(objPath.path())) {
qWarning() << "App already exists for the path:" << key;
return;
}
// Reset check count when new app is added
m_checkCount = 0;
if (auto appItem = parseDBus2AppItem(interfacesAndProperties)) {
qCDebug(logDdeIntegration) << "App item added, desktopId" << appItem->id;
watchingAppItemAdded(key, appItem);
}
});
connect(m_objectManager, &AppManager1ApplicationObjectManager::InterfacesRemoved, this,
[this](const QDBusObjectPath &objPath, const QStringList &interfaces) {
Q_UNUSED(interfaces)
const QString key(objPath.path());
qCDebug(logDdeIntegration) << "InterfacesRemoved by AM, path:" << key;
watchingAppItemRemoved(key);
});

fetchAppItems();

DConfig *config = DConfig::create("org.deepin.dde.application-manager", "org.deepin.dde.am", "", this);
if (!config->isValid()) {
qCWarning(logDdeIntegration) << "DConfig is invalid when getting launched times.";
} else {
static const QString AppsLaunchedTimes(u8"appsLaunchedTimes");
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
QObject::connect(config, &DConfig::valueChanged, this, [this, config](const QString &key) {
if (key != AppsLaunchedTimes) {
qCDebug(logDdeIntegration) << "Ignoring non-appsLaunchedTimes key:" << key;
return;
}

qCInfo(logDdeIntegration) << "appsLaunchedTimes of DConfig changed, updating";
const auto &value = config->value(AppsLaunchedTimes).toMap();
updateAppsLaunchedTimes(value);
});
}
}

void AppMgr::fetchAppItems()
{
qCDebug(logDdeIntegration) << "Begin to fetch apps.";
Expand Down
3 changes: 2 additions & 1 deletion src/ddeintegration/appmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

#include <QMap>
#include <QObject>
#include <QPointer>

Check warning on line 9 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 10 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 11 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 13 in src/ddeintegration/appmgr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dtkcore_global.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DCORE_BEGIN_NAMESPACE
class DConfig;
Expand Down Expand Up @@ -62,7 +63,6 @@
void checkPendingAppItems();

private:
void initObjectManager();
void fetchAppItems();
void watchingAppItemAdded(const QString &key, AppMgr::AppItem *appItem);
void watchingAppItemRemoved(const QString &key);
Expand All @@ -72,6 +72,7 @@

private:
__AppManager1ApplicationObjectManager *m_objectManager;
QDBusServiceWatcher *m_serviceWatcher = nullptr;
QMap<QString, AppMgr::AppItem *> m_appItems;
QMap<QString, AppMgr::AppItem *> m_pendingAppItems;
QTimer *m_checkTimer;
Expand Down
20 changes: 9 additions & 11 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ AppsModel::AppsModel(QObject *parent)
m_tmUpdateCache->setInterval(1000);
m_tmUpdateCache->setSingleShot(true);

if (AppMgr::instance()->isValid()) {
connect(AppMgr::instance(), &AppMgr::changed, m_tmUpdateCache, qOverload<>(&QTimer::start));
connect(AppMgr::instance(), &AppMgr::itemDataChanged, this, [this](const QString &id) {
const auto appItem = this->itemFromDesktopId(id);
if (!appItem) {
qWarning() << "Not existing item in AppsModel for the desktopId" << id;
return;
}
updateAppItemFromAM(appItem);
});
}
connect(AppMgr::instance(), &AppMgr::changed, m_tmUpdateCache, qOverload<>(&QTimer::start));
connect(AppMgr::instance(), &AppMgr::itemDataChanged, this, [this](const QString &id) {
const auto appItem = this->itemFromDesktopId(id);
if (!appItem) {
qWarning() << "Not existing item in AppsModel for the desktopId" << id;
return;
}
updateAppItemFromAM(appItem);
});

m_fwIconCache = new DFileWatcherManager(this);
const QStringList paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
Expand Down
Loading