1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@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 **************************************************************************/
33 #include "basecheckoutwizard.h"
34 #include "vcsbaseconstants.h"
35 #include "checkoutwizarddialog.h"
36 #include "checkoutjobs.h"
38 #include <projectexplorer/projectexplorer.h>
39 #include <projectexplorer/projectexplorerconstants.h>
41 #include <QCoreApplication>
44 #include <QMessageBox>
47 \class VcsBase::BaseCheckoutWizard
49 \brief A Core::IWizard implementing a wizard for initially checking out a project using
50 a version control system.
52 Implements all of Core::IWizard with the exception of
53 name()/description() and icon().
55 Pops up a QWizard consisting of a Parameter Page which is created
56 by a virtual factory function and a progress
57 page containing a log text. The factory function createJob()
58 creates a job with the output connected to the log window,
59 returning the path to the checkout.
61 On success, the wizard tries to locate a project file
64 \sa VcsBase::BaseCheckoutWizardPage
70 class BaseCheckoutWizardPrivate
73 BaseCheckoutWizardPrivate() : dialog(0) {}
76 Internal::CheckoutWizardDialog *dialog;
77 QList<QWizardPage *> parameterPages;
82 void BaseCheckoutWizardPrivate::clear()
84 parameterPages.clear();
89 } // namespace Internal
91 BaseCheckoutWizard::BaseCheckoutWizard(QObject *parent) :
92 Core::IWizard(parent),
93 d(new Internal::BaseCheckoutWizardPrivate)
97 BaseCheckoutWizard::~BaseCheckoutWizard()
102 Core::IWizard::WizardKind BaseCheckoutWizard::kind() const
104 return Core::IWizard::ProjectWizard;
107 QString BaseCheckoutWizard::category() const
109 return QLatin1String(ProjectExplorer::Constants::IMPORT_WIZARD_CATEGORY);
112 QString BaseCheckoutWizard::displayCategory() const
114 return QCoreApplication::translate("ProjectExplorer", ProjectExplorer::Constants::IMPORT_WIZARD_CATEGORY_DISPLAY);
117 QString BaseCheckoutWizard::id() const
122 QString BaseCheckoutWizard::descriptionImage() const
127 void BaseCheckoutWizard::setId(const QString &id)
132 void BaseCheckoutWizard::runWizard(const QString &path, QWidget *parent, const QString & /*platform*/, const QVariantMap &extraValues)
134 Q_UNUSED(extraValues)
135 // Create dialog and launch
136 d->parameterPages = createParameterPages(path);
137 Internal::CheckoutWizardDialog dialog(d->parameterPages, parent);
139 connect(&dialog, SIGNAL(progressPageShown()), this, SLOT(slotProgressPageShown()));
140 dialog.setWindowTitle(displayName());
141 if (dialog.exec() != QDialog::Accepted)
143 // Now try to find the project file and open
144 const QString checkoutPath = d->checkoutPath;
146 QString errorMessage;
147 const QString projectFile = openProject(checkoutPath, &errorMessage);
148 if (projectFile.isEmpty()) {
149 QMessageBox msgBox(QMessageBox::Warning, tr("Cannot Open Project"),
150 tr("Failed to open project in '%1'.").arg(QDir::toNativeSeparators(checkoutPath)));
151 msgBox.setDetailedText(errorMessage);
156 Core::FeatureSet BaseCheckoutWizard::requiredFeatures() const
158 return Core::FeatureSet();
161 Core::IWizard::WizardFlags BaseCheckoutWizard::flags() const
163 return Core::IWizard::PlatformIndependent;
166 static inline QString msgNoProjectFiles(const QDir &dir, const QStringList &patterns)
168 return BaseCheckoutWizard::tr("Could not find any project files matching (%1) in the directory '%2'.").arg(patterns.join(QLatin1String(", ")), QDir::toNativeSeparators(dir.absolutePath()));
171 // Try to find the project files in a project directory with some smartness
172 static QFileInfoList findProjectFiles(const QDir &projectDir, QString *errorMessage)
174 const QStringList projectFilePatterns = ProjectExplorer::ProjectExplorerPlugin::projectFilePatterns();
176 QFileInfoList projectFiles = projectDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
177 if (!projectFiles.empty())
179 // Try a 'src' directory
180 QFileInfoList srcDirs = projectDir.entryInfoList(QStringList(QLatin1String("src")), QDir::Dirs|QDir::NoDotAndDotDot|QDir::Readable);
181 if (srcDirs.empty()) {
182 *errorMessage = msgNoProjectFiles(projectDir, projectFilePatterns);
183 return QFileInfoList();
185 const QDir srcDir = QDir(srcDirs.front().absoluteFilePath());
186 projectFiles = srcDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
187 if (projectFiles.empty()) {
188 *errorMessage = msgNoProjectFiles(srcDir, projectFilePatterns);
189 return QFileInfoList();
191 return projectFiles;;
194 QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessage)
196 ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
198 *errorMessage = tr("The Project Explorer is not available.");
202 // Search the directory for project files
203 const QDir dir(path);
205 *errorMessage = tr("'%1' does not exist.").
206 arg(QDir::toNativeSeparators(path)); // Should not happen
209 QFileInfoList projectFiles = findProjectFiles(dir, errorMessage);
210 if (projectFiles.empty())
212 // Open. Do not use a busy cursor here as additional wizards might pop up
213 const QString projectFile = projectFiles.front().absoluteFilePath();
214 if (!pe->openProject(projectFile, errorMessage))
220 void BaseCheckoutWizard::slotProgressPageShown()
222 const QSharedPointer<AbstractCheckoutJob> job = createJob(d->parameterPages, &(d->checkoutPath));
223 d->dialog->start(job);
226 } // namespace VcsBase