From 2993f898472340b4d753ef0d96650292afa2aa30 Mon Sep 17 00:00:00 2001
From: Christian Kandeler <christian.kandeler@nokia.com>
Date: Wed, 24 Nov 2010 14:51:30 +0100
Subject: [PATCH] ProjectExplorer: Add publishing infrastructure.

Reviewed-by: dt
---
 .../projectexplorer/projectexplorer.cpp       | 28 ++++++
 src/plugins/projectexplorer/projectexplorer.h |  2 +
 .../projectexplorer/projectexplorer.pro       | 12 ++-
 .../projectexplorerconstants.h                |  1 +
 .../publishing/ipublishingwizardfactory.h     | 96 ++++++++++++++++++
 .../publishingwizardselectiondialog.cpp       | 89 +++++++++++++++++
 .../publishingwizardselectiondialog.h         | 68 +++++++++++++
 .../publishingwizardselectiondialog.ui        | 98 +++++++++++++++++++
 8 files changed, 391 insertions(+), 3 deletions(-)
 create mode 100644 src/plugins/projectexplorer/publishing/ipublishingwizardfactory.h
 create mode 100644 src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.cpp
 create mode 100644 src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.h
 create mode 100644 src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.ui

diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 4abac06f66a..8e70440bd9e 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -76,6 +76,8 @@
 #include "buildconfigdialog.h"
 #include "miniprojecttargetselector.h"
 #include "taskhub.h"
+#include "publishing/ipublishingwizardfactory.h"
+#include "publishing/publishingwizardselectiondialog.h"
 
 #include <coreplugin/basemode.h>
 #include <coreplugin/coreconstants.h>
@@ -114,6 +116,7 @@
 #include <QtGui/QMenu>
 #include <QtGui/QMessageBox>
 #include <QtGui/QMainWindow>
+#include <QtGui/QWizard>
 
 Q_DECLARE_METATYPE(Core::IEditorFactory*);
 Q_DECLARE_METATYPE(Core::IExternalEditor*);
@@ -154,6 +157,7 @@ struct ProjectExplorerPluginPrivate {
     Utils::ParameterAction *m_deployAction;
     Utils::ParameterAction *m_deployActionContextMenu;
     QAction *m_deploySessionAction;
+    Utils::ParameterAction *m_publishAction;
     Utils::ParameterAction *m_cleanAction;
     Utils::ParameterAction *m_cleanActionContextMenu;
     QAction *m_cleanSessionAction;
@@ -613,6 +617,14 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     cmd->setDefaultText(d->m_deployAction->text());
     mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
 
+    // Publish action
+    d->m_publishAction = new Utils::ParameterAction(tr("Publish Project..."), tr("Publish Project \"%1\"..."),
+                                                    Utils::ParameterAction::AlwaysEnabled, this);
+    cmd = am->registerAction(d->m_publishAction, Constants::PUBLISH, globalcontext);
+    cmd->setAttribute(Core::Command::CA_UpdateText);
+    cmd->setDefaultText(d->m_publishAction->text());
+    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
+
     // clean action
     d->m_cleanAction = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
                                                      Utils::ParameterAction::AlwaysEnabled, this);
@@ -823,6 +835,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     connect(d->m_deployAction, SIGNAL(triggered()), this, SLOT(deployProject()));
     connect(d->m_deployActionContextMenu, SIGNAL(triggered()), this, SLOT(deployProjectContextMenu()));
     connect(d->m_deploySessionAction, SIGNAL(triggered()), this, SLOT(deploySession()));
+    connect(d->m_publishAction, SIGNAL(triggered()), this, SLOT(publishProject()));
     connect(d->m_cleanProjectOnlyAction, SIGNAL(triggered()), this, SLOT(cleanProjectOnly()));
     connect(d->m_cleanAction, SIGNAL(triggered()), this, SLOT(cleanProject()));
     connect(d->m_cleanActionContextMenu, SIGNAL(triggered()), this, SLOT(cleanProjectContextMenu()));
@@ -1023,6 +1036,19 @@ void ProjectExplorerPlugin::setStartupProject(Project *project)
     updateActions();
 }
 
