From a9107d70e55c345339a22e1d29f5667e04c4b397 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 19 Mar 2010 15:37:27 +0100 Subject: removed unuseful rekonqpage dir (we are using just a class for it) --- src/CMakeLists.txt | 17 +- src/newtabpage.cpp | 443 ++++++++++++++++++++++++++++++++++ src/newtabpage.h | 109 +++++++++ src/previewselectorbar.cpp | 152 ++++++++++++ src/previewselectorbar.h | 66 +++++ src/rekonqpage/newtabpage.cpp | 443 ---------------------------------- src/rekonqpage/newtabpage.h | 109 --------- src/rekonqpage/previewselectorbar.cpp | 152 ------------ src/rekonqpage/previewselectorbar.h | 66 ----- 9 files changed, 778 insertions(+), 779 deletions(-) create mode 100644 src/newtabpage.cpp create mode 100644 src/newtabpage.h create mode 100644 src/previewselectorbar.cpp create mode 100644 src/previewselectorbar.h delete mode 100644 src/rekonqpage/newtabpage.cpp delete mode 100644 src/rekonqpage/newtabpage.h delete mode 100644 src/rekonqpage/previewselectorbar.cpp delete mode 100644 src/rekonqpage/previewselectorbar.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7d0c1639..d41ebfe0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,31 +8,30 @@ ADD_SUBDIRECTORY( tests ) SET( rekonq_KDEINIT_SRCS application.cpp + clicktoflash.cpp + filterurljob.cpp findbar.cpp mainview.cpp mainwindow.cpp + networkaccessmanager.cpp + newtabpage.cpp + previewselectorbar.cpp + protocolhandler.cpp sessionmanager.cpp tabbar.cpp + walletbar.cpp + webinspectorpanel.cpp webpage.cpp webpluginfactory.cpp websnap.cpp webview.cpp webtab.cpp - clicktoflash.cpp - networkaccessmanager.cpp - webinspectorpanel.cpp - walletbar.cpp - protocolhandler.cpp - filterurljob.cpp #---------------------------------------- history/autosaver.cpp history/historymanager.cpp history/historymodels.cpp history/historypanel.cpp #---------------------------------------- - rekonqpage/newtabpage.cpp - rekonqpage/previewselectorbar.cpp - #---------------------------------------- settings/settingsdialog.cpp settings/adblockwidget.cpp settings/networkwidget.cpp diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp new file mode 100644 index 00000000..6fd5160d --- /dev/null +++ b/src/newtabpage.cpp @@ -0,0 +1,443 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009-2010 by Andrea Diamantini +* Copyright (C) 2010 by Matthieu Gicquel +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "newtabpage.h" +#include "newtabpage.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "historymodels.h" +#include "bookmarksmanager.h" +#include "application.h" +#include "mainwindow.h" +#include "mainview.h" +#include "websnap.h" +#include "previewselectorbar.h" +#include "webtab.h" + +// KDE Includes +#include +#include +#include +#include +#include +#include + +// Qt Includes +#include + + +NewTabPage::NewTabPage(QWebFrame *frame) + : m_root(frame->documentElement()) +{ + QString htmlFilePath = KStandardDirs::locate("data", "rekonq/htmls/home.html"); + QString imagesPath = QString("file://") + KGlobal::dirs()->findResourceDir("data", "rekonq/pics/bg.png") + QString("rekonq/pics"); + + QFile file(htmlFilePath); + bool isOpened = file.open(QIODevice::ReadOnly); + if (!isOpened) + { + kDebug() << "Couldn't open the home.html file"; + } + else + { + m_html = file.readAll(); + m_html.replace(QString("%2"), imagesPath); + } +} + + +NewTabPage::~NewTabPage() +{ +} + + +void NewTabPage::generate(KUrl url) +{ + if(KUrl("about:preview").isParentOf(url)) + { + if(url.directory() == QString("preview/remove")) + { + removePreview(url.fileName().toInt()); + return; + } + if(url.directory() == QString("preview/modify")) + { + int index = url.fileName().toInt(); + Application::instance()->mainWindow()->currentTab()->createPreviewSelectorBar(index); + return; + } + } + + QWebPage *page = m_root.webFrame()->page(); + page->mainFrame()->setHtml(m_html); + + m_root = page->mainFrame()->documentElement().findFirst("#content"); + + browsingMenu(url); + + QString title; + if(url == KUrl("about:favorites")) + { + favoritesPage(); + title = i18n("Favorites"); + } + else if(url == KUrl("about:closedTabs")) + { + closedTabsPage(); + title = i18n("Closed Tabs"); + } + else if(url == KUrl("about:history")) + { + historyPage(); + title = i18n("History"); + } + else if(url == KUrl("about:bookmarks")) + { + bookmarksPage(); + title = i18n("Bookmarks"); + } + + m_root.document().findFirst("title").setPlainText(title); +} + + +void NewTabPage::favoritesPage() +{ + m_root.addClass("favorites"); + + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); + + for(int i=0; i<8; ++i) + { + KUrl url = urls.at(i); + QWebElement prev; + + if(url.isEmpty()) + prev = emptyPreview(i); + else if(!QFile::exists(WebSnap::fileForUrl(url).toLocalFile())) + prev = loadingPreview(i, url); + else + prev = validPreview(i, url, names.at(i)); + + setupPreview(prev, i); + + m_root.appendInside(prev); + } +} + + +QWebElement NewTabPage::emptyPreview(int index) +{ + QWebElement prev = markup(".thumbnail"); + + prev.findFirst(".preview img").setAttribute("src" , QString("file:///") + + KIconLoader::global()->iconPath("insert-image", KIconLoader::Desktop)); + prev.findFirst("span a").setPlainText(i18n("Set a Preview...")); + prev.findFirst("a").setAttribute("href", QString("about:preview/modify/" + QVariant(index).toString())); + + setupPreview(prev, index); + hideControls(prev); + + return prev; +} + + +QWebElement NewTabPage::loadingPreview(int index, KUrl url) +{ + QWebElement prev = markup(".thumbnail"); + + prev.findFirst(".preview img").setAttribute("src" , + QString("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); + prev.findFirst("span a").setPlainText(i18n("Loading Preview...")); + prev.findFirst("a").setAttribute("href", url.toMimeDataString()); + + setupPreview(prev, index); + showControls(prev); + + new WebSnap(url, m_root.webFrame(), index); + + 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 img").setAttribute("src" , previewPath.toMimeDataString()); + prev.findFirst("a").setAttribute("href", url.toMimeDataString()); + prev.findFirst("span a").setAttribute("href", url.toMimeDataString()); + prev.findFirst("span a").setPlainText(checkTitle(title)); + + setupPreview(prev, index); + showControls(prev); + + return prev; +} + + +void NewTabPage::hideControls(QWebElement e) +{ + e.findFirst(".remove").setStyleProperty("visibility", "hidden"); + e.findFirst(".modify").setStyleProperty("visibility", "hidden"); +} + + +void NewTabPage::showControls(QWebElement e) +{ + e.findFirst(".remove").setStyleProperty("visibility", "visible"); + e.findFirst(".modify").setStyleProperty("visibility", "visible"); +} + + +void NewTabPage::setupPreview(QWebElement e, int index) +{ + e.findFirst(".remove img").setAttribute("src", QString("file:///") + + KIconLoader::global()->iconPath("edit-delete", KIconLoader::DefaultState)); + e.findFirst(".remove").setAttribute("title", "Remove favorite"); + e.findFirst(".modify img").setAttribute("src", QString("file:///") + + KIconLoader::global()->iconPath("insert-image", KIconLoader::DefaultState)); + e.findFirst(".modify").setAttribute("title", "Set new favorite"); + + e.findFirst(".modify").setAttribute("href", QString("about:preview/modify/" + QVariant(index).toString())); + e.findFirst(".remove").setAttribute("href", QString("about:preview/remove/" + QVariant(index).toString())); + + e.setAttribute("id", "preview" + QVariant(index).toString()); +} + + +void NewTabPage::snapFinished(int index, KUrl url, QString title) +{ + // do not try to modify the page if it isn't the newTabPage + if(m_root.document().findAll("#rekonq-newtabpage").count() == 0) + return; + + QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); + QWebElement newPrev = validPreview(index, url, title); + + if(m_root.findAll(".closedTabs").count() != 0) + hideControls(newPrev); + + prev.replace(newPrev); + + // update title + if(m_root.findAll(".favorites").count() != 0) + { + QStringList names = ReKonfig::previewNames(); + names.replace(index, title); + ReKonfig::setPreviewNames(names); + + ReKonfig::self()->writeConfig(); + } +} + + +void NewTabPage::removePreview(int index) +{ + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); + + urls.replace(index, QString("")); + names.replace(index, QString("")); + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + + ReKonfig::self()->writeConfig(); + + QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); + prev.replace(emptyPreview(index)); +} + + +void NewTabPage::browsingMenu(const KUrl ¤tUrl) +{ + QList navItems; + + KIconLoader *loader = KIconLoader::global(); + + QWebElement nav = markup(".link"); // Favorites + nav.findFirst("a").setAttribute("href", "about:favorites"); + nav.findFirst("img").setAttribute("src" , QString("file:///" + + loader->iconPath("emblem-favorite", KIconLoader::Desktop ||KIconLoader::SizeSmall))); + nav.findFirst("a").appendInside(i18n("Favorites")); + navItems.append(nav); + + nav = markup(".link"); // Closed Tabs + nav.findFirst("a").setAttribute("href", "about:closedTabs"); + nav.findFirst("img").setAttribute("src" , QString("file:///" + + loader->iconPath("tab-close", KIconLoader::Desktop ||KIconLoader::SizeSmall))); + nav.findFirst("a").appendInside(i18n("Closed Tabs")); + navItems.append(nav); + + nav = markup(".link"); // Bookmarks + nav.findFirst("a").setAttribute("href", "about:bookmarks"); + nav.findFirst("img").setAttribute("src" , QString("file:///" + + loader->iconPath("bookmarks", KIconLoader::Desktop ||KIconLoader::SizeSmall))); + nav.findFirst("a").appendInside(i18n("Bookmarks")); + navItems.append(nav); + + nav = markup(".link"); // History + nav.findFirst("a").setAttribute("href", "about:history"); + nav.findFirst("img").setAttribute("src" , QString("file:///" + + loader->iconPath("view-history", KIconLoader::Desktop ||KIconLoader::SizeSmall))); + nav.findFirst("a").appendInside(i18n("History")); + navItems.append(nav); + + QWebElement it; + foreach(it, navItems) + { + if(it.findFirst("a").attribute("href") == currentUrl.toMimeDataString()) + it.addClass("current"); + else if(currentUrl == "about:home" && it.findFirst("a").attribute("href") == "about:favorites") + it.addClass("current"); + m_root.document().findFirst("#navigation").appendInside(it); + } +} + + +void NewTabPage::historyPage() +{ + m_root.addClass("history"); + + HistoryTreeModel *model = Application::historyManager()->historyTreeModel(); + + int i = 0; + do + { + QModelIndex index = model->index(i, 0, QModelIndex() ); + if(model->hasChildren(index)) + { + m_root.appendInside(markup("h3")); + m_root.lastChild().setPlainText(index.data().toString()); + + for(int j=0; j< model->rowCount(index); ++j) + { + QModelIndex son = model->index(j, 0, index ); + m_root.appendInside(son.data(HistoryModel::DateTimeRole).toDateTime().toString("hh:mm")); + m_root.appendInside(" "); + m_root.appendInside(markup("a")); + m_root.lastChild().setAttribute("href" , son.data(HistoryModel::UrlStringRole).toString()); + m_root.lastChild().appendInside(son.data().toString()); + m_root.appendInside("
"); + } + } + i++; + } + while( model->hasIndex( i , 0 , QModelIndex() ) ); +} + + +void NewTabPage::bookmarksPage() +{ + m_root.addClass("bookmarks"); + + KBookmarkGroup bookGroup = Application::bookmarkProvider()->rootGroup(); + if (bookGroup.isNull()) + { + return; + } + + KBookmark bookmark = bookGroup.first(); + while (!bookmark.isNull()) + { + createBookItem(bookmark, m_root); + bookmark = bookGroup.next(bookmark); + } +} + + +void NewTabPage::createBookItem(const KBookmark &bookmark, QWebElement parent) +{ + if (bookmark.isGroup()) + { + KBookmarkGroup group = bookmark.toGroup(); + KBookmark bm = group.first(); + parent.appendInside(markup("h3")); + parent.lastChild().setPlainText(group.text()); + parent.appendInside(markup(".bookfolder")); + while (!bm.isNull()) + { + createBookItem(bm, parent.lastChild()); // it is .bookfolder + bm = group.next(bm); + } + } + else if(bookmark.isSeparator()) + { + parent.appendInside("
"); + } + else + { + parent.appendInside(markup("a")); + parent.lastChild().setAttribute("href" , bookmark.url().prettyUrl()); + parent.lastChild().setPlainText(bookmark.text()); + parent.appendInside("
"); + } +} + + +void NewTabPage::closedTabsPage() +{ + m_root.addClass("closedTabs"); + + QList links = Application::instance()->mainWindow()->mainView()->recentlyClosedTabs(); + + for(int i=0; i < links.count(); ++i) + { + HistoryItem item = links.at(i); + QWebElement prev; + + if(item.url.isEmpty()) + continue; + else if(!QFile::exists(WebSnap::fileForUrl(item.url).toLocalFile())) + prev = loadingPreview(i, item.url); + else + prev = validPreview(i, item.url, item.title); + + prev.setAttribute("id", "preview" + QVariant(i).toString()); + hideControls(prev); + m_root.appendInside(prev); + } +} + + +QString NewTabPage::checkTitle(QString title) +{ + if(title.length() > 23) + { + title.truncate(20); + title += "..."; + } + return title; +} diff --git a/src/newtabpage.h b/src/newtabpage.h new file mode 100644 index 00000000..fd04e60a --- /dev/null +++ b/src/newtabpage.h @@ -0,0 +1,109 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009-2010 by Andrea Diamantini +* Copyright (C) 2010 by Matthieu Gicquel +* +* +* 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 REKONQ_NEW_TAB_PAGE +#define REKONQ_NEW_TAB_PAGE + + +// Local Includes +#include "rekonqprivate_export.h" + +// KDE Includes +#include + +// Qt Includes +#include +#include +#include + +// Forward Includes +class KBookmark; +class WebPage; + + +class REKONQ_TESTS_EXPORT NewTabPage : public QObject +{ +Q_OBJECT + +public: + NewTabPage(QWebFrame *frame); + ~NewTabPage(); + + /** + * This method takes an about: url and loads + * the corresponding part of the new tab page + */ + void generate(KUrl url = KUrl("about:home")); + + void snapFinished(int index, KUrl url, QString title); + void removePreview(int index); + +protected: + // these are the functions to build the new tab page + void browsingMenu(const KUrl ¤tUrl); + + void favoritesPage(); + void historyPage(); + void bookmarksPage(); + void closedTabsPage(); + + // Previews handling + QWebElement emptyPreview(int index); + QWebElement loadingPreview(int index, KUrl url); + QWebElement validPreview(int index, KUrl url, QString title); + + /** This function takes a QwebElement with the .thumbnail structure, + * hiding the "remove" and "modify" buttons + * + */ + void hideControls(QWebElement e); + void showControls(QWebElement e); + void setupPreview(QWebElement e, int index); + +private: + void createBookItem(const KBookmark &bookmark, QWebElement parent); + + /** This function helps to get faster a new markup of one type, + * it isn't easy to create one with QWebElement. + * + * It gets it in the #models div of home.html. + * It works for all elements defined here. + * + */ + inline QWebElement markup(QString selector) + { + return m_root.document().findFirst("#models > " + selector).clone(); + } + + QString checkTitle(QString title); + + QString m_html; + + QWebElement m_root; +}; + +#endif // REKONQ_NEW_TAB_PAGE diff --git a/src/previewselectorbar.cpp b/src/previewselectorbar.cpp new file mode 100644 index 00000000..924a5439 --- /dev/null +++ b/src/previewselectorbar.cpp @@ -0,0 +1,152 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 by Matthieu Gicquel +* Copyright (C) 2010 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 . +* +* ============================================================ */ + + +// Auto Includes +#include "previewselectorbar.h" +#include "previewselectorbar.moc" + +// Local Include +#include "rekonq.h" +#include "websnap.h" +#include "application.h" +#include "mainwindow.h" +#include "webtab.h" + +// KDE Includes +#include +#include + +// Qt Includes +#include +#include +#include + + +PreviewSelectorBar::PreviewSelectorBar(int index, QWidget* parent) + : QWidget(parent) + , m_button(0) + , m_label(0) + , m_previewIndex(index) +{ + m_label = new QLabel(i18n("Please open up the webpage you want to add as favorite"), this); + m_label->setWordWrap(true); + + QToolButton *closeButton = new QToolButton(this); + closeButton->setAutoRaise(true); + closeButton->setIcon(KIcon("dialog-close")); + connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(destroy())); + + m_button = new QPushButton(KIcon("insert-image"), i18n("Set to This Page"), this); + m_button->setMaximumWidth(250); + connect(m_button, SIGNAL(clicked(bool)), this, SLOT(clicked())); + + // layout + QHBoxLayout *layout = new QHBoxLayout(this); + layout->addWidget(closeButton); + layout->addWidget(m_label); + layout->addWidget(m_button); + + layout->setContentsMargins(2, 0, 2, 0); + + setLayout(layout); +} + + +PreviewSelectorBar::~PreviewSelectorBar() +{ +} + + +void PreviewSelectorBar::verifyUrl() +{ + + if(Application::instance()->mainWindow()->currentTab()->page()->mainFrame()->url().scheme() != "about") + { + m_button->setEnabled(true); + m_button->setToolTip(""); + } + else + { + m_button->setEnabled(false); + m_button->setToolTip(i18n("You can not add this webpage as favorite")); + } +} + + +void PreviewSelectorBar::loadProgress() +{ + m_button->setEnabled(false); + m_button->setToolTip(i18n("Page is loading...")); +} + + +void PreviewSelectorBar::loadFinished() +{ + m_button->setEnabled(true); + m_button->setToolTip(""); + + verifyUrl(); +} + + +void PreviewSelectorBar::clicked() +{ + WebPage *page = Application::instance()->mainWindow()->currentTab()->page(); + + if(page) + { + // this is done just lo let the render process being faster.. + WebSnap::renderPreview(*page); + + KUrl url = page->mainFrame()->url(); + QStringList names = ReKonfig::previewNames(); + QStringList urls = ReKonfig::previewUrls(); + + urls.replace(m_previewIndex, url.toMimeDataString()); + names.replace(m_previewIndex, page->mainFrame()->title()); + + ReKonfig::setPreviewNames(names); + ReKonfig::setPreviewUrls(urls); + + ReKonfig::self()->writeConfig(); + + + page->mainFrame()->load(KUrl("about:favorites")); + } + + destroy(); +} + + +void PreviewSelectorBar::destroy() +{ + if (parentWidget() && parentWidget()->layout()) + { + parentWidget()->layout()->removeWidget(this); + } + this->deleteLater(); +} diff --git a/src/previewselectorbar.h b/src/previewselectorbar.h new file mode 100644 index 00000000..bb9f26c4 --- /dev/null +++ b/src/previewselectorbar.h @@ -0,0 +1,66 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010 by Matthieu Gicquel +* Copyright (C) 2010 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 PREVIEWSELECTORBAR_H +#define PREVIEWSELECTORBAR_H + +// Local Includes +#include "rekonqprivate_export.h" +#include "webpage.h" + +// Qt Includes +#include +#include +#include + + +class REKONQ_TESTS_EXPORT PreviewSelectorBar : public QWidget +{ +Q_OBJECT + +public: + PreviewSelectorBar(int index, QWidget *parent); + ~PreviewSelectorBar(); + +private slots: + void clicked(); + + void loadProgress(); + void loadFinished(); + + void verifyUrl(); + + void destroy(); + +private: + QPushButton *m_button; + QLabel *m_label; + + int m_previewIndex; +}; + +#endif // PREVIEWSELECTORBAR_H diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp deleted file mode 100644 index 6fd5160d..00000000 --- a/src/rekonqpage/newtabpage.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009-2010 by Andrea Diamantini -* Copyright (C) 2010 by Matthieu Gicquel -* -* -* 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 . -* -* ============================================================ */ - - -// Self Includes -#include "newtabpage.h" -#include "newtabpage.moc" - -// Auto Includes -#include "rekonq.h" - -// Local Includes -#include "historymodels.h" -#include "bookmarksmanager.h" -#include "application.h" -#include "mainwindow.h" -#include "mainview.h" -#include "websnap.h" -#include "previewselectorbar.h" -#include "webtab.h" - -// KDE Includes -#include -#include -#include -#include -#include -#include - -// Qt Includes -#include - - -NewTabPage::NewTabPage(QWebFrame *frame) - : m_root(frame->documentElement()) -{ - QString htmlFilePath = KStandardDirs::locate("data", "rekonq/htmls/home.html"); - QString imagesPath = QString("file://") + KGlobal::dirs()->findResourceDir("data", "rekonq/pics/bg.png") + QString("rekonq/pics"); - - QFile file(htmlFilePath); - bool isOpened = file.open(QIODevice::ReadOnly); - if (!isOpened) - { - kDebug() << "Couldn't open the home.html file"; - } - else - { - m_html = file.readAll(); - m_html.replace(QString("%2"), imagesPath); - } -} - - -NewTabPage::~NewTabPage() -{ -} - - -void NewTabPage::generate(KUrl url) -{ - if(KUrl("about:preview").isParentOf(url)) - { - if(url.directory() == QString("preview/remove")) - { - removePreview(url.fileName().toInt()); - return; - } - if(url.directory() == QString("preview/modify")) - { - int index = url.fileName().toInt(); - Application::instance()->mainWindow()->currentTab()->createPreviewSelectorBar(index); - return; - } - } - - QWebPage *page = m_root.webFrame()->page(); - page->mainFrame()->setHtml(m_html); - - m_root = page->mainFrame()->documentElement().findFirst("#content"); - - browsingMenu(url); - - QString title; - if(url == KUrl("about:favorites")) - { - favoritesPage(); - title = i18n("Favorites"); - } - else if(url == KUrl("about:closedTabs")) - { - closedTabsPage(); - title = i18n("Closed Tabs"); - } - else if(url == KUrl("about:history")) - { - historyPage(); - title = i18n("History"); - } - else if(url == KUrl("about:bookmarks")) - { - bookmarksPage(); - title = i18n("Bookmarks"); - } - - m_root.document().findFirst("title").setPlainText(title); -} - - -void NewTabPage::favoritesPage() -{ - m_root.addClass("favorites"); - - QStringList names = ReKonfig::previewNames(); - QStringList urls = ReKonfig::previewUrls(); - - for(int i=0; i<8; ++i) - { - KUrl url = urls.at(i); - QWebElement prev; - - if(url.isEmpty()) - prev = emptyPreview(i); - else if(!QFile::exists(WebSnap::fileForUrl(url).toLocalFile())) - prev = loadingPreview(i, url); - else - prev = validPreview(i, url, names.at(i)); - - setupPreview(prev, i); - - m_root.appendInside(prev); - } -} - - -QWebElement NewTabPage::emptyPreview(int index) -{ - QWebElement prev = markup(".thumbnail"); - - prev.findFirst(".preview img").setAttribute("src" , QString("file:///") + - KIconLoader::global()->iconPath("insert-image", KIconLoader::Desktop)); - prev.findFirst("span a").setPlainText(i18n("Set a Preview...")); - prev.findFirst("a").setAttribute("href", QString("about:preview/modify/" + QVariant(index).toString())); - - setupPreview(prev, index); - hideControls(prev); - - return prev; -} - - -QWebElement NewTabPage::loadingPreview(int index, KUrl url) -{ - QWebElement prev = markup(".thumbnail"); - - prev.findFirst(".preview img").setAttribute("src" , - QString("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); - prev.findFirst("span a").setPlainText(i18n("Loading Preview...")); - prev.findFirst("a").setAttribute("href", url.toMimeDataString()); - - setupPreview(prev, index); - showControls(prev); - - new WebSnap(url, m_root.webFrame(), index); - - 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 img").setAttribute("src" , previewPath.toMimeDataString()); - prev.findFirst("a").setAttribute("href", url.toMimeDataString()); - prev.findFirst("span a").setAttribute("href", url.toMimeDataString()); - prev.findFirst("span a").setPlainText(checkTitle(title)); - - setupPreview(prev, index); - showControls(prev); - - return prev; -} - - -void NewTabPage::hideControls(QWebElement e) -{ - e.findFirst(".remove").setStyleProperty("visibility", "hidden"); - e.findFirst(".modify").setStyleProperty("visibility", "hidden"); -} - - -void NewTabPage::showControls(QWebElement e) -{ - e.findFirst(".remove").setStyleProperty("visibility", "visible"); - e.findFirst(".modify").setStyleProperty("visibility", "visible"); -} - - -void NewTabPage::setupPreview(QWebElement e, int index) -{ - e.findFirst(".remove img").setAttribute("src", QString("file:///") + - KIconLoader::global()->iconPath("edit-delete", KIconLoader::DefaultState)); - e.findFirst(".remove").setAttribute("title", "Remove favorite"); - e.findFirst(".modify img").setAttribute("src", QString("file:///") + - KIconLoader::global()->iconPath("insert-image", KIconLoader::DefaultState)); - e.findFirst(".modify").setAttribute("title", "Set new favorite"); - - e.findFirst(".modify").setAttribute("href", QString("about:preview/modify/" + QVariant(index).toString())); - e.findFirst(".remove").setAttribute("href", QString("about:preview/remove/" + QVariant(index).toString())); - - e.setAttribute("id", "preview" + QVariant(index).toString()); -} - - -void NewTabPage::snapFinished(int index, KUrl url, QString title) -{ - // do not try to modify the page if it isn't the newTabPage - if(m_root.document().findAll("#rekonq-newtabpage").count() == 0) - return; - - QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); - QWebElement newPrev = validPreview(index, url, title); - - if(m_root.findAll(".closedTabs").count() != 0) - hideControls(newPrev); - - prev.replace(newPrev); - - // update title - if(m_root.findAll(".favorites").count() != 0) - { - QStringList names = ReKonfig::previewNames(); - names.replace(index, title); - ReKonfig::setPreviewNames(names); - - ReKonfig::self()->writeConfig(); - } -} - - -void NewTabPage::removePreview(int index) -{ - QStringList names = ReKonfig::previewNames(); - QStringList urls = ReKonfig::previewUrls(); - - urls.replace(index, QString("")); - names.replace(index, QString("")); - - ReKonfig::setPreviewNames(names); - ReKonfig::setPreviewUrls(urls); - - ReKonfig::self()->writeConfig(); - - QWebElement prev = m_root.findFirst("#preview" + QVariant(index).toString()); - prev.replace(emptyPreview(index)); -} - - -void NewTabPage::browsingMenu(const KUrl ¤tUrl) -{ - QList navItems; - - KIconLoader *loader = KIconLoader::global(); - - QWebElement nav = markup(".link"); // Favorites - nav.findFirst("a").setAttribute("href", "about:favorites"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("emblem-favorite", KIconLoader::Desktop ||KIconLoader::SizeSmall))); - nav.findFirst("a").appendInside(i18n("Favorites")); - navItems.append(nav); - - nav = markup(".link"); // Closed Tabs - nav.findFirst("a").setAttribute("href", "about:closedTabs"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("tab-close", KIconLoader::Desktop ||KIconLoader::SizeSmall))); - nav.findFirst("a").appendInside(i18n("Closed Tabs")); - navItems.append(nav); - - nav = markup(".link"); // Bookmarks - nav.findFirst("a").setAttribute("href", "about:bookmarks"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("bookmarks", KIconLoader::Desktop ||KIconLoader::SizeSmall))); - nav.findFirst("a").appendInside(i18n("Bookmarks")); - navItems.append(nav); - - nav = markup(".link"); // History - nav.findFirst("a").setAttribute("href", "about:history"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("view-history", KIconLoader::Desktop ||KIconLoader::SizeSmall))); - nav.findFirst("a").appendInside(i18n("History")); - navItems.append(nav); - - QWebElement it; - foreach(it, navItems) - { - if(it.findFirst("a").attribute("href") == currentUrl.toMimeDataString()) - it.addClass("current"); - else if(currentUrl == "about:home" && it.findFirst("a").attribute("href") == "about:favorites") - it.addClass("current"); - m_root.document().findFirst("#navigation").appendInside(it); - } -} - - -void NewTabPage::historyPage() -{ - m_root.addClass("history"); - - HistoryTreeModel *model = Application::historyManager()->historyTreeModel(); - - int i = 0; - do - { - QModelIndex index = model->index(i, 0, QModelIndex() ); - if(model->hasChildren(index)) - { - m_root.appendInside(markup("h3")); - m_root.lastChild().setPlainText(index.data().toString()); - - for(int j=0; j< model->rowCount(index); ++j) - { - QModelIndex son = model->index(j, 0, index ); - m_root.appendInside(son.data(HistoryModel::DateTimeRole).toDateTime().toString("hh:mm")); - m_root.appendInside(" "); - m_root.appendInside(markup("a")); - m_root.lastChild().setAttribute("href" , son.data(HistoryModel::UrlStringRole).toString()); - m_root.lastChild().appendInside(son.data().toString()); - m_root.appendInside("
"); - } - } - i++; - } - while( model->hasIndex( i , 0 , QModelIndex() ) ); -} - - -void NewTabPage::bookmarksPage() -{ - m_root.addClass("bookmarks"); - - KBookmarkGroup bookGroup = Application::bookmarkProvider()->rootGroup(); - if (bookGroup.isNull()) - { - return; - } - - KBookmark bookmark = bookGroup.first(); - while (!bookmark.isNull()) - { - createBookItem(bookmark, m_root); - bookmark = bookGroup.next(bookmark); - } -} - - -void NewTabPage::createBookItem(const KBookmark &bookmark, QWebElement parent) -{ - if (bookmark.isGroup()) - { - KBookmarkGroup group = bookmark.toGroup(); - KBookmark bm = group.first(); - parent.appendInside(markup("h3")); - parent.lastChild().setPlainText(group.text()); - parent.appendInside(markup(".bookfolder")); - while (!bm.isNull()) - { - createBookItem(bm, parent.lastChild()); // it is .bookfolder - bm = group.next(bm); - } - } - else if(bookmark.isSeparator()) - { - parent.appendInside("
"); - } - else - { - parent.appendInside(markup("a")); - parent.lastChild().setAttribute("href" , bookmark.url().prettyUrl()); - parent.lastChild().setPlainText(bookmark.text()); - parent.appendInside("
"); - } -} - - -void NewTabPage::closedTabsPage() -{ - m_root.addClass("closedTabs"); - - QList links = Application::instance()->mainWindow()->mainView()->recentlyClosedTabs(); - - for(int i=0; i < links.count(); ++i) - { - HistoryItem item = links.at(i); - QWebElement prev; - - if(item.url.isEmpty()) - continue; - else if(!QFile::exists(WebSnap::fileForUrl(item.url).toLocalFile())) - prev = loadingPreview(i, item.url); - else - prev = validPreview(i, item.url, item.title); - - prev.setAttribute("id", "preview" + QVariant(i).toString()); - hideControls(prev); - m_root.appendInside(prev); - } -} - - -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 deleted file mode 100644 index fd04e60a..00000000 --- a/src/rekonqpage/newtabpage.h +++ /dev/null @@ -1,109 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009-2010 by Andrea Diamantini -* Copyright (C) 2010 by Matthieu Gicquel -* -* -* 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 REKONQ_NEW_TAB_PAGE -#define REKONQ_NEW_TAB_PAGE - - -// Local Includes -#include "rekonqprivate_export.h" - -// KDE Includes -#include - -// Qt Includes -#include -#include -#include - -// Forward Includes -class KBookmark; -class WebPage; - - -class REKONQ_TESTS_EXPORT NewTabPage : public QObject -{ -Q_OBJECT - -public: - NewTabPage(QWebFrame *frame); - ~NewTabPage(); - - /** - * This method takes an about: url and loads - * the corresponding part of the new tab page - */ - void generate(KUrl url = KUrl("about:home")); - - void snapFinished(int index, KUrl url, QString title); - void removePreview(int index); - -protected: - // these are the functions to build the new tab page - void browsingMenu(const KUrl ¤tUrl); - - void favoritesPage(); - void historyPage(); - void bookmarksPage(); - void closedTabsPage(); - - // Previews handling - QWebElement emptyPreview(int index); - QWebElement loadingPreview(int index, KUrl url); - QWebElement validPreview(int index, KUrl url, QString title); - - /** This function takes a QwebElement with the .thumbnail structure, - * hiding the "remove" and "modify" buttons - * - */ - void hideControls(QWebElement e); - void showControls(QWebElement e); - void setupPreview(QWebElement e, int index); - -private: - void createBookItem(const KBookmark &bookmark, QWebElement parent); - - /** This function helps to get faster a new markup of one type, - * it isn't easy to create one with QWebElement. - * - * It gets it in the #models div of home.html. - * It works for all elements defined here. - * - */ - inline QWebElement markup(QString selector) - { - return m_root.document().findFirst("#models > " + selector).clone(); - } - - QString checkTitle(QString title); - - QString m_html; - - QWebElement m_root; -}; - -#endif // REKONQ_NEW_TAB_PAGE diff --git a/src/rekonqpage/previewselectorbar.cpp b/src/rekonqpage/previewselectorbar.cpp deleted file mode 100644 index 924a5439..00000000 --- a/src/rekonqpage/previewselectorbar.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010 by Matthieu Gicquel -* Copyright (C) 2010 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 . -* -* ============================================================ */ - - -// Auto Includes -#include "previewselectorbar.h" -#include "previewselectorbar.moc" - -// Local Include -#include "rekonq.h" -#include "websnap.h" -#include "application.h" -#include "mainwindow.h" -#include "webtab.h" - -// KDE Includes -#include -#include - -// Qt Includes -#include -#include -#include - - -PreviewSelectorBar::PreviewSelectorBar(int index, QWidget* parent) - : QWidget(parent) - , m_button(0) - , m_label(0) - , m_previewIndex(index) -{ - m_label = new QLabel(i18n("Please open up the webpage you want to add as favorite"), this); - m_label->setWordWrap(true); - - QToolButton *closeButton = new QToolButton(this); - closeButton->setAutoRaise(true); - closeButton->setIcon(KIcon("dialog-close")); - connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(destroy())); - - m_button = new QPushButton(KIcon("insert-image"), i18n("Set to This Page"), this); - m_button->setMaximumWidth(250); - connect(m_button, SIGNAL(clicked(bool)), this, SLOT(clicked())); - - // layout - QHBoxLayout *layout = new QHBoxLayout(this); - layout->addWidget(closeButton); - layout->addWidget(m_label); - layout->addWidget(m_button); - - layout->setContentsMargins(2, 0, 2, 0); - - setLayout(layout); -} - - -PreviewSelectorBar::~PreviewSelectorBar() -{ -} - - -void PreviewSelectorBar::verifyUrl() -{ - - if(Application::instance()->mainWindow()->currentTab()->page()->mainFrame()->url().scheme() != "about") - { - m_button->setEnabled(true); - m_button->setToolTip(""); - } - else - { - m_button->setEnabled(false); - m_button->setToolTip(i18n("You can not add this webpage as favorite")); - } -} - - -void PreviewSelectorBar::loadProgress() -{ - m_button->setEnabled(false); - m_button->setToolTip(i18n("Page is loading...")); -} - - -void PreviewSelectorBar::loadFinished() -{ - m_button->setEnabled(true); - m_button->setToolTip(""); - - verifyUrl(); -} - - -void PreviewSelectorBar::clicked() -{ - WebPage *page = Application::instance()->mainWindow()->currentTab()->page(); - - if(page) - { - // this is done just lo let the render process being faster.. - WebSnap::renderPreview(*page); - - KUrl url = page->mainFrame()->url(); - QStringList names = ReKonfig::previewNames(); - QStringList urls = ReKonfig::previewUrls(); - - urls.replace(m_previewIndex, url.toMimeDataString()); - names.replace(m_previewIndex, page->mainFrame()->title()); - - ReKonfig::setPreviewNames(names); - ReKonfig::setPreviewUrls(urls); - - ReKonfig::self()->writeConfig(); - - - page->mainFrame()->load(KUrl("about:favorites")); - } - - destroy(); -} - - -void PreviewSelectorBar::destroy() -{ - if (parentWidget() && parentWidget()->layout()) - { - parentWidget()->layout()->removeWidget(this); - } - this->deleteLater(); -} diff --git a/src/rekonqpage/previewselectorbar.h b/src/rekonqpage/previewselectorbar.h deleted file mode 100644 index bb9f26c4..00000000 --- a/src/rekonqpage/previewselectorbar.h +++ /dev/null @@ -1,66 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010 by Matthieu Gicquel -* Copyright (C) 2010 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 PREVIEWSELECTORBAR_H -#define PREVIEWSELECTORBAR_H - -// Local Includes -#include "rekonqprivate_export.h" -#include "webpage.h" - -// Qt Includes -#include -#include -#include - - -class REKONQ_TESTS_EXPORT PreviewSelectorBar : public QWidget -{ -Q_OBJECT - -public: - PreviewSelectorBar(int index, QWidget *parent); - ~PreviewSelectorBar(); - -private slots: - void clicked(); - - void loadProgress(); - void loadFinished(); - - void verifyUrl(); - - void destroy(); - -private: - QPushButton *m_button; - QLabel *m_label; - - int m_previewIndex; -}; - -#endif // PREVIEWSELECTORBAR_H -- cgit v1.2.1