From 997d64c9743149b2b400891b09ab99e9613bf273 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 27 Nov 2009 02:21:04 +0100 Subject: Last structure change, promised! Anyway, this moving/renaming helped me finding lots of strange circulary dependencies and easily solve them :) We have also a more organized structure, hopefully letting people work on different areas altogether. --- src/CMakeLists.txt | 19 +- src/application.cpp | 5 +- src/bookmarks.cpp | 300 -------------------- src/bookmarks.h | 249 ---------------- src/bookmarks/bookmarksmanager.cpp | 299 ++++++++++++++++++++ src/bookmarks/bookmarksmanager.h | 249 ++++++++++++++++ src/bookmarks/bookmarkspanel.cpp | 110 ++++++++ src/bookmarks/bookmarkspanel.h | 58 ++++ src/bookmarks/bookmarksproxy.cpp | 29 ++ src/bookmarks/bookmarksproxy.h | 48 ++++ src/bookmarks/bookmarkstreemodel.cpp | 255 +++++++++++++++++ src/bookmarks/bookmarkstreemodel.h | 69 +++++ src/bookmarkspanel/bookmarkspanel.cpp | 110 -------- src/bookmarkspanel/bookmarkspanel.h | 58 ---- src/bookmarkspanel/bookmarksproxy.cpp | 29 -- src/bookmarkspanel/bookmarksproxy.h | 48 ---- src/bookmarkspanel/bookmarkstreemodel.cpp | 255 ----------------- src/bookmarkspanel/bookmarkstreemodel.h | 69 ----- src/history/history.cpp | 454 ------------------------------ src/history/history.h | 161 ----------- src/history/historymanager.cpp | 454 ++++++++++++++++++++++++++++++ src/history/historymanager.h | 161 +++++++++++ src/history/historymodels.h | 2 +- src/history/sidepanel.cpp | 60 ++++ src/history/sidepanel.h | 58 ++++ src/lineedit.cpp | 69 ----- src/lineedit.h | 55 ---- src/mainview.cpp | 4 +- src/mainview.h | 2 +- src/mainwindow.cpp | 7 +- src/mainwindow.h | 4 +- src/previewimage.cpp | 2 +- src/rekonqpage/newtabpage.cpp | 2 +- src/sidepanel.cpp | 60 ---- src/sidepanel.h | 58 ---- src/tabbar.cpp | 1 + src/urlbar.cpp | 342 ---------------------- src/urlbar.h | 99 ------- src/urlbar/lineedit.cpp | 69 +++++ src/urlbar/lineedit.h | 55 ++++ src/urlbar/urlbar.cpp | 342 ++++++++++++++++++++++ src/urlbar/urlbar.h | 99 +++++++ src/webview.cpp | 3 + 43 files changed, 2443 insertions(+), 2439 deletions(-) delete mode 100644 src/bookmarks.cpp delete mode 100644 src/bookmarks.h create mode 100644 src/bookmarks/bookmarksmanager.cpp create mode 100644 src/bookmarks/bookmarksmanager.h create mode 100644 src/bookmarks/bookmarkspanel.cpp create mode 100644 src/bookmarks/bookmarkspanel.h create mode 100644 src/bookmarks/bookmarksproxy.cpp create mode 100644 src/bookmarks/bookmarksproxy.h create mode 100644 src/bookmarks/bookmarkstreemodel.cpp create mode 100644 src/bookmarks/bookmarkstreemodel.h delete mode 100644 src/bookmarkspanel/bookmarkspanel.cpp delete mode 100644 src/bookmarkspanel/bookmarkspanel.h delete mode 100644 src/bookmarkspanel/bookmarksproxy.cpp delete mode 100644 src/bookmarkspanel/bookmarksproxy.h delete mode 100644 src/bookmarkspanel/bookmarkstreemodel.cpp delete mode 100644 src/bookmarkspanel/bookmarkstreemodel.h delete mode 100644 src/history/history.cpp delete mode 100644 src/history/history.h create mode 100644 src/history/historymanager.cpp create mode 100644 src/history/historymanager.h create mode 100644 src/history/sidepanel.cpp create mode 100644 src/history/sidepanel.h delete mode 100644 src/lineedit.cpp delete mode 100644 src/lineedit.h delete mode 100644 src/sidepanel.cpp delete mode 100644 src/sidepanel.h delete mode 100644 src/urlbar.cpp delete mode 100644 src/urlbar.h create mode 100644 src/urlbar/lineedit.cpp create mode 100644 src/urlbar/lineedit.h create mode 100644 src/urlbar/urlbar.cpp create mode 100644 src/urlbar/urlbar.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f7c85dd..a1604c3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,36 +9,37 @@ ADD_SUBDIRECTORY( adblock ) SET( rekonq_KDEINIT_SRCS application.cpp - bookmarks.cpp findbar.cpp - lineedit.cpp mainview.cpp mainwindow.cpp previewimage.cpp sessionmanager.cpp - sidepanel.cpp tabbar.cpp - urlbar.cpp webpage.cpp webpluginfactory.cpp websnap.cpp webview.cpp #---------------------------------------- history/autosaver.cpp - history/history.cpp + history/historymanager.cpp history/historymodels.cpp history/historypanel.cpp + history/sidepanel.cpp #---------------------------------------- rekonqpage/newtabpage.cpp #---------------------------------------- settings/settingsdialog.cpp #---------------------------------------- - bookmarkspanel/bookmarkspanel.cpp - bookmarkspanel/bookmarkstreemodel.cpp - bookmarkspanel/bookmarksproxy.cpp + bookmarks/bookmarksmanager.cpp + bookmarks/bookmarkspanel.cpp + bookmarks/bookmarkstreemodel.cpp + bookmarks/bookmarksproxy.cpp #---------------------------------------- adblock/adblockmanager.cpp adblock/khtml_filter.cpp +#---------------------------------------- + urlbar/urlbar.cpp + urlbar/lineedit.cpp ) @@ -57,6 +58,8 @@ KDE4_ADD_KCFG_FILES( rekonq_KDEINIT_SRCS rekonq.kcfgc ) INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/adblock + ${CMAKE_CURRENT_SOURCE_DIR}/urlbar + ${CMAKE_CURRENT_SOURCE_DIR}/bookmarks ${CMAKE_CURRENT_SOURCE_DIR}/history ${CMAKE_CURRENT_SOURCE_DIR}/rekonqpage ${CMAKE_CURRENT_SOURCE_DIR}/settings diff --git a/src/application.cpp b/src/application.cpp index 766d56ed..3a0ce638 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -35,7 +35,8 @@ // Local Includes #include "mainwindow.h" -#include "history.h" +#include "historymanager.h" +#include "bookmarksmanager.h" #include "mainview.h" #include "webview.h" #include "urlbar.h" @@ -443,4 +444,4 @@ AdBlockManager *Application::adblockManager() s_adblockManager = new AdBlockManager(instance()); } return s_adblockManager; -} \ No newline at end of file +} diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp deleted file mode 100644 index 5f1ea393..00000000 --- a/src/bookmarks.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin -* -* -* 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 "bookmarks.h" -#include "bookmarks.moc" - -// Local Includes -#include "mainwindow.h" -#include "webview.h" -#include "application.h" - -// KDE Includes -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Qt Includes -#include -#include - - - -BookmarkOwner::BookmarkOwner(QObject *parent) - : QObject(parent) - , KBookmarkOwner() -{ -} - - -void BookmarkOwner::openBookmark(const KBookmark & bookmark, - Qt::MouseButtons mouseButtons, - Qt::KeyboardModifiers keyboardModifiers) -{ - if (keyboardModifiers & Qt::ControlModifier || mouseButtons == Qt::MidButton) - { - emit openUrl(bookmark.url(), Rekonq::NewCurrentTab); - } - else - { - emit openUrl(bookmark.url(), Rekonq::CurrentTab); - } -} - - -bool BookmarkOwner::supportsTabs() const -{ - return true; -} - - -QString BookmarkOwner::currentUrl() const -{ - return Application::instance()->mainWindow()->currentTab()->url().url(); -} - - -QString BookmarkOwner::currentTitle() const -{ - return Application::instance()->mainWindow()->currentTab()->title(); -} - - -void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bm) -{ - QList urlList = bm.groupUrlList(); - QList::iterator url; - for (url = urlList.begin(); url != urlList.end(); ++url) - { - Application::instance()->loadUrl(*url, Rekonq::NewCurrentTab); - } -} - - -// ------------------------------------------------------------------------------------------------------ - - -BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, - KBookmarkOwner *owner, - KMenu *menu, - KActionCollection* actionCollection) - : KBookmarkMenu(manager, owner, menu, actionCollection) - -{ - KAction *a = KStandardAction::addBookmark(this, SLOT(slotAddBookmark()), this); -// a->setText(i18n("Bookmark this Page")); - actionCollection->addAction(QLatin1String("rekonq_add_bookmark"),a); -} - -BookmarkMenu::~BookmarkMenu() -{ -} - - -KMenu *BookmarkMenu::viewContextMenu(QAction *action) -{ - // contextMenu() returns an invalid KMenu (seg fault) for the folders in the toolbar - KMenu *menu = contextMenu(action); - if(menu) - return menu; - - return 0; // new KMenu(); -} - - -void BookmarkMenu::slotAddBookmark() -{ - KAction *action = qobject_cast(sender()); - if (action && !action->data().isNull()) - { - KBookmarkGroup parentBookmark = manager()->findByAddress(parentAddress()).toGroup(); - /// TODO Add bookmark Icon - parentBookmark.addBookmark(owner()->currentTitle(), action->data().toUrl()); - manager()->emitChanged(); - return; - } - - KBookmarkMenu::slotAddBookmark(); -} - - -// ------------------------------------------------------------------------------------------------------ - - -BookmarkProvider::BookmarkProvider(QObject *parent) - : QObject(parent) - , m_manager(0) - , m_owner(0) - , m_actionCollection(new KActionCollection(this)) - , m_bookmarkMenu(0) - , m_bookmarkToolBar(0) -{ - KUrl bookfile = KUrl("~/.kde/share/apps/konqueror/bookmarks.xml"); // share konqueror bookmarks - - if (!QFile::exists(bookfile.path())) - { - bookfile = KUrl("~/.kde4/share/apps/konqueror/bookmarks.xml"); - if (!QFile::exists(bookfile.path())) - { - QString bookmarksDefaultPath = KStandardDirs::locate("appdata" , "defaultbookmarks.xbel"); - QFile bkms(bookmarksDefaultPath); - QString bookmarksPath = KStandardDirs::locateLocal("appdata", "bookmarks.xml", true); - bookmarksPath.replace("rekonq", "konqueror"); - bkms.copy(bookmarksPath); - - bookfile = KUrl(bookmarksPath); - } - } - m_manager = KBookmarkManager::managerForExternalFile(bookfile.path()); - connect(m_manager, SIGNAL(changed(const QString &, const QString &)), - this, SLOT(slotBookmarksChanged(const QString &, const QString &))); - - // setup menu - m_owner = new BookmarkOwner(this); - connect(m_owner, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &)), this, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &))); -} - - -BookmarkProvider::~BookmarkProvider() -{ - delete m_bookmarkMenu; - delete m_actionCollection; - delete m_owner; - delete m_manager; -} - - -void BookmarkProvider::setupBookmarkBar(KToolBar *t) -{ - m_bookmarkToolBar = t; - connect(m_bookmarkToolBar, SIGNAL(customContextMenuRequested(const QPoint &)), - this, SLOT(contextMenu(const QPoint &))); - - slotBookmarksChanged("", ""); -} - - -void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString &caller) -{ - Q_UNUSED(group) - Q_UNUSED(caller) - - if (!m_bookmarkToolBar) - return; - - KBookmarkGroup toolBarGroup = m_manager->toolbar(); - if (toolBarGroup.isNull()) - return; - - if(m_bookmarkToolBar) - { - m_bookmarkToolBar->clear(); // FIXME CRASH - - KBookmark bookmark = toolBarGroup.first(); - while (!bookmark.isNull()) - { - m_bookmarkToolBar->addAction(fillBookmarkBar(bookmark)); - bookmark = toolBarGroup.next(bookmark); - } - } -} - - -QAction *BookmarkProvider::actionByName(const QString &name) -{ - QAction *action = m_actionCollection->action(name); - if (action) - return action; - return new QAction(this); // return empty object instead of NULL pointer -} - - -void BookmarkProvider::contextMenu(const QPoint &point) -{ - KAction* action = dynamic_cast(m_bookmarkToolBar->actionAt(point)); - if (!action) - return; - KMenu *menu = m_bookmarkMenu->viewContextMenu(action); - if (!menu) - return; - menu->popup(m_bookmarkToolBar->mapToGlobal(point)); -} - - -KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent) -{ - KMenu *menu = new KMenu(parent); - m_bookmarkMenu = new BookmarkMenu(m_manager, m_owner, menu, m_actionCollection); - KActionMenu *bookmarkActionMenu = new KActionMenu(parent); - bookmarkActionMenu->setMenu(menu); - bookmarkActionMenu->setText(i18n("&Bookmarks")); - return bookmarkActionMenu; -} - - -KAction *BookmarkProvider::fillBookmarkBar(const KBookmark &bookmark) -{ - if (bookmark.isGroup()) - { - KBookmarkGroup group = bookmark.toGroup(); - KBookmark bm = group.first(); - KActionMenu *menuAction = new KActionMenu(KIcon(bookmark.icon()), bookmark.text(), this); - menuAction->setDelayed(false); - while (!bm.isNull()) - { - menuAction->addAction(fillBookmarkBar(bm)); - bm = group.next(bm); - } - return menuAction; - } - - if(bookmark.isSeparator()) - { - KAction *a = new KAction(this); - a->setSeparator(true); - return a; - } - else - { - return new KBookmarkAction(bookmark, m_owner, this); - } -} - - -KBookmarkGroup BookmarkProvider::rootGroup() -{ - return m_manager->root(); -} diff --git a/src/bookmarks.h b/src/bookmarks.h deleted file mode 100644 index febac234..00000000 --- a/src/bookmarks.h +++ /dev/null @@ -1,249 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin -* -* -* 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 BOOKMARKS_H -#define BOOKMARKS_H - - -// Local Includes -#include "application.h" - -// Qt Includes -#include - -// KDE Includes -#include - -// Forward Declarations -class BookmarkProvider; - -class KAction; -class KActionCollection; -class KActionMenu; -class KUrl; -class KToolBar; -class KBookmarkManager; - - -/** - * Reimplementation of KBookmarkOwner, this class allows to manage - * bookmarks as actions - * - */ -class BookmarkOwner : public QObject , public KBookmarkOwner -{ - Q_OBJECT - -public: - - /** - * @short The class constructor. - * - * @param parent the pointer parent Bookmark provider. We need it - * to get pointer to MainWindow - */ - BookmarkOwner(QObject *parent = 0); - virtual ~BookmarkOwner() {} - - /** - * This function is called when a bookmark is selected and belongs to - * the ancestor class. - * This method actually emits signal to load bookmark's url. - * - * @param bookmark the bookmark to open - * @param mouseButtons the mouse buttons clicked to select the bookmark - * @param keyboardModifiers the keyboard modifiers pushed when the bookmark was selected - */ - virtual void openBookmark(const KBookmark &bookmark, - Qt::MouseButtons mouseButtons, - Qt::KeyboardModifiers keyboardModifiers); - - - /** - * this method, from KBookmarkOwner interface, allows to add the current page - * to the bookmark list, returning the URL page as QString. - * - * @return the current page's URL - */ - virtual QString currentUrl() const; - - /** - * this method, from KBookmarkOwner interface, allows to add the current page - * to the bookmark list, returning the title's page as QString. - * - * @return the current page's title - */ - virtual QString currentTitle() const; - - /** - * This function returns whether the owner supports tabs. - */ - virtual bool supportsTabs() const; - - /** - * Called if the user wants to open every bookmark in this folder in a new tab. - * The default implementation does nothing. - * This is only called if supportsTabs() returns true - */ - virtual void openFolderinTabs(const KBookmarkGroup &bm); - -signals: - /** - * This signal is emitted when an url has to be loaded - * - * @param url the URL to load - * - */ - void openUrl(const KUrl &, const Rekonq::OpenType &); -}; - -// ------------------------------------------------------------------------------ - - -// KDE Includes -#include - - -/** - * This class represent the rekonq bookmarks menu. - * It's just a simple class inherited from KBookmarkMenu - * - */ -class BookmarkMenu : public KBookmarkMenu -{ - Q_OBJECT - -public: - BookmarkMenu(KBookmarkManager* manager, - KBookmarkOwner* owner, - KMenu* menu, - KActionCollection* actionCollection); - ~BookmarkMenu(); - - virtual KMenu *viewContextMenu(QAction* action); - -protected slots: - void slotAddBookmark(); - -}; - - -// ------------------------------------------------------------------------------ - - -/** - * This class represent the interface to rekonq bookmarks system. - * All rekonq needs (Bookmarks Menu, Bookmarks Toolbar) is provided - * from this class. - * So it implements code to have each one - * - * - */ -class BookmarkProvider : public QObject -{ - Q_OBJECT - -public: - /** - * @short Class constructor. - * Connect BookmarksProvider with bookmarks source - * (actually konqueror's bookmarks) - * @param parent The MainWindow to provide bookmarks objects - * - */ - BookmarkProvider(QObject* parent = 0); - ~BookmarkProvider(); - - /** - * @short Get the Bookmarks Menu Action - * @param the parent widget - * @return the Bookmarks Menu - */ - KActionMenu *bookmarkActionMenu(QWidget *parent); - - - /** - * @short set the Bookmarks Toolbar Action - */ - void setupBookmarkBar(KToolBar *); - - - /** - * @short Get action by name - * This method returns poiner bookmark action of given name. - * @pre m_actionCollection != NULL - * @param name Name of action you want to get - * @return It returns actions if one exists or empty object - */ - QAction *actionByName(const QString &name); - - /** - * returns Bookmark Manager root group - * - * @return the root bookmark group - */ - KBookmarkGroup rootGroup(); - - KBookmarkManager *bookmarkManager() { return m_manager; } -signals: - /** - * @short This signal is emitted when an url has to be loaded - * - * @param url the URL to load - */ - void openUrl(const KUrl &, const Rekonq::OpenType &); - - -public slots: - /** - * @short Opens the context menu on given position - * @param point Point on which you want to open this menu - */ - void contextMenu(const QPoint &point); - - /** - * @short Waits for signal that the group with the address has been modified by the caller. - * Waits for signal that the group (or any of its children) with the address - * @p groupAddress (e.g. "/4/5") has been modified by the caller @p caller. - * @param group bookmark group address - * @param caller caller that modified the bookmarks - * @see KBookmarkManager::changed - */ - void slotBookmarksChanged(const QString &group, const QString &caller); - -private: - KAction *fillBookmarkBar(const KBookmark &bookmark); - - KBookmarkManager *m_manager; - BookmarkOwner *m_owner; - KActionCollection *m_actionCollection; - BookmarkMenu *m_bookmarkMenu; - KToolBar *m_bookmarkToolBar; -}; - -#endif diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp new file mode 100644 index 00000000..1c881e08 --- /dev/null +++ b/src/bookmarks/bookmarksmanager.cpp @@ -0,0 +1,299 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* Copyright (C) 2009 by Lionel Chauvin +* +* +* 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 "bookmarksmanager.h" +#include "bookmarksmanager.moc" + +// Local Includes +#include "mainwindow.h" +#include "webview.h" + +// KDE Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Qt Includes +#include +#include + + + +BookmarkOwner::BookmarkOwner(QObject *parent) + : QObject(parent) + , KBookmarkOwner() +{ +} + + +void BookmarkOwner::openBookmark(const KBookmark & bookmark, + Qt::MouseButtons mouseButtons, + Qt::KeyboardModifiers keyboardModifiers) +{ + if (keyboardModifiers & Qt::ControlModifier || mouseButtons == Qt::MidButton) + { + emit openUrl(bookmark.url(), Rekonq::NewCurrentTab); + } + else + { + emit openUrl(bookmark.url(), Rekonq::CurrentTab); + } +} + + +bool BookmarkOwner::supportsTabs() const +{ + return true; +} + + +QString BookmarkOwner::currentUrl() const +{ + return Application::instance()->mainWindow()->currentTab()->url().url(); +} + + +QString BookmarkOwner::currentTitle() const +{ + return Application::instance()->mainWindow()->currentTab()->title(); +} + + +void BookmarkOwner::openFolderinTabs(const KBookmarkGroup &bm) +{ + QList urlList = bm.groupUrlList(); + QList::iterator url; + for (url = urlList.begin(); url != urlList.end(); ++url) + { + Application::instance()->loadUrl(*url, Rekonq::NewCurrentTab); + } +} + + +// ------------------------------------------------------------------------------------------------------ + + +BookmarkMenu::BookmarkMenu(KBookmarkManager *manager, + KBookmarkOwner *owner, + KMenu *menu, + KActionCollection* actionCollection) + : KBookmarkMenu(manager, owner, menu, actionCollection) + +{ + KAction *a = KStandardAction::addBookmark(this, SLOT(slotAddBookmark()), this); +// a->setText(i18n("Bookmark this Page")); + actionCollection->addAction(QLatin1String("rekonq_add_bookmark"),a); +} + +BookmarkMenu::~BookmarkMenu() +{ +} + + +KMenu *BookmarkMenu::viewContextMenu(QAction *action) +{ + // contextMenu() returns an invalid KMenu (seg fault) for the folders in the toolbar + KMenu *menu = contextMenu(action); + if(menu) + return menu; + + return 0; // new KMenu(); +} + + +void BookmarkMenu::slotAddBookmark() +{ + KAction *action = qobject_cast(sender()); + if (action && !action->data().isNull()) + { + KBookmarkGroup parentBookmark = manager()->findByAddress(parentAddress()).toGroup(); + /// TODO Add bookmark Icon + parentBookmark.addBookmark(owner()->currentTitle(), action->data().toUrl()); + manager()->emitChanged(); + return; + } + + KBookmarkMenu::slotAddBookmark(); +} + + +// ------------------------------------------------------------------------------------------------------ + + +BookmarkProvider::BookmarkProvider(QObject *parent) + : QObject(parent) + , m_manager(0) + , m_owner(0) + , m_actionCollection(new KActionCollection(this)) + , m_bookmarkMenu(0) + , m_bookmarkToolBar(0) +{ + KUrl bookfile = KUrl("~/.kde/share/apps/konqueror/bookmarks.xml"); // share konqueror bookmarks + + if (!QFile::exists(bookfile.path())) + { + bookfile = KUrl("~/.kde4/share/apps/konqueror/bookmarks.xml"); + if (!QFile::exists(bookfile.path())) + { + QString bookmarksDefaultPath = KStandardDirs::locate("appdata" , "defaultbookmarks.xbel"); + QFile bkms(bookmarksDefaultPath); + QString bookmarksPath = KStandardDirs::locateLocal("appdata", "bookmarks.xml", true); + bookmarksPath.replace("rekonq", "konqueror"); + bkms.copy(bookmarksPath); + + bookfile = KUrl(bookmarksPath); + } + } + m_manager = KBookmarkManager::managerForExternalFile(bookfile.path()); + connect(m_manager, SIGNAL(changed(const QString &, const QString &)), + this, SLOT(slotBookmarksChanged(const QString &, const QString &))); + + // setup menu + m_owner = new BookmarkOwner(this); + connect(m_owner, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &)), this, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &))); +} + + +BookmarkProvider::~BookmarkProvider() +{ + delete m_bookmarkMenu; + delete m_actionCollection; + delete m_owner; + delete m_manager; +} + + +void BookmarkProvider::setupBookmarkBar(KToolBar *t) +{ + m_bookmarkToolBar = t; + connect(m_bookmarkToolBar, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(contextMenu(const QPoint &))); + + slotBookmarksChanged("", ""); +} + + +void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString &caller) +{ + Q_UNUSED(group) + Q_UNUSED(caller) + + if (!m_bookmarkToolBar) + return; + + KBookmarkGroup toolBarGroup = m_manager->toolbar(); + if (toolBarGroup.isNull()) + return; + + if(m_bookmarkToolBar) + { + m_bookmarkToolBar->clear(); // FIXME CRASH + + KBookmark bookmark = toolBarGroup.first(); + while (!bookmark.isNull()) + { + m_bookmarkToolBar->addAction(fillBookmarkBar(bookmark)); + bookmark = toolBarGroup.next(bookmark); + } + } +} + + +QAction *BookmarkProvider::actionByName(const QString &name) +{ + QAction *action = m_actionCollection->action(name); + if (action) + return action; + return new QAction(this); // return empty object instead of NULL pointer +} + + +void BookmarkProvider::contextMenu(const QPoint &point) +{ + KAction* action = dynamic_cast(m_bookmarkToolBar->actionAt(point)); + if (!action) + return; + KMenu *menu = m_bookmarkMenu->viewContextMenu(action); + if (!menu) + return; + menu->popup(m_bookmarkToolBar->mapToGlobal(point)); +} + + +KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent) +{ + KMenu *menu = new KMenu(parent); + m_bookmarkMenu = new BookmarkMenu(m_manager, m_owner, menu, m_actionCollection); + KActionMenu *bookmarkActionMenu = new KActionMenu(parent); + bookmarkActionMenu->setMenu(menu); + bookmarkActionMenu->setText(i18n("&Bookmarks")); + return bookmarkActionMenu; +} + + +KAction *BookmarkProvider::fillBookmarkBar(const KBookmark &bookmark) +{ + if (bookmark.isGroup()) + { + KBookmarkGroup group = bookmark.toGroup(); + KBookmark bm = group.first(); + KActionMenu *menuAction = new KActionMenu(KIcon(bookmark.icon()), bookmark.text(), this); + menuAction->setDelayed(false); + while (!bm.isNull()) + { + menuAction->addAction(fillBookmarkBar(bm)); + bm = group.next(bm); + } + return menuAction; + } + + if(bookmark.isSeparator()) + { + KAction *a = new KAction(this); + a->setSeparator(true); + return a; + } + else + { + return new KBookmarkAction(bookmark, m_owner, this); + } +} + + +KBookmarkGroup BookmarkProvider::rootGroup() +{ + return m_manager->root(); +} diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h new file mode 100644 index 00000000..febac234 --- /dev/null +++ b/src/bookmarks/bookmarksmanager.h @@ -0,0 +1,249 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* Copyright (C) 2009 by Lionel Chauvin +* +* +* 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 BOOKMARKS_H +#define BOOKMARKS_H + + +// Local Includes +#include "application.h" + +// Qt Includes +#include + +// KDE Includes +#include + +// Forward Declarations +class BookmarkProvider; + +class KAction; +class KActionCollection; +class KActionMenu; +class KUrl; +class KToolBar; +class KBookmarkManager; + + +/** + * Reimplementation of KBookmarkOwner, this class allows to manage + * bookmarks as actions + * + */ +class BookmarkOwner : public QObject , public KBookmarkOwner +{ + Q_OBJECT + +public: + + /** + * @short The class constructor. + * + * @param parent the pointer parent Bookmark provider. We need it + * to get pointer to MainWindow + */ + BookmarkOwner(QObject *parent = 0); + virtual ~BookmarkOwner() {} + + /** + * This function is called when a bookmark is selected and belongs to + * the ancestor class. + * This method actually emits signal to load bookmark's url. + * + * @param bookmark the bookmark to open + * @param mouseButtons the mouse buttons clicked to select the bookmark + * @param keyboardModifiers the keyboard modifiers pushed when the bookmark was selected + */ + virtual void openBookmark(const KBookmark &bookmark, + Qt::MouseButtons mouseButtons, + Qt::KeyboardModifiers keyboardModifiers); + + + /** + * this method, from KBookmarkOwner interface, allows to add the current page + * to the bookmark list, returning the URL page as QString. + * + * @return the current page's URL + */ + virtual QString currentUrl() const; + + /** + * this method, from KBookmarkOwner interface, allows to add the current page + * to the bookmark list, returning the title's page as QString. + * + * @return the current page's title + */ + virtual QString currentTitle() const; + + /** + * This function returns whether the owner supports tabs. + */ + virtual bool supportsTabs() const; + + /** + * Called if the user wants to open every bookmark in this folder in a new tab. + * The default implementation does nothing. + * This is only called if supportsTabs() returns true + */ + virtual void openFolderinTabs(const KBookmarkGroup &bm); + +signals: + /** + * This signal is emitted when an url has to be loaded + * + * @param url the URL to load + * + */ + void openUrl(const KUrl &, const Rekonq::OpenType &); +}; + +// ------------------------------------------------------------------------------ + + +// KDE Includes +#include + + +/** + * This class represent the rekonq bookmarks menu. + * It's just a simple class inherited from KBookmarkMenu + * + */ +class BookmarkMenu : public KBookmarkMenu +{ + Q_OBJECT + +public: + BookmarkMenu(KBookmarkManager* manager, + KBookmarkOwner* owner, + KMenu* menu, + KActionCollection* actionCollection); + ~BookmarkMenu(); + + virtual KMenu *viewContextMenu(QAction* action); + +protected slots: + void slotAddBookmark(); + +}; + + +// ------------------------------------------------------------------------------ + + +/** + * This class represent the interface to rekonq bookmarks system. + * All rekonq needs (Bookmarks Menu, Bookmarks Toolbar) is provided + * from this class. + * So it implements code to have each one + * + * + */ +class BookmarkProvider : public QObject +{ + Q_OBJECT + +public: + /** + * @short Class constructor. + * Connect BookmarksProvider with bookmarks source + * (actually konqueror's bookmarks) + * @param parent The MainWindow to provide bookmarks objects + * + */ + BookmarkProvider(QObject* parent = 0); + ~BookmarkProvider(); + + /** + * @short Get the Bookmarks Menu Action + * @param the parent widget + * @return the Bookmarks Menu + */ + KActionMenu *bookmarkActionMenu(QWidget *parent); + + + /** + * @short set the Bookmarks Toolbar Action + */ + void setupBookmarkBar(KToolBar *); + + + /** + * @short Get action by name + * This method returns poiner bookmark action of given name. + * @pre m_actionCollection != NULL + * @param name Name of action you want to get + * @return It returns actions if one exists or empty object + */ + QAction *actionByName(const QString &name); + + /** + * returns Bookmark Manager root group + * + * @return the root bookmark group + */ + KBookmarkGroup rootGroup(); + + KBookmarkManager *bookmarkManager() { return m_manager; } +signals: + /** + * @short This signal is emitted when an url has to be loaded + * + * @param url the URL to load + */ + void openUrl(const KUrl &, const Rekonq::OpenType &); + + +public slots: + /** + * @short Opens the context menu on given position + * @param point Point on which you want to open this menu + */ + void contextMenu(const QPoint &point); + + /** + * @short Waits for signal that the group with the address has been modified by the caller. + * Waits for signal that the group (or any of its children) with the address + * @p groupAddress (e.g. "/4/5") has been modified by the caller @p caller. + * @param group bookmark group address + * @param caller caller that modified the bookmarks + * @see KBookmarkManager::changed + */ + void slotBookmarksChanged(const QString &group, const QString &caller); + +private: + KAction *fillBookmarkBar(const KBookmark &bookmark); + + KBookmarkManager *m_manager; + BookmarkOwner *m_owner; + KActionCollection *m_actionCollection; + BookmarkMenu *m_bookmarkMenu; + KToolBar *m_bookmarkToolBar; +}; + +#endif diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp new file mode 100644 index 00000000..a09e0058 --- /dev/null +++ b/src/bookmarks/bookmarkspanel.cpp @@ -0,0 +1,110 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* 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 . +* +* ============================================================ */ + + +// rekonq includes +#include "bookmarkspanel.h" +#include "bookmarkstreemodel.h" +#include "bookmarksproxy.h" + +// Auto Includes +#include "rekonq.h" + +// Qt includes +#include +#include +#include +#include + +// KDE includes +#include +#include + +BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags): + QDockWidget(title, parent, flags) +{ + setup(); + + setShown(ReKonfig::showBookmarksPanel()); +} + + +BookmarksPanel::~BookmarksPanel() +{ + ReKonfig::setShowBookmarksPanel(!isHidden()); + + delete ui; +} + +void BookmarksPanel::bookmarkActivated( const QModelIndex &index ) +{ + if( index.isValid() ) + emit openUrl( qVariantValue< KUrl >( index.data( Qt::UserRole ) ) ); +} + +void BookmarksPanel::setup() +{ + setObjectName("bookmarksPanel"); + setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + ui = new QWidget(this); + + // setup search bar + QHBoxLayout *searchLayout = new QHBoxLayout; + searchLayout->setContentsMargins(5, 0, 0, 0); + QLabel *searchLabel = new QLabel(i18n("&Search:")); + searchLayout->addWidget(searchLabel); + KLineEdit *search = new KLineEdit; + search->setClearButtonShown(true); + searchLayout->addWidget(search); + searchLabel->setBuddy( search ); + + // setup tree view + QTreeView *treeView = new QTreeView(ui); + treeView->setUniformRowHeights(true); + treeView->setSelectionBehavior(QAbstractItemView::SelectRows); + treeView->setTextElideMode(Qt::ElideMiddle); + treeView->setAlternatingRowColors(true); + treeView->header()->hide(); + treeView->setRootIsDecorated( false ); + + // put everything together + QVBoxLayout *vBoxLayout = new QVBoxLayout; + vBoxLayout->setContentsMargins(0, 0, 0, 0); + vBoxLayout->addLayout(searchLayout); + vBoxLayout->addWidget(treeView); + + // add it to the UI + ui->setLayout(vBoxLayout); + setWidget(ui); + + BookmarksTreeModel *model = new BookmarksTreeModel( this ); + BookmarksProxy *proxy = new BookmarksProxy(ui); + proxy->setSourceModel( model ); + treeView->setModel( proxy ); + + connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); + connect( treeView, SIGNAL( activated(QModelIndex) ), this, SLOT( bookmarkActivated(QModelIndex) ) ); +} diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h new file mode 100644 index 00000000..8c3e6121 --- /dev/null +++ b/src/bookmarks/bookmarkspanel.h @@ -0,0 +1,58 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* 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 BOOKMARKSPANEL_H +#define BOOKMARKSPANEL_H + +// Qt Includes +#include + +// Forward Declarations +class KUrl; +class QModelIndex; + +class BookmarksPanel : public QDockWidget +{ + Q_OBJECT + Q_DISABLE_COPY(BookmarksPanel) + +public: + explicit BookmarksPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~BookmarksPanel(); + +signals: + void openUrl(const KUrl &); + +private slots: + void bookmarkActivated( const QModelIndex &index ); + +private: + void setup(); + + QWidget *ui; +}; + +#endif // BOOKMARKSPANEL_H diff --git a/src/bookmarks/bookmarksproxy.cpp b/src/bookmarks/bookmarksproxy.cpp new file mode 100644 index 00000000..87d1ce71 --- /dev/null +++ b/src/bookmarks/bookmarksproxy.cpp @@ -0,0 +1,29 @@ +#include "bookmarksproxy.h" + +BookmarksProxy::BookmarksProxy( QObject *parent ): + QSortFilterProxyModel( parent ) +{ +} + +bool BookmarksProxy::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const +{ + QModelIndex idx = sourceModel()->index( source_row, 0, source_parent ); + +// return idx.data().toString().contains( filterRegExp() ); + return recursiveMatch( idx ); +} + +bool BookmarksProxy::recursiveMatch( const QModelIndex &index ) const +{ + if( index.data().toString().contains( filterRegExp() ) ) { + return true; + } + + for( int childRow = 0; childRow < sourceModel()->rowCount( index ); ++childRow ) { + if( recursiveMatch( sourceModel()->index( childRow, 0, index ) ) ) { + return true; + } + } + + return false; +} diff --git a/src/bookmarks/bookmarksproxy.h b/src/bookmarks/bookmarksproxy.h new file mode 100644 index 00000000..99483331 --- /dev/null +++ b/src/bookmarks/bookmarksproxy.h @@ -0,0 +1,48 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* 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 BOOKMARKSPROXY_H +#define BOOKMARKSPROXY_H + +// Qt Includes +#include + +class BookmarksProxy : public QSortFilterProxyModel +{ + Q_OBJECT + Q_DISABLE_COPY(BookmarksProxy) + +public: + BookmarksProxy( QObject *parent = 0 ); + +protected: + virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const; + + // returns true if any child(or childs-child...) matches filter + bool recursiveMatch( const QModelIndex &index ) const; +}; + +#endif // BOOKMARKSPROXY_H diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp new file mode 100644 index 00000000..b5690a9b --- /dev/null +++ b/src/bookmarks/bookmarkstreemodel.cpp @@ -0,0 +1,255 @@ +#include "bookmarkstreemodel.h" + +// rekonq includes +#include "application.h" +#include "bookmarksmanager.h" + +// KDE includes +#include +#include + +class BookmarksTreeModel::BtmItem +{ +public: + BtmItem(const KBookmark &bm): + m_parent(0), m_kbm(bm) + { + } + ~BtmItem() + { + qDeleteAll(m_children); + } + + QVariant data( int role = Qt::DisplayRole ) const + { + if( m_kbm.isNull() ) + return QVariant();// should only happen for root item + + if( role == Qt::DisplayRole ) + return m_kbm.text(); + if( role == Qt::DecorationRole ) + return KIcon( m_kbm.icon() ); + if( role == Qt::UserRole ) + return m_kbm.url(); + + return QVariant(); + } + + int row() const + { + if(m_parent) + return m_parent->m_children.indexOf( const_cast< BtmItem* >( this ) ); + return 0; + } + int childCount() const + { + return m_children.count(); + } + BtmItem* child( int n ) + { + Q_ASSERT(n>=0); + Q_ASSERT(nm_parent = this; + m_children << child; + } + void clear() + { + qDeleteAll(m_children); + m_children.clear(); + } + +private: + BtmItem *m_parent; + QList< BtmItem* > m_children; + + KBookmark m_kbm; +}; + +BookmarksTreeModel::BookmarksTreeModel(QObject *parent): + QAbstractItemModel(parent), m_root(0) +{ + resetModel(); + connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( changed(QString,QString) ), this, SLOT( bookmarksChanged(QString) ) ); + connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( bookmarksChanged(QString) ), this, SLOT( bookmarksChanged(QString) ) ); +} + +BookmarksTreeModel::~BookmarksTreeModel() +{ + delete m_root; +} + +int BookmarksTreeModel::rowCount(const QModelIndex &parent) const +{ + BtmItem *parentItem = 0; + if( !parent.isValid() ) { + parentItem = m_root; + } + else { + parentItem = static_cast< BtmItem* >( parent.internalPointer() ); + } + + return parentItem->childCount(); +} + +int BookmarksTreeModel::columnCount(const QModelIndex &/*parent*/) const +{ + // name + return 1; +} + +QVariant BookmarksTreeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 ) + return i18n( "Bookmark" ); + + return QVariant(); +} + +Qt::ItemFlags BookmarksTreeModel::flags(const QModelIndex &/*index*/) const +{ + return Qt::ItemIsEnabled|Qt::ItemIsSelectable; +} + +QModelIndex BookmarksTreeModel::index(int row, int column, const QModelIndex &parent) const +{ + if( !hasIndex( row, column, parent ) ) { + return QModelIndex(); + } + + BtmItem *parentItem; + + if( !parent.isValid() ) { + parentItem = m_root; + } + else { + parentItem = static_cast< BtmItem* >( parent.internalPointer() ); + } + + BtmItem *childItem = parentItem->child( row ); + if( childItem ) { + return createIndex( row, column, childItem ); + } + + return QModelIndex(); +} + +QModelIndex BookmarksTreeModel::parent(const QModelIndex &index) const +{ + if( !index.isValid() ) { + return QModelIndex(); + } + + BtmItem *childItem = static_cast< BtmItem* >( index.internalPointer() ); + BtmItem *parentItem = childItem->parent(); + + if( parentItem == m_root ) { + return QModelIndex(); + } + + return createIndex( parentItem->row(), 0, parentItem ); +} + +QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const +{ + if( !index.isValid() ) { + return QVariant(); + } + + BtmItem *node = static_cast< BtmItem* >( index.internalPointer() ); + if( node && node == m_root ) { + if( role == Qt::DisplayRole ) + return i18n( "Bookmarks" ); + else if( role == Qt::DecorationRole ) + return KIcon( "bookmarks" ); + } + else if( node ) { + return node->data( role ); + } + + return QVariant(); +} + +// bool BookmarksTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) +// { +// } + +void BookmarksTreeModel::bookmarksChanged( const QString &groupAddress ) +{ +// qDebug( "bookmarksChanged '%s'", qPrintable( groupAddress ) ); + + if( groupAddress.isEmpty() ) { + resetModel(); + return; + } + + BtmItem *node = m_root; + QModelIndex nodeIndex; + + QStringList indexChain( groupAddress.split( '/', QString::SkipEmptyParts) ); + foreach( QString sIndex, indexChain ) { + bool ok; + int i = sIndex.toInt( &ok ); + if( !ok ) + break; + + if( i < 0 || i >= node->childCount() ) + break; + + node = node->child( i ); + nodeIndex = index( i, 0, nodeIndex ); + } +// qDebug( " changed: '%s'(0-%d)", ( node == m_root ? "ROOT" : qPrintable( node->data().toString() ) ), node->childCount() ); + emit dataChanged( index( 0, 0, nodeIndex ), index( node->childCount(), 0, nodeIndex ) ); +} + +void BookmarksTreeModel::resetModel() +{ + setRoot(Application::bookmarkProvider()->rootGroup()); +} + +void BookmarksTreeModel::setRoot(KBookmarkGroup bmg) +{ + delete m_root; + m_root = new BtmItem(KBookmark()); + + if( bmg.isNull() ) { + return; + } + + populate( m_root, bmg ); + + reset(); +} + +void BookmarksTreeModel::populate( BtmItem *node, KBookmarkGroup bmg) +{ + node->clear(); + + if( bmg.isNull() ) { + return; + } + + KBookmark bm = bmg.first(); + while( !bm.isNull() ) { + BtmItem *newChild = new BtmItem( bm ); + if( bm.isGroup() ) + populate( newChild, bm.toGroup() ); + + node->appendChild( newChild ); + bm = bmg.next( bm ); + } +} diff --git a/src/bookmarks/bookmarkstreemodel.h b/src/bookmarks/bookmarkstreemodel.h new file mode 100644 index 00000000..9753999c --- /dev/null +++ b/src/bookmarks/bookmarkstreemodel.h @@ -0,0 +1,69 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Nils Weigel +* +* +* 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 BOOKMARKSTREEMODEL_H +#define BOOKMARKSTREEMODEL_H + +// Qt Includes +#include + +// KDE includes +#include + +class BookmarksTreeModel : public QAbstractItemModel +{ + Q_OBJECT + Q_DISABLE_COPY(BookmarksTreeModel) + +public: + explicit BookmarksTreeModel(QObject *parent = 0); + ~BookmarksTreeModel(); + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + + virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + virtual QModelIndex parent(const QModelIndex &index) const; + virtual QVariant data(const QModelIndex &index, int role) const; +// virtual bool setData(const QModelIndex &index, const QVariant &value, int role); + +private slots: + void bookmarksChanged( const QString &groupAddress ); + +private: + class BtmItem; + BtmItem *m_root; + + void resetModel(); + + void setRoot(KBookmarkGroup bmg); + void populate( BtmItem *node, KBookmarkGroup bmg); +}; + +#endif // BOOKMARKSTREEMODEL_H diff --git a/src/bookmarkspanel/bookmarkspanel.cpp b/src/bookmarkspanel/bookmarkspanel.cpp deleted file mode 100644 index a09e0058..00000000 --- a/src/bookmarkspanel/bookmarkspanel.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Nils Weigel -* -* -* 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 . -* -* ============================================================ */ - - -// rekonq includes -#include "bookmarkspanel.h" -#include "bookmarkstreemodel.h" -#include "bookmarksproxy.h" - -// Auto Includes -#include "rekonq.h" - -// Qt includes -#include -#include -#include -#include - -// KDE includes -#include -#include - -BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags): - QDockWidget(title, parent, flags) -{ - setup(); - - setShown(ReKonfig::showBookmarksPanel()); -} - - -BookmarksPanel::~BookmarksPanel() -{ - ReKonfig::setShowBookmarksPanel(!isHidden()); - - delete ui; -} - -void BookmarksPanel::bookmarkActivated( const QModelIndex &index ) -{ - if( index.isValid() ) - emit openUrl( qVariantValue< KUrl >( index.data( Qt::UserRole ) ) ); -} - -void BookmarksPanel::setup() -{ - setObjectName("bookmarksPanel"); - setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - - ui = new QWidget(this); - - // setup search bar - QHBoxLayout *searchLayout = new QHBoxLayout; - searchLayout->setContentsMargins(5, 0, 0, 0); - QLabel *searchLabel = new QLabel(i18n("&Search:")); - searchLayout->addWidget(searchLabel); - KLineEdit *search = new KLineEdit; - search->setClearButtonShown(true); - searchLayout->addWidget(search); - searchLabel->setBuddy( search ); - - // setup tree view - QTreeView *treeView = new QTreeView(ui); - treeView->setUniformRowHeights(true); - treeView->setSelectionBehavior(QAbstractItemView::SelectRows); - treeView->setTextElideMode(Qt::ElideMiddle); - treeView->setAlternatingRowColors(true); - treeView->header()->hide(); - treeView->setRootIsDecorated( false ); - - // put everything together - QVBoxLayout *vBoxLayout = new QVBoxLayout; - vBoxLayout->setContentsMargins(0, 0, 0, 0); - vBoxLayout->addLayout(searchLayout); - vBoxLayout->addWidget(treeView); - - // add it to the UI - ui->setLayout(vBoxLayout); - setWidget(ui); - - BookmarksTreeModel *model = new BookmarksTreeModel( this ); - BookmarksProxy *proxy = new BookmarksProxy(ui); - proxy->setSourceModel( model ); - treeView->setModel( proxy ); - - connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); - connect( treeView, SIGNAL( activated(QModelIndex) ), this, SLOT( bookmarkActivated(QModelIndex) ) ); -} diff --git a/src/bookmarkspanel/bookmarkspanel.h b/src/bookmarkspanel/bookmarkspanel.h deleted file mode 100644 index 8c3e6121..00000000 --- a/src/bookmarkspanel/bookmarkspanel.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Nils Weigel -* -* -* 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 BOOKMARKSPANEL_H -#define BOOKMARKSPANEL_H - -// Qt Includes -#include - -// Forward Declarations -class KUrl; -class QModelIndex; - -class BookmarksPanel : public QDockWidget -{ - Q_OBJECT - Q_DISABLE_COPY(BookmarksPanel) - -public: - explicit BookmarksPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); - ~BookmarksPanel(); - -signals: - void openUrl(const KUrl &); - -private slots: - void bookmarkActivated( const QModelIndex &index ); - -private: - void setup(); - - QWidget *ui; -}; - -#endif // BOOKMARKSPANEL_H diff --git a/src/bookmarkspanel/bookmarksproxy.cpp b/src/bookmarkspanel/bookmarksproxy.cpp deleted file mode 100644 index 87d1ce71..00000000 --- a/src/bookmarkspanel/bookmarksproxy.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "bookmarksproxy.h" - -BookmarksProxy::BookmarksProxy( QObject *parent ): - QSortFilterProxyModel( parent ) -{ -} - -bool BookmarksProxy::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const -{ - QModelIndex idx = sourceModel()->index( source_row, 0, source_parent ); - -// return idx.data().toString().contains( filterRegExp() ); - return recursiveMatch( idx ); -} - -bool BookmarksProxy::recursiveMatch( const QModelIndex &index ) const -{ - if( index.data().toString().contains( filterRegExp() ) ) { - return true; - } - - for( int childRow = 0; childRow < sourceModel()->rowCount( index ); ++childRow ) { - if( recursiveMatch( sourceModel()->index( childRow, 0, index ) ) ) { - return true; - } - } - - return false; -} diff --git a/src/bookmarkspanel/bookmarksproxy.h b/src/bookmarkspanel/bookmarksproxy.h deleted file mode 100644 index 99483331..00000000 --- a/src/bookmarkspanel/bookmarksproxy.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Nils Weigel -* -* -* 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 BOOKMARKSPROXY_H -#define BOOKMARKSPROXY_H - -// Qt Includes -#include - -class BookmarksProxy : public QSortFilterProxyModel -{ - Q_OBJECT - Q_DISABLE_COPY(BookmarksProxy) - -public: - BookmarksProxy( QObject *parent = 0 ); - -protected: - virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const; - - // returns true if any child(or childs-child...) matches filter - bool recursiveMatch( const QModelIndex &index ) const; -}; - -#endif // BOOKMARKSPROXY_H diff --git a/src/bookmarkspanel/bookmarkstreemodel.cpp b/src/bookmarkspanel/bookmarkstreemodel.cpp deleted file mode 100644 index 99441a63..00000000 --- a/src/bookmarkspanel/bookmarkstreemodel.cpp +++ /dev/null @@ -1,255 +0,0 @@ -#include "bookmarkstreemodel.h" - -// rekonq includes -#include "../application.h" -#include "../bookmarks.h" - -// KDE includes -#include -#include - -class BookmarksTreeModel::BtmItem -{ -public: - BtmItem(const KBookmark &bm): - m_parent(0), m_kbm(bm) - { - } - ~BtmItem() - { - qDeleteAll(m_children); - } - - QVariant data( int role = Qt::DisplayRole ) const - { - if( m_kbm.isNull() ) - return QVariant();// should only happen for root item - - if( role == Qt::DisplayRole ) - return m_kbm.text(); - if( role == Qt::DecorationRole ) - return KIcon( m_kbm.icon() ); - if( role == Qt::UserRole ) - return m_kbm.url(); - - return QVariant(); - } - - int row() const - { - if(m_parent) - return m_parent->m_children.indexOf( const_cast< BtmItem* >( this ) ); - return 0; - } - int childCount() const - { - return m_children.count(); - } - BtmItem* child( int n ) - { - Q_ASSERT(n>=0); - Q_ASSERT(nm_parent = this; - m_children << child; - } - void clear() - { - qDeleteAll(m_children); - m_children.clear(); - } - -private: - BtmItem *m_parent; - QList< BtmItem* > m_children; - - KBookmark m_kbm; -}; - -BookmarksTreeModel::BookmarksTreeModel(QObject *parent): - QAbstractItemModel(parent), m_root(0) -{ - resetModel(); - connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( changed(QString,QString) ), this, SLOT( bookmarksChanged(QString) ) ); - connect( Application::bookmarkProvider()->bookmarkManager(), SIGNAL( bookmarksChanged(QString) ), this, SLOT( bookmarksChanged(QString) ) ); -} - -BookmarksTreeModel::~BookmarksTreeModel() -{ - delete m_root; -} - -int BookmarksTreeModel::rowCount(const QModelIndex &parent) const -{ - BtmItem *parentItem = 0; - if( !parent.isValid() ) { - parentItem = m_root; - } - else { - parentItem = static_cast< BtmItem* >( parent.internalPointer() ); - } - - return parentItem->childCount(); -} - -int BookmarksTreeModel::columnCount(const QModelIndex &/*parent*/) const -{ - // name - return 1; -} - -QVariant BookmarksTreeModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 ) - return i18n( "Bookmark" ); - - return QVariant(); -} - -Qt::ItemFlags BookmarksTreeModel::flags(const QModelIndex &/*index*/) const -{ - return Qt::ItemIsEnabled|Qt::ItemIsSelectable; -} - -QModelIndex BookmarksTreeModel::index(int row, int column, const QModelIndex &parent) const -{ - if( !hasIndex( row, column, parent ) ) { - return QModelIndex(); - } - - BtmItem *parentItem; - - if( !parent.isValid() ) { - parentItem = m_root; - } - else { - parentItem = static_cast< BtmItem* >( parent.internalPointer() ); - } - - BtmItem *childItem = parentItem->child( row ); - if( childItem ) { - return createIndex( row, column, childItem ); - } - - return QModelIndex(); -} - -QModelIndex BookmarksTreeModel::parent(const QModelIndex &index) const -{ - if( !index.isValid() ) { - return QModelIndex(); - } - - BtmItem *childItem = static_cast< BtmItem* >( index.internalPointer() ); - BtmItem *parentItem = childItem->parent(); - - if( parentItem == m_root ) { - return QModelIndex(); - } - - return createIndex( parentItem->row(), 0, parentItem ); -} - -QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const -{ - if( !index.isValid() ) { - return QVariant(); - } - - BtmItem *node = static_cast< BtmItem* >( index.internalPointer() ); - if( node && node == m_root ) { - if( role == Qt::DisplayRole ) - return i18n( "Bookmarks" ); - else if( role == Qt::DecorationRole ) - return KIcon( "bookmarks" ); - } - else if( node ) { - return node->data( role ); - } - - return QVariant(); -} - -// bool BookmarksTreeModel::setData(const QModelIndex &index, const QVariant &value, int role) -// { -// } - -void BookmarksTreeModel::bookmarksChanged( const QString &groupAddress ) -{ -// qDebug( "bookmarksChanged '%s'", qPrintable( groupAddress ) ); - - if( groupAddress.isEmpty() ) { - resetModel(); - return; - } - - BtmItem *node = m_root; - QModelIndex nodeIndex; - - QStringList indexChain( groupAddress.split( '/', QString::SkipEmptyParts) ); - foreach( QString sIndex, indexChain ) { - bool ok; - int i = sIndex.toInt( &ok ); - if( !ok ) - break; - - if( i < 0 || i >= node->childCount() ) - break; - - node = node->child( i ); - nodeIndex = index( i, 0, nodeIndex ); - } -// qDebug( " changed: '%s'(0-%d)", ( node == m_root ? "ROOT" : qPrintable( node->data().toString() ) ), node->childCount() ); - emit dataChanged( index( 0, 0, nodeIndex ), index( node->childCount(), 0, nodeIndex ) ); -} - -void BookmarksTreeModel::resetModel() -{ - setRoot(Application::bookmarkProvider()->rootGroup()); -} - -void BookmarksTreeModel::setRoot(KBookmarkGroup bmg) -{ - delete m_root; - m_root = new BtmItem(KBookmark()); - - if( bmg.isNull() ) { - return; - } - - populate( m_root, bmg ); - - reset(); -} - -void BookmarksTreeModel::populate( BtmItem *node, KBookmarkGroup bmg) -{ - node->clear(); - - if( bmg.isNull() ) { - return; - } - - KBookmark bm = bmg.first(); - while( !bm.isNull() ) { - BtmItem *newChild = new BtmItem( bm ); - if( bm.isGroup() ) - populate( newChild, bm.toGroup() ); - - node->appendChild( newChild ); - bm = bmg.next( bm ); - } -} diff --git a/src/bookmarkspanel/bookmarkstreemodel.h b/src/bookmarkspanel/bookmarkstreemodel.h deleted file mode 100644 index 9753999c..00000000 --- a/src/bookmarkspanel/bookmarkstreemodel.h +++ /dev/null @@ -1,69 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Nils Weigel -* -* -* 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 BOOKMARKSTREEMODEL_H -#define BOOKMARKSTREEMODEL_H - -// Qt Includes -#include - -// KDE includes -#include - -class BookmarksTreeModel : public QAbstractItemModel -{ - Q_OBJECT - Q_DISABLE_COPY(BookmarksTreeModel) - -public: - explicit BookmarksTreeModel(QObject *parent = 0); - ~BookmarksTreeModel(); - - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - - virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - - virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex parent(const QModelIndex &index) const; - virtual QVariant data(const QModelIndex &index, int role) const; -// virtual bool setData(const QModelIndex &index, const QVariant &value, int role); - -private slots: - void bookmarksChanged( const QString &groupAddress ); - -private: - class BtmItem; - BtmItem *m_root; - - void resetModel(); - - void setRoot(KBookmarkGroup bmg); - void populate( BtmItem *node, KBookmarkGroup bmg); -}; - -#endif // BOOKMARKSTREEMODEL_H diff --git a/src/history/history.cpp b/src/history/history.cpp deleted file mode 100644 index 07580433..00000000 --- a/src/history/history.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008 Benjamin C. Meyer -* Copyright (C) 2008-2009 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 . -* -* ============================================================ */ - - -// Self Includes -#include "history.h" -#include "history.moc" - -// Auto Includes -#include "rekonq.h" - -// Local Includes -#include "historymodels.h" -#include "autosaver.h" -#include "application.h" - -// KDE Includes -#include -#include -#include - -// Qt Includes -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -// generic algorithms -#include - - -static const unsigned int HISTORY_VERSION = 23; - - -HistoryManager::HistoryManager(QObject *parent) - : QWebHistoryInterface(parent) - , m_saveTimer(new AutoSaver(this)) - , m_historyLimit(30) - , m_historyModel(0) - , m_historyFilterModel(0) - , m_historyTreeModel(0) - , m_completion(0) -{ - // take care of the completion object - m_completion = new KCompletion; - m_completion->setOrder( KCompletion::Weighted ); - - m_expiredTimer.setSingleShot(true); - connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired())); - connect(this, SIGNAL(entryAdded(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); - connect(this, SIGNAL(entryRemoved(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); - - load(); - - m_historyModel = new HistoryModel(this, this); - m_historyFilterModel = new HistoryFilterModel(m_historyModel, this); - m_historyTreeModel = new HistoryTreeModel(m_historyFilterModel, this); - - // QWebHistoryInterface will delete the history manager - QWebHistoryInterface::setDefaultInterface(this); -} - - -HistoryManager::~HistoryManager() -{ - m_saveTimer->saveIfNeccessary(); - delete m_completion; -} - - -QList HistoryManager::history() const -{ - return m_history; -} - - -bool HistoryManager::historyContains(const QString &url) const -{ - return m_historyFilterModel->historyContains(url); -} - - -void HistoryManager::addHistoryEntry(const QString &url) -{ - QUrl cleanUrl(url); - - // don't store about: urls (home page related) - if(cleanUrl.scheme() == QString("about")) - return; - - cleanUrl.setPassword(QString()); - cleanUrl.setHost(cleanUrl.host().toLower()); - HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime()); - addHistoryEntry(item); - - // Add item to completion object - QString _url(url); - _url.remove(QRegExp("^http://|/$")); - m_completion->addItem(_url); -} - - -void HistoryManager::setHistory(const QList &history, bool loadedAndSorted) -{ - m_history = history; - - // verify that it is sorted by date - if (!loadedAndSorted) - qSort(m_history.begin(), m_history.end()); - - checkForExpired(); - - if (loadedAndSorted) - { - m_lastSavedUrl = m_history.value(0).url; - } - else - { - m_lastSavedUrl.clear(); - m_saveTimer->changeOccurred(); - } - emit historyReset(); -} - - -HistoryModel *HistoryManager::historyModel() const -{ - return m_historyModel; -} - - -HistoryFilterModel *HistoryManager::historyFilterModel() const -{ - return m_historyFilterModel; -} - - -HistoryTreeModel *HistoryManager::historyTreeModel() const -{ - return m_historyTreeModel; -} - - -void HistoryManager::checkForExpired() -{ - if (m_historyLimit < 0 || m_history.isEmpty()) - return; - - QDateTime now = QDateTime::currentDateTime(); - int nextTimeout = 0; - - while (!m_history.isEmpty()) - { - QDateTime checkForExpired = m_history.last().dateTime; - checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit)); - if (now.daysTo(checkForExpired) > 7) - { - // check at most in a week to prevent int overflows on the timer - nextTimeout = 7 * 86400; - } - else - { - nextTimeout = now.secsTo(checkForExpired); - } - if (nextTimeout > 0) - break; - HistoryItem item = m_history.takeLast(); - // remove from saved file also - m_lastSavedUrl.clear(); - emit entryRemoved(item); - } - - if (nextTimeout > 0) - m_expiredTimer.start(nextTimeout * 1000); -} - - -void HistoryManager::addHistoryEntry(const HistoryItem &item) -{ - QWebSettings *globalSettings = QWebSettings::globalSettings(); - if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) - return; - - m_history.prepend(item); - emit entryAdded(item); - - if (m_history.count() == 1) - checkForExpired(); -} - - -void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title) -{ - for (int i = 0; i < m_history.count(); ++i) - { - if (url == m_history.at(i).url) - { - m_history[i].title = title; - m_saveTimer->changeOccurred(); - if (m_lastSavedUrl.isEmpty()) - m_lastSavedUrl = m_history.at(i).url; - emit entryUpdated(i); - break; - } - } -} - - -void HistoryManager::removeHistoryEntry(const HistoryItem &item) -{ - m_lastSavedUrl.clear(); - m_history.removeOne(item); - emit entryRemoved(item); -} - - -void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title) -{ - for (int i = 0; i < m_history.count(); ++i) - { - if (url == m_history.at(i).url - && (title.isEmpty() || title == m_history.at(i).title)) - { - removeHistoryEntry(m_history.at(i)); - break; - } - } - - // Remove item from completion object - QString _url = url.path(); - _url.remove(QRegExp("^http://|/$")); - m_completion->removeItem(_url); -} - - -int HistoryManager::historyLimit() const -{ - return m_historyLimit; -} - - -void HistoryManager::setHistoryLimit(int limit) -{ - if (m_historyLimit == limit) - return; - m_historyLimit = limit; - checkForExpired(); - m_saveTimer->changeOccurred(); -} - - -void HistoryManager::clear() -{ - m_history.clear(); - m_lastSavedUrl.clear(); - m_saveTimer->changeOccurred(); - m_saveTimer->saveIfNeccessary(); - historyReset(); -} - - -void HistoryManager::loadSettings() -{ - int historyExpire = ReKonfig::expireHistory(); - int days; - switch (historyExpire) - { - case 0: days = 1; break; - case 1: days = 7; break; - case 2: days = 14; break; - case 3: days = 30; break; - case 4: days = 365; break; - case 5: days = -1; break; - default: days = -1; - } - m_historyLimit = days; -} - - -void HistoryManager::load() -{ - loadSettings(); - - QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); - QFile historyFile(historyFilePath); - if (!historyFile.exists()) - return; - if (!historyFile.open(QFile::ReadOnly)) - { - kWarning() << "Unable to open history file" << historyFile.fileName(); - return; - } - - QList list; - QDataStream in(&historyFile); - // Double check that the history file is sorted as it is read in - bool needToSort = false; - HistoryItem lastInsertedItem; - QByteArray data; - QDataStream stream; - QBuffer buffer; - stream.setDevice(&buffer); - while (!historyFile.atEnd()) - { - in >> data; - buffer.close(); - buffer.setBuffer(&data); - buffer.open(QIODevice::ReadOnly); - quint32 ver; - stream >> ver; - if (ver != HISTORY_VERSION) - continue; - HistoryItem item; - stream >> item.url; - stream >> item.dateTime; - stream >> item.title; - - if (!item.dateTime.isValid()) - continue; - - if (item == lastInsertedItem) - { - if (lastInsertedItem.title.isEmpty() && !list.isEmpty()) - list[0].title = item.title; - continue; - } - - if (!needToSort && !list.isEmpty() && lastInsertedItem < item) - needToSort = true; - - list.prepend(item); - lastInsertedItem = item; - - // Add item to completion object - QString _url = item.url; - _url.remove(QRegExp("^http://|/$")); - m_completion->addItem(_url); - } - if (needToSort) - qSort(list.begin(), list.end()); - - setHistory(list, true); - - // If we had to sort re-write the whole history sorted - if (needToSort) - { - m_lastSavedUrl.clear(); - m_saveTimer->changeOccurred(); - } -} - - -void HistoryManager::save() -{ - bool saveAll = m_lastSavedUrl.isEmpty(); - int first = m_history.count() - 1; - if (!saveAll) - { - // find the first one to save - for (int i = 0; i < m_history.count(); ++i) - { - if (m_history.at(i).url == m_lastSavedUrl) - { - first = i - 1; - break; - } - } - } - if (first == m_history.count() - 1) - saveAll = true; - - QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); - QFile historyFile(historyFilePath); - - // When saving everything use a temporary file to prevent possible data loss. - QTemporaryFile tempFile; - tempFile.setAutoRemove(false); - bool open = false; - if (saveAll) - { - open = tempFile.open(); - } - else - { - open = historyFile.open(QFile::Append); - } - - if (!open) - { - kWarning() << "Unable to open history file for saving" - << (saveAll ? tempFile.fileName() : historyFile.fileName()); - return; - } - - QDataStream out(saveAll ? &tempFile : &historyFile); - for (int i = first; i >= 0; --i) - { - QByteArray data; - QDataStream stream(&data, QIODevice::WriteOnly); - HistoryItem item = m_history.at(i); - stream << HISTORY_VERSION << item.url << item.dateTime << item.title; - out << data; - } - tempFile.close(); - - if (saveAll) - { - if (historyFile.exists() && !historyFile.remove()) - { - kWarning() << "History: error removing old history." << historyFile.errorString(); - } - if (!tempFile.rename(historyFile.fileName())) - { - kWarning() << "History: error moving new history over old." << tempFile.errorString() << historyFile.fileName(); - } - } - m_lastSavedUrl = m_history.value(0).url; -} - - -KCompletion * HistoryManager::completionObject() const -{ - return m_completion; -} diff --git a/src/history/history.h b/src/history/history.h deleted file mode 100644 index ff3b4381..00000000 --- a/src/history/history.h +++ /dev/null @@ -1,161 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008 Benjamin C. Meyer -* Copyright (C) 2008-2009 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 HISTORY_H -#define HISTORY_H - - -// KDE Includes -#include - -// Qt Includes -#include -#include -#include -#include -#include -#include - - -/** - * Elements in this class represent an history item - * - */ -class HistoryItem -{ -public: - HistoryItem() {} - explicit HistoryItem(const QString &u, - const QDateTime &d = QDateTime(), - const QString &t = QString() - ) - : title(t), url(u), dateTime(d) {} - - inline bool operator==(const HistoryItem &other) const - { - return other.title == title - && other.url == url && other.dateTime == dateTime; - } - - // history is sorted in reverse - inline bool operator <(const HistoryItem &other) const - { - return dateTime > other.dateTime; - } - - QString title; - QString url; - QDateTime dateTime; -}; - - - -// --------------------------------------------------------------------------------------------------------------- - - -// Forward Declarations -class AutoSaver; -class HistoryModel; -class HistoryFilterModel; -class HistoryTreeModel; - -class KCompletion; - - -/** - * THE History Manager: - * It manages rekonq history - * - */ -class HistoryManager : public QWebHistoryInterface -{ - Q_OBJECT - Q_PROPERTY(int historyLimit READ historyLimit WRITE setHistoryLimit) - -signals: - void historyReset(); - void entryAdded(const HistoryItem &item); - void entryRemoved(const HistoryItem &item); - void entryUpdated(int offset); - -public: - HistoryManager(QObject *parent = 0); - ~HistoryManager(); - - bool historyContains(const QString &url) const; - void addHistoryEntry(const QString &url); - void updateHistoryEntry(const KUrl &url, const QString &title); - void removeHistoryEntry(const KUrl &url, const QString &title = QString()); - - int historyLimit() const; - void setHistoryLimit(int limit); - - QList history() const; - void setHistory(const QList &history, bool loadedAndSorted = false); - - // History manager keeps around these models for use by the completer and other classes - HistoryModel *historyModel() const; - HistoryFilterModel *historyFilterModel() const; - HistoryTreeModel *historyTreeModel() const; - - /** - * @returns the KCompletion object. - */ - KCompletion *completionObject() const; - -public slots: - void clear(); - void loadSettings(); - -private slots: - void save(); - void checkForExpired(); - -protected: - void addHistoryEntry(const HistoryItem &item); - void removeHistoryEntry(const HistoryItem &item); - -private: - void load(); - - AutoSaver *m_saveTimer; - int m_historyLimit; - QTimer m_expiredTimer; - QList m_history; - QString m_lastSavedUrl; - - HistoryModel *m_historyModel; - HistoryFilterModel *m_historyFilterModel; - HistoryTreeModel *m_historyTreeModel; - - // the completion object we sync with - KCompletion *m_completion; -}; - - -#endif // HISTORY_H diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp new file mode 100644 index 00000000..29bdb45b --- /dev/null +++ b/src/history/historymanager.cpp @@ -0,0 +1,454 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008 Benjamin C. Meyer +* Copyright (C) 2008-2009 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 . +* +* ============================================================ */ + + +// Self Includes +#include "historymanager.h" +#include "historymanager.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "historymodels.h" +#include "autosaver.h" +#include "application.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +// generic algorithms +#include + + +static const unsigned int HISTORY_VERSION = 23; + + +HistoryManager::HistoryManager(QObject *parent) + : QWebHistoryInterface(parent) + , m_saveTimer(new AutoSaver(this)) + , m_historyLimit(30) + , m_historyModel(0) + , m_historyFilterModel(0) + , m_historyTreeModel(0) + , m_completion(0) +{ + // take care of the completion object + m_completion = new KCompletion; + m_completion->setOrder( KCompletion::Weighted ); + + m_expiredTimer.setSingleShot(true); + connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired())); + connect(this, SIGNAL(entryAdded(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); + connect(this, SIGNAL(entryRemoved(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); + + load(); + + m_historyModel = new HistoryModel(this, this); + m_historyFilterModel = new HistoryFilterModel(m_historyModel, this); + m_historyTreeModel = new HistoryTreeModel(m_historyFilterModel, this); + + // QWebHistoryInterface will delete the history manager + QWebHistoryInterface::setDefaultInterface(this); +} + + +HistoryManager::~HistoryManager() +{ + m_saveTimer->saveIfNeccessary(); + delete m_completion; +} + + +QList HistoryManager::history() const +{ + return m_history; +} + + +bool HistoryManager::historyContains(const QString &url) const +{ + return m_historyFilterModel->historyContains(url); +} + + +void HistoryManager::addHistoryEntry(const QString &url) +{ + QUrl cleanUrl(url); + + // don't store about: urls (home page related) + if(cleanUrl.scheme() == QString("about")) + return; + + cleanUrl.setPassword(QString()); + cleanUrl.setHost(cleanUrl.host().toLower()); + HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime()); + addHistoryEntry(item); + + // Add item to completion object + QString _url(url); + _url.remove(QRegExp("^http://|/$")); + m_completion->addItem(_url); +} + + +void HistoryManager::setHistory(const QList &history, bool loadedAndSorted) +{ + m_history = history; + + // verify that it is sorted by date + if (!loadedAndSorted) + qSort(m_history.begin(), m_history.end()); + + checkForExpired(); + + if (loadedAndSorted) + { + m_lastSavedUrl = m_history.value(0).url; + } + else + { + m_lastSavedUrl.clear(); + m_saveTimer->changeOccurred(); + } + emit historyReset(); +} + + +HistoryModel *HistoryManager::historyModel() const +{ + return m_historyModel; +} + + +HistoryFilterModel *HistoryManager::historyFilterModel() const +{ + return m_historyFilterModel; +} + + +HistoryTreeModel *HistoryManager::historyTreeModel() const +{ + return m_historyTreeModel; +} + + +void HistoryManager::checkForExpired() +{ + if (m_historyLimit < 0 || m_history.isEmpty()) + return; + + QDateTime now = QDateTime::currentDateTime(); + int nextTimeout = 0; + + while (!m_history.isEmpty()) + { + QDateTime checkForExpired = m_history.last().dateTime; + checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit)); + if (now.daysTo(checkForExpired) > 7) + { + // check at most in a week to prevent int overflows on the timer + nextTimeout = 7 * 86400; + } + else + { + nextTimeout = now.secsTo(checkForExpired); + } + if (nextTimeout > 0) + break; + HistoryItem item = m_history.takeLast(); + // remove from saved file also + m_lastSavedUrl.clear(); + emit entryRemoved(item); + } + + if (nextTimeout > 0) + m_expiredTimer.start(nextTimeout * 1000); +} + + +void HistoryManager::addHistoryEntry(const HistoryItem &item) +{ + QWebSettings *globalSettings = QWebSettings::globalSettings(); + if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) + return; + + m_history.prepend(item); + emit entryAdded(item); + + if (m_history.count() == 1) + checkForExpired(); +} + + +void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title) +{ + for (int i = 0; i < m_history.count(); ++i) + { + if (url == m_history.at(i).url) + { + m_history[i].title = title; + m_saveTimer->changeOccurred(); + if (m_lastSavedUrl.isEmpty()) + m_lastSavedUrl = m_history.at(i).url; + emit entryUpdated(i); + break; + } + } +} + + +void HistoryManager::removeHistoryEntry(const HistoryItem &item) +{ + m_lastSavedUrl.clear(); + m_history.removeOne(item); + emit entryRemoved(item); +} + + +void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title) +{ + for (int i = 0; i < m_history.count(); ++i) + { + if (url == m_history.at(i).url + && (title.isEmpty() || title == m_history.at(i).title)) + { + removeHistoryEntry(m_history.at(i)); + break; + } + } + + // Remove item from completion object + QString _url = url.path(); + _url.remove(QRegExp("^http://|/$")); + m_completion->removeItem(_url); +} + + +int HistoryManager::historyLimit() const +{ + return m_historyLimit; +} + + +void HistoryManager::setHistoryLimit(int limit) +{ + if (m_historyLimit == limit) + return; + m_historyLimit = limit; + checkForExpired(); + m_saveTimer->changeOccurred(); +} + + +void HistoryManager::clear() +{ + m_history.clear(); + m_lastSavedUrl.clear(); + m_saveTimer->changeOccurred(); + m_saveTimer->saveIfNeccessary(); + historyReset(); +} + + +void HistoryManager::loadSettings() +{ + int historyExpire = ReKonfig::expireHistory(); + int days; + switch (historyExpire) + { + case 0: days = 1; break; + case 1: days = 7; break; + case 2: days = 14; break; + case 3: days = 30; break; + case 4: days = 365; break; + case 5: days = -1; break; + default: days = -1; + } + m_historyLimit = days; +} + + +void HistoryManager::load() +{ + loadSettings(); + + QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); + QFile historyFile(historyFilePath); + if (!historyFile.exists()) + return; + if (!historyFile.open(QFile::ReadOnly)) + { + kWarning() << "Unable to open history file" << historyFile.fileName(); + return; + } + + QList list; + QDataStream in(&historyFile); + // Double check that the history file is sorted as it is read in + bool needToSort = false; + HistoryItem lastInsertedItem; + QByteArray data; + QDataStream stream; + QBuffer buffer; + stream.setDevice(&buffer); + while (!historyFile.atEnd()) + { + in >> data; + buffer.close(); + buffer.setBuffer(&data); + buffer.open(QIODevice::ReadOnly); + quint32 ver; + stream >> ver; + if (ver != HISTORY_VERSION) + continue; + HistoryItem item; + stream >> item.url; + stream >> item.dateTime; + stream >> item.title; + + if (!item.dateTime.isValid()) + continue; + + if (item == lastInsertedItem) + { + if (lastInsertedItem.title.isEmpty() && !list.isEmpty()) + list[0].title = item.title; + continue; + } + + if (!needToSort && !list.isEmpty() && lastInsertedItem < item) + needToSort = true; + + list.prepend(item); + lastInsertedItem = item; + + // Add item to completion object + QString _url = item.url; + _url.remove(QRegExp("^http://|/$")); + m_completion->addItem(_url); + } + if (needToSort) + qSort(list.begin(), list.end()); + + setHistory(list, true); + + // If we had to sort re-write the whole history sorted + if (needToSort) + { + m_lastSavedUrl.clear(); + m_saveTimer->changeOccurred(); + } +} + + +void HistoryManager::save() +{ + bool saveAll = m_lastSavedUrl.isEmpty(); + int first = m_history.count() - 1; + if (!saveAll) + { + // find the first one to save + for (int i = 0; i < m_history.count(); ++i) + { + if (m_history.at(i).url == m_lastSavedUrl) + { + first = i - 1; + break; + } + } + } + if (first == m_history.count() - 1) + saveAll = true; + + QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); + QFile historyFile(historyFilePath); + + // When saving everything use a temporary file to prevent possible data loss. + QTemporaryFile tempFile; + tempFile.setAutoRemove(false); + bool open = false; + if (saveAll) + { + open = tempFile.open(); + } + else + { + open = historyFile.open(QFile::Append); + } + + if (!open) + { + kWarning() << "Unable to open history file for saving" + << (saveAll ? tempFile.fileName() : historyFile.fileName()); + return; + } + + QDataStream out(saveAll ? &tempFile : &historyFile); + for (int i = first; i >= 0; --i) + { + QByteArray data; + QDataStream stream(&data, QIODevice::WriteOnly); + HistoryItem item = m_history.at(i); + stream << HISTORY_VERSION << item.url << item.dateTime << item.title; + out << data; + } + tempFile.close(); + + if (saveAll) + { + if (historyFile.exists() && !historyFile.remove()) + { + kWarning() << "History: error removing old history." << historyFile.errorString(); + } + if (!tempFile.rename(historyFile.fileName())) + { + kWarning() << "History: error moving new history over old." << tempFile.errorString() << historyFile.fileName(); + } + } + m_lastSavedUrl = m_history.value(0).url; +} + + +KCompletion * HistoryManager::completionObject() const +{ + return m_completion; +} diff --git a/src/history/historymanager.h b/src/history/historymanager.h new file mode 100644 index 00000000..ff3b4381 --- /dev/null +++ b/src/history/historymanager.h @@ -0,0 +1,161 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008 Benjamin C. Meyer +* Copyright (C) 2008-2009 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 HISTORY_H +#define HISTORY_H + + +// KDE Includes +#include + +// Qt Includes +#include +#include +#include +#include +#include +#include + + +/** + * Elements in this class represent an history item + * + */ +class HistoryItem +{ +public: + HistoryItem() {} + explicit HistoryItem(const QString &u, + const QDateTime &d = QDateTime(), + const QString &t = QString() + ) + : title(t), url(u), dateTime(d) {} + + inline bool operator==(const HistoryItem &other) const + { + return other.title == title + && other.url == url && other.dateTime == dateTime; + } + + // history is sorted in reverse + inline bool operator <(const HistoryItem &other) const + { + return dateTime > other.dateTime; + } + + QString title; + QString url; + QDateTime dateTime; +}; + + + +// --------------------------------------------------------------------------------------------------------------- + + +// Forward Declarations +class AutoSaver; +class HistoryModel; +class HistoryFilterModel; +class HistoryTreeModel; + +class KCompletion; + + +/** + * THE History Manager: + * It manages rekonq history + * + */ +class HistoryManager : public QWebHistoryInterface +{ + Q_OBJECT + Q_PROPERTY(int historyLimit READ historyLimit WRITE setHistoryLimit) + +signals: + void historyReset(); + void entryAdded(const HistoryItem &item); + void entryRemoved(const HistoryItem &item); + void entryUpdated(int offset); + +public: + HistoryManager(QObject *parent = 0); + ~HistoryManager(); + + bool historyContains(const QString &url) const; + void addHistoryEntry(const QString &url); + void updateHistoryEntry(const KUrl &url, const QString &title); + void removeHistoryEntry(const KUrl &url, const QString &title = QString()); + + int historyLimit() const; + void setHistoryLimit(int limit); + + QList history() const; + void setHistory(const QList &history, bool loadedAndSorted = false); + + // History manager keeps around these models for use by the completer and other classes + HistoryModel *historyModel() const; + HistoryFilterModel *historyFilterModel() const; + HistoryTreeModel *historyTreeModel() const; + + /** + * @returns the KCompletion object. + */ + KCompletion *completionObject() const; + +public slots: + void clear(); + void loadSettings(); + +private slots: + void save(); + void checkForExpired(); + +protected: + void addHistoryEntry(const HistoryItem &item); + void removeHistoryEntry(const HistoryItem &item); + +private: + void load(); + + AutoSaver *m_saveTimer; + int m_historyLimit; + QTimer m_expiredTimer; + QList m_history; + QString m_lastSavedUrl; + + HistoryModel *m_historyModel; + HistoryFilterModel *m_historyFilterModel; + HistoryTreeModel *m_historyTreeModel; + + // the completion object we sync with + KCompletion *m_completion; +}; + + +#endif // HISTORY_H diff --git a/src/history/historymodels.h b/src/history/historymodels.h index cb8bea41..08f3f63e 100644 --- a/src/history/historymodels.h +++ b/src/history/historymodels.h @@ -31,7 +31,7 @@ // Local Includes -#include "history.h" +#include "historymanager.h" // KDE Includes #include diff --git a/src/history/sidepanel.cpp b/src/history/sidepanel.cpp new file mode 100644 index 00000000..7c42301c --- /dev/null +++ b/src/history/sidepanel.cpp @@ -0,0 +1,60 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* +* +* 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 "sidepanel.h" +#include "sidepanel.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "historypanel.h" + + +SidePanel::SidePanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) + : QDockWidget(title, parent, flags) + , m_historyPanel(new HistoryPanel(this)) +{ + setObjectName("sidePanel"); + setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + setShown(ReKonfig::showSideBar()); + + connect(m_historyPanel, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); + + setWidget(m_historyPanel); +} + + +SidePanel::~SidePanel() +{ + // Save side panel's state + ReKonfig::setShowSideBar(!isHidden()); + + delete m_historyPanel; +} diff --git a/src/history/sidepanel.h b/src/history/sidepanel.h new file mode 100644 index 00000000..6aca3587 --- /dev/null +++ b/src/history/sidepanel.h @@ -0,0 +1,58 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* +* +* 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 SIDEPANEL_H +#define SIDEPANEL_H + +// Local Includes +#include "application.h" + +// Qt Includes +#include + +// Forward Declarations +class KUrl; +class HistoryPanel; + + +class SidePanel : public QDockWidget +{ + Q_OBJECT + +public: + explicit SidePanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~SidePanel(); + +signals: + void openUrl(const KUrl &); + +private: + HistoryPanel *m_historyPanel; + +}; + +#endif // SIDEPANEL_H diff --git a/src/lineedit.cpp b/src/lineedit.cpp deleted file mode 100644 index f3c93e8e..00000000 --- a/src/lineedit.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin -* -* -* 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 "lineedit.h" -#include "lineedit.moc" - -// Qt Includes -#include -#include -#include - - -LineEdit::LineEdit(QWidget* parent) - : KLineEdit(parent) -{ - setMinimumWidth(200); - setFocusPolicy(Qt::WheelFocus); - setHandleSignals(true); - setClearButtonShown(true); -} - - -LineEdit::~LineEdit() -{ -} - - -void LineEdit::keyPressEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_Escape) - { - clearFocus(); - event->accept(); - } - - KLineEdit::keyPressEvent(event); -} - - -void LineEdit::mouseDoubleClickEvent(QMouseEvent *) -{ - selectAll(); -} diff --git a/src/lineedit.h b/src/lineedit.h deleted file mode 100644 index 67ded052..00000000 --- a/src/lineedit.h +++ /dev/null @@ -1,55 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin -* -* -* 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 LINEEDIT_H -#define LINEEDIT_H - - -// KDE Includes -#include - -// Forward Declarations -class QContextMenuEvent; -class QFocusEvent; -class QKeyEvent; - - -class LineEdit : public KLineEdit -{ - Q_OBJECT - -public: - explicit LineEdit(QWidget *parent = 0); - virtual ~LineEdit(); - -protected: - virtual void keyPressEvent(QKeyEvent*); - virtual void mouseDoubleClickEvent(QMouseEvent *); -}; - -#endif // LINEEDIT_H diff --git a/src/mainview.cpp b/src/mainview.cpp index ebcad088..f4598f22 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -35,10 +35,7 @@ // Local Includes #include "tabbar.h" -#include "application.h" -#include "history.h" #include "urlbar.h" -#include "webview.h" #include "sessionmanager.h" // KDE Includes @@ -50,6 +47,7 @@ #include #include #include +#include // Qt Includes #include diff --git a/src/mainview.h b/src/mainview.h index 9c8a24aa..af957da2 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -35,7 +35,7 @@ #include "webview.h" #include "webpage.h" #include "application.h" -#include "history.h" +#include "historymanager.h" #include "mainwindow.h" // KDE Includes diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f2809beb..628743ee 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -34,15 +34,14 @@ #include "rekonq.h" // Local Includes -#include "application.h" #include "settingsdialog.h" -#include "history.h" -#include "bookmarks.h" +#include "historymanager.h" +#include "bookmarksmanager.h" #include "webview.h" #include "mainview.h" #include "findbar.h" #include "sidepanel.h" -#include "bookmarkspanel/bookmarkspanel.h" +#include "bookmarkspanel.h" #include "urlbar.h" #include "tabbar.h" #include "newtabpage.h" diff --git a/src/mainwindow.h b/src/mainwindow.h index 64ce6967..d47b0d50 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,13 +31,13 @@ // Local Includes -#include "bookmarks.h" -#include "webview.h" +#include "application.h" // KDE Includes #include #include #include +#include // Forward Declarations class QWebFrame; diff --git a/src/previewimage.cpp b/src/previewimage.cpp index 6d5b598d..80757ca2 100644 --- a/src/previewimage.cpp +++ b/src/previewimage.cpp @@ -30,7 +30,7 @@ // Local Includes #include "application.h" -#include "history.h" +#include "historymanager.h" #include "rekonq.h" #include "mainwindow.h" #include "mainview.h" diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp index b34990fc..4a7a72e0 100644 --- a/src/rekonqpage/newtabpage.cpp +++ b/src/rekonqpage/newtabpage.cpp @@ -32,7 +32,7 @@ // Local Includes #include "historymodels.h" -#include "bookmarks.h" +#include "bookmarksmanager.h" #include "application.h" #include "mainwindow.h" #include "mainview.h" diff --git a/src/sidepanel.cpp b/src/sidepanel.cpp deleted file mode 100644 index 7c42301c..00000000 --- a/src/sidepanel.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* -* -* 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 "sidepanel.h" -#include "sidepanel.moc" - -// Auto Includes -#include "rekonq.h" - -// Local Includes -#include "historypanel.h" - - -SidePanel::SidePanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) - : QDockWidget(title, parent, flags) - , m_historyPanel(new HistoryPanel(this)) -{ - setObjectName("sidePanel"); - setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - - setShown(ReKonfig::showSideBar()); - - connect(m_historyPanel, SIGNAL(openUrl(const KUrl&)), this, SIGNAL(openUrl(const KUrl&))); - - setWidget(m_historyPanel); -} - - -SidePanel::~SidePanel() -{ - // Save side panel's state - ReKonfig::setShowSideBar(!isHidden()); - - delete m_historyPanel; -} diff --git a/src/sidepanel.h b/src/sidepanel.h deleted file mode 100644 index 6aca3587..00000000 --- a/src/sidepanel.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2009 by Andrea Diamantini -* Copyright (C) 2009 by Paweł Prażak -* -* -* 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 SIDEPANEL_H -#define SIDEPANEL_H - -// Local Includes -#include "application.h" - -// Qt Includes -#include - -// Forward Declarations -class KUrl; -class HistoryPanel; - - -class SidePanel : public QDockWidget -{ - Q_OBJECT - -public: - explicit SidePanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); - ~SidePanel(); - -signals: - void openUrl(const KUrl &); - -private: - HistoryPanel *m_historyPanel; - -}; - -#endif // SIDEPANEL_H diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 6fdf4346..1246d669 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -45,6 +45,7 @@ #include #include #include +#include // Qt Includes #include diff --git a/src/urlbar.cpp b/src/urlbar.cpp deleted file mode 100644 index 2adfcd17..00000000 --- a/src/urlbar.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Domrachev Alexandr -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin -* -* -* 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 "urlbar.h" -#include "urlbar.moc" - -// Local Includes -#include "application.h" -#include "historymodels.h" -#include "lineedit.h" -#include "mainwindow.h" -#include "webview.h" - -// KDE Includes -#include -#include -#include - -// Qt Includes -#include -#include -#include - - -QColor UrlBar::s_defaultBaseColor; - - -UrlBar::UrlBar(QWidget *parent) - : KHistoryComboBox(true, parent) - , m_lineEdit(new LineEdit) - , m_progress(0) -{ - setUrlDropsEnabled(true); - setAutoDeleteCompletionObject(true); - - //cosmetic - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - setMinimumWidth(180); - - setTrapReturnKey(true); - - setupLineEdit(); - - // add every item to history - connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&))); - connect(completionBox(), SIGNAL(activated(const QString&)), SLOT(activated(const QString&))); - - connect(this, SIGNAL(cleared()), SLOT(cleared())); - - // setup completion box - setCompletionObject( Application::historyManager()->completionObject() ); - - // set dropdown list background - QPalette p = view()->palette(); - p.setColor(QPalette::Base, palette().color(QPalette::Base)); - view()->setPalette(p); - - // load urls on activated urlbar signal - connect(this, SIGNAL(activated(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&))); -} - - -UrlBar::~UrlBar() -{ -} - - -void UrlBar::selectAll() const -{ - lineEdit()->selectAll(); -} - - -KUrl UrlBar::url() const -{ - return m_currentUrl; -} - - -KLineEdit *UrlBar::lineEdit() const -{ - return m_lineEdit; -} - - -void UrlBar::setupLineEdit() -{ - // Make m_lineEdit background transparent - QPalette p = m_lineEdit->palette(); - p.setColor(QPalette::Base, Qt::transparent); - m_lineEdit->setPalette(p); - - if (!s_defaultBaseColor.isValid()) - { - s_defaultBaseColor = palette().color(QPalette::Base); - } - - setLineEdit(m_lineEdit); - - // Make the lineedit consume the Qt::Key_Enter event... - lineEdit()->setTrapReturnKey(true); - - lineEdit()->setHandleSignals(true); - - // clear the URL bar - lineEdit()->clear(); -} - - -void UrlBar::setUrl(const QUrl& url) -{ - if(url.scheme() == "about") - { - m_currentUrl = ""; - setFocus(); - } - else - m_currentUrl = url; - - updateUrl(); -} - - -void UrlBar::setProgress(int progress) -{ - m_progress = progress; - repaint(); -} - - -void UrlBar::updateUrl() -{ - // Don't change my typed url... - // FIXME this is not a proper solution (also if it works...) - if(hasFocus()) - { - kDebug() << "Don't change my typed url..."; - return; - } - - KIcon icon; - if(m_currentUrl.isEmpty()) icon = KIcon("arrow-right"); - else icon = Application::icon(m_currentUrl); - - if (count()) - { - changeUrl(0, icon, m_currentUrl); - } - else - { - insertUrl(0, icon, m_currentUrl); - } - - setCurrentIndex(0); - - // important security consideration: always display the beginning - // of the url rather than its end to prevent spoofing attempts. - // Must be AFTER setCurrentIndex - if (!hasFocus()) - { - lineEdit()->setCursorPosition(0); - } -} - - -void UrlBar::activated(const QString& url) -{ - if (url.isEmpty()) - return; - - setUrl(url); - - Application::historyManager()->addHistoryEntry(url); - - emit activated(m_currentUrl); -} - - -void UrlBar::cleared() -{ - // clear the history on user's request from context menu - clear(); - Application::historyManager()->clear(); -} - - -void UrlBar::loadFinished(bool) -{ - // reset progress bar after small delay - m_progress = 0; - QTimer::singleShot(200, this, SLOT(repaint())); -} - - -void UrlBar::updateProgress(int progress) -{ - m_progress = progress; - repaint(); -} - - -void UrlBar::paintEvent(QPaintEvent *event) -{ - // set background color of UrlBar - QPalette p = palette(); - p.setColor(QPalette::Base, s_defaultBaseColor); - setPalette(p); - - KHistoryComboBox::paintEvent(event); - - if (!hasFocus()) - { - QPainter painter(this); - - QColor loadingColor; - if (m_currentUrl.scheme() == QLatin1String("https")) - { - loadingColor = QColor(248, 248, 100); - } - else - { - loadingColor = QColor(116, 192, 250); - } - painter.setBrush(generateGradient(loadingColor, height())); - painter.setPen(Qt::transparent); - - QRect backgroundRect = lineEdit()->frameGeometry(); - int mid = backgroundRect.width() * m_progress / 100; - QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); - painter.drawRect(progressRect); - painter.end(); - } -} - - -void UrlBar::focusOutEvent(QFocusEvent *event) -{ - // set back last loaded url in case user cleared it - if (!m_currentUrl.equals(KUrl(lineEdit()->text()))) setUrl(m_currentUrl); - - KHistoryComboBox::focusOutEvent(event); -} - - -QSize UrlBar::sizeHint() const -{ - return lineEdit()->sizeHint(); -} - - -QLinearGradient UrlBar::generateGradient(const QColor &color, int height) -{ - QColor base = s_defaultBaseColor; - base.setAlpha(0); - QColor barColor = color; - barColor.setAlpha(200); - QLinearGradient gradient(0, 0, 0, height); - gradient.setColorAt(0, base); - gradient.setColorAt(0.25, barColor.lighter(120)); - gradient.setColorAt(0.5, barColor); - gradient.setColorAt(0.75, barColor.lighter(120)); - gradient.setColorAt(1, base); - return gradient; -} - - -void UrlBar::setBackgroundColor(QColor c) -{ - s_defaultBaseColor=c; - repaint(); -} - - -bool UrlBar::isLoading() -{ - if(m_progress == 0) - { - return false; - } - return true; -} - -void UrlBar::keyPressEvent(QKeyEvent *event) -{ - QString currentText = m_lineEdit->text().trimmed(); - if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) - && !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)) - { - QString append; - if (event->modifiers() == Qt::ControlModifier) - { - append = QLatin1String(".com"); - } - else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) - { - append = QLatin1String(".org"); - } - else if (event->modifiers() == Qt::ShiftModifier) - { - append = QLatin1String(".net"); - } - - QUrl url(QLatin1String("http://www.") + currentText); - QString host = url.host(); - if (!host.endsWith(append, Qt::CaseInsensitive)) - { - host += append; - url.setHost(host); - m_lineEdit->setText(url.toString()); - } - } - - KHistoryComboBox::keyPressEvent(event); -} - diff --git a/src/urlbar.h b/src/urlbar.h deleted file mode 100644 index 0e8bab26..00000000 --- a/src/urlbar.h +++ /dev/null @@ -1,99 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2008-2009 by Andrea Diamantini -* Copyright (C) 2009 by Domrachev Alexandr -* Copyright (C) 2009 by Paweł Prażak -* Copyright (C) 2009 by Lionel Chauvin -* -* -* 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 URLBAR_H -#define URLBAR_H - - -// Local Includes -#include "lineedit.h" - -// KDE Includes -#include -#include - -// Qt Includes -#include - -// Forward Declarations -class QLinearGradient; -class QWidget; -class KCompletion; - - -class UrlBar : public KHistoryComboBox -{ - Q_OBJECT - -public: - UrlBar(QWidget *parent = 0); - ~UrlBar(); - - void selectAll() const; - KUrl url() const; - QSize sizeHint() const; - void setBackgroundColor(QColor); - bool isLoading(); - - void setProgress(int progress); - -signals: - void activated(const KUrl&); - -public slots: - void setUrl(const QUrl &url); - void updateProgress(int progress); - void updateUrl(); - -private slots: - void activated(const QString& url); - void loadFinished(bool); - void cleared(); - -protected: - virtual void paintEvent(QPaintEvent *event); - virtual void focusOutEvent(QFocusEvent *event); - virtual void keyPressEvent(QKeyEvent *event); - -private: - void setupLineEdit(); - - KLineEdit *lineEdit() const; - - static QLinearGradient generateGradient(const QColor &color, int height); - - static QColor s_defaultBaseColor; - - LineEdit *m_lineEdit; - - KUrl m_currentUrl; - int m_progress; -}; - -#endif diff --git a/src/urlbar/lineedit.cpp b/src/urlbar/lineedit.cpp new file mode 100644 index 00000000..f3c93e8e --- /dev/null +++ b/src/urlbar/lineedit.cpp @@ -0,0 +1,69 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* Copyright (C) 2009 by Lionel Chauvin +* +* +* 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 "lineedit.h" +#include "lineedit.moc" + +// Qt Includes +#include +#include +#include + + +LineEdit::LineEdit(QWidget* parent) + : KLineEdit(parent) +{ + setMinimumWidth(200); + setFocusPolicy(Qt::WheelFocus); + setHandleSignals(true); + setClearButtonShown(true); +} + + +LineEdit::~LineEdit() +{ +} + + +void LineEdit::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Escape) + { + clearFocus(); + event->accept(); + } + + KLineEdit::keyPressEvent(event); +} + + +void LineEdit::mouseDoubleClickEvent(QMouseEvent *) +{ + selectAll(); +} diff --git a/src/urlbar/lineedit.h b/src/urlbar/lineedit.h new file mode 100644 index 00000000..67ded052 --- /dev/null +++ b/src/urlbar/lineedit.h @@ -0,0 +1,55 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* Copyright (C) 2009 by Paweł Prażak +* Copyright (C) 2009 by Lionel Chauvin +* +* +* 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 LINEEDIT_H +#define LINEEDIT_H + + +// KDE Includes +#include + +// Forward Declarations +class QContextMenuEvent; +class QFocusEvent; +class QKeyEvent; + + +class LineEdit : public KLineEdit +{ + Q_OBJECT + +public: + explicit LineEdit(QWidget *parent = 0); + virtual ~LineEdit(); + +protected: + virtual void keyPressEvent(QKeyEvent*); + virtual void mouseDoubleClickEvent(QMouseEvent *); +}; + +#endif // LINEEDIT_H diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp new file mode 100644 index 00000000..2adfcd17 --- /dev/null +++ b/src/urlbar/urlbar.cpp @@ -0,0 +1,342 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 by Domrachev Alexandr +* Copyright (C) 2009 by Paweł Prażak +* Copyright (C) 2009 by Lionel Chauvin +* +* +* 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 "urlbar.h" +#include "urlbar.moc" + +// Local Includes +#include "application.h" +#include "historymodels.h" +#include "lineedit.h" +#include "mainwindow.h" +#include "webview.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include +#include +#include + + +QColor UrlBar::s_defaultBaseColor; + + +UrlBar::UrlBar(QWidget *parent) + : KHistoryComboBox(true, parent) + , m_lineEdit(new LineEdit) + , m_progress(0) +{ + setUrlDropsEnabled(true); + setAutoDeleteCompletionObject(true); + + //cosmetic + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + setMinimumWidth(180); + + setTrapReturnKey(true); + + setupLineEdit(); + + // add every item to history + connect(this, SIGNAL(returnPressed(const QString&)), SLOT(activated(const QString&))); + connect(completionBox(), SIGNAL(activated(const QString&)), SLOT(activated(const QString&))); + + connect(this, SIGNAL(cleared()), SLOT(cleared())); + + // setup completion box + setCompletionObject( Application::historyManager()->completionObject() ); + + // set dropdown list background + QPalette p = view()->palette(); + p.setColor(QPalette::Base, palette().color(QPalette::Base)); + view()->setPalette(p); + + // load urls on activated urlbar signal + connect(this, SIGNAL(activated(const KUrl&)), Application::instance(), SLOT(loadUrl(const KUrl&))); +} + + +UrlBar::~UrlBar() +{ +} + + +void UrlBar::selectAll() const +{ + lineEdit()->selectAll(); +} + + +KUrl UrlBar::url() const +{ + return m_currentUrl; +} + + +KLineEdit *UrlBar::lineEdit() const +{ + return m_lineEdit; +} + + +void UrlBar::setupLineEdit() +{ + // Make m_lineEdit background transparent + QPalette p = m_lineEdit->palette(); + p.setColor(QPalette::Base, Qt::transparent); + m_lineEdit->setPalette(p); + + if (!s_defaultBaseColor.isValid()) + { + s_defaultBaseColor = palette().color(QPalette::Base); + } + + setLineEdit(m_lineEdit); + + // Make the lineedit consume the Qt::Key_Enter event... + lineEdit()->setTrapReturnKey(true); + + lineEdit()->setHandleSignals(true); + + // clear the URL bar + lineEdit()->clear(); +} + + +void UrlBar::setUrl(const QUrl& url) +{ + if(url.scheme() == "about") + { + m_currentUrl = ""; + setFocus(); + } + else + m_currentUrl = url; + + updateUrl(); +} + + +void UrlBar::setProgress(int progress) +{ + m_progress = progress; + repaint(); +} + + +void UrlBar::updateUrl() +{ + // Don't change my typed url... + // FIXME this is not a proper solution (also if it works...) + if(hasFocus()) + { + kDebug() << "Don't change my typed url..."; + return; + } + + KIcon icon; + if(m_currentUrl.isEmpty()) icon = KIcon("arrow-right"); + else icon = Application::icon(m_currentUrl); + + if (count()) + { + changeUrl(0, icon, m_currentUrl); + } + else + { + insertUrl(0, icon, m_currentUrl); + } + + setCurrentIndex(0); + + // important security consideration: always display the beginning + // of the url rather than its end to prevent spoofing attempts. + // Must be AFTER setCurrentIndex + if (!hasFocus()) + { + lineEdit()->setCursorPosition(0); + } +} + + +void UrlBar::activated(const QString& url) +{ + if (url.isEmpty()) + return; + + setUrl(url); + + Application::historyManager()->addHistoryEntry(url); + + emit activated(m_currentUrl); +} + + +void UrlBar::cleared() +{ + // clear the history on user's request from context menu + clear(); + Application::historyManager()->clear(); +} + + +void UrlBar::loadFinished(bool) +{ + // reset progress bar after small delay + m_progress = 0; + QTimer::singleShot(200, this, SLOT(repaint())); +} + + +void UrlBar::updateProgress(int progress) +{ + m_progress = progress; + repaint(); +} + + +void UrlBar::paintEvent(QPaintEvent *event) +{ + // set background color of UrlBar + QPalette p = palette(); + p.setColor(QPalette::Base, s_defaultBaseColor); + setPalette(p); + + KHistoryComboBox::paintEvent(event); + + if (!hasFocus()) + { + QPainter painter(this); + + QColor loadingColor; + if (m_currentUrl.scheme() == QLatin1String("https")) + { + loadingColor = QColor(248, 248, 100); + } + else + { + loadingColor = QColor(116, 192, 250); + } + painter.setBrush(generateGradient(loadingColor, height())); + painter.setPen(Qt::transparent); + + QRect backgroundRect = lineEdit()->frameGeometry(); + int mid = backgroundRect.width() * m_progress / 100; + QRect progressRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height()); + painter.drawRect(progressRect); + painter.end(); + } +} + + +void UrlBar::focusOutEvent(QFocusEvent *event) +{ + // set back last loaded url in case user cleared it + if (!m_currentUrl.equals(KUrl(lineEdit()->text()))) setUrl(m_currentUrl); + + KHistoryComboBox::focusOutEvent(event); +} + + +QSize UrlBar::sizeHint() const +{ + return lineEdit()->sizeHint(); +} + + +QLinearGradient UrlBar::generateGradient(const QColor &color, int height) +{ + QColor base = s_defaultBaseColor; + base.setAlpha(0); + QColor barColor = color; + barColor.setAlpha(200); + QLinearGradient gradient(0, 0, 0, height); + gradient.setColorAt(0, base); + gradient.setColorAt(0.25, barColor.lighter(120)); + gradient.setColorAt(0.5, barColor); + gradient.setColorAt(0.75, barColor.lighter(120)); + gradient.setColorAt(1, base); + return gradient; +} + + +void UrlBar::setBackgroundColor(QColor c) +{ + s_defaultBaseColor=c; + repaint(); +} + + +bool UrlBar::isLoading() +{ + if(m_progress == 0) + { + return false; + } + return true; +} + +void UrlBar::keyPressEvent(QKeyEvent *event) +{ + QString currentText = m_lineEdit->text().trimmed(); + if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) + && !currentText.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)) + { + QString append; + if (event->modifiers() == Qt::ControlModifier) + { + append = QLatin1String(".com"); + } + else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) + { + append = QLatin1String(".org"); + } + else if (event->modifiers() == Qt::ShiftModifier) + { + append = QLatin1String(".net"); + } + + QUrl url(QLatin1String("http://www.") + currentText); + QString host = url.host(); + if (!host.endsWith(append, Qt::CaseInsensitive)) + { + host += append; + url.setHost(host); + m_lineEdit->setText(url.toString()); + } + } + + KHistoryComboBox::keyPressEvent(event); +} + diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h new file mode 100644 index 00000000..0e8bab26 --- /dev/null +++ b/src/urlbar/urlbar.h @@ -0,0 +1,99 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2008-2009 by Andrea Diamantini +* Copyright (C) 2009 by Domrachev Alexandr +* Copyright (C) 2009 by Paweł Prażak +* Copyright (C) 2009 by Lionel Chauvin +* +* +* 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 URLBAR_H +#define URLBAR_H + + +// Local Includes +#include "lineedit.h" + +// KDE Includes +#include +#include + +// Qt Includes +#include + +// Forward Declarations +class QLinearGradient; +class QWidget; +class KCompletion; + + +class UrlBar : public KHistoryComboBox +{ + Q_OBJECT + +public: + UrlBar(QWidget *parent = 0); + ~UrlBar(); + + void selectAll() const; + KUrl url() const; + QSize sizeHint() const; + void setBackgroundColor(QColor); + bool isLoading(); + + void setProgress(int progress); + +signals: + void activated(const KUrl&); + +public slots: + void setUrl(const QUrl &url); + void updateProgress(int progress); + void updateUrl(); + +private slots: + void activated(const QString& url); + void loadFinished(bool); + void cleared(); + +protected: + virtual void paintEvent(QPaintEvent *event); + virtual void focusOutEvent(QFocusEvent *event); + virtual void keyPressEvent(QKeyEvent *event); + +private: + void setupLineEdit(); + + KLineEdit *lineEdit() const; + + static QLinearGradient generateGradient(const QColor &color, int height); + + static QColor s_defaultBaseColor; + + LineEdit *m_lineEdit; + + KUrl m_currentUrl; + int m_progress; +}; + +#endif diff --git a/src/webview.cpp b/src/webview.cpp index f38d363e..c25b8903 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -37,11 +37,14 @@ #include "mainwindow.h" #include "mainview.h" #include "webpage.h" +#include "bookmarksmanager.h" // KDE Includes #include #include #include +#include +#include // Qt Includes #include -- cgit v1.2.1