aboutsummaryrefslogtreecommitdiff
path: root/src/core/kdesktopfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/kdesktopfile.cpp')
-rw-r--r--src/core/kdesktopfile.cpp261
1 files changed, 136 insertions, 125 deletions
diff --git a/src/core/kdesktopfile.cpp b/src/core/kdesktopfile.cpp
index 0ebbb4b0..9fa3654d 100644
--- a/src/core/kdesktopfile.cpp
+++ b/src/core/kdesktopfile.cpp
@@ -40,7 +40,7 @@
class KDesktopFilePrivate : public KConfigPrivate
{
- public:
+public:
KDesktopFilePrivate(QStandardPaths::StandardLocation resourceType, const QString &fileName);
KConfigGroup desktopGroup;
};
@@ -83,129 +83,137 @@ QString KDesktopFile::locateLocal(const QString &path)
{
QString relativePath;
// Relative to config? (e.g. for autostart)
- Q_FOREACH(const QString& dir, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
+ Q_FOREACH (const QString &dir, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
if (path.startsWith(dir) + '/') {
relativePath = dir.mid(path.length() + 1);
return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + relativePath;
}
}
// Relative to xdg data dir? (much more common)
- Q_FOREACH(const QString& dir, QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) {
- if (path.startsWith(dir) + '/')
+ Q_FOREACH (const QString &dir, QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) {
+ if (path.startsWith(dir) + '/') {
relativePath = dir.mid(path.length() + 1);
+ }
}
if (relativePath.isEmpty()) {
// What now? The desktop file doesn't come from XDG_DATA_DIRS. Use filename only and hope for the best.
- relativePath = path.mid(path.lastIndexOf(QLatin1Char('/'))+1);
+ relativePath = path.mid(path.lastIndexOf(QLatin1Char('/')) + 1);
}
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + relativePath;
}
-bool KDesktopFile::isDesktopFile(const QString& path)
+bool KDesktopFile::isDesktopFile(const QString &path)
{
- return (path.length() > 8
- && path.endsWith(QLatin1String(".desktop")));
+ return (path.length() > 8
+ && path.endsWith(QLatin1String(".desktop")));
}
-bool KDesktopFile::isAuthorizedDesktopFile(const QString& path)
+bool KDesktopFile::isAuthorizedDesktopFile(const QString &path)
{
- if (path.isEmpty())
- return false; // Empty paths are not ok.
+ if (path.isEmpty()) {
+ return false; // Empty paths are not ok.
+ }
- if (QDir::isRelativePath(path))
- return true; // Relative paths are ok.
+ if (QDir::isRelativePath(path)) {
+ return true; // Relative paths are ok.
+ }
- const QString realPath = QFileInfo(path).canonicalFilePath();
- if (realPath.isEmpty())
- return false; // File doesn't exist.
+ const QString realPath = QFileInfo(path).canonicalFilePath();
+ if (realPath.isEmpty()) {
+ return false; // File doesn't exist.
+ }
#ifndef Q_OS_WIN
- const Qt::CaseSensitivity sensitivity = Qt::CaseSensitive;
+ const Qt::CaseSensitivity sensitivity = Qt::CaseSensitive;
#else
- const Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive;
+ const Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive;
#endif
- // Check if the .desktop file is installed as part of KDE or XDG.
- const QStringList appsDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
- Q_FOREACH (const QString &prefix, appsDirs) {
- if (QDir(prefix).exists() && realPath.startsWith(QFileInfo(prefix).canonicalFilePath(), sensitivity))
- return true;
- }
- const QString servicesDir = QLatin1String("kde5/services/"); // KGlobal::dirs()->xdgDataRelativePath("services")
- Q_FOREACH (const QString &xdgDataPrefix, QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) {
- if (QDir(xdgDataPrefix).exists()) {
- const QString prefix = QFileInfo(xdgDataPrefix).canonicalFilePath();
- if (realPath.startsWith(prefix + QLatin1Char('/') + servicesDir, sensitivity))
- return true;
- }
- }
- const QString autostartDir = QLatin1String("autostart/");
- Q_FOREACH (const QString &xdgDataPrefix, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
- if (QDir(xdgDataPrefix).exists()) {
- const QString prefix = QFileInfo(xdgDataPrefix).canonicalFilePath();
- if (realPath.startsWith(prefix + QLatin1Char('/') + autostartDir, sensitivity))
- return true;
- }
- }
-
- // Forbid desktop files outside of standard locations if kiosk is set so
- if (!KAuthorized::authorize(QLatin1String("run_desktop_files"))) {
- qWarning() << "Access to '" << path << "' denied because of 'run_desktop_files' restriction." << endl;
- return false;
- }
-
- // Not otherwise permitted, so only allow if the file is executable, or if
- // owned by root (uid == 0)
- QFileInfo entryInfo( path );
- if (entryInfo.isExecutable() || entryInfo.ownerId() == 0)
- return true;
-
- qWarning() << "Access to '" << path << "' denied, not owned by root, executable flag not set." << endl;
- return false;
+ // Check if the .desktop file is installed as part of KDE or XDG.
+ const QStringList appsDirs = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
+ Q_FOREACH (const QString &prefix, appsDirs) {
+ if (QDir(prefix).exists() && realPath.startsWith(QFileInfo(prefix).canonicalFilePath(), sensitivity)) {
+ return true;
+ }
+ }
+ const QString servicesDir = QLatin1String("kde5/services/"); // KGlobal::dirs()->xdgDataRelativePath("services")
+ Q_FOREACH (const QString &xdgDataPrefix, QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) {
+ if (QDir(xdgDataPrefix).exists()) {
+ const QString prefix = QFileInfo(xdgDataPrefix).canonicalFilePath();
+ if (realPath.startsWith(prefix + QLatin1Char('/') + servicesDir, sensitivity)) {
+ return true;
+ }
+ }
+ }
+ const QString autostartDir = QLatin1String("autostart/");
+ Q_FOREACH (const QString &xdgDataPrefix, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
+ if (QDir(xdgDataPrefix).exists()) {
+ const QString prefix = QFileInfo(xdgDataPrefix).canonicalFilePath();
+ if (realPath.startsWith(prefix + QLatin1Char('/') + autostartDir, sensitivity)) {
+ return true;
+ }
+ }
+ }
+
+ // Forbid desktop files outside of standard locations if kiosk is set so
+ if (!KAuthorized::authorize(QLatin1String("run_desktop_files"))) {
+ qWarning() << "Access to '" << path << "' denied because of 'run_desktop_files' restriction." << endl;
+ return false;
+ }
+
+ // Not otherwise permitted, so only allow if the file is executable, or if
+ // owned by root (uid == 0)
+ QFileInfo entryInfo(path);
+ if (entryInfo.isExecutable() || entryInfo.ownerId() == 0) {
+ return true;
+ }
+
+ qWarning() << "Access to '" << path << "' denied, not owned by root, executable flag not set." << endl;
+ return false;
}
QString KDesktopFile::readType() const
{
- Q_D(const KDesktopFile);
- return d->desktopGroup.readEntry("Type", QString());
+ Q_D(const KDesktopFile);
+ return d->desktopGroup.readEntry("Type", QString());
}
QString KDesktopFile::readIcon() const
{
- Q_D(const KDesktopFile);
- return d->desktopGroup.readEntry("Icon", QString());
+ Q_D(const KDesktopFile);
+ return d->desktopGroup.readEntry("Icon", QString());
}
QString KDesktopFile::readName() const
{
- Q_D(const KDesktopFile);
- return d->desktopGroup.readEntry("Name", QString());
+ Q_D(const KDesktopFile);
+ return d->desktopGroup.readEntry("Name", QString());
}
QString KDesktopFile::readComment() const
{
- Q_D(const KDesktopFile);
- return d->desktopGroup.readEntry("Comment", QString());
+ Q_D(const KDesktopFile);
+ return d->desktopGroup.readEntry("Comment", QString());
}
QString KDesktopFile::readGenericName() const
{
- Q_D(const KDesktopFile);
- return d->desktopGroup.readEntry("GenericName", QString());
+ Q_D(const KDesktopFile);
+ return d->desktopGroup.readEntry("GenericName", QString());
}
QString KDesktopFile::readPath() const
{
- Q_D(const KDesktopFile);
- // NOT readPathEntry, it is not XDG-compliant. Path entries written by
- // KDE4 will be still treated as such, though.
- return d->desktopGroup.readEntry("Path", QString());
+ Q_D(const KDesktopFile);
+ // NOT readPathEntry, it is not XDG-compliant. Path entries written by
+ // KDE4 will be still treated as such, though.
+ return d->desktopGroup.readEntry("Path", QString());
}
QString KDesktopFile::readDevice() const
{
- Q_D(const KDesktopFile);
- return d->desktopGroup.readEntry("Dev", QString());
+ Q_D(const KDesktopFile);
+ return d->desktopGroup.readEntry("Dev", QString());
}
QString KDesktopFile::readUrl() const
@@ -216,8 +224,7 @@ QString KDesktopFile::readUrl() const
} else {
// NOT readPathEntry (see readPath())
QString url = d->desktopGroup.readEntry("URL", QString());
- if ( !url.isEmpty() && !QDir::isRelativePath(url) )
- {
+ if (!url.isEmpty() && !QDir::isRelativePath(url)) {
// Handle absolute paths as such (i.e. we need to escape them)
return QUrl::fromLocalFile(url).toString();
}
@@ -236,67 +243,68 @@ KConfigGroup KDesktopFile::actionGroup(const QString &group)
return KConfigGroup(this, QLatin1String("Desktop Action ") + group);
}
-const KConfigGroup KDesktopFile::actionGroup(const QString& group) const
+const KConfigGroup KDesktopFile::actionGroup(const QString &group) const
{
- return const_cast<KDesktopFile*>(this)->actionGroup(group);
+ return const_cast<KDesktopFile *>(this)->actionGroup(group);
}
bool KDesktopFile::hasActionGroup(const QString &group) const
{
- return hasGroup(QString(QLatin1String("Desktop Action ") + group).toUtf8().constData());
+ return hasGroup(QString(QLatin1String("Desktop Action ") + group).toUtf8().constData());
}
bool KDesktopFile::hasLinkType() const
{
- return readType() == QLatin1String("Link");
+ return readType() == QLatin1String("Link");
}
bool KDesktopFile::hasApplicationType() const
{
- return readType() == QLatin1String("Application");
+ return readType() == QLatin1String("Application");
}
bool KDesktopFile::hasDeviceType() const
{
- return readType() == QLatin1String("FSDevice");
+ return readType() == QLatin1String("FSDevice");
}
bool KDesktopFile::tryExec() const
{
- Q_D(const KDesktopFile);
- // Test for TryExec and "X-KDE-AuthorizeAction"
- // NOT readPathEntry (see readPath())
- QString te = d->desktopGroup.readEntry("TryExec", QString());
-
- if (!te.isEmpty()) {
- return !QStandardPaths::findExecutable(te).isEmpty();
- }
- const QStringList list = d->desktopGroup.readEntry("X-KDE-AuthorizeAction", QStringList());
- if (!list.isEmpty())
- {
- for(QStringList::ConstIterator it = list.begin();
- it != list.end();
- ++it)
- {
- if (!KAuthorized::authorize((*it).trimmed()))
- return false;
- }
- }
-
- // See also KService::username()
- bool su = d->desktopGroup.readEntry("X-KDE-SubstituteUID", false);
- if (su)
- {
- QString user = d->desktopGroup.readEntry("X-KDE-Username", QString());
- if (user.isEmpty())
- user = QString::fromLocal8Bit(qgetenv("ADMIN_ACCOUNT"));
- if (user.isEmpty())
- user = QString::fromLatin1("root");
- if (!KAuthorized::authorize(QString::fromLatin1("user/")+user))
- return false;
- }
+ Q_D(const KDesktopFile);
+ // Test for TryExec and "X-KDE-AuthorizeAction"
+ // NOT readPathEntry (see readPath())
+ QString te = d->desktopGroup.readEntry("TryExec", QString());
+
+ if (!te.isEmpty()) {
+ return !QStandardPaths::findExecutable(te).isEmpty();
+ }
+ const QStringList list = d->desktopGroup.readEntry("X-KDE-AuthorizeAction", QStringList());
+ if (!list.isEmpty()) {
+ for (QStringList::ConstIterator it = list.begin();
+ it != list.end();
+ ++it) {
+ if (!KAuthorized::authorize((*it).trimmed())) {
+ return false;
+ }
+ }
+ }
- return true;
+ // See also KService::username()
+ bool su = d->desktopGroup.readEntry("X-KDE-SubstituteUID", false);
+ if (su) {
+ QString user = d->desktopGroup.readEntry("X-KDE-Username", QString());
+ if (user.isEmpty()) {
+ user = QString::fromLocal8Bit(qgetenv("ADMIN_ACCOUNT"));
+ }
+ if (user.isEmpty()) {
+ user = QString::fromLatin1("root");
+ }
+ if (!KAuthorized::authorize(QString::fromLatin1("user/") + user)) {
+ return false;
+ }
+ }
+
+ return true;
}
/**
@@ -313,8 +321,8 @@ bool KDesktopFile::tryExec() const
QStringList
KDesktopFile::sortOrder() const
{
- Q_D(const KDesktopFile);
- return d->desktopGroup.readEntry("SortOrder", QStringList());
+ Q_D(const KDesktopFile);
+ return d->desktopGroup.readEntry("SortOrder", QStringList());
}
//void KDesktopFile::virtual_hook( int id, void* data )
@@ -322,19 +330,20 @@ KDesktopFile::sortOrder() const
QString KDesktopFile::readDocPath() const
{
- Q_D(const KDesktopFile);
- //legacy entry in kde3 apps
- if(d->desktopGroup.hasKey( "DocPath" ))
- return d->desktopGroup.readPathEntry( "DocPath", QString() );
- return d->desktopGroup.readPathEntry( "X-DocPath", QString() );
+ Q_D(const KDesktopFile);
+ //legacy entry in kde3 apps
+ if (d->desktopGroup.hasKey("DocPath")) {
+ return d->desktopGroup.readPathEntry("DocPath", QString());
+ }
+ return d->desktopGroup.readPathEntry("X-DocPath", QString());
}
-KDesktopFile* KDesktopFile::copyTo(const QString &file) const
+KDesktopFile *KDesktopFile::copyTo(const QString &file) const
{
- KDesktopFile *config = new KDesktopFile(QString());
- this->KConfig::copyTo(file, config);
+ KDesktopFile *config = new KDesktopFile(QString());
+ this->KConfig::copyTo(file, config);
// config->setDesktopGroup();
- return config;
+ return config;
}
QStandardPaths::StandardLocation KDesktopFile::resource() const
@@ -355,12 +364,14 @@ bool KDesktopFile::noDisplay() const
return true;
}
if (d->desktopGroup.hasKey("OnlyShowIn")) {
- if (!d->desktopGroup.readXdgListEntry("OnlyShowIn").contains(QLatin1String("KDE")))
+ if (!d->desktopGroup.readXdgListEntry("OnlyShowIn").contains(QLatin1String("KDE"))) {
return true;
+ }
}
if (d->desktopGroup.hasKey("NotShowIn")) {
- if (d->desktopGroup.readXdgListEntry("NotShowIn").contains(QLatin1String("KDE")))
+ if (d->desktopGroup.readXdgListEntry("NotShowIn").contains(QLatin1String("KDE"))) {
return true;
+ }
}
return false;
}