]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placesitemmodel.cpp
Remove unused #include
[dolphin.git] / src / panels / places / placesitemmodel.cpp
index ad01ea87e736d3ed0ddcf20bb881e323d84b50d2..207a982713be7a3bad71e0cdf49f89bdb022f2ff 100644 (file)
  ***************************************************************************/
 
 #include "placesitemmodel.h"
-#include "placesitemsignalhandler.h"
 
 #include "dolphin_generalsettings.h"
-
-#include <KBookmark>
-#include <KBookmarkManager>
 #include "dolphindebug.h"
-#include <QIcon>
-#include <KProtocolInfo>
-#include <KLocalizedString>
-#include <QStandardPaths>
-#include <KAboutData>
 #include "placesitem.h"
-#include <QAction>
-#include <QDate>
-#include <QMimeData>
-#include <QTimer>
-#include <KUrlMimeData>
-#include <KFilePlacesModel>
+#include "placesitemsignalhandler.h"
+#include "views/dolphinview.h"
+#include "views/viewproperties.h"
 
-#include <Solid/Device>
+#include <KAboutData>
+#include <KLocalizedString>
+#include <KUrlMimeData>
 #include <Solid/DeviceNotifier>
-#include <Solid/OpticalDisc>
 #include <Solid/OpticalDrive>
-#include <Solid/StorageAccess>
-#include <Solid/StorageDrive>
 
-#include <views/dolphinview.h>
-#include <views/viewproperties.h>
+#include <QAction>
+#include <QIcon>
+#include <QMimeData>
+#include <QTimer>
 
 namespace {
-    // Hence a prefix to the application-name of the stored bookmarks is
+    // A suffix to the application-name of the stored bookmarks is
     // added, which is only read by PlacesItemModel.
-    const char AppNamePrefix[] = "-places-panel";
-
+    const QString AppNameSuffix = QStringLiteral("-places-panel");
     static QList<QUrl> balooURLs = {
         QUrl(QStringLiteral("timeline:/today")),
         QUrl(QStringLiteral("timeline:/yesterday")),
@@ -74,8 +62,9 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
     m_hiddenItemsShown(false),
     m_deviceToTearDown(nullptr),
     m_storageSetupInProgress(),
-    m_sourceModel(new KFilePlacesModel(this))
+    m_sourceModel(new KFilePlacesModel(KAboutData::applicationData().componentName() + AppNameSuffix, this))
 {
+    cleanupBookmarks();
     loadBookmarks();
     initializeDefaultViewProperties();
 
@@ -164,12 +153,13 @@ void PlacesItemModel::insertSortedItem(PlacesItem* item)
 
     for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) {
         sourceIndex = m_sourceModel->index(r, 0);
+        const KBookmark sourceBookmark = m_sourceModel->bookmarkForIndex(sourceIndex);
 
-        if (bookmarkId(m_sourceModel->bookmarkForIndex(sourceIndex)) == iBookmarkId) {
+        if (bookmarkId(sourceBookmark) == iBookmarkId) {
             break;
         }
 
-        if (!m_sourceModel->isHidden(sourceIndex)) {
+        if (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex)) {
             pos++;
         }
     }
@@ -409,7 +399,10 @@ void PlacesItemModel::addItemFromSourceModel(const QModelIndex &index)
 
     const KBookmark bookmark = m_sourceModel->bookmarkForIndex(index);
     Q_ASSERT(!bookmark.isNull());
-    PlacesItem *item = new PlacesItem(bookmark);
+    PlacesItem *item = itemFromBookmark(bookmark);
+    if (!item) {
+        item = new PlacesItem(bookmark);
+    }
     updateItem(item, index);
     insertSortedItem(item);
 
@@ -570,11 +563,7 @@ void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex &parent, int star
         const int targetRow = row + (start - r) - (r < row ? blockSize : 0);
         const QModelIndex targetIndex = m_sourceModel->index(targetRow, 0, destination);
 
-        const KBookmark bookmark = m_sourceModel->bookmarkForIndex(targetIndex);
-        PlacesItem *item = new PlacesItem(bookmark);
-        updateItem(item, targetIndex);
-
-        insertSortedItem(item);
+        addItemFromSourceModel(targetIndex);
     }
 }
 
@@ -605,6 +594,8 @@ void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const
             placeItem->setUrl(m_sourceModel->url(sourceIndex));
             placeItem->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"),
                                                   bookmark.metaDataItem(QStringLiteral("OnlyInApp")));
+            // must update the bookmark object
+            placeItem->setBookmark(bookmark);
         }
     }
 }
@@ -619,13 +610,32 @@ void PlacesItemModel::onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupTyp
     }
 }
 
+void PlacesItemModel::cleanupBookmarks()
+{
+    // KIO model now provides support for baloo urls, and because of that we
+    // need to remove old URLs that were visible only in Dolphin to avoid duplication
+    int row = 0;
+    do {
+        const QModelIndex sourceIndex = m_sourceModel->index(row, 0);
+        const KBookmark bookmark = m_sourceModel->bookmarkForIndex(sourceIndex);
+        const QUrl url = bookmark.url();
+        const QString appName = bookmark.metaDataItem(QStringLiteral("OnlyInApp"));
+
+        if ((appName == KAboutData::applicationData().componentName() ||
+             appName == KAboutData::applicationData().componentName() + AppNameSuffix) && balooURLs.contains(url)) {
+            qCDebug(DolphinDebug) << "Removing old baloo url:" << url;
+            m_sourceModel->removePlace(sourceIndex);
+        } else {
+            row++;
+        }
+    } while (row < m_sourceModel->rowCount());
+}
+
 void PlacesItemModel::loadBookmarks()
 {
     for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) {
         const QModelIndex sourceIndex = m_sourceModel->index(r, 0);
-        KBookmark bookmark = m_sourceModel->bookmarkForIndex(sourceIndex);
-        if (acceptBookmark(bookmark) &&
-                (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex))) {
+        if (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex)) {
             addItemFromSourceModel(sourceIndex);
         }
     }
@@ -636,24 +646,6 @@ void PlacesItemModel::loadBookmarks()
 #endif
 }
 
-bool PlacesItemModel::acceptBookmark(const KBookmark& bookmark) const
-{
-    const QString udi = bookmark.metaDataItem(QStringLiteral("UDI"));
-    const QUrl url = bookmark.url();
-    const QString appName = bookmark.metaDataItem(QStringLiteral("OnlyInApp"));
-
-    if (balooURLs.contains(url) && appName.isEmpty()) {
-        // Does not accept baloo URLS with empty appName, this came from new KIO model and will cause duplications
-        qCWarning(DolphinDebug) << "Ignore KIO url:" << url;
-        return false;
-    }
-    const bool allowedHere = (appName.isEmpty()
-                              || appName == KAboutData::applicationData().componentName()
-                              || appName == KAboutData::applicationData().componentName() + AppNamePrefix);
-
-    return (udi.isEmpty() && allowedHere);
-}
-
 void PlacesItemModel::clear() {
     KStandardItemModel::clear();
 }