Files
amnezia-client/client/mozilla/networkwatcher.h
T

57 lines
1.4 KiB
C++
Raw Normal View History

2023-07-15 14:19:48 -07:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef NETWORKWATCHER_H
#define NETWORKWATCHER_H
#include <QElapsedTimer>
#include <QMap>
2024-05-08 22:02:02 +01:00
#include <QNetworkInformation>
2023-07-15 14:19:48 -07:00
class NetworkWatcherImpl;
// This class watches for network changes to detect unsecured wifi.
class NetworkWatcher final : public QObject {
2024-05-08 22:02:02 +01:00
Q_OBJECT
Q_DISABLE_COPY_MOVE(NetworkWatcher)
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
public:
NetworkWatcher();
~NetworkWatcher();
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
void initialize();
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
// Public for the Inspector.
void unsecuredNetwork(const QString& networkName, const QString& networkId);
// Used for the Inspector. simulateOffline = true to mock being disconnected,
// false to restore.
void simulateDisconnection(bool simulatedDisconnection);
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
QNetworkInformation::Reachability getReachability();
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
signals:
void networkChange();
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
private:
void settingsChanged();
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
private:
bool m_active = false;
bool m_reportUnsecuredNetwork = false;
2024-05-08 22:02:02 +01:00
// Platform-specific implementation.
NetworkWatcherImpl* m_impl = nullptr;
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
QMap<QString, QElapsedTimer> m_networks;
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
// This is used to connect NotificationHandler lazily.
bool m_firstNotification = true;
2023-07-15 14:19:48 -07:00
2024-05-08 22:02:02 +01:00
// Used to simulate network disconnection in the Inspector
bool m_simulatedDisconnection = false;
2023-07-15 14:19:48 -07:00
};
#endif // NETWORKWATCHER_H