Changeset View
Changeset View
Standalone View
Standalone View
menufile.cpp
Show All 16 Lines | |||||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "menufile.h" | 19 | #include "menufile.h" | ||
20 | 20 | | |||
21 | #include <QFile> | 21 | #include <QFile> | ||
22 | #include <QTextStream> | 22 | #include <QTextStream> | ||
23 | #include <QRegExp> | 23 | #include <QRegExp> | ||
24 | #include <QFileInfo> | 24 | #include <QFileInfo> | ||
25 | #include <QStandardPaths> | ||||
25 | 26 | | |||
26 | #include "kmenuedit_debug.h" | 27 | #include "kmenuedit_debug.h" | ||
27 | #include <KGlobal> | | |||
28 | #include <KLocalizedString> | 28 | #include <KLocalizedString> | ||
29 | #include <KStandardDirs> | | |||
30 | 29 | | |||
31 | const QString MenuFile::MF_MENU = QStringLiteral("Menu"); | 30 | const QString MenuFile::MF_MENU = QStringLiteral("Menu"); | ||
32 | const QString MenuFile::MF_PUBLIC_ID = QStringLiteral("-//freedesktop//DTD Menu 1.0//EN"); | 31 | const QString MenuFile::MF_PUBLIC_ID = QStringLiteral("-//freedesktop//DTD Menu 1.0//EN"); | ||
33 | const QString MenuFile::MF_SYSTEM_ID = QStringLiteral("http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd"); | 32 | const QString MenuFile::MF_SYSTEM_ID = QStringLiteral("http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd"); | ||
34 | const QString MenuFile::MF_NAME = QStringLiteral("Name"); | 33 | const QString MenuFile::MF_NAME = QStringLiteral("Name"); | ||
35 | const QString MenuFile::MF_INCLUDE = QStringLiteral("Include"); | 34 | const QString MenuFile::MF_INCLUDE = QStringLiteral("Include"); | ||
36 | const QString MenuFile::MF_EXCLUDE = QStringLiteral("Exclude"); | 35 | const QString MenuFile::MF_EXCLUDE = QStringLiteral("Exclude"); | ||
37 | const QString MenuFile::MF_FILENAME = QStringLiteral("Filename"); | 36 | const QString MenuFile::MF_FILENAME = QStringLiteral("Filename"); | ||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Line(s) | 123 | { | |||
181 | 180 | | |||
182 | if (subMenuName.isEmpty()) { | 181 | if (subMenuName.isEmpty()) { | ||
183 | return newElem; | 182 | return newElem; | ||
184 | } else { | 183 | } else { | ||
185 | return findMenu(newElem, subMenuName, create); | 184 | return findMenu(newElem, subMenuName, create); | ||
186 | } | 185 | } | ||
187 | } | 186 | } | ||
188 | 187 | | |||
188 | static QString relativeToDesktopDirsLocation(const QString &file) | ||||
189 | { | ||||
190 | const QString canonical = QFileInfo(file).canonicalFilePath(); | ||||
191 | const QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | ||||
192 | for (const QString &dir : dirs) { | ||||
193 | const QString base = dir + QLatin1String("/desktop-directories"); | ||||
194 | if (canonical.startsWith(base)) | ||||
195 | return canonical.mid(base.length()+1); | ||||
196 | } | ||||
197 | return QString(); | ||||
198 | } | ||||
199 | | ||||
189 | static QString entryToDirId(const QString &path) | 200 | static QString entryToDirId(const QString &path) | ||
190 | { | 201 | { | ||
191 | // See also KDesktopFile::locateLocal | 202 | // See also KDesktopFile::locateLocal | ||
192 | QString local; | 203 | QString local; | ||
193 | if (QFileInfo(path).isAbsolute()) { | 204 | if (QFileInfo(path).isAbsolute()) { | ||
194 | // XDG Desktop menu items come with absolute paths, we need to | 205 | // XDG Desktop menu items come with absolute paths, we need to | ||
195 | // extract their relative path and then build a local path. | 206 | // extract their relative path and then build a local path. | ||
196 | local = KGlobal::dirs()->relativeLocation("xdgdata-dirs", path); | 207 | local = relativeToDesktopDirsLocation(path); | ||
197 | } | 208 | } | ||
198 | 209 | | |||
199 | if (local.isEmpty() || local.startsWith(QLatin1Char('/'))) { | 210 | if (local.isEmpty() || local.startsWith(QLatin1Char('/'))) { | ||
200 | // What now? Use filename only and hope for the best. | 211 | // What now? Use filename only and hope for the best. | ||
201 | local = path.mid(path.lastIndexOf(QLatin1Char('/'))+1); | 212 | local = path.mid(path.lastIndexOf(QLatin1Char('/'))+1); | ||
202 | } | 213 | } | ||
203 | return local; | 214 | return local; | ||
204 | } | 215 | } | ||
▲ Show 20 Lines • Show All 342 Lines • Show Last 20 Lines |