]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placesitemmodel.cpp
Fix search in places panel.
[dolphin.git] / src / panels / places / placesitemmodel.cpp
index cfe6d2e462dfdeb2d0ea97a4744d718df2737f3b..0d8ac6981def9a3a68d1d7fa6fde98cd885b160b 100644 (file)
 #include "dolphin_generalsettings.h"
 
 #include <KBookmark>
-#include <KBookmarkGroup>
 #include <KBookmarkManager>
-#include <KDebug>
+#include "dolphindebug.h"
 #include <QIcon>
-#include <kprotocolinfo.h>
+#include <KProtocolInfo>
 #include <KLocalizedString>
-#include <KComponentData>
 #include <QStandardPaths>
 #include <KUser>
-#include <KGlobal>
+#include <KAboutData>
 #include "placesitem.h"
 #include <QAction>
 #include <QDate>
@@ -80,7 +78,6 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
     m_systemBookmarksIndexes(),
     m_bookmarkedItems(),
     m_hiddenItemToRemove(-1),
-    m_saveBookmarksTimer(0),
     m_updateBookmarksTimer(0),
     m_storageSetupInProgress()
 {
@@ -88,8 +85,8 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
     Baloo::IndexerConfig config;
     m_fileIndexingEnabled = config.fileIndexingEnabled();
 #endif
-    const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kfileplaces/bookmarks.xml");
-    m_bookmarkManager = KBookmarkManager::managerForFile(file, "kfilePlaces");
+    const QString file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/user-places.xbel";
+    m_bookmarkManager = KBookmarkManager::managerForExternalFile(file);
 
     createSystemBookmarks();
     initializeAvailableDevices();
@@ -97,11 +94,6 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
 
     const int syncBookmarksTimeout = 100;
 
-    m_saveBookmarksTimer = new QTimer(this);
-    m_saveBookmarksTimer->setInterval(syncBookmarksTimeout);
-    m_saveBookmarksTimer->setSingleShot(true);
-    connect(m_saveBookmarksTimer, &QTimer::timeout, this, &PlacesItemModel::saveBookmarks);
-
     m_updateBookmarksTimer = new QTimer(this);
     m_updateBookmarksTimer->setInterval(syncBookmarksTimeout);
     m_updateBookmarksTimer->setSingleShot(true);
@@ -109,13 +101,10 @@ PlacesItemModel::PlacesItemModel(QObject* parent) :
 
     connect(m_bookmarkManager, &KBookmarkManager::changed,
             m_updateBookmarksTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
-    connect(m_bookmarkManager, &KBookmarkManager::bookmarksChanged,
-            m_updateBookmarksTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
 }
 
 PlacesItemModel::~PlacesItemModel()
 {
-    saveBookmarks();
     qDeleteAll(m_bookmarkedItems);
     m_bookmarkedItems.clear();
 }
@@ -197,7 +186,7 @@ void PlacesItemModel::setHiddenItemsShown(bool show)
     }
 
 #ifdef PLACESITEMMODEL_DEBUG
-        kDebug() << "Changed visibility of hidden items";
+        qCDebug(DolphinDebug) << "Changed visibility of hidden items";
         showModelState();
 #endif
 }
@@ -501,10 +490,8 @@ void PlacesItemModel::onItemInserted(int index)
         m_bookmarkedItems.insert(bookmarkIndex, 0);
     }
 
-    triggerBookmarksSaving();
-
 #ifdef PLACESITEMMODEL_DEBUG
-    kDebug() << "Inserted item" << index;
+    qCDebug(DolphinDebug) << "Inserted item" << index;
     showModelState();
 #endif
 }
@@ -521,10 +508,8 @@ void PlacesItemModel::onItemRemoved(int index, KStandardItem* removedItem)
     Q_ASSERT(!m_bookmarkedItems[boomarkIndex]);
     m_bookmarkedItems.removeAt(boomarkIndex);
 
-    triggerBookmarksSaving();
-
 #ifdef PLACESITEMMODEL_DEBUG
-    kDebug() << "Removed item" << index;
+    qCDebug(DolphinDebug) << "Removed item" << index;
     showModelState();
 #endif
 }
@@ -552,8 +537,6 @@ void PlacesItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRo
             QTimer::singleShot(0, this, SLOT(hideItem()));
         }
     }
-
-    triggerBookmarksSaving();
 }
 
 void PlacesItemModel::slotDeviceAdded(const QString& udi)
@@ -819,7 +802,7 @@ void PlacesItemModel::loadBookmarks()
     }
 
 #ifdef PLACESITEMMODEL_DEBUG
-    kDebug() << "Loaded bookmarks";
+    qCDebug(DolphinDebug) << "Loaded bookmarks";
     showModelState();
 #endif
 }
@@ -833,8 +816,8 @@ bool PlacesItemModel::acceptBookmark(const KBookmark& bookmark,
     const bool deviceAvailable = availableDevices.contains(udi);
 
     const bool allowedHere = (appName.isEmpty()
-                              || appName == KGlobal::mainComponent().componentName()
-                              || appName == KGlobal::mainComponent().componentName() + AppNamePrefix)
+                              || appName == KAboutData::applicationData().componentName()
+                              || appName == KAboutData::applicationData().componentName() + AppNamePrefix)
                              && (m_fileIndexingEnabled || (url.scheme() != QLatin1String("timeline") &&
                                                            url.scheme() != QLatin1String("search")));
 
