1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "baseprojectwizarddialog.h"
36 #include <coreplugin/basefilewizard.h>
37 #include <coreplugin/icore.h>
38 #include <coreplugin/filemanager.h>
39 #include <utils/projectintropage.h>
41 #include <QtCore/QDir>
43 namespace ProjectExplorer {
45 struct BaseProjectWizardDialogPrivate {
46 explicit BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id = -1);
48 const int desiredIntroPageId;
49 Utils::ProjectIntroPage *introPage;
53 BaseProjectWizardDialogPrivate::BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id) :
54 desiredIntroPageId(id),
60 BaseProjectWizardDialog::BaseProjectWizardDialog(QWidget *parent) :
61 Utils::Wizard(parent),
62 d(new BaseProjectWizardDialogPrivate(new Utils::ProjectIntroPage))
67 BaseProjectWizardDialog::BaseProjectWizardDialog(Utils::ProjectIntroPage *introPage,
70 Utils::Wizard(parent),
71 d(new BaseProjectWizardDialogPrivate(introPage, introId))
76 void BaseProjectWizardDialog::init()
78 Core::BaseFileWizard::setupWizard(this);
79 if (d->introPageId == -1) {
80 d->introPageId = addPage(d->introPage);
82 d->introPageId = d->desiredIntroPageId;
83 setPage(d->desiredIntroPageId, d->introPage);
85 wizardProgress()->item(d->introPageId)->setTitle(tr("Location"));
86 connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
87 connect(this, SIGNAL(nextClicked()), this, SLOT(nextClicked()));
90 BaseProjectWizardDialog::~BaseProjectWizardDialog()
95 QString BaseProjectWizardDialog::projectName() const
97 return d->introPage->projectName();
100 QString BaseProjectWizardDialog::path() const
102 return d->introPage->path();
105 void BaseProjectWizardDialog::setIntroDescription(const QString &des)
107 d->introPage->setDescription(des);
110 void BaseProjectWizardDialog::setPath(const QString &path)
112 d->introPage->setPath(path);
115 void BaseProjectWizardDialog::setProjectName(const QString &name)
117 d->introPage->setProjectName(name);
120 void BaseProjectWizardDialog::slotAccepted()
122 if (d->introPage->useAsDefaultPath()) {
123 // Store the path as default path for new projects if desired.
124 Core::FileManager *fm = Core::ICore::instance()->fileManager();
125 fm->setProjectsDirectory(path());
126 fm->setUseProjectsDirectory(true);
130 void BaseProjectWizardDialog::nextClicked()
132 if (currentId() == d->introPageId) {
133 emit projectParametersChanged(d->introPage->projectName(), d->introPage->path());
137 Utils::ProjectIntroPage *BaseProjectWizardDialog::introPage() const
142 QString BaseProjectWizardDialog::uniqueProjectName(const QString &path)
144 const QDir pathDir(path);
145 //: File path suggestion for a new project. If you choose
146 //: to translate it, make sure it is a valid path name without blanks.
147 const QString prefix = tr("untitled");
148 for (unsigned i = 0; ; i++) {
149 QString name = prefix;
151 name += QString::number(i);
152 if (!pathDir.exists(name))
157 } // namespace ProjectExplorer