2 * Copyright 2014 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Michael Zanetti <michael.zanetti@canonical.com>
20#include "desktopfilehandler.h"
23#include <QStandardPaths>
30QString DesktopFileHandler::findDesktopFile(const QString &appId)
33 QString helper = appId;
35 QStringList searchDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
36#ifdef LAUNCHER_TESTING
43 helper.replace(dashPos, 1, '/');
46 if (helper.contains("/")) {
47 path += helper.split('/').first() + '/';
48 helper.remove(QRegExp("^" + path));
51 Q_FOREACH(const QString &searchDirName, searchDirs) {
52 QDir searchDir(searchDirName + "/" + path);
53 Q_FOREACH(const QString &desktopFile, searchDir.entryList(QStringList() << "*.desktop")) {
54 if (desktopFile.startsWith(helper)) {
55 QFileInfo fileInfo(searchDir, desktopFile);
56 return fileInfo.absoluteFilePath();
61 dashPos = helper.indexOf("-");
62 } while (dashPos != -1);
67QString DesktopFileHandler::displayName(const QString &appId)
69 QString desktopFile = findDesktopFile(appId);
70 if (desktopFile.isEmpty()) {
74 QSettings settings(desktopFile, QSettings::IniFormat);
75 settings.beginGroup("Desktop Entry");
77 // First try to find Name[xx_YY] and Name[xx] in .desktop file
78 QString locale = QLocale::system().name();
79 QString shortLocale = locale.split('_').first();
81 if (locale != shortLocale && settings.contains(QString("Name[%1]").arg(locale))) {
82 return settings.value(QString("Name[%1]").arg(locale)).toString();
85 if (settings.contains(QString("Name[%1]").arg(shortLocale))) {
86 return settings.value(QString("Name[%1]").arg(shortLocale)).toString();
89 // No translation found in desktop file. Get the untranslated one and have a go with gettext.
90 QString displayName = settings.value("Name").toString();
92 if (settings.contains("X-Ubuntu-Gettext-Domain")) {
93 const QString domain = settings.value("X-Ubuntu-Gettext-Domain").toString();
94 return dgettext(domain.toUtf8().constData(), displayName.toUtf8().constData());
100QString DesktopFileHandler::icon(const QString &appId)
102 QString desktopFile = findDesktopFile(appId);
103 if (desktopFile.isEmpty()) {
107 QSettings settings(desktopFile, QSettings::IniFormat);
108 settings.beginGroup("Desktop Entry");
109 QString iconString = settings.value("Icon").toString();
110 QString pathString = settings.value("Path").toString();
112 if (QFileInfo(iconString).exists()) {
113 return QFileInfo(iconString).absoluteFilePath();
114 } else if (QFileInfo(pathString + '/' + iconString).exists()) {
115 return pathString + '/' + iconString;
117 return "image://theme/" + iconString;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list