--- /dev/null
+/**
+ * Copyright (C) 2017 Deepin Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ **/
+
+#include "dstandardpaths.h"
+
+#include <QProcessEnvironment>
+
+DCORE_BEGIN_NAMESPACE
+
+
+class DSnapStandardPaths
+{
+public:
+ inline static QString writableLocation(QStandardPaths::StandardLocation /*type*/)
+ {
+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+ return env.value("SNAP_USER_COMMON");
+ }
+
+ inline static QStringList standardLocations(QStandardPaths::StandardLocation type)
+ {
+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+
+ switch (type) {
+ case QStandardPaths::GenericDataLocation: {
+ QString snapRoot = env.value("SNAP");
+ QString genericDataDir = snapRoot + "/usr/share/";
+ return QStringList() << genericDataDir;
+ }
+ default:
+ break;
+ }
+
+ return QStringList() << env.value("SNAP_USER_COMMON");
+ }
+
+private:
+ DSnapStandardPaths();
+ ~DSnapStandardPaths();
+ Q_DISABLE_COPY(DSnapStandardPaths)
+};
+
+
+static DStandardPaths::Mode s_mode = DStandardPaths::Auto;
+
+QString DStandardPaths::writableLocation(QStandardPaths::StandardLocation type)
+{
+ switch (s_mode) {
+ case Auto:
+ case Test:
+ return QStandardPaths::writableLocation(type);
+ case Snap:
+ return DSnapStandardPaths::writableLocation(type);
+ }
+ return QStandardPaths::writableLocation(type);
+}
+
+QStringList DStandardPaths::standardLocations(QStandardPaths::StandardLocation type)
+{
+ switch (s_mode) {
+ case Auto:
+ case Test:
+ return QStandardPaths::standardLocations(type);
+ case Snap:
+ return DSnapStandardPaths::standardLocations(type);
+ }
+ return QStandardPaths::standardLocations(type);
+}
+
+QString DStandardPaths::locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
+{
+ return QStandardPaths::locate(type, fileName, options);
+}
+
+QStringList DStandardPaths::locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
+{
+ return QStandardPaths::locateAll(type, fileName, options);
+}
+
+QString DStandardPaths::findExecutable(const QString &executableName, const QStringList &paths)
+{
+ return QStandardPaths::findExecutable(executableName, paths);
+}
+
+void DStandardPaths::setMode(DStandardPaths::Mode mode)
+{
+ s_mode = mode;
+ QStandardPaths::setTestModeEnabled(mode == Test);
+}
+
+DCORE_END_NAMESPACE
--- /dev/null
+/**
+ * Copyright (C) 2017 Deepin Technology Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ **/
+
+#ifndef DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H
+#define DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H
+
+#include <QStandardPaths>
+
+#include "dtkcore_global.h"
+
+DCORE_BEGIN_NAMESPACE
+
+class DStandardPathsPrivate;
+class DStandardPaths
+{
+public:
+ enum Mode {
+ Auto,
+ Snap,
+ Test,
+ };
+
+ static QString writableLocation(QStandardPaths::StandardLocation type);
+ static QStringList standardLocations(QStandardPaths::StandardLocation type);
+
+ static QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile);
+ static QStringList locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile);
+ static QString findExecutable(const QString &executableName, const QStringList &paths = QStringList());
+ static void setMode(Mode mode);
+
+private:
+ DStandardPaths();
+ ~DStandardPaths();
+ Q_DISABLE_COPY(DStandardPaths)
+};
+
+DCORE_END_NAMESPACE
+
+#endif // DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H