Falkon Develop
Cross-platform Qt-based web browser
desktopfile.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "desktopfile.h"
19
20#include <QSettings>
21#include <QStandardPaths>
22#include <QLocale>
23
25= default;
26
27DesktopFile::DesktopFile(const QString &fileName)
28{
29 m_settings.reset(new QSettings(fileName, QSettings::IniFormat));
30 m_settings->beginGroup(QSL("Desktop Entry"));
31}
32
33QString DesktopFile::fileName() const
34{
35 return m_settings ? m_settings->fileName() : QString();
36}
37
38QString DesktopFile::name() const
39{
40 return value(QSL("Name"), true).toString();
41}
42
43QString DesktopFile::comment() const
44{
45 return value(QSL("Comment"), true).toString();
46}
47
48QString DesktopFile::type() const
49{
50 return value(QSL("Type")).toString();
51}
52
53QString DesktopFile::icon() const
54{
55 return value(QSL("Icon")).toString();
56}
57
58QVariant DesktopFile::value(const QString &key, bool localized) const
59{
60 if (!m_settings) {
61 return {};
62 }
63 if (localized) {
64 const QLocale locale = QLocale::system();
65 QString localeKey = QSL("%1[%2]").arg(key, locale.name());
66 if (m_settings->contains(localeKey)) {
67 return m_settings->value(localeKey);
68 }
69 localeKey = QSL("%1[%2]").arg(key, locale.bcp47Name());
70 if (m_settings->contains(localeKey)) {
71 return m_settings->value(localeKey);
72 }
73 const int i = locale.name().indexOf(QLatin1Char('_'));
74 if (i > 0) {
75 localeKey = QSL("%1[%2]").arg(key, locale.name().left(i));
76 if (m_settings->contains(localeKey)) {
77 return m_settings->value(localeKey);
78 }
79 }
80 }
81 return m_settings->value(key);
82}
83
85{
86 if (!m_settings) {
87 return false;
88 }
89
90 const QString exec = m_settings->value(QSL("TryExec")).toString();
91 return exec.isEmpty() || !QStandardPaths::findExecutable(exec).isEmpty();
92}
QString comment() const
Definition: desktopfile.cpp:43
QString type() const
Definition: desktopfile.cpp:48
bool tryExec() const
Definition: desktopfile.cpp:84
QVariant value(const QString &key, bool localized=false) const
Definition: desktopfile.cpp:58
QString icon() const
Definition: desktopfile.cpp:53
QString name() const
Definition: desktopfile.cpp:38
QString fileName() const
Definition: desktopfile.cpp:33
i
Definition: i18n.py:23
locale
Definition: i18n.py:21
#define QSL(x)
Definition: qzcommon.h:40