1 /*
2     Copyright 2012 Patrick von Reth <vonreth@kde.org>
3     Copyright 2006 Kevin Ottens <ervin@kde.org>
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 "wmistorage.h"
23 #include "wmiquery.h"
24 
25 using namespace Solid::Backends::Wmi;
26 
Storage(WmiDevice * device)27 Storage::Storage(WmiDevice *device)
28     : Block(device)
29 {
30 
31     if(m_device->type() == Solid::DeviceInterface::StorageDrive)
32     {
33         WmiQuery::Item item =  WmiDevice::win32DiskPartitionByDeviceIndex(m_device->property("DeviceID").toString());
34         QString id = item.getProperty("DeviceID").toString();
35         m_logicalDisk = WmiDevice::win32LogicalDiskByDiskPartitionID(id);
36     }else if(m_device->type() == Solid::DeviceInterface::OpticalDrive)
37     {
38         QString id = m_device->property("Drive").toString();
39         m_logicalDisk = WmiDevice::win32LogicalDiskByDriveLetter(id);
40     }
41 }
42 
~Storage()43 Storage::~Storage()
44 {
45 
46 }
47 
bus() const48 Solid::StorageDrive::Bus Storage::bus() const
49 {
50      if(m_device->type() == Solid::DeviceInterface::OpticalDrive)
51          return Solid::StorageDrive::Platform;
52 
53 
54     QString bus =  m_device->property("InterfaceType").toString().toLower();
55 
56     if (bus=="ide")
57     {
58         return Solid::StorageDrive::Ide;
59     }
60     else if (bus=="usb")
61     {
62         return Solid::StorageDrive::Usb;
63     }
64     else if (bus=="1394")
65     {
66         return Solid::StorageDrive::Ieee1394;
67     }
68     else if (bus=="scsi")
69     {
70         return Solid::StorageDrive::Scsi;
71     }
72 //    else if (bus=="sata")//not availible http://msdn.microsoft.com/en-us/library/windows/desktop/aa394132(v=vs.85).aspx
73 //    {
74 //        return Solid::StorageDrive::Sata;
75 //    }
76     else
77     {
78         return Solid::StorageDrive::Platform;
79     }
80 }
81 
driveType() const82 Solid::StorageDrive::DriveType Storage::driveType() const
83 {
84     ushort type = m_logicalDisk.getProperty("DriveType").toUInt();
85     switch(type){
86     case 2:
87         return Solid::StorageDrive::MemoryStick;
88     case 3:
89         return Solid::StorageDrive::HardDisk;
90     case 5:
91         return Solid::StorageDrive::CdromDrive;
92     default:
93         return Solid::StorageDrive::HardDisk;
94     }
95 }
96 
isRemovable() const97 bool Storage::isRemovable() const
98 {
99     return driveType() != Solid::StorageDrive::HardDisk;
100 }
101 
isHotpluggable() const102 bool Storage::isHotpluggable() const
103 {
104     return bus() == Solid::StorageDrive::Usb;
105 }
106 
size() const107 qulonglong Storage::size() const
108 {
109     return m_device->property("Size").toULongLong();
110 }
111 
112 #include "backends/wmi/moc_wmistorage.cpp"
113