feat: add property "LastLaunchedTime"

1. reactor some utils implementation.
2. remove constexpr before `decltype(auto)` due to GCC bug.
refer: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe
2023-08-23 17:20:47 +08:00
committed by Comix
parent 2bdb9e99ee
commit 9f2a8b6798
8 changed files with 108 additions and 18 deletions

View File

@ -52,12 +52,19 @@ QSharedPointer<ApplicationService> ApplicationService::createApplicationService(
objectPath = QString{DDEApplicationManager1ObjectPath} + "/" + QUuid::createUuid().toString(QUuid::Id128);
}
DesktopFileGuard guard{app->desktopFileSource()};
if (!guard.try_open()) {
return nullptr;
}
sourceStream.setDevice(app->desktopFileSource().sourceFile());
std::unique_ptr<DesktopEntry> entry{std::make_unique<DesktopEntry>()};
auto error = entry->parse(sourceStream);
if (error != DesktopErrorCode::NoError) {
if (error != DesktopErrorCode::EntryKeyInvalid) {
qWarning() << "parse failed:" << error;
return nullptr;
}
}
@ -65,6 +72,7 @@ QSharedPointer<ApplicationService> ApplicationService::createApplicationService(
if (auto val = entry->value(DesktopFileEntryKey, "Hidden"); val.has_value()) {
bool ok{false};
if (auto hidden = val.value().toBoolean(ok); ok and hidden) {
qWarning() << "invalid hidden value:" << *val.value().find(defaultKeyStr);
return nullptr;
}
}
@ -333,6 +341,11 @@ QString ApplicationService::id() const noexcept
return m_desktopSource.desktopId();
}
qulonglong ApplicationService::lastLaunchedTime() const noexcept
{
return m_lastLaunch;
}
IconMap ApplicationService::icons() const
{
if (m_Icons) {

View File

@ -13,6 +13,7 @@
#include <QSharedPointer>
#include <QUuid>
#include <QTextStream>
#include <QDBusContext>
#include <QFile>
#include <memory>
#include <utility>
@ -22,7 +23,7 @@
#include "desktopicons.h"
#include "dbus/jobmanager1service.h"
class ApplicationService : public QObject
class ApplicationService : public QObject, public QDBusContext
{
Q_OBJECT
public:
@ -38,6 +39,9 @@ public:
Q_PROPERTY(QString ID READ id CONSTANT)
[[nodiscard]] QString id() const noexcept;
Q_PROPERTY(qulonglong LastLaunchedTime READ lastLaunchedTime)
[[nodiscard]] qulonglong lastLaunchedTime() const noexcept;
Q_PROPERTY(IconMap Icons READ icons)
[[nodiscard]] IconMap icons() const;
IconMap &iconsRef();
@ -83,6 +87,7 @@ private:
static QSharedPointer<ApplicationService> createApplicationService(DesktopFile source,
ApplicationManager1Service *parent) noexcept;
bool m_AutoStart{false};
qlonglong m_lastLaunch{0};
QDBusObjectPath m_applicationPath;
QString m_launcher{getApplicationLauncherBinary()};
DesktopFile m_desktopSource;