diff options
| author | Peter Penz <[email protected]> | 2012-05-18 23:21:49 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-05-18 23:31:44 +0200 |
| commit | e9d29bcf30ccbd7c76ba37ce9efcfac1649fc46e (patch) | |
| tree | 954ea3c1e8f7204c5e51353f444333496988ae1e /src/panels/places | |
| parent | d9eab08fcb8bfc56470a7f418465607888b5f1ba (diff) | |
Enable basic drag and drop support for the Places Panel
The dropping has not been implemented yet, however in the context of
this step the creating of the drag-pixmap is now forwarded to
the item-widgets. This allows creating some optimized dragging-pixmaps
e.g. for the details-view, where only the name and icon should
be provided as drag-pixmap.
Diffstat (limited to 'src/panels/places')
| -rw-r--r-- | src/panels/places/placesitemmodel.cpp | 42 | ||||
| -rw-r--r-- | src/panels/places/placesitemmodel.h | 6 |
2 files changed, 43 insertions, 5 deletions
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 14ec54be8..68311bbab 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -37,6 +37,7 @@ #include "placesitem.h" #include <QAction> #include <QDate> +#include <QMimeData> #include <QTimer> #include <Solid/Device> @@ -291,7 +292,9 @@ void PlacesItemModel::requestEject(int index) this, SLOT(slotStorageTeardownDone(Solid::ErrorType,QVariant))); drive->eject(); } else { - + const QString label = item->text(); + const QString message = i18nc("@info", "The device '%1' is not a disk and cannot be ejected.", label); + emit errorMessage(message); } } } @@ -305,14 +308,43 @@ void PlacesItemModel::requestTeardown(int index) connect(access, SIGNAL(teardownDone(Solid::ErrorType,QVariant,QString)), this, SLOT(slotStorageTeardownDone(Solid::ErrorType,QVariant))); access->teardown(); - } else { - const QString label = item->text(); - const QString message = i18nc("@info", "The device '%1' is not a disk and cannot be ejected.", label); - emit errorMessage(message); } } } +QMimeData* PlacesItemModel::createMimeData(const QSet<int>& indexes) const +{ + KUrl::List urls; + QByteArray itemData; + + QDataStream stream(&itemData, QIODevice::WriteOnly); + + foreach (int index, indexes) { + const KUrl itemUrl = placesItem(index)->url(); + if (itemUrl.isValid()) { + urls << itemUrl; + } + stream << index; + } + + QMimeData* mimeData = new QMimeData(); + if (!urls.isEmpty()) { + urls.populateMimeData(mimeData); + } + + const QString internalMimeType = "application/x-dolphinplacesmodel-" + + QString::number((qptrdiff)this); + mimeData->setData(internalMimeType, itemData); + + return mimeData; +} + +bool PlacesItemModel::supportsDropping(int index) const +{ + Q_UNUSED(index); + return true; +} + KUrl PlacesItemModel::convertedUrl(const KUrl& url) { KUrl newUrl = url; diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h index 0f8f3025d..7225c04f4 100644 --- a/src/panels/places/placesitemmodel.h +++ b/src/panels/places/placesitemmodel.h @@ -105,6 +105,12 @@ public: void requestEject(int index); void requestTeardown(int index); + /** @reimp */ + virtual QMimeData* createMimeData(const QSet<int>& indexes) const; + + /** @reimp */ + virtual bool supportsDropping(int index) const; + /** * @return Converts the URL, which contains "virtual" URLs for system-items like * "search:/documents" into a Nepomuk-Query-URL that will be handled by |
