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

Solid

device.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 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 Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) version 3, or any
00008     later version accepted by the membership of KDE e.V. (or its
00009     successor approved by the membership of KDE e.V.), which shall
00010     act as a proxy defined in Section 6 of version 3 of the license.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "device.h"
00022 #include "device_p.h"
00023 #include "devicenotifier.h"
00024 #include "devicemanager_p.h"
00025 
00026 #include "deviceinterface_p.h"
00027 #include "soliddefs_p.h"
00028 
00029 #include <solid/ifaces/device.h>
00030 
00031 #include <solid/genericinterface.h>
00032 #include <solid/ifaces/genericinterface.h>
00033 #include <solid/processor.h>
00034 #include <solid/ifaces/processor.h>
00035 #include <solid/block.h>
00036 #include <solid/ifaces/block.h>
00037 #include <solid/storageaccess.h>
00038 #include <solid/ifaces/storageaccess.h>
00039 #include <solid/storagedrive.h>
00040 #include <solid/ifaces/storagedrive.h>
00041 #include <solid/opticaldrive.h>
00042 #include <solid/ifaces/opticaldrive.h>
00043 #include <solid/storagevolume.h>
00044 #include <solid/ifaces/storagevolume.h>
00045 #include <solid/opticaldisc.h>
00046 #include <solid/ifaces/opticaldisc.h>
00047 #include <solid/camera.h>
00048 #include <solid/ifaces/camera.h>
00049 #include <solid/portablemediaplayer.h>
00050 #include <solid/ifaces/portablemediaplayer.h>
00051 #include <solid/networkinterface.h>
00052 #include <solid/ifaces/networkinterface.h>
00053 #include <solid/acadapter.h>
00054 #include <solid/ifaces/acadapter.h>
00055 #include <solid/battery.h>
00056 #include <solid/ifaces/battery.h>
00057 #include <solid/button.h>
00058 #include <solid/ifaces/button.h>
00059 #include <solid/audiointerface.h>
00060 #include <solid/ifaces/audiointerface.h>
00061 #include <solid/dvbinterface.h>
00062 #include <solid/ifaces/dvbinterface.h>
00063 #include <solid/video.h>
00064 #include <solid/ifaces/video.h>
00065 #include <solid/serialinterface.h>
00066 #include <solid/ifaces/serialinterface.h>
00067 #include <solid/smartcardreader.h>
00068 #include <solid/ifaces/smartcardreader.h>
00069 #include <solid/internetgateway.h>
00070 #include <solid/ifaces/internetgateway.h>
00071 
00072 
00073 Solid::Device::Device(const QString &udi)
00074 {
00075     DeviceManagerPrivate *manager
00076         = static_cast<DeviceManagerPrivate *>(Solid::DeviceNotifier::instance());
00077     d = manager->findRegisteredDevice(udi);
00078 }
00079 
00080 Solid::Device::Device(const Device &device)
00081     : d(device.d)
00082 {
00083 }
00084 
00085 Solid::Device::~Device()
00086 {
00087 }
00088 
00089 Solid::Device &Solid::Device::operator=(const Solid::Device &device)
00090 {
00091     d = device.d;
00092     return *this;
00093 }
00094 
00095 bool Solid::Device::isValid() const
00096 {
00097     return d->backendObject()!=0;
00098 }
00099 
00100 QString Solid::Device::udi() const
00101 {
00102     return d->udi();
00103 }
00104 
00105 QString Solid::Device::parentUdi() const
00106 {
00107     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), parentUdi());
00108 }
00109 
00110 Solid::Device Solid::Device::parent() const
00111 {
00112     QString udi = parentUdi();
00113 
00114     if (udi.isEmpty())
00115     {
00116         return Device();
00117     }
00118     else
00119     {
00120         return Device(udi);
00121     }
00122 }
00123 
00124 QString Solid::Device::vendor() const
00125 {
00126     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), vendor());
00127 }
00128 
00129 QString Solid::Device::product() const
00130 {
00131     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), product());
00132 }
00133 
00134 QString Solid::Device::icon() const
00135 {
00136     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), icon());
00137 }
00138 
00139 QStringList Solid::Device::emblems() const
00140 {
00141     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QStringList(), emblems());
00142 }
00143 
00144 QString Solid::Device::description() const
00145 {
00146     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), description());
00147 }
00148 
00149 bool Solid::Device::isDeviceInterface(const DeviceInterface::Type &type) const
00150 {
00151     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), false, queryDeviceInterface(type));
00152 }
00153 
00154 #define deviceinterface_cast(IfaceType, DevType, backendObject) \
00155     (qobject_cast<IfaceType *>(backendObject) ? new DevType(backendObject) : 0)
00156 
00157 Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type)
00158 {
00159     const Solid::DeviceInterface *interface = const_cast<const Device *>(this)->asDeviceInterface(type);
00160     return const_cast<Solid::DeviceInterface *>(interface);
00161 }
00162 
00163 const Solid::DeviceInterface *Solid::Device::asDeviceInterface(const DeviceInterface::Type &type) const
00164 {
00165     Ifaces::Device *device = qobject_cast<Ifaces::Device *>(d->backendObject());
00166 
00167     if (device!=0)
00168     {
00169         DeviceInterface *iface = d->interface(type);
00170 
00171         if (iface!=0) {
00172             return iface;
00173         }
00174 
00175         QObject *dev_iface = device->createDeviceInterface(type);
00176 
00177         if (dev_iface!=0)
00178         {
00179             switch (type)
00180             {
00181             case DeviceInterface::GenericInterface:
00182                 iface = deviceinterface_cast(Ifaces::GenericInterface, GenericInterface, dev_iface);
00183                 break;
00184             case DeviceInterface::Processor:
00185                 iface = deviceinterface_cast(Ifaces::Processor, Processor, dev_iface);
00186                 break;
00187             case DeviceInterface::Block:
00188                 iface = deviceinterface_cast(Ifaces::Block, Block, dev_iface);
00189                 break;
00190             case DeviceInterface::StorageAccess:
00191                 iface = deviceinterface_cast(Ifaces::StorageAccess, StorageAccess, dev_iface);
00192                 break;
00193             case DeviceInterface::StorageDrive:
00194                 iface = deviceinterface_cast(Ifaces::StorageDrive, StorageDrive, dev_iface);
00195                 break;
00196             case DeviceInterface::OpticalDrive:
00197                 iface = deviceinterface_cast(Ifaces::OpticalDrive, OpticalDrive, dev_iface);
00198                 break;
00199             case DeviceInterface::StorageVolume:
00200                 iface = deviceinterface_cast(Ifaces::StorageVolume, StorageVolume, dev_iface);
00201                 break;
00202             case DeviceInterface::OpticalDisc:
00203                 iface = deviceinterface_cast(Ifaces::OpticalDisc, OpticalDisc, dev_iface);
00204                 break;
00205             case DeviceInterface::Camera:
00206                 iface = deviceinterface_cast(Ifaces::Camera, Camera, dev_iface);
00207                 break;
00208             case DeviceInterface::PortableMediaPlayer:
00209                 iface = deviceinterface_cast(Ifaces::PortableMediaPlayer, PortableMediaPlayer, dev_iface);
00210                 break;
00211             case DeviceInterface::NetworkInterface:
00212                 iface = deviceinterface_cast(Ifaces::NetworkInterface, NetworkInterface, dev_iface);
00213                 break;
00214             case DeviceInterface::AcAdapter:
00215                 iface = deviceinterface_cast(Ifaces::AcAdapter, AcAdapter, dev_iface);
00216                 break;
00217             case DeviceInterface::Battery:
00218                 iface = deviceinterface_cast(Ifaces::Battery, Battery, dev_iface);
00219                 break;
00220             case DeviceInterface::Button:
00221                 iface = deviceinterface_cast(Ifaces::Button, Button, dev_iface);
00222                 break;
00223             case DeviceInterface::AudioInterface:
00224                 iface = deviceinterface_cast(Ifaces::AudioInterface, AudioInterface, dev_iface);
00225                 break;
00226             case DeviceInterface::DvbInterface:
00227                 iface = deviceinterface_cast(Ifaces::DvbInterface, DvbInterface, dev_iface);
00228                 break;
00229             case DeviceInterface::Video:
00230                 iface = deviceinterface_cast(Ifaces::Video, Video, dev_iface);
00231                 break;
00232             case DeviceInterface::SerialInterface:
00233                 iface = deviceinterface_cast(Ifaces::SerialInterface, SerialInterface, dev_iface);
00234                 break;
00235             case DeviceInterface::SmartCardReader:
00236                 iface = deviceinterface_cast(Ifaces::SmartCardReader, SmartCardReader, dev_iface);
00237                 break;
00238             case DeviceInterface::InternetGateway:
00239                 iface = deviceinterface_cast(Ifaces::InternetGateway, InternetGateway, dev_iface);
00240             case DeviceInterface::Unknown:
00241             case DeviceInterface::Last:
00242                 break;
00243             }
00244         }
00245 
00246         if (iface!=0)
00247         {
00248             // Lie on the constness since we're simply doing caching here
00249             const_cast<Device *>(this)->d->setInterface(type, iface);
00250             iface->d_ptr->setDevicePrivate(d.data());
00251         }
00252 
00253         return iface;
00254     }
00255     else
00256     {
00257         return 0;
00258     }
00259 }
00260 
00261 
00263 
00264 
00265 Solid::DevicePrivate::DevicePrivate(const QString &udi)
00266     : QObject(), QSharedData(), m_udi(udi)
00267 {
00268 }
00269 
00270 Solid::DevicePrivate::~DevicePrivate()
00271 {
00272     foreach (DeviceInterface *iface, m_ifaces) {
00273         delete iface->d_ptr->backendObject();
00274     }
00275     setBackendObject(0);
00276 }
00277 
00278 void Solid::DevicePrivate::_k_destroyed(QObject *object)
00279 {
00280     Q_UNUSED(object);
00281     setBackendObject(0);
00282 }
00283 
00284 void Solid::DevicePrivate::setBackendObject(Ifaces::Device *object)
00285 {
00286 
00287     if (m_backendObject) {
00288         m_backendObject.data()->disconnect(this);
00289     }
00290 
00291     delete m_backendObject.data();
00292     m_backendObject = object;
00293 
00294     if (object) {
00295         connect(object, SIGNAL(destroyed(QObject *)),
00296                 this, SLOT(_k_destroyed(QObject *)));
00297     }
00298 
00299     if (!m_ifaces.isEmpty()) {
00300         foreach (DeviceInterface *iface, m_ifaces) {
00301             delete iface;
00302         }
00303 
00304         m_ifaces.clear();
00305         if (!ref.deref()) deleteLater();
00306     }
00307 }
00308 
00309 Solid::DeviceInterface *Solid::DevicePrivate::interface(const DeviceInterface::Type &type) const
00310 {
00311     return m_ifaces[type];
00312 }
00313 
00314 void Solid::DevicePrivate::setInterface(const DeviceInterface::Type &type, DeviceInterface *interface)
00315 {
00316     if(m_ifaces.isEmpty())
00317         ref.ref();
00318     m_ifaces[type] = interface;
00319 }
00320 
00321 #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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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