• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Solid

  • solid
  • solid
device.cpp
Go to the documentation of this file.
1/*
2 Copyright 2005-2007 Kevin Ottens <ervin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include "device.h"
22#include "device_p.h"
23#include "devicenotifier.h"
24#include "devicemanager_p.h"
25
26#include "deviceinterface_p.h"
27#include "soliddefs_p.h"
28
29#include <solid/ifaces/device.h>
30
31#include <solid/genericinterface.h>
32#include <solid/ifaces/genericinterface.h>
33#include <solid/processor.h>
34#include <solid/ifaces/processor.h>
35#include <solid/block.h>
36#include <solid/ifaces/block.h>
37#include <solid/storageaccess.h>
38#include <solid/ifaces/storageaccess.h>
39#include <solid/storagedrive.h>
40#include <solid/ifaces/storagedrive.h>
41#include <solid/opticaldrive.h>
42#include <solid/ifaces/opticaldrive.h>
43#include <solid/storagevolume.h>
44#include <solid/ifaces/storagevolume.h>
45#include <solid/opticaldisc.h>
46#include <solid/ifaces/opticaldisc.h>
47#include <solid/camera.h>
48#include <solid/ifaces/camera.h>
49#include <solid/portablemediaplayer.h>
50#include <solid/ifaces/portablemediaplayer.h>
51#include <solid/networkinterface.h>
52#include <solid/ifaces/networkinterface.h>
53#include <solid/networkshare.h>
54#include <solid/ifaces/networkshare.h>
55#include <solid/acadapter.h>
56#include <solid/ifaces/acadapter.h>
57#include <solid/battery.h>
58#include <solid/ifaces/battery.h>
59#include <solid/button.h>
60#include <solid/ifaces/button.h>
61#include <solid/audiointerface.h>
62#include <solid/ifaces/audiointerface.h>
63#include <solid/dvbinterface.h>
64#include <solid/ifaces/dvbinterface.h>
65#include <solid/video.h>
66#include <solid/ifaces/video.h>
67#include <solid/serialinterface.h>
68#include <solid/ifaces/serialinterface.h>
69#include <solid/smartcardreader.h>
70#include <solid/ifaces/smartcardreader.h>
71#include <solid/internetgateway.h>
72#include <solid/ifaces/internetgateway.h>
73
74
75Solid::Device::Device(const QString &udi)
76{
77 DeviceManagerPrivate *manager
78 = static_cast<DeviceManagerPrivate *>(Solid::DeviceNotifier::instance());
79 d = manager->findRegisteredDevice(udi);
80}
81
82Solid::Device::Device(const Device &device)
83 : d(device.d)
84{
85}
86
87Solid::Device::~Device()
88{
89}
90
91Solid::Device &Solid::Device::operator=(const Solid::Device &device)
92{
93 d = device.d;
94 return *this;
95}
96
97bool Solid::Device::isValid() const
98{
99 return d->backendObject()!=0;
100}
101
102QString Solid::Device::udi() const
103{
104 return d->udi();
105}
106
107QString Solid::Device::parentUdi() const
108{
109 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), parentUdi());
110}
111
112Solid::Device Solid::Device::parent() const
113{
114 QString udi = parentUdi();
115
116 if (udi.isEmpty())
117 {
118 return Device();
119 }
120 else
121 {
122 return Device(udi);
123 }
124}
125
126QString Solid::Device::vendor() const
127{
128 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), vendor());
129}
130
131QString Solid::Device::product() const
132{
133 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), product());
134}
135
136QString Solid::Device::icon() const
137{
138 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), icon());
139}
140
141QStringList Solid::Device::emblems() const
142{
143 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QStringList(), emblems());
144}
145
146QString Solid::Device::description() const
147{
148 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), description());
149}
150
151bool Solid::Device::isDeviceInterface(const DeviceInterface::Type &type) const
152{
153 return_SOLID_CALL(Ifaces::Device *, d->backendObject(), false, queryDeviceInterface(type));
154}
155
156#define deviceinterface_cast(IfaceType, DevType, backendObject) \
157 (qobject_cast<IfaceType *>(backendObject) ? new DevType(backendObject) : 0)
158
159Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type)
160{
161 const Solid::DeviceInterface *interface = const_cast<const Device *>(this)->asDeviceInterface(type);
162 return const_cast<Solid::DeviceInterface *>(interface);
163}
164
165const Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type) const
166{
167 Ifaces::Device *device = qobject_cast<Ifaces::Device *>(d->backendObject());
168
169 if (device!=0)
170 {
171 DeviceInterface *iface = d->interface(type);
172
173 if (iface!=0) {
174 return iface;
175 }
176
177 QObject *dev_iface = device->createDeviceInterface(type);
178
179 if (dev_iface!=0)
180 {
181 switch (type)
182 {
183 case DeviceInterface::GenericInterface:
184 iface = deviceinterface_cast(Ifaces::GenericInterface, GenericInterface, dev_iface);
185 break;
186 case DeviceInterface::Processor:
187 iface = deviceinterface_cast(Ifaces::Processor, Processor, dev_iface);
188 break;
189 case DeviceInterface::Block:
190 iface = deviceinterface_cast(Ifaces::Block, Block, dev_iface);
191 break;
192 case DeviceInterface::StorageAccess:
193 iface = deviceinterface_cast(Ifaces::StorageAccess, StorageAccess, dev_iface);
194 break;
195 case DeviceInterface::StorageDrive:
196 iface = deviceinterface_cast(Ifaces::StorageDrive, StorageDrive, dev_iface);
197 break;
198 case DeviceInterface::OpticalDrive:
199 iface = deviceinterface_cast(Ifaces::OpticalDrive, OpticalDrive, dev_iface);
200 break;
201 case DeviceInterface::StorageVolume:
202 iface = deviceinterface_cast(Ifaces::StorageVolume, StorageVolume, dev_iface);
203 break;
204 case DeviceInterface::OpticalDisc:
205 iface = deviceinterface_cast(Ifaces::OpticalDisc, OpticalDisc, dev_iface);
206 break;
207 case DeviceInterface::Camera:
208 iface = deviceinterface_cast(Ifaces::Camera, Camera, dev_iface);
209 break;
210 case DeviceInterface::PortableMediaPlayer:
211 iface = deviceinterface_cast(Ifaces::PortableMediaPlayer, PortableMediaPlayer, dev_iface);
212 break;
213 case DeviceInterface::NetworkInterface:
214 iface = deviceinterface_cast(Ifaces::NetworkInterface, NetworkInterface, dev_iface);
215 break;
216 case DeviceInterface::AcAdapter:
217 iface = deviceinterface_cast(Ifaces::AcAdapter, AcAdapter, dev_iface);
218 break;
219 case DeviceInterface::Battery:
220 iface = deviceinterface_cast(Ifaces::Battery, Battery, dev_iface);
221 break;
222 case DeviceInterface::Button:
223 iface = deviceinterface_cast(Ifaces::Button, Button, dev_iface);
224 break;
225 case DeviceInterface::AudioInterface:
226 iface = deviceinterface_cast(Ifaces::AudioInterface, AudioInterface, dev_iface);
227 break;
228 case DeviceInterface::DvbInterface:
229 iface = deviceinterface_cast(Ifaces::DvbInterface, DvbInterface, dev_iface);
230 break;
231 case DeviceInterface::Video:
232 iface = deviceinterface_cast(Ifaces::Video, Video, dev_iface);
233 break;
234 case DeviceInterface::SerialInterface:
235 iface = deviceinterface_cast(Ifaces::SerialInterface, SerialInterface, dev_iface);
236 break;
237 case DeviceInterface::SmartCardReader:
238 iface = deviceinterface_cast(Ifaces::SmartCardReader, SmartCardReader, dev_iface);
239 break;
240 case DeviceInterface::InternetGateway:
241 iface = deviceinterface_cast(Ifaces::InternetGateway, InternetGateway, dev_iface);
242 break;
243 case DeviceInterface::NetworkShare:
244 iface = deviceinterface_cast(Ifaces::NetworkShare, NetworkShare, dev_iface);
245 break;
246 case DeviceInterface::Unknown:
247 case DeviceInterface::Last:
248 break;
249 }
250 }
251
252 if (iface!=0)
253 {
254 // Lie on the constness since we're simply doing caching here
255 const_cast<Device *>(this)->d->setInterface(type, iface);
256 iface->d_ptr->setDevicePrivate(d.data());
257 }
258
259 return iface;
260 }
261 else
262 {
263 return 0;
264 }
265}
266
267
269
270
271Solid::DevicePrivate::DevicePrivate(const QString &udi)
272 : QObject(), QSharedData(), m_udi(udi)
273{
274}
275
276Solid::DevicePrivate::~DevicePrivate()
277{
278 foreach (DeviceInterface *iface, m_ifaces) {
279 delete iface->d_ptr->backendObject();
280 }
281 setBackendObject(0);
282}
283
284void Solid::DevicePrivate::_k_destroyed(QObject *object)
285{
286 Q_UNUSED(object);
287 setBackendObject(0);
288}
289
290void Solid::DevicePrivate::setBackendObject(Ifaces::Device *object)
291{
292
293 if (m_backendObject) {
294 m_backendObject.data()->disconnect(this);
295 }
296
297 delete m_backendObject.data();
298 m_backendObject = object;
299
300 if (object) {
301 connect(object, SIGNAL(destroyed(QObject*)),
302 this, SLOT(_k_destroyed(QObject*)));
303 }
304
305 if (!m_ifaces.isEmpty()) {
306 foreach (DeviceInterface *iface, m_ifaces) {
307 delete iface;
308 }
309
310 m_ifaces.clear();
311 if (!ref.deref()) deleteLater();
312 }
313}
314
315Solid::DeviceInterface *Solid::DevicePrivate::interface(const DeviceInterface::Type &type) const
316{
317 return m_ifaces[type];
318}
319
320void Solid::DevicePrivate::setInterface(const DeviceInterface::Type &type, DeviceInterface *interface)
321{
322 if(m_ifaces.isEmpty())
323 ref.ref();
324 m_ifaces[type] = interface;
325}
326
327#include "device_p.moc"
acadapter.h
audiointerface.h
battery.h
block.h
button.h
camera.h
QObject
QSharedData
Solid::AcAdapter
This device interface is available on AC adapters.
Definition: acadapter.h:37
Solid::AudioInterface
This device interface is available on interfaces exposed by sound cards.
Definition: audiointerface.h:38
Solid::Battery
This device interface is available on batteries.
Definition: battery.h:37
Solid::Block
This device interface is available on block devices.
Definition: block.h:41
Solid::Button
This device interface is available on button devices.
Definition: button.h:43
Solid::Camera
This device interface is available on digital camera devices.
Definition: camera.h:47
Solid::DeviceInterfacePrivate::backendObject
QObject * backendObject() const
Definition: deviceinterface.cpp:129
Solid::DeviceInterfacePrivate::setDevicePrivate
void setDevicePrivate(DevicePrivate *devicePrivate)
Definition: deviceinterface.cpp:144
Solid::DeviceInterface
Base class of all the device interfaces.
Definition: deviceinterface.h:43
Solid::DeviceInterface::Type
Type
This enum type defines the type of device interface that a Device can have.
Definition: deviceinterface.h:67
Solid::DeviceInterface::SmartCardReader
@ SmartCardReader
Definition: deviceinterface.h:73
Solid::DeviceInterface::SerialInterface
@ SerialInterface
Definition: deviceinterface.h:73
Solid::DeviceInterface::NetworkShare
@ NetworkShare
Definition: deviceinterface.h:74
Solid::DeviceInterface::AcAdapter
@ AcAdapter
Definition: deviceinterface.h:71
Solid::DeviceInterface::DvbInterface
@ DvbInterface
Definition: deviceinterface.h:72
Solid::DeviceInterface::NetworkInterface
@ NetworkInterface
Definition: deviceinterface.h:71
Solid::DeviceInterface::Last
@ Last
Definition: deviceinterface.h:74
Solid::DeviceInterface::PortableMediaPlayer
@ PortableMediaPlayer
Definition: deviceinterface.h:70
Solid::DeviceInterface::StorageDrive
@ StorageDrive
Definition: deviceinterface.h:68
Solid::DeviceInterface::Camera
@ Camera
Definition: deviceinterface.h:70
Solid::DeviceInterface::GenericInterface
@ GenericInterface
Definition: deviceinterface.h:67
Solid::DeviceInterface::AudioInterface
@ AudioInterface
Definition: deviceinterface.h:72
Solid::DeviceInterface::Video
@ Video
Definition: deviceinterface.h:72
Solid::DeviceInterface::StorageAccess
@ StorageAccess
Definition: deviceinterface.h:68
Solid::DeviceInterface::OpticalDrive
@ OpticalDrive
Definition: deviceinterface.h:69
Solid::DeviceInterface::Processor
@ Processor
Definition: deviceinterface.h:67
Solid::DeviceInterface::Block
@ Block
Definition: deviceinterface.h:68
Solid::DeviceInterface::OpticalDisc
@ OpticalDisc
Definition: deviceinterface.h:69
Solid::DeviceInterface::InternetGateway
@ InternetGateway
Definition: deviceinterface.h:73
Solid::DeviceInterface::Unknown
@ Unknown
Definition: deviceinterface.h:67
Solid::DeviceInterface::Battery
@ Battery
Definition: deviceinterface.h:71
Solid::DeviceInterface::StorageVolume
@ StorageVolume
Definition: deviceinterface.h:69
Solid::DeviceInterface::Button
@ Button
Definition: deviceinterface.h:72
Solid::DeviceInterface::d_ptr
DeviceInterfacePrivate * d_ptr
Definition: deviceinterface.h:118
Solid::DeviceManagerPrivate
Definition: devicemanager_p.h:43
Solid::DeviceManagerPrivate::findRegisteredDevice
DevicePrivate * findRegisteredDevice(const QString &udi)
Definition: devicemanager.cpp:219
Solid::DeviceNotifier::instance
static DeviceNotifier * instance()
Definition: devicemanager.cpp:170
Solid::DevicePrivate::setInterface
void setInterface(const DeviceInterface::Type &type, DeviceInterface *interface)
Definition: device.cpp:320
Solid::DevicePrivate::DevicePrivate
DevicePrivate(const QString &udi)
Definition: device.cpp:271
Solid::DevicePrivate::interface
DeviceInterface * interface(const DeviceInterface::Type &type) const
Definition: device.cpp:315
Solid::DevicePrivate::setBackendObject
void setBackendObject(Ifaces::Device *object)
Definition: device.cpp:290
Solid::DevicePrivate::_k_destroyed
void _k_destroyed(QObject *object)
Definition: device.cpp:284
Solid::DevicePrivate::~DevicePrivate
~DevicePrivate()
Definition: device.cpp:276
Solid::Device
This class allows applications to deal with devices available in the underlying system.
Definition: device.h:49
Solid::Device::description
QString description() const
Retrieves the description of device.
Definition: device.cpp:146
Solid::Device::emblems
QStringList emblems() const
Retrieves the names of the emblems representing the state of this device.
Definition: device.cpp:141
Solid::Device::udi
QString udi() const
Retrieves the Universal Device Identifier (UDI).
Definition: device.cpp:102
Solid::Device::operator=
Device & operator=(const Device &device)
Assigns a device to this device and returns a reference to it.
Definition: device.cpp:91
Solid::Device::parentUdi
QString parentUdi() const
Retrieves the Universal Device Identifier (UDI) of the Device's parent.
Definition: device.cpp:107
Solid::Device::icon
QString icon() const
Retrieves the name of the icon representing this device.
Definition: device.cpp:136
Solid::Device::~Device
~Device()
Destroys the device.
Definition: device.cpp:87
Solid::Device::isDeviceInterface
bool isDeviceInterface(const DeviceInterface::Type &type) const
Tests if a device interface is available from the device.
Definition: device.cpp:151
Solid::Device::parent
Device parent() const
Retrieves the parent of the Device.
Definition: device.cpp:112
Solid::Device::asDeviceInterface
DeviceInterface * asDeviceInterface(const DeviceInterface::Type &type)
Retrieves a specialized interface to interact with the device corresponding to a particular device in...
Definition: device.cpp:159
Solid::Device::Device
Device(const QString &udi=QString())
Constructs a device for a given Universal Device Identifier (UDI).
Definition: device.cpp:75
Solid::Device::vendor
QString vendor() const
Retrieves the name of the device vendor.
Definition: device.cpp:126
Solid::Device::isValid
bool isValid() const
Indicates if this device is valid.
Definition: device.cpp:97
Solid::Device::product
QString product() const
Retrieves the name of the product corresponding to this device.
Definition: device.cpp:131
Solid::DvbInterface
This device interface is available on Digital Video Broadcast (DVB) devices.
Definition: dvbinterface.h:42
Solid::GenericInterface
Generic interface to deal with a device.
Definition: genericinterface.h:45
Solid::InternetGateway
Definition: internetgateway.h:38
Solid::NetworkInterface
This device interface is available on network interfaces.
Definition: networkinterface.h:37
Solid::NetworkShare
NetworkShare interface.
Definition: networkshare.h:45
Solid::OpticalDisc
This device interface is available on optical discs.
Definition: opticaldisc.h:39
Solid::OpticalDrive
This device interface is available on CD-R*,DVD*,Blu-Ray,HD-DVD drives.
Definition: opticaldrive.h:43
Solid::PortableMediaPlayer
This class implements Portable Media Player device interface and represents a portable media player a...
Definition: portablemediaplayer.h:46
Solid::Processor
This device interface is available on processors.
Definition: processor.h:37
Solid::SerialInterface
This device interface is available on serial interfaces.
Definition: serialinterface.h:38
Solid::SmartCardReader
This device interface is available on smart card readers.
Definition: smartcardreader.h:37
Solid::StorageAccess
This device interface is available on volume devices to access them (i.e.
Definition: storageaccess.h:43
Solid::StorageDrive
This device interface is available on storage devices.
Definition: storagedrive.h:40
Solid::StorageVolume
This device interface is available on volume devices.
Definition: storagevolume.h:40
Solid::Video
This device interface is available on video devices.
Definition: video.h:45
deviceinterface_cast
#define deviceinterface_cast(IfaceType, DevType, backendObject)
Definition: device.cpp:156
device.h
device_p.h
deviceinterface_p.h
devicemanager_p.h
devicenotifier.h
dvbinterface.h
genericinterface.h
internetgateway.h
networkinterface.h
networkshare.h
opticaldisc.h
opticaldrive.h
portablemediaplayer.h
processor.h
serialinterface.h
smartcardreader.h
soliddefs_p.h
return_SOLID_CALL
#define return_SOLID_CALL(Type, Object, Default, Method)
Definition: soliddefs_p.h:26
storageaccess.h
storagedrive.h
storagevolume.h
video.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Solid

Skip menu "Solid"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal