summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@digia.com>2014-06-06 14:19:04 +0300
committerAndrew Knight <andrew.knight@digia.com>2014-06-25 16:34:23 +0200
commitb740e27e365000380d22a290ad6615e5b5bce7e5 (patch)
tree035a60e02303aa89cb7eafd0686dcd4f5045e31d /src
parent5e32bfa3e2ee226f8ef056a1d559ba508ea512b8 (diff)
winrt: Clean up QWinRTServices
- Remove WinRT types from the header - Use ComPtr everywhere - Use convenience methods for HRESULT and async operations Task-number: QTBUG-38115 Change-Id: I540a3349612b98c45545c92b2cb6d21a34918b8f Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/winrt/qwinrtservices.cpp122
-rw-r--r--src/plugins/platforms/winrt/qwinrtservices.h27
2 files changed, 68 insertions, 81 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtservices.cpp b/src/plugins/platforms/winrt/qwinrtservices.cpp
index b0f9247d36..6272b46f44 100644
--- a/src/plugins/platforms/winrt/qwinrtservices.cpp
+++ b/src/plugins/platforms/winrt/qwinrtservices.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@@ -43,6 +43,7 @@
#include <QtCore/QUrl>
#include <QtCore/QDir>
#include <QtCore/QCoreApplication>
+#include <QtCore/qfunctions_winrt.h>
#include <wrl.h>
#include <windows.foundation.h>
@@ -56,83 +57,84 @@ using namespace ABI::Windows::System;
QT_BEGIN_NAMESPACE
+class QWinRTServicesPrivate
+{
+public:
+ ComPtr<IUriRuntimeClassFactory> uriFactory;
+ ComPtr<IStorageFileStatics> fileFactory;
+ ComPtr<ILauncherStatics> launcher;
+};
+
QWinRTServices::QWinRTServices()
+ : d_ptr(new QWinRTServicesPrivate)
{
- GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Uri).Get(), &m_uriFactory);
- GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_StorageFile).Get(), &m_fileFactory);
- GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_System_Launcher).Get(), &m_launcher);
+ Q_D(QWinRTServices);
+
+ HRESULT hr;
+ hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Uri).Get(),
+ IID_PPV_ARGS(&d->uriFactory));
+ Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr)));
+
+ hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_StorageFile).Get(),
+ IID_PPV_ARGS(&d->fileFactory));
+ Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr)));
+
+ hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_System_Launcher).Get(),
+ IID_PPV_ARGS(&d->launcher));
+ Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr)));
}
QWinRTServices::~QWinRTServices()
{
- if (m_uriFactory)
- m_uriFactory->Release();
-
- if (m_fileFactory)
- m_fileFactory->Release();
-
- if (m_launcher)
- m_launcher->Release();
}
bool QWinRTServices::openUrl(const QUrl &url)
{
- if (!(m_uriFactory && m_launcher))
- return QPlatformServices::openUrl(url);
+ Q_D(QWinRTServices);
- IUriRuntimeClass *uri;
+ ComPtr<IUriRuntimeClass> uri;
QString urlString = url.toString();
- // ### TODO: Replace with HStringReference when WP8.0 support is removed
- HString uriString;
- uriString.Set((const wchar_t*)urlString.utf16(), urlString.length());
- m_uriFactory->CreateUri(uriString.Get(), &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();
+ HStringReference uriString(reinterpret_cast<LPCWSTR>(urlString.utf16()), urlString.length());
+ HRESULT hr = d->uriFactory->CreateUri(uriString.Get(), &uri);
+ RETURN_FALSE_IF_FAILED("Failed to create URI from QUrl.");
+
+ ComPtr<IAsyncOperation<bool>> op;
+ hr = d->launcher->LaunchUriAsync(uri.Get(), &op);
+ RETURN_FALSE_IF_FAILED("Failed to start URI launch.");
+
+ boolean result;
+ hr = QWinRTFunctions::await(op, &result);
+ RETURN_FALSE_IF_FAILED("Failed to launch URI.");
return result;
}
bool QWinRTServices::openDocument(const QUrl &url)
{
- if (!(m_fileFactory && m_launcher))
- return QPlatformServices::openDocument(url);
-
- const QString pathString = QDir::toNativeSeparators(url.toLocalFile());
- // ### TODO: Replace with HStringReference when WP8.0 support is removed
- HString path;
- path.Set((const wchar_t*)pathString.utf16(), pathString.length());
- IAsyncOperation<StorageFile*> *fileOp;
- m_fileFactory->GetFileFromPathAsync(path.Get(), &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();
+ Q_D(QWinRTServices);
+
+ HRESULT hr;
+ ComPtr<IStorageFile> file;
+ {
+ const QString pathString = QDir::toNativeSeparators(url.toLocalFile());
+ HStringReference path(reinterpret_cast<LPCWSTR>(pathString.utf16()), pathString.length());
+ ComPtr<IAsyncOperation<StorageFile *>> op;
+ hr = d->fileFactory->GetFileFromPathAsync(path.Get(), &op);
+ RETURN_FALSE_IF_FAILED("Failed to initialize file URI.");
+
+ hr = QWinRTFunctions::await(op, file.GetAddressOf());
+ RETURN_FALSE_IF_FAILED("Failed to get file URI.");
+ }
+
+ boolean result;
+ {
+ ComPtr<IAsyncOperation<bool>> op;
+ hr = d->launcher->LaunchFileAsync(file.Get(), &op);
+ RETURN_FALSE_IF_FAILED("Failed to start file launch.");
+
+ hr = QWinRTFunctions::await(op, &result);
+ RETURN_FALSE_IF_FAILED("Failed to launch file.");
+ }
return result;
}
diff --git a/src/plugins/platforms/winrt/qwinrtservices.h b/src/plugins/platforms/winrt/qwinrtservices.h
index 9cc917030a..d3abe6f2bd 100644
--- a/src/plugins/platforms/winrt/qwinrtservices.h
+++ b/src/plugins/platforms/winrt/qwinrtservices.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
@@ -43,23 +43,11 @@
#define QWINRTSERVICES_H
#include <qpa/qplatformservices.h>
+#include <QtCore/QScopedPointer>
-namespace ABI {
- namespace Windows {
- namespace Foundation {
- struct IUriRuntimeClassFactory;
- }
- namespace Storage {
- struct IStorageFileStatics;
- }
- namespace System {
- struct ILauncherStatics;
- }
- }
-}
-
-QT_BEGIN_NAMESPACE
+QT_USE_NAMESPACE
+class QWinRTServicesPrivate;
class QWinRTServices : public QPlatformServices
{
public:
@@ -70,11 +58,8 @@ public:
bool openDocument(const QUrl &url);
private:
- ABI::Windows::Foundation::IUriRuntimeClassFactory *m_uriFactory;
- ABI::Windows::Storage::IStorageFileStatics *m_fileFactory;
- ABI::Windows::System::ILauncherStatics *m_launcher;
+ QScopedPointer<QWinRTServicesPrivate> d_ptr;
+ Q_DECLARE_PRIVATE(QWinRTServices)
};
-QT_END_NAMESPACE
-
#endif // QWINRTSERVICES_H