From 31a832c34df5436a4aea4aa7e25e5da07bd38653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 11 Mar 2019 11:54:19 +0100 Subject: [PATCH] Add PluginManager::getPluginsDirectory() --- src/plugins/PluginManager.cpp | 28 ++++++++++++++++++---------- src/plugins/PluginManager.h | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/plugins/PluginManager.cpp b/src/plugins/PluginManager.cpp index abe924d1..a417aec5 100644 --- a/src/plugins/PluginManager.cpp +++ b/src/plugins/PluginManager.cpp @@ -30,25 +30,33 @@ PluginManager::~PluginManager() { } +QString PluginManager::getPluginsDirectory() const +{ + QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); + if (locations.isEmpty()) { + return QString(); + } + QDir pluginsDir(locations.first()); + pluginsDir.mkpath("plugins"); + if (!pluginsDir.cd("plugins")) { + return QString(); + } + return pluginsDir.absolutePath(); +} + void PluginManager::loadPlugins() { assert(plugins.isEmpty()); - QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); - if (locations.isEmpty()) { - qCritical() << "Failed to get a standard path to load plugins from."; + QString pluginsDirStr = getPluginsDirectory(); + if (pluginsDirStr.isEmpty()) { + qCritical() << "Failed to get a path to load plugins from."; return; } - QDir pluginsDir(locations.first()); - pluginsDir.mkpath("."); + QDir pluginsDir(pluginsDirStr); qInfo() << "Plugins are loaded from" << pluginsDir.absolutePath(); - pluginsDir.mkdir("plugins"); - if (!pluginsDir.cd("plugins")) { - return; - } - QDir nativePluginsDir = pluginsDir; nativePluginsDir.mkdir("native"); if (nativePluginsDir.cd("native")) { diff --git a/src/plugins/PluginManager.h b/src/plugins/PluginManager.h index 1f71b919..f02f862a 100644 --- a/src/plugins/PluginManager.h +++ b/src/plugins/PluginManager.h @@ -29,6 +29,8 @@ public: const QList &getPlugins() { return plugins; } + QString getPluginsDirectory() const; + private: QList plugins;