mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-24 18:04:14 +08:00
Ref T295, QNetworkConfiguration as string
This commit is contained in:
@@ -416,14 +416,69 @@ namespace BlackMisc
|
|||||||
const QNetworkConfiguration c = am->configuration();
|
const QNetworkConfiguration c = am->configuration();
|
||||||
static const QMetaEnum enumAccessible = QMetaEnum::fromType<QNetworkAccessManager::NetworkAccessibility>();
|
static const QMetaEnum enumAccessible = QMetaEnum::fromType<QNetworkAccessManager::NetworkAccessibility>();
|
||||||
|
|
||||||
const QString msg = QString("Accessible: %1 (%2) bearer: %3 %4").arg(
|
const QString msg = QString("Accessible: %1 (%2) config: %3").arg(
|
||||||
boolToYesNo(accessible),
|
boolToYesNo(accessible),
|
||||||
enumAccessible.valueToKey(am->networkAccessible()),
|
enumAccessible.valueToKey(am->networkAccessible()),
|
||||||
c.bearerTypeName(), c.identifier());
|
networkConfigurationToString(c));
|
||||||
msgs.push_back(CStatusMessage(cats, accessible ? CStatusMessage::SeverityInfo : CStatusMessage::SeverityError, msg));
|
msgs.push_back(CStatusMessage(cats, accessible ? CStatusMessage::SeverityInfo : CStatusMessage::SeverityError, msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CNetworkUtils::networkConfigurationToString(const QNetworkConfiguration &configuration)
|
||||||
|
{
|
||||||
|
static const QString s("%1 %2 valid: %3 %4 %5");
|
||||||
|
const QString stateFlagsStr = networkStatesToString(configuration.state());
|
||||||
|
return s.arg(configuration.name(), configuration.identifier(), boolToYesNo(configuration.isValid()), stateFlagsStr, networkTypeToString(configuration.type()));
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CNetworkUtils::networkTypeToString(QNetworkConfiguration::Type type)
|
||||||
|
{
|
||||||
|
static const QString iap("InternetAccessPoint");
|
||||||
|
static const QString sn("ServiceNetwork");
|
||||||
|
static const QString i("Invalid");
|
||||||
|
static const QString uc("UserChoice");
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case QNetworkConfiguration::InternetAccessPoint: return iap;
|
||||||
|
case QNetworkConfiguration::ServiceNetwork: return sn;
|
||||||
|
case QNetworkConfiguration::UserChoice: return uc;
|
||||||
|
default:
|
||||||
|
case QNetworkConfiguration::Invalid: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CNetworkUtils::networkStateToString(QNetworkConfiguration::StateFlag state)
|
||||||
|
{
|
||||||
|
static const QString disco("Discovered");
|
||||||
|
static const QString a("Active");
|
||||||
|
static const QString u("Undefined");
|
||||||
|
static const QString d("Defined");
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case QNetworkConfiguration::Defined: return d;
|
||||||
|
case QNetworkConfiguration::Active: return a;
|
||||||
|
case QNetworkConfiguration::Discovered: return disco;
|
||||||
|
default:
|
||||||
|
case QNetworkConfiguration::Undefined: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CNetworkUtils::networkStatesToString(QNetworkConfiguration::StateFlags states)
|
||||||
|
{
|
||||||
|
QStringList statesSl;
|
||||||
|
if (states.testFlag(QNetworkConfiguration::Active)) { statesSl << networkStateToString(QNetworkConfiguration::Active); }
|
||||||
|
if (states.testFlag(QNetworkConfiguration::Discovered)) { statesSl << networkStateToString(QNetworkConfiguration::Discovered); }
|
||||||
|
if (states.testFlag(QNetworkConfiguration::Defined)) { statesSl << networkStateToString(QNetworkConfiguration::Defined); }
|
||||||
|
if (states.testFlag(QNetworkConfiguration::Undefined)) { statesSl << networkStateToString(QNetworkConfiguration::Undefined); }
|
||||||
|
return statesSl.join(", ");
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkConfiguration>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
@@ -159,6 +160,18 @@ namespace BlackMisc
|
|||||||
//! \remark that can take a moment to complete, as it checks network
|
//! \remark that can take a moment to complete, as it checks network
|
||||||
static BlackMisc::CStatusMessageList createNetworkReport(const CUrl &url, const QNetworkAccessManager *am = nullptr);
|
static BlackMisc::CStatusMessageList createNetworkReport(const CUrl &url, const QNetworkAccessManager *am = nullptr);
|
||||||
|
|
||||||
|
//! Configuration as string
|
||||||
|
static QString networkConfigurationToString(const QNetworkConfiguration &configuration);
|
||||||
|
|
||||||
|
//! Type to string
|
||||||
|
static const QString &networkTypeToString(QNetworkConfiguration::Type type);
|
||||||
|
|
||||||
|
//! State to string
|
||||||
|
static const QString &networkStateToString(QNetworkConfiguration::StateFlag state);
|
||||||
|
|
||||||
|
//! States to string
|
||||||
|
static QString networkStatesToString(QNetworkConfiguration::StateFlags states);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Hidden constructor
|
//! Hidden constructor
|
||||||
CNetworkUtils() {}
|
CNetworkUtils() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user