diff --git a/src/lib/app/datapaths.cpp b/src/lib/app/datapaths.cpp index 27b5eccf1..15a71ded7 100644 --- a/src/lib/app/datapaths.cpp +++ b/src/lib/app/datapaths.cpp @@ -77,6 +77,19 @@ QStringList DataPaths::allPaths(DataPaths::Path type) return qz_data_paths()->m_paths[type]; } +// static +QString DataPaths::locate(Path type, const QString &file) +{ + const QStringList dirs = allPaths(type); + for (const QString &dir : dirs) { + const QString fullPath = QDir(dir).absoluteFilePath(file); + if (QFileInfo::exists(fullPath)) { + return fullPath; + } + } + return QString(); +} + // static QString DataPaths::currentProfilePath() { diff --git a/src/lib/app/datapaths.h b/src/lib/app/datapaths.h index ad933ed3c..67fca2cfe 100644 --- a/src/lib/app/datapaths.h +++ b/src/lib/app/datapaths.h @@ -53,6 +53,8 @@ public: static QString path(Path type); // Returns all paths (Themes -> /usr/share/themes, ~/.config/falkon/themes) static QStringList allPaths(Path type); + // Returns full path of existing file + static QString locate(Path type, const QString &file); // Convenience function for getting CurrentProfile static QString currentProfilePath(); diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index f3c7befb1..a985e6058 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -991,16 +991,7 @@ void MainApplication::loadSettings() void MainApplication::loadTheme(const QString &name) { - QString activeThemePath; - const QStringList themePaths = DataPaths::allPaths(DataPaths::Themes); - - foreach (const QString &path, themePaths) { - const QString theme = QString("%1/%2").arg(path, name); - if (QFile::exists(theme + QLatin1String("/main.css"))) { - activeThemePath = theme; - break; - } - } + QString activeThemePath = DataPaths::locate(DataPaths::Themes, name); if (activeThemePath.isEmpty()) { qWarning() << "Cannot load theme " << name; diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index 6ebf0d5ee..39a05df6a 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -109,14 +109,8 @@ void Plugins::loadPlugins() if (QFileInfo(pluginFile).isAbsolute()) { fullPath = pluginFile; } else { - const QStringList dirs = DataPaths::allPaths(DataPaths::Plugins); - for (const QString &dir : dirs) { - fullPath = dir + QL1C('/') + pluginFile; - if (QFileInfo::exists(fullPath)) { - break; - } - } - if (!QFileInfo::exists(fullPath)) { + fullPath = DataPaths::locate(DataPaths::Plugins, pluginFile); + if (fullPath.isEmpty()) { qWarning() << "Plugin" << pluginFile << "not found"; continue; }