┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2012-05-16 19:15:49 +0200
committerPeter Penz <[email protected]>2012-05-16 19:19:57 +0200
commit2fd31c8a95eaa38defa0f6adf3b83b12fc1aa1a3 (patch)
treec207e2e743e23f88a42b8eac5e5c3907c02ac745 /src
parenta632e8b9ef43f3b3516012bc1c44f53f31c385da (diff)
Update trash-icon dependent on whether the thrash is empty or not
The class PlacesItemStorageAccessListener has been renamed to PlacesItemSignalHandler and represents a generic signal handler for the PlacesItem.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/panels/places/placesitem.cpp54
-rw-r--r--src/panels/places/placesitem.h21
-rw-r--r--src/panels/places/placesitemlistwidget.h4
-rw-r--r--src/panels/places/placesitemmodel.cpp4
-rw-r--r--src/panels/places/placesitemsignalhandler.cpp (renamed from src/panels/places/placesitemstorageaccesslistener.cpp)27
-rw-r--r--src/panels/places/placesitemsignalhandler.h (renamed from src/panels/places/placesitemstorageaccesslistener.h)42
7 files changed, 99 insertions, 55 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dfdde9ba0..0373d0e78 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -162,7 +162,7 @@ set(dolphin_SRCS
panels/places/placesitemlistgroupheader.cpp
panels/places/placesitemlistwidget.cpp
panels/places/placesitemmodel.cpp
- panels/places/placesitemstorageaccesslistener.cpp
+ panels/places/placesitemsignalhandler.cpp
panels/panel.cpp
panels/folders/treeviewcontextmenu.cpp
panels/folders/folderspanel.cpp
diff --git a/src/panels/places/placesitem.cpp b/src/panels/places/placesitem.cpp
index 9e4cb6846..7a5daff8e 100644
--- a/src/panels/places/placesitem.cpp
+++ b/src/panels/places/placesitem.cpp
@@ -24,9 +24,10 @@
#include <KBookmarkManager>
#include <KDebug>
+#include <KDirLister>
#include <KIcon>
#include <KLocale>
-#include "placesitemstorageaccesslistener.h"
+#include "placesitemsignalhandler.h"
#include <QDateTime>
#include <Solid/Block>
@@ -36,29 +37,18 @@ PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) :
m_access(),
m_volume(),
m_disc(),
- m_accessListener(0),
+ m_signalHandler(0),
+ m_trashDirLister(0),
m_bookmark()
{
+ m_signalHandler = new PlacesItemSignalHandler(this);
setBookmark(bookmark);
}
-PlacesItem::PlacesItem(const PlacesItem& item) :
- KStandardItem(item),
- m_device(item.m_device),
- m_access(item.m_access),
- m_volume(item.m_volume),
- m_disc(item.m_disc),
- m_accessListener(0),
- m_bookmark(item.m_bookmark)
-{
- if (item.m_accessListener) {
- m_accessListener = new PlacesItemStorageAccessListener(this);
- }
-}
-
PlacesItem::~PlacesItem()
{
- delete m_accessListener;
+ delete m_signalHandler;
+ delete m_trashDirLister;
}
void PlacesItem::setUrl(const KUrl& url)
@@ -69,6 +59,20 @@ void PlacesItem::setUrl(const KUrl& url)
// setting an equal URL results in an itemsChanged()
// signal.
if (dataValue("url").value<KUrl>() != url) {
+ delete m_trashDirLister;
+ if (url.protocol() == QLatin1String("trash")) {
+ // The trash icon must always be updated dependent on whether
+ // the trash is empty or not. We use a KDirLister that automatically
+ // watches for changes if the number of items has been changed.
+ // The update of the icon is handled in onTrashDirListerCompleted().
+ m_trashDirLister = new KDirLister();
+ m_trashDirLister->setAutoErrorHandlingEnabled(false, 0);
+ m_trashDirLister->setDelayedMimeTypes(true);
+ QObject::connect(m_trashDirLister, SIGNAL(completed()),
+ m_signalHandler, SLOT(onTrashDirListerCompleted()));
+ m_trashDirLister->openUrl(url);
+ }
+
setDataValue("url", url);
}
}
@@ -120,7 +124,6 @@ void PlacesItem::setBookmark(const KBookmark& bookmark)
delete m_access;
delete m_volume;
delete m_disc;
- delete m_accessListener;
const QString udi = bookmark.metaDataItem("UDI");
if (udi.isEmpty()) {
@@ -240,11 +243,8 @@ void PlacesItem::initializeDevice(const QString& udi)
if (m_access) {
setUrl(m_access->filePath());
- if (!m_accessListener) {
- // The access listener takes care to call PlacesItem::onAccessibilityChanged()
- // in case if the accessibility of m_access has been changed.
- m_accessListener = new PlacesItemStorageAccessListener(this);
- }
+ QObject::connect(m_access, SIGNAL(accessibilityChanged(bool,QString)),
+ m_signalHandler, SLOT(onAccessibilityChanged()));
} else if (m_disc && (m_disc->availableContent() & Solid::OpticalDisc::Audio) != 0) {
const QString device = m_device.as<Solid::Block>()->device();
setUrl(QString("audiocd:/?device=%1").arg(device));
@@ -256,6 +256,14 @@ void PlacesItem::onAccessibilityChanged()
setIconOverlays(m_device.emblems());
}
+void PlacesItem::onTrashDirListerCompleted()
+{
+ Q_ASSERT(url().protocol() == QLatin1String("trash"));
+
+ const bool isTrashEmpty = m_trashDirLister->items().isEmpty();
+ setIcon(isTrashEmpty ? "user-trash" : "user-trash-full");
+}
+
void PlacesItem::updateBookmarkForRole(const QByteArray& role)
{
Q_ASSERT(!m_bookmark.isNull());
diff --git a/src/panels/places/placesitem.h b/src/panels/places/placesitem.h
index 81fbe5c60..1d221170c 100644
--- a/src/panels/places/placesitem.h
+++ b/src/panels/places/placesitem.h
@@ -29,7 +29,8 @@
#include <Solid/StorageAccess>
#include <Solid/StorageVolume>
-class PlacesItemStorageAccessListener;
+class KDirLister;
+class PlacesItemSignalHandler;
/**
* @brief Extends KStandardItem by places-specific properties.
@@ -47,7 +48,6 @@ public:
};
explicit PlacesItem(const KBookmark& bookmark, PlacesItem* parent = 0);
- explicit PlacesItem(const PlacesItem& item);
virtual ~PlacesItem();
void setUrl(const KUrl& url);
@@ -85,15 +85,23 @@ protected:
const QHash<QByteArray, QVariant>& previous);
private:
+ PlacesItem(const PlacesItem& item);
+
void initializeDevice(const QString& udi);
/**
- * Is invoked by m_accessListener if the accessibility
- * of the storage access m_access has been changed.
+ * Is invoked if the accessibility of the storage access
+ * m_access has been changed and updates the emblem.
*/
void onAccessibilityChanged();
/**
+ * Is invoked if the listing of the trash has been completed.
+ * Updates the state of the trash-icon to be empty or full.
+ */
+ void onTrashDirListerCompleted();
+
+ /**
* Applies the data-value from the role to m_bookmark.
*/
void updateBookmarkForRole(const QByteArray& role);
@@ -105,10 +113,11 @@ private:
QPointer<Solid::StorageAccess> m_access;
QPointer<Solid::StorageVolume> m_volume;
QPointer<Solid::OpticalDisc> m_disc;
- QPointer<PlacesItemStorageAccessListener> m_accessListener;
+ QPointer<PlacesItemSignalHandler> m_signalHandler;
+ QPointer<KDirLister> m_trashDirLister;
KBookmark m_bookmark;
- friend class PlacesItemStorageAccessListener; // Calls onAccessibilityChanged()
+ friend class PlacesItemSignalHandler; // Calls onAccessibilityChanged()
};
#endif
diff --git a/src/panels/places/placesitemlistwidget.h b/src/panels/places/placesitemlistwidget.h
index 28e0f00e8..d7a4f3ddd 100644
--- a/src/panels/places/placesitemlistwidget.h
+++ b/src/panels/places/placesitemlistwidget.h
@@ -22,6 +22,10 @@
#include <kitemviews/kstandarditemlistwidget.h>
+/**
+ * @brief Extends KStandardItemListWidget to interpret the hidden
+ * property of the PlacesModel.
+*/
class PlacesItemListWidget : public KStandardItemListWidget
{
Q_OBJECT
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp
index 4fb86fda8..aaeab796e 100644
--- a/src/panels/places/placesitemmodel.cpp
+++ b/src/panels/places/placesitemmodel.cpp
@@ -761,8 +761,8 @@ void PlacesItemModel::hideItem(int index)
const int newIndex = bookmarkIndex(index);
if (newIndex >= 0) {
- PlacesItem* hiddenItem = new PlacesItem(*shownItem);
- const KBookmark hiddenBookmark = hiddenItem->bookmark();
+ const KBookmark hiddenBookmark = shownItem->bookmark();
+ PlacesItem* hiddenItem = new PlacesItem(hiddenBookmark);
const PlacesItem* previousItem = placesItem(index - 1);
KBookmark previousBookmark;
diff --git a/src/panels/places/placesitemstorageaccesslistener.cpp b/src/panels/places/placesitemsignalhandler.cpp
index 7d65a2874..54a916de7 100644
--- a/src/panels/places/placesitemstorageaccesslistener.cpp
+++ b/src/panels/places/placesitemsignalhandler.cpp
@@ -17,29 +17,34 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#include "placesitemstorageaccesslistener.h"
+#include "placesitemsignalhandler.h"
#include "placesitem.h"
#include <Solid/StorageAccess>
-PlacesItemStorageAccessListener::PlacesItemStorageAccessListener(PlacesItem* item,
- QObject* parent) :
+PlacesItemSignalHandler::PlacesItemSignalHandler(PlacesItem* item,
+ QObject* parent) :
QObject(parent),
m_item(item)
{
- if (item) {
- connect(item->m_access, SIGNAL(accessibilityChanged(bool,QString)),
- this, SLOT(slotAccessibilityChanged()));
- }
}
-PlacesItemStorageAccessListener::~PlacesItemStorageAccessListener()
+PlacesItemSignalHandler::~PlacesItemSignalHandler()
+{
+}
+
+void PlacesItemSignalHandler::onAccessibilityChanged()
{
+ if (m_item) {
+ m_item->onAccessibilityChanged();
+ }
}
-void PlacesItemStorageAccessListener::slotAccessibilityChanged()
+void PlacesItemSignalHandler::onTrashDirListerCompleted()
{
- m_item->onAccessibilityChanged();
+ if (m_item) {
+ m_item->onTrashDirListerCompleted();
+ }
}
-#include "placesitemstorageaccesslistener.moc"
+#include "placesitemsignalhandler.moc"
diff --git a/src/panels/places/placesitemstorageaccesslistener.h b/src/panels/places/placesitemsignalhandler.h
index a3187c81a..d767b58d3 100644
--- a/src/panels/places/placesitemstorageaccesslistener.h
+++ b/src/panels/places/placesitemsignalhandler.h
@@ -17,31 +17,49 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
-#ifndef PLACESITEMSTORAGEACCESSLISTENER_H
-#define PLACESITEMSTORAGEACCESSLISTENER_H
+#ifndef PLACESITEMSIGNALHANDLER_H
+#define PLACESITEMSIGNALHANDLER_H
#include <QObject>
class PlacesItem;
/**
- * @brief Helper class for PlacesItem to listen to accessibility changes
- * of the storage access.
+ * @brief Helper class for PlacesItem to be able to listen to signals
+ * and performing a corresponding action.
*
- * Connects to the storage access from the given places item and
- * calls PlacesItem::onAccessibilityChanged() in case if the accessibility
- * has been changed.
+ * PlacesItem is derived from KStandardItem, which is no QObject-class
+ * on purpose. To be able to internally listening to signals and performing a
+ * corresponding action, PlacesItemSignalHandler is used.
+ *
+ * E.g. if the PlacesItem wants to react on accessibility-changes of a storage-access,
+ * the signal-handler can be used like this:
+ * <code>
+ * QObject::connect(storageAccess, SIGNAL(accessibilityChanged(bool,QString)),
+ * signalHandler, SLOT(onAccessibilityChanged()));
+ * </code>
+ *
+ * The slot PlacesItemSignalHandler::onAccessibilityChanged() will call
+ * the method PlacesItem::onAccessibilityChanged().
*/
-class PlacesItemStorageAccessListener: public QObject
+class PlacesItemSignalHandler: public QObject
{
Q_OBJECT
public:
- explicit PlacesItemStorageAccessListener(PlacesItem* item, QObject* parent = 0);
- virtual ~PlacesItemStorageAccessListener();
+ explicit PlacesItemSignalHandler(PlacesItem* item, QObject* parent = 0);
+ virtual ~PlacesItemSignalHandler();
+
+public slots:
+ /**
+ * Calls PlacesItem::onAccessibilityChanged()
+ */
+ void onAccessibilityChanged();
-private slots:
- void slotAccessibilityChanged();
+ /**
+ * Calls PlacesItem::onTrashDirListerCompleted()
+ */
+ void onTrashDirListerCompleted();
private:
PlacesItem* m_item;