• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 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 
75 Solid::Device::Device(const QString &udi)
76 {
77  DeviceManagerPrivate *manager
78  = static_cast<DeviceManagerPrivate *>(Solid::DeviceNotifier::instance());
79  d = manager->findRegisteredDevice(udi);
80 }
81 
82 Solid::Device::Device(const Device &device)
83  : d(device.d)
84 {
85 }
86 
87 Solid::Device::~Device()
88 {
89 }
90 
91 Solid::Device &Solid::Device::operator=(const Solid::Device &device)
92 {
93  d = device.d;
94  return *this;
95 }
96 
97 bool Solid::Device::isValid() const
98 {
99  return d->backendObject()!=0;
100 }
101 
102 QString Solid::Device::udi() const
103 {
104  return d->udi();
105 }
106 
107 QString Solid::Device::parentUdi() const
108 {
109  return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), parentUdi());
110 }
111 
112 Solid::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 
126 QString Solid::Device::vendor() const
127 {
128  return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), vendor());
129 }
130 
131 QString Solid::Device::product() const
132 {
133  return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), product());
134 }
135 
136 QString Solid::Device::icon() const
137 {
138  return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), icon());
139 }
140 
141 QStringList Solid::Device::emblems() const
142 {
143  return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QStringList(), emblems());
144 }
145 
146 QString Solid::Device::description() const
147 {
148  return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), description());
149 }
150 
151 bool 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 
159 Solid::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 
165 const 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 
271 Solid::DevicePrivate::DevicePrivate(const QString &udi)
272  : QObject(), QSharedData(), m_udi(udi)
273 {
274 }
275 
276 Solid::DevicePrivate::~DevicePrivate()
277 {
278  foreach (DeviceInterface *iface, m_ifaces) {
279  delete iface->d_ptr->backendObject();
280  }
281  setBackendObject(0);
282 }
283 
284 void Solid::DevicePrivate::_k_destroyed(QObject *object)
285 {
286  Q_UNUSED(object);
287  setBackendObject(0);
288 }
289 
290 void 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 
315 Solid::DeviceInterface *Solid::DevicePrivate::interface(const DeviceInterface::Type &type) const
316 {
317  return m_ifaces[type];
318 }
319 
320 void 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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Jul 12 2013 08:52:02 by doxygen 1.8.3.1 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.10.5 API Reference

Skip menu "kdelibs-4.10.5 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