]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitemmodel.h
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef PLACESITEMMODEL_H
21 #define PLACESITEMMODEL_H
23 #include <config-nepomuk.h>
25 #include <kitemviews/kstandarditemmodel.h>
31 #include <Solid/Predicate>
32 #include <Solid/StorageAccess>
34 class KBookmarkManager
;
39 // #define PLACESITEMMODEL_DEBUG
42 * @brief Model for maintaining the bookmarks of the places panel.
44 * It is compatible to the KFilePlacesModel from kdelibs but adds
45 * the ability to have groups for places.
47 class PlacesItemModel
: public KStandardItemModel
52 explicit PlacesItemModel(QObject
* parent
= 0);
53 virtual ~PlacesItemModel();
55 PlacesItem
* createPlacesItem(const QString
& text
,
57 const QString
& iconName
);
59 PlacesItem
* placesItem(int index
) const;
61 void setHiddenItemsShown(bool show
);
62 bool hiddenItemsShown() const;
64 int hiddenCount() const;
67 * Search the item which is equal to the URL or at least
68 * is a parent URL. If there are more than one possible
69 * candidates, return the item which covers the biggest
70 * range of the URL. -1 is returned if no closest item
73 int closestItem(const KUrl
& url
) const;
76 * @return Name of the group where the item with the URL
79 QString
groupName(const KUrl
& url
) const;
81 QAction
* ejectAction(int index
) const;
82 QAction
* teardownAction(int index
) const;
84 void requestEject(int index
);
85 void requestTeardown(int index
);
88 void errorMessage(const QString
& message
);
91 virtual void onItemInserted(int index
);
92 virtual void onItemRemoved(int index
, KStandardItem
* removedItem
);
93 virtual void onItemChanged(int index
, const QSet
<QByteArray
>& changedRoles
);
96 void slotDeviceAdded(const QString
& udi
);
97 void slotDeviceRemoved(const QString
& udi
);
98 void slotStorageTeardownDone(Solid::ErrorType error
, const QVariant
& errorData
);
99 void removeHiddenItem();
100 void saveBookmarks();
103 void loadBookmarks();
106 * Helper method for loadBookmarks(): Adds the items
107 * to the model if the "isHidden"-property is false,
108 * otherwise the items get added to m_hiddenItems.
110 void addItems(const QList
<PlacesItem
*>& items
);
113 * Creates system bookmarks that are shown per default and can
114 * only be hidden but not removed. The result will be stored
115 * in m_systemBookmarks.
117 void createSystemBookmarks();
119 void initializeAvailableDevices();
122 * @param index Item index related to the model.
123 * @return Corresponding item index related to m_hiddenItems.
125 int hiddenIndex(int index
) const;
127 static QString
placesGroupName();
128 static QString
recentlyAccessedGroupName();
129 static QString
searchForGroupName();
131 #ifdef PLACESITEMMODEL_DEBUG
132 void showModelState();
136 bool m_nepomukRunning
;
137 bool m_hiddenItemsShown
;
139 QSet
<QString
> m_availableDevices
;
140 Solid::Predicate m_predicate
;
141 KBookmarkManager
* m_bookmarkManager
;
143 struct SystemBookmarkData
145 SystemBookmarkData(const KUrl
& url
,
148 const QString
& group
) :
149 url(url
), icon(icon
), text(text
), group(group
) {}
156 QList
<SystemBookmarkData
> m_systemBookmarks
;
157 QHash
<KUrl
, int> m_systemBookmarksIndexes
;
159 QList
<PlacesItem
*> m_hiddenItems
;
161 // Index of the hidden item that should be removed in
162 // removeHiddenItem(). The removing must be done
163 // asynchronously as in the scope of onItemChanged()
164 // removing an item is not allowed.
165 int m_hiddenItemToRemove
;
167 QTimer
* m_saveBookmarksTimer
;