]>
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
;
48 #define PLACESITEMMODEL_DEBUG
51 * @brief Model for maintaining the bookmarks of the places panel.
53 * It is compatible to the KFilePlacesModel from kdelibs but adds
54 * the ability to have groups for places.
56 class PlacesItemModel
: public KStandardItemModel
61 explicit PlacesItemModel(QObject
* parent
= 0);
62 virtual ~PlacesItemModel();
64 PlacesItem
* placesItem(int index
) const;
66 void setHiddenItemsShown(bool show
);
67 bool hiddenItemsShown() const;
69 int hiddenCount() const;
71 void setItemHidden(int index
, bool hide
);
72 bool isItemHidden(int index
) const;
75 * @return True if the item is a default item created by
76 * the system (e.g. the places for home, root, trash etc.)
78 bool isSystemItem(int index
) const;
81 * Search the item which is equal to the URL or at least
82 * is a parent URL. If there are more than one possible
83 * candidates, return the item which covers the biggest
84 * range of the URL. -1 is returned if no closest item
87 int closestItem(const KUrl
& url
) const;
90 * @return Name of the group where the item with the URL
93 QString
groupName(const KUrl
& url
) const;
95 QAction
* ejectAction(int index
) const;
96 QAction
* teardownAction(int index
) const;
98 void requestEject(int index
);
99 void requestTeardown(int index
);
102 void errorMessage(const QString
& message
);
105 virtual void onItemInserted(int index
);
106 virtual void onItemRemoved(int index
);
109 void slotDeviceAdded(const QString
& udi
);
110 void slotDeviceRemoved(const QString
& udi
);
111 void slotStorageTeardownDone(Solid::ErrorType error
, const QVariant
& errorData
);
114 void loadBookmarks();
117 * Helper method for loadBookmarks(): Adds the items
118 * to the model if the "isHidden"-property is false,
119 * otherwise the items get added to m_hiddenItems.
121 void addItems(const QList
<PlacesItem
*>& items
);
124 * Creates system bookmarks that are shown per default and can
125 * only be hidden but not removed. The result will be stored
126 * in m_systemBookmarks.
128 void createSystemBookmarks();
130 void initializeAvailableDevices();
133 * @param index Item index related to the model.
134 * @return Corresponding item index related to m_hiddenItems.
136 int hiddenIndex(int index
) const;
138 static QString
placesGroupName();
139 static QString
recentlyAccessedGroupName();
140 static QString
searchForGroupName();
142 static KUrl
translatedSystemBookmarkUrl(const KUrl
& url
);
145 * @return URL using the timeline-protocol for searching.
147 static KUrl
createTimelineUrl(const KUrl
& url
);
150 * Helper method for createTimelineUrl().
151 * @return String that represents a date-path in the format that
152 * the timeline-protocol expects.
154 static QString
timelineDateString(int year
, int month
, int day
= 0);
157 * @return URL that can be listed by KIO and results in searching
158 * for a given term. The URL \a url represents a places-internal
159 * URL like e.g. "search:/documents"
161 static KUrl
createSearchUrl(const KUrl
& url
);
165 * Helper method for createSearchUrl().
166 * @return URL that can be listed by KIO and results in searching
167 * for the given term.
169 static KUrl
searchUrlForTerm(const Nepomuk::Query::Term
& term
);
172 #ifdef PLACESITEMMODEL_DEBUG
173 void showModelState();
177 bool m_nepomukRunning
;
178 bool m_hiddenItemsShown
;
180 QSet
<QString
> m_availableDevices
;
181 Solid::Predicate m_predicate
;
182 KBookmarkManager
* m_bookmarkManager
;
184 struct SystemBookmarkData
186 SystemBookmarkData(const KUrl
& url
,
189 const QString
& group
) :
190 url(url
), icon(icon
), text(text
), group(group
) {}
197 QList
<SystemBookmarkData
> m_systemBookmarks
;
198 QHash
<KUrl
, int> m_systemBookmarksIndexes
;
200 QList
<PlacesItem
*> m_hiddenItems
;