1 /*
2     Copyright 2005 Kevin Ottens <ervin@kde.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) version 3, or any
8     later version accepted by the membership of KDE e.V. (or its
9     successor approved by the membership of KDE e.V.), which shall
10     act as a proxy defined in Section 6 of version 3 of the license.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "ifaces/device.h"
22 
23 #include <QDBusConnection>
24 #include <QDBusMessage>
25 
Device(QObject * parent)26 Solid::Ifaces::Device::Device(QObject *parent)
27     : QObject(parent)
28 {
29 
30 }
31 
~Device()32 Solid::Ifaces::Device::~Device()
33 {
34 
35 }
36 
parentUdi() const37 QString Solid::Ifaces::Device::parentUdi() const
38 {
39     return QString();
40 }
41 
registerAction(const QString & actionName,QObject * dest,const char * requestSlot,const char * doneSlot) const42 void Solid::Ifaces::Device::registerAction(const QString &actionName,
43                                            QObject *dest,
44                                            const char *requestSlot,
45                                            const char *doneSlot) const
46 {
47     QDBusConnection::sessionBus().connect(QString(), deviceDBusPath(),
48                                           "org.kde.Solid.Device", actionName+"Requested",
49                                           dest, requestSlot);
50 
51     QDBusConnection::sessionBus().connect(QString(), deviceDBusPath(),
52                                           "org.kde.Solid.Device", actionName+"Done",
53                                           dest, doneSlot);
54 }
55 
broadcastActionDone(const QString & actionName,int error,const QString & errorString) const56 void Solid::Ifaces::Device::broadcastActionDone(const QString &actionName,
57                                                 int error, const QString &errorString) const
58 {
59     QDBusMessage signal = QDBusMessage::createSignal(deviceDBusPath(), "org.kde.Solid.Device", actionName+"Done");
60     signal << error << errorString;
61 
62     QDBusConnection::sessionBus().send(signal);
63 }
64 
broadcastActionRequested(const QString & actionName) const65 void Solid::Ifaces::Device::broadcastActionRequested(const QString &actionName) const
66 {
67     QDBusMessage signal = QDBusMessage::createSignal(deviceDBusPath(), "org.kde.Solid.Device", actionName+"Requested");
68     QDBusConnection::sessionBus().send(signal);
69 }
70 
deviceDBusPath() const71 QString Solid::Ifaces::Device::deviceDBusPath() const
72 {
73     const QByteArray encodedUdi = udi().toUtf8().toPercentEncoding(QByteArray(), ".~", '_');
74     return QString("/org/kde/solid/Device_") + QString::fromLatin1(encodedUdi);
75 }
76 
77 #include "ifaces/moc_device.cpp"
78