#include <kiconloader.h>
#include <kglobalsettings.h>
-#include <kbookmarkmanager.h>
+#include <kfileplacesmodel.h>
#include <kmenu.h>
#include <kdebug.h>
#include <QPixmap>
#include <kicon.h>
-BookmarkSelector::BookmarkSelector(UrlNavigator* parent, KBookmarkManager* bookmarkManager) :
+BookmarkSelector::BookmarkSelector(UrlNavigator* parent, KFilePlacesModel* placesModel) :
UrlButton(parent),
- m_selectedAddress(),
+ m_selectedItem(-1),
m_urlNavigator(parent),
- m_bookmarkManager(bookmarkManager)
+ m_placesModel(placesModel)
{
setFocusPolicy(Qt::NoFocus);
- m_bookmarksMenu = new KMenu(this);
-
- 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);
- m_bookmarksMenu->addAction(action);
- 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());
- setMinimumWidth(pixmap.width() + 2);
- }
- bookmark = root.next(bookmark);
- ++i;
- }
+ m_placesMenu = new KMenu(this);
- connect(m_bookmarksMenu, SIGNAL(triggered(QAction*)),
- this, SLOT(activateBookmark(QAction*)));
+ updateMenu();
- setMenu(m_bookmarksMenu);
+ connect(m_placesModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
+ this, SLOT(updateMenu()));
+ connect(m_placesModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
+ this, SLOT(updateMenu()));
+ connect(m_placesMenu, SIGNAL(triggered(QAction*)),
+ this, SLOT(activatePlace(QAction*)));
+
+ setMenu(m_placesMenu);
}
BookmarkSelector::~BookmarkSelector()
{
}
+void BookmarkSelector::updateMenu()
+{
+ m_placesMenu->clear();
+
+ for (int i=0; i<m_placesModel->rowCount(); ++i) {
+ QModelIndex index = m_placesModel->index(i, 0);
+ QAction* action = new QAction(m_placesModel->icon(index),
+ m_placesModel->text(index),
+ m_placesMenu);
+ m_placesMenu->addAction(action);
+
+ action->setData(i);
+
+ if (i == m_selectedItem) {
+ //QPixmap pixmap = SmallIcon(bookmark.icon());
+ setIcon(m_placesModel->icon(index));
+ //setIconSize(pixmap.size());
+ //setMinimumWidth(pixmap.width() + 2);
+ }
+ }
+}
+
void BookmarkSelector::updateSelection(const KUrl& url)
{
- KBookmark bookmark = m_bookmarkManager->root().closestBookmark(url);
- if (!bookmark.isNull()) {
- m_selectedAddress = bookmark.address();
- setIcon(KIcon(bookmark.icon()));
+ QModelIndex index = m_placesModel->closestItem(url);
+
+ if (index.isValid()) {
+ m_selectedItem = index.row();
+ setIcon(m_placesModel->icon(index));
}
else {
- m_selectedAddress = QString();
+ m_selectedItem = -1;
// No bookmark has been found which matches to the given Url. Show
// a generic folder icon as pixmap for indication:
setIcon(KIcon("folder"));
}
}
-KBookmark BookmarkSelector::selectedBookmark() const
+KUrl BookmarkSelector::selectedPlaceUrl() const
+{
+ QModelIndex index = m_placesModel->index(m_selectedItem, 0);
+
+ if (index.isValid())
+ return m_placesModel->url(index);
+ else
+ return KUrl();
+}
+
+QString BookmarkSelector::selectedPlaceText() const
{
- return m_bookmarkManager->findByAddress(m_selectedAddress);
+ QModelIndex index = m_placesModel->index(m_selectedItem, 0);
+
+ if (index.isValid())
+ return m_placesModel->text(index);
+ else
+ return QString();
}
QSize BookmarkSelector::sizeHint() const
painter.drawPixmap(x, y, pixmap);
}
-void BookmarkSelector::activateBookmark(QAction* action)
+void BookmarkSelector::activatePlace(QAction* action)
{
assert(action != 0);
- m_selectedAddress = action->data().toString();
+ m_selectedItem = action->data().toInt();
- const KBookmark bookmark = selectedBookmark();
- setPixmap(SmallIcon(bookmark.icon()));
- emit bookmarkActivated(bookmark.url());
+ QModelIndex index = m_placesModel->index(m_selectedItem, 0);
+
+ if (index.isValid()) {
+ setIcon(m_placesModel->icon(index));
+ emit placeActivated(m_placesModel->url(index));
+ }
}
#include "bookmarkselector.moc"
#ifndef BOOKMARKSELECTOR_H
#define BOOKMARKSELECTOR_H
-#include <kbookmark.h>
#include <urlbutton.h>
+#include <kurl.h>
+class KFilePlacesModel;
class UrlNavigator;
class KMenu;
-class KUrl;
/**
* @brief Allows to select a bookmark from a popup menu.
* @param parent Parent widget where the bookmark selector
* is embedded into.
*/
- BookmarkSelector(UrlNavigator* parent, KBookmarkManager* bookmarkManager);
+ BookmarkSelector(UrlNavigator* parent, KFilePlacesModel* placesModel);
virtual ~BookmarkSelector();
void updateSelection(const KUrl& url);
/** Returns the selected bookmark. */
- KBookmark selectedBookmark() const;
+ KUrl selectedPlaceUrl() const;
+ /** Returns the selected bookmark. */
+ QString selectedPlaceText() const;
/** @see QWidget::sizeHint() */
virtual QSize sizeHint() const;
signals:
/**
* Is send when a bookmark has been activated by the user.
- * @param url URL of the selected bookmark.
+ * @param url URL of the selected place.
*/
- void bookmarkActivated(const KUrl& url);
+ void placeActivated(const KUrl& url);
protected:
/**
* Updates the selected index and the icon to the bookmark
* which is indicated by the triggered action \a action.
*/
- void activateBookmark(QAction* action);
+ void activatePlace(QAction* action);
+
+ void updateMenu();
private:
- QString m_selectedAddress;
+ int m_selectedItem;
UrlNavigator* m_urlNavigator;
- KMenu* m_bookmarksMenu;
- KBookmarkManager* m_bookmarkManager;
+ KMenu* m_placesMenu;
+ KFilePlacesModel* m_placesModel;
};
#endif
#include <kdirmodel.h>
#include <kfileitemdelegate.h>
+#include <kfileplacesmodel.h>
#include <klocale.h>
#include <kiconeffect.h>
#include <kio/netaccess.h>
connect(clipboard, SIGNAL(dataChanged()),
this, SLOT(updateCutItems()));
- m_urlNavigator = new UrlNavigator(DolphinSettings::instance().bookmarkManager(), url, this);
+ m_urlNavigator = new UrlNavigator(new KFilePlacesModel(this), url, this);
m_urlNavigator->setUrlEditable(DolphinSettings::instance().generalSettings()->editableUrl());
m_urlNavigator->setHomeUrl(DolphinSettings::instance().generalSettings()->homeUrl());
m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
class UrlNavigator::Private
{
public:
- Private(UrlNavigator* q, KBookmarkManager* bookmarkManager);
+ Private(UrlNavigator* q, KFilePlacesModel* placesModel);
void slotReturnPressed(const QString&);
void slotRemoteHostActivated();
};
-UrlNavigator::Private::Private(UrlNavigator* q, KBookmarkManager* bookmarkManager)
+UrlNavigator::Private::Private(UrlNavigator* q, KFilePlacesModel* placesModel)
:
m_active(true),
m_showHiddenFiles(false),
q, SLOT(switchView()));
// initialize the bookmark selector
- m_bookmarkSelector = new BookmarkSelector(q, bookmarkManager);
- connect(m_bookmarkSelector, SIGNAL(bookmarkActivated(const KUrl&)),
+ m_bookmarkSelector = new BookmarkSelector(q, placesModel);
+ connect(m_bookmarkSelector, SIGNAL(placeActivated(const KUrl&)),
q, SLOT(setUrl(const KUrl&)));
// initialize the path box of the traditional view
m_filler->show();
// get the data from the currently selected bookmark
- KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
+ KUrl placeUrl = m_bookmarkSelector->selectedPlaceUrl();
- QString bookmarkPath;
- if (bookmark.isNull()) {
- // No bookmark is a part of the current Url.
- // The following code tries to guess the bookmark
+ QString placePath;
+ if (!placeUrl.isValid()) {
+ // No place is a part of the current Url.
+ // The following code tries to guess the place
// path. E. g. "fish://root@192.168.0.2/var/lib" writes
- // "fish://root@192.168.0.2" to 'bookmarkPath', which leads to the
+ // "fish://root@192.168.0.2" to 'placePath', which leads to the
// navigation indication 'Custom Path > var > lib".
int idx = path.indexOf(QString("//"));
idx = path.indexOf("/", (idx < 0) ? 0 : idx + 2);
- bookmarkPath = (idx < 0) ? path : path.left(idx);
+ placePath = (idx < 0) ? path : path.left(idx);
}
else {
- bookmarkPath = bookmark.url().pathOrUrl();
+ placePath = placeUrl.pathOrUrl();
}
- const uint len = bookmarkPath.length();
+ const uint len = placePath.length();
// calculate the start point for the URL navigator buttons by counting
- // the slashs inside the bookmark URL
+ // the slashs inside the place URL
int slashCount = 0;
for (uint i = 0; i < len; ++i) {
- if (bookmarkPath.at(i) == QChar('/')) {
+ if (placePath.at(i) == QChar('/')) {
++slashCount;
}
}
- if ((len > 0) && bookmarkPath.at(len - 1) == QChar('/')) {
+ if ((len > 0) && placePath.at(len - 1) == QChar('/')) {
assert(slashCount > 0);
--slashCount;
}
const KUrl currentUrl = q->url();
- if (!currentUrl.isLocalFile() && bookmark.isNull()) {
+ if (!currentUrl.isLocalFile() && !placeUrl.isValid()) {
QString protocol = currentUrl.protocol();
if (!m_protocols) {
deleteButtons();
QString text;
if (isFirstButton) {
// the first URL navigator button should get the name of the
- // bookmark instead of the directory name
- const KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
- text = bookmark.text();
+ // place instead of the directory name
+ const KUrl placeUrl = m_bookmarkSelector->selectedPlaceUrl();
+ text = m_bookmarkSelector->selectedPlaceText();
if (text.isEmpty()) {
if (currentUrl.isLocalFile()) {
text = i18n("Custom Path");
////
-UrlNavigator::UrlNavigator(KBookmarkManager* bookmarkManager,
+UrlNavigator::UrlNavigator(KFilePlacesModel* placesModel,
const KUrl& url,
QWidget* parent) :
QWidget(parent),
- d( new Private(this, bookmarkManager) )
+ d( new Private(this, placesModel) )
{
d->m_history.prepend(HistoryElem(url));
#include <kurl.h>
#include <QWidget>
-class KBookmarkManager;
+class KFilePlacesModel;
class QMouseEvent;
/**
Q_OBJECT
public:
- UrlNavigator(KBookmarkManager* bookmarkManager, const KUrl& url, QWidget* parent);
+ UrlNavigator(KFilePlacesModel* placesModel, const KUrl& url, QWidget* parent);
virtual ~UrlNavigator();
/** Returns the current active URL. */