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

Engines

soliddeviceengine.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 Christopher Blauvelt <cblauvelt@gmail.com>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program 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
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 #include "soliddeviceengine.h"
00020 
00021 #include <config-workspace.h>
00022 
00023 #include <KDebug>
00024 #include <KLocale>
00025 
00026 #include "plasma/datacontainer.h"
00027 
00028 // The pattern here is:
00029 //  FreeBSD: param + mount
00030 //  Linux: stat + vfs
00031 #ifdef HAVE_SYS_PARAM_H
00032 #include <sys/param.h>
00033 #endif
00034 
00035 #ifdef HAVE_SYS_MOUNT_H
00036 #include <sys/mount.h>
00037 #endif
00038 
00039 #include <sys/stat.h>
00040 #ifdef HAVE_SYS_STATFS_H
00041 #include <sys/statfs.h>
00042 #endif
00043 #ifdef HAVE_SYS_STATVFS_H
00044 #include <sys/statvfs.h>
00045 #endif
00046 
00047 #ifdef HAVE_SYS_VFS_H
00048 #include <sys/vfs.h>
00049 #endif
00050 
00051 SolidDeviceEngine::SolidDeviceEngine(QObject* parent, const QVariantList& args)
00052         : Plasma::DataEngine(parent, args),
00053           temperature(0),
00054           notifier(0)
00055 {
00056     Q_UNUSED(args)
00057     signalmanager = new DeviceSignalMapManager(this);
00058 
00059     listenForNewDevices();
00060     temperature = new HddTemp();
00061     setMinimumPollingInterval(1000);
00062     connect(this, SIGNAL(sourceRemoved(const QString&)),
00063             this, SLOT(sourceRemoved(const QString&)));
00064 }
00065 
00066 SolidDeviceEngine::~SolidDeviceEngine()
00067 {
00068     delete signalmanager;
00069     delete temperature;
00070 }
00071 
00072 void SolidDeviceEngine::listenForNewDevices()
00073 {
00074     if(notifier) {
00075         return;
00076     }
00077     //detect when new devices are added
00078     notifier = Solid::DeviceNotifier::instance();
00079     connect(notifier, SIGNAL(deviceAdded(const QString&)),
00080             this, SLOT(deviceAdded(const QString&)));
00081     connect(notifier, SIGNAL(deviceRemoved(const QString&)),
00082             this, SLOT(deviceRemoved(const QString&)));
00083 }
00084 
00085 bool SolidDeviceEngine::sourceRequestEvent(const QString &name)
00086 {
00087 
00088     //create a predicate to check for validity
00089     Solid::Predicate predicate = Solid::Predicate::fromString(name);
00090     Solid::Device device(name);
00091     if(predicate.isValid()  && !predicatemap.contains(name)) {
00092         foreach (const Solid::Device &device, Solid::Device::listFromQuery(predicate)) {
00093             predicatemap[name] << device.udi();
00094         }
00095         setData(name, predicatemap[name]);
00096         return true;
00097     } else if (device.isValid()) {
00098         if (devicemap.contains(name) ) {
00099             return true;
00100         } else {
00101             devicemap[name] = device;
00102             return populateDeviceData(name);
00103         }
00104     }
00105 
00106     kDebug() << "Source is not a predicate or a device.";
00107     return false;
00108 }
00109 
00110 void SolidDeviceEngine::sourceRemoved(const QString &source)
00111 {
00112     devicemap.remove(source);
00113     predicatemap.remove(source);
00114 }
00115 
00116 bool SolidDeviceEngine::populateDeviceData(const QString &name)
00117 {
00118     Solid::Device device = devicemap.value(name);
00119     if (!device.isValid()) {
00120         return false;
00121     }
00122 
00123     QStringList devicetypes;
00124     setData(name, I18N_NOOP("Parent UDI"), device.parentUdi());
00125     setData(name, I18N_NOOP("Vendor"), device.vendor());
00126     setData(name, I18N_NOOP("Product"), device.product());
00127     setData(name, I18N_NOOP("Icon"), device.icon());
00128 
00129     if (device.is<Solid::Processor>()) {
00130         Solid::Processor *processor = device.as<Solid::Processor>();
00131         if (processor == 0) {
00132             return false;
00133         }
00134 
00135         devicetypes << I18N_NOOP("Processor");
00136         setData(name, I18N_NOOP("Number"), processor->number());
00137         setData(name, I18N_NOOP("Max Speed"), processor->maxSpeed());
00138         setData(name, I18N_NOOP("Can Change Frequency"), processor->canChangeFrequency());
00139     }
00140     if (device.is<Solid::Block>()) {
00141         Solid::Block *block = device.as<Solid::Block>();
00142         if (block == 0) {
00143             return false;
00144         }
00145 
00146         devicetypes << I18N_NOOP("Block");
00147         setData(name, I18N_NOOP("Major"), block->deviceMajor());
00148         setData(name, I18N_NOOP("Minor"), block->deviceMajor());
00149         setData(name, I18N_NOOP("Device"), block->device());
00150     }
00151     if (device.is<Solid::StorageAccess>()) {
00152         Solid::StorageAccess *storageaccess = device.as<Solid::StorageAccess>();
00153         if (storageaccess == 0) return false;
00154 
00155         devicetypes << I18N_NOOP("Storage Access");
00156         setData(name, I18N_NOOP("Accessible"), storageaccess->isAccessible());
00157         setData(name, I18N_NOOP("File Path"), storageaccess->filePath());
00158         QVariant freeDiskVar;
00159         qlonglong freeDisk = freeDiskSpace(storageaccess->filePath());
00160         if ( freeDisk != -1 ) {
00161             freeDiskVar.setValue( freeDisk );
00162         }
00163         setData(name, I18N_NOOP("Free Space"), freeDiskVar );
00164 
00165         signalmanager->mapDevice(storageaccess, device.udi());
00166     }
00167     if (device.is<Solid::StorageDrive>()) {
00168         Solid::StorageDrive *storagedrive = device.as<Solid::StorageDrive>();
00169         if (storagedrive == 0) {
00170             return false;
00171         }
00172 
00173         devicetypes << I18N_NOOP("Storage Drive");
00174 
00175         QStringList bus;
00176         bus << I18N_NOOP("Ide") << I18N_NOOP("Usb") << I18N_NOOP("Ieee1394") << I18N_NOOP("Scsi") << I18N_NOOP("Sata") << I18N_NOOP("Platform");
00177         QStringList drivetype;
00178         drivetype << I18N_NOOP("Hard Disk") <<  I18N_NOOP("Cdrom Drive") <<  I18N_NOOP("Floppy") <<  I18N_NOOP("Tape") <<  I18N_NOOP("Compact Flash") <<  I18N_NOOP("Memory Stick") <<  I18N_NOOP("Smart Media") <<  I18N_NOOP("SdMmc") <<  I18N_NOOP("Xd");
00179 
00180         setData(name, I18N_NOOP("Bus"), bus.at((int)storagedrive->bus()));
00181         setData(name, I18N_NOOP("Drive Type"), drivetype.at((int)storagedrive->driveType()));
00182         setData(name, I18N_NOOP("Removable"), storagedrive->isRemovable());
00183         setData(name, I18N_NOOP("Hotpluggable"), storagedrive->isHotpluggable());
00184 
00185         updateHardDiskTemperature(name);
00186     }
00187     if (device.is<Solid::OpticalDrive>()) {
00188         Solid::OpticalDrive *opticaldrive = device.as<Solid::OpticalDrive>();
00189         if (opticaldrive == 0) {
00190             return false;
00191         }
00192 
00193         devicetypes << I18N_NOOP("Optical Drive");
00194 
00195         QStringList supportedtypes;
00196         Solid::OpticalDrive::MediumTypes mediatypes = opticaldrive->supportedMedia();
00197         if (mediatypes & Solid::OpticalDrive::Cdr) {
00198             supportedtypes << I18N_NOOP("Cdr");
00199         }
00200         if (mediatypes & Solid::OpticalDrive::Cdrw) {
00201             supportedtypes << I18N_NOOP("Cdrw");
00202         }
00203         if (mediatypes & Solid::OpticalDrive::Dvd) {
00204             supportedtypes << I18N_NOOP("Dvd");
00205         }
00206         if (mediatypes & Solid::OpticalDrive::Dvdr) {
00207             supportedtypes << I18N_NOOP("Dvdr");
00208         }
00209         if (mediatypes & Solid::OpticalDrive::Dvdrw) {
00210             supportedtypes << I18N_NOOP("Dvdrw");
00211         }
00212         if (mediatypes & Solid::OpticalDrive::Dvdram) {
00213             supportedtypes << I18N_NOOP("Dvdram");
00214         }
00215         if (mediatypes & Solid::OpticalDrive::Dvdplusr) {
00216             supportedtypes << I18N_NOOP("Dvdplusr");
00217         }
00218         if (mediatypes & Solid::OpticalDrive::Dvdplusrw) {
00219             supportedtypes << I18N_NOOP("Dvdplusrw");
00220         }
00221         if (mediatypes & Solid::OpticalDrive::Dvdplusdl) {
00222             supportedtypes << I18N_NOOP("Dvdplusdl");
00223         }
00224         if (mediatypes & Solid::OpticalDrive::Dvdplusdlrw) {
00225             supportedtypes << I18N_NOOP("Dvdplusdlrw");
00226         }
00227         if (mediatypes & Solid::OpticalDrive::Bd) {
00228             supportedtypes << I18N_NOOP("Bd");
00229         }
00230         if (mediatypes & Solid::OpticalDrive::Bdr) {
00231             supportedtypes << I18N_NOOP("Bdr");
00232         }
00233         if (mediatypes & Solid::OpticalDrive::Bdre) {
00234             supportedtypes << I18N_NOOP("Bdre");
00235         }
00236         if (mediatypes & Solid::OpticalDrive::HdDvd) {
00237             supportedtypes << I18N_NOOP("HdDvd");
00238         }
00239         if (mediatypes & Solid::OpticalDrive::HdDvdr) {
00240             supportedtypes << I18N_NOOP("HdDvdr");
00241         }
00242         if (mediatypes & Solid::OpticalDrive::HdDvdrw) {
00243             supportedtypes << I18N_NOOP("HdDvdrw");
00244         }
00245         setData(name, I18N_NOOP("Supported Media"), supportedtypes);
00246 
00247         setData(name, I18N_NOOP("Read Speed"), opticaldrive->readSpeed());
00248         setData(name, I18N_NOOP("Write Speed"), opticaldrive->writeSpeed());
00249 
00250         //the following method return QList<int> so we need to convert it to QList<QVariant>
00251         QList<int> writespeeds = opticaldrive->writeSpeeds();
00252         QList<QVariant> variantlist = QList<QVariant>();
00253         foreach(int num, writespeeds) {
00254             variantlist << QVariant(num);
00255         }
00256         setData(name, I18N_NOOP("Write Speeds"), variantlist);
00257 
00258     }
00259     if (device.is<Solid::StorageVolume>()) {
00260         Solid::StorageVolume *storagevolume = device.as<Solid::StorageVolume>();
00261         if (storagevolume == 0) {
00262             return false;
00263         }
00264 
00265         devicetypes << I18N_NOOP("Storage Volume");
00266 
00267         QStringList usagetypes;
00268         usagetypes << I18N_NOOP("File System") << I18N_NOOP("Partition Table") << I18N_NOOP("Raid") << I18N_NOOP("Other") << I18N_NOOP("Unused");
00269 
00270         setData(name, I18N_NOOP("Ignored"), storagevolume->isIgnored());
00271         setData(name, I18N_NOOP("Usage"), usagetypes.at((int)storagevolume->usage()));
00272         setData(name, I18N_NOOP("File System Type"), storagevolume->fsType());
00273         setData(name, I18N_NOOP("Label"), storagevolume->label());
00274         setData(name, I18N_NOOP("Uuid"), storagevolume->uuid());
00275         setData(name, I18N_NOOP("Size"), storagevolume->size());
00276     }
00277     if (device.is<Solid::OpticalDisc>()) {
00278         Solid::OpticalDisc *opticaldisc = device.as<Solid::OpticalDisc>();
00279         if (opticaldisc == 0) {
00280             return false;
00281         }
00282 
00283         devicetypes << I18N_NOOP("OpticalDisc");
00284 
00285         //get the content types
00286         QStringList contenttypelist;
00287         Solid::OpticalDisc::ContentTypes contenttypes = opticaldisc->availableContent();
00288         if (contenttypes & Solid::OpticalDisc::Audio) {
00289             contenttypelist << I18N_NOOP("Audio");
00290         }
00291         if (contenttypes & Solid::OpticalDisc::Audio) {
00292             contenttypelist << I18N_NOOP("Data");
00293         }
00294         if (contenttypes & Solid::OpticalDisc::Audio) {
00295             contenttypelist << I18N_NOOP("Video Cd");
00296         }
00297         if (contenttypes & Solid::OpticalDisc::Audio) {
00298             contenttypelist << I18N_NOOP("Super Video Cd");
00299         }
00300         if (contenttypes & Solid::OpticalDisc::Audio) {
00301             contenttypelist << I18N_NOOP("Video Dvd");
00302         }
00303         setData(name, I18N_NOOP("Available Content"), contenttypelist);
00304 
00305         QStringList disctypes;
00306         disctypes << I18N_NOOP("Unknown Disc Type") << I18N_NOOP("CD Rom") << I18N_NOOP("CD Recordable")
00307                 << I18N_NOOP("CD Rewritable") << I18N_NOOP("DVD Rom") << I18N_NOOP("DVD Ram")
00308                 << I18N_NOOP("DVD Recordable") << I18N_NOOP("DVD Rewritable") << I18N_NOOP("DVD Plus Recordable")
00309                 << I18N_NOOP("DVD Plus Rewritable") << I18N_NOOP("DVD Plus Recordable Duallayer")
00310                 << I18N_NOOP("DVD Plus Rewritable Duallayer") << I18N_NOOP("Blu Ray Rom") << I18N_NOOP("Blu Ray Recordable")
00311                 << I18N_NOOP("Blu Ray Rewritable") << I18N_NOOP("HD DVD Rom") <<  I18N_NOOP("HD DVD Recordable")
00312                 << I18N_NOOP("HD DVD Rewritable");
00313         //+1 because the enum starts at -1
00314         setData(name, I18N_NOOP("Disc Type"), disctypes.at((int)opticaldisc->discType() + 1));
00315         setData(name, I18N_NOOP("Appendable"), opticaldisc->isAppendable());
00316         setData(name, I18N_NOOP("Blank"), opticaldisc->isBlank());
00317         setData(name, I18N_NOOP("Rewritable"), opticaldisc->isRewritable());
00318         setData(name, I18N_NOOP("Capacity"), opticaldisc->capacity());
00319     }
00320     if (device.is<Solid::Camera>()) {
00321         Solid::Camera *camera = device.as<Solid::Camera>();
00322         if (camera == 0) {
00323             return false;
00324         }
00325 
00326         devicetypes << I18N_NOOP("Camera");
00327 
00328         setData(name, I18N_NOOP("Supported Protocols"), camera->supportedProtocols());
00329         setData(name, I18N_NOOP("Supported Drivers"), camera->supportedDrivers());
00330     }
00331     if (device.is<Solid::PortableMediaPlayer>()) {
00332         Solid::PortableMediaPlayer *mediaplayer = device.as<Solid::PortableMediaPlayer>();
00333         if (mediaplayer == 0) {
00334             return false;
00335         }
00336 
00337         devicetypes << I18N_NOOP("Portable Media Player");
00338 
00339         setData(name, I18N_NOOP("Supported Protocols"), mediaplayer->supportedProtocols());
00340         setData(name, I18N_NOOP("Supported Drivers"), mediaplayer->supportedDrivers());
00341     }
00342     if (device.is<Solid::NetworkInterface>()) {
00343         Solid::NetworkInterface *networkinterface = device.as<Solid::NetworkInterface>();
00344         if (networkinterface == 0) {
00345             return false;
00346         }
00347 
00348         devicetypes << I18N_NOOP("Network Interface");
00349 
00350         setData(name, I18N_NOOP("Interface Name"), networkinterface->ifaceName());
00351         setData(name, I18N_NOOP("Wireless"), networkinterface->isWireless());
00352         setData(name, I18N_NOOP("Hardware Address"), networkinterface->hwAddress());
00353         setData(name, I18N_NOOP("Mac Address"), networkinterface->macAddress());
00354     }
00355     if (device.is<Solid::AcAdapter>()) {
00356         Solid::AcAdapter *ac = device.as<Solid::AcAdapter>();
00357         if (ac == 0) {
00358             return false;
00359         }
00360 
00361         devicetypes << I18N_NOOP("AD Adapter");
00362 
00363         setData(name, I18N_NOOP("Plugged In"), ac->isPlugged());
00364         signalmanager->mapDevice(ac, device.udi());
00365     }
00366     if (device.is<Solid::Battery>()) {
00367         Solid::Battery *battery = device.as<Solid::Battery>();
00368         if (battery == 0) {
00369             return false;
00370         }
00371 
00372         devicetypes << I18N_NOOP("Battery");
00373 
00374         QStringList batterytype;
00375         batterytype << I18N_NOOP("Unknown Battery") << I18N_NOOP("PDA Battery") << I18N_NOOP("UPS Battery")
00376                 << I18N_NOOP("Primary Battery") << I18N_NOOP("Mouse Battery") << I18N_NOOP("Keyboard Battery")
00377                 << I18N_NOOP("Keyboard Mouse Battery") << I18N_NOOP("Camera Battery");
00378 
00379         QStringList chargestate;
00380         chargestate << I18N_NOOP("Fully Charged") << I18N_NOOP("Charging") << I18N_NOOP("Discharging");
00381 
00382         setData(name, I18N_NOOP("Plugged In"), battery->isPlugged());
00383         setData(name, I18N_NOOP("Type"), batterytype.at((int)battery->type()));
00384         setData(name, I18N_NOOP("Charge Percent"), battery->chargePercent());
00385         setData(name, I18N_NOOP("Rechargeable"), battery->isRechargeable());
00386         setData(name, I18N_NOOP("Charge State"), chargestate.at((int)battery->chargeState()));
00387 
00388         signalmanager->mapDevice(battery, device.udi());
00389     }
00390     if (device.is<Solid::Button>()) {
00391         Solid::Button *button = device.as<Solid::Button>();
00392         if (button == 0) {
00393             return false;
00394         }
00395 
00396         devicetypes << I18N_NOOP("Button");
00397 
00398         QStringList buttontype;
00399         buttontype << I18N_NOOP("Lid Button") << I18N_NOOP("Power Button") << I18N_NOOP("Sleep Button")
00400                 << I18N_NOOP("Unknown Button Type");
00401 
00402         setData(name, I18N_NOOP("Type"), buttontype.at((int)button->type()));
00403         setData(name, I18N_NOOP("Has State"), button->hasState());
00404         setData(name, I18N_NOOP("State Value"), button->stateValue());
00405         setData(name, I18N_NOOP("Pressed"), false);  //this is an extra value that is tracked by the button signals
00406 
00407         signalmanager->mapDevice(button, device.udi());
00408     }
00409     if (device.is<Solid::AudioInterface>()) {
00410         Solid::AudioInterface *audiointerface = device.as<Solid::AudioInterface>();
00411         if (audiointerface == 0) {
00412             return false;
00413         }
00414 
00415         devicetypes << I18N_NOOP("Audio Interface");
00416 
00417         QStringList audiodriver;
00418         audiodriver << I18N_NOOP("ALSA") << I18N_NOOP("Open Sound System") << I18N_NOOP("Unknown Audio Driver");
00419 
00420         setData(name, I18N_NOOP("Driver"), audiodriver.at((int)audiointerface->driver()));
00421         setData(name, I18N_NOOP("Driver Handle"), audiointerface->driverHandle());
00422         setData(name, I18N_NOOP("Name"), audiointerface->name());
00423 
00424         //get AudioInterfaceTypes
00425         QStringList audiointerfacetypes;
00426         Solid::AudioInterface::AudioInterfaceTypes devicetypes = audiointerface->deviceType();
00427         if (devicetypes & Solid::AudioInterface::UnknownAudioInterfaceType) {
00428             audiointerfacetypes << I18N_NOOP("Unknown Audio Interface Type");
00429         }
00430         if (devicetypes & Solid::AudioInterface::AudioControl) {
00431             audiointerfacetypes << I18N_NOOP("Audio Control");
00432         }
00433         if (devicetypes & Solid::AudioInterface::AudioInput) {
00434             audiointerfacetypes << I18N_NOOP("Audio Input");
00435         }
00436         if (devicetypes & Solid::AudioInterface::AudioOutput) {
00437             audiointerfacetypes << I18N_NOOP("Audio Output");
00438         }
00439         setData(name, I18N_NOOP("Audio Device Type"), audiointerfacetypes);
00440 
00441         //get SoundCardTypes
00442         QStringList soundcardtype;
00443         soundcardtype << I18N_NOOP("Internal Soundcard") << I18N_NOOP("USB Soundcard") << I18N_NOOP("Firewire Soundcard")
00444                 << I18N_NOOP("Headset") << I18N_NOOP("Modem");
00445         setData(name, I18N_NOOP("Soundcard Type"), soundcardtype.at((int)audiointerface->soundcardType()));
00446     }
00447     if (device.is<Solid::DvbInterface>()) {
00448         Solid::DvbInterface *dvbinterface = device.as<Solid::DvbInterface>();
00449         if (dvbinterface == 0) {
00450             return false;
00451         }
00452 
00453         devicetypes << I18N_NOOP("DVB Interface");
00454 
00455         setData(name, I18N_NOOP("Device"), dvbinterface->device());
00456         setData(name, I18N_NOOP("Device Adapter"), dvbinterface->deviceAdapter());
00457 
00458         //get devicetypes
00459         QStringList dvbdevicetypes;
00460         dvbdevicetypes << I18N_NOOP("DVB Unknown") << I18N_NOOP("DVB Audio") << I18N_NOOP("DVB Ca")
00461                 << I18N_NOOP("DVB Demux") << I18N_NOOP("DVB DVR") << I18N_NOOP("DVB Frontend")
00462                 << I18N_NOOP("DVB Net") << I18N_NOOP("DVB OSD") << I18N_NOOP("DVB Sec") << I18N_NOOP("DVB Video");
00463 
00464         setData(name, I18N_NOOP("DVB Device Type"), dvbdevicetypes.at((int)dvbinterface->deviceType()));
00465         setData(name, I18N_NOOP("Device Index"), dvbinterface->deviceIndex());
00466     }
00467     if (device.is<Solid::Video>()) {
00468         Solid::Video *video = device.as<Solid::Video>();
00469         if (video == 0) {
00470             return false;
00471         }
00472 
00473         devicetypes << I18N_NOOP("Video");
00474 
00475         setData(name, I18N_NOOP("Supported Protocols"), video->supportedProtocols());
00476         setData(name, I18N_NOOP("Supported Drivers"), video->supportedDrivers());
00477 
00478         QStringList handles;
00479         foreach (const QString &driver, video->supportedDrivers()) {
00480             handles << video->driverHandle(driver).toString();
00481         }
00482         setData(name, I18N_NOOP("Driver Handles"), handles);
00483     }
00484 
00485     setData(name, I18N_NOOP("Device Types"), devicetypes);
00486     return true;
00487 }
00488 
00489 void SolidDeviceEngine::deviceAdded(const QString& udi)
00490 {
00491     Solid::Device device(udi);
00492 
00493     foreach (const QString &query, predicatemap.keys()) {
00494         Solid::Predicate predicate = Solid::Predicate::fromString(query);
00495         if (predicate.matches(device)) {
00496             predicatemap[query] << udi;
00497             setData(query, predicatemap[query]);
00498         }
00499     }
00500 
00501     scheduleSourcesUpdated();
00502 }
00503 
00504 qlonglong SolidDeviceEngine::freeDiskSpace(const QString &mountPoint)
00505 {
00506     //determine the free space available on the device
00507     const QByteArray pathBa=mountPoint.toAscii();
00508     // path is only valid as long as pathBa exists
00509     const char *path=pathBa.constData();
00510 
00511 #ifdef HAVE_STATVFS
00512     struct statvfs fs_obj;
00513     if (statvfs(path,&fs_obj) < 0) {
00514         return -1;
00515     } else {
00516         return (qlonglong)fs_obj.f_bfree*(qlonglong)fs_obj.f_frsize;
00517     }
00518 #elif defined(HAVE_STATFS) && !defined(USE_SOLARIS)
00519     struct statfs fs_obj;
00520     if (statfs(path,&fs_obj) < 0){
00521         return -1;
00522     }
00523     else{
00524         return (qlonglong)fs_obj.f_bfree*(qlonglong)fs_obj.f_bsize;
00525     }
00526 #else
00527 #ifdef __GNUC__
00528 #warning "This system does not support statfs or statvfs - freeDiskSpace() will return -1"
00529 #endif
00530 #endif
00531     return -1;
00532 }
00533 
00534 bool SolidDeviceEngine::updateFreeSpace(const QString &udi)
00535 {
00536     Solid::Device device = devicemap.value(udi);
00537     if (!device.is<Solid::StorageAccess>()) {
00538         return false;
00539     }
00540 
00541     Solid::StorageAccess *storageaccess = device.as<Solid::StorageAccess>();
00542     if (storageaccess == 0) return false;
00543 
00544     QVariant freeSpaceVar;
00545     qlonglong freeSpace = freeDiskSpace(storageaccess->filePath());
00546     if ( freeSpace != -1 ) {
00547         freeSpaceVar.setValue( freeSpace );
00548     }
00549     setData(udi, I18N_NOOP("Free Space"), freeSpaceVar );
00550     return true;
00551 }
00552 
00553 bool SolidDeviceEngine::updateHardDiskTemperature(const QString &udi)
00554 {
00555     Solid::Device device = devicemap.value(udi);
00556     Solid::Block *block = device.as<Solid::Block>();
00557     if (block != 0 && temperature->sources().contains(block->device())) {
00558         setData(udi, I18N_NOOP("Temperature"), temperature->data(block->device(), HddTemp::Temperature));
00559         setData(udi, I18N_NOOP("Temperature Unit"), temperature->data(block->device(), HddTemp::Unit));
00560         return true;
00561     }
00562     return false;
00563 }
00564 
00565 bool SolidDeviceEngine::updateSourceEvent(const QString& source)
00566 {
00567     bool update1 = updateFreeSpace(source);
00568     bool update2 = updateHardDiskTemperature(source);
00569 
00570     return (update1 || update2);
00571 }
00572 
00573 void SolidDeviceEngine::deviceRemoved(const QString& udi)
00574 {
00575     foreach (const QString &query, predicatemap.keys()) {
00576         predicatemap[query].removeAll(udi);
00577         setData(query, predicatemap[query]);
00578     }
00579 
00580     devicemap.remove(udi);
00581     removeSource(udi);
00582     scheduleSourcesUpdated();
00583 }
00584 
00585 void SolidDeviceEngine::deviceChanged(const QString& udi, const QString &property, const QVariant &value)
00586 {
00587     setData(udi, property, value);
00588     scheduleSourcesUpdated();
00589 }
00590 
00591 #include "soliddeviceengine.moc"

Engines

Skip menu "Engines"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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