diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/newtabpage.cpp | 65 | ||||
-rw-r--r-- | src/thumbupdater.cpp | 81 | ||||
-rw-r--r-- | src/thumbupdater.h | 58 |
4 files changed, 143 insertions, 62 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1180ad0d..b1c9b74b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,7 @@ SET( rekonq_KDEINIT_SRCS tabpreviewpopup.cpp tabbar.cpp tabhighlighteffect.cpp + thumbupdater.cpp urlfilterproxymodel.cpp urlpanel.cpp walletbar.cpp diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index c4788d6d..0ed711bf 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -42,6 +42,7 @@ #include "mainview.h" #include "mainwindow.h" #include "previewselectorbar.h" +#include "thumbupdater.h" #include "websnap.h" #include "webpage.h" #include "webtab.h" @@ -618,76 +619,16 @@ void NewTabPage::reloadPreview(int index) QString id = QL1S("#preview") + QString::number(index); QWebElement thumb = m_root.document().findFirst(id); - // Set loading animation - thumb.findFirst(QL1S(".preview img")).setAttribute(QL1S("src"), QL1S("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); - thumb.findFirst(QL1S("span a")).setPlainText(i18n("Loading Preview...")); - QString urlString = ReKonfig::previewUrls().at(index); QString nameString = ReKonfig::previewNames().at(index); kDebug() << "URL: " << urlString; kDebug() << "NAME: " << nameString; - // Load URL - QWebFrame *frame = qobject_cast<QWebFrame *>(parent()); - WebSnap *snap = new WebSnap(KUrl(urlString), frame); + ThumbUpdater *t = new ThumbUpdater(thumb, urlString, nameString); + t->updateThumb(); } -// NOTE: comment this out WITHOUT really deleting. May be of inspiration... -// QWebElement NewTabPage::loadingPreview(int index, const KUrl &url) -// { -// QWebElement prev = markup(QL1S(".thumbnail")); -// -// prev.findFirst(QL1S(".preview img")).setAttribute(QL1S("src"), -// QL1S("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); -// prev.findFirst(QL1S("span a")).setPlainText(i18n("Loading Preview...")); -// prev.findFirst(QL1S("a")).setAttribute(QL1S("href"), url.toMimeDataString()); -// -// setupPreview(prev, index); -// showControls(prev); -// -// // NOTE: we need the page frame for two reasons -// // 1) to link to the WebPage calling the snapFinished slot -// // 2) to "auto-destroy" snaps on tab closing :) -// QWebFrame *frame = qobject_cast<QWebFrame *>(parent()); -// WebSnap *snap = new WebSnap(url, frame); -// connect(snap, SIGNAL(snapDone(bool)), frame->page(), SLOT(updateImage(bool)), Qt::UniqueConnection); -// return prev; -// } -// -// -// void NewTabPage::updateThumbs() -// { -// // Update page, but only if open -// if (m_root.document().findAll(QL1S("#rekonq-newtabpage")).count() == 0) -// return; -// if (m_root.findAll(QL1S(".favorites")).count() == 0 && m_root.findAll(QL1S(".closedTabs")).count() == 0) -// return; -// -// QStringList urls = ReKonfig::previewUrls(); -// QStringList names = ReKonfig::previewNames(); -// -// for (int i = 0; i < urls.count(); i++) -// { -// KUrl url = KUrl(urls.at(i)); -// QString title = names.at(i); -// -// if (WebSnap::existsImage(url)) -// { -// QWebElement prev = m_root.findFirst(QL1S("#preview") + QVariant(i).toString()); -// if (KUrl(prev.findFirst("a").attribute(QL1S("href"))) == url) -// { -// QWebElement newPrev = validPreview(i, url, title); -// -// if (m_root.findAll(QL1S(".closedTabs")).count() != 0) -// hideControls(newPrev); -// -// prev.replace(newPrev); -// } -// } -// } -// } - QWebElement NewTabPage::validPreview(int index, const KUrl &url, const QString &title) { diff --git a/src/thumbupdater.cpp b/src/thumbupdater.cpp new file mode 100644 index 00000000..e230b87f --- /dev/null +++ b/src/thumbupdater.cpp @@ -0,0 +1,81 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#include "thumbupdater.h" +#include "thumbupdater.moc" + +#include "application.h" +#include "iconmanager.h" +#include "websnap.h" + +#include <KLocale> +#include <KStandardDirs> + +#include <QWebFrame> + + +ThumbUpdater::ThumbUpdater(QWebElement el, const QString & urlString, const QString & nameString, QObject *parent) + : QObject(parent) + , _thumb(el) + , _url(urlString) + , _title(nameString) +{ +} + + +void ThumbUpdater::updateThumb() +{ + // Set loading animation + _thumb.findFirst(QL1S(".preview img")).setAttribute(QL1S("src"), QL1S("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); + _thumb.findFirst(QL1S("span a")).setPlainText(i18n("Loading Preview...")); + + // Load URL + QWebFrame *frame = qobject_cast<QWebFrame *>(parent()); + WebSnap *snap = new WebSnap(KUrl(_url), frame); + connect(snap, SIGNAL(snapDone(bool)), this, SLOT(updateImage(bool)), Qt::UniqueConnection); +} + + +ThumbUpdater::~ThumbUpdater() +{ + kDebug() << "bye bye"; +} + + +void ThumbUpdater::updateImage(bool ok) +{ + KUrl u(_url); + + QString previewPath = ok + ? QL1S("file://") + WebSnap::imagePathFromUrl(u) + : rApp->iconManager()->iconPathForUrl(u) + ; + + _thumb.findFirst(QL1S(".preview img")).setAttribute(QL1S("src"), previewPath); + _thumb.findFirst(QL1S("span a")).setPlainText(_title); + + this->deleteLater(); +} diff --git a/src/thumbupdater.h b/src/thumbupdater.h new file mode 100644 index 00000000..5bd858cf --- /dev/null +++ b/src/thumbupdater.h @@ -0,0 +1,58 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot com> +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#ifndef THUMB_UPDATER_H +#define THUMB_UPDATER_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Qt Includes +#include <QObject> +#include <QWebElement> + + +class REKONQ_TESTS_EXPORT ThumbUpdater : public QObject +{ + Q_OBJECT + +public: + ThumbUpdater(QWebElement el, const QString & urlString, const QString & nameString, QObject *parent = 0); + ~ThumbUpdater(); + + void updateThumb(); + +private Q_SLOTS: + void updateImage(bool); + +private: + QWebElement _thumb; + QString _url; + QString _title; +}; + +#endif // THUMB_UPDATER_H |