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 <KUrl>
26#include <QPointer>
27#include <Solid/Device>
28#include <Solid/OpticalDisc>
29#include <Solid/StorageAccess>
30#include <Solid/StorageVolume>
31#include <Solid/PortableMediaPlayer>
32
33class KDirLister;
34class PlacesItemSignalHandler;
35
36/**
37 * @brief Extends KStandardItem by places-specific properties.
38 */
39class PlacesItem : public KStandardItem
40{
41
42public:
43 enum GroupType
44 {
45 PlacesType,
46 SearchForType,
47 RecentlyAccessedType,
48 DevicesType
49 };
50
51 explicit PlacesItem(const KBookmark& bookmark, PlacesItem* parent = 0);
52 virtual ~PlacesItem();
53
54 void setUrl(const KUrl& url);
55 KUrl 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 KUrl& url,
78 const QString& iconName);
79 static KBookmark createDeviceBookmark(KBookmarkManager* manager,
80 const QString& udi);
81
82protected:
83 virtual void onDataValueChanged(const QByteArray& role,
84 const QVariant& current,
85 const QVariant& previous);
86
87 virtual void onDataChanged(const QHash<QByteArray, QVariant>& current,
88 const QHash<QByteArray, QVariant>& previous);
89
90private:
91 PlacesItem(const PlacesItem& item);
92
93 void initializeDevice(const QString& udi);
94
95 /**
96 * Is invoked if the accessibility of the storage access
97 * m_access has been changed and updates the emblem.
98 */
99 void onAccessibilityChanged();
100
101 /**
102 * Is invoked if the listing of the trash has been completed.
103 * Updates the state of the trash-icon to be empty or full.
104 */
105 void onTrashDirListerCompleted();
106
107 /**
108 * Applies the data-value from the role to m_bookmark.
109 */
110 void updateBookmarkForRole(const QByteArray& role);
111
112 static QString generateNewId();
113
114private:
115 Solid::Device m_device;
116 QPointer<Solid::StorageAccess> m_access;
117 QPointer<Solid::StorageVolume> m_volume;
118 QPointer<Solid::OpticalDisc> m_disc;
119 QPointer<Solid::PortableMediaPlayer> m_mtp;
120 QPointer<PlacesItemSignalHandler> m_signalHandler;
121 QPointer<KDirLister> m_trashDirLister;
122 KBookmark m_bookmark;
123
124 friend class PlacesItemSignalHandler; // Calls onAccessibilityChanged()
125};
126
127#endif
128
129
130