43 #include <winrt/base.h>
48 template <
typename Async>
49 auto wait_for(Async
const& async, Windows::Foundation::TimeSpan
const&
timeout);
52 #include <winrt/Windows.Networking.Connectivity.h>
61 if (
riid == __uuidof(
T)) {
62 *ppvObject =
static_cast<T *
>(from);
72 auto hr = CoCreateInstance(CLSID_NetworkListManager,
nullptr, CLSCTX_INPROC_SERVER,
73 IID_INetworkListManager, &networkListManager);
75 qCWarning(lcNetInfoNLM) <<
"Could not get a NetworkListManager instance:"
80 ComPtr<IConnectionPointContainer> connectionPointContainer;
81 hr = networkListManager.As(&connectionPointContainer);
83 hr = connectionPointContainer->FindConnectionPoint(IID_INetworkListManagerEvents,
87 qCWarning(lcNetInfoNLM) <<
"Failed to get connection point for network list manager events:"
102 return QueryInterfaceImpl<IUnknown>(
this,
riid, ppvObject)
103 || QueryInterfaceImpl<INetworkListManagerEvents>(
this,
riid, ppvObject)
119 if (!connectionPoint) {
120 qCWarning(lcNetInfoNLM,
"Initialization failed, can't start!");
123 auto hr = connectionPoint->Advise(
this, &cookie);
125 qCWarning(lcNetInfoNLM) <<
"Failed to subscribe to network connectivity events:"
131 NLM_CONNECTIVITY connectivity;
132 hr = networkListManager->GetConnectivity(&connectivity);
138 #ifdef SUPPORTS_WINRT
139 using namespace winrt::Windows::Networking::Connectivity;
141 token = NetworkInformation::NetworkStatusChanged(
142 [
this](
const winrt::Windows::Foundation::IInspectable sender) {
156 auto hr = connectionPoint->Unadvise(cookie);
158 qCWarning(lcNetInfoNLM) <<
"Failed to unsubscribe from network connectivity events:"
164 #ifdef SUPPORTS_WINRT
165 using namespace winrt::Windows::Networking::Connectivity;
167 NetworkInformation::NetworkStatusChanged(
token);
175 if (!networkListManager)
177 ComPtr<IEnumNetworks> networks;
179 networkListManager->GetNetworks(NLM_ENUM_NETWORK_CONNECTED, networks.GetAddressOf());
180 if (FAILED(hr) || networks ==
nullptr)
184 ComPtr<INetwork> network;
185 hr = networks->Next(1, network.GetAddressOf(),
nullptr);
186 while (SUCCEEDED(hr) && network !=
nullptr) {
187 ComPtr<IPropertyBag> propertyBag;
188 hr = network.As(&propertyBag);
189 if (SUCCEEDED(hr) && propertyBag !=
nullptr) {
194 const wchar_t *versions[] = { NA_InternetConnectivityV6, NA_InternetConnectivityV4 };
195 for (
const auto version : versions) {
198 && (V_UINT(&
variant) & NLM_INTERNET_CONNECTIVITY_WEBHIJACK)
199 == NLM_INTERNET_CONNECTIVITY_WEBHIJACK) {
205 hr = networks->Next(1, network.GetAddressOf(),
nullptr);
211 #ifdef SUPPORTS_WINRT
213 using namespace winrt::Windows::Networking::Connectivity;
219 if (profile.IsWwanConnectionProfile())
221 if (profile.IsWlanConnectionProfile())
224 NetworkAdapter adapter = profile.NetworkAdapter();
225 if (adapter ==
nullptr)
242 return fromIanaId(adapter.IanaInterfaceType());
245 [[nodiscard]]
bool getMetered(
const ConnectionProfile &profile)
247 ConnectionCost cost = profile.GetConnectionCost();
248 NetworkCostType
type = cost.NetworkCostType();
249 return type == NetworkCostType::Fixed ||
type == NetworkCostType::Variable;
253 void QNetworkListManagerEvents::emitWinRTUpdates()
255 using namespace winrt::Windows::Networking::Connectivity;
256 ConnectionProfile profile = NetworkInformation::GetInternetConnectionProfile();
257 if (profile ==
nullptr)
bool checkBehindCaptivePortal()
void transportMediumChanged(QNetworkInformation::TransportMedium)
void isMeteredChanged(bool)
void connectivityChanged(NLM_CONNECTIVITY)
virtual ~QNetworkListManagerEvents()
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override
QNetworkListManagerEvents()
HRESULT STDMETHODCALLTYPE ConnectivityChanged(NLM_CONNECTIVITY newConnectivity) override
bool QueryInterfaceImpl(IUnknown *from, REFIID riid, void **ppvObject)
#define qCWarning(category,...)
QT_BEGIN_NAMESPACE QString errorStringFromHResult(HRESULT hr)
GLbitfield GLuint64 timeout
[4]
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
IUIViewSettingsInterop __RPC__in REFIID riid