1 /*
2     Copyright 2010 Michael Zanetti <mzanetti@kde.org>
3     Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) version 3, or any
9     later version accepted by the membership of KDE e.V. (or its
10     successor approved by the membership of KDE e.V.), which shall
11     act as a proxy defined in Section 6 of version 3 of the license.
12 
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16     Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "udisksstoragedrive.h"
23 
24 #include <QDebug>
25 
26 using namespace Solid::Backends::UDisks;
27 
UDisksStorageDrive(UDisksDevice * device)28 UDisksStorageDrive::UDisksStorageDrive(UDisksDevice* device)
29     : Block(device)
30 {
31 
32 }
33 
~UDisksStorageDrive()34 UDisksStorageDrive::~UDisksStorageDrive()
35 {
36 
37 }
38 
size() const39 qulonglong UDisksStorageDrive::size() const
40 {
41     return m_device->prop("DeviceSize").toULongLong();
42 }
43 
isHotpluggable() const44 bool UDisksStorageDrive::isHotpluggable() const
45 {
46     return m_device->prop("DriveCanDetach").toBool();
47 }
48 
isRemovable() const49 bool UDisksStorageDrive::isRemovable() const
50 {
51     return m_device->prop("DeviceIsRemovable").toBool() ||
52             !m_device->prop( "DeviceIsSystemInternal" ).toBool();
53 }
54 
driveType() const55 Solid::StorageDrive::DriveType UDisksStorageDrive::driveType() const
56 {
57     const QStringList mediaTypes = m_device->prop("DriveMediaCompatibility").toStringList();
58     bool isHardDisk = m_device->prop( "DeviceIsSystemInternal" ).toBool();
59 
60     if ( isHardDisk )
61     {
62         return Solid::StorageDrive::HardDisk;
63     }
64     else if ( !mediaTypes.filter( "optical" ).isEmpty() ) // optical disks
65     {
66         return Solid::StorageDrive::CdromDrive;
67     }
68     else if ( mediaTypes.contains( "floppy" ) )
69     {
70         return Solid::StorageDrive::Floppy;
71     }
72 #if 0 // TODO add to Solid
73     else if ( mediaTypes.contains( "floppy_jaz" ) )
74     {
75         return Solid::StorageDrive::Jaz;
76     }
77     else if ( mediaTypes.contains( "floppy_zip" ) )
78     {
79         return Solid::StorageDrive::Zip;
80     }
81 #endif
82     /*
83     else if (type=="tape")      // FIXME: DK doesn't know about tapes
84     {
85         return Solid::StorageDrive::Tape;
86     }
87     */
88 #if 0 // TODO add to Solid
89     else if ( mediaTypes.contains( "flash" ) )
90     {
91         return Solid::StorageDrive::Flash;
92     }
93 #endif
94     else if ( mediaTypes.contains( "flash_cf" ) )
95     {
96         return Solid::StorageDrive::CompactFlash;
97     }
98     else if ( mediaTypes.contains( "flash_ms" ) )
99     {
100         return Solid::StorageDrive::MemoryStick;
101     }
102     else if ( mediaTypes.contains( "flash_sm" ) )
103     {
104         return Solid::StorageDrive::SmartMedia;
105     }
106     else if ( mediaTypes.contains( "flash_sd" ) || mediaTypes.contains( "flash_sdhc" ) || mediaTypes.contains( "flash_mmc" ) )
107     {
108         return Solid::StorageDrive::SdMmc;
109     }
110     // FIXME: DK doesn't know about xD cards either
111     else
112     {
113         return Solid::StorageDrive::HardDisk;
114     }
115 }
116 
bus() const117 Solid::StorageDrive::Bus UDisksStorageDrive::bus() const
118 {
119     const QString bus = m_device->prop( "DriveConnectionInterface" ).toString();
120 
121     if ( bus == "ata" || bus == "ata_parallel" ) // parallel (classical) ATA
122     {
123         return Solid::StorageDrive::Ide;
124     }
125     else if ( bus == "usb" )
126     {
127         return Solid::StorageDrive::Usb;
128     }
129     else if ( bus == "firewire" )
130     {
131         return Solid::StorageDrive::Ieee1394;
132     }
133     else if ( bus == "scsi" )
134     {
135         return Solid::StorageDrive::Scsi;
136     }
137     else if ( bus == "ata_serial" || bus == "ata_serial_esata" ) // serial ATA
138     {
139         return Solid::StorageDrive::Sata;
140     }
141 #if 0  // TODO add these to Solid
142     else if ( bus == "sdio" )
143     {
144         return Solid::StorageDrive::SDIO;
145     }
146     else if ( bus == "virtual" )
147     {
148         return Solid::StorageDrive::Virtual;
149     }
150 #endif
151     else
152         return Solid::StorageDrive::Platform;
153 }
154 
155