X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f158bf097a079cba181afa9ecc03e5eb20f3573a..87e8d0ba:/src/panels/places/placesitemmodel.h diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h index cd4fd2f75..a1b23b220 100644 --- a/src/panels/places/placesitemmodel.h +++ b/src/panels/places/placesitemmodel.h @@ -20,29 +20,22 @@ #ifndef PLACESITEMMODEL_H #define PLACESITEMMODEL_H -#include - #include +#include -#include +#include #include #include #include +#include +#include +class KBookmark; class KBookmarkManager; +class PlacesItem; class QAction; -#ifdef HAVE_NEPOMUK - namespace Nepomuk - { - namespace Query - { - class Term; - } - } -#endif - -#define PLACESITEMMODEL_DEBUG +// #define PLACESITEMMODEL_DEBUG /** * @brief Model for maintaining the bookmarks of the places panel. @@ -55,22 +48,42 @@ class PlacesItemModel: public KStandardItemModel Q_OBJECT public: - explicit PlacesItemModel(QObject* parent = 0); - virtual ~PlacesItemModel(); + explicit PlacesItemModel(QObject* parent = nullptr); + ~PlacesItemModel() override; - void setHiddenItemsShown(bool show); - bool hiddenItemsShown() const; + /** + * @brief Create a new place entry in the bookmark file + * and add it to the model + */ + void createPlacesItem(const QString& text, + const QUrl& url, + const QString& iconName = QString(), + int after = -1); - int hiddenCount() const; + PlacesItem* placesItem(int index) const; + + /** + * @brief Mark an item as hiden + * @param index of the item to be hidden + */ + void hideItem(int index); - void setItemHidden(int index, bool hide); - bool isItemHidden(int index) const; + /** + * If set to true, all items that are marked as hidden + * will be shown in the view. The items will + * stay marked as hidden, which is visually indicated + * by the view by desaturating the icon and the text. + */ + void setHiddenItemsShown(bool show); + bool hiddenItemsShown() const; /** - * @return True if the item is a default item created by - * the system (e.g. the places for home, root, trash etc.) + * @return Number of items that are marked as hidden. + * Note that this does not mean that the items + * are really hidden + * (see PlacesItemModel::setHiddenItemsShown()). */ - bool isSystemItem(int index) const; + int hiddenCount() const; /** * Search the item which is equal to the URL or at least @@ -79,99 +92,144 @@ public: * range of the URL. -1 is returned if no closest item * could be found. */ - int closestItem(const KUrl& url) const; - - /** - * @return Name of the group where the item with the URL - * \a URL belongs to. - */ - QString groupName(const KUrl& url) const; + int closestItem(const QUrl& url) const; QAction* ejectAction(int index) const; - QAction* tearDownAction(int index) const; + QAction* teardownAction(int index) const; -protected: - virtual void onItemInserted(int index); - virtual void onItemRemoved(int index); + void requestEject(int index); + void requestTearDown(int index); -private: - void loadBookmarks(); + bool storageSetupNeeded(int index) const; + void requestStorageSetup(int index); + + QMimeData* createMimeData(const KItemSet& indexes) const override; + + bool supportsDropping(int index) const override; + + void dropMimeDataBefore(int index, const QMimeData* mimeData); /** - * Creates system bookmarks that are shown per default and can - * only be hidden but not removed. The result will be stored - * in m_systemBookmarks. + * @return Converts the URL, which contains "virtual" URLs for system-items like + * "search:/documents" into a Query-URL that will be handled by + * the corresponding IO-slave. Virtual URLs for bookmarks are used to + * be independent from internal format changes. */ - void createSystemBookmarks(); + static QUrl convertedUrl(const QUrl& url); + + void clear() override; + + void proceedWithTearDown(); /** - * @param index Item index related to the model. - * @return Corresponding item index related to m_hiddenItems. + * @brief Remove item from bookmark + * + * This function remove the index from bookmark file permanently + * + * @param index - the item to be removed */ - int hiddenIndex(int index) const; + void deleteItem(int index); + + /** + * Force a sync on the bookmarks and indicates to other applications that the + * state of the bookmarks has been changed. + */ + void refresh(); + + bool isDir(int index) const override; - static QString placesGroupName(); - static QString recentlyAccessedGroupName(); - static QString searchForGroupName(); - static KUrl translatedSystemBookmarkUrl(const KUrl& url); + KFilePlacesModel::GroupType groupType(int row) const; + bool isGroupHidden(KFilePlacesModel::GroupType type) const; + void setGroupHidden(KFilePlacesModel::GroupType type, bool hidden); + +signals: + void errorMessage(const QString& message); + void storageSetupDone(int index, bool success); + void storageTearDownRequested(const QString& mountPath); + void storageTearDownExternallyRequested(const QString& mountPath); + +protected: + void onItemInserted(int index) override; + void onItemRemoved(int index, KStandardItem* removedItem) override; + void onItemChanged(int index, const QSet& changedRoles) override; + +private slots: + void slotStorageTearDownDone(Solid::ErrorType error, const QVariant& errorData); + void slotStorageSetupDone(Solid::ErrorType error, const QVariant& errorData, const QString& udi); + + // source model control + void onSourceModelRowsInserted(const QModelIndex &parent, int first, int last); + void onSourceModelRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last); + void onSourceModelRowsAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row); + void onSourceModelRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row); + void onSourceModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); + void onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden); + +private: + /** + * Remove bookmarks created by the previous version of dolphin that are + * not valid anymore + */ + void cleanupBookmarks(); /** - * @return URL using the timeline-protocol for searching. + * Loads the bookmarks from the bookmark-manager and creates items for + * the model or moves hidden items to m_bookmarkedItems. */ - static KUrl createTimelineUrl(const KUrl& url); + void loadBookmarks(); + + QString internalMimeType() const; /** - * Helper method for createTimelineUrl(). - * @return String that represents a date-path in the format that - * the timeline-protocol expects. + * @return Adjusted drop index which assures that the item is aligned + * into the same group as specified by PlacesItem::groupType(). */ - static QString timelineDateString(int year, int month, int day = 0); + int groupedDropIndex(int index, const PlacesItem* item) const; /** - * @return URL that can be listed by KIO and results in searching - * for a given term. The URL \a url represents a places-internal - * URL like e.g. "search:/documents" + * @return True if the bookmarks have the same identifiers. The identifier + * is the unique "ID"-property in case if no UDI is set, otherwise + * the UDI is used as identifier. */ - static KUrl createSearchUrl(const KUrl& url); + static bool equalBookmarkIdentifiers(const KBookmark& b1, const KBookmark& b2); -#ifdef HAVE_NEPOMUK /** - * Helper method for createSearchUrl(). - * @return URL that can be listed by KIO and results in searching - * for the given term. + * Appends the item \a item as last element of the group + * the item belongs to. If no item with the same group is + * present, the item gets appended as last element of the + * model. PlacesItemModel takes the ownership + * of the item. */ - static KUrl searchUrlForTerm(const Nepomuk::Query::Term& term); -#endif + void insertSortedItem(PlacesItem* item); #ifdef PLACESITEMMODEL_DEBUG void showModelState(); #endif + PlacesItem *itemFromBookmark(const KBookmark &bookmark) const; + + void addItemFromSourceModel(const QModelIndex &index); + void removeItemByIndex(const QModelIndex &mapToSource); + + QString bookmarkId(const KBookmark &bookmark) const; + void initializeDefaultViewProperties() const; + + int mapFromSource(const QModelIndex &index) const; + QModelIndex mapToSource(int row) const; + + static void updateItem(PlacesItem *item, const QModelIndex &index); + private: - bool m_nepomukRunning; bool m_hiddenItemsShown; - QSet m_availableDevices; - KBookmarkManager* m_bookmarkManager; - - struct SystemBookmarkData - { - SystemBookmarkData(const KUrl& url, - const QString& icon, - const QString& text, - const QString& group) : - url(url), icon(icon), text(text), group(group) {} - KUrl url; - QString icon; - QString text; - QString group; - }; - - QList m_systemBookmarks; - QHash m_systemBookmarksIndexes; - - QList m_hiddenItems; + Solid::StorageAccess *m_deviceToTearDown; + + QHash m_storageSetupInProgress; + + QScopedPointer m_sourceModel; + + QVector m_indexMap; }; #endif