From ff01aab13b1f68bd1f5983117ccdfe7771d49675 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 10 May 2012 09:26:45 +0200 Subject: move left modify action in favorites to be the update one Also implement ThumbUpdater class to easily manage thumb updates BUG:291236 --- src/CMakeLists.txt | 1 + src/newtabpage.cpp | 65 ++--------------------------------------- src/thumbupdater.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/thumbupdater.h | 58 +++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 62 deletions(-) create mode 100644 src/thumbupdater.cpp create mode 100644 src/thumbupdater.h (limited to 'src') 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(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(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 +* +* +* 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 . +* +* ============================================================ */ + + +#include "thumbupdater.h" +#include "thumbupdater.moc" + +#include "application.h" +#include "iconmanager.h" +#include "websnap.h" + +#include +#include + +#include + + +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(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 +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef THUMB_UPDATER_H +#define THUMB_UPDATER_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Qt Includes +#include +#include + + +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 -- cgit v1.2.1