abstractmobileappwizard.cpp 5.99 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30

#include "abstractmobileappwizard.h"
31
#include "abstractmobileapp.h"
32

33
#include "../qmakeprojectimporter.h"
34 35

#include <extensionsystem/pluginmanager.h>
36 37
#include <qmakeprojectmanager/qmakeproject.h>
#include <qmakeprojectmanager/qmakeprojectmanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
38
#include <qtsupport/qtsupportconstants.h>
Tobias Hunger's avatar
Tobias Hunger committed
39
#include <qtsupport/qtkitinformation.h>
40
#include <projectexplorer/projectexplorer.h>
41
#include <projectexplorer/targetsetuppage.h>
42
#include <projectexplorer/customwizard/customwizard.h>
43
#include <projectexplorer/session.h>
44
#include <coreplugin/editormanager/editormanager.h>
45

46
using namespace Core;
47
using namespace ProjectExplorer;
48
using namespace QtSupport;
49

50
namespace QmakeProjectManager {
51

52 53
AbstractMobileAppWizardDialog::AbstractMobileAppWizardDialog(QWidget *parent,
                                                             const QtSupport::QtVersionNumber &minimumQtVersionNumber,
54 55 56
                                                             const QtSupport::QtVersionNumber &maximumQtVersionNumber,
                                                             const Core::WizardDialogParameters &parameters)
    : ProjectExplorer::BaseProjectWizardDialog(parent, parameters)
57
    , m_kitsPage(0)
58 59
    , m_minimumQtVersionNumber(minimumQtVersionNumber)
    , m_maximumQtVersionNumber(maximumQtVersionNumber)
60
{
61
    if (!parameters.extraValues().contains(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS))) {
62
        m_kitsPage = new ProjectExplorer::TargetSetupPage;
63 64 65 66 67 68 69 70
        updateKitsPage();
        resize(900, 450);
    }
}

void AbstractMobileAppWizardDialog::addKitsPage()
{
    if (m_kitsPage)
71
        addPage(m_kitsPage);
72 73 74 75 76
}

void AbstractMobileAppWizardDialog::updateKitsPage()
{
    if (m_kitsPage) {
77 78
        QString platform = selectedPlatform();
        if (platform.isEmpty()) {
79
            m_kitsPage->setPreferredKitMatcher(
80
                QtKitInformation::qtVersionMatcher(FeatureSet(QtSupport::Constants::FEATURE_MOBILE)));
81
        } else {
82
            m_kitsPage->setPreferredKitMatcher(QtKitInformation::platformMatcher(platform));
83
        }
84 85 86
        m_kitsPage->setRequiredKitMatcher(QtKitInformation::qtVersionMatcher(requiredFeatures(),
                                                                           m_minimumQtVersionNumber,
                                                                           m_maximumQtVersionNumber));
87
    }
Feetu Nyrhinen's avatar
Feetu Nyrhinen committed
88 89
}

90
ProjectExplorer::TargetSetupPage *AbstractMobileAppWizardDialog::kitsPage() const
91
{
92
    return m_kitsPage;
93 94
}

Tobias Hunger's avatar
Tobias Hunger committed
95
Core::BaseFileWizard *AbstractMobileAppWizard::create(QWidget *parent, const Core::WizardDialogParameters &parameters) const
96
{
Tobias Hunger's avatar
Tobias Hunger committed
97
    AbstractMobileAppWizardDialog * const wdlg = createInternal(parent, parameters);
98
    wdlg->setProjectName(ProjectExplorer::BaseProjectWizardDialog::uniqueProjectName(parameters.defaultPath()));
Robert Loehning's avatar
Robert Loehning committed
99 100
    connect(wdlg, SIGNAL(projectParametersChanged(QString,QString)),
        SLOT(useProjectPath(QString,QString)));
101
    wdlg->addExtensionPages(parameters.extensionPages());
102

103 104 105 106 107 108
    return wdlg;
}

Core::GeneratedFiles AbstractMobileAppWizard::generateFiles(const QWizard *wizard,
    QString *errorMessage) const
{
Feetu Nyrhinen's avatar
Feetu Nyrhinen committed
109
    prepareGenerateFiles(wizard, errorMessage);
110 111 112
    return app()->generateFiles(errorMessage);
}

113 114 115
bool AbstractMobileAppWizard::postGenerateFiles(const QWizard *w,
    const Core::GeneratedFiles &l, QString *errorMessage)
{
116 117 118
    Q_UNUSED(w)
    Q_UNUSED(l)
    Q_UNUSED(errorMessage)
119 120
    QmakeManager * const manager
        = ExtensionSystem::PluginManager::getObject<QmakeManager>();
121
    Q_ASSERT(manager);
122
    QmakeProject project(manager, app()->path(AbstractMobileApp::AppPro));
123
    bool success = true;
124 125
    if (wizardDialog()->kitsPage()) {
        success = wizardDialog()->kitsPage()->setupProject(&project);
126
        if (success) {
127 128 129 130 131 132 133
            project.saveSettings();
            success = ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
        }
    }
    if (success) {
        const QString fileToOpen = fileToOpenPostGeneration();
        if (!fileToOpen.isEmpty()) {
134 135 136
            EditorManager::openEditor(fileToOpen);
            Project *project = SessionManager::projectForFile(fileToOpen);
            ProjectExplorerPlugin::setCurrentFile(project, fileToOpen);
137
        }
138 139 140 141
    }
    return success;
}

142 143 144
void AbstractMobileAppWizard::useProjectPath(const QString &projectName,
    const QString &projectPath)
{
145 146
    app()->setProjectName(projectName);
    app()->setProjectPath(projectPath);
147 148
    if (wizardDialog()->kitsPage())
        wizardDialog()->kitsPage()->setProjectPath(app()->path(AbstractMobileApp::AppPro));
149
    projectPathChanged(app()->path(AbstractMobileApp::AppPro));
150 151
}

152
} // namespace QmakeProjectManager