bool QWinRTServices::openDocument(const QUrl &url) { if (!(m_fileFactory && m_launcher)) return QPlatformServices::openDocument(url); const QString pathString = QDir::toNativeSeparators(url.toLocalFile()); HSTRING_HEADER header; HSTRING path; WindowsCreateStringReference((const wchar_t*)pathString.utf16(), pathString.length(), &header, &path); IAsyncOperation<StorageFile*> *fileOp; m_fileFactory->GetFileFromPathAsync(path, &fileOp); if (!fileOp) return false; IStorageFile *file = nullptr; while (fileOp->GetResults(&file) == E_ILLEGAL_METHOD_CALL) QCoreApplication::processEvents(); fileOp->Release(); if (!file) return false; IAsyncOperation<bool> *launchOp; m_launcher->LaunchFileAsync(file, &launchOp); if (!launchOp) return false; boolean result = false; while (launchOp->GetResults(&result) == E_ILLEGAL_METHOD_CALL) QCoreApplication::processEvents(); launchOp->Release(); return result; }
bool QWinRTServices::openUrl(const QUrl &url) { if (!(m_uriFactory && m_launcher)) return QPlatformServices::openUrl(url); IUriRuntimeClass *uri; QString urlString = url.toString(); HSTRING uriString; HSTRING_HEADER header; WindowsCreateStringReference((const wchar_t*)urlString.utf16(), urlString.length(), &header, &uriString); m_uriFactory->CreateUri(uriString, &uri); if (!uri) return false; IAsyncOperation<bool> *launchOp; m_launcher->LaunchUriAsync(uri, &launchOp); uri->Release(); if (!launchOp) return false; boolean result = false; while (launchOp->GetResults(&result) == E_ILLEGAL_METHOD_CALL) QCoreApplication::processEvents(); launchOp->Release(); return result; }
QT_BEGIN_NAMESPACE void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply) { // TODO: Add nameserver support for winRT if (!nameserver.isNull()) qWarning() << "Ignoring nameserver as its currently not supported on WinRT"; // TODO: is there any way to do "proper" dns lookup? if (requestType != QDnsLookup::A && requestType != QDnsLookup::AAAA && requestType != QDnsLookup::ANY) { reply->error = QDnsLookup::InvalidRequestError; reply->errorString = QLatin1String("WinRT only supports IPv4 and IPv6 requests"); return; } QString aceHostname = QUrl::fromAce(requestName); if (aceHostname.isEmpty()) { reply->error = QDnsLookup::InvalidRequestError; reply->errorString = requestName.isEmpty() ? tr("No hostname given") : tr("Invalid hostname"); return; } IHostNameFactory *hostnameFactory; HStringReference classId(RuntimeClass_Windows_Networking_HostName); if (FAILED(GetActivationFactory(classId.Get(), &hostnameFactory))) { reply->error = QDnsLookup::ResolverError; reply->errorString = QLatin1String("Could not obtain hostname factory"); return; } IHostName *host; HStringReference hostNameRef((const wchar_t*)aceHostname.utf16()); hostnameFactory->CreateHostName(hostNameRef.Get(), &host); hostnameFactory->Release(); IDatagramSocketStatics *datagramSocketStatics; GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Networking_Sockets_DatagramSocket).Get(), &datagramSocketStatics); IAsyncOperation<IVectorView<EndpointPair*> *> *op; HSTRING proto; WindowsCreateString(L"0", 1, &proto); datagramSocketStatics->GetEndpointPairsAsync(host, proto, &op); datagramSocketStatics->Release(); host->Release(); IVectorView<EndpointPair*> *endpointPairs = 0; HRESULT hr = op->GetResults(&endpointPairs); int waitCount = 0; while (hr == E_ILLEGAL_METHOD_CALL) { WaitForSingleObjectEx(GetCurrentThread(), 50, FALSE); hr = op->GetResults(&endpointPairs); if (++waitCount > 1200) // Wait for 1 minute max return; } op->Release(); if (!endpointPairs) return; unsigned int size; endpointPairs->get_Size(&size); for (unsigned int i = 0; i < size; ++i) { IEndpointPair *endpointpair; endpointPairs->GetAt(i, &endpointpair); IHostName *remoteHost; endpointpair->get_RemoteHostName(&remoteHost); endpointpair->Release(); HostNameType type; remoteHost->get_Type(&type); if (type == HostNameType_Bluetooth || type == HostNameType_DomainName || (requestType != QDnsLookup::ANY && ((type == HostNameType_Ipv4 && requestType == QDnsLookup::AAAA) || (type == HostNameType_Ipv6 && requestType == QDnsLookup::A)))) continue; HSTRING name; remoteHost->get_CanonicalName(&name); remoteHost->Release(); UINT32 length; PCWSTR rawString = WindowsGetStringRawBuffer(name, &length); QDnsHostAddressRecord record; record.d->name = aceHostname; record.d->value = QHostAddress(QString::fromWCharArray(rawString, length)); reply->hostAddressRecords.append(record); } }