2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2021-09-20 18:04:24 +00:00
|
|
|
|
|
|
|
#ifndef MAINWINDOW_H
|
|
|
|
#define MAINWINDOW_H
|
|
|
|
|
|
|
|
#include <QtWidgets/qmainwindow.h>
|
|
|
|
#include <QtWidgets/qlabel.h>
|
|
|
|
#include <QtCore/qmetaobject.h>
|
|
|
|
|
|
|
|
#include <QtNetwork/qnetworkinformation.h>
|
|
|
|
|
|
|
|
template<typename QEnum>
|
|
|
|
QString enumToString(const QEnum value)
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(QMetaEnum::fromType<QEnum>().valueToKey(int(value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
class MainWindow : public QMainWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
using Reachability = QNetworkInformation::Reachability;
|
2021-10-05 05:45:46 +00:00
|
|
|
using TransportMedium = QNetworkInformation::TransportMedium;
|
2021-09-20 18:04:24 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
MainWindow() : QMainWindow(nullptr)
|
|
|
|
{
|
|
|
|
label->setText("hello");
|
|
|
|
setCentralWidget(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void updateReachability(Reachability newValue)
|
|
|
|
{
|
|
|
|
reachability = newValue;
|
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateCaptiveState(bool newValue)
|
|
|
|
{
|
|
|
|
captive = newValue;
|
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
2021-10-05 05:45:46 +00:00
|
|
|
void updateTransportMedium(TransportMedium newValue)
|
2021-09-23 12:38:18 +00:00
|
|
|
{
|
2021-10-05 05:45:46 +00:00
|
|
|
transportMedium = newValue;
|
2021-09-23 12:38:18 +00:00
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
2021-10-25 18:23:24 +00:00
|
|
|
void updateMetered(bool newValue)
|
|
|
|
{
|
|
|
|
metered = newValue;
|
|
|
|
updateText();
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:04:24 +00:00
|
|
|
private:
|
|
|
|
void updateText()
|
|
|
|
{
|
|
|
|
QString str =
|
2021-10-25 18:23:24 +00:00
|
|
|
QLatin1String("Reachability: %1\nBehind captive portal: %2\nTransport medium: %3"
|
|
|
|
"\nMetered: %4")
|
2021-11-03 13:07:42 +00:00
|
|
|
.arg(enumToString(reachability), captive ? u"true" : u"false",
|
2021-10-25 18:23:24 +00:00
|
|
|
enumToString(transportMedium), metered ? u"true" : u"false");
|
2021-09-20 18:04:24 +00:00
|
|
|
label->setText(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel *const label = new QLabel(this);
|
|
|
|
Reachability reachability = Reachability::Unknown;
|
2021-10-05 05:45:46 +00:00
|
|
|
TransportMedium transportMedium = TransportMedium::Unknown;
|
2021-09-20 18:04:24 +00:00
|
|
|
bool captive = false;
|
2021-10-25 18:23:24 +00:00
|
|
|
bool metered = false;
|
2021-09-20 18:04:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|