| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2006-2007 Kevin Ottens <ervin@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 | */ |
| 6 | |
| 7 | #ifndef SOLID_STORAGEACCESS_H |
| 8 | #define SOLID_STORAGEACCESS_H |
| 9 | |
| 10 | #include <solid/solid_export.h> |
| 11 | |
| 12 | #include <QVariant> |
| 13 | #include <solid/deviceinterface.h> |
| 14 | #include <solid/solidnamespace.h> |
| 15 | |
| 16 | namespace Solid |
| 17 | { |
| 18 | class StorageAccessPrivate; |
| 19 | class Device; |
| 20 | |
| 21 | /*! |
| 22 | * \class Solid::StorageAccess |
| 23 | * \inheaderfile Solid/StorageAccess |
| 24 | * \inmodule Solid |
| 25 | * |
| 26 | * \brief This device interface is available on volume devices to access them |
| 27 | * (i.e. mount or unmount them). |
| 28 | * |
| 29 | * A volume is anything that can contain data (partition, optical disc, |
| 30 | * memory card). It's a particular kind of block device. |
| 31 | */ |
| 32 | class SOLID_EXPORT StorageAccess : public DeviceInterface |
| 33 | { |
| 34 | Q_OBJECT |
| 35 | |
| 36 | /*! |
| 37 | * \property Solid::StorageAccess::accessible |
| 38 | */ |
| 39 | Q_PROPERTY(bool accessible READ isAccessible) |
| 40 | |
| 41 | /*! |
| 42 | * \property Solid::StorageAccess::filePath |
| 43 | */ |
| 44 | Q_PROPERTY(QString filePath READ filePath) |
| 45 | |
| 46 | /*! |
| 47 | * \property Solid::StorageAccess::ignored |
| 48 | */ |
| 49 | Q_PROPERTY(bool ignored READ isIgnored) |
| 50 | |
| 51 | /*! |
| 52 | * \property Solid::StorageAccess::encrypted |
| 53 | */ |
| 54 | Q_PROPERTY(bool encrypted READ isEncrypted) |
| 55 | |
| 56 | Q_DECLARE_PRIVATE(StorageAccess) |
| 57 | friend class Device; |
| 58 | |
| 59 | private: |
| 60 | /*! |
| 61 | * \internal |
| 62 | * |
| 63 | * Creates a new StorageAccess object. |
| 64 | * |
| 65 | * You generally won't need this. It's created when necessary using |
| 66 | * Device::as(). |
| 67 | * |
| 68 | * \a backendObject the device interface object provided by the backend |
| 69 | * |
| 70 | * \sa Solid::Device::as() |
| 71 | */ |
| 72 | SOLID_NO_EXPORT explicit StorageAccess(QObject *backendObject); |
| 73 | |
| 74 | public: |
| 75 | ~StorageAccess() override; |
| 76 | |
| 77 | /*! |
| 78 | * Get the Solid::DeviceInterface::Type of the StorageAccess device interface. |
| 79 | * |
| 80 | * Returns the StorageVolume device interface type |
| 81 | * \sa Solid::Ifaces::Enums::DeviceInterface::Type |
| 82 | */ |
| 83 | static Type deviceInterfaceType() |
| 84 | { |
| 85 | return DeviceInterface::StorageAccess; |
| 86 | } |
| 87 | |
| 88 | /*! |
| 89 | * Indicates if this volume is mounted. |
| 90 | * |
| 91 | * Returns true if the volume is mounted |
| 92 | */ |
| 93 | bool isAccessible() const; |
| 94 | |
| 95 | /*! |
| 96 | * Retrieves the absolute path of this volume mountpoint. |
| 97 | * |
| 98 | * Returns the absolute path to the mount point if the volume is |
| 99 | * mounted, QString() otherwise |
| 100 | */ |
| 101 | QString filePath() const; |
| 102 | |
| 103 | /*! |
| 104 | * Indicates if this volume should be ignored by applications. |
| 105 | * |
| 106 | * If it should be ignored, it generally means that it should be |
| 107 | * invisible to the user. It's useful for firmware partitions or |
| 108 | * OS reinstall partitions on some systems. |
| 109 | * |
| 110 | * Returns true if the volume should be ignored |
| 111 | */ |
| 112 | bool isIgnored() const; |
| 113 | |
| 114 | /*! |
| 115 | * Checks if source of the storage is encrypted. |
| 116 | * |
| 117 | * Returns true if storage is encrypted one |
| 118 | * |
| 119 | * \since 5.80 |
| 120 | */ |
| 121 | bool isEncrypted() const; |
| 122 | |
| 123 | /*! |
| 124 | * Mounts the volume. |
| 125 | * |
| 126 | * Returns false if the operation is not supported, true if the |
| 127 | * operation is attempted |
| 128 | */ |
| 129 | bool setup(); |
| 130 | |
| 131 | /*! |
| 132 | * Unmounts the volume. |
| 133 | * |
| 134 | * Returns false if the operation is not supported, true if the |
| 135 | * operation is attempted |
| 136 | */ |
| 137 | bool teardown(); |
| 138 | |
| 139 | /*! |
| 140 | * Indicates if this volume can check for filesystem errors. |
| 141 | * |
| 142 | * Returns true if the volume is can be checked |
| 143 | */ |
| 144 | bool canCheck() const; |
| 145 | |
| 146 | /*! |
| 147 | * Checks the filesystem for consistency avoiding any modifications or repairs. |
| 148 | * |
| 149 | * Mounted or unsupported filesystems will result in an error. |
| 150 | * |
| 151 | * Returns Whether the filesystem is undamaged. |
| 152 | */ |
| 153 | bool check(); |
| 154 | |
| 155 | /*! |
| 156 | * Indicates if the filesystem of this volume supports repair |
| 157 | * attempts. It does not indicate if such an attempt will succeed. |
| 158 | * |
| 159 | * Returns true if the volume is can be repaired |
| 160 | */ |
| 161 | bool canRepair() const; |
| 162 | |
| 163 | /*! |
| 164 | * Tries to repair the filesystem. |
| 165 | * |
| 166 | * Mounted or unsupported filesystems will result in an error. |
| 167 | * |
| 168 | * Returns Whether the filesystem could be successfully repaired |
| 169 | */ |
| 170 | bool repair(); |
| 171 | |
| 172 | Q_SIGNALS: |
| 173 | /*! |
| 174 | * This signal is emitted when the accessiblity of this device |
| 175 | * has changed. |
| 176 | * |
| 177 | * \a accessible true if the volume is accessible, false otherwise |
| 178 | * |
| 179 | * \a udi the UDI of the volume |
| 180 | */ |
| 181 | void accessibilityChanged(bool accessible, const QString &udi); |
| 182 | |
| 183 | /*! |
| 184 | * This signal is emitted when the attempted setting up of this |
| 185 | * device is completed. The signal might be spontaneous i.e. |
| 186 | * it can be triggered by another process. |
| 187 | * |
| 188 | * \a error type of error that occurred, if any |
| 189 | * |
| 190 | * \a errorData more information about the error, if any |
| 191 | * |
| 192 | * \a udi the UDI of the volume |
| 193 | */ |
| 194 | void setupDone(Solid::ErrorType error, QVariant errorData, const QString &udi); |
| 195 | |
| 196 | /*! |
| 197 | * This signal is emitted when the attempted tearing down of this |
| 198 | * device is completed. The signal might be spontaneous i.e. |
| 199 | * it can be triggered by another process. |
| 200 | * |
| 201 | * \a error type of error that occurred, if any |
| 202 | * |
| 203 | * \a errorData more information about the error, if any |
| 204 | * |
| 205 | * \a udi the UDI of the volume |
| 206 | */ |
| 207 | void teardownDone(Solid::ErrorType error, QVariant errorData, const QString &udi); |
| 208 | |
| 209 | /*! |
| 210 | * This signal is emitted when a setup of this device is requested. |
| 211 | * The signal might be spontaneous i.e. it can be triggered by |
| 212 | * another process. |
| 213 | * |
| 214 | * \a udi the UDI of the volume |
| 215 | */ |
| 216 | void setupRequested(const QString &udi); |
| 217 | |
| 218 | /*! |
| 219 | * This signal is emitted when a teardown of this device is requested. |
| 220 | * The signal might be spontaneous i.e. it can be triggered by |
| 221 | * another process |
| 222 | * |
| 223 | * \a udi the UDI of the volume |
| 224 | */ |
| 225 | void teardownRequested(const QString &udi); |
| 226 | |
| 227 | /*! |
| 228 | * This signal is emitted when a check of this device is requested. |
| 229 | * The signal might be spontaneous i.e. it can be triggered by |
| 230 | * another process. |
| 231 | * |
| 232 | * \a udi the UDI of the volume |
| 233 | * |
| 234 | * \since 6.11 |
| 235 | */ |
| 236 | void checkRequested(const QString &udi); |
| 237 | |
| 238 | /*! |
| 239 | * This signal is emitted when the attempted check of this |
| 240 | * device is completed. The signal might be spontaneous i.e. |
| 241 | * it can be triggered by another process. |
| 242 | * |
| 243 | * \a error type of error that occurred, if any |
| 244 | * |
| 245 | * \a errorData more information about the error, if any |
| 246 | * |
| 247 | * \a udi the UDI of the volume |
| 248 | * |
| 249 | * \since 6.11 |
| 250 | */ |
| 251 | void checkDone(Solid::ErrorType error, QVariant errorData, const QString &udi); |
| 252 | |
| 253 | /*! |
| 254 | * This signal is emitted when a repair of this device is requested. |
| 255 | * The signal might be spontaneous i.e. it can be triggered by |
| 256 | * another process. |
| 257 | * |
| 258 | * \a udi the UDI of the volume |
| 259 | */ |
| 260 | void repairRequested(const QString &udi); |
| 261 | |
| 262 | /*! |
| 263 | * This signal is emitted when the attempted repaired of this |
| 264 | * device is completed. The signal might be spontaneous i.e. |
| 265 | * it can be triggered by another process. |
| 266 | * |
| 267 | * \a error type of error that occurred, if any |
| 268 | * |
| 269 | * \a errorData more information about the error, if any |
| 270 | * |
| 271 | * \a udi the UDI of the volume |
| 272 | */ |
| 273 | void repairDone(Solid::ErrorType error, QVariant errorData, const QString &udi); |
| 274 | |
| 275 | protected: |
| 276 | SOLID_NO_EXPORT StorageAccess(StorageAccessPrivate &dd, QObject *backendObject); |
| 277 | }; |
| 278 | } |
| 279 | |
| 280 | #endif |
| 281 | |