qconnectionagent.h 4.28 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

#include <QObject>
#include <QStringList>
#include <QVariant>
22
#include <QVector>
lpotter's avatar
lpotter committed
23 24 25

class UserAgent;
class NetworkManager;
26
class NetworkService;
27
class NetworkTechnology;
28 29
class QTimer;

30
class QConnectionAgent : public QObject
lpotter's avatar
lpotter committed
31 32 33 34
{
    Q_OBJECT

public:
35
    explicit QConnectionAgent(QObject *parent = 0);
36
    ~QConnectionAgent();
37

38
    bool isValid() const;
lpotter's avatar
lpotter committed
39 40 41 42 43

Q_SIGNALS:

    void userInputRequested(const QString &servicePath, const QVariantMap &fields);
    void userInputCanceled();
44
    void errorReported(const QString &servicePath, const QString &error);
lpotter's avatar
lpotter committed
45
    void connectionRequest();
46
    void configurationNeeded(const QString &type);
47
    void connectionState(const QString &state, const QString &type);
48
    void connectNow(const QString &path);
49

50
    void requestBrowser(const QString &url);
51
    void tetheringFinished(bool);
52

lpotter's avatar
lpotter committed
53 54 55 56
public Q_SLOTS:

    void onUserInputRequested(const QString &servicePath, const QVariantMap &fields);
    void onUserInputCanceled();
57
    void onErrorReported(const QString &servicePath, const QString &error);
lpotter's avatar
lpotter committed
58 59 60 61 62 63

    void onConnectionRequest();

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

64
    void connectToType(const QString &type);
65

66
    void startTethering(const QString &type);
67
    void stopTethering(bool keepPowered = false);
68

lpotter's avatar
lpotter committed
69
private:
70 71 72 73

    class Service
    {
    public:
Pekka Vuorela's avatar
Pekka Vuorela committed
74 75
        QString path;
        NetworkService *service;
76

Pekka Vuorela's avatar
Pekka Vuorela committed
77 78 79
        bool operator==(const Service &other) const {
            return other.path == path;
        }
80 81 82 83 84
    };

    class ServiceList : public QVector<Service>
    {
    public:
Pekka Vuorela's avatar
Pekka Vuorela committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
        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);
        }
104 105
    };

106 107
    void setup();
    void updateServices();
108 109 110
    bool isStateOnline(const QString &state);
    void removeAllTypes(const QString &type);

111 112
    bool shouldSuppressError(const QString &error, bool cellular) const;

lpotter's avatar
lpotter committed
113
    UserAgent *ua;
114
    NetworkManager *netman;
lpotter's avatar
lpotter committed
115
    QString currentNetworkState;
116
    ServiceList orderedServicesList;
117
    QStringList techPreferenceList;
118
    bool isEthernet;
119
    bool connmanAvailable;
120

121
    NetworkTechnology *tetheringWifiTech;
122
    bool tetheringEnabled;
123
    bool flightModeSuppression;
124
    uint scanTimeoutInterval;
125

126 127
    QTimer *scanTimer;
    QStringList knownTechnologies;
128
    bool delayedTethering;
129
    bool valid;
130

131
private slots:
132 133 134 135
    void serviceErrorChanged(const QString &error);
    void serviceStateChanged(const QString &state);
    void networkStateChanged(const QString &state);

136
    void connmanAvailabilityChanged(bool b);
137 138
    void servicesError(const QString &);
    void technologyPowerChanged(bool);
139
    void browserRequest(const QString &servicePath, const QString &url);
140 141 142
    void techChanged();

    void servicesListChanged(const QStringList &);
143 144
    void offlineModeChanged(bool);
    void flightModeDialogSuppressionTimeout();
145

146
    void serviceAutoconnectChanged(bool);
147
    void scanTimeout();
148 149
    void techTetheringChanged(bool b);
    void servicesChanged();
150 151

    void openConnectionDialog(const QString &type);
152
    void setWifiTetheringEnabled();
lpotter's avatar
lpotter committed
153 154
};

155
#endif // QCONNECTIONAGENT_H