1 /*
2  * Copyright (C) 2014 Nicolas Bonnefon and other contributors
3  *
4  * This file is part of glogg.
5  *
6  * glogg is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * glogg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef DBUSEXTERNALCOM_H
21 #define DBUSEXTERNALCOM_H
22 
23 #include "externalcom.h"
24 
25 #include <memory>
26 #include <QObject>
27 #include <QtDBus/QtDBus>
28 
29 // An implementation of ExternalInstance using D-Bus via Qt
30 class DBusExternalInstance : public ExternalInstance {
31   public:
32     DBusExternalInstance();
~DBusExternalInstance()33     ~DBusExternalInstance() {}
34 
35     virtual void loadFile( const QString& file_name ) const;
36     virtual uint32_t getVersion() const;
37 
38   private:
39     std::shared_ptr<QDBusInterface> dbusInterface_;
40 };
41 
42 class DBusInterfaceExternalCommunicator : public QObject
43 {
44   Q_OBJECT
45 
46   public:
DBusInterfaceExternalCommunicator()47     DBusInterfaceExternalCommunicator() : QObject() {}
~DBusInterfaceExternalCommunicator()48     ~DBusInterfaceExternalCommunicator() {}
49 
50   public slots:
51     void loadFile( const QString& file_name );
52     qint32 version() const;
53 
54   signals:
55     void signalLoadFile( const QString& file_name );
56 };
57 
58 // An implementation of ExternalCommunicator using D-Bus via Qt
59 class DBusExternalCommunicator : public ExternalCommunicator
60 {
61   Q_OBJECT
62 
63   public:
64     // Constructor: initialise the D-Bus connection,
65     // can throw if D-Bus is not available
66     DBusExternalCommunicator();
~DBusExternalCommunicator()67     ~DBusExternalCommunicator() {}
68 
69     virtual void startListening();
70 
71     virtual ExternalInstance* otherInstance() const;
72 
73   public slots:
74     qint32 version() const;
75 
76   private:
77     std::shared_ptr<DBusInterfaceExternalCommunicator> dbus_iface_object_;
78 };
79 
80 #endif
81