From 4ba9903ccb5982d7d49b37850fffd47dc3e5da40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Ander=20Pe=C3=B1alba?= Date: Fri, 22 Oct 2010 19:21:11 +0200 Subject: BookmarksPanel API improved --- src/bookmarks/bookmarkprovider.cpp | 12 ++++----- src/bookmarks/bookmarkspanel.cpp | 55 +++++++++++++------------------------- src/bookmarks/bookmarkspanel.h | 21 ++++++++------- src/history/historypanel.cpp | 2 +- src/history/historypanel.h | 2 +- src/urlpanel.cpp | 3 +-- src/urlpanel.h | 2 +- 7 files changed, 40 insertions(+), 57 deletions(-) diff --git a/src/bookmarks/bookmarkprovider.cpp b/src/bookmarks/bookmarkprovider.cpp index ccdc3269..0924ae30 100644 --- a/src/bookmarks/bookmarkprovider.cpp +++ b/src/bookmarks/bookmarkprovider.cpp @@ -55,13 +55,13 @@ BookmarkProvider::BookmarkProvider(QObject *parent) kDebug() << "Loading Bookmarks Manager..."; // NOTE - // This hackish code is needed to continue sharing bookmarks with konqueror, + // This hackish code is needed to continue sharing bookmarks with konqueror, // until we can (hopefully) start using an akonadi resource. // // The cleanest code has a subdole bug inside does not allowing people to start // using rekonq and then using konqueror. So if konqueror bk file has not just been created, // bk are stored in rekonq dir and then they will be lost when you start using konqi - + KUrl bookfile = KUrl("~/.kde/share/apps/konqueror/bookmarks.xml"); // share konqueror bookmarks if (!QFile::exists(bookfile.path())) { @@ -79,7 +79,7 @@ BookmarkProvider::BookmarkProvider(QObject *parent) m_manager = KBookmarkManager::managerForFile(bookfile.path(), "rekonq"); m_manager->setEditorOptions("", true); - + connect(m_manager, SIGNAL(changed(const QString &, const QString &)), this, SLOT(slotBookmarksChanged())); @@ -112,7 +112,7 @@ KActionMenu* BookmarkProvider::bookmarkActionMenu(QWidget *parent) bookmarkActionMenu->setText(i18n("&Bookmarks")); BookmarkMenu *bMenu = new BookmarkMenu(m_manager, m_owner, menu, m_actionCollection); m_bookmarkMenus.append(bMenu); - + kDebug() << "new Bookmarks menu... DONE"; return bookmarkActionMenu; @@ -226,7 +226,7 @@ void BookmarkProvider::fillBookmarkBar(BookmarkToolBar *toolBar) menuAction->setDelayed(false); BookmarkMenu *bMenu = new BookmarkMenu(bookmarkManager(), bookmarkOwner(), menuAction->menu(), bookmark.address()); m_bookmarkMenus.append(bMenu); - + connect(menuAction->menu(), SIGNAL(aboutToShow()), toolBar, SLOT(menuDisplayed())); connect(menuAction->menu(), SIGNAL(aboutToHide()), toolBar, SLOT(menuHidden())); @@ -254,7 +254,7 @@ void BookmarkProvider::slotPanelChanged() foreach (BookmarksPanel *panel, m_bookmarkPanels) { if (panel && panel != sender()) - panel->startLoadFoldedState(); + panel->loadFoldedState(); } } diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp index f732cb22..1763a1e5 100644 --- a/src/bookmarks/bookmarkspanel.cpp +++ b/src/bookmarks/bookmarkspanel.cpp @@ -51,7 +51,7 @@ BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::Window setVisible(ReKonfig::showBookmarksPanel()); panelTreeView()->setDragEnabled(true); panelTreeView()->setAcceptDrops(true); - connect(_bkTreeModel, SIGNAL(bookmarksUpdated()), this, SLOT(startLoadFoldedState())); + connect(_bkTreeModel, SIGNAL(bookmarksUpdated()), this, SLOT(loadFoldedState())); } @@ -61,7 +61,7 @@ BookmarksPanel::~BookmarksPanel() } -void BookmarksPanel::startLoadFoldedState() +void BookmarksPanel::loadFoldedState() { _loadingState = true; loadFoldedState(QModelIndex()); @@ -76,32 +76,13 @@ void BookmarksPanel::contextMenu(const QPoint &pos) BookmarksContextMenu menu(bookmarkForIndex( panelTreeView()->indexAt(pos) ), Application::bookmarkProvider()->bookmarkManager(), - Application::bookmarkProvider()->bookmarkOwner(), - this + Application::bookmarkProvider()->bookmarkOwner() ); menu.exec(panelTreeView()->mapToGlobal(pos)); } -void BookmarksPanel::contextMenuItem(const QPoint &pos) -{ - contextMenu(pos); -} - - -void BookmarksPanel::contextMenuGroup(const QPoint &pos) -{ - contextMenu(pos); -} - - -void BookmarksPanel::contextMenuEmpty(const QPoint &pos) -{ - contextMenu(pos); -} - - void BookmarksPanel::deleteBookmark() { QModelIndex index = panelTreeView()->currentIndex(); @@ -132,12 +113,25 @@ void BookmarksPanel::onExpand(const QModelIndex &index) } +void BookmarksPanel::setup() +{ + UrlPanel::setup(); + kDebug() << "Bookmarks panel..."; + + connect(panelTreeView(), SIGNAL(delKeyPressed()), this, SLOT(deleteBookmark())); + connect(panelTreeView(), SIGNAL(collapsed(const QModelIndex &)), this, SLOT(onCollapse(const QModelIndex &))); + connect(panelTreeView(), SIGNAL(expanded(const QModelIndex &)), this, SLOT(onExpand(const QModelIndex &))); + + loadFoldedState(); +} + + void BookmarksPanel::loadFoldedState(const QModelIndex &root) { QAbstractItemModel *model = panelTreeView()->model(); if(!model) return; - + int count = model->rowCount(root); QModelIndex index; @@ -157,19 +151,6 @@ void BookmarksPanel::loadFoldedState(const QModelIndex &root) } -void BookmarksPanel::setup() -{ - UrlPanel::setup(); - kDebug() << "Bookmarks panel..."; - - connect(panelTreeView(), SIGNAL(delKeyPressed()), this, SLOT(deleteBookmark())); - connect(panelTreeView(), SIGNAL(collapsed(const QModelIndex &)), this, SLOT(onCollapse(const QModelIndex &))); - connect(panelTreeView(), SIGNAL(expanded(const QModelIndex &)), this, SLOT(onExpand(const QModelIndex &))); - - startLoadFoldedState(); -} - - KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index) { if (!index.isValid()) @@ -183,7 +164,7 @@ KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index) } -QAbstractItemModel* BookmarksPanel::getModel() +QAbstractItemModel* BookmarksPanel::model() { return _bkTreeModel; } diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h index f042d4c8..be797502 100644 --- a/src/bookmarks/bookmarkspanel.h +++ b/src/bookmarks/bookmarkspanel.h @@ -52,27 +52,30 @@ public: virtual ~BookmarksPanel(); public Q_SLOTS: - void startLoadFoldedState(); + void loadFoldedState(); + +Q_SIGNALS: + void expansionChanged(); private Q_SLOTS: void contextMenu(const QPoint &pos); - virtual void contextMenuItem(const QPoint &pos); - virtual void contextMenuGroup(const QPoint &pos); - virtual void contextMenuEmpty(const QPoint &pos); + + virtual void contextMenuItem (const QPoint &pos) {contextMenu(pos);} + virtual void contextMenuGroup (const QPoint &pos) {contextMenu(pos);} + virtual void contextMenuEmpty (const QPoint &pos) {contextMenu(pos);} void deleteBookmark(); void onCollapse(const QModelIndex &index); void onExpand(const QModelIndex &index); - void loadFoldedState(const QModelIndex &root); - -Q_SIGNALS: - void expansionChanged(); private: virtual void setup(); + + void loadFoldedState(const QModelIndex &root); + KBookmark bookmarkForIndex(const QModelIndex &index); - virtual QAbstractItemModel* getModel(); + virtual QAbstractItemModel* model(); BookmarksTreeModel *_bkTreeModel; bool _loadingState; diff --git a/src/history/historypanel.cpp b/src/history/historypanel.cpp index 28f7f4ee..d1b02c42 100644 --- a/src/history/historypanel.cpp +++ b/src/history/historypanel.cpp @@ -144,7 +144,7 @@ void HistoryPanel::setup() } -QAbstractItemModel* HistoryPanel::getModel() +QAbstractItemModel* HistoryPanel::model() { return Application::historyManager()->historyTreeModel(); } diff --git a/src/history/historypanel.h b/src/history/historypanel.h index 0a5ae216..00aca4a9 100644 --- a/src/history/historypanel.h +++ b/src/history/historypanel.h @@ -53,7 +53,7 @@ private Q_SLOTS: private: virtual void setup(); - virtual QAbstractItemModel* getModel(); + virtual QAbstractItemModel* model(); }; #endif // HISTORYPANEL_H diff --git a/src/urlpanel.cpp b/src/urlpanel.cpp index b3e8b2f3..d7ddd896 100644 --- a/src/urlpanel.cpp +++ b/src/urlpanel.cpp @@ -94,9 +94,8 @@ void UrlPanel::setup() ui->setLayout(vBoxLayout); setWidget(ui); - QAbstractItemModel *model = getModel(); UrlFilterProxyModel *proxy = new UrlFilterProxyModel(this); - proxy->setSourceModel(model); + proxy->setSourceModel(model()); _treeView->setModel(proxy); connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); diff --git a/src/urlpanel.h b/src/urlpanel.h index 722eeae0..42ff85fa 100644 --- a/src/urlpanel.h +++ b/src/urlpanel.h @@ -58,7 +58,7 @@ public Q_SLOTS: protected: virtual void setup(); - virtual QAbstractItemModel* getModel() = 0; + virtual QAbstractItemModel* model() = 0; PanelTreeView* panelTreeView() const {return _treeView;} -- cgit v1.2.1