connection-manager.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2013 Canonical Ltd.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00022 
00023 #ifndef SIGNON_CONNECTION_MANAGER_H
00024 #define SIGNON_CONNECTION_MANAGER_H
00025 
00026 #include <QDBusConnection>
00027 #include <QObject>
00028 
00029 class QDBusPendingCallWatcher;
00030 
00031 namespace SignOn {
00032 
00033 class ConnectionManager: public QObject
00034 {
00035     Q_OBJECT
00036 
00037     enum SocketConnectionStatus {
00038         SocketConnectionOk = 0,
00039         SocketConnectionUnavailable,
00040         SocketConnectionNoService
00041     };
00042 
00043     enum ServiceStatus {
00044         ServiceStatusUnknown = 0,
00045         ServiceActivating,
00046         ServiceActivated
00047     };
00048 
00049 public:
00050     ConnectionManager(QObject *parent = 0);
00051     ~ConnectionManager();
00052 
00053     static ConnectionManager *instance();
00054 
00055     bool hasConnection() const;
00056     const QDBusConnection &connection() const { return m_connection; }
00057     static const QDBusConnection &get() { return instance()->connection(); }
00058 
00059 public Q_SLOTS:
00060     void connect();
00061 
00062 Q_SIGNALS:
00063     void connected(const QDBusConnection &connection);
00064     void disconnected();
00065 
00066 private:
00067     SocketConnectionStatus setupSocketConnection();
00068     void init();
00069 
00070 private Q_SLOTS:
00071     void onActivationDone(QDBusPendingCallWatcher *watcher);
00072     void onDisconnected();
00073 
00074 private:
00075     QDBusConnection m_connection;
00076     ServiceStatus m_serviceStatus;
00077 };
00078 
00079 }
00080 
00081 #endif // SIGNON_CONNECTION_MANAGER_H