/
qconnectionagent.h
159 lines (128 loc) · 4.77 KB
/
qconnectionagent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/****************************************************************************
**
** Copyright (C) 2014-2017 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.
**
****************************************************************************/
#ifndef QCONNECTIONAGENT_H
#define QCONNECTIONAGENT_H
#include <QObject>
#include <QStringList>
#include <QVariant>
#include <QVector>
#include <QLoggingCategory>
#include "networkmanager.h"
#include "networkservice.h"
class UserAgent;
class NetworkService;
class NetworkTechnology;
class QTimer;
class QConnectionAgent : public QObject
{
Q_OBJECT
public:
explicit QConnectionAgent(QObject *parent = 0);
~QConnectionAgent();
bool isValid() const;
Q_SIGNALS:
void userInputRequested(const QString &servicePath, const QVariantMap &fields);
void userInputCanceled();
void errorReported(const QString &servicePath, const QString &error);
void connectionRequest();
void configurationNeeded(const QString &type);
void connectionState(const QString &state, const QString &type);
void connectNow(const QString &path);
void requestBrowser(const QString &url, const QString &serviceName);
void wifiTetheringFinished(bool);
void bluetoothTetheringFinished(bool);
public Q_SLOTS:
void onErrorReported(const QString &servicePath, const QString &error);
void onConnectionRequest();
void onBrowserRequested(const QString &url, const QString &serviceName);
void sendConnectReply(const QString &in0, int in1);
void sendUserReply(const QVariantMap &input);
void connectToType(const QString &type);
void startTethering(const QString &type);
void stopTethering(const QString &type, bool keepPowered = false);
private:
class Service
{
public:
QString path;
NetworkService *service;
bool operator==(const Service &other) const {
return other.path == path;
}
};
class ServiceList : public QVector<Service>
{
public:
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);
}
};
void setup();
void updateServices();
void removeAllTypes(const QString &type);
bool shouldSuppressError(const QString &error, bool cellular) const;
UserAgent *ua;
QSharedPointer<NetworkManager> netman;
ServiceList orderedServicesList;
QStringList techPreferenceList;
bool isEthernet;
NetworkTechnology *tetheringWifiTech;
NetworkTechnology *tetheringBtTech;
// Turn on Wifi tethering when the tech is next powered up. Wifi will be turned on
// when this is enabled, so it won't be long. This gets reset once tethering is on
// so will not be restored after flight mode or power off
bool tetherWifiWhenPowered;
// Turn on Bluetooth tethering whenever the BT adaptor is powered on. This will not
// get reset, and is stored persistently in config, so when the option is enabled
// tethering will always be started when BT is powered on.
bool tetherBtWhenPowered;
bool flightModeSuppression;
uint scanTimeoutInterval;
QTimer *scanTimer;
QStringList knownTechnologies;
bool valid;
private slots:
void serviceErrorChanged(const QString &error);
void serviceStateChanged(NetworkService::ServiceState state);
void networkManagerStateChanged(NetworkManager::State state);
void connmanAvailabilityChanged(bool available);
void servicesError(const QString &);
void technologyPowerChanged(bool);
void techChanged();
void servicesListChanged(const QStringList &);
void offlineModeChanged(bool);
void flightModeDialogSuppressionTimeout();
void serviceAutoconnectChanged(bool);
void scanTimeout();
void techTetheringChanged(bool on);
void openConnectionDialog(const QString &type);
void enableWifiTethering();
void enableBtTethering();
};
#endif // QCONNECTIONAGENT_H