]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitemmodel.h
2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef PLACESITEMMODEL_H
8 #define PLACESITEMMODEL_H
10 #include "kitemviews/kstandarditemmodel.h"
12 #include <KFilePlacesModel>
13 #include <Solid/Predicate>
14 #include <Solid/StorageAccess>
26 * @brief Model for maintaining the bookmarks of the places panel.
28 * It is based on KFilePlacesModel from KIO.
30 class PlacesItemModel
: public KStandardItemModel
35 explicit PlacesItemModel(QObject
* parent
= nullptr);
36 ~PlacesItemModel() override
;
39 * @brief Create a new place entry in the bookmark file
40 * and add it to the model
42 void createPlacesItem(const QString
& text
, const QUrl
& url
, const QString
& iconName
= {}, const QString
& appName
= {});
43 void createPlacesItem(const QString
& text
, const QUrl
& url
, const QString
& iconName
, const QString
& appName
, int after
);
45 PlacesItem
* placesItem(int index
) const;
48 * @brief Mark an item as hidden
49 * @param index of the item to be hidden
51 void hideItem(int index
);
54 * If set to true, all items that are marked as hidden
55 * will be shown in the view. The items will
56 * stay marked as hidden, which is visually indicated
57 * by the view by desaturating the icon and the text.
59 void setHiddenItemsShown(bool show
);
60 bool hiddenItemsShown() const;
63 * @return Number of items that are marked as hidden.
64 * Note that this does not mean that the items
66 * (see PlacesItemModel::setHiddenItemsShown()).
68 int hiddenCount() const;
71 * Search the item which is equal to the URL or at least
72 * is a parent URL. If there are more than one possible
73 * candidates, return the item which covers the biggest
74 * range of the URL. -1 is returned if no closest item
77 int closestItem(const QUrl
& url
) const;
79 QAction
* ejectAction(int index
) const;
80 QAction
* teardownAction(int index
) const;
82 void requestEject(int index
);
83 void requestTearDown(int index
);
85 bool storageSetupNeeded(int index
) const;
86 void requestStorageSetup(int index
);
88 QMimeData
* createMimeData(const KItemSet
& indexes
) const override
;
90 bool supportsDropping(int index
) const override
;
92 void dropMimeDataBefore(int index
, const QMimeData
* mimeData
);
95 * @return Converts the URL, which contains "virtual" URLs for system-items like
96 * "search:/documents" into a Query-URL that will be handled by
97 * the corresponding IO-slave. Virtual URLs for bookmarks are used to
98 * be independent from internal format changes.
100 static QUrl
convertedUrl(const QUrl
& url
);
102 void clear() override
;
104 void proceedWithTearDown();
107 * @brief Remove item from bookmark
109 * This function remove the index from bookmark file permanently
111 * @param index - the item to be removed
113 void deleteItem(int index
);
116 * Force a sync on the bookmarks and indicates to other applications that the
117 * state of the bookmarks has been changed.
121 bool isDir(int index
) const override
;
124 KFilePlacesModel::GroupType
groupType(int row
) const;
125 bool isGroupHidden(KFilePlacesModel::GroupType type
) const;
126 void setGroupHidden(KFilePlacesModel::GroupType type
, bool hidden
);
129 void errorMessage(const QString
& message
);
130 void storageSetupDone(int index
, bool success
);
131 void storageTearDownRequested(const QString
& mountPath
);
132 void storageTearDownExternallyRequested(const QString
& mountPath
);
133 void storageTearDownSuccessful();
136 void onItemInserted(int index
) override
;
137 void onItemRemoved(int index
, KStandardItem
* removedItem
) override
;
138 void onItemChanged(int index
, const QSet
<QByteArray
>& changedRoles
) override
;
141 void slotStorageTearDownDone(Solid::ErrorType error
, const QVariant
& errorData
);
142 void slotStorageSetupDone(Solid::ErrorType error
, const QVariant
& errorData
, const QString
& udi
);
144 // source model control
145 void onSourceModelRowsInserted(const QModelIndex
&parent
, int first
, int last
);
146 void onSourceModelRowsAboutToBeRemoved(const QModelIndex
&parent
, int first
, int last
);
147 void onSourceModelRowsAboutToBeMoved(const QModelIndex
&parent
, int start
, int end
, const QModelIndex
&destination
, int row
);
148 void onSourceModelRowsMoved(const QModelIndex
&parent
, int start
, int end
, const QModelIndex
&destination
, int row
);
149 void onSourceModelDataChanged(const QModelIndex
&topLeft
, const QModelIndex
&bottomRight
, const QVector
<int> &roles
);
150 void onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group
, bool hidden
);
154 * Remove bookmarks created by the previous version of dolphin that are
157 void cleanupBookmarks();
160 * Loads the bookmarks from the bookmark-manager and creates items for
161 * the model or moves hidden items to m_bookmarkedItems.
163 void loadBookmarks();
165 QString
internalMimeType() const;
168 * @return Adjusted drop index which assures that the item is aligned
169 * into the same group as specified by PlacesItem::groupType().
171 int groupedDropIndex(int index
, const PlacesItem
* item
) const;
174 * @return True if the bookmarks have the same identifiers. The identifier
175 * is the unique "ID"-property in case if no UDI is set, otherwise
176 * the UDI is used as identifier.
178 static bool equalBookmarkIdentifiers(const KBookmark
& b1
, const KBookmark
& b2
);
181 * Appends the item \a item as last element of the group
182 * the item belongs to. If no item with the same group is
183 * present, the item gets appended as last element of the
184 * model. PlacesItemModel takes the ownership
187 void insertSortedItem(PlacesItem
* item
);
189 PlacesItem
*itemFromBookmark(const KBookmark
&bookmark
) const;
191 void addItemFromSourceModel(const QModelIndex
&index
);
192 void removeItemByIndex(const QModelIndex
&mapToSource
);
194 QString
bookmarkId(const KBookmark
&bookmark
) const;
195 void initializeDefaultViewProperties() const;
197 int mapFromSource(const QModelIndex
&index
) const;
198 QModelIndex
mapToSource(int row
) const;
200 static void updateItem(PlacesItem
*item
, const QModelIndex
&index
);
203 bool m_hiddenItemsShown
;
205 Solid::StorageAccess
*m_deviceToTearDown
;
207 QHash
<QObject
*, int> m_storageSetupInProgress
;
209 KFilePlacesModel
*m_sourceModel
;
211 QVector
<QPersistentModelIndex
> m_indexMap
;