baseprojectwizarddialog.cpp 4.76 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
30
31
32
33
34
35
36
37
38
39
40
41
**
**************************************************************************/

#include "baseprojectwizarddialog.h"

#include <coreplugin/basefilewizard.h>
#include <coreplugin/icore.h>
#include <coreplugin/filemanager.h>
#include <utils/projectintropage.h>

#include <QtCore/QDir>

42
43
44
45
46
/*!
    \class ProjectExplorer::BaseProjectWizardDialog

    \brief Base class for project wizards.

47
    Presents the introductory page and takes care of setting the folder chosen
48
49
50
    as default projects' folder should the user wish to do that.
*/

51
52
namespace ProjectExplorer {

53
struct BaseProjectWizardDialogPrivate {
54
55
    explicit BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id = -1);

56
    const int desiredIntroPageId;
57
    Utils::ProjectIntroPage *introPage;
58
    int introPageId;
59
60
61
};

BaseProjectWizardDialogPrivate::BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id) :
62
63
    desiredIntroPageId(id),
    introPage(page),
64
    introPageId(-1)
65
66
67
68
{
}

BaseProjectWizardDialog::BaseProjectWizardDialog(QWidget *parent) :
69
    Utils::Wizard(parent),
70
71
72
73
74
75
76
77
    d(new BaseProjectWizardDialogPrivate(new Utils::ProjectIntroPage))
{
    init();
}

BaseProjectWizardDialog::BaseProjectWizardDialog(Utils::ProjectIntroPage *introPage,
                                                 int introId,
                                                 QWidget *parent) :
78
    Utils::Wizard(parent),
79
80
81
82
83
84
85
86
    d(new BaseProjectWizardDialogPrivate(introPage, introId))
{
    init();
}

void BaseProjectWizardDialog::init()
{
    Core::BaseFileWizard::setupWizard(this);
87
88
89
90
91
92
    if (d->introPageId == -1) {
        d->introPageId = addPage(d->introPage);
    } else {
        d->introPageId = d->desiredIntroPageId;
        setPage(d->desiredIntroPageId, d->introPage);
    }
93
    wizardProgress()->item(d->introPageId)->setTitle(tr("Location"));
94
    connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted()));
95
    connect(this, SIGNAL(nextClicked()), this, SLOT(nextClicked()));
96
97
98
99
100
101
102
}

BaseProjectWizardDialog::~BaseProjectWizardDialog()
{
    delete d;
}

103
QString BaseProjectWizardDialog::projectName() const
104
{
105
    return d->introPage->projectName();
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
}

QString BaseProjectWizardDialog::path() const
{
    return d->introPage->path();
}

void BaseProjectWizardDialog::setIntroDescription(const QString &des)
{
    d->introPage->setDescription(des);
}

void BaseProjectWizardDialog::setPath(const QString &path)
{
    d->introPage->setPath(path);
}

123
void BaseProjectWizardDialog::setProjectName(const QString &name)
124
{
125
    d->introPage->setProjectName(name);
126
127
128
129
130
}

void BaseProjectWizardDialog::slotAccepted()
{
    if (d->introPage->useAsDefaultPath()) {
131
        // Store the path as default path for new projects if desired.
132
133
        Core::FileManager::setProjectsDirectory(path());
        Core::FileManager::setUseProjectsDirectory(true);
134
135
136
    }
}

137
void BaseProjectWizardDialog::nextClicked()
138
{
139
140
    if (currentId() == d->introPageId) {
        emit projectParametersChanged(d->introPage->projectName(), d->introPage->path());
141
142
143
    }
}

144
145
146
147
148
Utils::ProjectIntroPage *BaseProjectWizardDialog::introPage() const
{
    return d->introPage;
}

149
QString BaseProjectWizardDialog::uniqueProjectName(const QString &path)
150
151
{
    const QDir pathDir(path);
152
    //: File path suggestion for a new project. If you choose
153
154
    //: to translate it, make sure it is a valid path name without blanks
    //: and using only ascii chars.
155
    const QString prefix = tr("untitled");
Friedemann Kleint's avatar
Friedemann Kleint committed
156
    for (unsigned i = 0; ; ++i) {
157
158
159
160
161
162
163
164
165
        QString name = prefix;
        if (i)
            name += QString::number(i);
        if (!pathDir.exists(name))
            return name;
    }
    return prefix;
}
} // namespace ProjectExplorer