trikRuntime
wiFiClientWidget.h
Go to the documentation of this file.
1 /* Copyright 2013 Roman Kurbatov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 /* This file was modified by Yurii Litvinov to make it comply with the requirements of trikRuntime
16  * project. See git revision history for detailed changes. */
17 
18 #pragma once
19 
20 #include <QtCore/qglobal.h>
21 
22 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
23  #include <QtGui/QLabel>
24  #include <QtGui/QTextEdit>
25  #include <QtGui/QVBoxLayout>
26  #include <QtGui/QListView>
27 #else
28  #include <QtWidgets/QLabel>
29  #include <QtWidgets/QTextEdit>
30  #include <QtWidgets/QVBoxLayout>
31  #include <QtWidgets/QListView>
32 #endif
33 
34 #include <QtCore/QList>
35 #include <QtCore/QTimer>
36 #include <QtGui/QStandardItem>
37 #include <QtGui/QStandardItemModel>
38 
40 
41 #include "trikGuiDialog.h"
42 
43 namespace trikWiFi {
44 class TrikWiFi;
45 }
46 
47 namespace trikGui {
48 
72 {
73  Q_OBJECT
74 
75 public:
78  explicit WiFiClientWidget(trikWiFi::TrikWiFi &trikWiFi, QWidget *parent = nullptr);
79 
82 
83  void renewFocus() override;
84 
85 protected:
86  void keyPressEvent(QKeyEvent *event) override;
87 
88 private slots:
90  void onNetworksInfoUpdated();
91 
93  void onConnected();
94 
97  void onDisconnected(trikWiFi::DisconnectReason reason);
98 
100  void onStatusUpdated();
101 
103  void onError(const QString &message);
104 
106  void onConnectionTimeout();
107 
108 private:
111  enum class ConnectionState {
112  notConnected
113  , connecting
114  , connected
115  , errored
116  };
117 
119  struct NetworkInfo {
121  QString ssid;
122 
125  bool isKnown;
126 
128  trikWiFi::Security security;
129  };
130 
132  void setConnectionStatus(ConnectionState state, const QString &ip, const QString &ssid);
133 
136  void updateConnectionStatusesInNetworkList();
137 
139  void connectToSelectedNetwork();
140 
142  void showScanning();
143 
144  QLabel mConnectionIconLabel;
145  QLabel mIpLabel;
146  QLabel mIpValueLabel;
147  QLabel mNameLabel;
148  QLabel mNameValueLabel;
149  QLabel mAvailableNetworksLabel;
150  QListView mAvailableNetworksView;
151  QStandardItemModel mAvailableNetworksModel;
152  QVBoxLayout mMainLayout;
153  QHBoxLayout mIpAddressLayout;
154  QHBoxLayout mNameLayout;
155  trikWiFi::TrikWiFi &mWiFi;
156  QString mCurrentSsid;
157  QHash<QString, NetworkInfo> mNetworks;
158  ConnectionState mConnectionState;
159 
160  QTimer mConnectionTimeoutTimer;
161 };
162 
163 }
Widget that shows current IP address and a list of available WiFi networks.
Definition: wiFiClientWidget.h:71
Base class for all trikGui dialog widgets.
Definition: trikGuiDialog.h:24
DisconnectReason
Enum with possible reasons of "disconnect" message.
Definition: networkStructs.h:35
Class for WiFi management.
Definition: trikWiFi.h:31
Definition: abstractIndicator.h:21
Definition: controller.h:25
Security
Enum with possible network security.
Definition: networkStructs.h:22