My Project
connection-manager.h
1/*
2 * This file is part of signon
3 *
4 * Copyright (C) 2013-2016 Canonical Ltd.
5 *
6 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * version 2.1 as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * 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, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef SIGNON_CONNECTION_MANAGER_H
24#define SIGNON_CONNECTION_MANAGER_H
25
26#include <QDBusConnection>
27#include <QObject>
28
29class QDBusPendingCallWatcher;
30
31namespace SignOn {
32
33class ConnectionManager: public QObject
34{
35 Q_OBJECT
36
37 enum SocketConnectionStatus {
38 SocketConnectionOk = 0,
39 SocketConnectionUnavailable,
40 SocketConnectionNoService
41 };
42
43 enum ServiceStatus {
44 ServiceStatusUnknown = 0,
45 ServiceActivating,
46 ServiceActivated
47 };
48
49public:
50 ConnectionManager(QObject *parent = 0);
52
53 static ConnectionManager *instance();
54
55 bool hasConnection() const;
56 const QDBusConnection &connection() const { return m_connection; }
57 static const QDBusConnection &get() { return instance()->connection(); }
58
59public Q_SLOTS:
60 void connect();
61
62Q_SIGNALS:
63 void connected(const QDBusConnection &connection);
64 void disconnected();
65
66private:
67 SocketConnectionStatus setupSocketConnection();
68 void init();
69
70private Q_SLOTS:
71 void onActivationDone(QDBusPendingCallWatcher *watcher);
72 void onDisconnected();
73
74private:
75 QDBusConnection m_connection;
76 ServiceStatus m_serviceStatus;
77};
78
79}
80
81#endif // SIGNON_CONNECTION_MANAGER_H