+void ProjectExplorerPlugin::publishProject()
+{
+    const Project * const project = d->m_session->startupProject();
+    QTC_ASSERT(project, return);
+    PublishingWizardSelectionDialog selectionDialog(project);
+    if (selectionDialog.exec() == QDialog::Accepted) {
+        QWizard * const publishingWizard
+            = selectionDialog.createSelectedWizard();
+        publishingWizard->exec();
+        delete publishingWizard;
+    }
+}
+
 void ProjectExplorerPlugin::savePersistentSettings()
 {
     if (debug)
@@ -1479,6 +1505,8 @@ void ProjectExplorerPlugin::updateActions()
     d->m_cleanSessionAction->setEnabled(hasProjects && !building);
     d->m_cancelBuildAction->setEnabled(building);
 
+    d->m_publishAction->setEnabled(hasProjects);
+
     d->m_projectSelectorAction->setEnabled(!session()->projects().isEmpty());
     d->m_projectSelectorActionMenu->setEnabled(!session()->projects().isEmpty());
 
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index 3fa0a6038d0..324a9049f5d 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -206,6 +206,8 @@ private slots:
     void updateActions();
     void loadCustomWizards();
 
+    void publishProject();
+
 #ifdef WITH_TESTS
     void testGccOutputParsers_data();
     void testGccOutputParsers();
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index 1e2100f89e3..11b3873315d 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -96,7 +96,10 @@ HEADERS += projectexplorer.h \
     taskhub.h \
     localapplicationruncontrol.h \
     customexecutableconfigurationwidget.h \
-    sessionnodeimpl.h
+    sessionnodeimpl.h \
+    publishing/publishingwizardselectiondialog.h \
+    publishing/ipublishingwizardfactory.h
+
 SOURCES += projectexplorer.cpp \
     projectwindow.cpp \
     buildmanager.cpp \
@@ -177,7 +180,9 @@ SOURCES += projectexplorer.cpp \
     processparameters.cpp \
     localapplicationruncontrol.cpp \
     customexecutableconfigurationwidget.cpp \
-    sessionnodeimpl.cpp
+    sessionnodeimpl.cpp \
+    publishing/publishingwizardselectiondialog.cpp
+
 FORMS += processstep.ui \
     editorsettingspropertiespage.ui \
     runsettingspropertiespage.ui \
@@ -187,7 +192,8 @@ FORMS += processstep.ui \
     projectexplorersettingspage.ui \
     projectwelcomepagewidget.ui \
     targetsettingswidget.ui \
-    doubletabwidget.ui
+    doubletabwidget.ui \
+    publishing/publishingwizardselectiondialog.ui
 
 equals(TEST, 1) {
     SOURCES += \
diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h
index f081a65ca29..0390e35e62c 100644
--- a/src/plugins/projectexplorer/projectexplorerconstants.h
+++ b/src/plugins/projectexplorer/projectexplorerconstants.h
@@ -57,6 +57,7 @@ const char * const DEPLOYPROJECTONLY    = "ProjectExplorer.DeployProjectOnly";
 const char * const DEPLOY               = "ProjectExplorer.Deploy";
 const char * const DEPLOYCM             = "ProjectExplorer.DeployCM";
 const char * const DEPLOYSESSION        = "ProjectExplorer.DeploySession";
+const char * const PUBLISH              = "ProjectExplorer.Publish";
 const char * const CLEANPROJECTONLY     = "ProjectExplorer.CleanProjectOnly";
 const char * const CLEAN                = "ProjectExplorer.Clean";
 const char * const CLEANCM              = "ProjectExplorer.CleanCM";
diff --git a/src/plugins/projectexplorer/publishing/ipublishingwizardfactory.h b/src/plugins/projectexplorer/publishing/ipublishingwizardfactory.h
new file mode 100644
index 00000000000..18acd0d55b6
--- /dev/null
+++ b/src/plugins/projectexplorer/publishing/ipublishingwizardfactory.h
@@ -0,0 +1,96 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+#ifndef IPUBLISHING_WIZARD_FACTORY_H
+#define IPUBLISHING_WIZARD_FACTORY_H
+
+#include <projectexplorer/projectexplorer_export.h>
+
+#include <extensionsystem/pluginmanager.h>
+
+#include <QtCore/QList>
+#include <QtGui/QWizard>
+
+namespace ProjectExplorer {
+class Project;
+
+/*!
+  \class ProjectExplorer::IPublishingWizardFactory
+
+  \brief Provides an interface for creating wizards to publish a project.
+
+  A class implementing this interface is used to create an associated wizard
+  that allows users to publish their project to a remote facility, e.g. an
+  app store.
+  Such a wizard would typically transform the project's content into
+  a form expected by that facility ("packaging") and also upload it, if possible.
+
+  The factory objects have to be added to the global object pool via
+  \c ExtensionSystem::PluginManager::addObject().
+  \sa ExtensionSystem::PluginManager::addObject()
+*/
+
+class PROJECTEXPLORER_EXPORT IPublishingWizardFactory : public QObject
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(IPublishingWizardFactory)
+public:
+    /*!
+      A short, one-line description of the type of wizard that this
+      factory can create.
+    */
+    virtual QString displayName() const=0;
+
+    /*!
+      A longer description explaining the exact purpose of the wizard
+      created by this factory.
+    */
+    virtual QString description() const=0;
+
+    /*!
+      Returns true iff the type of wizard that this factory can create
+      is available for the given project.
+    */
+    virtual bool canCreateWizard(const Project *project) const=0;
+
+    /*!
+      Creates a wizard that can publish the given project.
+      Behavior is undefined if canCreateWizard() returns false for
+      that project.
+      \return The newly created publishing wizard
+      \sa canCreateWizard()
+    */
+    virtual QWizard *createWizard(const Project *project) const=0;
+
+protected:
+    IPublishingWizardFactory(QObject *parent = 0) : QObject(parent) {}
+};
+
+} // namespace ProjectExplorer
+
+#endif // IPUBLISHING_WIZARD_FACTORY_H
diff --git a/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.cpp b/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.cpp
new file mode 100644
index 00000000000..bf8df3da432
--- /dev/null
+++ b/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.cpp
@@ -0,0 +1,89 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+#include "publishingwizardselectiondialog.h"
+#include "ui_publishingwizardselectiondialog.h"
+
+#include "ipublishingwizardfactory.h"
+
+#include <extensionsystem/pluginmanager.h>
+#include <projectexplorer/project.h>
+#include <utils/qtcassert.h>
+
+#include <QtGui/QPushButton>
+
+namespace ProjectExplorer {
+namespace Internal {
+
+PublishingWizardSelectionDialog::PublishingWizardSelectionDialog(const Project *project,
+        QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::PublishingWizardSelectionDialog),
+    m_project(project)
+{
+    ui->setupUi(this);
+    ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Start Wizard"));
+    const QList<IPublishingWizardFactory *> &factories
+        = ExtensionSystem::PluginManager::instance()->getObjects<IPublishingWizardFactory>();
+    foreach (const IPublishingWizardFactory * const factory, factories) {
+        if (factory->canCreateWizard(project)) {
+            m_factories << factory;
+            ui->serviceComboBox->addItem(factory->displayName());
+        }
+    }
+    if (!m_factories.isEmpty()) {
+        connect(ui->serviceComboBox, SIGNAL(currentIndexChanged(int)),
+            SLOT(handleWizardIndexChanged(int)));
+        ui->serviceComboBox->setCurrentIndex(0);
+        handleWizardIndexChanged(ui->serviceComboBox->currentIndex());
+    } else {
+        ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+        ui->descriptionTextArea->appendHtml(QLatin1String("<font color=\"red\">")
+            + tr("Publishing is currently not possible for project '%1'.")
+                  .arg(project->displayName())
+            + QLatin1String("</font>"));
+    }
+}
+
+PublishingWizardSelectionDialog::~PublishingWizardSelectionDialog()
+{
+    delete ui;
+}
+
+QWizard *PublishingWizardSelectionDialog::createSelectedWizard() const
+{
+    return m_factories.at(ui->serviceComboBox->currentIndex())->createWizard(m_project);
+}
+
+void PublishingWizardSelectionDialog::handleWizardIndexChanged(int index)
+{
+    ui->descriptionTextArea->setPlainText(m_factories.at(index)->description());
+}
+
+} // namespace Internal
+} // namespace ProjectExplorer
diff --git a/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.h b/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.h
new file mode 100644
index 00000000000..7f8a018bcf2
--- /dev/null
+++ b/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.h
@@ -0,0 +1,68 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+#ifndef PUBLISHINGWIZARDSELECTIONDIALOG_H
+#define PUBLISHINGWIZARDSELECTIONDIALOG_H
+
+#include <QtCore/QList>
+#include <QtGui/QDialog>
+
+QT_FORWARD_DECLARE_CLASS(QWizard);
+
+namespace ProjectExplorer {
+class IPublishingWizardFactory;
+class Project;
+namespace Internal {
+namespace Ui {
+class PublishingWizardSelectionDialog;
+}
+
+class PublishingWizardSelectionDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit PublishingWizardSelectionDialog(const Project *project,
+        QWidget *parent = 0);
+    ~PublishingWizardSelectionDialog();
+    QWizard *createSelectedWizard() const;
+
+private slots:
+    void handleWizardIndexChanged(int index);
+
+private:
+    Ui::PublishingWizardSelectionDialog *ui;
+
+    const Project * const m_project;
+    QList<const IPublishingWizardFactory *> m_factories;
+};
+
+} // namespace Internal
+} // namespace ProjectExplorer
+
+#endif // PUBLISHINGWIZARDSELECTIONDIALOG_H
diff --git a/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.ui b/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.ui
new file mode 100644
index 00000000000..84078fb7c2c
--- /dev/null
+++ b/src/plugins/projectexplorer/publishing/publishingwizardselectiondialog.ui
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ProjectExplorer::Internal::PublishingWizardSelectionDialog</class>
+ <widget class="QDialog" name="ProjectExplorer::Internal::PublishingWizardSelectionDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>409</width>
+    <height>330</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Publishing Wizard Selection</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Available Wizards:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="serviceComboBox"/>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QPlainTextEdit" name="descriptionTextArea">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>ProjectExplorer::Internal::PublishingWizardSelectionDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>ProjectExplorer::Internal::PublishingWizardSelectionDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
-- 
GitLab