File: udisksstoragedrive.cpp

package info (click to toggle)
cantata 3.4.0.ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,428 kB
  • sloc: cpp: 109,584; perl: 1,366; xml: 722; python: 139; lex: 110; sh: 105; yacc: 78; makefile: 8
file content (140 lines) | stat: -rw-r--r-- 3,942 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
    Copyright 2010 Michael Zanetti <mzanetti@kde.org>
    Copyright 2010 Lukas Tinkl <ltinkl@redhat.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) version 3, or any
    later version accepted by the membership of KDE e.V. (or its
    successor approved by the membership of KDE e.V.), which shall
    act as a proxy defined in Section 6 of version 3 of the license.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#include "udisksstoragedrive.h"

#include <QDebug>

using namespace Solid::Backends::UDisks;

UDisksStorageDrive::UDisksStorageDrive(UDisksDevice* device)
	: Block(device)
{
}

UDisksStorageDrive::~UDisksStorageDrive()
{
}

qulonglong UDisksStorageDrive::size() const
{
	return m_device->prop("DeviceSize").toULongLong();
}

bool UDisksStorageDrive::isHotpluggable() const
{
	return m_device->prop("DriveCanDetach").toBool();
}

bool UDisksStorageDrive::isRemovable() const
{
	return m_device->prop("DeviceIsRemovable").toBool() || !m_device->prop("DeviceIsSystemInternal").toBool();
}

Solid::StorageDrive::DriveType UDisksStorageDrive::driveType() const
{
	const QStringList mediaTypes = m_device->prop("DriveMediaCompatibility").toStringList();
	bool isHardDisk = m_device->prop("DeviceIsSystemInternal").toBool();

	if (isHardDisk) {
		return Solid::StorageDrive::HardDisk;
	}
	else if (!mediaTypes.filter("optical").isEmpty())// optical disks
	{
		return Solid::StorageDrive::CdromDrive;
	}
	else if (mediaTypes.contains("floppy")) {
		return Solid::StorageDrive::Floppy;
	}
#if 0// TODO add to Solid
    else if ( mediaTypes.contains( "floppy_jaz" ) )
    {
        return Solid::StorageDrive::Jaz;
    }
    else if ( mediaTypes.contains( "floppy_zip" ) )
    {
        return Solid::StorageDrive::Zip;
    }
#endif
	/*
    else if (type=="tape")      // FIXME: DK doesn't know about tapes
    {
        return Solid::StorageDrive::Tape;
    }
    */
#if 0// TODO add to Solid
    else if ( mediaTypes.contains( "flash" ) )
    {
        return Solid::StorageDrive::Flash;
    }
#endif
	else if (mediaTypes.contains("flash_cf")) {
		return Solid::StorageDrive::CompactFlash;
	}
	else if (mediaTypes.contains("flash_ms")) {
		return Solid::StorageDrive::MemoryStick;
	}
	else if (mediaTypes.contains("flash_sm")) {
		return Solid::StorageDrive::SmartMedia;
	}
	else if (mediaTypes.contains("flash_sd") || mediaTypes.contains("flash_sdhc") || mediaTypes.contains("flash_mmc")) {
		return Solid::StorageDrive::SdMmc;
	}
	// FIXME: DK doesn't know about xD cards either
	else {
		return Solid::StorageDrive::HardDisk;
	}
}

Solid::StorageDrive::Bus UDisksStorageDrive::bus() const
{
	const QString bus = m_device->prop("DriveConnectionInterface").toString();

	if (bus == "ata" || bus == "ata_parallel")// parallel (classical) ATA
	{
		return Solid::StorageDrive::Ide;
	}
	else if (bus == "usb") {
		return Solid::StorageDrive::Usb;
	}
	else if (bus == "firewire") {
		return Solid::StorageDrive::Ieee1394;
	}
	else if (bus == "scsi") {
		return Solid::StorageDrive::Scsi;
	}
	else if (bus == "ata_serial" || bus == "ata_serial_esata")// serial ATA
	{
		return Solid::StorageDrive::Sata;
	}
#if 0// TODO add these to Solid
    else if ( bus == "sdio" )
    {
        return Solid::StorageDrive::SDIO;
    }
    else if ( bus == "virtual" )
    {
        return Solid::StorageDrive::Virtual;
    }
#endif
	else
		return Solid::StorageDrive::Platform;
}