OSDN Git Service

84a5247e67b4f2d478eb4fda12f7ad1fb999af6a
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / baseprojectwizarddialog.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "baseprojectwizarddialog.h"
35
36 #include <coreplugin/basefilewizard.h>
37 #include <coreplugin/icore.h>
38 #include <coreplugin/filemanager.h>
39 #include <utils/projectintropage.h>
40
41 #include <QtCore/QDir>
42
43 namespace ProjectExplorer {
44
45 struct BaseProjectWizardDialogPrivate {
46     explicit BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id = -1);
47
48     const int desiredIntroPageId;
49     Utils::ProjectIntroPage *introPage;
50     int introPageId;
51 };
52
53 BaseProjectWizardDialogPrivate::BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id) :
54     desiredIntroPageId(id),
55     introPage(page),
56     introPageId(-1)
57 {
58 }
59
60 BaseProjectWizardDialog::BaseProjectWizardDialog(QWidget *parent) :
61     Utils::Wizard(parent),
62     d(new BaseProjectWizardDialogPrivate(new Utils::ProjectIntroPage))
63 {
64     init();
65 }
66
67 BaseProjectWizardDialog::BaseProjectWizardDialog(Utils::ProjectIntroPage *introPage,
68                                                  int introId,
69                                                  QWidget *parent) :
70     Utils::Wizard(parent),
71     d(new BaseProjectWizardDialogPrivate(introPage, introId))
72 {
73     init();
74 }
75
76 void BaseProjectWizardDialog::init()
77 {
78     Core::BaseFileWizard::setupWizard(this);
79     if (d->introPageId == -1) {
80         d->introPageId = addPage(d->introPage);
81     } else {
82         d->introPageId = d->desiredIntroPageId;
83         setPage(d->desiredIntroPageId, d->introPage);
84     }
85     wizardProgress()->item(d->introPageId)->setTitle(tr("Location"));
86     connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
87     connect(this, SIGNAL(nextClicked()), this, SLOT(nextClicked()));
88 }
89
90 BaseProjectWizardDialog::~BaseProjectWizardDialog()
91 {
92     delete d;
93 }
94
95 QString BaseProjectWizardDialog::projectName() const
96 {
97     return d->introPage->projectName();
98 }
99
100 QString BaseProjectWizardDialog::path() const
101 {
102     return d->introPage->path();
103 }
104
105 void BaseProjectWizardDialog::setIntroDescription(const QString &des)
106 {
107     d->introPage->setDescription(des);
108 }
109
110 void BaseProjectWizardDialog::setPath(const QString &path)
111 {
112     d->introPage->setPath(path);
113 }
114
115 void BaseProjectWizardDialog::setProjectName(const QString &name)
116 {
117     d->introPage->setProjectName(name);
118 }
119
120 void BaseProjectWizardDialog::slotAccepted()
121 {
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);
127     }
128 }
129
130 void BaseProjectWizardDialog::nextClicked()
131 {
132     if (currentId() == d->introPageId) {
133         emit projectParametersChanged(d->introPage->projectName(), d->introPage->path());
134     }
135 }
136
137 Utils::ProjectIntroPage *BaseProjectWizardDialog::introPage() const
138 {
139     return d->introPage;
140 }
141
142 QString BaseProjectWizardDialog::uniqueProjectName(const QString &path)
143 {
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;
150         if (i)
151             name += QString::number(i);
152         if (!pathDir.exists(name))
153             return name;
154     }
155     return prefix;
156 }
157 } // namespace ProjectExplorer