1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "subdirsprojectwizard.h"
27 
28 #include "subdirsprojectwizarddialog.h"
29 #include "../qmakeprojectmanagerconstants.h"
30 
31 #include <projectexplorer/projectexplorerconstants.h>
32 #include <coreplugin/icore.h>
33 #include <qtsupport/qtsupportconstants.h>
34 
35 #include <utils/algorithm.h>
36 
37 #include <QCoreApplication>
38 
39 namespace QmakeProjectManager {
40 namespace Internal {
41 
SubdirsProjectWizard()42 SubdirsProjectWizard::SubdirsProjectWizard()
43 {
44     setId("U.Qt4Subdirs");
45     setCategory(QLatin1String(ProjectExplorer::Constants::QT_PROJECT_WIZARD_CATEGORY));
46     setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
47         ProjectExplorer::Constants::QT_PROJECT_WIZARD_CATEGORY_DISPLAY));
48     setDisplayName(tr("Subdirs Project"));
49     setDescription(tr("Creates a qmake-based subdirs project. This allows you to group "
50                 "your projects in a tree structure."));
51     setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
52     setRequiredFeatures({QtSupport::Constants::FEATURE_QT_PREFIX});
53 }
54 
create(QWidget * parent,const Core::WizardDialogParameters & parameters) const55 Core::BaseFileWizard *SubdirsProjectWizard::create(QWidget *parent,
56                                                    const Core::WizardDialogParameters &parameters) const
57 {
58     SubdirsProjectWizardDialog *dialog = new SubdirsProjectWizardDialog(this, displayName(), icon(),
59                                                                         parent, parameters);
60 
61     dialog->setProjectName(SubdirsProjectWizardDialog::uniqueProjectName(parameters.defaultPath()));
62     const QString buttonText = dialog->wizardStyle() == QWizard::MacStyle
63             ? tr("Done && Add Subproject") : tr("Finish && Add Subproject");
64     dialog->setButtonText(QWizard::FinishButton, buttonText);
65     return dialog;
66 }
67 
generateFiles(const QWizard * w,QString *) const68 Core::GeneratedFiles SubdirsProjectWizard::generateFiles(const QWizard *w,
69                                                          QString * /*errorMessage*/) const
70 {
71     const auto *wizard = qobject_cast< const SubdirsProjectWizardDialog *>(w);
72     const QtProjectParameters params = wizard->parameters();
73     const QString projectPath = params.projectPath();
74     const QString profileName = Core::BaseFileWizardFactory::buildFileName(projectPath, params.fileName, profileSuffix());
75 
76     Core::GeneratedFile profile(profileName);
77     profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute | Core::GeneratedFile::OpenEditorAttribute);
78     profile.setContents(QLatin1String("TEMPLATE = subdirs\n"));
79     return Core::GeneratedFiles() << profile;
80 }
81 
postGenerateFiles(const QWizard * w,const Core::GeneratedFiles & files,QString * errorMessage) const82 bool SubdirsProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &files,
83                                              QString *errorMessage) const
84 {
85     const auto *wizard = qobject_cast< const SubdirsProjectWizardDialog *>(w);
86     if (QtWizard::qt4ProjectPostGenerateFiles(wizard, files, errorMessage)) {
87         const QtProjectParameters params = wizard->parameters();
88         const QString projectPath = params.projectPath();
89         const QString profileName = Core::BaseFileWizardFactory::buildFileName(projectPath, params.fileName, profileSuffix());
90         QVariantMap map;
91         map.insert(QLatin1String(ProjectExplorer::Constants::PREFERRED_PROJECT_NODE), profileName);
92         map.insert(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS),
93                    Utils::transform<QStringList>(wizard->selectedKits(), &Utils::Id::toString));
94         IWizardFactory::requestNewItemDialog(tr("New Subproject", "Title of dialog"),
95                                              Utils::filtered(Core::IWizardFactory::allWizardFactories(),
96                                                              [](Core::IWizardFactory *f) {
97                                                                  return f->supportedProjectTypes().contains(Constants::QMAKEPROJECT_ID);
98                                                              }),
99                                              wizard->parameters().projectPath(), map);
100     } else {
101         return false;
102     }
103     return true;
104 }
105 
106 } // namespace Internal
107 } // namespace QmakeProjectManager
108