declarativeconnectionagent.h 3.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: lorn.potter@gmail.com
**
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
****************************************************************************/

17 18
#ifndef DECLARATIVECONNECTIONAGENT_H
#define DECLARATIVECONNECTIONAGENT_H
lpotter's avatar
lpotter committed
19

20
#include "declarativeconnectionagent.h"
21
#include "connectiond_interface.h"
lpotter's avatar
lpotter committed
22

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/*
 *This class is for accessing connman's UserAgent from multiple sources.
 *This is because currently, there can only be one UserAgent per system.
 *
 *It also makes use of a patch to connman, that allows the UserAgent
 *to get signaled when a connection is needed. This is the real reason
 *this daemon is needed. An InputRequest is short lived, and thus, may
 *not clash with other apps that need to use UserAgent.
 *
 *When you are trying to intercept a connection request, you need a long
 *living process to wait until such time. This will immediately clash if
 *a wlan needs user Input signal from connman, and the configure will never
 *get the proper signal.
 *
 *This qml type can be used as such:
 *
 *import com.jolla.connection 1.0
 *
 *    ConnectionAgent {
 *       id: userAgent
 *        onUserInputRequested: {
 *            console.log("        onUserInputRequested:")
 *        }
 *
 *       onConnectionRequest: {
 *          console.log("onConnectionRequest ")
 *            sendSuppress()
 *        }
 *        onErrorReported: {
 *            console.log("Got error from connman: " + error);
 *       }
 *   }
 *
 **/

class DeclarativeConnectionAgent : public QObject
lpotter's avatar
lpotter committed
59 60
{
    Q_OBJECT
61

62
    Q_DISABLE_COPY(DeclarativeConnectionAgent)
63

lpotter's avatar
lpotter committed
64
public:
65 66
    explicit DeclarativeConnectionAgent(QObject *parent = 0);
    ~DeclarativeConnectionAgent();
lpotter's avatar
lpotter committed
67 68 69 70

public slots:
    void sendUserReply(const QVariantMap &input);
    void sendConnectReply(const QString &replyMessage, int timeout = 120);
71
    void connectToType(const QString &type);
72
    void startTethering(const QString &type);
73
    void stopTethering(bool keepPowered = false);
lpotter's avatar
lpotter committed
74 75 76 77

signals:
    void userInputRequested(const QString &servicePath, const QVariantMap &fields);
    void userInputCanceled();
78
    void errorReported(const QString &servicePath, const QString &error);
lpotter's avatar
lpotter committed
79
    void connectionRequest();
80
    void configurationNeeded(const QString &type);
81
    void connectionState(const QString &state, const QString &type);
82
    void browserRequested(const QString &url);
83
    void tetheringFinished(bool);
lpotter's avatar
lpotter committed
84 85

private:
86
    bool checkValidness();
lpotter's avatar
lpotter committed
87 88 89 90 91 92
    com::jolla::Connectiond *connManagerInterface;
    QDBusServiceWatcher *connectiondWatcher;

private slots:
    void onUserInputRequested(const QString &service, const QVariantMap &fields);

93 94
    void connectToConnectiond();
    void connectiondUnregistered();
lpotter's avatar
lpotter committed
95 96
};

97
#endif
lpotter's avatar
lpotter committed
98