From 8f1b78bf8acf1aa3ae5ee9c7598294f5656c4960 Mon Sep 17 00:00:00 2001
From: Joerg Bornemann <joerg.bornemann@digia.com>
Date: Thu, 13 Mar 2014 12:32:17 +0100
Subject: [PATCH] WinRt: add windeployqt configuration widget

A simple line edit to display or change the arguments that are
passed to windeployqt.

Task-number: QTCREATORBUG-11693

Change-Id: I059f5c2af3fce17f9f8463ecfa2af91f21ffe6d8
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
---
 src/plugins/winrt/winrt.pro                   |  3 +
 src/plugins/winrt/winrt.qbs                   |  3 +
 src/plugins/winrt/winrtconstants.h            |  1 +
 .../winrt/winrtpackagedeploymentstep.cpp      | 45 ++++++++++--
 .../winrt/winrtpackagedeploymentstep.h        | 10 +++
 .../winrtpackagedeploymentstepwidget.cpp      | 73 +++++++++++++++++++
 .../winrt/winrtpackagedeploymentstepwidget.h  | 64 ++++++++++++++++
 .../winrt/winrtpackagedeploymentstepwidget.ui | 47 ++++++++++++
 8 files changed, 241 insertions(+), 5 deletions(-)
 create mode 100644 src/plugins/winrt/winrtpackagedeploymentstepwidget.cpp
 create mode 100644 src/plugins/winrt/winrtpackagedeploymentstepwidget.h
 create mode 100644 src/plugins/winrt/winrtpackagedeploymentstepwidget.ui

diff --git a/src/plugins/winrt/winrt.pro b/src/plugins/winrt/winrt.pro
index 85c18c7c06..f86adb8fcd 100644
--- a/src/plugins/winrt/winrt.pro
+++ b/src/plugins/winrt/winrt.pro
@@ -6,6 +6,7 @@ HEADERS += \
     winrtdevice.h \
     winrtdevicefactory.h \
     winrtpackagedeploymentstep.h \
+    winrtpackagedeploymentstepwidget.h \
     winrtphoneqtversion.h \
     winrtplugin.h \
     winrtqtversion.h \
@@ -20,6 +21,7 @@ SOURCES += \
     winrtdevice.cpp \
     winrtdevicefactory.cpp \
     winrtpackagedeploymentstep.cpp \
+    winrtpackagedeploymentstepwidget.cpp \
     winrtphoneqtversion.cpp \
     winrtplugin.cpp \
     winrtqtversion.cpp \
@@ -32,4 +34,5 @@ SOURCES += \
 DEFINES += WINRT_LIBRARY
 
 FORMS += \
+    winrtpackagedeploymentstepwidget.ui \
     winrtrunconfigurationwidget.ui
