mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-17 15:31:20 +00:00
Make use of KFilePlaces instead of the bookmark system in the URL
navigator. Yay! svn path=/trunk/KDE/kdebase/apps/; revision=649452
This commit is contained in:
parent
c2c6f743a5
commit
78c312a0f3
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include <kiconloader.h>
|
#include <kiconloader.h>
|
||||||
#include <kglobalsettings.h>
|
#include <kglobalsettings.h>
|
||||||
#include <kbookmarkmanager.h>
|
#include <kfileplacesmodel.h>
|
||||||
#include <kmenu.h>
|
#include <kmenu.h>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
|
||||||
|
@ -33,65 +33,88 @@
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <kicon.h>
|
#include <kicon.h>
|
||||||
|
|
||||||
BookmarkSelector::BookmarkSelector(UrlNavigator* parent, KBookmarkManager* bookmarkManager) :
|
BookmarkSelector::BookmarkSelector(UrlNavigator* parent, KFilePlacesModel* placesModel) :
|
||||||
UrlButton(parent),
|
UrlButton(parent),
|
||||||
m_selectedAddress(),
|
m_selectedItem(-1),
|
||||||
m_urlNavigator(parent),
|
m_urlNavigator(parent),
|
||||||
m_bookmarkManager(bookmarkManager)
|
m_placesModel(placesModel)
|
||||||
{
|
{
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
|
|
||||||
m_bookmarksMenu = new KMenu(this);
|
m_placesMenu = new KMenu(this);
|
||||||
|
|
||||||
KBookmarkGroup root = m_bookmarkManager->root();
|
updateMenu();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(m_bookmarksMenu, SIGNAL(triggered(QAction*)),
|
connect(m_placesModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
|
||||||
this, SLOT(activateBookmark(QAction*)));
|
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_bookmarksMenu);
|
setMenu(m_placesMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
BookmarkSelector::~BookmarkSelector()
|
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)
|
void BookmarkSelector::updateSelection(const KUrl& url)
|
||||||
{
|
{
|
||||||
KBookmark bookmark = m_bookmarkManager->root().closestBookmark(url);
|
QModelIndex index = m_placesModel->closestItem(url);
|
||||||
if (!bookmark.isNull()) {
|
|
||||||
m_selectedAddress = bookmark.address();
|
if (index.isValid()) {
|
||||||
setIcon(KIcon(bookmark.icon()));
|
m_selectedItem = index.row();
|
||||||
|
setIcon(m_placesModel->icon(index));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_selectedAddress = QString();
|
m_selectedItem = -1;
|
||||||
// No bookmark has been found which matches to the given Url. Show
|
// No bookmark has been found which matches to the given Url. Show
|
||||||
// a generic folder icon as pixmap for indication:
|
// a generic folder icon as pixmap for indication:
|
||||||
setIcon(KIcon("folder"));
|
setIcon(KIcon("folder"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KBookmark BookmarkSelector::selectedBookmark() const
|
KUrl BookmarkSelector::selectedPlaceUrl() const
|
||||||
{
|
{
|
||||||
return m_bookmarkManager->findByAddress(m_selectedAddress);
|
QModelIndex index = m_placesModel->index(m_selectedItem, 0);
|
||||||
|
|
||||||
|
if (index.isValid())
|
||||||
|
return m_placesModel->url(index);
|
||||||
|
else
|
||||||
|
return KUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BookmarkSelector::selectedPlaceText() const
|
||||||
|
{
|
||||||
|
QModelIndex index = m_placesModel->index(m_selectedItem, 0);
|
||||||
|
|
||||||
|
if (index.isValid())
|
||||||
|
return m_placesModel->text(index);
|
||||||
|
else
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize BookmarkSelector::sizeHint() const
|
QSize BookmarkSelector::sizeHint() const
|
||||||
|
@ -148,14 +171,17 @@ void BookmarkSelector::paintEvent(QPaintEvent* /*event*/)
|
||||||
painter.drawPixmap(x, y, pixmap);
|
painter.drawPixmap(x, y, pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkSelector::activateBookmark(QAction* action)
|
void BookmarkSelector::activatePlace(QAction* action)
|
||||||
{
|
{
|
||||||
assert(action != 0);
|
assert(action != 0);
|
||||||
m_selectedAddress = action->data().toString();
|
m_selectedItem = action->data().toInt();
|
||||||
|
|
||||||
const KBookmark bookmark = selectedBookmark();
|
QModelIndex index = m_placesModel->index(m_selectedItem, 0);
|
||||||
setPixmap(SmallIcon(bookmark.icon()));
|
|
||||||
emit bookmarkActivated(bookmark.url());
|
if (index.isValid()) {
|
||||||
|
setIcon(m_placesModel->icon(index));
|
||||||
|
emit placeActivated(m_placesModel->url(index));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "bookmarkselector.moc"
|
#include "bookmarkselector.moc"
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
#ifndef BOOKMARKSELECTOR_H
|
#ifndef BOOKMARKSELECTOR_H
|
||||||
#define BOOKMARKSELECTOR_H
|
#define BOOKMARKSELECTOR_H
|
||||||
|
|
||||||
#include <kbookmark.h>
|
|
||||||
#include <urlbutton.h>
|
#include <urlbutton.h>
|
||||||
|
#include <kurl.h>
|
||||||
|
|
||||||
|
class KFilePlacesModel;
|
||||||
class UrlNavigator;
|
class UrlNavigator;
|
||||||
class KMenu;
|
class KMenu;
|
||||||
class KUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Allows to select a bookmark from a popup menu.
|
* @brief Allows to select a bookmark from a popup menu.
|
||||||
|
@ -44,7 +44,7 @@ public:
|
||||||
* @param parent Parent widget where the bookmark selector
|
* @param parent Parent widget where the bookmark selector
|
||||||
* is embedded into.
|
* is embedded into.
|
||||||
*/
|
*/
|
||||||
BookmarkSelector(UrlNavigator* parent, KBookmarkManager* bookmarkManager);
|
BookmarkSelector(UrlNavigator* parent, KFilePlacesModel* placesModel);
|
||||||
|
|
||||||
virtual ~BookmarkSelector();
|
virtual ~BookmarkSelector();
|
||||||
|
|
||||||
|
@ -58,7 +58,9 @@ public:
|
||||||
void updateSelection(const KUrl& url);
|
void updateSelection(const KUrl& url);
|
||||||
|
|
||||||
/** Returns the selected bookmark. */
|
/** Returns the selected bookmark. */
|
||||||
KBookmark selectedBookmark() const;
|
KUrl selectedPlaceUrl() const;
|
||||||
|
/** Returns the selected bookmark. */
|
||||||
|
QString selectedPlaceText() const;
|
||||||
|
|
||||||
/** @see QWidget::sizeHint() */
|
/** @see QWidget::sizeHint() */
|
||||||
virtual QSize sizeHint() const;
|
virtual QSize sizeHint() const;
|
||||||
|
@ -66,9 +68,9 @@ public:
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* Is send when a bookmark has been activated by the user.
|
* 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:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
@ -82,13 +84,15 @@ private slots:
|
||||||
* Updates the selected index and the icon to the bookmark
|
* Updates the selected index and the icon to the bookmark
|
||||||
* which is indicated by the triggered action \a action.
|
* which is indicated by the triggered action \a action.
|
||||||
*/
|
*/
|
||||||
void activateBookmark(QAction* action);
|
void activatePlace(QAction* action);
|
||||||
|
|
||||||
|
void updateMenu();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_selectedAddress;
|
int m_selectedItem;
|
||||||
UrlNavigator* m_urlNavigator;
|
UrlNavigator* m_urlNavigator;
|
||||||
KMenu* m_bookmarksMenu;
|
KMenu* m_placesMenu;
|
||||||
KBookmarkManager* m_bookmarkManager;
|
KFilePlacesModel* m_placesModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <kdirmodel.h>
|
#include <kdirmodel.h>
|
||||||
#include <kfileitemdelegate.h>
|
#include <kfileitemdelegate.h>
|
||||||
|
#include <kfileplacesmodel.h>
|
||||||
#include <klocale.h>
|
#include <klocale.h>
|
||||||
#include <kiconeffect.h>
|
#include <kiconeffect.h>
|
||||||
#include <kio/netaccess.h>
|
#include <kio/netaccess.h>
|
||||||
|
@ -96,7 +97,7 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
|
||||||
connect(clipboard, SIGNAL(dataChanged()),
|
connect(clipboard, SIGNAL(dataChanged()),
|
||||||
this, SLOT(updateCutItems()));
|
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->setUrlEditable(DolphinSettings::instance().generalSettings()->editableUrl());
|
||||||
m_urlNavigator->setHomeUrl(DolphinSettings::instance().generalSettings()->homeUrl());
|
m_urlNavigator->setHomeUrl(DolphinSettings::instance().generalSettings()->homeUrl());
|
||||||
m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
|
m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
|
||||||
|
|
|
@ -98,7 +98,7 @@ HistoryElem::~HistoryElem()
|
||||||
class UrlNavigator::Private
|
class UrlNavigator::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private(UrlNavigator* q, KBookmarkManager* bookmarkManager);
|
Private(UrlNavigator* q, KFilePlacesModel* placesModel);
|
||||||
|
|
||||||
void slotReturnPressed(const QString&);
|
void slotReturnPressed(const QString&);
|
||||||
void slotRemoteHostActivated();
|
void slotRemoteHostActivated();
|
||||||
|
@ -162,7 +162,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UrlNavigator::Private::Private(UrlNavigator* q, KBookmarkManager* bookmarkManager)
|
UrlNavigator::Private::Private(UrlNavigator* q, KFilePlacesModel* placesModel)
|
||||||
:
|
:
|
||||||
m_active(true),
|
m_active(true),
|
||||||
m_showHiddenFiles(false),
|
m_showHiddenFiles(false),
|
||||||
|
@ -189,8 +189,8 @@ UrlNavigator::Private::Private(UrlNavigator* q, KBookmarkManager* bookmarkManage
|
||||||
q, SLOT(switchView()));
|
q, SLOT(switchView()));
|
||||||
|
|
||||||
// initialize the bookmark selector
|
// initialize the bookmark selector
|
||||||
m_bookmarkSelector = new BookmarkSelector(q, bookmarkManager);
|
m_bookmarkSelector = new BookmarkSelector(q, placesModel);
|
||||||
connect(m_bookmarkSelector, SIGNAL(bookmarkActivated(const KUrl&)),
|
connect(m_bookmarkSelector, SIGNAL(placeActivated(const KUrl&)),
|
||||||
q, SLOT(setUrl(const KUrl&)));
|
q, SLOT(setUrl(const KUrl&)));
|
||||||
|
|
||||||
// initialize the path box of the traditional view
|
// initialize the path box of the traditional view
|
||||||
|
@ -403,39 +403,39 @@ void UrlNavigator::Private::updateContent()
|
||||||
m_filler->show();
|
m_filler->show();
|
||||||
|
|
||||||
// get the data from the currently selected bookmark
|
// get the data from the currently selected bookmark
|
||||||
KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
|
KUrl placeUrl = m_bookmarkSelector->selectedPlaceUrl();
|
||||||
|
|
||||||
QString bookmarkPath;
|
QString placePath;
|
||||||
if (bookmark.isNull()) {
|
if (!placeUrl.isValid()) {
|
||||||
// No bookmark is a part of the current Url.
|
// No place is a part of the current Url.
|
||||||
// The following code tries to guess the bookmark
|
// The following code tries to guess the place
|
||||||
// path. E. g. "fish://root@192.168.0.2/var/lib" writes
|
// 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".
|
// navigation indication 'Custom Path > var > lib".
|
||||||
int idx = path.indexOf(QString("//"));
|
int idx = path.indexOf(QString("//"));
|
||||||
idx = path.indexOf("/", (idx < 0) ? 0 : idx + 2);
|
idx = path.indexOf("/", (idx < 0) ? 0 : idx + 2);
|
||||||
bookmarkPath = (idx < 0) ? path : path.left(idx);
|
placePath = (idx < 0) ? path : path.left(idx);
|
||||||
}
|
}
|
||||||
else {
|
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
|
// 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;
|
int slashCount = 0;
|
||||||
for (uint i = 0; i < len; ++i) {
|
for (uint i = 0; i < len; ++i) {
|
||||||
if (bookmarkPath.at(i) == QChar('/')) {
|
if (placePath.at(i) == QChar('/')) {
|
||||||
++slashCount;
|
++slashCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((len > 0) && bookmarkPath.at(len - 1) == QChar('/')) {
|
if ((len > 0) && placePath.at(len - 1) == QChar('/')) {
|
||||||
assert(slashCount > 0);
|
assert(slashCount > 0);
|
||||||
--slashCount;
|
--slashCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
const KUrl currentUrl = q->url();
|
const KUrl currentUrl = q->url();
|
||||||
if (!currentUrl.isLocalFile() && bookmark.isNull()) {
|
if (!currentUrl.isLocalFile() && !placeUrl.isValid()) {
|
||||||
QString protocol = currentUrl.protocol();
|
QString protocol = currentUrl.protocol();
|
||||||
if (!m_protocols) {
|
if (!m_protocols) {
|
||||||
deleteButtons();
|
deleteButtons();
|
||||||
|
@ -511,9 +511,9 @@ void UrlNavigator::Private::updateButtons(const QString& path, int startIndex)
|
||||||
QString text;
|
QString text;
|
||||||
if (isFirstButton) {
|
if (isFirstButton) {
|
||||||
// the first URL navigator button should get the name of the
|
// the first URL navigator button should get the name of the
|
||||||
// bookmark instead of the directory name
|
// place instead of the directory name
|
||||||
const KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
|
const KUrl placeUrl = m_bookmarkSelector->selectedPlaceUrl();
|
||||||
text = bookmark.text();
|
text = m_bookmarkSelector->selectedPlaceText();
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
if (currentUrl.isLocalFile()) {
|
if (currentUrl.isLocalFile()) {
|
||||||
text = i18n("Custom Path");
|
text = i18n("Custom Path");
|
||||||
|
@ -576,11 +576,11 @@ void UrlNavigator::Private::deleteButtons()
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
||||||
UrlNavigator::UrlNavigator(KBookmarkManager* bookmarkManager,
|
UrlNavigator::UrlNavigator(KFilePlacesModel* placesModel,
|
||||||
const KUrl& url,
|
const KUrl& url,
|
||||||
QWidget* parent) :
|
QWidget* parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
d( new Private(this, bookmarkManager) )
|
d( new Private(this, placesModel) )
|
||||||
{
|
{
|
||||||
d->m_history.prepend(HistoryElem(url));
|
d->m_history.prepend(HistoryElem(url));
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include <kurl.h>
|
#include <kurl.h>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class KBookmarkManager;
|
class KFilePlacesModel;
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +50,7 @@ class UrlNavigator : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UrlNavigator(KBookmarkManager* bookmarkManager, const KUrl& url, QWidget* parent);
|
UrlNavigator(KFilePlacesModel* placesModel, const KUrl& url, QWidget* parent);
|
||||||
virtual ~UrlNavigator();
|
virtual ~UrlNavigator();
|
||||||
|
|
||||||
/** Returns the current active URL. */
|
/** Returns the current active URL. */
|
||||||
|
|
Loading…
Reference in a new issue