• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Solid

device.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2005-2007 Kevin Ottens <ervin@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #include "device.h"
00021 #include "device_p.h"
00022 #include "devicenotifier.h"
00023 #include "devicemanager_p.h"
00024 
00025 #include "deviceinterface_p.h"
00026 #include "soliddefs_p.h"
00027 
00028 #include <solid/ifaces/device.h>
00029 
00030 #include <solid/genericinterface.h>
00031 #include <solid/ifaces/genericinterface.h>
00032 #include <solid/processor.h>
00033 #include <solid/ifaces/processor.h>
00034 #include <solid/block.h>
00035 #include <solid/ifaces/block.h>
00036 #include <solid/storageaccess.h>
00037 #include <solid/ifaces/storageaccess.h>
00038 #include <solid/storagedrive.h>
00039 #include <solid/ifaces/storagedrive.h>
00040 #include <solid/opticaldrive.h>
00041 #include <solid/ifaces/opticaldrive.h>
00042 #include <solid/storagevolume.h>
00043 #include <solid/ifaces/storagevolume.h>
00044 #include <solid/opticaldisc.h>
00045 #include <solid/ifaces/opticaldisc.h>
00046 #include <solid/camera.h>
00047 #include <solid/ifaces/camera.h>
00048 #include <solid/portablemediaplayer.h>
00049 #include <solid/ifaces/portablemediaplayer.h>
00050 #include <solid/networkinterface.h>
00051 #include <solid/ifaces/networkinterface.h>
00052 #include <solid/acadapter.h>
00053 #include <solid/ifaces/acadapter.h>
00054 #include <solid/battery.h>
00055 #include <solid/ifaces/battery.h>
00056 #include <solid/button.h>
00057 #include <solid/ifaces/button.h>
00058 #include <solid/audiointerface.h>
00059 #include <solid/ifaces/audiointerface.h>
00060 #include <solid/dvbinterface.h>
00061 #include <solid/ifaces/dvbinterface.h>
00062 #include <solid/video.h>
00063 #include <solid/ifaces/video.h>
00064 
00065 
00066 Solid::Device::Device(const QString &udi)
00067 {
00068     DeviceManagerPrivate *manager
00069         = static_cast<DeviceManagerPrivate *>(Solid::DeviceNotifier::instance());
00070     d = manager->findRegisteredDevice(udi);
00071 }
00072 
00073 Solid::Device::Device(const Device &device)
00074     : d(device.d)
00075 {
00076 }
00077 
00078 Solid::Device::~Device()
00079 {
00080 }
00081 
00082 Solid::Device &Solid::Device::operator=(const Solid::Device &device)
00083 {
00084     d = device.d;
00085     return *this;
00086 }
00087 
00088 bool Solid::Device::isValid() const
00089 {
00090     return d->backendObject()!=0;
00091 }
00092 
00093 QString Solid::Device::udi() const
00094 {
00095     return d->udi();
00096 }
00097 
00098 QString Solid::Device::parentUdi() const
00099 {
00100     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), parentUdi());
00101 }
00102 
00103 Solid::Device Solid::Device::parent() const
00104 {
00105     QString udi = parentUdi();
00106 
00107     if (udi.isEmpty())
00108     {
00109         return Device();
00110     }
00111     else
00112     {
00113         return Device(udi);
00114     }
00115 }
00116 
00117 QString Solid::Device::vendor() const
00118 {
00119     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), vendor());
00120 }
00121 
00122 QString Solid::Device::product() const
00123 {
00124     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), product());
00125 }
00126 
00127 QString Solid::Device::icon() const
00128 {
00129     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), icon());
00130 }
00131 
00132 bool Solid::Device::isDeviceInterface(const DeviceInterface::Type &type) const
00133 {
00134     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), false, queryDeviceInterface(type));
00135 }
00136 
00137 #define deviceinterface_cast(IfaceType, DevType, backendObject) \
00138     (qobject_cast<IfaceType *>(backendObject) ? new DevType(backendObject) : 0)
00139 
00140 Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type)
00141 {
00142     const Solid::DeviceInterface *interface = const_cast<const Device *>(this)->asDeviceInterface(type);
00143     return const_cast<Solid::DeviceInterface *>(interface);
00144 }
00145 
00146 const Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type) const
00147 {
00148     Ifaces::Device *device = qobject_cast<Ifaces::Device *>(d->backendObject());
00149 
00150     if (device!=0)
00151     {
00152         DeviceInterface *iface = d->interface(type);
00153 
00154         if (iface!=0) {
00155             return iface;
00156         }
00157 
00158         QObject *dev_iface = device->createDeviceInterface(type);
00159 
00160         if (dev_iface!=0)
00161         {
00162             switch (type)
00163             {
00164             case DeviceInterface::GenericInterface:
00165                 iface = deviceinterface_cast(Ifaces::GenericInterface, GenericInterface, dev_iface);
00166                 break;
00167             case DeviceInterface::Processor:
00168                 iface = deviceinterface_cast(Ifaces::Processor, Processor, dev_iface);
00169                 break;
00170             case DeviceInterface::Block:
00171                 iface = deviceinterface_cast(Ifaces::Block, Block, dev_iface);
00172                 break;
00173             case DeviceInterface::StorageAccess:
00174                 iface = deviceinterface_cast(Ifaces::StorageAccess, StorageAccess, dev_iface);
00175                 break;
00176             case DeviceInterface::StorageDrive:
00177                 iface = deviceinterface_cast(Ifaces::StorageDrive, StorageDrive, dev_iface);
00178                 break;
00179             case DeviceInterface::OpticalDrive:
00180                 iface = deviceinterface_cast(Ifaces::OpticalDrive, OpticalDrive, dev_iface);
00181                 break;
00182             case DeviceInterface::StorageVolume:
00183                 iface = deviceinterface_cast(Ifaces::StorageVolume, StorageVolume, dev_iface);
00184                 break;
00185             case DeviceInterface::OpticalDisc:
00186                 iface = deviceinterface_cast(Ifaces::OpticalDisc, OpticalDisc, dev_iface);
00187                 break;
00188             case DeviceInterface::Camera:
00189                 iface = deviceinterface_cast(Ifaces::Camera, Camera, dev_iface);
00190                 break;
00191             case DeviceInterface::PortableMediaPlayer:
00192                 iface = deviceinterface_cast(Ifaces::PortableMediaPlayer, PortableMediaPlayer, dev_iface);
00193                 break;
00194             case DeviceInterface::NetworkInterface:
00195                 iface = deviceinterface_cast(Ifaces::NetworkInterface, NetworkInterface, dev_iface);
00196                 break;
00197             case DeviceInterface::AcAdapter:
00198                 iface = deviceinterface_cast(Ifaces::AcAdapter, AcAdapter, dev_iface);
00199                 break;
00200             case DeviceInterface::Battery:
00201                 iface = deviceinterface_cast(Ifaces::Battery, Battery, dev_iface);
00202                 break;
00203             case DeviceInterface::Button:
00204                 iface = deviceinterface_cast(Ifaces::Button, Button, dev_iface);
00205                 break;
00206             case DeviceInterface::AudioInterface:
00207                 iface = deviceinterface_cast(Ifaces::AudioInterface, AudioInterface, dev_iface);
00208                 break;
00209             case DeviceInterface::DvbInterface:
00210                 iface = deviceinterface_cast(Ifaces::DvbInterface, DvbInterface, dev_iface);
00211                 break;
00212             case DeviceInterface::Video:
00213                 iface = deviceinterface_cast(Ifaces::Video, Video, dev_iface);
00214                 break;
00215             case DeviceInterface::Unknown:
00216             case DeviceInterface::Last:
00217                 break;
00218             }
00219         }
00220 
00221         if (iface!=0)
00222         {
00223             // Lie on the constness since we're simply doing caching here
00224             const_cast<Device *>(this)->d->setInterface(type, iface);
00225         }
00226 
00227         return iface;
00228     }
00229     else
00230     {
00231         return 0;
00232     }
00233 }
00234 
00235 
00237 
00238 
00239 Solid::DevicePrivate::DevicePrivate(const QString &udi)
00240     : QObject(), QSharedData(), m_udi(udi)
00241 {
00242 }
00243 
00244 Solid::DevicePrivate::~DevicePrivate()
00245 {
00246     qDeleteAll(m_ifaces);
00247 }
00248 
00249 void Solid::DevicePrivate::_k_destroyed(QObject *object)
00250 {
00251     Q_UNUSED(object);
00252     setBackendObject(0);
00253 }
00254 
00255 void Solid::DevicePrivate::setBackendObject(Ifaces::Device *object)
00256 {
00257     m_backendObject = object;
00258 
00259     if (m_backendObject) {
00260         connect(m_backendObject, SIGNAL(destroyed(QObject *)),
00261                 this, SLOT(_k_destroyed(QObject *)));
00262     }
00263 
00264     if (!m_ifaces.isEmpty()) {
00265         foreach (DeviceInterface *iface, m_ifaces) {
00266             delete iface->d_ptr->backendObject();
00267             delete iface;
00268         }
00269 
00270         m_ifaces.clear();
00271 
00272         if (!ref.deref()) deleteLater();
00273     }
00274 }
00275 
00276 Solid::DeviceInterface *Solid::DevicePrivate::interface(const DeviceInterface::Type &type) const
00277 {
00278     return m_ifaces[type];
00279 }
00280 
00281 void Solid::DevicePrivate::setInterface(const DeviceInterface::Type &type, DeviceInterface *interface)
00282 {
00283     ref.ref();
00284     m_ifaces[type] = interface;
00285 }
00286 
00287 #include "device_p.moc"

Solid

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal