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>
30DesktopFileHandler::DesktopFileHandler(const QString &appId, QObject *parent):
37QString DesktopFileHandler::appId() const
42void DesktopFileHandler::setAppId(const QString &appId)
44 if (m_appId != appId) {
50QString DesktopFileHandler::filename() const
55bool DesktopFileHandler::isValid() const
57 return !m_filename.isEmpty();
60void DesktopFileHandler::load()
64 if (m_appId.isEmpty()) {
69 QString helper = m_appId;
71 QStringList searchDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
72#ifdef LAUNCHER_TESTING
73 searchDirs << QStringLiteral(".");
79 helper.replace(dashPos, 1, '/');
82 if (helper.contains('/')) {
83 path += helper.split('/').at(0) + '/';
84 helper.remove(QRegExp("^" + path));
87 Q_FOREACH(const QString &searchDirName, searchDirs) {
88 QDir searchDir(searchDirName + "/" + path);
89 const QString desktop = QStringLiteral("*.desktop");
90 Q_FOREACH(const QString &desktopFile, searchDir.entryList(QStringList() << desktop)) {
91 if (desktopFile.startsWith(helper)) {
92 QFileInfo fileInfo(searchDir, desktopFile);
93 m_filename = fileInfo.absoluteFilePath();
99 dashPos = helper.indexOf('-');
100 } while (dashPos != -1);
103QString DesktopFileHandler::displayName() const
109 QSettings settings(m_filename, QSettings::IniFormat);
110 settings.setIniCodec("UTF-8");
111 settings.beginGroup(QStringLiteral("Desktop Entry"));
113 // First try to find Name[xx_YY] and Name[xx] in .desktop file
114 QString locale = QLocale().name();
115 QString shortLocale = locale.split('_').first();
117 if (locale != shortLocale && settings.contains(QStringLiteral("Name[%1]").arg(locale))) {
118 return settings.value(QStringLiteral("Name[%1]").arg(locale)).toString();
121 if (settings.contains(QStringLiteral("Name[%1]").arg(shortLocale))) {
122 return settings.value(QStringLiteral("Name[%1]").arg(shortLocale)).toString();
125 // No translation found in desktop file. Get the untranslated one and have a go with gettext.
126 QString displayName = settings.value(QStringLiteral("Name")).toString();
128 if (settings.contains(QStringLiteral("X-Ubuntu-Gettext-Domain"))) {
129 const QString domain = settings.value(QStringLiteral("X-Ubuntu-Gettext-Domain")).toString();
130 return dgettext(domain.toUtf8().constData(), displayName.toUtf8().constData());
136QString DesktopFileHandler::icon() const
142 QSettings settings(m_filename, QSettings::IniFormat);
143 settings.setIniCodec("UTF-8");
144 settings.beginGroup(QStringLiteral("Desktop Entry"));
145 QString iconString = settings.value(QStringLiteral("Icon")).toString();
146 QString pathString = settings.value(QStringLiteral("Path")).toString();
148 if (QFileInfo(iconString).exists()) {
149 return QFileInfo(iconString).absoluteFilePath();
150 } else if (QFileInfo(pathString + '/' + iconString).exists()) {
151 return pathString + '/' + iconString;
153 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