forked from quickshell/quickshell
		
	core/desktopentry: paper over id casing issues
This commit is contained in:
		
							parent
							
								
									fdbb490537
								
							
						
					
					
						commit
						db23c0264a
					
				
					 2 changed files with 30 additions and 5 deletions
				
			
		| 
						 | 
					@ -319,6 +319,7 @@ void DesktopEntryManager::scanPath(const QDir& dir, const QString& prefix) {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			auto id = prefix + entry.fileName().sliced(0, entry.fileName().length() - 8);
 | 
								auto id = prefix + entry.fileName().sliced(0, entry.fileName().length() - 8);
 | 
				
			||||||
 | 
								auto lowerId = id.toLower();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			auto text = QString::fromUtf8(file->readAll());
 | 
								auto text = QString::fromUtf8(file->readAll());
 | 
				
			||||||
			auto* dentry = new DesktopEntry(id, this);
 | 
								auto* dentry = new DesktopEntry(id, this);
 | 
				
			||||||
| 
						 | 
					@ -332,13 +333,28 @@ void DesktopEntryManager::scanPath(const QDir& dir, const QString& prefix) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			qCDebug(logDesktopEntry) << "Found desktop entry" << id << "at" << path;
 | 
								qCDebug(logDesktopEntry) << "Found desktop entry" << id << "at" << path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (this->desktopEntries.contains(id)) {
 | 
								auto conflictingId = this->desktopEntries.contains(id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (conflictingId) {
 | 
				
			||||||
				qCDebug(logDesktopEntry) << "Replacing old entry for" << id;
 | 
									qCDebug(logDesktopEntry) << "Replacing old entry for" << id;
 | 
				
			||||||
				delete this->desktopEntries.value(id);
 | 
									delete this->desktopEntries.value(id);
 | 
				
			||||||
				this->desktopEntries.remove(id);
 | 
									this->desktopEntries.remove(id);
 | 
				
			||||||
 | 
									this->lowercaseDesktopEntries.remove(lowerId);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			this->desktopEntries.insert(id, dentry);
 | 
								this->desktopEntries.insert(id, dentry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (this->lowercaseDesktopEntries.contains(lowerId)) {
 | 
				
			||||||
 | 
									qCInfo(logDesktopEntry).nospace()
 | 
				
			||||||
 | 
											<< "Multiple desktop entries have the same lowercased id " << lowerId
 | 
				
			||||||
 | 
											<< ". This can cause ambiguity when byId requests are not made with the correct case "
 | 
				
			||||||
 | 
												 "already.";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									this->lowercaseDesktopEntries.remove(lowerId);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								this->lowercaseDesktopEntries.insert(lowerId, dentry);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -349,7 +365,13 @@ DesktopEntryManager* DesktopEntryManager::instance() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DesktopEntry* DesktopEntryManager::byId(const QString& id) {
 | 
					DesktopEntry* DesktopEntryManager::byId(const QString& id) {
 | 
				
			||||||
	return this->desktopEntries.value(id);
 | 
						if (auto* entry = this->desktopEntries.value(id)) {
 | 
				
			||||||
 | 
							return entry;
 | 
				
			||||||
 | 
						} else if (auto* entry = this->lowercaseDesktopEntries.value(id.toLower())) {
 | 
				
			||||||
 | 
							return entry;
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return nullptr;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ObjectModel<DesktopEntry>* DesktopEntryManager::applications() { return &this->mApplications; }
 | 
					ObjectModel<DesktopEntry>* DesktopEntryManager::applications() { return &this->mApplications; }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,10 +55,8 @@ public:
 | 
				
			||||||
	static QVector<QString> parseExecString(const QString& execString);
 | 
						static QVector<QString> parseExecString(const QString& execString);
 | 
				
			||||||
	static void doExec(const QString& execString, const QString& workingDirectory);
 | 
						static void doExec(const QString& execString, const QString& workingDirectory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					 | 
				
			||||||
	QHash<QString, QString> mEntries;
 | 
					 | 
				
			||||||
	QHash<QString, DesktopAction*> mActions;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
	QString mId;
 | 
						QString mId;
 | 
				
			||||||
	QString mName;
 | 
						QString mName;
 | 
				
			||||||
	QString mGenericName;
 | 
						QString mGenericName;
 | 
				
			||||||
| 
						 | 
					@ -71,6 +69,10 @@ private:
 | 
				
			||||||
	QVector<QString> mCategories;
 | 
						QVector<QString> mCategories;
 | 
				
			||||||
	QVector<QString> mKeywords;
 | 
						QVector<QString> mKeywords;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						QHash<QString, QString> mEntries;
 | 
				
			||||||
 | 
						QHash<QString, DesktopAction*> mActions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	friend class DesktopAction;
 | 
						friend class DesktopAction;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -124,6 +126,7 @@ private:
 | 
				
			||||||
	void scanPath(const QDir& dir, const QString& prefix = QString());
 | 
						void scanPath(const QDir& dir, const QString& prefix = QString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QHash<QString, DesktopEntry*> desktopEntries;
 | 
						QHash<QString, DesktopEntry*> desktopEntries;
 | 
				
			||||||
 | 
						QHash<QString, DesktopEntry*> lowercaseDesktopEntries;
 | 
				
			||||||
	ObjectModel<DesktopEntry> mApplications {this};
 | 
						ObjectModel<DesktopEntry> mApplications {this};
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue