1/*
2 Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifndef SOLID_STORAGEACCESS_H
22#define SOLID_STORAGEACCESS_H
23
24#include <solid/solid_export.h>
25
26#include <solid/solidnamespace.h>
27#include <solid/deviceinterface.h>
28#include <QtCore/QVariant>
29
30namespace Solid
31{
32 class StorageAccessPrivate;
33 class Device;
34
35 /**
36 * This device interface is available on volume devices to access them
37 * (i.e. mount or unmount them).
38 *
39 * A volume is anything that can contain data (partition, optical disc,
40 * memory card). It's a particular kind of block device.
41 */
42 class SOLID_EXPORT StorageAccess : public DeviceInterface
43 {
44 Q_OBJECT
45 Q_PROPERTY(bool accessible READ isAccessible)
46 Q_PROPERTY(QString filePath READ filePath)
47 Q_PROPERTY(bool ignored READ isIgnored)
48 Q_DECLARE_PRIVATE(StorageAccess)
49 friend class Device;
50
51 private:
52 /**
53 * Creates a new StorageAccess object.
54 * You generally won't need this. It's created when necessary using
55 * Device::as().
56 *
57 * @param backendObject the device interface object provided by the backend
58 * @see Solid::Device::as()
59 */
60 explicit StorageAccess(QObject *backendObject);
61
62 public:
63 /**
64 * Destroys a StorageAccess object.
65 */
66 virtual ~StorageAccess();
67
68
69 /**
70 * Get the Solid::DeviceInterface::Type of the StorageAccess device interface.
71 *
72 * @return the StorageVolume device interface type
73 * @see Solid::Ifaces::Enums::DeviceInterface::Type
74 */
75 static Type deviceInterfaceType() { return DeviceInterface::StorageAccess; }
76
77
78 /**
79 * Indicates if this volume is mounted.
80 *
81 * @return true if the volume is mounted
82 */
83 bool isAccessible() const;
84
85 /**
86 * Retrieves the absolute path of this volume mountpoint.
87 *
88 * @return the absolute path to the mount point if the volume is
89 * mounted, QString() otherwise
90 */
91 QString filePath() const;
92
93 /**
94 * Indicates if this volume should be ignored by applications.
95 *
96 * If it should be ignored, it generally means that it should be
97 * invisible to the user. It's useful for firmware partitions or
98 * OS reinstall partitions on some systems.
99 *
100 * @return true if the volume should be ignored
101 */
102 bool isIgnored() const;
103
104 /**
105 * Mounts the volume.
106 *
107 * @return false if the operation is not supported, true if the
108 * operation is attempted
109 */
110 bool setup();
111
112 /**
113 * Unmounts the volume.
114 *
115 * @return false if the operation is not supported, true if the
116 * operation is attempted
117 */
118 bool teardown();
119
120 Q_SIGNALS:
121 /**
122 * This signal is emitted when the accessiblity of this device
123 * has changed.
124 *
125 * @param accessible true if the volume is accessible, false otherwise
126 * @param udi the UDI of the volume
127 */
128 void accessibilityChanged(bool accessible, const QString &udi);
129
130 /**
131 * This signal is emitted when the attempted setting up of this
132 * device is completed. The signal might be spontaneous i.e.
133 * it can be triggered by another process.
134 *
135 * @param error type of error that occurred, if any
136 * @param errorData more information about the error, if any
137 * @param udi the UDI of the volume
138 */
139 void setupDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
140
141 /**
142 * This signal is emitted when the attempted tearing down of this
143 * device is completed. The signal might be spontaneous i.e.
144 * it can be triggered by another process.
145 *
146 * @param error type of error that occurred, if any
147 * @param errorData more information about the error, if any
148 * @param udi the UDI of the volume
149 */
150 void teardownDone(Solid::ErrorType error, QVariant errorData, const QString &udi);
151
152 /**
153 * This signal is emitted when a setup of this device is requested.
154 * The signal might be spontaneous i.e. it can be triggered by
155 * another process.
156 *
157 * @param udi the UDI of the volume
158 */
159 void setupRequested(const QString &udi);
160
161 /**
162 * This signal is emitted when a teardown of this device is requested.
163 * The signal might be spontaneous i.e. it can be triggered by
164 * another process
165 *
166 * @param udi the UDI of the volume
167 */
168 void teardownRequested(const QString &udi);
169
170 protected:
171 /**
172 * @internal
173 */
174 StorageAccess(StorageAccessPrivate &dd, QObject *backendObject);
175 };
176}
177
178#endif
179