@@ -853,7 +836,7 @@ PlacesItem* PlacesItemModel::createSystemPlacesItem(const SystemBookmarkData& da
         // As long as the KFilePlacesView from kdelibs is available, the system-bookmarks
         // for "Recently Saved" and "Search For" should be a setting available only
         // in the Places Panel (see description of AppNamePrefix for more details).
-        const QString appName = KGlobal::mainComponent().componentName() + AppNamePrefix;
+        const QString appName = KAboutData::applicationData().componentName() + AppNamePrefix;
         bookmark.setMetaDataItem("OnlyInApp", appName);
     }
 
@@ -932,16 +915,16 @@ void PlacesItemModel::createSystemBookmarks()
                                                     "view-calendar-month",
                                                     I18N_NOOP2("KFile System Bookmarks", "Last Month")));
         m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/documents"),
-                                                    "folder-txt",
+                                                    "folder-text",
                                                     I18N_NOOP2("KFile System Bookmarks", "Documents")));
         m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/images"),
-                                                    "folder-image",
+                                                    "folder-images",
                                                     I18N_NOOP2("KFile System Bookmarks", "Images")));
         m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/audio"),
                                                     "folder-sound",
                                                     I18N_NOOP2("KFile System Bookmarks", "Audio Files")));
         m_systemBookmarks.append(SystemBookmarkData(QUrl("search:/videos"),
-                                                    "folder-video",
+                                                    "folder-videos",
                                                     I18N_NOOP2("KFile System Bookmarks", "Videos")));
     }
 
@@ -1035,20 +1018,12 @@ void PlacesItemModel::hideItem(int index)
             // bookmark should still be remembered, so readd it again:
             m_bookmarkManager->root().addBookmark(hiddenBookmark);
             m_bookmarkManager->root().moveBookmark(hiddenBookmark, previousBookmark);
-            triggerBookmarksSaving();
         }
 
         m_bookmarkedItems.insert(newIndex, hiddenItem);
     }
 }
 
-void PlacesItemModel::triggerBookmarksSaving()
-{
-    if (m_saveBookmarksTimer) {
-        m_saveBookmarksTimer->start();
-    }
-}
-
 QString PlacesItemModel::internalMimeType() const
 {
     return "application/x-dolphinplacesmodel-" +
@@ -1186,7 +1161,6 @@ QUrl PlacesItemModel::createSearchUrl(const QUrl& url)
 QUrl PlacesItemModel::searchUrlForType(const QString& type)
 {
     Baloo::Query query;
-    query.addType("File");
     query.addType(type);
 
     return query.toSearchUrl();
@@ -1196,25 +1170,25 @@ QUrl PlacesItemModel::searchUrlForType(const QString& type)
 #ifdef PLACESITEMMODEL_DEBUG
 void PlacesItemModel::showModelState()
 {
-    kDebug() << "=================================";
-    kDebug() << "Model:";
-    kDebug() << "hidden-index model-index   text";
+    qCDebug(DolphinDebug) << "=================================";
+    qCDebug(DolphinDebug) << "Model:";
+    qCDebug(DolphinDebug) << "hidden-index model-index   text";
     int modelIndex = 0;
     for (int i = 0; i < m_bookmarkedItems.count(); ++i) {
         if (m_bookmarkedItems[i]) {
-            kDebug() <<  i << "(Hidden)    " << "             " << m_bookmarkedItems[i]->dataValue("text").toString();
+            qCDebug(DolphinDebug) <<  i << "(Hidden)    " << "             " << m_bookmarkedItems[i]->dataValue("text").toString();
         } else {
             if (item(modelIndex)) {
-                kDebug() <<  i << "          " << modelIndex << "           " << item(modelIndex)->dataValue("text").toString();
+                qCDebug(DolphinDebug) <<  i << "          " << modelIndex << "           " << item(modelIndex)->dataValue("text").toString();
             } else {
-                kDebug() <<  i << "          " << modelIndex << "           " << "(not available yet)";
+                qCDebug(DolphinDebug) <<  i << "          " << modelIndex << "           " << "(not available yet)";
             }
             ++modelIndex;
         }
     }
 
-    kDebug();
-    kDebug() << "Bookmarks:";
+    qCDebug(DolphinDebug);
+    qCDebug(DolphinDebug) << "Bookmarks:";
 
     int bookmarkIndex = 0;
     KBookmarkGroup root = m_bookmarkManager->root();
@@ -1223,9 +1197,9 @@ void PlacesItemModel::showModelState()
         const QString udi = bookmark.metaDataItem("UDI");
         const QString text = udi.isEmpty() ? bookmark.text() : udi;
         if (bookmark.metaDataItem("IsHidden") == QLatin1String("true")) {
-            kDebug() << bookmarkIndex << "(Hidden)" << text;
+            qCDebug(DolphinDebug) << bookmarkIndex << "(Hidden)" << text;
         } else {
-            kDebug() << bookmarkIndex << "        " << text;
+            qCDebug(DolphinDebug) << bookmarkIndex << "        " << text;
         }
 
         bookmark = root.next(bookmark);