Merge lp:~jonas-drange/ubuntu-system-settings/snapd-paths2 into lp:ubuntu-system-settings

Proposed by Jonas G. Drange on 2016-09-14
Status: Work in progress
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/snapd-paths2
Merge into: lp:ubuntu-system-settings
Diff against target: 585 lines (+157/-47)
18 files modified
CMakeLists.txt (+9/-5)
plugins/about/storageabout.cpp (+13/-3)
plugins/background/MainPage.qml (+3/-4)
plugins/background/background.cpp (+13/-1)
plugins/background/background.h (+8/-0)
plugins/language/language-plugin.cpp (+17/-9)
plugins/language/onscreenkeyboard-plugin.cpp (+10/-2)
plugins/security-privacy/securityprivacy.cpp (+3/-1)
plugins/security-privacy/trust-store-model.cpp (+5/-1)
plugins/sound/PageComponent.qml (+2/-2)
plugins/sound/SoundsList.qml (+3/-2)
plugins/sound/sound.cpp (+10/-0)
src/CMakeLists.txt (+2/-0)
src/main.cpp (+7/-3)
src/plugin-manager.cpp (+14/-3)
src/plugin.cpp (+20/-4)
src/utils.cpp (+12/-5)
tests/CMakeLists.txt (+6/-2)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-system-settings/snapd-paths2
Reviewer Review Type Date Requested Status
Alberto Mardegan 2016-09-14 Needs Fixing on 2016-09-15
Review via email: mp+305751@code.launchpad.net

Description of the Change

Rewrites code that reference hard coded paths (e.g. /usr/share/foo) to use QStandardPaths. Some paths, e.g. to /etc, are still hard coded, but I've prepended $SNAP, which should be empty ("") on traditional non-snappy systems.

Packaging changes are deps that were missing.

Note: I have left the background panel mostly alone, due to [1]. I've also left the Updates panel alone—it will never be expected to work as it is now, on snappy.

[1] https://code.launchpad.net/~mterry/ubuntu-system-settings/default-wallpaper/+merge/297632

To post a comment you must log in.
Alberto Mardegan (mardy) wrote :

Nothing major, but please see the inline comments.

review: Needs Fixing
1716. By Jonas G. Drange on 2016-09-15

address comments from mardy

1717. By Jonas G. Drange on 2016-09-15

use data dir in settings dir

1718. By Jonas G. Drange on 2016-09-15

migrate more paths to work on a snappy system

1719. By Jonas G. Drange on 2016-09-16

more nuking of usr in trust store, osk plugin and sound plugin

1720. By Jonas G. Drange on 2016-09-19

add comment, fix one piece of whitespace

1721. By Jonas G. Drange on 2016-09-19

clean up diff

1722. By Jonas G. Drange on 2016-09-19

more cleanup

Unmerged revisions

1722. By Jonas G. Drange on 2016-09-19

more cleanup

1721. By Jonas G. Drange on 2016-09-19

clean up diff

1720. By Jonas G. Drange on 2016-09-19

add comment, fix one piece of whitespace

1719. By Jonas G. Drange on 2016-09-16

more nuking of usr in trust store, osk plugin and sound plugin

1718. By Jonas G. Drange on 2016-09-15

migrate more paths to work on a snappy system

1717. By Jonas G. Drange on 2016-09-15

use data dir in settings dir

1716. By Jonas G. Drange on 2016-09-15

address comments from mardy

1715. By Jonas G. Drange on 2016-09-14

search xdg paths for qml and .settings files

1714. By Jonas G. Drange on 2016-09-14

use ctx prop for mountpoint

1713. By Jonas G. Drange on 2016-09-14

