]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/places/placesitem.h
Merge remote-tracking branch 'origin/Applications/17.12'
[dolphin.git] / src / panels / places / placesitem.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 PLACESITEM_H
21 #define PLACESITEM_H
22
23 #include <KBookmark>
24 #include <kitemviews/kstandarditem.h>
25 #include <QUrl>
26 #include <QPointer>
27 #include <Solid/Device>
28 #include <Solid/OpticalDisc>
29 #include <Solid/StorageAccess>
30 #include <Solid/StorageVolume>
31 #include <Solid/PortableMediaPlayer>
32
33 class KDirLister;
34 class PlacesItemSignalHandler;
35
36 /**
37 * @brief Extends KStandardItem by places-specific properties.
38 */
39 class PlacesItem : public KStandardItem
40 {
41
42 public:
43 enum GroupType
44 {
45 PlacesType,
46 SearchForType,
47 RecentlySavedType,
48 DevicesType
49 };
50
51 explicit PlacesItem(const KBookmark& bookmark, PlacesItem* parent = nullptr);
52 ~PlacesItem() override;
53
54 void setUrl(const QUrl& url);
55 QUrl url() const;
56
57 void setUdi(const QString& udi);
58 QString udi() const;
59
60 void setHidden(bool hidden);
61 bool isHidden() const;
62
63 void setSystemItem(bool isSystemItem);
64 bool isSystemItem() const;
65
66 Solid::Device device() const;
67
68 void setBookmark(const KBookmark& bookmark);
69 KBookmark bookmark() const;
70
71 GroupType groupType() const;
72
73 bool storageSetupNeeded() const;
74
75 static KBookmark createBookmark(KBookmarkManager* manager,
76 const QString& text,
77 const QUrl& url,
78 const QString& iconName);
79 static KBookmark createDeviceBookmark(KBookmarkManager* manager,
80 const QString& udi);
81
82 PlacesItemSignalHandler* signalHandler() const;
83
84 protected:
85 void onDataValueChanged(const QByteArray& role,
86 const QVariant& current,
87 const QVariant& previous) override;
88
89 void onDataChanged(const QHash<QByteArray, QVariant>& current,
90 const QHash<QByteArray, QVariant>& previous) override;
91
92 private:
93 PlacesItem(const PlacesItem& item);
94
95 void initializeDevice(const QString& udi);
96
97 /**
98 * Is invoked if the accessibility of the storage access
99 * m_access has been changed and updates the emblem.
100 */
101 void onAccessibilityChanged();
102
103 /**
104 * Is invoked if the listing of the trash has been completed.
105 * Updates the state of the trash-icon to be empty or full.
106 */
107 void onTrashDirListerCompleted();
108
109 /**
110 * Applies the data-value from the role to m_bookmark.
111 */
112 void updateBookmarkForRole(const QByteArray& role);
113
114 static QString generateNewId();
115
116 private:
117 Solid::Device m_device;
118 QPointer<Solid::StorageAccess> m_access;
119 QPointer<Solid::StorageVolume> m_volume;
120 QPointer<Solid::OpticalDisc> m_disc;
121 QPointer<Solid::PortableMediaPlayer> m_mtp;
122 QPointer<PlacesItemSignalHandler> m_signalHandler;
123 QPointer<KDirLister> m_trashDirLister;
124 KBookmark m_bookmark;
125
126 friend class PlacesItemSignalHandler; // Calls onAccessibilityChanged()
127 };
128
129 #endif
130
131