• Skip to content
  • Skip to link menu
KDE 4.3 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 #include <solid/serialinterface.h>
00065 #include <solid/ifaces/serialinterface.h>
00066 #include <solid/smartcardreader.h>
00067 #include <solid/ifaces/smartcardreader.h>
00068 
00069 
00070 Solid::Device::Device(const QString &udi)
00071 {
00072     DeviceManagerPrivate *manager
00073         = static_cast<DeviceManagerPrivate *>(Solid::DeviceNotifier::instance());
00074     d = manager->findRegisteredDevice(udi);
00075 }
00076 
00077 Solid::Device::Device(const Device &device)
00078     : d(device.d)
00079 {
00080 }
00081 
00082 Solid::Device::~Device()
00083 {
00084 }
00085 
00086 Solid::Device &Solid::Device::operator=(const Solid::Device &device)
00087 {
00088     d = device.d;
00089     return *this;
00090 }
00091 
00092 bool Solid::Device::isValid() const
00093 {
00094     return d->backendObject()!=0;
00095 }
00096 
00097 QString Solid::Device::udi() const
00098 {
00099     return d->udi();
00100 }
00101 
00102 QString Solid::Device::parentUdi() const
00103 {
00104     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), parentUdi());
00105 }
00106 
00107 Solid::Device Solid::Device::parent() const
00108 {
00109     QString udi = parentUdi();
00110 
00111     if (udi.isEmpty())
00112     {
00113         return Device();
00114     }
00115     else
00116     {
00117         return Device(udi);
00118     }
00119 }
00120 
00121 QString Solid::Device::vendor() const
00122 {
00123     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), vendor());
00124 }
00125 
00126 QString Solid::Device::product() const
00127 {
00128     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), product());
00129 }
00130 
00131 QString Solid::Device::icon() const
00132 {
00133     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), icon());
00134 }
00135 
00136 bool Solid::Device::isDeviceInterface(const DeviceInterface::Type &type) const
00137 {
00138     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), false, queryDeviceInterface(type));
00139 }
00140 
00141 #define deviceinterface_cast(IfaceType, DevType, backendObject) \
00142     (qobject_cast<IfaceType *>(backendObject) ? new DevType(backendObject) : 0)
00143 
00144 Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type)
00145 {
00146     const Solid::DeviceInterface *interface = const_cast<const Device *>(this)->asDeviceInterface(type);
00147     return const_cast<Solid::DeviceInterface *>(interface);
00148 }
00149 
00150 const Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type) const
00151 {
00152     Ifaces::Device *device = qobject_cast<Ifaces::Device *>(d->backendObject());
00153 
00154     if (device!=0)
00155     {
00156         DeviceInterface *iface = d->interface(type);
00157 
00158         if (iface!=0) {
00159             return iface;
00160         }
00161 
00162         QObject *dev_iface = device->createDeviceInterface(type);
00163 
00164         if (dev_iface!=0)
00165         {
00166             switch (type)
00167             {
00168             case DeviceInterface::GenericInterface:
00169                 iface = deviceinterface_cast(Ifaces::GenericInterface, GenericInterface, dev_iface);
00170                 break;
00171             case DeviceInterface::Processor:
00172                 iface = deviceinterface_cast(Ifaces::Processor, Processor, dev_iface);
00173                 break;
00174             case DeviceInterface::Block:
00175                 iface = deviceinterface_cast(Ifaces::Block, Block, dev_iface);
00176                 break;
00177             case DeviceInterface::StorageAccess:
00178                 iface = deviceinterface_cast(Ifaces::StorageAccess, StorageAccess, dev_iface);
00179                 break;
00180             case DeviceInterface::StorageDrive:
00181                 iface = deviceinterface_cast(Ifaces::StorageDrive, StorageDrive, dev_iface);
00182                 break;
00183             case DeviceInterface::OpticalDrive:
00184                 iface = deviceinterface_cast(Ifaces::OpticalDrive, OpticalDrive, dev_iface);
00185                 break;
00186             case DeviceInterface::StorageVolume:
00187                 iface = deviceinterface_cast(Ifaces::StorageVolume, StorageVolume, dev_iface);
00188                 break;
00189             case DeviceInterface::OpticalDisc:
00190                 iface = deviceinterface_cast(Ifaces::OpticalDisc, OpticalDisc, dev_iface);
00191                 break;
00192             case DeviceInterface::Camera:
00193                 iface = deviceinterface_cast(Ifaces::Camera, Camera, dev_iface);
00194                 break;
00195             case DeviceInterface::PortableMediaPlayer:
00196                 iface = deviceinterface_cast(Ifaces::PortableMediaPlayer, PortableMediaPlayer, dev_iface);
00197                 break;
00198             case DeviceInterface::NetworkInterface:
00199                 iface = deviceinterface_cast(Ifaces::NetworkInterface, NetworkInterface, dev_iface);
00200                 break;
00201             case DeviceInterface::AcAdapter:
00202                 iface = deviceinterface_cast(Ifaces::AcAdapter, AcAdapter, dev_iface);
00203                 break;
00204             case DeviceInterface::Battery:
00205                 iface = deviceinterface_cast(Ifaces::Battery, Battery, dev_iface);
00206                 break;
00207             case DeviceInterface::Button:
00208                 iface = deviceinterface_cast(Ifaces::Button, Button, dev_iface);
00209                 break;
00210             case DeviceInterface::AudioInterface:
00211                 iface = deviceinterface_cast(Ifaces::AudioInterface, AudioInterface, dev_iface);
00212                 break;
00213             case DeviceInterface::DvbInterface:
00214                 iface = deviceinterface_cast(Ifaces::DvbInterface, DvbInterface, dev_iface);
00215                 break;
00216             case DeviceInterface::Video:
00217                 iface = deviceinterface_cast(Ifaces::Video, Video, dev_iface);
00218                 break;
00219             case DeviceInterface::SerialInterface:
00220                 iface = deviceinterface_cast(Ifaces::SerialInterface, SerialInterface, dev_iface);
00221                 break;
00222             case DeviceInterface::SmartCardReader:
00223                 iface = deviceinterface_cast(Ifaces::SmartCardReader, SmartCardReader, dev_iface);
00224                 break;
00225             case DeviceInterface::Unknown:
00226             case DeviceInterface::Last:
00227                 break;
00228             }
00229         }
00230 
00231         if (iface!=0)
00232         {
00233             // Lie on the constness since we're simply doing caching here
00234             const_cast<Device *>(this)->d->setInterface(type, iface);
00235         }
00236 
00237         return iface;
00238     }
00239     else
00240     {
00241         return 0;
00242     }
00243 }
00244 
00245 
00247 
00248 
00249 Solid::DevicePrivate::DevicePrivate(const QString &udi)
00250     : QObject(), QSharedData(), m_udi(udi)
00251 {
00252 }
00253 
00254 Solid::DevicePrivate::~DevicePrivate()
00255 {
00256     qDeleteAll(m_ifaces);
00257 }
00258 
00259 void Solid::DevicePrivate::_k_destroyed(QObject *object)
00260 {
00261     Q_UNUSED(object);
00262     setBackendObject(0);
00263 }
00264 
00265 void Solid::DevicePrivate::setBackendObject(Ifaces::Device *object)
00266 {
00267     m_backendObject = object;
00268 
00269     if (m_backendObject) {
00270         connect(m_backendObject, SIGNAL(destroyed(QObject *)),
00271                 this, SLOT(_k_destroyed(QObject *)));
00272     }
00273 
00274     if (!m_ifaces.isEmpty()) {
00275         foreach (DeviceInterface *iface, m_ifaces) {
00276             delete iface->d_ptr->backendObject();
00277             delete iface;
00278         }
00279 
00280         m_ifaces.clear();
00281 
00282         if (!ref.deref()) deleteLater();
00283     }
00284 }
00285 
00286 Solid::DeviceInterface *Solid::DevicePrivate::interface(const DeviceInterface::Type &type) const
00287 {
00288     return m_ifaces[type];
00289 }
00290 
00291 void Solid::DevicePrivate::setInterface(const DeviceInterface::Type &type, DeviceInterface *interface)
00292 {
00293     ref.ref();
00294     m_ifaces[type] = interface;
00295 }
00296 
00297 #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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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