diff --git a/runners/bookmarks/browsers/firefox.cpp b/runners/bookmarks/browsers/firefox.cpp --- a/runners/bookmarks/browsers/firefox.cpp +++ b/runners/bookmarks/browsers/firefox.cpp @@ -24,6 +24,7 @@ #include "bookmarksrunner_defs.h" #include #include +#include #include #include #include "bookmarkmatch.h" @@ -41,7 +42,6 @@ //qDebug() << "Loading Firefox Bookmarks Browser"; } - Firefox::~Firefox() { if (!m_dbCacheFile.isEmpty()) { @@ -161,56 +161,43 @@ } } - - void Firefox::reloadConfiguration() { - KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") ); - if (QSqlDatabase::isDriverAvailable(QStringLiteral("QSQLITE"))) { - KConfigGroup grp = config; - /* This allows the user to specify a profile database */ - m_dbFile = grp.readEntry("dbfile", QLatin1String("")); - if (m_dbFile.isEmpty() || !QFile::exists(m_dbFile)) { - //Try to get the right database file, the default profile is used - KConfig firefoxProfile(QDir::homePath() + "/.mozilla/firefox/profiles.ini", - KConfig::SimpleConfig); - QStringList profilesList = firefoxProfile.groupList(); - profilesList = profilesList.filter(QRegExp(QStringLiteral("^Profile\\d+$"))); - int size = profilesList.size(); - - QString profilePath; - if (size == 1) { - // There is only 1 profile so we select it - KConfigGroup fGrp = firefoxProfile.group(profilesList.first()); - profilePath = fGrp.readEntry("Path", ""); - } else { - // There are multiple profiles, find the default one - foreach(const QString & profileName, profilesList) { - KConfigGroup fGrp = firefoxProfile.group(profileName); - if (fGrp.readEntry("Default", 0)) { - profilePath = fGrp.readEntry("Path", ""); - break; - } - } - } + if (!QSqlDatabase::isDriverAvailable(QStringLiteral("QSQLITE"))) { + return; + } - if (profilePath.isEmpty()) { - //qDebug() << "No default firefox profile found"; - return; - } - //qDebug() << "Profile " << profilePath << " found"; - profilePath.prepend(QStringLiteral("%1/.mozilla/firefox/").arg(QDir::homePath())); - m_dbFile = profilePath + "/places.sqlite"; - grp.writeEntry("dbfile", m_dbFile); - m_dbFile_fav = profilePath + "/favicons.sqlite"; + // Try to get the right database file, the default profile is used + KConfig firefoxProfile(QDir::homePath() + "/.mozilla/firefox/profiles.ini", KConfig::SimpleConfig); + QStringList profilesList = firefoxProfile.groupList(); + profilesList = profilesList.filter(QRegularExpression(QStringLiteral("^Profile\\d+$"))); + const int size = profilesList.size(); + + QString profilePath; + if (size == 1) { + // There is only 1 profile so we select it + KConfigGroup fGrp = firefoxProfile.group(profilesList.first()); + profilePath = fGrp.readEntry("Path"); + } else { + // When profiles get edited the default profile might be in the Install.* group + const QStringList installConfig = firefoxProfile.groupList().filter(QRegularExpression("Install.*")); + if (installConfig.size() == 1) { + profilePath = firefoxProfile.group(installConfig.first()).readEntry("Default"); } else { - auto dir = QDir(m_dbFile); - if (dir.cdUp()) { - QString profilePath = dir.absolutePath(); - m_dbFile_fav = profilePath + "/favicons.sqlite"; + // Check the other entries individually + for (const QString &profileName: qAsConst(profilesList)) { + KConfigGroup fGrp = firefoxProfile.group(profileName); + if (fGrp.readEntry("Default", 0)) { + profilePath = fGrp.readEntry("Path"); + break; + } } } - } else { - //qDebug() << "SQLITE driver isn't available"; + } + + if (!profilePath.isEmpty()) { + profilePath.prepend(QStringLiteral("%1/.mozilla/firefox/").arg(QDir::homePath())); + m_dbFile = profilePath + "/places.sqlite"; + m_dbFile_fav = profilePath + "/favicons.sqlite"; } }