not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / dataengines / hotplug / hotplugengine.cpp
blobafb6707e917b79035d06417ed2c3d0c8a6163223
1 /*
2 * Copyright (C) 2007 Menard Alexis <darktears31@gmail.com>
4 * This program is free software you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "hotplugengine.h"
22 #include <KConfigGroup>
23 #include <KDebug>
24 #include <KLocale>
25 #include <KStandardDirs>
26 #include <KDesktopFile>
27 #include <Plasma/DataContainer>
29 //solid specific includes
30 #include <solid/devicenotifier.h>
31 #include <solid/device.h>
32 #include <solid/deviceinterface.h>
33 #include <solid/predicate.h>
37 HotplugEngine::HotplugEngine(QObject* parent, const QVariantList& args)
38 : Plasma::DataEngine(parent, args)
40 Q_UNUSED(args)
41 files = KGlobal::dirs()->findAllResources("data", "solid/actions/");
43 foreach (const Solid::Device &dev, Solid::Device::allDevices()) {
44 onDeviceAdded(dev.udi());
47 connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(const QString &)),
48 this, SLOT(onDeviceAdded(const QString &)));
49 connect(Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString &)),
50 this, SLOT(onDeviceRemoved(const QString &)));
53 HotplugEngine::~HotplugEngine()
58 void HotplugEngine::onDeviceAdded(const QString &udi)
60 bool new_device = false;
61 Solid::Device device(udi);
63 QStringList interestingDesktopFiles;
64 //search in all desktop configuration file if the device inserted is a correct device
65 foreach (const QString &path, files) {
66 KDesktopFile cfg(path);
67 QString string_predicate = cfg.desktopGroup().readEntry("X-KDE-Solid-Predicate");
68 //kDebug()<<string_predicate;
69 Solid::Predicate predicate = Solid::Predicate::fromString(string_predicate);
70 if (predicate.matches(device)) {
71 new_device=true;
72 interestingDesktopFiles<<KUrl(path).fileName();
76 if (new_device) {
77 //kDebug()<<device.product();
78 //kDebug()<<device.vendor();
79 //kDebug()<< "number of interesting desktop file : " << interestingDesktopFiles.size();
80 setData(udi, "added", true);
81 setData(udi, "udi", device.udi());
83 if (device.vendor().length()==0) {
84 setData(udi, "text", device.product());
85 } else {
86 setData(udi, "text", device.vendor() + ' ' + device.product());
88 setData(udi, "icon", device.icon());
89 setData(udi, "predicateFiles", interestingDesktopFiles);
91 kDebug() << "add hardware solid : " << udi;
92 scheduleSourcesUpdated();
96 void HotplugEngine::onDeviceRemoved(const QString &udi)
98 removeSource(udi);
100 kDebug() << "remove hardware solid : " << udi;
102 scheduleSourcesUpdated();
105 #include "hotplugengine.moc"