summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYoann Laissus <yoann.laissus@gmail.com>2010-07-18 19:15:44 +0200
committerYoann Laissus <yoann.laissus@gmail.com>2010-07-18 19:15:44 +0200
commit737dd6ec3b8daa1517b392dbad1f13b090e5d33b (patch)
tree6005c75d4062e5f5a1de6390eb5eb3aa187f005b /src
parentSVN_SILENT made messages (.desktop file) (diff)
downloadrekonq-737dd6ec3b8daa1517b392dbad1f13b090e5d33b.tar.xz
- Performance improvements (partial updates of the tree)
- Synchronisation of the folded states between each windows - Code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/bookmarkcontextmenu.cpp11
-rw-r--r--src/bookmarks/bookmarksmanager.cpp31
-rw-r--r--src/bookmarks/bookmarksmanager.h6
-rw-r--r--src/bookmarks/bookmarkspanel.cpp8
-rw-r--r--src/bookmarks/bookmarkspanel.h4
-rw-r--r--src/bookmarks/bookmarkstreemodel.cpp85
-rw-r--r--src/bookmarks/bookmarkstreemodel.h4
-rw-r--r--src/mainwindow.cpp3
8 files changed, 94 insertions, 58 deletions
diff --git a/src/bookmarks/bookmarkcontextmenu.cpp b/src/bookmarks/bookmarkcontextmenu.cpp
index b5df463c..dec4382f 100644
--- a/src/bookmarks/bookmarkcontextmenu.cpp
+++ b/src/bookmarks/bookmarkcontextmenu.cpp
@@ -212,6 +212,7 @@ void BookmarkContextMenu::copyToClipboard()
void BookmarkContextMenu::deleteBookmark()
{
KBookmark bm = bookmark();
+ KBookmarkGroup bmg = bm.parentGroup();
bool folder = bm.isGroup();
QString name = QString(bm.text()).replace("&&", "&");
@@ -226,8 +227,8 @@ void BookmarkContextMenu::deleteBookmark()
)
return;
- bm.parentGroup().deleteBookmark(bm);
- manager()->emitChanged();
+ bmg.deleteBookmark(bm);
+ manager()->emitChanged(bmg);
}
@@ -266,7 +267,7 @@ void BookmarkContextMenu::newBookmarkGroup()
KBookmark newBk;
newBk = dialog->createNewFolder("New folder", selected.parentGroup());
selected.parentGroup().moveBookmark(newBk, selected);
- manager()->emitChanged();
+ manager()->emitChanged(newBk.parentGroup());
}
}
else
@@ -303,7 +304,7 @@ void BookmarkContextMenu::newSeparator()
if (!selected.isNull())
parent.moveBookmark(newBk, selected);
- manager()->emitChanged();
+ manager()->emitChanged(newBk.parentGroup());
}
@@ -328,6 +329,6 @@ void BookmarkContextMenu::bookmarkCurrentPage()
parent.addBookmark(owner()->currentTitle(), KUrl(owner()->currentUrl()), "text-html");
}
- manager()->emitChanged();
+ manager()->emitChanged(parent);
}
diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp
index 537b5366..57a29907 100644
--- a/src/bookmarks/bookmarksmanager.cpp
+++ b/src/bookmarks/bookmarksmanager.cpp
@@ -483,3 +483,34 @@ void BookmarkProvider::slotAddBookmark()
parentBookmark.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)
+ {
+ if (panel && panel != sender())
+ panel->startLoadFoldedState();
+ }
+}
diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h
index 4be3a94b..0915e894 100644
--- a/src/bookmarks/bookmarksmanager.h
+++ b/src/bookmarks/bookmarksmanager.h
@@ -37,6 +37,7 @@
// Local Includes
#include "application.h"
#include "urlresolver.h"
+#include "bookmarkspanel.h"
// Qt Includes
#include <QWidget>
@@ -234,6 +235,9 @@ public:
QString titleForBookmarkUrl(QString url);
+ void registerBookmarkPanel(BookmarksPanel *panel);
+ void removeBookmarkPanel(BookmarksPanel *panel);
+
signals:
/**
* @short This signal is emitted when an url has to be loaded
@@ -263,6 +267,7 @@ public slots:
private slots:
void triggerBookmarkMenu();
void slotAddBookmark();
+ void slotPanelChanged();
private:
void fillBookmarkBar(KToolBar *toolBar);
@@ -272,6 +277,7 @@ private:
BookmarkOwner *m_owner;
KActionCollection *m_actionCollection;
QList<KToolBar*> m_bookmarkToolBars;
+ QList<BookmarksPanel*> m_bookmarkPanels;
AwesomeUrlCompletion *m_completion;
KActionMenu *_bookmarkActionMenu;
diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp
index 0dbb89c4..25aab516 100644
--- a/src/bookmarks/bookmarkspanel.cpp
+++ b/src/bookmarks/bookmarkspanel.cpp
@@ -126,7 +126,7 @@ void BookmarksPanel::setup()
connect(m_treeView, SIGNAL(collapsed(const QModelIndex &)), this, SLOT(onCollapse(const QModelIndex &)));
connect(m_treeView, SIGNAL(expanded(const QModelIndex &)), this, SLOT(onExpand(const QModelIndex &)));
connect(search, SIGNAL(textChanged(const QString &)), proxy, SLOT(setFilterFixedString(const QString &)));
- loadFoldedState();
+ startLoadFoldedState();
_loaded = true;
}
@@ -152,7 +152,7 @@ void BookmarksPanel::onCollapse(const QModelIndex &index)
KBookmark bookmark = bookmarkForIndex(index);
bookmark.internalElement().setAttribute("folded", "yes");
- emit saveOnlyRequested();
+ emit expansionChanged();
}
@@ -163,11 +163,11 @@ void BookmarksPanel::onExpand(const QModelIndex &index)
KBookmark bookmark = bookmarkForIndex(index);
bookmark.internalElement().setAttribute("folded", "no");
- emit saveOnlyRequested();
+ emit expansionChanged();
}
-void BookmarksPanel::loadFoldedState()
+void BookmarksPanel::startLoadFoldedState()
{
m_loadingState = true;
loadFoldedState(QModelIndex());
diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h
index 3d2dc26b..d94f2b99 100644
--- a/src/bookmarks/bookmarkspanel.h
+++ b/src/bookmarks/bookmarkspanel.h
@@ -59,10 +59,11 @@ public:
signals:
void openUrl(const KUrl &, const Rekonq::OpenType &);
void itemHovered(const QString &);
- void saveOnlyRequested();
+ void expansionChanged();
public slots:
void showing(bool);
+ void startLoadFoldedState();
private slots:
void contextMenu(const QPoint &pos);
@@ -71,7 +72,6 @@ private slots:
void onCollapse(const QModelIndex &index);
void onExpand(const QModelIndex &index);
void loadFoldedState(const QModelIndex &root);
- void loadFoldedState();
private:
void setup();
diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp
index 82748ba3..b58b66e9 100644
--- a/src/bookmarks/bookmarkstreemodel.cpp
+++ b/src/bookmarks/bookmarkstreemodel.cpp
@@ -148,9 +148,8 @@ BookmarksTreeModel::BookmarksTreeModel(QObject *parent)
, m_root(0)
{
resetModel();
- connect(this, SIGNAL(bookmarksUpdated()), parent, SLOT(loadFoldedState()));
- connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(bookmarksChanged()));
- connect(parent, SIGNAL(saveOnlyRequested()), this, SLOT(saveOnly()));
+ connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(bookmarksChanged(const QString &)));
+ connect(this, SIGNAL(bookmarksUpdated()), parent, SLOT(startLoadFoldedState()));
}
@@ -284,10 +283,37 @@ QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const
}
-void BookmarksTreeModel::bookmarksChanged()
+void BookmarksTreeModel::bookmarksChanged(const QString &groupAddress)
{
- resetModel();
- emit bookmarksUpdated();
+ if (groupAddress.isEmpty())
+ {
+ resetModel();
+ emit bookmarksUpdated();
+ }
+ else
+ {
+ beginResetModel();
+ BtmItem *node = m_root;
+ QModelIndex nodeIndex;
+
+ QStringList indexChain( groupAddress.split( '/', QString::SkipEmptyParts) );
+ foreach( const 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 );
+ }
+ populate(node, Application::bookmarkProvider()->bookmarkManager()->findByAddress(groupAddress).toGroup());
+ endResetModel();
+ emit bookmarksUpdated();
+ }
}
@@ -299,6 +325,7 @@ void BookmarksTreeModel::resetModel()
void BookmarksTreeModel::setRoot(KBookmarkGroup bmg)
{
+ beginResetModel();
delete m_root;
m_root = new BtmItem(KBookmark());
@@ -306,7 +333,7 @@ void BookmarksTreeModel::setRoot(KBookmarkGroup bmg)
return;
populate(m_root, bmg);
- reset();
+ endResetModel();
}
@@ -336,20 +363,6 @@ KBookmark BookmarksTreeModel::bookmarkForIndex(const QModelIndex &index) const
}
-void BookmarksTreeModel::saveOnly()
-{
- disconnect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(bookmarksChanged()));
- connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(reconnectManager()));
- Application::bookmarkProvider()->bookmarkManager()->emitChanged();
-}
-
-
-void BookmarksTreeModel::reconnectManager()
-{
- connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(QString, QString)), this, SLOT(bookmarksChanged()));
-}
-
-
Qt::DropActions BookmarksTreeModel::supportedDropActions() const
{
return Qt::MoveAction;
@@ -366,8 +379,8 @@ QMimeData* BookmarksTreeModel::mimeData(const QModelIndexList & indexes) const
{
QMimeData *mimeData = new QMimeData;
- QByteArray addresse = bookmarkForIndex(indexes.first()).address().toLatin1();
- mimeData->setData("application/rekonq-bookmark", addresse);
+ QByteArray address = bookmarkForIndex(indexes.first()).address().toLatin1();
+ mimeData->setData("application/rekonq-bookmark", address);
bookmarkForIndex(indexes.first()).populateMimeData(mimeData);
return mimeData;
@@ -395,32 +408,16 @@ bool BookmarksTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
if (!destIndex.isValid())
{
- if (!parent.isValid()) // Drop into a blank area
- {
- Application::bookmarkProvider()->rootGroup().deleteBookmark(bookmark);
- Application::bookmarkProvider()->rootGroup().addBookmark(bookmark);
- }
- else // Drop at the last item of the group or directly on the main item of the group
- {
- root.deleteBookmark(bookmark);
- root.addBookmark(bookmark);
- }
+ root.deleteBookmark(bookmark);
+ root.addBookmark(bookmark);
}
- else
+ else if (row != 1)
{
- if (row == -1)
- {
- root.deleteBookmark(bookmark);
- root.addBookmark(bookmark);
- }
- else // A classic drop
- {
- root.moveBookmark(bookmark, root.previous(dropDestBookmark));
- }
+ root.moveBookmark(bookmark, root.previous(dropDestBookmark));
}
- Application::bookmarkProvider()->bookmarkManager()->emitChanged(root);
+ Application::bookmarkProvider()->bookmarkManager()->emitChanged();
}
}
return true;
diff --git a/src/bookmarks/bookmarkstreemodel.h b/src/bookmarks/bookmarkstreemodel.h
index 8dd0923c..c509840b 100644
--- a/src/bookmarks/bookmarkstreemodel.h
+++ b/src/bookmarks/bookmarkstreemodel.h
@@ -84,9 +84,7 @@ public:
virtual QMimeData *mimeData(const QModelIndexList & indexes) const;
private slots:
- void bookmarksChanged();
- void saveOnly();
- void reconnectManager();
+ void bookmarksChanged(const QString &groupAddress);
signals:
void bookmarksUpdated();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b27b7c81..0deeb15b 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -161,6 +161,7 @@ MainWindow::MainWindow()
MainWindow::~MainWindow()
{
Application::bookmarkProvider()->removeToolBar(m_bmBar);
+ Application::bookmarkProvider()->removeBookmarkPanel(m_bookmarksPanel);
Application::instance()->removeMainWindow(this);
delete m_view;
@@ -566,6 +567,8 @@ void MainWindow::setupPanels()
addDockWidget(Qt::LeftDockWidgetArea, m_bookmarksPanel);
+ Application::bookmarkProvider()->registerBookmarkPanel(m_bookmarksPanel);
+
// setup bookmarks panel action
a = (KAction *) m_bookmarksPanel->toggleViewAction();
a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_B));