┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/panels
diff options
context:
space:
mode:
Diffstat (limited to 'src/panels')
-rw-r--r--src/panels/folders/folderspanel.cpp4
-rw-r--r--src/panels/folders/folderspanel.h6
-rw-r--r--src/panels/places/placespanel.cpp78
-rw-r--r--src/panels/places/placespanel.h13
4 files changed, 85 insertions, 16 deletions
diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp
index 5e8286cdc..9b22aa5a0 100644
--- a/src/panels/folders/folderspanel.cpp
+++ b/src/panels/folders/folderspanel.cpp
@@ -173,7 +173,7 @@ void FoldersPanel::slotItemActivated(int index)
{
const KFileItem item = m_model->fileItem(index);
if (!item.isNull()) {
- emit changeUrl(item.url(), Qt::LeftButton);
+ emit folderActivated(item.url());
}
}
@@ -181,7 +181,7 @@ void FoldersPanel::slotItemMiddleClicked(int index)
{
const KFileItem item = m_model->fileItem(index);
if (!item.isNull()) {
- emit changeUrl(item.url(), Qt::MiddleButton);
+ emit folderMiddleClicked(item.url());
}
}
diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h
index b21ecabad..a14c7d4d0 100644
--- a/src/panels/folders/folderspanel.h
+++ b/src/panels/folders/folderspanel.h
@@ -51,10 +51,8 @@ public:
void rename(const KFileItem& item);
signals:
- /**
- * Is emitted if the an URL change is requested.
- */
- void changeUrl(const KUrl& url, Qt::MouseButtons buttons);
+ void folderActivated(const KUrl& url);
+ void folderMiddleClicked(const KUrl& url);
protected:
/** @see Panel::urlChanged() */
diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp
index 4ac822760..5ea4b971c 100644
--- a/src/panels/places/placespanel.cpp
+++ b/src/panels/places/placespanel.cpp
@@ -1,6 +1,9 @@
/***************************************************************************
* Copyright (C) 2008-2012 by Peter Penz <[email protected]> *
- * Copyright (C) 2010 by Christian Muehlhaeuser <[email protected]> *
+ * *
+ * Based on KFilePlacesModel from kdelibs: *
+ * Copyright (C) 2007 Kevin Ottens <[email protected]> *
+ * Copyright (C) 2007 David Faure <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -20,12 +23,18 @@
#include "placespanel.h"
+#include <KBookmark>
+#include <KBookmarkGroup>
+#include <KBookmarkManager>
+#include <KComponentData>
+#include <KDebug>
#include <KIcon>
#include <kitemviews/kitemlistcontainer.h>
#include <kitemviews/kitemlistcontroller.h>
#include <kitemviews/kstandarditem.h>
#include <kitemviews/kstandarditemlistview.h>
#include <kitemviews/kstandarditemmodel.h>
+#include <KStandardDirs>
#include <views/draganddrophelper.h>
#include <QVBoxLayout>
#include <QShowEvent>
@@ -33,7 +42,9 @@
PlacesPanel::PlacesPanel(QWidget* parent) :
Panel(parent),
m_controller(0),
- m_model(0)
+ m_model(0),
+ m_availableDevices(),
+ m_bookmarkManager(0)
{
}
@@ -57,17 +68,17 @@ void PlacesPanel::showEvent(QShowEvent* event)
// Postpone the creating of the controller to the first show event.
// This assures that no performance and memory overhead is given when the folders panel is not
// used at all and stays invisible.
- KStandardItemListView* view = new KStandardItemListView();
+ const QString file = KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml");
+ m_bookmarkManager = KBookmarkManager::managerForFile(file, "kfileplaces");
m_model = new KStandardItemModel(this);
- m_model->appendItem(new KStandardItem("Temporary"));
- m_model->appendItem(new KStandardItem("out of"));
- m_model->appendItem(new KStandardItem("order. Press"));
- m_model->appendItem(new KStandardItem("F9 and use"));
- m_model->appendItem(new KStandardItem("the left icon"));
- m_model->appendItem(new KStandardItem("of the location"));
- m_model->appendItem(new KStandardItem("bar instead."));
+ loadBookmarks();
+
+ KStandardItemListView* view = new KStandardItemListView();
m_controller = new KItemListController(m_model, view, this);
+ m_controller->setSelectionBehavior(KItemListController::SingleSelection);
+ connect(m_controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int)));
+ connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
KItemListContainer* container = new KItemListContainer(m_controller, this);
container->setEnabledFrame(false);
@@ -80,10 +91,57 @@ void PlacesPanel::showEvent(QShowEvent* event)
Panel::showEvent(event);
}
+void PlacesPanel::slotItemActivated(int index)
+{
+ const KStandardItem* item = m_model->item(index);
+ if (item) {
+ const KUrl url = item->dataValue("url").value<KUrl>();
+ emit placeActivated(url);
+ }
+}
+
+void PlacesPanel::slotItemMiddleClicked(int index)
+{
+ const KStandardItem* item = m_model->item(index);
+ if (item) {
+ const KUrl url = item->dataValue("url").value<KUrl>();
+ emit placeMiddleClicked(url);
+ }
+}
+
void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
{
Q_UNUSED(parent);
DragAndDropHelper::dropUrls(KFileItem(), dest, event);
}
+void PlacesPanel::loadBookmarks()
+{
+ KBookmarkGroup root = m_bookmarkManager->root();
+ KBookmark bookmark = root.first();
+ QSet<QString> devices = m_availableDevices;
+
+ while (!bookmark.isNull()) {
+ const QString udi = bookmark.metaDataItem("UDI");
+ const QString appName = bookmark.metaDataItem("OnlyInApp");
+ const bool deviceAvailable = devices.remove(udi);
+
+ const bool allowedHere = appName.isEmpty() || (appName == KGlobal::mainComponent().componentName());
+
+ if ((udi.isEmpty() && allowedHere) || deviceAvailable) {
+ KStandardItem* item = new KStandardItem();
+ item->setIcon(KIcon(bookmark.icon()));
+ item->setText(bookmark.text());
+ item->setDataValue("address", bookmark.address());
+ item->setDataValue("url", bookmark.url());
+ if (deviceAvailable) {
+ item->setDataValue("udi", udi);
+ }
+ m_model->appendItem(item);
+ }
+
+ bookmark = root.next(bookmark);
+ }
+}
+
#include "placespanel.moc"
diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h
index 1c46cd57d..80cb732f0 100644
--- a/src/panels/places/placespanel.h
+++ b/src/panels/places/placespanel.h
@@ -22,7 +22,9 @@
#define PLACESPANEL_H
#include <panels/panel.h>
+#include <QSet>
+class KBookmarkManager;
class KItemListController;
class KStandardItemModel;
@@ -37,16 +39,27 @@ public:
PlacesPanel(QWidget* parent);
virtual ~PlacesPanel();
+signals:
+ void placeActivated(const KUrl& url);
+ void placeMiddleClicked(const KUrl& url);
+
protected:
virtual bool urlChanged();
virtual void showEvent(QShowEvent* event);
private slots:
+ void slotItemActivated(int index);
+ void slotItemMiddleClicked(int index);
void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
private:
+ void loadBookmarks();
+
+private:
KItemListController* m_controller;
KStandardItemModel* m_model;
+ QSet<QString> m_availableDevices;
+ KBookmarkManager* m_bookmarkManager;
};
#endif // PLACESPANEL_H