/
qconnectionagent.h
159 lines (126 loc) · 4.39 KB
1
2
/****************************************************************************
**
3
** Copyright (C) 2014-2017 Jolla Ltd
4
5
6
** Contact: lorn.potter@gmail.com
**
** GNU Lesser General Public License Usage
7
** This file may be used under the terms of the GNU Lesser
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
18
19
20
21
#include <QObject>
#include <QStringList>
#include <QVariant>
22
#include <QVector>
23
24
25
class UserAgent;
class NetworkManager;
26
class NetworkService;
27
class NetworkTechnology;
28
29
class QTimer;
30
class QConnectionAgent : public QObject
31
32
33
34
{
Q_OBJECT
public:
35
explicit QConnectionAgent(QObject *parent = 0);
36
~QConnectionAgent();
37
38
bool isValid() const;
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);
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
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);
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
69
private:
70
71
72
73
class Service
{
public:
74
75
QString path;
NetworkService *service;
76
77
78
79
bool operator==(const Service &other) const {
return other.path == path;
}
80
81
82
83
84
};
class ServiceList : public QVector<Service>
{
public:
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
111
112
bool isStateOnline(const QString &state);
bool isBestService(NetworkService *service);
QString findBestConnectableService();
void removeAllTypes(const QString &type);
113
114
bool shouldSuppressError(const QString &error, bool cellular) const;
115
UserAgent *ua;
116
NetworkManager *netman;
117
QString currentNetworkState;
118
ServiceList orderedServicesList;
119
QStringList techPreferenceList;
120
bool isEthernet;
121
bool connmanAvailable;
122
123
NetworkTechnology *tetheringWifiTech;
124
bool tetheringEnabled;
125
bool flightModeSuppression;
126
uint scanTimeoutInterval;
127
128
129
QTimer *scanTimer;
QStringList knownTechnologies;
130
bool delayedTethering;
131
bool valid;
132
133
134
135
private slots:
void onScanFinished();
136
137
138
139
void serviceErrorChanged(const QString &error);
void serviceStateChanged(const QString &state);
void networkStateChanged(const QString &state);
140
void connmanAvailabilityChanged(bool b);
141
142
void servicesError(const QString &);
void technologyPowerChanged(bool);
143
void browserRequest(const QString &servicePath, const QString &url);
144
145
146
void techChanged();
void servicesListChanged(const QStringList &);
147
148
void offlineModeChanged(bool);
void flightModeDialogSuppressionTimeout();
149
150
void serviceAutoconnectChanged(bool);
151
void scanTimeout();
152
153
void techTetheringChanged(bool b);
void servicesChanged();
154
155
void openConnectionDialog(const QString &type);
156
void setWifiTetheringEnabled();
157
158
};
159
#endif // QCONNECTIONAGENT_H