diff --git a/src/plugins/winrt/winrt.qbs b/src/plugins/winrt/winrt.qbs
index 0b6d180f81..45f3e3acee 100644
--- a/src/plugins/winrt/winrt.qbs
+++ b/src/plugins/winrt/winrt.qbs
@@ -21,6 +21,9 @@ QtcPlugin {
         "winrtdevicefactory.h",
         "winrtpackagedeploymentstep.cpp",
         "winrtpackagedeploymentstep.h",
+        "winrtpackagedeploymentstepwidget.cpp",
+        "winrtpackagedeploymentstepwidget.h",
+        "winrtpackagedeploymentstepwidget.ui",
         "winrtphoneqtversion.cpp",
         "winrtphoneqtversion.h",
         "winrtplugin.cpp",
diff --git a/src/plugins/winrt/winrtconstants.h b/src/plugins/winrt/winrtconstants.h
index a573a4fc6d..3704603cff 100644
--- a/src/plugins/winrt/winrtconstants.h
+++ b/src/plugins/winrt/winrtconstants.h
@@ -37,6 +37,7 @@ const char WINRT_DEVICE_TYPE_LOCAL[] = "WinRt.Device.Local";
 const char WINRT_DEVICE_TYPE_EMULATOR[] = "WinRt.Device.Emulator";
 const char WINRT_DEVICE_TYPE_PHONE[] = "WinRt.Device.Phone";
 const char WINRT_BUILD_STEP_DEPLOY[] = "WinRt.BuildStep.Deploy";
+const char WINRT_BUILD_STEP_DEPLOY_ARGUMENTS[] = "WinRt.BuildStep.Deploy.Arguments";
 const char WINRT_WINRTQT[] = "WinRt.QtVersion.WindowsRuntime";
 const char WINRT_WINPHONEQT[] = "WinRt.QtVersion.WindowsPhone";
 const char WINRT_QTMAP_SUBKEYNAME[] = "WinRt";
diff --git a/src/plugins/winrt/winrtpackagedeploymentstep.cpp b/src/plugins/winrt/winrtpackagedeploymentstep.cpp
index d648d46713..ae4585230a 100644
--- a/src/plugins/winrt/winrtpackagedeploymentstep.cpp
+++ b/src/plugins/winrt/winrtpackagedeploymentstep.cpp
@@ -28,6 +28,7 @@
 ****************************************************************************/
 
 #include "winrtpackagedeploymentstep.h"
+#include "winrtpackagedeploymentstepwidget.h"
 #include "winrtconstants.h"
 
 #include <projectexplorer/project.h>
@@ -46,6 +47,7 @@ WinRtPackageDeploymentStep::WinRtPackageDeploymentStep(BuildStepList *bsl)
     : AbstractProcessStep(bsl, Constants::WINRT_BUILD_STEP_DEPLOY)
 {
     setDisplayName(tr("Deploy Qt binaries and application files to output directory"));
+    m_args = defaultWinDeployQtArguments();
 }
 
 bool WinRtPackageDeploymentStep::init()
@@ -57,10 +59,8 @@ bool WinRtPackageDeploymentStep::init()
     // ### Actually, targetForProject is supposed to return the file path including the file
     // extension. Whenever this will eventually work, we have to remove the .exe suffix here.
 
-    QString args;
-    QtcProcess::addArg(&args, QDir::toNativeSeparators(targetPath));
-    QtcProcess::addArg(&args, QStringLiteral("--qmldir"));
-    QtcProcess::addArg(&args, QDir::toNativeSeparators(project()->projectDirectory()));
+    QString args = QtcProcess::quoteArg(QDir::toNativeSeparators(targetPath));
+    args += QLatin1Char(' ') + m_args;
 
     ProcessParameters *params = processParameters();
     params->setCommand(QLatin1String("windeployqt.exe"));
@@ -72,7 +72,42 @@ bool WinRtPackageDeploymentStep::init()
 
 BuildStepConfigWidget *WinRtPackageDeploymentStep::createConfigWidget()
 {
-    return new SimpleBuildStepConfigWidget(this);
+    return new WinRtPackageDeploymentStepWidget(this);
+}
+
+void WinRtPackageDeploymentStep::setWinDeployQtArguments(const QString &args)
+{
+    m_args = args;
+}
+
+QString WinRtPackageDeploymentStep::winDeployQtArguments() const
+{
+    return m_args;
+}
+
+QString WinRtPackageDeploymentStep::defaultWinDeployQtArguments() const
+{
+    QString args;
+    QtcProcess::addArg(&args, QStringLiteral("--qmldir"));
+    QtcProcess::addArg(&args, QDir::toNativeSeparators(project()->projectDirectory()));
+    return args;
+}
+
+bool WinRtPackageDeploymentStep::fromMap(const QVariantMap &map)
+{
+    if (!AbstractProcessStep::fromMap(map))
+        return false;
+    QVariant v = map.value(QLatin1String(Constants::WINRT_BUILD_STEP_DEPLOY_ARGUMENTS));
+    if (v.isValid())
+        m_args = v.toString();
+    return true;
+}
+
+QVariantMap WinRtPackageDeploymentStep::toMap() const
+{
+    QVariantMap map = AbstractProcessStep::toMap();
+    map.insert(QLatin1String(Constants::WINRT_BUILD_STEP_DEPLOY_ARGUMENTS), m_args);
+    return map;
 }
 
 } // namespace Internal
diff --git a/src/plugins/winrt/winrtpackagedeploymentstep.h b/src/plugins/winrt/winrtpackagedeploymentstep.h
index 8d51f741fa..592395827b 100644
--- a/src/plugins/winrt/winrtpackagedeploymentstep.h
+++ b/src/plugins/winrt/winrtpackagedeploymentstep.h
@@ -42,6 +42,16 @@ public:
     explicit WinRtPackageDeploymentStep(ProjectExplorer::BuildStepList *bsl);
     bool init();
     ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
