]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitemmodel.h
Places Panel: Minor fixes/improvements
[dolphin.git] / src / panels / places / placesitemmodel.h
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef PLACESITEMMODEL_H
21 #define PLACESITEMMODEL_H
22
23 #include <config-nepomuk.h>
24
25 #include <kitemviews/kstandarditemmodel.h>
26
27 #include <KUrl>
28 #include <QHash>
29 #include <QList>
30 #include <QSet>
31
32 class KBookmarkManager;
33 class QAction;
34
35 #ifdef HAVE_NEPOMUK
36 namespace Nepomuk
37 {
38 namespace Query
39 {
40 class Term;
41 }
42 }
43 #endif
44
45 class PlacesItemModel: public KStandardItemModel
46 {
47 Q_OBJECT
48
49 public:
50 explicit PlacesItemModel(QObject* parent = 0);
51 virtual ~PlacesItemModel();
52
53 void setHiddenItemsShown(bool show);
54 bool hiddenItemsShown() const;
55
56 int hiddenCount() const;
57
58 /**
59 * @return True if the item is a default item created by
60 * the system (e.g. the places for home, root, trash etc.)
61 */
62 bool isSystemItem(int index) const;
63
64 /**
65 * Search the item which is equal to the URL or at least
66 * is a parent URL. If there are more than one possible
67 * candidates, return the item which covers the biggest
68 * range of the URL. -1 is returned if no closest item
69 * could be found.
70 */
71 int closestItem(const KUrl& url) const;
72
73 /**
74 * @return Name of the group where the item with the URL
75 * \a URL belongs to.
76 */
77 QString groupName(const KUrl& url) const;
78
79 QAction* ejectAction(int index) const;
80 QAction* tearDownAction(int index) const;
81
82 private:
83 void loadBookmarks();
84
85 void createSystemBookmarks();
86
87 static QString placesGroupName();
88 static QString recentlyAccessedGroupName();
89 static QString searchForGroupName();
90
91 static KUrl translatedSystemBookmarkUrl(const KUrl& url);
92
93 /**
94 * @return URL using the timeline-protocol for searching.
95 */
96 static KUrl createTimelineUrl(const KUrl& url);
97
98 /**
99 * Helper method for createTimelineUrl().
100 * @return String that represents a date-path in the format that
101 * the timeline-protocol expects.
102 */
103 static QString timelineDateString(int year, int month, int day = 0);
104
105 /**
106 * @return URL that can be listed by KIO and results in searching
107 * for a given term. The URL \a url represents a places-internal
108 * URL like e.g. "search:/documents"
109 */
110 static KUrl createSearchUrl(const KUrl& url);
111
112 #ifdef HAVE_NEPOMUK
113 /**
114 * Helper method for createSearchUrl().
115 * @return URL that can be listed by KIO and results in searching
116 * for the given term.
117 */
118 static KUrl searchUrlForTerm(const Nepomuk::Query::Term& term);
119 #endif
120
121 private:
122 bool m_nepomukRunning;
123 bool m_hiddenItemsShown;
124
125 QSet<QString> m_availableDevices;
126 KBookmarkManager* m_bookmarkManager;
127
128 struct SystemBookmarkData
129 {
130 SystemBookmarkData(const KUrl& url,
131 const QString& icon,
132 const QString& text,
133 const QString& group) :
134 url(url), icon(icon), text(text), group(group) {}
135 KUrl url;
136 QString icon;
137 QString text;
138 QString group;
139 };
140
141 QList<SystemBookmarkData> m_systemBookmarks;
142 QHash<KUrl, int> m_systemBookmarksIndexes;
143 };
144
145 #endif
146
147