Skip to content

Commit 9e7b4f6

Browse files
committed
core/desktopentry: cleanups
1 parent e04b93c commit 9e7b4f6

File tree

3 files changed

+28
-67
lines changed

3 files changed

+28
-67
lines changed

src/core/desktopentry.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,9 @@ ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString&
101101

102102
auto finishCategory = [&data, &groupName, &entries]() {
103103
if (groupName == "Desktop Entry") {
104-
const auto typeIt = entries.constFind("Type");
105-
if (typeIt == entries.cend() || typeIt->second != "Application") return;
104+
if (entries.value("Type").second != "Application") return;
106105

107-
if (const auto hiddenIt = entries.constFind("Hidden");
108-
hiddenIt != entries.cend() && hiddenIt->second == "true")
109-
return;
106+
if (entries.value("Hidden").second == "true") return;
110107

111108
for (const auto& [key, pair]: entries.asKeyValueRange()) {
112109
auto& [_, value] = pair;
@@ -128,7 +125,7 @@ ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString&
128125
}
129126
} else if (groupName.startsWith("Desktop Action ")) {
130127
auto actionName = groupName.sliced(16);
131-
auto action = DesktopActionData();
128+
DesktopActionData action;
132129
action.id = actionName;
133130

134131
for (const auto& [key, pair]: entries.asKeyValueRange()) {
@@ -168,7 +165,7 @@ ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString&
168165
const auto& value = line.sliced(splitIdx + 1);
169166

170167
auto localeIdx = key.indexOf('[');
171-
auto locale = Locale();
168+
Locale locale;
172169
if (localeIdx != -1 && localeIdx != key.length() - 1) {
173170
locale = Locale(key.sliced(localeIdx + 1, key.length() - localeIdx - 2));
174171
key = key.sliced(0, localeIdx);
@@ -215,9 +212,7 @@ void DesktopEntry::updateState(const ParsedDesktopEntryData& newState) {
215212
void DesktopEntry::updateActions(const QHash<QString, DesktopActionData>& newActions) {
216213
auto old = this->mActions;
217214

218-
for (auto it = newActions.cbegin(); it != newActions.cend(); ++it) {
219-
const auto& key = it.key();
220-
const auto& d = it.value();
215+
for (const auto& [key, d]: newActions.asKeyValueRange()) {
221216

222217
DesktopAction* act = nullptr;
223218
if (auto found = old.find(key); found != old.end()) {
@@ -238,7 +233,7 @@ void DesktopEntry::updateActions(const QHash<QString, DesktopActionData>& newAct
238233
act->mEntries = d.entries;
239234
}
240235

241-
for (auto* leftover: std::as_const(old)) {
236+
for (auto* leftover: old) {
242237
leftover->deleteLater();
243238
}
244239
}
@@ -552,7 +547,7 @@ void DesktopEntryManager::onScanCompleted(const QList<ParsedDesktopEntryData>& s
552547

553548
auto newApplications = QVector<DesktopEntry*>();
554549
for (auto* entry: this->desktopEntries.values())
555-
if (!entry->noDisplay()) newApplications.append(entry);
550+
if (!entry->bNoDisplay) newApplications.append(entry);
556551

557552
this->mApplications.diffUpdate(newApplications);
558553

src/core/desktopentry.hpp

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,23 @@ class DesktopEntry: public QObject {
5050
Q_OBJECT;
5151
Q_PROPERTY(QString id MEMBER mId CONSTANT);
5252
/// Name of the specific application, such as "Firefox".
53-
Q_PROPERTY(QString name READ name NOTIFY nameChanged BINDABLE bindableName);
53+
// clang-format off
54+
Q_PROPERTY(QString name READ default WRITE default NOTIFY nameChanged BINDABLE bindableName);
5455
/// Short description of the application, such as "Web Browser". May be empty.
55-
Q_PROPERTY(
56-
QString genericName READ genericName NOTIFY genericNameChanged BINDABLE bindableGenericName
57-
);
56+
Q_PROPERTY(QString genericName READ default WRITE default NOTIFY genericNameChanged BINDABLE bindableGenericName);
5857
/// Initial class or app id the app intends to use. May be useful for matching running apps
5958
/// to desktop entries.
60-
Q_PROPERTY(
61-
QString startupClass READ startupClass NOTIFY startupClassChanged BINDABLE
62-
bindableStartupClass
63-
);
59+
Q_PROPERTY(QString startupClass READ default WRITE default NOTIFY startupClassChanged BINDABLE bindableStartupClass);
6460
/// If true, this application should not be displayed in menus and launchers.
65-
Q_PROPERTY(bool noDisplay READ noDisplay NOTIFY noDisplayChanged BINDABLE bindableNoDisplay);
61+
Q_PROPERTY(bool noDisplay READ default WRITE default NOTIFY noDisplayChanged BINDABLE bindableNoDisplay);
6662
/// Long description of the application, such as "View websites on the internet". May be empty.
67-
Q_PROPERTY(QString comment READ comment NOTIFY commentChanged BINDABLE bindableComment);
63+
Q_PROPERTY(QString comment READ default WRITE default NOTIFY commentChanged BINDABLE bindableComment);
6864
/// Name of the icon associated with this application. May be empty.
69-
Q_PROPERTY(QString icon READ icon NOTIFY iconChanged BINDABLE bindableIcon);
65+
Q_PROPERTY(QString icon READ default WRITE default NOTIFY iconChanged BINDABLE bindableIcon);
7066
/// The raw `Exec` string from the desktop entry.
7167
///
7268
/// > [!WARNING] This cannot be reliably run as a command. See @@command for one you can run.
73-
Q_PROPERTY(
74-
QString execString READ execString NOTIFY execStringChanged BINDABLE bindableExecString
75-
);
69+
Q_PROPERTY(QString execString READ default WRITE default NOTIFY execStringChanged BINDABLE bindableExecString);
7670
/// The parsed `Exec` command in the desktop entry.
7771
///
7872
/// The entry can be run with @@execute(), or by using this command in
@@ -81,24 +75,14 @@ class DesktopEntry: public QObject {
8175
/// the invoked process. See @@execute() for details.
8276
///
8377
/// > [!NOTE] The provided command does not invoke a terminal even if @@runInTerminal is true.
84-
Q_PROPERTY(QVector<QString> command READ command NOTIFY commandChanged BINDABLE bindableCommand);
78+
Q_PROPERTY(QVector<QString> command READ default WRITE default NOTIFY commandChanged BINDABLE bindableCommand);
8579
/// The working directory to execute from.
86-
Q_PROPERTY(
87-
QString workingDirectory READ workingDirectory NOTIFY workingDirectoryChanged BINDABLE
88-
bindableWorkingDirectory
89-
);
80+
Q_PROPERTY(QString workingDirectory READ default WRITE default NOTIFY workingDirectoryChanged BINDABLE bindableWorkingDirectory);
9081
/// If the application should run in a terminal.
91-
Q_PROPERTY(
92-
bool runInTerminal READ runInTerminal NOTIFY runInTerminalChanged BINDABLE
93-
bindableRunInTerminal
94-
);
95-
Q_PROPERTY(
96-
QVector<QString> categories READ categories NOTIFY categoriesChanged BINDABLE
97-
bindableCategories
98-
);
99-
Q_PROPERTY(
100-
QVector<QString> keywords READ keywords NOTIFY keywordsChanged BINDABLE bindableKeywords
101-
);
82+
Q_PROPERTY(bool runInTerminal READ default WRITE default NOTIFY runInTerminalChanged BINDABLE bindableRunInTerminal);
83+
Q_PROPERTY(QVector<QString> categories READ default WRITE default NOTIFY categoriesChanged BINDABLE bindableCategories);
84+
Q_PROPERTY(QVector<QString> keywords READ default WRITE default NOTIFY keywordsChanged BINDABLE bindableKeywords);
85+
// clang-format on
10286
Q_PROPERTY(QVector<DesktopAction*> actions READ actions CONSTANT);
10387
QML_ELEMENT;
10488
QML_UNCREATABLE("DesktopEntry instances must be retrieved from DesktopEntries");
@@ -125,19 +109,6 @@ class DesktopEntry: public QObject {
125109
[[nodiscard]] bool isValid() const;
126110
[[nodiscard]] QVector<DesktopAction*> actions() const;
127111

128-
[[nodiscard]] QString name() const { return this->bName; }
129-
[[nodiscard]] QString genericName() const { return this->bGenericName; }
130-
[[nodiscard]] QString startupClass() const { return this->bStartupClass; }
131-
[[nodiscard]] bool noDisplay() const { return this->bNoDisplay; }
132-
[[nodiscard]] QString comment() const { return this->bComment; }
133-
[[nodiscard]] QString icon() const { return this->bIcon; }
134-
[[nodiscard]] QString execString() const { return this->bExecString; }
135-
[[nodiscard]] QVector<QString> command() const { return this->bCommand; }
136-
[[nodiscard]] QString workingDirectory() const { return this->bWorkingDirectory; }
137-
[[nodiscard]] bool runInTerminal() const { return this->bRunInTerminal; }
138-
[[nodiscard]] QVector<QString> categories() const { return this->bCategories; }
139-
[[nodiscard]] QVector<QString> keywords() const { return this->bKeywords; }
140-
141112
[[nodiscard]] QBindable<QString> bindableName() const { return &this->bName; }
142113
[[nodiscard]] QBindable<QString> bindableGenericName() const { return &this->bGenericName; }
143114
[[nodiscard]] QBindable<QString> bindableStartupClass() const { return &this->bStartupClass; }
@@ -237,14 +208,13 @@ class DesktopEntry: public QObject {
237208
class DesktopAction: public QObject {
238209
Q_OBJECT;
239210
Q_PROPERTY(QString id MEMBER mId CONSTANT);
240-
Q_PROPERTY(QString name READ name NOTIFY nameChanged BINDABLE bindableName);
241-
Q_PROPERTY(QString icon READ icon NOTIFY iconChanged BINDABLE bindableIcon);
211+
// clang-format off
212+
Q_PROPERTY(QString name READ default WRITE default NOTIFY nameChanged BINDABLE bindableName);
213+
Q_PROPERTY(QString icon READ default WRITE default NOTIFY iconChanged BINDABLE bindableIcon);
242214
/// The raw `Exec` string from the action.
243215
///
244216
/// > [!WARNING] This cannot be reliably run as a command. See @@command for one you can run.
245-
Q_PROPERTY(
246-
QString execString READ execString NOTIFY execStringChanged BINDABLE bindableExecString
247-
);
217+
Q_PROPERTY(QString execString READ default WRITE default NOTIFY execStringChanged BINDABLE bindableExecString);
248218
/// The parsed `Exec` command in the action.
249219
///
250220
/// The entry can be run with @@execute(), or by using this command in
@@ -253,7 +223,8 @@ class DesktopAction: public QObject {
253223
/// the invoked process.
254224
///
255225
/// > [!NOTE] The provided command does not invoke a terminal even if @@runInTerminal is true.
256-
Q_PROPERTY(QVector<QString> command READ command NOTIFY commandChanged BINDABLE bindableCommand);
226+
Q_PROPERTY(QVector<QString> command READ default WRITE default NOTIFY commandChanged BINDABLE bindableCommand);
227+
// clang-format on
257228
QML_ELEMENT;
258229
QML_UNCREATABLE("DesktopAction instances must be retrieved from a DesktopEntry");
259230

@@ -269,11 +240,6 @@ class DesktopAction: public QObject {
269240
/// and @@DesktopEntry.workingDirectory.
270241
Q_INVOKABLE void execute() const;
271242

272-
[[nodiscard]] QString name() const { return this->bName; }
273-
[[nodiscard]] QString icon() const { return this->bIcon; }
274-
[[nodiscard]] QString execString() const { return this->bExecString; }
275-
[[nodiscard]] QVector<QString> command() const { return this->bCommand; }
276-
277243
[[nodiscard]] QBindable<QString> bindableName() const { return &this->bName; }
278244
[[nodiscard]] QBindable<QString> bindableIcon() const { return &this->bIcon; }
279245
[[nodiscard]] QBindable<QString> bindableExecString() const { return &this->bExecString; }

src/core/desktopentrymonitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
static void addPathAndParents(QFileSystemWatcher& watcher, const QString& path) {
1111
watcher.addPath(path);
1212

13-
QString p = QFileInfo(path).absolutePath();
13+
auto p = QFileInfo(path).absolutePath();
1414
while (!p.isEmpty()) {
1515
watcher.addPath(p);
1616
const auto parent = QFileInfo(p).dir().absolutePath();

0 commit comments

Comments
 (0)