mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
plasma: drop firefox bookmarks support, fetch icons via KDED module
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
54fdd9aef4
commit
2557dbff56
20 changed files with 41 additions and 609 deletions
|
@ -3,12 +3,9 @@
|
|||
set(krunner_bookmarksrunner_SRCS
|
||||
browserfactory.cpp
|
||||
bookmarkmatch.cpp
|
||||
faviconfromblob.cpp
|
||||
favicon.cpp
|
||||
fetchsqlite.cpp
|
||||
bookmarksrunner.cpp
|
||||
browsers/kdebrowser.cpp
|
||||
browsers/firefox.cpp
|
||||
browsers/chromefindprofile.cpp
|
||||
browsers/chrome.cpp
|
||||
)
|
||||
|
@ -18,7 +15,7 @@ target_link_libraries(krunner_bookmarksrunner
|
|||
${KDE4_KIO_LIBS}
|
||||
${KDE4_PLASMA_LIBS}
|
||||
${QT_QTSCRIPT_LIBRARY}
|
||||
${QT_QTSQL_LIBRARY}
|
||||
${QT_QTDBUS_LIBRARY}
|
||||
)
|
||||
|
||||
install(TARGETS krunner_bookmarksrunner DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} )
|
||||
|
|
|
@ -30,7 +30,7 @@ class Browser;
|
|||
class BrowserFactory;
|
||||
class KJob;
|
||||
|
||||
/** This runner searchs for bookmarks in browsers like Konqueror, Firefox and Chromium */
|
||||
/** This runner searchs for bookmarks in browsers like Konqueror and Chromium */
|
||||
class BookmarksRunner : public Plasma::AbstractRunner
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#ifndef BROWSER_H
|
||||
#define BROWSER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include "bookmarkmatch.h"
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "browserfactory.h"
|
||||
#include "browser.h"
|
||||
#include "browsers/kdebrowser.h"
|
||||
#include "browsers/firefox.h"
|
||||
#include "browsers/chromefindprofile.h"
|
||||
#include "browsers/chrome.h"
|
||||
|
||||
|
@ -32,9 +31,7 @@ Browser *BrowserFactory::find(const QString& browserName, QObject* parent)
|
|||
}
|
||||
delete m_previousBrowser;
|
||||
m_previousBrowserName = browserName;
|
||||
if (browserName.contains("firefox", Qt::CaseInsensitive) || browserName.contains("iceweasel", Qt::CaseInsensitive)) {
|
||||
m_previousBrowser = new Firefox(parent);
|
||||
} else if (browserName.contains("chrome", Qt::CaseInsensitive)) {
|
||||
if (browserName.contains("chrome", Qt::CaseInsensitive)) {
|
||||
m_previousBrowser = new Chrome(new FindChromeProfile("google-chrome", QDir::homePath(), parent), parent);
|
||||
} else if (browserName.contains("chromium", Qt::CaseInsensitive)) {
|
||||
m_previousBrowser = new Chrome(new FindChromeProfile("chromium", QDir::homePath(), parent), parent);
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#include <KDebug>
|
||||
|
||||
#include "chrome.h"
|
||||
#include "faviconfromblob.h"
|
||||
#include "browsers/findprofile.h"
|
||||
#include "bookmarksrunner_defs.h"
|
||||
#include "favicon.h"
|
||||
|
||||
class ProfileBookmarks {
|
||||
public:
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <QList>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
class FaviconFromBlob;
|
||||
class ProfileBookmarks;
|
||||
class Chrome : public QObject, public Browser
|
||||
{
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
|
||||
#include "chromefindprofile.h"
|
||||
#include "bookmarksrunner_defs.h"
|
||||
#include "faviconfromblob.h"
|
||||
|
||||
#include "favicon.h"
|
||||
|
||||
FindChromeProfile::FindChromeProfile (const QString &applicationName, const QString &homeDirectory, QObject* parent )
|
||||
: QObject(parent), m_applicationName(applicationName), m_homeDirectory(homeDirectory)
|
||||
|
@ -59,7 +58,7 @@ QList<Profile> FindChromeProfile::find()
|
|||
foreach(QString profile, profilesConfig.keys()) {
|
||||
QString profilePath = QString("%1/%2").arg(configDirectory).arg(profile);
|
||||
QString profileBookmarksPath = QString("%1/%2").arg(profilePath).arg("Bookmarks");
|
||||
profiles << Profile(profileBookmarksPath, FaviconFromBlob::chrome(profilePath, this));
|
||||
profiles << Profile(profileBookmarksPath, new Favicon(this));
|
||||
}
|
||||
|
||||
return profiles;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QDir>
|
||||
|
||||
#include "browsers/findprofile.h"
|
||||
|
||||
class FindChromeProfile : public QObject, public FindProfile
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
#ifndef FIND_PROFILE_H
|
||||
#define FIND_PROFILE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
|
|
|
@ -1,170 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
|
||||
* Copyright 2012 Glenn Ergeerts <marco.gulino@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KSharedConfig>
|
||||
#include <KJob>
|
||||
#include <KStandardDirs>
|
||||
#include <KDebug>
|
||||
|
||||
#include "firefox.h"
|
||||
#include "bookmarksrunner_defs.h"
|
||||
#include "bookmarkmatch.h"
|
||||
#include "favicon.h"
|
||||
#include "fetchsqlite.h"
|
||||
#include "faviconfromblob.h"
|
||||
|
||||
Firefox::Firefox(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_favicon(new FallbackFavicon(this)),
|
||||
m_fetchsqlite(0)
|
||||
{
|
||||
reloadConfiguration();
|
||||
kDebug(kdbg_code) << "Loading Firefox Bookmarks Browser";
|
||||
}
|
||||
|
||||
|
||||
Firefox::~Firefox()
|
||||
{
|
||||
if (!m_dbCacheFile.isEmpty()) {
|
||||
QFile db_CacheFile(m_dbCacheFile);
|
||||
if (db_CacheFile.exists()) {
|
||||
kDebug(kdbg_code) << "Cache file was removed: " << db_CacheFile.remove();
|
||||
}
|
||||
}
|
||||
kDebug(kdbg_code) << "Deleted Firefox Bookmarks Browser";
|
||||
}
|
||||
|
||||
void Firefox::prepare()
|
||||
{
|
||||
if (m_dbCacheFile.isEmpty()) {
|
||||
m_dbCacheFile = KStandardDirs::locateLocal("cache", "") + "bookmarkrunnerfirefoxdbfile.sqlite";
|
||||
}
|
||||
if (!m_dbFile.isEmpty()) {
|
||||
m_fetchsqlite = new FetchSqlite(m_dbFile, m_dbCacheFile);
|
||||
m_fetchsqlite->prepare();
|
||||
|
||||
delete m_favicon;
|
||||
m_favicon = 0;
|
||||
|
||||
m_favicon = FaviconFromBlob::firefox(m_fetchsqlite, this);
|
||||
}
|
||||
}
|
||||
|
||||
QList< BookmarkMatch > Firefox::match(const QString& term, bool addEverything)
|
||||
{
|
||||
QList< BookmarkMatch > matches;
|
||||
if (!m_fetchsqlite) {
|
||||
return matches;
|
||||
}
|
||||
kDebug(kdbg_code) << "Firefox bookmark: match " << term;
|
||||
|
||||
QString tmpTerm = term;
|
||||
QString query;
|
||||
if (addEverything) {
|
||||
query = QString("SELECT moz_bookmarks.fk, moz_bookmarks.title, moz_places.url," \
|
||||
"moz_places.favicon_id FROM moz_bookmarks, moz_places WHERE " \
|
||||
"moz_bookmarks.type = 1 AND moz_bookmarks.fk = moz_places.id");
|
||||
} else {
|
||||
const QString escapedTerm = tmpTerm.replace('\'', "\\'");
|
||||
query = QString("SELECT moz_bookmarks.fk, moz_bookmarks.title, moz_places.url," \
|
||||
"moz_places.favicon_id FROM moz_bookmarks, moz_places WHERE " \
|
||||
"moz_bookmarks.type = 1 AND moz_bookmarks.fk = moz_places.id AND " \
|
||||
"(moz_bookmarks.title LIKE '%" + escapedTerm + "%' or moz_places.url LIKE '%"
|
||||
+ escapedTerm + "%')");
|
||||
}
|
||||
QList<QVariantMap> results = m_fetchsqlite->query(query, QMap<QString, QVariant>());
|
||||
foreach(QVariantMap result, results) {
|
||||
const QString title = result.value("title").toString();
|
||||
const QUrl url = result.value("url").toUrl();
|
||||
if (url.scheme().contains("place")) {
|
||||
//Don't use bookmarks with empty title, url or Firefox intern url
|
||||
kDebug(kdbg_code) << "element " << url << " was not added";
|
||||
continue;
|
||||
}
|
||||
|
||||
BookmarkMatch bookmarkMatch( m_favicon, term, title, url.toString());
|
||||
bookmarkMatch.addTo(matches, addEverything);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
|
||||
void Firefox::teardown()
|
||||
{
|
||||
if(m_fetchsqlite) {
|
||||
m_fetchsqlite->teardown();
|
||||
delete m_favicon;
|
||||
m_favicon = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Firefox::reloadConfiguration()
|
||||
{
|
||||
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), QLatin1String("General") );
|
||||
if (QSqlDatabase::isDriverAvailable("QSQLITE")) {
|
||||
KConfigGroup grp = config;
|
||||
/* This allows the user to specify a profile database */
|
||||
m_dbFile = grp.readEntry<QString>("dbfile", "");
|
||||
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("^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<int>("Default", 0)) {
|
||||
profilePath = fGrp.readEntry("Path", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (profilePath.isEmpty()) {
|
||||
kDebug(kdbg_code) << "No default firefox profile found";
|
||||
return;
|
||||
}
|
||||
kDebug(kdbg_code) << "Profile " << profilePath << " found";
|
||||
profilePath.prepend(QString("%1/.mozilla/firefox/").arg(QDir::homePath()));
|
||||
m_dbFile = profilePath + "/places.sqlite";
|
||||
grp.writeEntry("dbfile", m_dbFile);
|
||||
}
|
||||
} else {
|
||||
kDebug(kdbg_code) << "SQLITE driver isn't available";
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
|
||||
* Copyright 2012 Glenn Ergeerts <marco.gulino@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef FIREFOX_H
|
||||
#define FIREFOX_H
|
||||
|
||||
#include "browser.h"
|
||||
|
||||
class KJob;
|
||||
class Favicon;
|
||||
class FetchSqlite;
|
||||
class Firefox : public QObject, public Browser
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Firefox(QObject *parent = 0);
|
||||
virtual ~Firefox();
|
||||
virtual QList<BookmarkMatch> match(const QString& term, bool addEverything);
|
||||
public slots:
|
||||
virtual void teardown();
|
||||
virtual void prepare();
|
||||
private:
|
||||
virtual void reloadConfiguration();
|
||||
QString m_dbFile;
|
||||
QString m_dbCacheFile;
|
||||
Favicon * m_favicon;
|
||||
FetchSqlite *m_fetchsqlite;
|
||||
};
|
||||
|
||||
#endif // FIREFOX_H
|
|
@ -18,30 +18,18 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kdebrowser.h"
|
||||
#include <KBookmarkManager>
|
||||
#include <QStack>
|
||||
#include <QIcon>
|
||||
#include "bookmarkmatch.h"
|
||||
#include <KUrl>
|
||||
#include <KMimeType>
|
||||
|
||||
#include "kdebrowser.h"
|
||||
#include "bookmarkmatch.h"
|
||||
#include "favicon.h"
|
||||
|
||||
|
||||
QIcon KDEFavicon::iconFor(const QString &url) {
|
||||
const QString iconFile = KMimeType::favIconForUrl(KUrl(url));
|
||||
if (iconFile.isEmpty()) {
|
||||
return defaultIcon();
|
||||
}
|
||||
return KIcon(iconFile);
|
||||
}
|
||||
|
||||
|
||||
KDEFavicon::KDEFavicon(QObject *parent) : Favicon(parent) {}
|
||||
|
||||
|
||||
KDEBrowser::KDEBrowser(QObject *parent) :
|
||||
QObject(parent), m_bookmarkManager(KBookmarkManager::userBookmarksManager()), m_favicon(new KDEFavicon(this))
|
||||
QObject(parent), m_bookmarkManager(KBookmarkManager::userBookmarksManager()), m_favicon(new Favicon(this))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,16 +23,8 @@
|
|||
|
||||
#include "browser.h"
|
||||
#include "favicon.h"
|
||||
|
||||
class KBookmarkManager;
|
||||
class Favicon;
|
||||
|
||||
class KDEFavicon : public Favicon {
|
||||
Q_OBJECT
|
||||
public:
|
||||
KDEFavicon(QObject *parent = 0);
|
||||
virtual QIcon iconFor(const QString &url);
|
||||
|
||||
};
|
||||
|
||||
class KDEBrowser : public QObject, public Browser
|
||||
{
|
||||
|
|
|
@ -18,9 +18,33 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <QDBusReply>
|
||||
#include <QDBusInterface>
|
||||
#include <KMimeType>
|
||||
|
||||
#include "favicon.h"
|
||||
|
||||
Favicon::Favicon(QObject *parent) :
|
||||
QObject(parent), m_default_icon(KIcon("bookmarks"))
|
||||
{
|
||||
}
|
||||
|
||||
QIcon Favicon::iconFor(const QString &url) {
|
||||
const KUrl kurl(url);
|
||||
QString iconFile = KMimeType::favIconForUrl(kurl);
|
||||
if (iconFile.isEmpty()) {
|
||||
QDBusInterface kded(QString::fromLatin1("org.kde.kded"),
|
||||
QString::fromLatin1("/modules/favicons"),
|
||||
QString::fromLatin1("org.kde.FavIcon"));
|
||||
const QDBusReply<void> reply = kded.call(QString::fromLatin1("downloadHostIcon"), url );
|
||||
if (reply.isValid()) {
|
||||
iconFile = KMimeType::favIconForUrl(kurl);
|
||||
}
|
||||
if (iconFile.isEmpty()) {
|
||||
return defaultIcon();
|
||||
}
|
||||
}
|
||||
return KIcon(iconFile);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class Favicon : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit Favicon(QObject *parent = 0);
|
||||
virtual QIcon iconFor(const QString &url) = 0;
|
||||
QIcon iconFor(const QString &url);
|
||||
|
||||
protected:
|
||||
inline KIcon defaultIcon() const { return m_default_icon; }
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
|
||||
* Copyright 2012 Glenn Ergeerts <marco.gulino@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "faviconfromblob.h"
|
||||
|
||||
#include <KDebug>
|
||||
#include <QPixmap>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <KStandardDirs>
|
||||
#include <QPainter>
|
||||
#include <QDir>
|
||||
#include "bookmarksrunner_defs.h"
|
||||
#include "fetchsqlite.h"
|
||||
|
||||
#include <QSqlDatabase>
|
||||
|
||||
#define dbFileName m_profileCacheDirectory + QDir::separator() + "Favicons.sqlite"
|
||||
|
||||
|
||||
class StaticQuery : public BuildQuery {
|
||||
public:
|
||||
StaticQuery(const QString &query) : m_query(query) {}
|
||||
virtual QString query(QSqlDatabase *database) const {
|
||||
Q_UNUSED(database);
|
||||
return m_query;
|
||||
}
|
||||
private:
|
||||
const QString m_query;
|
||||
};
|
||||
|
||||
class ChromeQuery : public BuildQuery {
|
||||
public:
|
||||
ChromeQuery() {}
|
||||
virtual QString query(QSqlDatabase *database) const {
|
||||
kDebug(kdbg_code) << "tables: " << database->tables();
|
||||
if(database->tables().contains("favicon_bitmaps")) {
|
||||
return "SELECT * FROM favicons " \
|
||||
"inner join icon_mapping on icon_mapping.icon_id = favicons.id " \
|
||||
"inner join favicon_bitmaps on icon_mapping.icon_id = favicon_bitmaps.icon_id " \
|
||||
"WHERE page_url = :url ORDER BY height desc LIMIT 1;";
|
||||
}
|
||||
return "SELECT * FROM favicons inner join icon_mapping " \
|
||||
"on icon_mapping.icon_id = favicons.id " \
|
||||
"WHERE page_url = :url LIMIT 1;";
|
||||
}
|
||||
};
|
||||
|
||||
FaviconFromBlob *FaviconFromBlob::chrome(const QString &profileDirectory, QObject *parent)
|
||||
{
|
||||
QString profileName = QFileInfo(profileDirectory).fileName();
|
||||
QString faviconCache = QString("%1/KRunner-Chrome-Favicons-%2.sqlite")
|
||||
.arg(KStandardDirs::locateLocal("cache", ""))
|
||||
.arg(profileName);
|
||||
FetchSqlite *fetchSqlite = new FetchSqlite(profileDirectory + "/Favicons", faviconCache, parent);
|
||||
return new FaviconFromBlob(profileName, new ChromeQuery(), "image_data", fetchSqlite, parent);
|
||||
}
|
||||
|
||||
FaviconFromBlob *FaviconFromBlob::firefox(FetchSqlite *fetchSqlite, QObject *parent)
|
||||
{
|
||||
|
||||
QString faviconQuery = QString("SELECT moz_favicons.data FROM moz_favicons" \
|
||||
" inner join moz_places ON moz_places.favicon_id = moz_favicons.id" \
|
||||
" WHERE moz_places.url = :url LIMIT 1;");
|
||||
return new FaviconFromBlob("firefox-default", new StaticQuery(faviconQuery), "data", fetchSqlite, parent);
|
||||
}
|
||||
|
||||
|
||||
FaviconFromBlob::FaviconFromBlob(const QString &profileName, BuildQuery *buildQuery, const QString &blobColumn, FetchSqlite *fetchSqlite, QObject *parent)
|
||||
: Favicon(parent), m_buildQuery(buildQuery), m_blobcolumn(blobColumn), m_fetchsqlite(fetchSqlite)
|
||||
{
|
||||
m_profileCacheDirectory = QString("%1/KRunner-Favicons-%2")
|
||||
.arg(KStandardDirs::locateLocal("cache", ""))
|
||||
.arg(profileName);
|
||||
kDebug(kdbg_code) << "got cache directory: " << m_profileCacheDirectory;
|
||||
cleanCacheDirectory();
|
||||
QDir().mkpath(m_profileCacheDirectory);
|
||||
}
|
||||
|
||||
FaviconFromBlob::~FaviconFromBlob()
|
||||
{
|
||||
cleanCacheDirectory();
|
||||
delete m_buildQuery;
|
||||
}
|
||||
|
||||
void FaviconFromBlob::prepare()
|
||||
{
|
||||
m_fetchsqlite->prepare();
|
||||
}
|
||||
|
||||
void FaviconFromBlob::teardown()
|
||||
{
|
||||
m_fetchsqlite->teardown();
|
||||
}
|
||||
|
||||
void FaviconFromBlob::cleanCacheDirectory()
|
||||
{
|
||||
foreach(QFileInfo file, QDir(m_profileCacheDirectory).entryInfoList(QDir::NoDotAndDotDot)) {
|
||||
kDebug(kdbg_code) << "Removing file " << file.absoluteFilePath() << ": " <<
|
||||
QFile(file.absoluteFilePath()).remove();
|
||||
}
|
||||
QDir().rmdir(m_profileCacheDirectory);
|
||||
}
|
||||
|
||||
QIcon FaviconFromBlob::iconFor(const QString &url)
|
||||
{
|
||||
kDebug(kdbg_code) << "got url: " << url;
|
||||
QString fileChecksum = QString("%1").arg(qChecksum(url.toAscii(), url.toAscii().size()));
|
||||
QFile iconFile( m_profileCacheDirectory + QDir::separator() + fileChecksum + "_favicon" );
|
||||
if(iconFile.size() == 0)
|
||||
iconFile.remove();
|
||||
if(!iconFile.exists()) {
|
||||
QMap<QString,QVariant> bindVariables;
|
||||
bindVariables.insert("url", url);
|
||||
QList<QVariantMap> faviconFound = m_fetchsqlite->query(m_buildQuery, bindVariables);
|
||||
if(faviconFound.isEmpty()) return defaultIcon();
|
||||
|
||||
QByteArray iconData = faviconFound.first().value(m_blobcolumn).toByteArray();
|
||||
kDebug(kdbg_code) << "Favicon found: " << iconData.size() << " bytes";
|
||||
if(iconData.size() <=0)
|
||||
return defaultIcon();
|
||||
|
||||
iconFile.open(QFile::WriteOnly);
|
||||
iconFile.write(iconData);
|
||||
iconFile.close();
|
||||
}
|
||||
return QIcon(iconFile.fileName());
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
|
||||
* Copyright 2012 Glenn Ergeerts <marco.gulino@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef CHROMEFAVICON_H
|
||||
#define CHROMEFAVICON_H
|
||||
|
||||
#include <QIcon>
|
||||
#include "favicon.h"
|
||||
#include "fetchsqlite.h"
|
||||
|
||||
class FaviconFromBlob : public Favicon
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static FaviconFromBlob *chrome(const QString &profileDirectory, QObject *parent = 0);
|
||||
static FaviconFromBlob *firefox(FetchSqlite *fetchSqlite, QObject *parent = 0);
|
||||
~FaviconFromBlob();
|
||||
virtual QIcon iconFor(const QString &url);
|
||||
|
||||
public slots:
|
||||
virtual void prepare();
|
||||
virtual void teardown();
|
||||
|
||||
private:
|
||||
FaviconFromBlob(const QString &profileName, BuildQuery *buildQuery, const QString &blobColumn, FetchSqlite *fetchSqlite, QObject *parent = 0);
|
||||
QString m_profileCacheDirectory;
|
||||
BuildQuery *m_buildQuery;
|
||||
QString const m_blobcolumn;
|
||||
FetchSqlite *m_fetchsqlite;
|
||||
void cleanCacheDirectory();
|
||||
};
|
||||
|
||||
#endif // CHROMEFAVICON_H
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
|
||||
* Copyright 2012 Glenn Ergeerts <marco.gulino@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "fetchsqlite.h"
|
||||
#include "bookmarksrunner_defs.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <KDebug>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
#include <QSqlRecord>
|
||||
|
||||
FetchSqlite::FetchSqlite(const QString &originalFilePath, const QString ©To, QObject *parent) :
|
||||
QObject(parent), m_databaseFile(copyTo)
|
||||
{
|
||||
m_db = QSqlDatabase::addDatabase("QSQLITE", originalFilePath);
|
||||
m_db.setHostName("localhost");
|
||||
|
||||
QFile originalFile(originalFilePath);
|
||||
QFile(copyTo).remove();
|
||||
bool couldCopy = originalFile.copy(copyTo);
|
||||
if(!couldCopy) {
|
||||
kDebug(kdbg_code) << "error copying favicon database from " << originalFile.fileName() << " to " << copyTo;
|
||||
kDebug(kdbg_code) << originalFile.errorString();
|
||||
}
|
||||
}
|
||||
|
||||
FetchSqlite::~FetchSqlite()
|
||||
{
|
||||
if(m_db.isOpen()) m_db.close();
|
||||
QFile(m_databaseFile).remove();
|
||||
}
|
||||
|
||||
void FetchSqlite::prepare()
|
||||
{
|
||||
m_db.setDatabaseName(m_databaseFile);
|
||||
bool ok = m_db.open();
|
||||
kDebug(kdbg_code) << "Sqlite Database " << m_databaseFile << " was opened: " << ok;
|
||||
if(!ok) {
|
||||
kDebug(kdbg_code) << "Error: " << m_db.lastError().text();
|
||||
}
|
||||
}
|
||||
|
||||
void FetchSqlite::teardown()
|
||||
{
|
||||
m_db.close();
|
||||
}
|
||||
|
||||
QList<QVariantMap> FetchSqlite::query(BuildQuery *buildQuery, QMap<QString, QVariant> bindObjects)
|
||||
{
|
||||
return query(buildQuery->query(&m_db), bindObjects);
|
||||
}
|
||||
|
||||
QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant> bindObjects)
|
||||
{
|
||||
kDebug(kdbg_code) << "query: " << sql;
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare(sql);
|
||||
foreach(const QString &variableName, bindObjects.keys()) {
|
||||
query.bindValue(variableName, bindObjects.value(variableName));
|
||||
kDebug(kdbg_code) << "* Bound " << variableName << " to " << query.boundValue(variableName);
|
||||
}
|
||||
|
||||
if(!query.exec()) {
|
||||
QSqlError error = m_db.lastError();
|
||||
kDebug(kdbg_code) << "query failed: " << error.text() << " (" << error.type() << ", " << error.number() << ")";
|
||||
kDebug(kdbg_code) << query.lastQuery();
|
||||
}
|
||||
|
||||
QList<QVariantMap> result;
|
||||
while(query.next()) {
|
||||
QVariantMap recordValues;
|
||||
QSqlRecord record = query.record();
|
||||
for(int field=0; field<record.count(); field++) {
|
||||
QVariant value = record.value(field);
|
||||
recordValues.insert(record.fieldName(field), value );
|
||||
}
|
||||
result << recordValues;
|
||||
}
|
||||
return result;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Glenn Ergeerts <glenn.ergeerts@telenet.be>
|
||||
* Copyright 2012 Glenn Ergeerts <marco.gulino@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef FETCHSQLITE_H
|
||||
#define FETCHSQLITE_H
|
||||
#include <QSqlDatabase>
|
||||
#include <QList>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class BuildQuery {
|
||||
public:
|
||||
virtual QString query(QSqlDatabase *database) const = 0;
|
||||
virtual ~BuildQuery() {}
|
||||
};
|
||||
|
||||
class FetchSqlite : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FetchSqlite(const QString &originalFile, const QString ©To, QObject *parent = 0);
|
||||
~FetchSqlite();
|
||||
void prepare();
|
||||
void teardown();
|
||||
QList<QVariantMap> query(const QString &sql, QMap<QString,QVariant> bindObjects);
|
||||
QList<QVariantMap> query(BuildQuery *buildQuery, QMap<QString,QVariant> bindObjects);
|
||||
|
||||
private:
|
||||
QString const m_databaseFile;
|
||||
QSqlDatabase m_db;
|
||||
};
|
||||
|
||||
#endif // FETCHSQLITE_H
|
|
@ -5,7 +5,6 @@ set( testChromeBookmarks_SRCS
|
|||
../browsers/chromefindprofile.cpp
|
||||
../bookmarkmatch.cpp
|
||||
../favicon.cpp
|
||||
../fetchsqlite.cpp
|
||||
)
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
|
@ -16,10 +15,10 @@ kde4_add_test(plasma-runner-bookmarks-TestChromeBookmarks ${testChromeBookmarks_
|
|||
|
||||
target_link_libraries(plasma-runner-bookmarks-TestChromeBookmarks
|
||||
${KDE4_KDECORE_LIBS}
|
||||
${QT_QTTEST_LIBRARY}
|
||||
${QT_QTSQL_LIBRARY}
|
||||
${KDE4_PLASMA_LIBS}
|
||||
${KDE4_KIO_LIBS}
|
||||
${QT_QTTEST_LIBRARY}
|
||||
${QT_QTDBUS_LIBRARY}
|
||||
)
|
||||
|
||||
file(COPY chrome-config-home DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
Loading…
Add table
Reference in a new issue