1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
35 #include "qt4project.h"
36 #include "qt4projectmanager.h"
37 #include "qt4projectmanagerconstants.h"
38 #include "qt4target.h"
39 #include "modulespage.h"
40 #include "targetsetuppage.h"
42 #include <coreplugin/icore.h>
43 #include <coreplugin/editormanager/editormanager.h>
45 #include <cpptools/cpptoolsconstants.h>
47 #include <projectexplorer/projectexplorer.h>
48 #include <projectexplorer/task.h>
50 #include <extensionsystem/pluginmanager.h>
52 #include <QtCore/QCoreApplication>
53 #include <QtCore/QVariant>
55 using namespace Qt4ProjectManager;
56 using namespace Qt4ProjectManager::Internal;
58 static inline Core::BaseFileWizardParameters
59 wizardParameters(const QString &id,
60 const QString &category,
61 const QString &categoryTranslationScope,
62 const QString &displayCategory,
64 const QString &description,
67 Core::BaseFileWizardParameters rc(Core::IWizard::ProjectWizard);
68 rc.setCategory(category);
69 rc.setDisplayCategory(QCoreApplication::translate(categoryTranslationScope.toLatin1(),
70 displayCategory.toLatin1()));
72 rc.setDisplayName(name);
74 rc.setDescription(description);
78 // -------------------- QtWizard
79 QtWizard::QtWizard(const QString &id,
80 const QString &category,
81 const QString &categoryTranslationScope,
82 const QString &displayCategory,
84 const QString &description, const QIcon &icon) :
85 Core::BaseFileWizard(wizardParameters(id,
87 categoryTranslationScope,
95 QString QtWizard::sourceSuffix()
97 return preferredSuffix(QLatin1String(Constants::CPP_SOURCE_MIMETYPE));
100 QString QtWizard::headerSuffix()
102 return preferredSuffix(QLatin1String(Constants::CPP_HEADER_MIMETYPE));
105 QString QtWizard::formSuffix()
107 return preferredSuffix(QLatin1String(Constants::FORM_MIMETYPE));
110 QString QtWizard::profileSuffix()
112 return preferredSuffix(QLatin1String(Constants::PROFILE_MIMETYPE));
115 bool QtWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
117 return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage);
120 bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w,
121 const Core::GeneratedFiles &generatedFiles,
122 QString *errorMessage)
124 const BaseQt4ProjectWizardDialog *dialog = qobject_cast<const BaseQt4ProjectWizardDialog *>(w);
126 // Generate user settings
127 foreach (const Core::GeneratedFile &file, generatedFiles)
128 if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) {
129 dialog->writeUserFile(file.path());
133 // Post-Generate: Open the projects/editors
134 return ProjectExplorer::CustomProjectWizard::postGenerateOpen(generatedFiles ,errorMessage);
137 QString QtWizard::templateDir()
139 QString rc = Core::ICore::instance()->resourcePath();
140 rc += QLatin1String("/templates/qt4project");
144 bool QtWizard::lowerCaseFiles()
146 QString lowerCaseSettingsKey = QLatin1String(CppTools::Constants::CPPTOOLS_SETTINGSGROUP);
147 lowerCaseSettingsKey += QLatin1Char('/');
148 lowerCaseSettingsKey += QLatin1String(CppTools::Constants::LOWERCASE_CPPFILES_KEY);
149 const bool lowerCaseDefault = CppTools::Constants::lowerCaseFilesDefault;
150 return Core::ICore::instance()->settings()->value(lowerCaseSettingsKey, QVariant(lowerCaseDefault)).toBool();
153 bool QtWizard::showModulesPageForApplications()
158 bool QtWizard::showModulesPageForLibraries()
163 // ------------ CustomQt4ProjectWizard
164 CustomQt4ProjectWizard::CustomQt4ProjectWizard(const Core::BaseFileWizardParameters& baseFileParameters,
166 ProjectExplorer::CustomProjectWizard(baseFileParameters, parent)
170 QWizard *CustomQt4ProjectWizard::createWizardDialog(QWidget *parent,
171 const QString &defaultPath,
172 const WizardPageList &extensionPages) const
174 BaseQt4ProjectWizardDialog *wizard = new BaseQt4ProjectWizardDialog(false, parent);
175 initProjectWizardDialog(wizard, defaultPath, extensionPages);
176 if (wizard->pageIds().contains(targetPageId))
177 qWarning("CustomQt4ProjectWizard: Unable to insert target page at %d", int(targetPageId));
178 wizard->addTargetSetupPage(QSet<QString>(), false, targetPageId);
182 bool CustomQt4ProjectWizard::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage)
184 return QtWizard::qt4ProjectPostGenerateFiles(w, l, errorMessage);
187 void CustomQt4ProjectWizard::registerSelf()
189 ProjectExplorer::CustomWizard::registerFactory<CustomQt4ProjectWizard>(QLatin1String("qt4project"));
192 // ----------------- BaseQt4ProjectWizardDialog
193 BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage, QWidget *parent) :
194 ProjectExplorer::BaseProjectWizardDialog(parent),
198 init(showModulesPage);
201 BaseQt4ProjectWizardDialog::BaseQt4ProjectWizardDialog(bool showModulesPage,
202 Utils::ProjectIntroPage *introPage,
203 int introId, QWidget *parent) :
204 ProjectExplorer::BaseProjectWizardDialog(introPage, introId, parent),
208 init(showModulesPage);
211 BaseQt4ProjectWizardDialog::~BaseQt4ProjectWizardDialog()
213 if (m_targetSetupPage && !m_targetSetupPage->parent())
214 delete m_targetSetupPage;
215 if (m_modulesPage && !m_modulesPage->parent())
216 delete m_modulesPage;
219 void BaseQt4ProjectWizardDialog::init(bool showModulesPage)
222 m_modulesPage = new ModulesPage;
223 connect(this, SIGNAL(projectParametersChanged(QString,QString)),
224 this, SLOT(generateProfileName(QString,QString)));
227 int BaseQt4ProjectWizardDialog::addModulesPage(int id)
232 setPage(id, m_modulesPage);
233 wizardProgress()->item(id)->setTitle(tr("Modules"));
236 const int newId = addPage(m_modulesPage);
237 wizardProgress()->item(newId)->setTitle(tr("Modules"));
241 int BaseQt4ProjectWizardDialog::addTargetSetupPage(QSet<QString> targets, bool mobile, int id)
243 m_targetSetupPage = new TargetSetupPage;
247 m_targetSetupPage->setPreferMobile(mobile);
250 setPage(id, m_targetSetupPage);
252 id = addPage(m_targetSetupPage);
253 wizardProgress()->item(id)->setTitle(tr("Targets"));
258 QString BaseQt4ProjectWizardDialog::selectedModules() const
260 return m_modulesPage ? m_modulesPage->selectedModules() : m_selectedModules;
263 void BaseQt4ProjectWizardDialog::setSelectedModules(const QString &modules, bool lock)
266 foreach(const QString &module, modules.split(QLatin1Char(' '))) {
267 m_modulesPage->setModuleSelected(module, true);
268 m_modulesPage->setModuleEnabled(module, !lock);
271 m_selectedModules = modules;
275 QString BaseQt4ProjectWizardDialog::deselectedModules() const
277 return m_modulesPage ? m_modulesPage->deselectedModules() : m_deselectedModules;
280 void BaseQt4ProjectWizardDialog::setDeselectedModules(const QString &modules)
283 foreach(const QString &module, modules.split(QLatin1Char(' ')))
284 m_modulesPage->setModuleSelected(module, false);
286 m_deselectedModules = modules;
290 bool BaseQt4ProjectWizardDialog::writeUserFile(const QString &proFileName) const
292 if (!m_targetSetupPage)
295 Qt4Manager *manager = ExtensionSystem::PluginManager::instance()->getObject<Qt4Manager>();
298 Qt4Project *pro = new Qt4Project(manager, proFileName);
299 bool success = m_targetSetupPage->setupProject(pro);
306 bool BaseQt4ProjectWizardDialog::setupProject(Qt4Project *project) const
308 return m_targetSetupPage->setupProject(project);
311 bool BaseQt4ProjectWizardDialog::isTargetSelected(const QString &targetid) const
313 return m_targetSetupPage->isTargetSelected(targetid);
316 void BaseQt4ProjectWizardDialog::generateProfileName(const QString &name, const QString &path)
318 const QString proFile = QDir::fromNativeSeparators(path) + QChar('/') + name + QChar('/') + name + QLatin1String(".pro");
319 m_targetSetupPage->setProFilePath(proFile);
322 QSet<QString> BaseQt4ProjectWizardDialog::desktopTarget()
325 rc.insert(QLatin1String(Constants::DESKTOP_TARGET_ID));