/
qconnectionagent.h
177 lines (139 loc) · 4.66 KB
1
2
/****************************************************************************
**
3
** Copyright (C) 2014 Jolla Ltd
4
5
6
7
** Contact: lorn.potter@gmail.com
**
**
** GNU Lesser General Public License Usage
8
** This file may be used under the terms of the GNU Lesser
9
10
11
12
13
14
15
16
** 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 QCONNECTIONAGENT_H
#define QCONNECTIONAGENT_H
19
20
21
22
23
24
25
#include <QObject>
#include <QMap>
#include <QStringList>
#include <QVariant>
#include <QDBusMessage>
#include <QDBusObjectPath>
26
27
#include <QQueue>
#include <QPair>
28
#include <QElapsedTimer>
29
#include <QVector>
30
31
32
33
34
class UserAgent;
class SessionAgent;
class NetworkManager;
35
class NetworkService;
36
class NetworkTechnology;
37
class WakeupWatcher;
38
39
class QTimer;
40
class QConnectionAgent : public QObject
41
42
43
44
{
Q_OBJECT
public:
45
explicit QConnectionAgent(QObject *parent = 0);
46
~QConnectionAgent();
47
48
bool isValid() const;
49
50
51
52
53
Q_SIGNALS:
void userInputRequested(const QString &servicePath, const QVariantMap &fields);
void userInputCanceled();
54
void errorReported(const QString &servicePath, const QString &error);
55
void connectionRequest();
56
void configurationNeeded(const QString &type);
57
void connectionState(const QString &state, const QString &type);
58
void connectNow(const QString &path);
59
60
void requestBrowser(const QString &url);
61
void tetheringFinished(bool);
62
63
64
65
66
public Q_SLOTS:
void onUserInputRequested(const QString &servicePath, const QVariantMap &fields);
void onUserInputCanceled();
67
void onErrorReported(const QString &servicePath, const QString &error);
68
69
70
71
72
73
void onConnectionRequest();
void sendConnectReply(const QString &in0, int in1);
void sendUserReply(const QVariantMap &input);
74
void connectToType(const QString &type);
75
76
void startTethering(const QString &type);
77
void stopTethering(bool keepPowered = false);
78
79
private:
80
81
82
83
class Service
{
public:
84
85
QString path;
NetworkService *service;
86
87
88
89
bool operator==(const Service &other) const {
return other.path == path;
}
90
91
92
93
94
};
class ServiceList : public QVector<Service>
{
public:
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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);
}
114
115
};
116
117
void setup();
void updateServices();
118
119
120
121
122
bool isStateOnline(const QString &state);
bool isBestService(NetworkService *service);
QString findBestConnectableService();
void removeAllTypes(const QString &type);
123
UserAgent *ua;
124
125
NetworkManager *netman;
126
SessionAgent *sessionAgent;
127
128
QString currentNetworkState;
129
130
ServiceList orderedServicesList;
131
132
QStringList techPreferenceList;
133
bool isEthernet;
134
bool connmanAvailable;
135
136
NetworkTechnology *tetheringWifiTech;
137
bool tetheringEnabled;
138
bool flightModeSuppression;
139
WakeupWatcher *mceWatch;
140
uint scanTimeoutInterval;
141
142
143
QTimer *scanTimer;
QStringList knownTechnologies;
144
145
bool tetheringStarted;
bool delayedTethering;
146
bool valid;
147
148
149
150
private slots:
void onScanFinished();
151
152
153
154
void serviceErrorChanged(const QString &error);
void serviceStateChanged(const QString &state);
void networkStateChanged(const QString &state);
155
void connmanAvailabilityChanged(bool b);
156
157
void servicesError(const QString &);
void technologyPowerChanged(bool);
158
void browserRequest(const QString &servicePath, const QString &url);
159
160
161
void techChanged();
void servicesListChanged(const QStringList &);
162
163
void offlineModeChanged(bool);
void flightModeDialogSuppressionTimeout();
164
165
void displayStateChanged(const QString &);
166
// void sleepStateChanged(bool);
167
168
void serviceAutoconnectChanged(bool);
169
void scanTimeout();
170
171
void techTetheringChanged(bool b);
void servicesChanged();
172
173
void openConnectionDialog(const QString &type);
174
void setWifiTetheringEnabled();
175
176
};
177
#endif // QCONNECTIONAGENT_H