Improved urlnavigator API to avoid exposing the full QList (api independent from implementation now).
svn path=/trunk/KDE/kdebase/apps/; revision=646954
void BookmarkSelector::updateSelection(const KUrl& url)
{
- KBookmark bookmark = baseBookmark(m_bookmarkManager, url);
+ KBookmark bookmark = m_bookmarkManager->root().closestBookmark(url);
if (!bookmark.isNull()) {
m_selectedAddress = bookmark.address();
setIcon(SmallIcon(bookmark.icon()));
return QSize(height, height);
}
-KBookmark BookmarkSelector::baseBookmark(KBookmarkManager* bookmarkManager, const KUrl& url)
-{
- 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*/)
{
QPainter painter(this);
/** @see QWidget::sizeHint() */
virtual QSize sizeHint() const;
- /**
- * Returns the base bookmark for the URL \a url.
- * The base bookmark is defined as bookmark which is equal to
- * the URL or at least is a parent URL. If there are more than
- * one possible parent URL candidates, the bookmark which covers
- * the bigger range of the URL is returned.
- *
- * Example: the url is '/home/peter/Documents/Music. Available
- * bookmarks are:
- * - /home/peter
- * - /home/peter/Documents
- *
- * The base URL will be '/home/peter/Documents'.
- */
- static KBookmark baseBookmark(KBookmarkManager* bookmarkManager, const KUrl& url);
-
signals:
/**
* Is send when a bookmark has been activated by the user.
void BookmarksSidebarPage::adjustSelection(const KUrl& url)
{
- // TODO (remarked in dolphin/TODO): the following code is quite equal
- // to BookmarkSelector::updateSelection().
-
KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root();
- KBookmark bookmark = root.first();
-
- int maxLength = 0;
- int selectedIndex = -1;
-
- // 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) {
- selectedIndex = i;
- maxLength = length;
- }
- }
- bookmark = root.next(bookmark);
- ++i;
- }
+ KBookmark bookmark = root.closestBookmark(url);
const bool block = m_bookmarksList->signalsBlocked();
m_bookmarksList->blockSignals(true);
- if (selectedIndex < 0) {
+ if (bookmark.isNull()) {
// no bookmark matches, hence deactivate any selection
const int currentIndex = m_bookmarksList->index(m_bookmarksList->selectedItem());
m_bookmarksList->setSelected(currentIndex, false);
}
else {
// select the bookmark which is part of the current Url
+ // TODO when porting to QListWidget, use the address as item data?
+ int selectedIndex = bookmark.address().mid(1).toInt(); // convert "/5" to 5.
m_bookmarksList->setSelected(selectedIndex, true);
}
m_bookmarksList->blockSignals(block);
void DolphinMainWindow::updateHistory()\r
{\r
int index = 0;\r
- const QList<UrlNavigator::HistoryElem> list = m_activeView->urlHistory(index);\r
\r
QAction* backAction = actionCollection()->action("go_back");\r
if (backAction != 0) {\r
- backAction->setEnabled(index < static_cast<int>(list.count()) - 1);\r
+ backAction->setEnabled(index < m_activeView->urlNavigator()->historySize() - 1);\r
}\r
\r
QAction* forwardAction = actionCollection()->action("go_forward");\r
m_urlNavigator->editUrl(editable);
}
-const QList<UrlNavigator::HistoryElem> DolphinView::urlHistory(int& index) const
-{
- return m_urlNavigator->history(index);
-}
-
bool DolphinView::hasSelection() const
{
return itemView()->selectionModel()->hasSelection();
void DolphinView::restoreContentsPos()
{
- int index = 0;
- const QList<UrlNavigator::HistoryElem> history = urlHistory(index);
- if (!history.isEmpty()) {
+ UrlNavigator::HistoryElem historyItem = m_urlNavigator->currentHistoryItem();
+ if (!historyItem.url().isEmpty()) {
QAbstractItemView* view = itemView();
- // TODO: view->setCurrentItem(history[index].currentFileName());
-
- const UrlNavigator::HistoryElem& it = history[index];
- view->horizontalScrollBar()->setValue(it.contentsX());
- view->verticalScrollBar()->setValue(it.contentsY());
+ // TODO: view->setCurrentItem(historyItem.currentFileName());
+ view->horizontalScrollBar()->setValue(historyItem.contentsX());
+ view->verticalScrollBar()->setValue(historyItem.contentsY());
}
}
*/
void setUrlEditable(bool editable);
- /**
- * Returns the complete URL history. The index 0 indicates the oldest
- * history element.
- * @param index Output parameter which indicates the current
- * index of the location.
- */
- const QList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
-
/** Returns true, if at least one item is selected. */
bool hasSelection() const;
#include "treeviewsidebarpage.h"
-#include "bookmarkselector.h"
+#include "kbookmarkmanager.h"
#include "dolphinmainwindow.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
m_url = url;
// adjust the root of the tree to the base bookmark
- const KUrl baseUrl = BookmarkSelector::baseBookmark(DolphinSettings::instance().bookmarkManager(), url).url();
+ KBookmarkManager* bookmarkManager = DolphinSettings::instance().bookmarkManager();
+ const KUrl baseUrl = bookmarkManager->root().closestBookmark(url).url();
if (m_dirLister->url() != baseUrl) {
m_dirLister->stop();
m_dirLister->openUrl(baseUrl);
return newurl;
}
-const QList<UrlNavigator::HistoryElem>& UrlNavigator::history(int& index) const
+UrlNavigator::HistoryElem UrlNavigator::currentHistoryItem() const
{
- index = m_historyIndex;
- return m_history;
+ return m_history[m_historyIndex];
+}
+
+int UrlNavigator::historySize() const
+{
+ return m_history.count();
}
void UrlNavigator::goBack()
*
* The URL navigator also remembers the URL history and allows to go
* back and forward within this history.
-*/
-
-//typedef QList<KUrl> UrlStack;
-
+ */
class UrlNavigator : public QWidget
{
Q_OBJECT
/** Returns the portion of the current active URL up to the button at index. */
KUrl url(int index) const;
+ /** Returns the amount of items in the history */
+ int historySize() const;
+
/**
- * Returns the complete URL history. The index 0 indicates the oldest
+ * Returns one item out of the history. The index 0 indicates the oldest
* history element.
* @param index Output parameter which indicates the current
* index of the location.
*/
- const QList<HistoryElem>& history(int& index) const;
+ HistoryElem currentHistoryItem() const;
/**
* Goes back one step in the URL history. The signals
QLineEdit* m_host;
QLinkedList<UrlNavigatorButton*> m_navButtons;
QWidget* m_filler;
- //UrlStack m_urls;
};
#endif
#define URLNAVIGATORBUTTON_H
#include <kio/global.h>
-#include <urlbutton.h>
+#include "urlbutton.h"
class KJob;
class KUrl;