qconnectionagent.h 4.6 KB
Newer Older
lpotter's avatar
lpotter committed
1 2
/****************************************************************************
**
3
** Copyright (C) 2014-2017 Jolla Ltd
lpotter's avatar
lpotter committed
4 5 6
** Contact: lorn.potter@gmail.com
**
** GNU Lesser General Public License Usage
Lorn Potter's avatar
Lorn Potter committed
7
** This file may be used under the terms of the GNU Lesser
lpotter's avatar
lpotter committed
8 9 10 11 12 13 14 15
** 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.
**
****************************************************************************/

16 17
#ifndef QCONNECTIONAGENT_H
#define QCONNECTIONAGENT_H
lpotter's avatar
lpotter committed
18 19 20 21 22 23 24

#include <QObject>
#include <QMap>
#include <QStringList>
#include <QVariant>
#include <QDBusMessage>
#include <QDBusObjectPath>
25 26
#include <QQueue>
#include <QPair>
27
#include <QElapsedTimer>
28
#include <QVector>
lpotter's avatar
lpotter committed
29 30 31 32 33

class UserAgent;
class SessionAgent;

class NetworkManager;
34
class NetworkService;
35
class NetworkTechnology;
36
class WakeupWatcher;
37 38
class QTimer;

39
class QConnectionAgent : public QObject
lpotter's avatar
lpotter committed
40 41 42 43
{
    Q_OBJECT

public:
44
    explicit QConnectionAgent(QObject *parent = 0);
45
    ~QConnectionAgent();
46

47
    bool isValid() const;
lpotter's avatar
lpotter committed
48 49 50 51 52

Q_SIGNALS:

    void userInputRequested(const QString &servicePath, const QVariantMap &fields);
    void userInputCanceled();
53
    void errorReported(const QString &servicePath, const QString &error);
lpotter's avatar
lpotter committed
54
    void connectionRequest();
55
    void configurationNeeded(const QString &type);
56
    void connectionState(const QString &state, const QString &type);
57
    void connectNow(const QString &path);
58

59
    void requestBrowser(const QString &url);
60
    void tetheringFinished(bool);
61

lpotter's avatar
lpotter committed
62 63 64 65
public Q_SLOTS:

    void onUserInputRequested(const QString &servicePath, const QVariantMap &fields);
    void onUserInputCanceled();
66
    void onErrorReported(const QString &servicePath, const QString &error);
lpotter's avatar
lpotter committed
67 68 69 70 71 72

    void onConnectionRequest();

    void sendConnectReply(const QString &in0, int in1);
    void sendUserReply(const QVariantMap &input);

73
    void connectToType(const QString &type);
74

75
    void startTethering(const QString &type);
76
    void stopTethering(bool keepPowered = false);
77

lpotter's avatar
lpotter committed
78
private:
79 80 81 82

    class Service
    {
    public:
Pekka Vuorela's avatar
Pekka Vuorela committed
83 84
        QString path;
        NetworkService *service;
85

Pekka Vuorela's avatar
Pekka Vuorela committed
86 87 88
        bool operator==(const Service &other) const {
            return other.path == path;
        }
89 90 91 92 93
    };

    class ServiceList : public QVector<Service>
    {
    public:
Pekka Vuorela's avatar
Pekka Vuorela committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
        int indexOf(const QString &path, int from = 0) const {
            Service key;
            key.path = path;
            return QVector<Service>::indexOf(key, from);
        }

        bool contains(const QString &path) const {
            Service key;
            key.path = path;
            return QVector<Service>::indexOf(key) >= 0;
        }

        void remove(const QString &path) {
            Service key;
            key.path = path;
            int pos = QVector<Service>::indexOf(key);
            if (pos >= 0)
                QVector<Service>::remove(pos);
        }
113 114
    };

115 116
    void setup();
    void updateServices();
117 118 119 120 121
    bool isStateOnline(const QString &state);
    bool isBestService(NetworkService *service);
    QString findBestConnectableService();
    void removeAllTypes(const QString &type);

lpotter's avatar
lpotter committed
122
    UserAgent *ua;
123 124

    NetworkManager *netman;
125
    SessionAgent *sessionAgent;
126

lpotter's avatar
lpotter committed
127
    QString currentNetworkState;
128

129
    ServiceList orderedServicesList;
130 131

    QStringList techPreferenceList;
132
    bool isEthernet;
133
    bool connmanAvailable;
134

135
    NetworkTechnology *tetheringWifiTech;
136
    bool tetheringEnabled;
137
    bool flightModeSuppression;
138
    WakeupWatcher *mceWatch;
139
    uint scanTimeoutInterval;
140

141 142
    QTimer *scanTimer;
    QStringList knownTechnologies;
143
    bool delayedTethering;
144
    bool valid;
145

146 147 148
private slots:
    void onScanFinished();

149 150 151 152
    void serviceErrorChanged(const QString &error);
    void serviceStateChanged(const QString &state);
    void networkStateChanged(const QString &state);

153
    void connmanAvailabilityChanged(bool b);
154 155
    void servicesError(const QString &);
    void technologyPowerChanged(bool);
156
    void browserRequest(const QString &servicePath, const QString &url);
157 158 159
    void techChanged();

    void servicesListChanged(const QStringList &);
160 161
    void offlineModeChanged(bool);
    void flightModeDialogSuppressionTimeout();
162 163 164

    void displayStateChanged(const QString &);

165
    void serviceAutoconnectChanged(bool);
166
    void scanTimeout();
167 168
    void techTetheringChanged(bool b);
    void servicesChanged();
169 170

    void openConnectionDialog(const QString &type);
171
    void setWifiTetheringEnabled();
lpotter's avatar
lpotter committed
172 173
};

174
#endif // QCONNECTIONAGENT_H