diff options
author | matgic78 <matgic78@gmail.com> | 2009-12-17 18:22:23 +0100 |
---|---|---|
committer | matgic78 <matgic78@gmail.com> | 2010-02-06 11:22:46 +0100 |
commit | 8343d45f3dfd631a3f5ac4213918f285930eb446 (patch) | |
tree | 8ec95f3f7b2c97ca6bf02ae70d8654011b72a99a /src/rekonqpage | |
parent | QPointers --> QWeakPointers (diff) | |
download | rekonq-8343d45f3dfd631a3f5ac4213918f285930eb446.tar.xz |
Re-implemented previews in homepage without using plugins. Not finished yet :
Little things that change:
-nice buttons appearing on hover
-transitions on hover
TODO:
-when a preview is empty or when loading, it is very ugly
-for now there's no way to choose the page you want to preview
-port "closed Tabs" to this new architecture
-totally remove PreviewImage classes
-eventually, specific contextmenu for previews
Diffstat (limited to 'src/rekonqpage')
-rw-r--r-- | src/rekonqpage/newtabpage.cpp | 155 | ||||
-rw-r--r-- | src/rekonqpage/newtabpage.h | 19 |
2 files changed, 140 insertions, 34 deletions
diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp index 66f74b86..4299c8bb 100644 --- a/src/rekonqpage/newtabpage.cpp +++ b/src/rekonqpage/newtabpage.cpp @@ -46,6 +46,7 @@ // Qt Includes #include <QFile> +#include <websnap.h> NewTabPage::NewTabPage(QWebFrame *frame) @@ -72,6 +73,16 @@ NewTabPage::~NewTabPage() void NewTabPage::generate(const KUrl &url) { + if(KUrl("about:preview").isParentOf(url)) + { + if(url.directory() == QString("preview/remove")) + { + removePreview(url.fileName().toInt()); + return; + } + } + + QWebPage *page = m_root.webFrame()->page(); page->mainFrame()->setHtml(m_html); @@ -80,26 +91,26 @@ void NewTabPage::generate(const KUrl &url) browsingMenu(url); QString title; - if(url == KUrl("about:closedTabs")) + if(url == KUrl("about:home") || url == KUrl("about:favorites")) + { + favoritesPage(); + title = i18n("Favorites"); + } + else if(url == KUrl("about:closedTabs")) { closedTabsPage(); title = i18n("Closed Tabs"); } - if(url == KUrl("about:history")) + else if(url == KUrl("about:history")) { historyPage(); title = i18n("History"); } - if(url == KUrl("about:bookmarks")) + else if(url == KUrl("about:bookmarks")) { bookmarksPage(); title = i18n("Bookmarks"); } - if(url == KUrl("about:home") || url == KUrl("about:favorites")) - { - favoritesPage(); - title = i18n("Favorites"); - } m_root.document().findFirst("title").setPlainText(title); } @@ -114,34 +125,111 @@ void NewTabPage::favoritesPage() for(int i=0; i<8; ++i) { - QWebElement speed = markup(".thumbnail"); - speed.findFirst("object").setAttribute("data" , urls.at(i)); - speed.findFirst("param[name=title]").setAttribute("value", names.at(i)); - speed.findFirst("param[name=index]").setAttribute("value", QString::number(i)); - speed.findFirst("param[name=isFavorite]").setAttribute("value", "true"); + QWebElement speed; + + if(urls.at(i).isEmpty()) + speed = emptyPreview(); + else if(!QFile::exists(WebSnap::fileForUrl(urls.at(i)).toLocalFile())) + speed = loadingPreview(i, urls.at(i)); + else + speed = validPreview(i, urls.at(i), names.at(i)); + + speed.setAttribute("id", "preview" + QVariant(i).toString()); m_root.appendInside(speed); } } -// FIXME : port to new PreviewImage API to use... -/*QString NewTabPage::lastVisitedPage() +QWebElement NewTabPage::emptyPreview() { - QString last; - QList<HistoryItem> history = Application::historyManager()->history(); - for (int i = 0; i < 8 && i < history.size(); ++i) - { - HistoryItem it = history.at(i); - last += "<div class=\"thumbnail\">"; - last += "<object type=\"application/image-preview\" data=\"" + it.url + "\" >"; - last += "</object>"; - last += "<br />"; - last += "<a href=\"" + it.url + "\">" + it.title + "</a></div>"; - } + QWebElement prev = markup(".thumbnail"); + + prev.findFirst("img").setAttribute("src" , QString("file:///") + + KIconLoader::global()->iconPath("insert-image", KIconLoader::Desktop)); + prev.findFirst("span").appendInside(i18n("Set a Preview...")); + + return prev; +} + + +QWebElement NewTabPage::loadingPreview(int index, KUrl url) +{ + QWebElement prev = markup(".thumbnail"); + + prev.findFirst("img").setAttribute("src" , + QString("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); + prev.findFirst("span").appendInside(i18n("Loading Preview...")); + WebSnap *snap = new WebSnap(url); + snap->SetData(QVariant(index)); + connect(snap, SIGNAL(finished()), SLOT(snapFinished())); + + return prev; +} + +QWebElement NewTabPage::validPreview(int index, KUrl url, QString title) +{ + QWebElement prev = markup(".thumbnail"); + KUrl previewPath = WebSnap::fileForUrl(url); + QString iString = QVariant(index).toString(); + + prev.findFirst(".preview").setAttribute("src" , previewPath.toMimeDataString()); + prev.findFirst("a").setAttribute("href", url.toMimeDataString()); + prev.findFirst("span > a").setAttribute("href", url.toMimeDataString()); + prev.findFirst("span").appendInside(checkTitle(title)); + + prev.findFirst(".modify img").setAttribute("src", QString("file:///") + + KIconLoader::global()->iconPath("insert-image", KIconLoader::DefaultState)); + prev.findFirst(".modify").setAttribute("href", QString("about:preview/modify/" + iString )); + + prev.findFirst(".remove img").setAttribute("src", QString("file:///") + + KIconLoader::global()->iconPath("edit-delete", KIconLoader::DefaultState)); + prev.findFirst(".remove").setAttribute("href", QString("about:preview/remove/" + iString )); + + return prev; +} - return last; -}*/ +void NewTabPage::snapFinished() +{ + WebSnap *snap = qobject_cast<WebSnap*>(sender()); + QWebElement thumb = m_root.findFirst("#preview" + snap->data().toString()); + thumb.findFirst("img").setAttribute("src", WebSnap::fileForUrl(snap->snapUrl()).toMimeDataString()); + thumb.findFirst("p").setPlainText(snap->snapTitle()); + + // Save the new config + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); + + // stripTrailingSlash to be sure to get the same string for same address + urls.replace(snap->data().toInt(), snap->snapUrl().toString(QUrl::StripTrailingSlash)); + names.replace(snap->data().toInt() , snap->snapTitle()); + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + + ReKonfig::self()->writeConfig(); +} + + +void NewTabPage::removePreview(int index) +{ + QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); + + + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); + + urls.replace(index, QString("")); + names.replace(index, QString("")); + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + + // sync file data + ReKonfig::self()->writeConfig(); + + prev.replace(emptyPreview()); +} void NewTabPage::browsingMenu(const KUrl ¤tUrl) @@ -278,3 +366,14 @@ void NewTabPage::closedTabsPage() m_root.appendInside(closed); } } + + +QString NewTabPage::checkTitle(QString title) +{ + if(title.length() > 23) + { + title.truncate(20); + title += "..."; + } + return title; +} diff --git a/src/rekonqpage/newtabpage.h b/src/rekonqpage/newtabpage.h index 003aa84e..84880a10 100644 --- a/src/rekonqpage/newtabpage.h +++ b/src/rekonqpage/newtabpage.h @@ -28,9 +28,6 @@ #define REKONQ_NEW_TAB_PAGE -// rekonq Includes -#include <webpage.h> - // KDE Includes #include <KUrl> @@ -41,11 +38,12 @@ // Forward Includes class KBookmark; +class WebPage; -class NewTabPage +class NewTabPage : public QObject { - +Q_OBJECT public: NewTabPage(QWebFrame *frame); ~NewTabPage(); @@ -56,12 +54,19 @@ public: * new tab page */ void generate(const KUrl &url = KUrl("about:home")); + +protected slots: + void snapFinished(); + void removePreview(int index); protected: // these are the function to build the new tab page void browsingMenu(const KUrl ¤tUrl); void favoritesPage(); - //QString lastVisitedPage(); + QWebElement emptyPreview(); + QWebElement loadingPreview(int index, KUrl url); + QWebElement validPreview(int index, KUrl url, QString title); + void historyPage(); void bookmarksPage(); void closedTabsPage(); @@ -77,6 +82,8 @@ private: { return m_root.document().findFirst("#models > " + selector).clone(); } + + QString checkTitle(QString title); QString m_html; |