use xdg dirs for usr share stuff

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2016-06-01 04:08:58 +0000
3+++ CMakeLists.txt 2016-09-19 12:34:26 +0000
4@@ -53,16 +53,20 @@
5 find_program(INTLTOOL_MERGE intltool-merge)
6 find_program(INTLTOOL_EXTRACT intltool-extract)
7
8-set(PLUGIN_MANIFEST_DIR_BASE share/ubuntu/settings/system)
9+set(PLUGIN_DATA_DIR_BASE "share")
10+set(PLUGIN_MANIFEST_DIR_BASE "ubuntu/settings/system")
11+set(PLUGIN_QML_DIR_BASE "${PLUGIN_MANIFEST_DIR_BASE}/qml-plugins")
12 set(PLUGIN_MODULE_DIR_BASE ubuntu-system-settings)
13 set(PLUGIN_PRIVATE_MODULE_DIR_BASE "${PLUGIN_MODULE_DIR_BASE}/private")
14-set(PLUGIN_QML_DIR_BASE share/ubuntu/settings/system/qml-plugins)
15
16-set(PLUGIN_MANIFEST_DIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_MANIFEST_DIR_BASE}")
17+set(PLUGIN_DATA_DIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_DATA_DIR_BASE}") # E.g. /usr/share.
18+set(PLUGIN_MANIFEST_DIR "${PLUGIN_DATA_DIR}/${PLUGIN_MANIFEST_DIR_BASE}")
19 set(PLUGIN_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/${LIBDIR}/${PLUGIN_MODULE_DIR_BASE}")
20-set(PLUGIN_QML_DIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_QML_DIR_BASE}")
21+set(PLUGIN_QML_DIR "${PLUGIN_DATA_DIR}/${PLUGIN_QML_DIR_BASE}")
22+
23+set(RELATIVE_PLUGIN_QML_DIR "${RELATIVE_PLUGIN_MANIFEST_DIR}/qml-plugins")
24 set(PLUGIN_PRIVATE_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/${LIBDIR}/${PLUGIN_PRIVATE_MODULE_DIR_BASE}")
25-set(SETTINGS_SHARE_DIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_MANIFEST_DIR_BASE}")
26+set(SETTINGS_SHARE_DIR "${PLUGIN_DATA_DIR}/${PLUGIN_MANIFEST_DIR_BASE}")
27 set(PUSH_HELPER_DIR "lib/ubuntu-push-client/legacy-helpers")
28
29 SET(CMAKE_INSTALL_RPATH "${PLUGIN_MODULE_DIR}")
30
31=== modified file 'plugins/about/storageabout.cpp'
32--- plugins/about/storageabout.cpp 2016-03-30 17:43:50 +0000
33+++ plugins/about/storageabout.cpp 2016-09-19 12:34:26 +0000
34@@ -37,8 +37,10 @@
35 #include <QJsonArray>
36 #include <QJsonDocument>
37 #include <QJsonObject>
38+#include <QStandardPaths>
39 #include <QtCore/QStorageInfo>
40 #include <QtCore/QSharedPointer>
41+#include <QtGlobal>
42 #include <QProcess>
43 #include <QVariant>
44 #include <hybris/properties/properties.h>
45@@ -195,7 +197,7 @@
46 {
47 if (m_ubuntuBuildID.isEmpty() || m_ubuntuBuildID.isNull())
48 {
49- QFile file("/etc/media-info");
50+ QFile file(qgetenv("SNAP").append("/etc/media-info"));
51 if (!file.exists())
52 return "";
53 file.open(QIODevice::ReadOnly | QIODevice::Text);
54@@ -226,10 +228,18 @@
55 QString StorageAbout::licenseInfo(const QString &subdir) const
56 {
57
58- QString copyright = "/usr/share/doc/" + subdir + "/copyright";
59+ QString copyright = "doc/" + subdir + "/copyright";
60 QString copyrightText;
61
62- QFile file(copyright);
63+ QString copyrightFile = QStandardPaths::locate(
64+ QStandardPaths::GenericDataLocation, copyright,
65+ QStandardPaths::LocateFile
66+ );
67+ if (copyrightFile.isEmpty()) {
68+ return QString();
69+ }
70+
71+ QFile file(copyrightFile);
72 if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
73 return QString();
74 copyrightText = QString(file.readAll());
75
76=== modified file 'plugins/background/MainPage.qml'
77--- plugins/background/MainPage.qml 2015-11-13 21:14:07 +0000
78+++ plugins/background/MainPage.qml 2016-09-19 12:34:26 +0000
79@@ -36,17 +36,16 @@
80
81 signal save (string uri)
82
83- /* TODO: For now hardcoded paths, later we'll use GSettings */
84 /* TODO: fix bug where rotating in uss will change default
85 background to tablet_back… thus losing track of phone_back… */
86 property string defaultBackground:
87 mainPage.width >= units.gu(60) ?
88- "/usr/share/unity8/graphics/tablet_background.jpg" :
89- "/usr/share/unity8/graphics/phone_background.jpg"
90+ backgroundPanel.defaultTabletBackgroundFile :
91+ backgroundPanel.defaultPhoneBackgroundFile
92
93 /* If there is no uri then use the default */
94 property string welcomeBackground: (backgroundPanel.backgroundFile === "file:") ?
95- "file:///usr/share/unity8/graphics/phone_background.jpg" :
96+ Qt.resolvedUrl(backgroundPanel.defaultPhoneBackgroundFile) :
97 backgroundPanel.backgroundFile
98
99 property var activeTransfer
100
101=== modified file 'plugins/background/background.cpp'
102--- plugins/background/background.cpp 2014-07-08 09:18:09 +0000
103+++ plugins/background/background.cpp 2016-09-19 12:34:26 +0000
104@@ -50,6 +50,18 @@
105 return QString();
106 }
107
108+QString Background::defaultPhoneBackgroundFile()
109+{
110+ auto file = "/usr/share/unity8/graphics/phone_background.jpg";
111+ return qgetenv("SNAP").append(file);
112+}
113+
114+QString Background::defaultTabletBackgroundFile()
115+{
116+ auto file = "/usr/share/unity8/graphics/tablet_background.jpg";
117+ return qgetenv("SNAP").append(file);
118+}
119+
120 void Background::setBackgroundFile(QUrl backgroundFile)
121 {
122 if (!backgroundFile.isLocalFile())
123@@ -162,7 +174,7 @@
124 if (envDir != "")
125 dir = QDir(envDir);
126 else
127- dir = QDir("/usr/share/backgrounds/");
128+ dir = QDir(qgetenv("SNAP") + "/usr/share/backgrounds/");
129
130
131 dir.setFilter(QDir::Files | QDir::NoSymLinks);
132
133=== modified file 'plugins/background/background.h'
134--- plugins/background/background.h 2015-03-16 13:51:36 +0000
135+++ plugins/background/background.h 2016-09-19 12:34:26 +0000
136@@ -45,10 +45,18 @@
137 READ ubuntuArt
138 NOTIFY ubuntuArtChanged )
139
140+ Q_PROPERTY( QString defaultPhoneBackgroundFile
141+ READ defaultPhoneBackgroundFile CONSTANT )
142+
143+ Q_PROPERTY( QString defaultTabletBackgroundFile
144+ READ defaultTabletBackgroundFile CONSTANT )
145+
146 public:
147 explicit Background(QObject *parent = 0);
148 ~Background();
149 QString backgroundFile();
150+ QString defaultPhoneBackgroundFile();
151+ QString defaultTabletBackgroundFile();
152 void setBackgroundFile(QUrl backgroundFile);
153 Q_INVOKABLE QUrl prepareBackgroundFile(const QUrl &url, bool shareWithGreeter);
154 Q_INVOKABLE bool fileExists(const QString &file);
155
156=== modified file 'plugins/language/language-plugin.cpp'
157--- plugins/language/language-plugin.cpp 2015-12-22 13:49:39 +0000
158+++ plugins/language/language-plugin.cpp 2016-09-19 12:34:26 +0000
159@@ -17,6 +17,7 @@
160 * You should have received a copy of the GNU General Public License along
161 * with this program. If not, see <http://www.gnu.org/licenses/>.
162 */
163+#include <QStandardPaths>
164 #include <QtDebug>
165 #include "language-plugin.h"
166 #include "keyboard-layout.h"
167@@ -24,7 +25,7 @@
168 #include <act/act.h>
169 #include <unicode/locid.h>
170
171-#define LANGUAGE2LOCALE "/usr/share/language-tools/language2locale"
172+#define LANGUAGE2LOCALE "language-tools/language2locale"
173
174 static const char * const LOCALE_BLACKLIST[] = {
175 "C",
176@@ -208,14 +209,21 @@
177 QString language(languageLocale.locale.getLanguage());
178
179 if (!likelyLocaleForLanguage.contains(language)) {
180- QProcess likelyProcess;
181- likelyProcess.start(LANGUAGE2LOCALE,
182- QStringList(language),
183- QIODevice::ReadOnly);
184- likelyProcess.waitForFinished();
185- QString likelyLocale(likelyProcess.readAllStandardOutput());
186- likelyLocale = likelyLocale.left(likelyLocale.indexOf('.'));
187- likelyLocaleForLanguage.insert(language, likelyLocale.trimmed());
188+ QString l2lPath = QStandardPaths::locate(
189+ QStandardPaths::GenericDataLocation, LANGUAGE2LOCALE
190+ );
191+ if (l2lPath.isEmpty()) {
192+ qWarning() << "Could not find language2locale file.";
193+ } else {
194+ QProcess likelyProcess;
195+ likelyProcess.start(l2lPath, QStringList(language),
196+ QIODevice::ReadOnly);
197+ likelyProcess.waitForFinished();
198+ QString likelyLocale(likelyProcess.readAllStandardOutput());
199+ likelyLocale = likelyLocale.left(likelyLocale.indexOf('.'));
200+ likelyLocaleForLanguage.insert(language,
201+ likelyLocale.trimmed());
202+ }
203 }
204
205 languageLocale.likely = likelyLocaleForLanguage[language] ==
206
207=== modified file 'plugins/language/onscreenkeyboard-plugin.cpp'
208--- plugins/language/onscreenkeyboard-plugin.cpp 2015-12-22 13:49:39 +0000
209+++ plugins/language/onscreenkeyboard-plugin.cpp 2016-09-19 12:34:26 +0000
210@@ -19,6 +19,7 @@
211 * with this program. If not, see <http://www.gnu.org/licenses/>.
212 */
213
214+#include <QStandardPaths>
215 #include <QtDebug>
216 #include "onscreenkeyboard-plugin.h"
217
218@@ -28,7 +29,7 @@
219 #define KEY_CURRENT_LAYOUT "active-language"
220 #define KEY_PLUGIN_PATHS "plugin-paths"
221
222-#define LAYOUTS_DIR "/usr/share/maliit/plugins/com/ubuntu/lib"
223+#define LAYOUTS_DIR "maliit/plugins/com/ubuntu/lib"
224
225 OnScreenKeyboardPlugin::OnScreenKeyboardPlugin(QObject *parent) :
226 QObject(parent),
227@@ -37,7 +38,14 @@
228 GVariantIter *iter;
229 const gchar *path;
230
231- m_layoutPaths.append(LAYOUTS_DIR);
232+ QString layoutPath = QStandardPaths::locate(
233+ QStandardPaths::GenericDataLocation, LAYOUTS_DIR,
234+ QStandardPaths::LocateDirectory
235+ );
236+ if (!layoutPath.isEmpty()) {
237+ m_layoutPaths.append(layoutPath);
238+ }
239+
240 g_settings_get(m_maliitSettings, KEY_PLUGIN_PATHS, "as", &iter);
241 for (int i(0); g_variant_iter_next(iter, "&s", &path); i++) {
242 m_layoutPaths.append(path);
243
244=== modified file 'plugins/security-privacy/securityprivacy.cpp'
245--- plugins/security-privacy/securityprivacy.cpp 2016-05-26 12:20:47 +0000
246+++ plugins/security-privacy/securityprivacy.cpp 2016-09-19 12:34:26 +0000
247@@ -22,6 +22,7 @@
248 #include <QtCore/QDateTime>
249 #include <QtCore/QDebug>
250 #include <QtCore/QProcess>
251+#include <QtGlobal>
252 #include <QtDBus/QDBusConnection>
253 #include <QtDBus/QDBusConnectionInterface>
254 #include <QtDBus/QDBusInterface>
255@@ -336,7 +337,8 @@
256 passwdData += value.toUtf8() + '\n' + value.toUtf8() + '\n';
257
258 QProcess pamHelper;
259- pamHelper.setProgram("/usr/bin/passwd");
260+ // TODO: Decide if this approach is sufficient in a snap world. lp:1616486
261+ pamHelper.setProgram(qgetenv("SNAP") + "/usr/bin/passwd");
262 pamHelper.start();
263 pamHelper.write(passwdData);
264 pamHelper.closeWriteChannel();
265
266=== modified file 'plugins/security-privacy/trust-store-model.cpp'
267--- plugins/security-privacy/trust-store-model.cpp 2015-09-29 11:39:39 +0000
268+++ plugins/security-privacy/trust-store-model.cpp 2016-09-19 12:34:26 +0000
269@@ -24,6 +24,7 @@
270 #include <QIcon>
271 #include <QList>
272 #include <QMap>
273+#include <QtGlobal>
274 #include <QSet>
275 #include <QStandardPaths>
276
277@@ -104,7 +105,10 @@
278
279 /* try system location as well, that's at least needed for unity8-dash
280 * which is not a click (yet) and doesn't have a .local entry */
281- QString usrDesktopFilename(QString("/usr/share/applications/%1.desktop").arg(id));
282+ QString usrDesktopFilename(
283+ qgetenv("SNAP") +
284+ QString("/usr/share/applications/%1.desktop").arg(id)
285+ );
286 if (QFile(usrDesktopFilename).exists())
287 return usrDesktopFilename;
288
289
290=== modified file 'plugins/sound/PageComponent.qml'
291--- plugins/sound/PageComponent.qml 2016-08-23 13:34:14 +0000
292+++ plugins/sound/PageComponent.qml 2016-09-19 12:34:26 +0000
293@@ -154,7 +154,7 @@
294 title: i18n.tr("Ringtone"),
295 showStopButton: true,
296 soundType: 0,
297- soundsDir: "/usr/share/sounds/ubuntu/ringtones/"
298+ soundsDir: "sounds/ubuntu/ringtones/"
299 }
300 )
301 }
302@@ -212,7 +212,7 @@
303 { title: i18n.tr("Message received"),
304 soundType: 1,
305 soundsDir:
306- "/usr/share/sounds/ubuntu/notifications/" })
307+ "sounds/ubuntu/notifications/" })
308 }
309
310 SettingsListItems.Standard {
311
312=== modified file 'plugins/sound/SoundsList.qml'
313--- plugins/sound/SoundsList.qml 2016-03-21 18:36:31 +0000
314+++ plugins/sound/SoundsList.qml 2016-09-19 12:34:26 +0000
315@@ -28,9 +28,10 @@
316 flickable: scrollWidget
317
318 function refreshSoundFileNames() {
319+ var customDir = mountPoint + "/custom/usr/share/" + soundsDir;
320 if (soundType === 0)
321- return backendInfo.listSounds([soundsDir, "/custom" + soundsDir, backendInfo.customRingtonePath])
322- return backendInfo.listSounds([soundsDir, "/custom" + soundsDir])
323+ return backendInfo.listSounds([soundsDir, customDir, backendInfo.customRingtonePath])
324+ return backendInfo.listSounds([soundsDir, customDir])
325 }
326
327 UbuntuSoundPanel {
328
329=== modified file 'plugins/sound/sound.cpp'
330--- plugins/sound/sound.cpp 2016-08-22 13:29:22 +0000
331+++ plugins/sound/sound.cpp 2016-09-19 12:34:26 +0000
332@@ -245,6 +245,16 @@
333 QStringList soundsListFromDir(const QString &dirString)
334 {
335 QDir soundsDir(dirString);
336+ if (soundsDir.isRelative()) {
337+ QString path = QStandardPaths::locate(
338+ QStandardPaths::GenericDataLocation, dirString,
339+ QStandardPaths::LocateDirectory
340+ );
341+ if (path.isEmpty()) {
342+ return QStringList();
343+ }
344+ soundsDir = QDir(path);
345+ }
346
347 if (soundsDir.exists())
348 {
349
350=== modified file 'src/CMakeLists.txt'
351--- src/CMakeLists.txt 2016-08-16 11:46:12 +0000
352+++ src/CMakeLists.txt 2016-09-19 12:34:26 +0000
353@@ -4,7 +4,9 @@
354 add_definitions(-DI18N_DOMAIN="ubuntu-system-settings")
355 add_definitions(-DPLUGIN_PRIVATE_MODULE_DIR="${PLUGIN_PRIVATE_MODULE_DIR}")
356 add_definitions(-DPLUGIN_MANIFEST_DIR="${PLUGIN_MANIFEST_DIR}")
357+add_definitions(-DPLUGIN_MANIFEST_DIR_BASE="${PLUGIN_MANIFEST_DIR_BASE}")
358 add_definitions(-DPLUGIN_QML_DIR="${PLUGIN_QML_DIR}")
359+add_definitions(-DPLUGIN_QML_DIR_BASE="${PLUGIN_QML_DIR_BASE}")
360 add_definitions(-DPLUGIN_MODULE_DIR="${PLUGIN_MODULE_DIR}")
361
362 add_subdirectory(SystemSettings)
363
364=== modified file 'src/main.cpp'
365--- src/main.cpp 2016-07-31 22:11:50 +0000
366+++ src/main.cpp 2016-09-19 12:34:26 +0000
367@@ -23,11 +23,13 @@
368 #include "plugin-manager.h"
369 #include "utils.h"
370
371+#include <QByteArray>
372 #include <QGuiApplication>
373 #include <QProcessEnvironment>
374 #include <QQmlContext>
375 #include <QUrl>
376 #include <QQuickView>
377+#include <QtGlobal>
378 #include <QtQml>
379 #include <QtQml/QQmlDebuggingEnabler>
380 static QQmlDebuggingEnabler debuggingEnabler(false);
381@@ -37,6 +39,7 @@
382 int main(int argc, char **argv)
383 {
384 QGuiApplication app(argc, argv);
385+ QByteArray mountPoint = qEnvironmentVariableIsSet("SNAP") ? qgetenv("SNAP") : "";
386
387 /* The testability driver is only loaded by QApplication but not by
388 * QGuiApplication. However, QApplication depends on QWidget which would
389@@ -88,10 +91,11 @@
390 qmlRegisterType<SystemSettings::PluginManager>("SystemSettings", 1, 0, "PluginManager");
391 view.engine()->rootContext()->setContextProperty("Utilities", &utils);
392 view.setResizeMode(QQuickView::SizeRootObjectToView);
393- view.engine()->addImportPath(PLUGIN_PRIVATE_MODULE_DIR);
394- view.engine()->addImportPath(PLUGIN_QML_DIR);
395+ view.engine()->addImportPath(mountPoint + PLUGIN_PRIVATE_MODULE_DIR);
396+ view.engine()->addImportPath(mountPoint + PLUGIN_QML_DIR);
397 view.rootContext()->setContextProperty("defaultPlugin", defaultPlugin);
398- view.rootContext()->setContextProperty("i18nDirectory", I18N_DIRECTORY);
399+ view.rootContext()->setContextProperty("mountPoint", mountPoint);
400+ view.rootContext()->setContextProperty("i18nDirectory", mountPoint + I18N_DIRECTORY);
401 view.rootContext()->setContextProperty("pluginOptions", pluginOptions);
402 view.rootContext()->setContextProperty("view", &view);
403 view.setSource(QUrl("qrc:/qml/MainWindow.qml"));
404
405=== modified file 'src/plugin-manager.cpp'
406--- src/plugin-manager.cpp 2014-08-28 07:22:28 +0000
407+++ src/plugin-manager.cpp 2016-09-19 12:34:26 +0000
408@@ -28,11 +28,12 @@
409 #include <QProcessEnvironment>
410 #include <QQmlContext>
411 #include <QQmlEngine>
412+#include <QStandardPaths>
413 #include <QStringList>
414
415 using namespace SystemSettings;
416
417-static const QLatin1String baseDir{PLUGIN_MANIFEST_DIR};
418+static const QLatin1String baseDir{PLUGIN_MANIFEST_DIR_BASE};
419
420 namespace SystemSettings {
421
422@@ -80,7 +81,17 @@
423 {
424 Q_Q(PluginManager);
425 clear();
426- QDir path(baseDir, "*.settings");
427+
428+ /* Create a list of search paths (e.g. /usr/share, /usr/local/share) and
429+ * append the baseDir. The reason for not using locateAll is that locateAll
430+ * does not seem to work with a dir and file pattern, which means it will
431+ * look for all .settings files, not just those in well-known locations. */
432+ QStandardPaths::StandardLocation loc = QStandardPaths::GenericDataLocation;
433+ QFileInfoList searchPaths;
434+ Q_FOREACH(const QString &path, QStandardPaths::standardLocations(loc)) {
435+ QDir dir(QString("%1/%2").arg(path).arg(baseDir), "*.settings");
436+ searchPaths.append(dir.entryInfoList());
437+ }
438
439 /* Use an environment variable USS_SHOW_ALL_UI to show unfinished / beta /
440 * deferred components or panels */
441@@ -95,7 +106,7 @@
442 if (ctx)
443 ctx->engine()->rootContext()->setContextProperty("showAllUI", showAll);
444
445- Q_FOREACH(QFileInfo fileInfo, path.entryInfoList()) {
446+ Q_FOREACH(QFileInfo fileInfo, searchPaths) {
447 Plugin *plugin = new Plugin(fileInfo);
448 QQmlEngine::setContextForObject(plugin, ctx);
449 QMap<QString, Plugin*> &pluginList = m_plugins[plugin->category()];
450
451=== modified file 'src/plugin.cpp'
452--- src/plugin.cpp 2015-08-13 20:31:53 +0000
453+++ src/plugin.cpp 2016-09-19 12:34:26 +0000
454@@ -29,6 +29,7 @@
455 #include <QPluginLoader>
456 #include <QQmlContext>
457 #include <QQmlEngine>
458+#include <QStandardPaths>
459 #include <QStringList>
460 #include <QVariantMap>
461
462@@ -38,7 +39,7 @@
463 using namespace SystemSettings;
464
465 static const QLatin1String pluginModuleDir{PLUGIN_MODULE_DIR};
466-static const QLatin1String pluginQmlDir{PLUGIN_QML_DIR};
467+static const QLatin1String pluginQmlDir{PLUGIN_QML_DIR_BASE};
468
469 namespace SystemSettings {
470
471@@ -60,6 +61,7 @@
472 mutable PluginInterface2 *m_plugin2;
473 QString m_baseName;
474 QVariantMap m_data;
475+ QString m_dataPath;
476 };
477
478 } // namespace
479@@ -86,6 +88,15 @@
480 }
481
482 m_data = json.toVariant().toMap();
483+
484+ QStandardPaths::StandardLocation loc = QStandardPaths::GenericDataLocation;
485+ Q_FOREACH(const QString &path, QStandardPaths::standardLocations(loc)) {
486+ QDir dir(QString("%1/%2/%3").arg(path).arg(pluginQmlDir).arg(m_baseName));
487+ if (dir.exists()) {
488+ m_dataPath = dir.absolutePath();
489+ break;
490+ }
491+ }
492 }
493
494 bool PluginPrivate::ensureLoaded() const
495@@ -102,7 +113,12 @@
496 if (plugin.isEmpty())
497 return false;
498
499- QString name = QString("%1/lib%2.so").arg(pluginModuleDir).arg(plugin);
500+ QQmlEngine engine;
501+ const QString mountPoint = engine.rootContext()
502+ ->contextProperty("mountPoint").value<QByteArray>();
503+
504+ QString name = QString("%1%2/lib%3.so")
505+ .arg(mountPoint).arg(pluginModuleDir).arg(plugin);
506
507 m_loader.setFileName(name);
508 if (Q_UNLIKELY(!m_loader.load())) {
509@@ -143,8 +159,8 @@
510 QUrl componentUrl = m_data.value(key).toString();
511 if (!componentUrl.isEmpty()) {
512 if (componentUrl.isRelative()) {
513- QDir dir(pluginQmlDir);
514- if (dir.cd(m_baseName)) {
515+ if (!m_dataPath.isEmpty()) {
516+ QDir dir(m_dataPath);
517 componentUrl =
518 QUrl::fromLocalFile(dir.filePath(componentUrl.path()));
519 }
520
521=== modified file 'src/utils.cpp'
522--- src/utils.cpp 2016-02-16 15:20:07 +0000
523+++ src/utils.cpp 2016-09-19 12:34:26 +0000
524@@ -22,7 +22,8 @@
525 #include "debug.h"
526
527 #include <glib.h>
528-#include <QUrl>
529+#include <QStandardPaths>
530+#include <QUrlQuery>
531 #include <QUrlQuery>
532
533
534@@ -94,13 +95,19 @@
535 */
536 QString Utilities::getDestinationUrl(const QString &source)
537 {
538+ QString mapFile = QStandardPaths::locate(
539+ QStandardPaths::GenericDataLocation,
540+ QString("%1/%2").arg(PLUGIN_MANIFEST_DIR).arg("url-map.ini")
541+ );
542+ if (Q_UNLIKELY(mapFile.isEmpty())) {
543+ qWarning() << "could not locate map file";
544+ return source;
545+ }
546+
547 // This method will be called from multiple threads, and QSettings
548 // is reentrant, meaning each call to this function require its own
549 // settings instance.
550- QSettings map(
551- QString("%1/%2").arg(PLUGIN_MANIFEST_DIR).arg("url-map.ini"),
552- QSettings::IniFormat
553- );
554+ QSettings map(mapFile, QSettings::IniFormat);
555 map.sync();
556
557 // If reading the map failed, return the source unchanged.
558
559=== modified file 'tests/CMakeLists.txt'
560--- tests/CMakeLists.txt 2016-08-19 12:30:40 +0000
561+++ tests/CMakeLists.txt 2016-09-19 12:34:26 +0000
562@@ -10,9 +10,11 @@
563
564 add_definitions(-DI18N_DOMAIN="ubuntu-system-settings")
565 add_definitions(-DPLUGIN_PRIVATE_MODULE_DIR="${PLUGIN_PRIVATE_MODULE_DIR}")
566+add_definitions(-DPLUGIN_MODULE_DIR="${CMAKE_CURRENT_BINARY_DIR}")
567 add_definitions(-DPLUGIN_MANIFEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data")
568-add_definitions(-DPLUGIN_MODULE_DIR="${CMAKE_CURRENT_BINARY_DIR}")
569+add_definitions(-DPLUGIN_MANIFEST_DIR_BASE="data")
570 add_definitions(-DPLUGIN_QML_DIR="${CMAKE_CURRENT_BINARY_DIR}")
571+add_definitions(-DPLUGIN_QML_DIR_BASE="${CMAKE_CURRENT_BINARY_DIR}")
572 add_definitions(-DSYSTEM_IMAGE_DBUS_TEMPLATE="${CMAKE_SOURCE_DIR}/tests/autopilot/ubuntu_system_settings/tests/systemimage.py")
573
574 add_library(test-plugin SHARED test-plugin.cpp test-plugin.h)
575@@ -49,7 +51,9 @@
576 qt5_use_modules(tst-plugins Core Qml Test)
577 target_link_libraries(tst-plugins SystemSettings ${GLIB_LDFLAGS})
578 add_test(tst-plugins tst-plugins)
579-set_tests_properties(tst-plugins PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")
580+set_tests_properties(tst-plugins PROPERTIES ENVIRONMENT
581+ "QT_QPA_PLATFORM=minimal;XDG_DATA_DIRS=${CMAKE_CURRENT_SOURCE_DIR}"
582+)
583
584 qt5_use_modules(tst-arguments Core Test)
585 target_link_libraries(tst-arguments ${GLIB_LDFLAGS})

Subscribers

People subscribed via source and target branches