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
#include <KBookmarkManager>
#include <KDebug>
+#include <KDirLister>
#include <KIcon>
#include <KLocale>
-#include "placesitemstorageaccesslistener.h"
+#include "placesitemsignalhandler.h"
#include <QDateTime>
#include <Solid/Block>
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)
// 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);
}
}
delete m_access;
delete m_volume;
delete m_disc;
- delete m_accessListener;
const QString udi = bookmark.metaDataItem("UDI");
if (udi.isEmpty()) {
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));
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());
#include <Solid/StorageAccess>
#include <Solid/StorageVolume>
-class PlacesItemStorageAccessListener;
+class KDirLister;
+class PlacesItemSignalHandler;
/**
* @brief Extends KStandardItem by places-specific properties.
};
explicit PlacesItem(const KBookmark& bookmark, PlacesItem* parent = 0);
- explicit PlacesItem(const PlacesItem& item);
virtual ~PlacesItem();
void setUrl(const KUrl& url);
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.
*/
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
#include <kitemviews/kstandarditemlistwidget.h>
+/**
+ * @brief Extends KStandardItemListWidget to interpret the hidden
+ * property of the PlacesModel.
+*/
class PlacesItemListWidget : public KStandardItemListWidget
{
Q_OBJECT
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;
* 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"
* 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;