summaryrefslogtreecommitdiff
path: root/src/bookmarks
diff options
context:
space:
mode:
Diffstat (limited to 'src/bookmarks')
-rw-r--r--src/bookmarks/bookmarkowner.cpp6
-rw-r--r--src/bookmarks/bookmarkprovider.cpp (renamed from src/bookmarks/bookmarksmanager.cpp)226
-rw-r--r--src/bookmarks/bookmarkprovider.h (renamed from src/bookmarks/bookmarksmanager.h)65
-rw-r--r--src/bookmarks/bookmarkscontextmenu.h6
-rw-r--r--src/bookmarks/bookmarkspanel.cpp2
-rw-r--r--src/bookmarks/bookmarkstoolbar.cpp2
-rw-r--r--src/bookmarks/bookmarkstoolbar.h7
-rw-r--r--src/bookmarks/bookmarkstreemodel.cpp25
8 files changed, 160 insertions, 179 deletions
diff --git a/src/bookmarks/bookmarkowner.cpp b/src/bookmarks/bookmarkowner.cpp
index f47b978d..862a7de4 100644
--- a/src/bookmarks/bookmarkowner.cpp
+++ b/src/bookmarks/bookmarkowner.cpp
@@ -32,13 +32,15 @@
// Local Includes
#include "application.h"
-#include "bookmarksmanager.h"
+#include "bookmarkprovider.h"
#include "mainwindow.h"
#include "webtab.h"
#include "mainview.h"
// KDE Includes
+#include <KAction>
#include <KBookmarkDialog>
+#include <KLocalizedString>
#include <KMessageBox>
// Qt Includes
@@ -163,7 +165,7 @@ void BookmarkOwner::openBookmarkFolder(const KBookmark &bookmark)
return;
}
- foreach (KUrl url, urlList)
+ Q_FOREACH(const KUrl &url, urlList)
{
emit openUrl(url, Rekonq::NewFocusedTab);
}
diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarkprovider.cpp
index dc545698..41704f58 100644
--- a/src/bookmarks/bookmarksmanager.cpp
+++ b/src/bookmarks/bookmarkprovider.cpp
@@ -28,17 +28,17 @@
// Self Includes
-#include "bookmarksmanager.h"
+#include "bookmarkprovider.h"
// Local Includes
#include "application.h"
-#include "mainwindow.h"
#include "bookmarkspanel.h"
#include "bookmarkscontextmenu.h"
#include "bookmarkstoolbar.h"
#include "bookmarkowner.h"
// KDE Includes
+#include <KActionCollection>
#include <KStandardDirs>
// Qt Includes
@@ -50,35 +50,27 @@ BookmarkProvider::BookmarkProvider(QObject *parent)
, m_manager(0)
, m_owner(0)
, m_actionCollection(new KActionCollection(this))
- , _bookmarkActionMenu(0)
{
kDebug() << "Loading Bookmarks Manager...";
- KUrl bookfile = KUrl("~/.kde/share/apps/konqueror/bookmarks.xml"); // share konqueror bookmarks
+ QString bookmarkFile = KStandardDirs::locate("data", "konqueror/bookmarks.xml"); // share konqueror's bookmarks
- if (!QFile::exists(bookfile.path()))
+ if (!QFile::exists(bookmarkFile))
{
- 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);
- }
+ bookmarkFile = KStandardDirs::locateLocal("appdata", "bookmarks.xml", true);
+ QFile bkms( KStandardDirs::locate("appdata" , "defaultbookmarks.xbel") );
+ bkms.copy(bookmarkFile);
}
- m_manager = KBookmarkManager::managerForFile(bookfile.path(), "rekonq");
+ m_manager = KBookmarkManager::managerForFile(bookmarkFile, "rekonq");
connect(m_manager, SIGNAL(changed(const QString &, const QString &)),
this, SLOT(slotBookmarksChanged(const QString &, const QString &)));
// setup menu
m_owner = new BookmarkOwner(m_manager, this);
- connect(m_owner, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &)), this, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType &)));
+ connect(m_owner, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType&)),
+ this, SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType&)));
KAction *a = KStandardAction::addBookmark(this, SLOT(slotAddBookmark()), this);
m_actionCollection->addAction(QL1S("rekonq_add_bookmark"), a);
@@ -89,12 +81,26 @@ BookmarkProvider::BookmarkProvider(QObject *parent)
BookmarkProvider::~BookmarkProvider()
{
- delete m_actionCollection;
- delete m_owner;
delete m_manager;
}
+KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent)
+{
+ kDebug() << "new Bookmarks menu...";
+
+ KMenu *menu = new KMenu(parent);
+ KActionMenu *bookmarkActionMenu = new KActionMenu(menu);
+ bookmarkActionMenu->setMenu(menu);
+ bookmarkActionMenu->setText(i18n("&Bookmarks"));
+ new BookmarkMenu(m_manager, m_owner, menu, m_actionCollection);
+
+ kDebug() << "new Bookmarks menu... DONE";
+
+ return bookmarkActionMenu;
+}
+
+
void BookmarkProvider::registerBookmarkBar(BookmarkToolBar *toolbar)
{
if (m_bookmarkToolBars.contains(toolbar))
@@ -104,40 +110,76 @@ void BookmarkProvider::registerBookmarkBar(BookmarkToolBar *toolbar)
m_bookmarkToolBars.append(toolbar);
toolbar->toolBar()->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(toolbar->toolBar(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenu(const QPoint &)));
+ connect(toolbar->toolBar(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(contextMenu(const QPoint&)));
kDebug() << "new bookmark bar... DONE!";
}
-void BookmarkProvider::removeToolBar(BookmarkToolBar *toolbar)
+void BookmarkProvider::removeBookmarkBar(BookmarkToolBar *toolbar)
{
m_bookmarkToolBars.removeOne(toolbar);
}
-void BookmarkProvider::slotBookmarksChanged(const QString &group, const QString &caller)
+void BookmarkProvider::registerBookmarkPanel(BookmarksPanel *panel)
{
- Q_UNUSED(group)
- Q_UNUSED(caller)
-
- foreach(BookmarkToolBar *bookmarkToolBar, m_bookmarkToolBars)
+ if (panel && !m_bookmarkPanels.contains(panel))
{
- if (bookmarkToolBar)
- {
- bookmarkToolBar->toolBar()->clear();
- fillBookmarkBar(bookmarkToolBar);
- }
+ m_bookmarkPanels.append(panel);
+ connect(panel, SIGNAL(expansionChanged()), this, SLOT(slotPanelChanged()));
}
}
-QAction *BookmarkProvider::actionByName(const QString &name)
+void BookmarkProvider::removeBookmarkPanel(BookmarksPanel *panel)
+{
+ if (!panel)
+ return;
+
+ m_bookmarkPanels.removeOne(panel);
+ panel->disconnect(this);
+
+ if (m_bookmarkPanels.isEmpty())
+ Application::bookmarkProvider()->bookmarkManager()->emitChanged();
+}
+
+
+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
+ return new QAction(this);
+}
+
+
+KBookmarkGroup BookmarkProvider::rootGroup()
+{
+ return m_manager->root();
+}
+
+
+QList<KBookmark> BookmarkProvider::find(const QString &text)
+{
+ QList<KBookmark> list;
+
+ KBookmarkGroup root = Application::bookmarkProvider()->rootGroup();
+ if (!root.isNull())
+ for (KBookmark bookmark = root.first(); !bookmark.isNull(); bookmark = root.next(bookmark))
+ find(&list, bookmark, text);
+
+ return list;
+}
+
+
+KBookmark BookmarkProvider::bookmarkForUrl(const KUrl &url)
+{
+ KBookmarkGroup root = rootGroup();
+ if (root.isNull())
+ return KBookmark();
+
+ return bookmarkForUrl(root, url);
}
@@ -150,7 +192,7 @@ void BookmarkProvider::contextMenu(const QPoint &point)
if (!bookmarkToolBar)
return;
- KBookmarkActionInterface* action = dynamic_cast<KBookmarkActionInterface *>(bookmarkToolBar->actionAt(point));
+ KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface*>(bookmarkToolBar->actionAt(point));
if (!action)
return;
@@ -159,18 +201,16 @@ void BookmarkProvider::contextMenu(const QPoint &point)
}
-KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent)
+void BookmarkProvider::slotBookmarksChanged(const QString& /*groupAddress*/, const QString& /*caller*/)
{
- kDebug() << "new Bookmarks Menu...";
-
- KMenu *menu = new KMenu(parent);
- _bookmarkActionMenu = new KActionMenu(parent);
- _bookmarkActionMenu->setMenu(menu);
- _bookmarkActionMenu->setText(i18n("&Bookmarks"));
- new BookmarkMenu(m_manager, m_owner, menu, m_actionCollection);
-
- kDebug() << "new Bookmarks Menu...DONE";
- return _bookmarkActionMenu;
+ foreach(BookmarkToolBar *bookmarkToolBar, m_bookmarkToolBars)
+ {
+ if (bookmarkToolBar)
+ {
+ bookmarkToolBar->toolBar()->clear();
+ fillBookmarkBar(bookmarkToolBar);
+ }
+ }
}
@@ -187,19 +227,19 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
KBookmarkActionMenu *menuAction = new KBookmarkActionMenu(bookmark.toGroup(), this);
menuAction->setDelayed(false);
new BookmarkMenu(bookmarkManager(), bookmarkOwner(), menuAction->menu(), bookmark.address());
+
connect(menuAction->menu(), SIGNAL(aboutToShow()), toolBar, SLOT(menuDisplayed()));
connect(menuAction->menu(), SIGNAL(aboutToHide()), toolBar, SLOT(menuHidden()));
+
toolBar->toolBar()->addAction(menuAction);
}
-
else if (bookmark.isSeparator())
{
toolBar->toolBar()->addSeparator();
}
-
else
{
- KBookmarkAction* action = new KBookmarkAction(bookmark, m_owner, this);
+ KBookmarkAction *action = new KBookmarkAction(bookmark, m_owner, this);
action->setIconText(action->iconText().replace('&', "&&"));
connect(action, SIGNAL(hovered()), toolBar, SLOT(actionHovered()));
toolBar->toolBar()->addAction(action);
@@ -209,82 +249,13 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar)
}
-KBookmarkGroup BookmarkProvider::rootGroup()
-{
- return m_manager->root();
-}
-
-
-QList<KBookmark> BookmarkProvider::find(QString text)
-{
- QList<KBookmark> list;
- KBookmarkGroup bookGroup = Application::bookmarkProvider()->rootGroup();
- if (bookGroup.isNull())
- {
- return list;
- }
-
- KBookmark bookmark = bookGroup.first();
- while (!bookmark.isNull())
- {
- list = find(list, bookmark, text);
- bookmark = bookGroup.next(bookmark);
- }
-
- return list;
-}
-
-
-QList<KBookmark> BookmarkProvider::find(QList<KBookmark> list, const KBookmark &bookmark, QString text)
-{
- if (bookmark.isGroup())
- {
- KBookmarkGroup group = bookmark.toGroup();
- KBookmark bm = group.first();
- while (!bm.isNull())
- {
- list = find(list, bm, text); // it is .bookfolder
- bm = group.next(bm);
- }
- }
- else if (bookmark.url().url().contains(text) || bookmark.fullText().contains(text))
- {
- list << bookmark;
- }
-
- return list;
-}
-
-
void BookmarkProvider::slotAddBookmark()
{
- KBookmarkGroup parentBookmark = rootGroup();
- parentBookmark.addBookmark(bookmarkOwner()->currentTitle(), bookmarkOwner()->currentUrl());
+ rootGroup().addBookmark(bookmarkOwner()->currentTitle(), bookmarkOwner()->currentUrl());
bookmarkManager()->emitChanged();
}
-void BookmarkProvider::registerBookmarkPanel(BookmarksPanel *panel)
-{
- if (panel && !m_bookmarkPanels.contains(panel))
- {
- m_bookmarkPanels.append(panel);
- connect(panel, SIGNAL(expansionChanged()), this, SLOT(slotPanelChanged()));
- }
-}
-
-
-void BookmarkProvider::removeBookmarkPanel(BookmarksPanel *panel)
-{
- m_bookmarkPanels.removeOne(panel);
-
- if (m_bookmarkPanels.isEmpty())
- {
- Application::bookmarkProvider()->bookmarkManager()->emitChanged();
- }
-}
-
-
void BookmarkProvider::slotPanelChanged()
{
foreach (BookmarksPanel *panel, m_bookmarkPanels)
@@ -295,17 +266,18 @@ void BookmarkProvider::slotPanelChanged()
}
-KBookmark BookmarkProvider::bookmarkForUrl(const KUrl &url)
+void BookmarkProvider::find(QList<KBookmark> *list, const KBookmark &bookmark, const QString &text)
{
- KBookmark found;
-
- KBookmarkGroup root = rootGroup();
- if (root.isNull())
+ if (bookmark.isGroup())
{
- return found;
+ KBookmarkGroup group = bookmark.toGroup();
+ for (KBookmark bm = group.first(); !bm.isNull(); bm = group.next(bm))
+ find(list, bm, text);
+ }
+ else if (bookmark.url().url().contains(text) || bookmark.fullText().contains(text))
+ {
+ *list << bookmark;
}
-
- return bookmarkForUrl(root, url);
}
diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarkprovider.h
index 0c2b9ee2..e21bd227 100644
--- a/src/bookmarks/bookmarksmanager.h
+++ b/src/bookmarks/bookmarkprovider.h
@@ -27,30 +27,38 @@
* ============================================================ */
-#ifndef BOOKMARKS_H
-#define BOOKMARKS_H
+#ifndef BOOKMARKPROVIDER_H
+#define BOOKMARKPROVIDER_H
// Rekonq Includes
#include "rekonq_defines.h"
-// KDE Includes
-#include <KBookmarkMenu>
-#include <KToolBar>
+// Qt Includes
+#include <QObject>
// Forward Declarations
class BookmarksPanel;
class BookmarkToolBar;
class BookmarkOwner;
+class KAction;
+class KActionCollection;
+class KActionMenu;
+class KBookmark;
+class KBookmarkGroup;
+class KBookmarkManager;
+class KToolBar;
+class KUrl;
+
+class QAction;
+class QPoint;
/**
* 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
- *
- *
+ * So it implements code to have each one.
*/
class BookmarkProvider : public QObject
{
@@ -60,11 +68,10 @@ public:
/**
* @short Class constructor.
* Connect BookmarksProvider with bookmarks source
- * (actually konqueror's bookmarks)
- * @param parent The MainWindow to provide bookmarks objects
- *
+ * (actually konqueror's bookmarks).
+ * @param parent The MainWindow to provide bookmarks objects.
*/
- BookmarkProvider(QObject* parent = 0);
+ BookmarkProvider(QObject *parent = 0);
~BookmarkProvider();
/**
@@ -72,14 +79,16 @@ public:
* @param the parent widget
* @return the Bookmarks Menu
*/
- KActionMenu *bookmarkActionMenu(QWidget *parent);
+ KActionMenu* bookmarkActionMenu(QWidget *parent);
/**
* @short set the Bookmarks Toolbar Action
*/
- void registerBookmarkBar(BookmarkToolBar *);
+ void registerBookmarkBar(BookmarkToolBar *toolbar);
+ void removeBookmarkBar(BookmarkToolBar *toolbar);
- void removeToolBar(BookmarkToolBar *);
+ void registerBookmarkPanel(BookmarksPanel *panel);
+ void removeBookmarkPanel(BookmarksPanel *panel);
/**
* @short Get action by name
@@ -88,7 +97,7 @@ public:
* @param name Name of action you want to get
* @return It returns actions if one exists or empty object
*/
- QAction *actionByName(const QString &name);
+ QAction* actionByName(const QString &name);
/**
* returns Bookmark Manager root group
@@ -97,22 +106,17 @@ public:
*/
KBookmarkGroup rootGroup();
- inline KBookmarkManager *bookmarkManager() { return m_manager; }
+ inline KBookmarkManager* bookmarkManager() { return m_manager; }
- inline BookmarkOwner *bookmarkOwner() { return m_owner; }
+ inline BookmarkOwner* bookmarkOwner() { return m_owner; }
- QList<KBookmark> find(QString text);
-
- void registerBookmarkPanel(BookmarksPanel *panel);
- void removeBookmarkPanel(BookmarksPanel *panel);
+ QList<KBookmark> find(const QString &text);
KBookmark bookmarkForUrl(const KUrl &url);
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 &);
@@ -128,11 +132,11 @@ public slots:
* @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 groupAddress bookmark group address
* @param caller caller that modified the bookmarks
* @see KBookmarkManager::changed
*/
- void slotBookmarksChanged(const QString &group, const QString &caller);
+ void slotBookmarksChanged(const QString &groupAddress, const QString &caller);
void fillBookmarkBar(BookmarkToolBar *toolBar);
private slots:
@@ -140,19 +144,16 @@ private slots:
void slotPanelChanged();
private:
- QList<KBookmark> find(QList<KBookmark> list, const KBookmark &bookmark, QString text);
+ void find(QList<KBookmark> *list, const KBookmark &bookmark, const QString &text);
- QString titleForBookmarkUrl(const KBookmark &bookmark, const QString &url);
KBookmark bookmarkForUrl(const KBookmark &bookmark, const KUrl &url);
KBookmarkManager *m_manager;
BookmarkOwner *m_owner;
KActionCollection *m_actionCollection;
- QList<BookmarkToolBar *> m_bookmarkToolBars;
+ QList<BookmarkToolBar*> m_bookmarkToolBars;
QList<BookmarksPanel*> m_bookmarkPanels;
-
- KActionMenu *_bookmarkActionMenu;
};
-#endif
+#endif // BOOKMARKPROVIDER_H
diff --git a/src/bookmarks/bookmarkscontextmenu.h b/src/bookmarks/bookmarkscontextmenu.h
index 424f8da4..a6691fdd 100644
--- a/src/bookmarks/bookmarkscontextmenu.h
+++ b/src/bookmarks/bookmarkscontextmenu.h
@@ -24,8 +24,8 @@
* ============================================================ */
-#ifndef BOOKMARKCONTEXTMENU_H
-#define BOOKMARKCONTEXTMENU_H
+#ifndef BOOKMARKS_CONTEXT_MENU_H
+#define BOOKMARKS_CONTEXT_MENU_H
// KDE Includes
#include <KBookmarkMenu>
@@ -50,4 +50,4 @@ private:
BookmarkOwner *bmOwner;
};
-#endif // BOOKMARKCONTEXTMENU_H
+#endif // BOOKMARKS_CONTEXT_MENU_H
diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp
index 1b561515..08f99155 100644
--- a/src/bookmarks/bookmarkspanel.cpp
+++ b/src/bookmarks/bookmarkspanel.cpp
@@ -30,7 +30,7 @@
// Local Includes
#include "application.h"
-#include "bookmarksmanager.h"
+#include "bookmarkprovider.h"
#include "bookmarkstreemodel.h"
#include "bookmarksproxy.h"
#include "bookmarkscontextmenu.h"
diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp
index bce2bd1e..64e9c3b9 100644
--- a/src/bookmarks/bookmarkstoolbar.cpp
+++ b/src/bookmarks/bookmarkstoolbar.cpp
@@ -33,7 +33,7 @@
#include "bookmarkscontextmenu.h"
#include "mainwindow.h"
#include "application.h"
-#include "bookmarksmanager.h"
+#include "bookmarkprovider.h"
#include "bookmarkowner.h"
// Qt Includes
diff --git a/src/bookmarks/bookmarkstoolbar.h b/src/bookmarks/bookmarkstoolbar.h
index 5991a032..54a430e3 100644
--- a/src/bookmarks/bookmarkstoolbar.h
+++ b/src/bookmarks/bookmarkstoolbar.h
@@ -30,8 +30,6 @@
// KDE Includes
#include <KBookmarkMenu>
-#include <KToolBar>
-
/**
* This class represent the rekonq bookmarks menu.
@@ -69,6 +67,11 @@ private:
// ------------------------------------------------------------------------------
+
+// KDE Includes
+#include <KToolBar>
+
+
/**
* This class manage the bookmark toolbar.
* Some events from the toolbar are handled to allow the drag and drop
diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp
index 7f0bf66f..ee19daf1 100644
--- a/src/bookmarks/bookmarkstreemodel.cpp
+++ b/src/bookmarks/bookmarkstreemodel.cpp
@@ -30,7 +30,11 @@
// Local Includes
#include "application.h"
-#include "bookmarksmanager.h"
+#include "bookmarkprovider.h"
+
+// KDE Includes
+#include <KBookmarkManager>
+#include <KLocalizedString>
// Qt Includes
#include <QtCore/QMimeData>
@@ -56,28 +60,27 @@ QVariant BtmItem::data(int role) const
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();
+
if (role == Qt::ToolTipRole)
{
- QString tooltip = "";
-
- if (!m_kbm.fullText().isEmpty())
- {
- tooltip += m_kbm.fullText();
- }
+ QString tooltip = m_kbm.fullText();
if (m_kbm.isGroup())
- {
tooltip += i18ncp("%1=Number of items in bookmark folder", " (1 item)", " (%1 items)", childCount());
- }
- if (!m_kbm.url().url().isEmpty())
+
+ QString url = m_kbm.url().url();
+ if (!url.isEmpty())
{
if (!tooltip.isEmpty())
tooltip += '\n';
- tooltip += m_kbm.url().url();
+ tooltip += url;
}
+
return tooltip;
}