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_STORAGEDRIVE_H
8 #define SOLID_STORAGEDRIVE_H
9 
10 #include <solid/solid_export.h>
11 
12 #include <solid/deviceinterface.h>
13 
14 namespace Solid
15 {
16 class StorageDrivePrivate;
17 class Device;
18 
19 /**
20  * This device interface is available on storage devices.
21  *
22  * A storage is anything that can contain a set of volumes (card reader,
23  * hard disk, cdrom drive...). It's a particular kind of block device.
24  */
25 class SOLID_EXPORT StorageDrive : public DeviceInterface
26 {
27     Q_OBJECT
28     Q_PROPERTY(Bus bus READ bus)
29     Q_PROPERTY(DriveType driveType READ driveType)
30     Q_PROPERTY(bool removable READ isRemovable)
31     Q_PROPERTY(bool hotpluggable READ isHotpluggable)
32     Q_PROPERTY(bool inUse READ isInUse)
33     Q_PROPERTY(qulonglong size READ size)
34     Q_DECLARE_PRIVATE(StorageDrive)
35     friend class Device;
36 
37 public:
38     /**
39      * This enum type defines the type of bus a storage device is attached to.
40      *
41      * - Ide : An Integrated Drive Electronics (IDE) bus, also known as ATA
42      * - Usb : An Universal Serial Bus (USB)
43      * - Ieee1394 : An Ieee1394 bus, also known as Firewire
44      * - Scsi : A Small Computer System Interface bus
45      * - Sata : A Serial Advanced Technology Attachment (SATA) bus
46      * - Platform : A legacy bus that is part of the underlying platform
47      */
48     enum Bus { Ide, Usb, Ieee1394, Scsi, Sata, Platform };
49     Q_ENUM(Bus)
50 
51     /**
52      * This enum type defines the type of drive a storage device can be.
53      *
54      * - HardDisk : A hard disk
55      * - CdromDrive : An optical drive
56      * - Floppy : A floppy disk drive
57      * - Tape : A tape drive
58      * - CompactFlash : A Compact Flash card reader
59      * - MemoryStick : A Memory Stick card reader
60      * - SmartMedia : A Smart Media card reader
61      * - SdMmc : A SecureDigital/MultiMediaCard card reader
62      * - Xd : A xD card reader
63      */
64     enum DriveType { HardDisk, CdromDrive, Floppy, Tape, CompactFlash, MemoryStick, SmartMedia, SdMmc, Xd };
65     Q_ENUM(DriveType)
66 
67 private:
68     /**
69      * Creates a new StorageDrive object.
70      * You generally won't need this. It's created when necessary using
71      * Device::as().
72      *
73      * @param backendObject the device interface object provided by the backend
74      * @see Solid::Device::as()
75      */
76     explicit StorageDrive(QObject *backendObject);
77 
78 public:
79     /**
80      * Destroys a StorageDrive object.
81      */
82     ~StorageDrive() override;
83 
84     /**
85      * Get the Solid::DeviceInterface::Type of the StorageDrive device interface.
86      *
87      * @return the StorageDrive device interface type
88      * @see Solid::DeviceInterface::Type
89      */
deviceInterfaceType()90     static Type deviceInterfaceType()
91     {
92         return DeviceInterface::StorageDrive;
93     }
94 
95     /**
96      * Retrieves the type of physical interface this storage device is
97      * connected to.
98      *
99      * @return the bus type
100      * @see Solid::StorageDrive::Bus
101      */
102     Bus bus() const;
103 
104     /**
105      * Retrieves the type of this storage drive.
106      *
107      * @return the drive type
108      * @see Solid::StorageDrive::DriveType
109      */
110     DriveType driveType() const;
111 
112     /**
113      * Indicates if the media contained by this drive can be removed.
114      *
115      * For example memory card can be removed from the drive by the user,
116      * while partitions can't be removed from hard disks.
117      *
118      * @return true if media can be removed, false otherwise.
119      */
120     bool isRemovable() const;
121 
122     /**
123      * Indicates if this storage device can be plugged or unplugged while
124      * the computer is running.
125      *
126      * @return true if this storage supports hotplug, false otherwise
127      */
128     bool isHotpluggable() const;
129 
130     /**
131      * Retrieves this drives size in bytes.
132      *
133      * @return the size of this drive
134      */
135     qulonglong size() const;
136 
137     /**
138      * Indicates if the storage device is currently in use
139      * i.e. if at least one child storage access is
140      * mounted
141      *
142      * @return true if at least one child storage access is mounted
143      */
144     bool isInUse() const;
145 
146 protected:
147     /**
148      * @internal
149      */
150     StorageDrive(StorageDrivePrivate &dd, QObject *backendObject);
151 };
152 }
153 
154 #endif // SOLID_STORAGEDRIVE_H
155