| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2012~2012 by CSSlayer * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify * |
| 5 |
* it under the terms of the GNU General Public License as published by * |
| 6 |
* the Free Software Foundation; either version 2 of the License, or * |
| 7 |
* (at your option) any later version. * |
| 8 |
* * |
| 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 * |
| 12 |
* GNU General Public License for more details. * |
| 13 |
* * |
| 14 |
* You should have received a copy of the GNU General Public License * |
| 15 |
* along with this program; if not, write to the * |
| 16 |
* Free Software Foundation, Inc., * |
| 17 |
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * |
| 18 |
***************************************************************************/ |
| 19 |
|
| 20 |
#ifndef FCITXQTCONNECTION_H |
| 21 |
#define FCITXQTCONNECTION_H |
| 22 |
|
| 23 |
#include "fcitxqtdbusaddons_export.h" |
| 24 |
|
| 25 |
#include <QtCore/QObject> |
| 26 |
|
| 27 |
class QDBusConnection; |
| 28 |
|
| 29 |
class FcitxQtConnectionPrivate; |
| 30 |
|
| 31 |
/** |
| 32 |
* dbus connection to fcitx |
| 33 |
**/ |
| 34 |
class FCITXQTDBUSADDONS_EXPORT FcitxQtConnection : public QObject { |
| 35 |
Q_OBJECT |
| 36 |
Q_PROPERTY(bool autoReconnect READ autoReconnect WRITE setAutoReconnect) |
| 37 |
Q_PROPERTY(bool connected READ isConnected) |
| 38 |
Q_PROPERTY(QDBusConnection *connection READ connection) |
| 39 |
Q_PROPERTY(QString serviceName READ serviceName) |
| 40 |
public: |
| 41 |
/** |
| 42 |
* create a new connection |
| 43 |
* |
| 44 |
* @param parent |
| 45 |
**/ |
| 46 |
explicit FcitxQtConnection(QObject *parent = 0); |
| 47 |
|
| 48 |
/** |
| 49 |
* destroy the connection |
| 50 |
**/ |
| 51 |
virtual ~FcitxQtConnection(); |
| 52 |
|
| 53 |
/** |
| 54 |
* the connection will not start to work until you call this function |
| 55 |
* you may want to connect to the signal before you call this function |
| 56 |
**/ |
| 57 |
void startConnection(); |
| 58 |
void endConnection(); |
| 59 |
/** |
| 60 |
* automatically reconnect if fcitx disappeared |
| 61 |
* |
| 62 |
* @param a ... |
| 63 |
* @return void |
| 64 |
**/ |
| 65 |
void setAutoReconnect(bool a); |
| 66 |
|
| 67 |
/** |
| 68 |
* check this connection is doing automatical reconnect or not |
| 69 |
* |
| 70 |
* default value is true |
| 71 |
**/ |
| 72 |
bool autoReconnect(); |
| 73 |
|
| 74 |
/** |
| 75 |
* return the current dbus connection to fcitx, notice, the object return |
| 76 |
* by this function might be deteled if fcitx disappear, or might return 0 |
| 77 |
* if fcitx is not running |
| 78 |
* |
| 79 |
* @return QDBusConnection* |
| 80 |
**/ |
| 81 |
QDBusConnection *connection(); |
| 82 |
/** |
| 83 |
* current fcitx dbus service name, can be used for create DBus proxy |
| 84 |
* |
| 85 |
* @return service name |
| 86 |
**/ |
| 87 |
const QString &serviceName(); |
| 88 |
/** |
| 89 |
* check its connected or not |
| 90 |
**/ |
| 91 |
bool isConnected(); |
| 92 |
|
| 93 |
Q_SIGNALS: |
| 94 |
/** |
| 95 |
* this signal will be emitted upon fcitx appears |
| 96 |
**/ |
| 97 |
void connected(); |
| 98 |
/** |
| 99 |
* this signal will be emitted upon fcitx disappears |
| 100 |
* |
| 101 |
* it will come with connected in pair |
| 102 |
**/ |
| 103 |
void disconnected(); |
| 104 |
|
| 105 |
private: |
| 106 |
FcitxQtConnectionPrivate *const d_ptr; |
| 107 |
Q_DECLARE_PRIVATE(FcitxQtConnection); |
| 108 |
}; |
| 109 |
|
| 110 |
#endif // FCITXCONNECTION_H |