Add PluginManager::getPluginsDirectory()

This commit is contained in:
Florian Märkl 2019-03-11 11:54:19 +01:00
parent 193fef46df
commit 31a832c34d
2 changed files with 20 additions and 10 deletions

View File

@ -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")) {

View File

@ -29,6 +29,8 @@ public:
const QList<CutterPlugin *> &getPlugins() { return plugins; }
QString getPluginsDirectory() const;
private:
QList<CutterPlugin *> plugins;