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

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

Skip menu "kdelibs"
  • 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
Generated for kdelibs by doxygen 1.7.5
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