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

Engines

hotplugengine.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 Menard Alexis <darktears31@gmail.com>
00003  *
00004  * This program is free software you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "hotplugengine.h"
00021 
00022 #include <KConfigGroup>
00023 #include <KDebug>
00024 #include <KLocale>
00025 #include <KStandardDirs>
00026 #include <KDesktopFile>
00027 #include <Plasma/DataContainer>
00028 
00029 //solid specific includes
00030 #include <solid/devicenotifier.h>
00031 #include <solid/device.h>
00032 #include <solid/deviceinterface.h>
00033 #include <solid/predicate.h>
00034 
00035 
00036 
00037 HotplugEngine::HotplugEngine(QObject* parent, const QVariantList& args)
00038     : Plasma::DataEngine(parent, args)
00039 {
00040     Q_UNUSED(args)
00041     files = KGlobal::dirs()->findAllResources("data", "solid/actions/");
00042 
00043     foreach (const Solid::Device &dev, Solid::Device::allDevices()) {
00044         onDeviceAdded(dev.udi());
00045     }
00046 
00047     connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(const QString &)),
00048             this, SLOT(onDeviceAdded(const QString &)));
00049     connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString &)),
00050             this, SLOT(onDeviceRemoved(const QString &)));
00051 }
00052 
00053 HotplugEngine::~HotplugEngine()
00054 {
00055 
00056 }
00057 
00058 void HotplugEngine::onDeviceAdded(const QString &udi)
00059 {
00060     bool new_device = false;
00061     Solid::Device device(udi);
00062 
00063     QStringList interestingDesktopFiles;
00064     //search in all desktop configuration file if the device inserted is a correct device
00065     foreach (const QString &path, files) {
00066         KDesktopFile cfg(path);
00067         QString string_predicate = cfg.desktopGroup().readEntry("X-KDE-Solid-Predicate");
00068         //kDebug()<<string_predicate;
00069         Solid::Predicate predicate = Solid::Predicate::fromString(string_predicate);
00070         if (predicate.matches(device)) {
00071             new_device=true;
00072             interestingDesktopFiles<<KUrl(path).fileName();
00073         }
00074     }
00075 
00076     if (new_device) {
00077         //kDebug()<<device.product();
00078         //kDebug()<<device.vendor();
00079         //kDebug()<< "number of interesting desktop file : " << interestingDesktopFiles.size();
00080         setData(udi, "added", true);
00081         setData(udi, "udi", device.udi());
00082 
00083         if (device.vendor().length()==0) {
00084             setData(udi, "text", device.product());
00085         } else {
00086             setData(udi, "text", device.vendor() + ' ' + device.product());
00087         }
00088         setData(udi, "icon", device.icon());
00089         setData(udi, "predicateFiles", interestingDesktopFiles);
00090 
00091         kDebug() << "add hardware solid : " << udi;
00092         scheduleSourcesUpdated();
00093     }
00094 }
00095 
00096 void HotplugEngine::onDeviceRemoved(const QString &udi)
00097 {
00098     removeSource(udi);
00099 
00100     kDebug() << "remove hardware solid : " << udi;
00101 
00102     scheduleSourcesUpdated();
00103 }
00104 
00105 #include "hotplugengine.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
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference 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