2 ******************************************************************************
4 * @file projectintropage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
8 * @see The GNU Public License (GPL) Version 3
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "projectintropage.h"
30 #include "filewizardpage.h"
31 #include "ui_projectintropage.h"
33 #include <QMessageBox>
34 #include <QtCore/QDir>
35 #include <QtCore/QFileInfo>
38 struct ProjectIntroPagePrivate
{
39 ProjectIntroPagePrivate();
40 Ui::ProjectIntroPage m_ui
;
42 // Status label style sheets
43 const QString m_errorStyleSheet
;
44 const QString m_warningStyleSheet
;
45 const QString m_hintStyleSheet
;
48 ProjectIntroPagePrivate::ProjectIntroPagePrivate() :
50 m_errorStyleSheet(QLatin1String("background : red;")),
51 m_warningStyleSheet(QLatin1String("background : yellow;")),
55 ProjectIntroPage::ProjectIntroPage(QWidget
*parent
) :
57 m_d(new ProjectIntroPagePrivate
)
59 m_d
->m_ui
.setupUi(this);
61 m_d
->m_ui
.nameLineEdit
->setInitialText(tr("<Enter_Name>"));
62 m_d
->m_ui
.nameLineEdit
->setFocus(Qt::TabFocusReason
);
63 connect(m_d
->m_ui
.pathChooser
, SIGNAL(changed(QString
)), this, SLOT(slotChanged()));
64 connect(m_d
->m_ui
.nameLineEdit
, SIGNAL(textChanged(QString
)), this, SLOT(slotChanged()));
65 connect(m_d
->m_ui
.pathChooser
, SIGNAL(returnPressed()), this, SLOT(slotActivated()));
66 connect(m_d
->m_ui
.nameLineEdit
, SIGNAL(validReturnPressed()), this, SLOT(slotActivated()));
69 void ProjectIntroPage::insertControl(int row
, QWidget
*label
, QWidget
*control
)
71 m_d
->m_ui
.formLayout
->insertRow(row
, label
, control
);
74 ProjectIntroPage::~ProjectIntroPage()
79 QString
ProjectIntroPage::name() const
81 return m_d
->m_ui
.nameLineEdit
->text();
84 QString
ProjectIntroPage::path() const
86 return m_d
->m_ui
.pathChooser
->path();
89 void ProjectIntroPage::setPath(const QString
&path
)
91 m_d
->m_ui
.pathChooser
->setPath(path
);
94 void ProjectIntroPage::setName(const QString
&name
)
96 m_d
->m_ui
.nameLineEdit
->setText(name
);
99 QString
ProjectIntroPage::description() const
101 return m_d
->m_ui
.descriptionLabel
->text();
104 void ProjectIntroPage::setDescription(const QString
&description
)
106 m_d
->m_ui
.descriptionLabel
->setText(description
);
109 void ProjectIntroPage::changeEvent(QEvent
*e
)
111 QWizardPage::changeEvent(e
);
114 case QEvent::LanguageChange
:
115 m_d
->m_ui
.retranslateUi(this);
122 bool ProjectIntroPage::isComplete() const
124 return m_d
->m_complete
;
127 bool ProjectIntroPage::validate()
129 // Validate and display status
130 if (!m_d
->m_ui
.pathChooser
->isValid()) {
131 displayStatusMessage(Error
, m_d
->m_ui
.pathChooser
->errorMessage());
135 // Name valid? Ignore 'DisplayingInitialText' state.
136 bool nameValid
= false;
137 switch (m_d
->m_ui
.nameLineEdit
->state()) {
138 case BaseValidatingLineEdit::Invalid
:
139 displayStatusMessage(Error
, m_d
->m_ui
.nameLineEdit
->errorMessage());
142 case BaseValidatingLineEdit::DisplayingInitialText
:
144 case BaseValidatingLineEdit::Valid
:
149 // Check existence of the directory
150 QString projectDir
= path();
151 projectDir
+= QDir::separator();
152 projectDir
+= m_d
->m_ui
.nameLineEdit
->text();
153 const QFileInfo
projectDirFile(projectDir
);
154 if (!projectDirFile
.exists()) { // All happy
159 if (projectDirFile
.isDir()) {
160 displayStatusMessage(Warning
, tr("The project already exists."));
163 // Not a directory, but something else, likely causing directory creation to fail
164 displayStatusMessage(Error
, tr("A file with that name already exists."));
168 void ProjectIntroPage::slotChanged()
170 const bool newComplete
= validate();
172 if (newComplete
!= m_d
->m_complete
) {
173 m_d
->m_complete
= newComplete
;
174 emit
completeChanged();
178 void ProjectIntroPage::slotActivated()
180 if (m_d
->m_complete
) {
185 bool ProjectIntroPage::validateProjectDirectory(const QString
&name
, QString
*errorMessage
)
187 return ProjectNameValidatingLineEdit::validateProjectName(name
, errorMessage
);
190 void ProjectIntroPage::displayStatusMessage(StatusLabelMode m
, const QString
&s
)
194 m_d
->m_ui
.stateLabel
->setStyleSheet(m_d
->m_errorStyleSheet
);
197 m_d
->m_ui
.stateLabel
->setStyleSheet(m_d
->m_warningStyleSheet
);
200 m_d
->m_ui
.stateLabel
->setStyleSheet(m_d
->m_hintStyleSheet
);
203 m_d
->m_ui
.stateLabel
->setText(s
);
206 void ProjectIntroPage::hideStatusLabel()
208 displayStatusMessage(Hint
, QString());