Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/browsers/firefox.cpp
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "firefox.h" | 21 | #include "firefox.h" | ||
22 | #include <KJob> | 22 | #include <KJob> | ||
23 | #include <QDebug> | 23 | #include <QDebug> | ||
24 | #include "bookmarksrunner_defs.h" | 24 | #include "bookmarksrunner_defs.h" | ||
25 | #include <QFile> | 25 | #include <QFile> | ||
26 | #include <QDir> | 26 | #include <QDir> | ||
27 | #include <QRegularExpression> | ||||
27 | #include <KConfigGroup> | 28 | #include <KConfigGroup> | ||
28 | #include <KSharedConfig> | 29 | #include <KSharedConfig> | ||
29 | #include "bookmarkmatch.h" | 30 | #include "bookmarkmatch.h" | ||
30 | #include "favicon.h" | 31 | #include "favicon.h" | ||
31 | #include "fetchsqlite.h" | 32 | #include "fetchsqlite.h" | ||
32 | #include "faviconfromblob.h" | 33 | #include "faviconfromblob.h" | ||
33 | 34 | | |||
34 | Firefox::Firefox(QObject *parent) : | 35 | Firefox::Firefox(QObject *parent) : | ||
35 | QObject(parent), | 36 | QObject(parent), | ||
36 | m_favicon(new FallbackFavicon(this)), | 37 | m_favicon(new FallbackFavicon(this)), | ||
37 | m_fetchsqlite(nullptr), | 38 | m_fetchsqlite(nullptr), | ||
38 | m_fetchsqlite_fav(nullptr) | 39 | m_fetchsqlite_fav(nullptr) | ||
39 | { | 40 | { | ||
40 | reloadConfiguration(); | 41 | reloadConfiguration(); | ||
41 | //qDebug() << "Loading Firefox Bookmarks Browser"; | 42 | //qDebug() << "Loading Firefox Bookmarks Browser"; | ||
42 | } | 43 | } | ||
43 | 44 | | |||
44 | | ||||
45 | Firefox::~Firefox() | 45 | Firefox::~Firefox() | ||
46 | { | 46 | { | ||
47 | if (!m_dbCacheFile.isEmpty()) { | 47 | if (!m_dbCacheFile.isEmpty()) { | ||
48 | QFile db_CacheFile(m_dbCacheFile); | 48 | QFile db_CacheFile(m_dbCacheFile); | ||
49 | if (db_CacheFile.exists()) { | 49 | if (db_CacheFile.exists()) { | ||
50 | //qDebug() << "Cache file was removed: " << db_CacheFile.remove(); | 50 | //qDebug() << "Cache file was removed: " << db_CacheFile.remove(); | ||
51 | } | 51 | } | ||
52 | } | 52 | } | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 155 | if(m_fetchsqlite_fav) { | |||
156 | m_fetchsqlite_fav->teardown(); | 156 | m_fetchsqlite_fav->teardown(); | ||
157 | delete m_fetchsqlite_fav; | 157 | delete m_fetchsqlite_fav; | ||
158 | m_fetchsqlite_fav = nullptr; | 158 | m_fetchsqlite_fav = nullptr; | ||
159 | delete m_favicon; | 159 | delete m_favicon; | ||
160 | m_favicon = nullptr; | 160 | m_favicon = nullptr; | ||
161 | } | 161 | } | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | | ||||
165 | | ||||
166 | void Firefox::reloadConfiguration() | 164 | void Firefox::reloadConfiguration() | ||
167 | { | 165 | { | ||
168 | KConfigGroup config(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("General") ); | 166 | if (!QSqlDatabase::isDriverAvailable(QStringLiteral("QSQLITE"))) { | ||
169 | if (QSqlDatabase::isDriverAvailable(QStringLiteral("QSQLITE"))) { | 167 | return; | ||
170 | KConfigGroup grp = config; | 168 | } | ||
171 | /* This allows the user to specify a profile database */ | 169 | | ||
172 | m_dbFile = grp.readEntry<QString>("dbfile", QLatin1String("")); | | |||
173 | if (m_dbFile.isEmpty() || !QFile::exists(m_dbFile)) { | | |||
174 | //Try to get the right database file, the default profile is used | 170 | // Try to get the right database file, the default profile is used | ||
175 | KConfig firefoxProfile(QDir::homePath() + "/.mozilla/firefox/profiles.ini", | 171 | KConfig firefoxProfile(QDir::homePath() + "/.mozilla/firefox/profiles.ini", KConfig::SimpleConfig); | ||
176 | KConfig::SimpleConfig); | | |||
177 | QStringList profilesList = firefoxProfile.groupList(); | 172 | QStringList profilesList = firefoxProfile.groupList(); | ||
178 | profilesList = profilesList.filter(QRegExp(QStringLiteral("^Profile\\d+$"))); | 173 | profilesList = profilesList.filter(QRegularExpression(QStringLiteral("^Profile\\d+$"))); | ||
179 | int size = profilesList.size(); | 174 | const int size = profilesList.size(); | ||
180 | 175 | | |||
181 | QString profilePath; | 176 | QString profilePath; | ||
182 | if (size == 1) { | 177 | if (size == 1) { | ||
183 | // There is only 1 profile so we select it | 178 | // There is only 1 profile so we select it | ||
184 | KConfigGroup fGrp = firefoxProfile.group(profilesList.first()); | 179 | KConfigGroup fGrp = firefoxProfile.group(profilesList.first()); | ||
185 | profilePath = fGrp.readEntry("Path", ""); | 180 | profilePath = fGrp.readEntry("Path"); | ||
186 | } else { | 181 | } else { | ||
187 | // There are multiple profiles, find the default one | 182 | // When profiles get edited the default profile might be in the Install.* group | ||
188 | foreach(const QString & profileName, profilesList) { | 183 | const QStringList installConfig = firefoxProfile.groupList().filter(QRegularExpression("Install.*")); | ||
184 | if (installConfig.size() == 1) { | ||||
185 | profilePath = firefoxProfile.group(installConfig.first()).readEntry("Default"); | ||||
186 | } else { | ||||
187 | // Check the other entries individually | ||||
188 | for (const QString &profileName: qAsConst(profilesList)) { | ||||
189 | KConfigGroup fGrp = firefoxProfile.group(profileName); | 189 | KConfigGroup fGrp = firefoxProfile.group(profileName); | ||
190 | if (fGrp.readEntry<int>("Default", 0)) { | 190 | if (fGrp.readEntry<int>("Default", 0)) { | ||
191 | profilePath = fGrp.readEntry("Path", ""); | 191 | profilePath = fGrp.readEntry("Path"); | ||
192 | break; | 192 | break; | ||
193 | } | 193 | } | ||
194 | } | 194 | } | ||
195 | } | 195 | } | ||
196 | | ||||
197 | if (profilePath.isEmpty()) { | | |||
198 | //qDebug() << "No default firefox profile found"; | | |||
199 | return; | | |||
200 | } | 196 | } | ||
201 | //qDebug() << "Profile " << profilePath << " found"; | 197 | | ||
198 | if (!profilePath.isEmpty()) { | ||||
202 | profilePath.prepend(QStringLiteral("%1/.mozilla/firefox/").arg(QDir::homePath())); | 199 | profilePath.prepend(QStringLiteral("%1/.mozilla/firefox/").arg(QDir::homePath())); | ||
203 | m_dbFile = profilePath + "/places.sqlite"; | 200 | m_dbFile = profilePath + "/places.sqlite"; | ||
204 | grp.writeEntry("dbfile", m_dbFile); | | |||
205 | m_dbFile_fav = profilePath + "/favicons.sqlite"; | | |||
206 | } else { | | |||
207 | auto dir = QDir(m_dbFile); | | |||
208 | if (dir.cdUp()) { | | |||
209 | QString profilePath = dir.absolutePath(); | | |||
210 | m_dbFile_fav = profilePath + "/favicons.sqlite"; | 201 | m_dbFile_fav = profilePath + "/favicons.sqlite"; | ||
211 | } | 202 | } | ||
212 | } | 203 | } | ||
213 | } else { | | |||
214 | //qDebug() << "SQLITE driver isn't available"; | | |||
215 | } | | |||
216 | } | |