From 5ce8878b23a2fe0f76f84c86f1fd881f812750ad Mon Sep 17 00:00:00 2001
From: Simon Frei <freisim93@gmail.com>
Date: Mon, 30 Oct 2017 17:16:19 +0100
Subject: [PATCH] remove unused KIO legacy and polish drag&drop mime

---
 app/dragdrop/albumdragdrop.cpp             |  5 ++---
 app/dragdrop/ddragobjects.cpp              | 35 ++++++++----------------------
 app/dragdrop/ddragobjects.h                | 12 ++++------
 app/dragdrop/imagedragdrop.cpp             |  9 +++-----
 app/dragdrop/tagdragdrop.cpp               |  5 ++---
 libs/database/item/imageinfo.cpp           | 18 ++-------------
 libs/database/item/imageinfo.h             | 12 ++--------
 utilities/fuzzysearch/fuzzysearchview.cpp  |  3 +--
 utilities/imageeditor/main/imagewindow.cpp | 10 ++++-----
 utilities/lighttable/lighttablepreview.cpp |  8 +++----
 utilities/queuemanager/views/queuelist.cpp | 12 ++++------
 utilities/queuemanager/views/queuepool.cpp |  3 +--
 12 files changed, 38 insertions(+), 94 deletions(-)

diff --git a/app/dragdrop/albumdragdrop.cpp b/app/dragdrop/albumdragdrop.cpp
index 1faec67633..afd943b30a 100644
--- a/app/dragdrop/albumdragdrop.cpp
+++ b/app/dragdrop/albumdragdrop.cpp
@@ -115,16 +115,15 @@ bool AlbumDragDropHandler::dropEvent(QAbstractItemView* view, const QDropEvent*
     {
 
         QList<QUrl>      urls;
-        QList<QUrl>      kioURLs;
         QList<int>       albumIDs;
         QList<qlonglong> imageIDs;
 
-        if (!DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+        if (!DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
         {
             return false;
         }
 
-        if (urls.isEmpty() || kioURLs.isEmpty() || albumIDs.isEmpty() || imageIDs.isEmpty())
+        if (urls.isEmpty() || albumIDs.isEmpty() || imageIDs.isEmpty())
         {
             return false;
         }
diff --git a/app/dragdrop/ddragobjects.cpp b/app/dragdrop/ddragobjects.cpp
index 76b1b71ada..09bd7b2d30 100644
--- a/app/dragdrop/ddragobjects.cpp
+++ b/app/dragdrop/ddragobjects.cpp
@@ -32,7 +32,6 @@ namespace Digikam
 {
 
 DItemDrag::DItemDrag(const QList<QUrl>& urls,
-                     const QList<QUrl>& kioUrls,
                      const QList<int>& albumIDs,
                      const QList<qlonglong>& imageIDs)
     : QMimeData()
@@ -41,13 +40,9 @@ DItemDrag::DItemDrag(const QList<QUrl>& urls,
     QByteArray  ba;
     QDataStream ds(&ba, QIODevice::WriteOnly);
     ds << urls;
-    setData(QLatin1String("digikam/item-ids"), ba);
-
-    QByteArray  ba2;
-    QDataStream ds2(&ba2, QIODevice::WriteOnly);
-    ds2 << kioUrls;
-    setData(QLatin1String("digikam/digikamalbums"), ba2);
+    setData(QLatin1String("digikam/item-urls"), ba);
 
+    // inconsistent numbering is legacy
     QByteArray  ba3;
     QDataStream ds3(&ba3, QIODevice::WriteOnly);
     ds3 << albumIDs;
@@ -56,7 +51,7 @@ DItemDrag::DItemDrag(const QList<QUrl>& urls,
     QByteArray  ba4;
     QDataStream ds4(&ba4, QIODevice::WriteOnly);
     ds4 << imageIDs;
-    setData(QLatin1String("digikam/image-ids-long"), ba4);
+    setData(QLatin1String("digikam/item-ids"), ba4);
 
     // commonly accessible mime data, for dragging to outside digikam
     setUrls(urls);
@@ -66,10 +61,9 @@ QStringList DItemDrag::mimeTypes()
 {
     // we do not want to decode text/uri-list with this object,
     // we only export this data above for dragging to outside digikam.
-    return QStringList() << QLatin1String("digikam/item-ids")
+    return QStringList() << QLatin1String("digikam/item-urls")
                          << QLatin1String("digikam/album-ids")
-                         << QLatin1String("digikam/image-ids-long")
-                         << QLatin1String("digikam/digikamalbums");
+                         << QLatin1String("digikam/item-ids");
 }
 
 bool DItemDrag::canDecode(const QMimeData* e)
@@ -87,16 +81,14 @@ bool DItemDrag::canDecode(const QMimeData* e)
 
 bool DItemDrag::decode(const QMimeData* e,
                        QList<QUrl>& urls,
-                       QList<QUrl>& kioUrls,
                        QList<int>& albumIDs,
                        QList<qlonglong>& imageIDs)
 {
     urls.clear();
-    kioUrls.clear();
     albumIDs.clear();
     imageIDs.clear();
 
-    QByteArray ba = e->data(QLatin1String("digikam/item-ids"));
+    QByteArray ba = e->data(QLatin1String("digikam/item-urls"));
 
     if (ba.size())
     {
@@ -111,10 +103,9 @@ bool DItemDrag::decode(const QMimeData* e,
     if (!urls.isEmpty())
     {
         QByteArray albumarray = e->data(QLatin1String("digikam/album-ids"));
-        QByteArray imagearray = e->data(QLatin1String("digikam/image-ids-long"));
-        QByteArray kioarray   = e->data(QLatin1String("digikam/digikamalbums"));
+        QByteArray imagearray = e->data(QLatin1String("digikam/item-ids"));
 
-        if (albumarray.size() && imagearray.size() && kioarray.size())
+        if (albumarray.size() && imagearray.size())
         {
             QDataStream dsAlbums(albumarray);
 
@@ -130,14 +121,6 @@ bool DItemDrag::decode(const QMimeData* e,
                 dsImages >> imageIDs;
             }
 
-            QUrl u;
-            QDataStream dsKio(kioarray);
-
-            if (!dsKio.atEnd())
-            {
-                dsKio >> kioUrls;
-            }
-
             return true;
         }
     }
@@ -175,7 +158,7 @@ QStringList DAlbumDrag::mimeTypes()
 
 bool DAlbumDrag::canDecode(const QMimeData* e)
 {
-    if (e->hasFormat(QLatin1String("digikam/item-ids")) || e->hasFormat(QLatin1String("digikam/image-ids-long")))
+    if (e->hasFormat(QLatin1String("digikam/item-urls")) || e->hasFormat(QLatin1String("digikam/item-ids")))
     {
         return false;
     }
diff --git a/app/dragdrop/ddragobjects.h b/app/dragdrop/ddragobjects.h
index 2b2087e4ea..4ebb9f0f34 100644
--- a/app/dragdrop/ddragobjects.h
+++ b/app/dragdrop/ddragobjects.h
@@ -41,21 +41,18 @@ namespace Digikam
 {
 
 /**
- * Provides a drag object for a list of KURLs with its related database IDs.
+ * Provides a drag object with additional information for internal drag&drop
  *
  * Images can be moved through ItemDrag. It is possible to move them on
- * another application which understands KURLDrag, like konqueror, to
- * copy the images. digiKam can use the IDs, if ItemDrag is dropped
- * on digikam itself.
- * The kioURLs are internally used with the digikamalbums kioslave.
- * The "normal" KURLDrag urls are used for external drops (k3b, gimp, ...)
+ * another application which is supported through QT to e.g. copy the images.
+ * digiKam can use the IDs, if ItemDrag is dropped on digikam itself.
+ * The urls set via setUrls() are used for external drops (k3b, gimp, ...)
  */
 class DItemDrag : public QMimeData
 {
 public:
 
     DItemDrag(const QList<QUrl>& urls,
-              const QList<QUrl>& kioURLs,
               const QList<int>& albumIDs,
               const QList<qlonglong>& imageIDs);
 
@@ -63,7 +60,6 @@ public:
     static QStringList mimeTypes();
     static bool decode(const QMimeData* e,
                        QList<QUrl>& urls,
-                       QList<QUrl>& kioURLs,
                        QList<int>& albumIDs,
                        QList<qlonglong>& imageIDs);
 };
diff --git a/app/dragdrop/imagedragdrop.cpp b/app/dragdrop/imagedragdrop.cpp
index 7a212cbad5..4d529d4c03 100644
--- a/app/dragdrop/imagedragdrop.cpp
+++ b/app/dragdrop/imagedragdrop.cpp
@@ -281,16 +281,15 @@ bool ImageDragDropHandler::dropEvent(QAbstractItemView* abstractview, const QDro
     {
         // Drag & drop inside of digiKam
         QList<QUrl>      urls;
-        QList<QUrl>      kioURLs;
         QList<int>       albumIDs;
         QList<qlonglong> imageIDs;
 
-        if (!DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+        if (!DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
         {
             return false;
         }
 
-        if (urls.isEmpty() || kioURLs.isEmpty() || albumIDs.isEmpty() || imageIDs.isEmpty())
+        if (urls.isEmpty() || albumIDs.isEmpty() || imageIDs.isEmpty())
         {
             return false;
         }
@@ -632,14 +631,12 @@ QMimeData* ImageDragDropHandler::createMimeData(const QList<QModelIndex>& indexe
     QList<ImageInfo> infos = model()->imageInfos(indexes);
 
     QList<QUrl>      urls;
-    QList<QUrl>      kioURLs;
     QList<int>       albumIDs;
     QList<qlonglong> imageIDs;
 
     foreach(const ImageInfo& info, infos)
     {
         urls.append(info.fileUrl());
-        kioURLs.append(info.databaseUrl());
         albumIDs.append(info.albumId());
         imageIDs.append(info.id());
     }
@@ -649,7 +646,7 @@ QMimeData* ImageDragDropHandler::createMimeData(const QList<QModelIndex>& indexe
         return 0;
     }
 
-    return new DItemDrag(urls, kioURLs, albumIDs, imageIDs);
+    return new DItemDrag(urls, albumIDs, imageIDs);
 }
 
 } // namespace Digikam
diff --git a/app/dragdrop/tagdragdrop.cpp b/app/dragdrop/tagdragdrop.cpp
index 1dd8f314ed..cdd487a52d 100644
--- a/app/dragdrop/tagdragdrop.cpp
+++ b/app/dragdrop/tagdragdrop.cpp
@@ -150,16 +150,15 @@ bool TagDragDropHandler::dropEvent(QAbstractItemView* view, const QDropEvent* e,
     else if (DItemDrag::canDecode(e->mimeData()))
     {
         QList<QUrl>      urls;
-        QList<QUrl>      kioURLs;
         QList<int>       albumIDs;
         QList<qlonglong> imageIDs;
 
-        if (!DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+        if (!DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
         {
             return false;
         }
 
-        if (urls.isEmpty() || kioURLs.isEmpty() || albumIDs.isEmpty() || imageIDs.isEmpty())
+        if (urls.isEmpty() || albumIDs.isEmpty() || imageIDs.isEmpty())
         {
             return false;
         }
diff --git a/libs/database/item/imageinfo.cpp b/libs/database/item/imageinfo.cpp
index 53536fb590..343753ce5b 100644
--- a/libs/database/item/imageinfo.cpp
+++ b/libs/database/item/imageinfo.cpp
@@ -762,20 +762,6 @@ int ImageInfo::orientation() const
     return values.first().toInt();
 }
 
-CoreDbUrl ImageInfo::databaseUrl() const
-{
-    if (!m_data)
-    {
-        return CoreDbUrl();
-    }
-
-    QString album     = ImageInfoStatic::cache()->albumRelativePath(m_data->albumId);
-    QString albumRoot = CollectionManager::instance()->albumRootPath(m_data->albumRootId);
-
-    ImageInfoReadLocker lock;
-    return CoreDbUrl::fromAlbumAndName(m_data->name, album, QUrl::fromLocalFile(albumRoot), m_data->albumRootId);
-}
-
 QUrl ImageInfo::fileUrl() const
 {
     return QUrl::fromLocalFile(filePath());
@@ -1843,8 +1829,8 @@ ThumbnailIdentifier ImageInfo::thumbnailIdentifier(qlonglong id)
 
 QDebug operator<<(QDebug stream, const ImageInfo& info)
 {
-    return stream << "ImageInfo [id = " << info.id() << ", databaseurl = "
-                  << info.databaseUrl() << "]";
+    return stream << "ImageInfo [id = " << info.id() << ", path = "
+                  << info.filePath() << "]";
 }
 
 ImageInfo::DatabaseFieldsHashRaw ImageInfo::getDatabaseFieldsRaw(const DatabaseFields::Set& requestedSet) const
diff --git a/libs/database/item/imageinfo.h b/libs/database/item/imageinfo.h
index 91b650f1eb..ec06b37efe 100644
--- a/libs/database/item/imageinfo.h
+++ b/libs/database/item/imageinfo.h
@@ -151,23 +151,15 @@ public:
      */
     QSize dimensions() const;
 
-    /**
-     * Returns the digikamalbums:// URL.
-     * The returned object can be used as a QUrl.
-     * Always use this for KIO operations
-     */
-    CoreDbUrl databaseUrl() const;
-
     /**
      * Returns the file:// url.
-     * This is equivalent to databaseUrl().fileUrl()
+     * This is equivalent to QUrl::fromLocalFile(filePath())
      */
     QUrl fileUrl() const;
 
     /**
-     * Equivalent to fileUrl().path()
+     * Returns the file path to the image
      */
-    // Deprecate?
     QString filePath() const;
 
     /**
diff --git a/utilities/fuzzysearch/fuzzysearchview.cpp b/utilities/fuzzysearch/fuzzysearchview.cpp
index 6c1ae620a7..9aaa38f870 100644
--- a/utilities/fuzzysearch/fuzzysearchview.cpp
+++ b/utilities/fuzzysearch/fuzzysearchview.cpp
@@ -969,11 +969,10 @@ void FuzzySearchView::dropEvent(QDropEvent* e)
     if (DItemDrag::canDecode(e->mimeData()))
     {
         QList<QUrl>      urls;
-        QList<QUrl>      ioURLs;
         QList<int>       albumIDs;
         QList<qlonglong> imageIDs;
 
-        if (!DItemDrag::decode(e->mimeData(), urls, ioURLs, albumIDs, imageIDs))
+        if (!DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
         {
             return;
         }
diff --git a/utilities/imageeditor/main/imagewindow.cpp b/utilities/imageeditor/main/imagewindow.cpp
index df3b07be63..a6d2ef6974 100644
--- a/utilities/imageeditor/main/imagewindow.cpp
+++ b/utilities/imageeditor/main/imagewindow.cpp
@@ -1475,9 +1475,8 @@ void ImageWindow::dragMoveEvent(QDragMoveEvent* e)
     QList<int>       albumIDs;
     QList<qlonglong> imageIDs;
     QList<QUrl>      urls;
-    QList<QUrl>      kioURLs;
 
-    if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs) ||
+    if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs) ||
         DAlbumDrag::decode(e->mimeData(), urls, albumID)                    ||
         DTagListDrag::canDecode(e->mimeData()))
     {
@@ -1494,9 +1493,8 @@ void ImageWindow::dropEvent(QDropEvent* e)
     QList<int>       albumIDs;
     QList<qlonglong> imageIDs;
     QList<QUrl>      urls;
-    QList<QUrl>      kioURLs;
 
-    if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+    if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
     {
         ImageInfoList imageInfoList(imageIDs);
 
@@ -1674,10 +1672,10 @@ void ImageWindow::slotAddedDropedItems(QDropEvent* e)
     int              albumID;
     QList<int>       albumIDs;
     QList<qlonglong> imageIDs;
-    QList<QUrl>      urls, kioURLs;
+    QList<QUrl>      urls;
     ImageInfoList    imgList;
 
-    if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+    if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
     {
         imgList = ImageInfoList(imageIDs);
     }
diff --git a/utilities/lighttable/lighttablepreview.cpp b/utilities/lighttable/lighttablepreview.cpp
index cc9b9dc98b..28d694ef0d 100644
--- a/utilities/lighttable/lighttablepreview.cpp
+++ b/utilities/lighttable/lighttablepreview.cpp
@@ -106,9 +106,9 @@ bool LightTablePreview::dragEventWrapper(const QMimeData* data) const
         int              albumID;
         QList<int>       albumIDs;
         QList<qlonglong> imageIDs;
-        QList<QUrl>      urls, kioURLs;
+        QList<QUrl>      urls;
 
-        if (DItemDrag::decode(data, urls, kioURLs, albumIDs, imageIDs) ||
+        if (DItemDrag::decode(data, urls, albumIDs, imageIDs) ||
             DAlbumDrag::decode(data, urls, albumID)                    ||
             DTagListDrag::canDecode(data))
         {
@@ -126,9 +126,9 @@ void LightTablePreview::dropEvent(QDropEvent* e)
         int              albumID;
         QList<int>       albumIDs;
         QList<qlonglong> imageIDs;
-        QList<QUrl>      urls, kioURLs;
+        QList<QUrl>      urls;
 
-        if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+        if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
         {
             emit signalDroppedItems(ImageInfoList(imageIDs));
             e->accept();
diff --git a/utilities/queuemanager/views/queuelist.cpp b/utilities/queuemanager/views/queuelist.cpp
index de9848658f..0022bc8fde 100644
--- a/utilities/queuemanager/views/queuelist.cpp
+++ b/utilities/queuemanager/views/queuelist.cpp
@@ -363,7 +363,6 @@ Qt::DropActions QueueListView::supportedDropActions() const
 QMimeData* QueueListView::mimeData(const QList<QTreeWidgetItem*> items) const
 {
     QList<QUrl> urls;
-    QList<QUrl> kioURLs;
     QList<int> albumIDs;
     QList<qlonglong> imageIDs;
 
@@ -374,13 +373,12 @@ QMimeData* QueueListView::mimeData(const QList<QTreeWidgetItem*> items) const
         if (vitem)
         {
             urls.append(vitem->info().fileUrl());
-            kioURLs.append(vitem->info().databaseUrl());
             albumIDs.append(vitem->info().albumId());
             imageIDs.append(vitem->info().id());
         }
     }
 
-    DItemDrag* const mimeData = new DItemDrag(urls, kioURLs, albumIDs, imageIDs);
+    DItemDrag* const mimeData = new DItemDrag(urls, albumIDs, imageIDs);
     return mimeData;
 }
 
@@ -434,13 +432,12 @@ void QueueListView::dragMoveEvent(QDragMoveEvent* e)
     QList<int>       albumIDs;
     QList<qlonglong> imageIDs;
     QList<QUrl>      urls;
-    QList<QUrl>      kioURLs;
 
-    if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs) ||
+    if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs) ||
         DAlbumDrag::decode(e->mimeData(), urls, albumID)                    ||
         DTagListDrag::canDecode(e->mimeData()))
     {
-        if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+        if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
         {
             ImageInfoList imageInfoList;
 
@@ -479,9 +476,8 @@ void QueueListView::dropEvent(QDropEvent* e)
     QList<int>       albumIDs;
     QList<qlonglong> imageIDs;
     QList<QUrl>      urls;
-    QList<QUrl>      kioURLs;
 
-    if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs))
+    if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs))
     {
         ImageInfoList imageInfoList;
 
diff --git a/utilities/queuemanager/views/queuepool.cpp b/utilities/queuemanager/views/queuepool.cpp
index 2a323c722d..fd923642c6 100644
--- a/utilities/queuemanager/views/queuepool.cpp
+++ b/utilities/queuemanager/views/queuepool.cpp
@@ -429,9 +429,8 @@ void QueuePool::slotTestCanDecode(const QDragMoveEvent* e, bool& accept)
     QList<int>       albumIDs;
     QList<qlonglong> imageIDs;
     QList<QUrl>      urls;
-    QList<QUrl>      kioURLs;
 
-    if (DItemDrag::decode(e->mimeData(), urls, kioURLs, albumIDs, imageIDs) ||
+    if (DItemDrag::decode(e->mimeData(), urls, albumIDs, imageIDs) ||
         DAlbumDrag::decode(e->mimeData(), urls, albumID)                    ||
         DTagListDrag::canDecode(e->mimeData()))
     {
-- 
2.14.2

