summaryrefslogtreecommitdiffstats
path: root/src/network/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/kernel')
-rw-r--r--src/network/kernel/qnetworkinformation.cpp55
-rw-r--r--src/network/kernel/qnetworkinformation.h1
-rw-r--r--src/network/kernel/qnetworkinformation_p.h11
3 files changed, 65 insertions, 2 deletions
diff --git a/src/network/kernel/qnetworkinformation.cpp b/src/network/kernel/qnetworkinformation.cpp
index 79375dee81..4f0b1405ef 100644
--- a/src/network/kernel/qnetworkinformation.cpp
+++ b/src/network/kernel/qnetworkinformation.cpp
@@ -604,11 +604,62 @@ QNetworkInformation::Features QNetworkInformation::supportedFeatures() const
}
/*!
+ \since 6.3
+
+ Attempts to load the platform-default backend.
+
+ This platform-to-plugin mapping is as follows:
+
+ \table
+ \header
+ \li Platform
+ \li Plugin-name
+ \row
+ \li Windows
+ \li networklistmanager
+ \row
+ \li Apple (macOS/iOS)
+ \li scnetworkreachability
+ \row
+ \li Android
+ \li android
+ \row
+ \li Linux
+ \li networkmanager
+ \endtable
+
+ This function is provided for convenience where the default for a given
+ platform is good enough. If you are not using the default plugins you must
+ use one of the other load() overloads.
+
+ Returns \c true if it managed to load the backend or if it was already
+ loaded. Returns \c false otherwise.
+
+ \sa instance
+*/
+bool QNetworkInformation::load()
+{
+ int index = -1;
+#ifdef Q_OS_WIN
+ index = QNetworkInformationBackend::PluginNamesWindowsIndex;
+#elif defined(Q_OS_DARWIN)
+ index = QNetworkInformationBackend::PluginNamesAppleIndex;
+#elif defined(Q_OS_ANDROID)
+ index = QNetworkInformationBackend::PluginNamesAndroidIndex;
+#elif defined(Q_OS_LINUX)
+ index = QNetworkInformationBackend::PluginNamesLinuxIndex;
+#endif
+ if (index == -1)
+ return false;
+ return load(QNetworkInformationBackend::PluginNames[index]);
+}
+
+/*!
Attempts to load a backend whose name matches \a backend
(case insensitively).
Returns \c true if it managed to load the requested backend or
- if it was already loaded. Returns \c false otherwise
+ if it was already loaded. Returns \c false otherwise.
\sa instance
*/
@@ -622,7 +673,7 @@ bool QNetworkInformation::load(QStringView backend)
Load a backend which supports \a features.
Returns \c true if it managed to load the requested backend or
- if it was already loaded. Returns \c false otherwise
+ if it was already loaded. Returns \c false otherwise.
\sa instance
*/
diff --git a/src/network/kernel/qnetworkinformation.h b/src/network/kernel/qnetworkinformation.h
index febf5bbc8f..e280894fef 100644
--- a/src/network/kernel/qnetworkinformation.h
+++ b/src/network/kernel/qnetworkinformation.h
@@ -96,6 +96,7 @@ public:
bool supports(Features features) const;
Features supportedFeatures() const;
+ static bool load();
static bool load(QStringView backend);
static bool load(Features features);
static QStringList availableBackends();
diff --git a/src/network/kernel/qnetworkinformation_p.h b/src/network/kernel/qnetworkinformation_p.h
index ba07870be3..971340b6e3 100644
--- a/src/network/kernel/qnetworkinformation_p.h
+++ b/src/network/kernel/qnetworkinformation_p.h
@@ -67,6 +67,17 @@ class Q_NETWORK_EXPORT QNetworkInformationBackend : public QObject
using TransportMedium = QNetworkInformation::TransportMedium;
public:
+ static inline const char16_t PluginNames[4][22] = {
+ { u"networklistmanager" },
+ { u"scnetworkreachability" },
+ { u"android" },
+ { u"networkmanager" },
+ };
+ static constexpr int PluginNamesWindowsIndex = 0;
+ static constexpr int PluginNamesAppleIndex = 1;
+ static constexpr int PluginNamesAndroidIndex = 2;
+ static constexpr int PluginNamesLinuxIndex = 3;
+
QNetworkInformationBackend() = default;
~QNetworkInformationBackend() override;