+
+    void setWinDeployQtArguments(const QString &args);
+    QString winDeployQtArguments() const;
+    QString defaultWinDeployQtArguments() const;
+
+    bool fromMap(const QVariantMap &map);
+    QVariantMap toMap() const;
+
+private:
+    QString m_args;
 };
 
 } // namespace Internal
diff --git a/src/plugins/winrt/winrtpackagedeploymentstepwidget.cpp b/src/plugins/winrt/winrtpackagedeploymentstepwidget.cpp
new file mode 100644
index 0000000000..ad0ec2c094
--- /dev/null
+++ b/src/plugins/winrt/winrtpackagedeploymentstepwidget.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "winrtpackagedeploymentstepwidget.h"
+#include <ui_winrtpackagedeploymentstepwidget.h>
+#include <coreplugin/coreconstants.h>
+#include <QIcon>
+
+namespace WinRt {
+namespace Internal {
+
+WinRtPackageDeploymentStepWidget::WinRtPackageDeploymentStepWidget(WinRtPackageDeploymentStep *step)
+    : m_ui(new Ui::WinRtPackageDeploymentStepWidget)
+    , m_step(step)
+{
+    m_ui->setupUi(this);
+    m_ui->leArguments->setText(m_step->winDeployQtArguments());
+    m_ui->btnRestoreDefaultArgs->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RESET)));
+}
+
+WinRtPackageDeploymentStepWidget::~WinRtPackageDeploymentStepWidget()
+{
+    delete m_ui;
+}
+
+QString WinRtPackageDeploymentStepWidget::summaryText() const
+{
+    return QStringLiteral("<b>") + displayName() + QStringLiteral("</b>");
+}
+
+QString WinRtPackageDeploymentStepWidget::displayName() const
+{
+    return m_step->displayName();
+}
+
+void WinRtPackageDeploymentStepWidget::on_btnRestoreDefaultArgs_clicked()
+{
+    m_ui->leArguments->setText(m_step->defaultWinDeployQtArguments());
+}
+
+void WinRtPackageDeploymentStepWidget::on_leArguments_textChanged(QString str)
+{
+    m_step->setWinDeployQtArguments(str);
+}
+
+} // namespace Internal
+} // namespace WinRt
diff --git a/src/plugins/winrt/winrtpackagedeploymentstepwidget.h b/src/plugins/winrt/winrtpackagedeploymentstepwidget.h
new file mode 100644
index 0000000000..beb136fc10
--- /dev/null
+++ b/src/plugins/winrt/winrtpackagedeploymentstepwidget.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef WINRTPACKAGEDEPLOYMENTSTEPWIDGET_H
+#define WINRTPACKAGEDEPLOYMENTSTEPWIDGET_H
+
+#include "winrtpackagedeploymentstep.h"
+
+#include <projectexplorer/buildstep.h>
+
+namespace WinRt {
+namespace Internal {
+
+namespace Ui { class WinRtPackageDeploymentStepWidget; }
+
+class WinRtPackageDeploymentStepWidget : public ProjectExplorer::BuildStepConfigWidget
+{
+    Q_OBJECT
+public:
+    WinRtPackageDeploymentStepWidget(WinRtPackageDeploymentStep *step);
+    ~WinRtPackageDeploymentStepWidget();
+
+    virtual QString summaryText() const;
+    virtual QString displayName() const;
+
+private slots:
+    void on_btnRestoreDefaultArgs_clicked();
+    void on_leArguments_textChanged(QString str);
+
+private:
+    Ui::WinRtPackageDeploymentStepWidget *m_ui;
+    WinRtPackageDeploymentStep *m_step;
+};
+
+} // namespace Internal
+} // namespace WinRt
+
+#endif // WINRTPACKAGEDEPLOYMENTSTEPWIDGET_H
diff --git a/src/plugins/winrt/winrtpackagedeploymentstepwidget.ui b/src/plugins/winrt/winrtpackagedeploymentstepwidget.ui
new file mode 100644
index 0000000000..e3ce32adfc
--- /dev/null
+++ b/src/plugins/winrt/winrtpackagedeploymentstepwidget.ui
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WinRt::Internal::WinRtPackageDeploymentStepWidget</class>
+ <widget class="QWidget" name="WinRt::Internal::WinRtPackageDeploymentStepWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>59</height>
+   </rect>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Arguments:</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLineEdit" name="leArguments"/>
+   </item>
+   <item>
+    <widget class="QToolButton" name="btnRestoreDefaultArgs">
+     <property name="text">
+      <string>Restore Default Arguments</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
-- 
GitLab