┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2007-03-26 20:32:50 +0000
committerDavid Faure <[email protected]>2007-03-26 20:32:50 +0000
commit581a2b1c642ae259a2e0990a5ea7bef3286cd412 (patch)
treeff875ee8f2df09b36196fb8a10087eeb12f76d0f
parentad6c01d200e2504de1a383355bd82906fe5c06ed (diff)
A small step in trying to make urlnavigator useable in kdelibs for the file dialog:
remove dependency on DolphinSettings::bookmarkManager(). svn path=/trunk/KDE/kdebase/apps/; revision=646880
-rw-r--r--src/bookmarkselector.cpp84
-rw-r--r--src/bookmarkselector.h17
-rw-r--r--src/dolphinsettings.cpp13
-rw-r--r--src/dolphinview.cpp3
-rw-r--r--src/treeviewsidebarpage.cpp3
-rw-r--r--src/urlnavigator.cpp6
-rw-r--r--src/urlnavigator.h3
7 files changed, 54 insertions, 75 deletions
diff --git a/src/bookmarkselector.cpp b/src/bookmarkselector.cpp
index 73950434d..84ec0fc4e 100644
--- a/src/bookmarkselector.cpp
+++ b/src/bookmarkselector.cpp
@@ -19,7 +19,6 @@
#include "bookmarkselector.h"
-#include "dolphinsettings.h"
#include "urlnavigator.h"
#include <assert.h>
@@ -33,25 +32,28 @@
#include <QPainter>
#include <QPixmap>
-BookmarkSelector::BookmarkSelector(UrlNavigator* parent) :
+BookmarkSelector::BookmarkSelector(UrlNavigator* parent, KBookmarkManager* bookmarkManager) :
UrlButton(parent),
- m_selectedIndex(0),
- m_urlNavigator(parent)
+ m_selectedAddress(),
+ m_urlNavigator(parent),
+ m_bookmarkManager(bookmarkManager)
{
setFocusPolicy(Qt::NoFocus);
m_bookmarksMenu = new KMenu(this);
- KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root();
+ KBookmarkGroup root = m_bookmarkManager->root();
KBookmark bookmark = root.first();
int i = 0;
while (!bookmark.isNull()) {
QAction* action = new QAction(MainBarIcon(bookmark.icon()),
bookmark.text(),
this);
- action->setData(i);
m_bookmarksMenu->addAction(action);
- if (i == m_selectedIndex) {
+ QString address = QChar('/');
+ address += QString::number(i);
+ action->setData(address);
+ if (address == m_selectedAddress) {
QPixmap pixmap = SmallIcon(bookmark.icon());
setIcon(QIcon(pixmap));
setIconSize(pixmap.size());
@@ -73,12 +75,13 @@ BookmarkSelector::~BookmarkSelector()
void BookmarkSelector::updateSelection(const KUrl& url)
{
- m_selectedIndex = baseBookmarkIndex(url);
- if (m_selectedIndex >= 0) {
- KBookmark bookmark = DolphinSettings::instance().bookmark(m_selectedIndex);
+ KBookmark bookmark = baseBookmark(m_bookmarkManager, url);
+ if (!bookmark.isNull()) {
+ m_selectedAddress = bookmark.address();
setIcon(SmallIcon(bookmark.icon()));
}
else {
+ m_selectedAddress = QString();
// No bookmark has been found which matches to the given Url. Show
// a generic folder icon as pixmap for indication:
setIcon(SmallIcon("folder"));
@@ -87,7 +90,7 @@ void BookmarkSelector::updateSelection(const KUrl& url)
KBookmark BookmarkSelector::selectedBookmark() const
{
- return DolphinSettings::instance().bookmark(m_selectedIndex);
+ return m_bookmarkManager->findByAddress(m_selectedAddress);
}
QSize BookmarkSelector::sizeHint() const
@@ -96,10 +99,32 @@ QSize BookmarkSelector::sizeHint() const
return QSize(height, height);
}
-KBookmark BookmarkSelector::baseBookmark(const KUrl& url)
+KBookmark BookmarkSelector::baseBookmark(KBookmarkManager* bookmarkManager, const KUrl& url)
{
- const int index = baseBookmarkIndex(url);
- return DolphinSettings::instance().bookmark(index);
+ const KBookmarkGroup root = bookmarkManager->root();
+ KBookmark bookmark = root.first();
+ KBookmark foundBookmark;
+
+ int maxLength = 0;
+
+ // Search the bookmark which is equal to the Url or at least is a parent Url.
+ // If there are more than one possible parent Url candidates, choose the bookmark
+ // which covers the bigger range of the Url.
+ int i = 0;
+ while (!bookmark.isNull()) {
+ const KUrl bookmarkUrl = bookmark.url();
+ if (bookmarkUrl.isParentOf(url)) {
+ const int length = bookmarkUrl.prettyUrl().length();
+ if (length > maxLength) {
+ foundBookmark = bookmark;
+ maxLength = length;
+ }
+ }
+ bookmark = root.next(bookmark);
+ ++i;
+ }
+
+ return foundBookmark;
}
void BookmarkSelector::paintEvent(QPaintEvent* /*event*/)
@@ -153,41 +178,12 @@ void BookmarkSelector::paintEvent(QPaintEvent* /*event*/)
void BookmarkSelector::activateBookmark(QAction* action)
{
assert(action != 0);
- m_selectedIndex = action->data().toInt();
+ m_selectedAddress = action->data().toString();
const KBookmark bookmark = selectedBookmark();
setPixmap(SmallIcon(bookmark.icon()));
emit bookmarkActivated(bookmark.url());
}
-int BookmarkSelector::baseBookmarkIndex(const KUrl& url)
-{
- int index = -1; // return value
-
- KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root();
- KBookmark bookmark = root.first();
-
- int maxLength = 0;
-
- // Search the bookmark which is equal to the Url or at least is a parent Url.
- // If there are more than one possible parent Url candidates, choose the bookmark
- // which covers the bigger range of the Url.
- int i = 0;
- while (!bookmark.isNull()) {
- const KUrl bookmarkUrl = bookmark.url();
- if (bookmarkUrl.isParentOf(url)) {
- const int length = bookmarkUrl.prettyUrl().length();
- if (length > maxLength) {
- index = i;
- maxLength = length;
- }
- }
- bookmark = root.next(bookmark);
- ++i;
- }
-
- return index;
-}
-
#include "bookmarkselector.moc"
diff --git a/src/bookmarkselector.h b/src/bookmarkselector.h
index 334f25ba3..a92f186ec 100644
--- a/src/bookmarkselector.h
+++ b/src/bookmarkselector.h
@@ -44,7 +44,7 @@ public:
* @param parent Parent widget where the bookmark selector
* is embedded into.
*/
- BookmarkSelector(UrlNavigator* parent);
+ BookmarkSelector(UrlNavigator* parent, KBookmarkManager* bookmarkManager);
virtual ~BookmarkSelector();
@@ -57,12 +57,6 @@ public:
*/
void updateSelection(const KUrl& url);
- /**
- * Returns the index of the selected bookmark. To get
- * the bookmark, use BookmarkSelector::selectedBookmark().
- */
- int selectedIndex() const { return m_selectedIndex; }
-
/** Returns the selected bookmark. */
KBookmark selectedBookmark() const;
@@ -83,7 +77,7 @@ public:
*
* The base URL will be '/home/peter/Documents'.
*/
- static KBookmark baseBookmark(const KUrl& url);
+ static KBookmark baseBookmark(KBookmarkManager* bookmarkManager, const KUrl& url);
signals:
/**
@@ -107,13 +101,10 @@ private slots:
void activateBookmark(QAction* action);
private:
- static int baseBookmarkIndex(const KUrl& url);
-
-private:
- int m_selectedIndex;
+ QString m_selectedAddress;
UrlNavigator* m_urlNavigator;
KMenu* m_bookmarksMenu;
-
+ KBookmarkManager* m_bookmarkManager;
};
#endif
diff --git a/src/dolphinsettings.cpp b/src/dolphinsettings.cpp
index 7e3388524..837a5f4d1 100644
--- a/src/dolphinsettings.cpp
+++ b/src/dolphinsettings.cpp
@@ -47,18 +47,7 @@ DolphinSettings& DolphinSettings::instance()
KBookmark DolphinSettings::bookmark(int index) const
{
- int i = 0;
- KBookmarkGroup root = bookmarkManager()->root();
- KBookmark bookmark = root.first();
- while (!bookmark.isNull()) {
- if (i == index) {
- return bookmark;
- }
- ++i;
- bookmark = root.next(bookmark);
- }
-
- return KBookmark();
+ return bookmarkManager()->findByAddress( QString('/')+QString::number(index) );
}
KBookmarkManager* DolphinSettings::bookmarkManager() const
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp
index 311ca36b4..23c91b9f4 100644
--- a/src/dolphinview.cpp
+++ b/src/dolphinview.cpp
@@ -51,6 +51,7 @@
#include "renamedialog.h"
#include "urlnavigator.h"
#include "viewproperties.h"
+#include "dolphinsettings.h"
DolphinView::DolphinView(DolphinMainWindow* mainWindow,
QWidget* parent,
@@ -90,7 +91,7 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
connect(clipboard, SIGNAL(dataChanged()),
this, SLOT(updateCutItems()));
- m_urlNavigator = new UrlNavigator(url, this);
+ m_urlNavigator = new UrlNavigator(DolphinSettings::instance().bookmarkManager(), url, this);
m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
this, SLOT(loadDirectory(const KUrl&)));
diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp
index 19feb5874..aef455c1e 100644
--- a/src/treeviewsidebarpage.cpp
+++ b/src/treeviewsidebarpage.cpp
@@ -34,6 +34,7 @@
#include <QItemSelectionModel>
#include <QTreeView>
#include <QVBoxLayout>
+#include "dolphinsettings.h"
// TODO: currently when using a proxy model the strange effect occurs
// that items get duplicated. Activate the following define to have the proxy
@@ -98,7 +99,7 @@ void TreeViewSidebarPage::setUrl(const KUrl& url)
m_url = url;
// adjust the root of the tree to the base bookmark
- const KUrl baseUrl = BookmarkSelector::baseBookmark(url).url();
+ const KUrl baseUrl = BookmarkSelector::baseBookmark(DolphinSettings::instance().bookmarkManager(), url).url();
if (m_dirLister->url() != baseUrl) {
m_dirLister->stop();
m_dirLister->openUrl(baseUrl);
diff --git a/src/urlnavigator.cpp b/src/urlnavigator.cpp
index 1a49b386b..ca3b1789c 100644
--- a/src/urlnavigator.cpp
+++ b/src/urlnavigator.cpp
@@ -65,7 +65,8 @@ UrlNavigator::HistoryElem::~HistoryElem()
{
}
-UrlNavigator::UrlNavigator(const KUrl& url,
+UrlNavigator::UrlNavigator(KBookmarkManager* bookmarkManager,
+ const KUrl& url,
QWidget* parent) :
QWidget(parent),
m_active(true),
@@ -101,7 +102,7 @@ UrlNavigator::UrlNavigator(const KUrl& url,
}
// initialize the bookmark selector
- m_bookmarkSelector = new BookmarkSelector(this);
+ m_bookmarkSelector = new BookmarkSelector(this, bookmarkManager);
connect(m_bookmarkSelector, SIGNAL(bookmarkActivated(const KUrl&)),
this, SLOT(setUrl(const KUrl&)));
@@ -532,7 +533,6 @@ void UrlNavigator::updateContent()
// get the data from the currently selected bookmark
KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
- //int bookmarkIndex = m_bookmarkSelector->selectedIndex();
QString bookmarkPath;
if (bookmark.isNull()) {
diff --git a/src/urlnavigator.h b/src/urlnavigator.h
index 5e0d7f836..aa46709aa 100644
--- a/src/urlnavigator.h
+++ b/src/urlnavigator.h
@@ -27,6 +27,7 @@
#include <QList>
#include <QLinkedList>
+class KBookmarkManager;
class QHBoxLayout;
class QLabel;
class QLineEdit;
@@ -97,7 +98,7 @@ public:
int m_contentsY;
};
- UrlNavigator(const KUrl& url, QWidget* parent);
+ UrlNavigator(KBookmarkManager* bookmarkManager, const KUrl& url, QWidget* parent);
virtual ~UrlNavigator();
/** Returns the current active URL. */