2012-10-02 09:12:39 +02:00
/****************************************************************************
2009-07-17 17:19:23 +02:00
* *
2014-01-07 13:27:11 +01:00
* * Copyright ( C ) 2014 Digia Plc and / or its subsidiary ( - ies ) .
2012-10-02 09:12:39 +02:00
* * Contact : http : //www.qt-project.org/legal
2009-07-17 17:19:23 +02:00
* *
2012-10-02 09:12:39 +02:00
* * This file is part of Qt Creator .
2009-07-17 17:19:23 +02:00
* *
2012-10-02 09:12:39 +02:00
* * Commercial License Usage
* * Licensees holding valid commercial Qt licenses may use this file in
* * accordance with the commercial license agreement provided with the
* * Software or , alternatively , in accordance with the terms contained in
* * a written agreement between you and Digia . For licensing terms and
* * conditions see http : //qt.digia.com/licensing. For further information
* * use the contact form at http : //qt.digia.com/contact-us.
2009-07-17 17:19:23 +02:00
* *
* * GNU Lesser General Public License Usage
2012-10-02 09:12:39 +02:00
* * Alternatively , 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.
* *
* * In addition , as a special exception , Digia gives you certain additional
* * rights . These rights are described in the Digia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
* * version 1.1 , included in the file LGPL_EXCEPTION . txt in this package .
* *
2012-10-02 09:12:39 +02:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-07-17 17:19:23 +02:00
# include "basecheckoutwizard.h"
# include "checkoutwizarddialog.h"
2013-03-27 08:29:38 +01:00
# include <coreplugin/featureprovider.h>
2009-07-17 17:19:23 +02:00
# include <projectexplorer/projectexplorer.h>
2012-02-15 10:42:41 +01:00
# include <QCoreApplication>
# include <QDir>
# include <QMessageBox>
2009-07-17 17:19:23 +02:00
2011-03-28 14:19:17 +02:00
/*!
2012-01-07 12:31:48 +01:00
\ class VcsBase : : BaseCheckoutWizard
2011-03-28 14:19:17 +02:00
2013-06-05 14:29:24 +02:00
\ brief The BaseCheckoutWizard class implements a wizard for initially
checking out a project using a version control system .
2011-03-28 14:19:17 +02:00
Implements all of Core : : IWizard with the exception of
name ( ) / description ( ) and icon ( ) .
Pops up a QWizard consisting of a Parameter Page which is created
by a virtual factory function and a progress
page containing a log text . The factory function createJob ( )
creates a job with the output connected to the log window ,
returning the path to the checkout .
On success , the wizard tries to locate a project file
and open it .
2012-01-07 12:31:48 +01:00
\ sa VcsBase : : BaseCheckoutWizardPage
2011-03-28 14:19:17 +02:00
*/
2012-01-07 12:31:48 +01:00
namespace VcsBase {
2011-12-08 13:07:00 +01:00
namespace Internal {
2009-07-17 17:19:23 +02:00
2011-12-08 13:07:00 +01:00
class BaseCheckoutWizardPrivate
{
public :
2009-07-21 11:14:48 +02:00
BaseCheckoutWizardPrivate ( ) : dialog ( 0 ) { }
2009-07-17 17:19:23 +02:00
void clear ( ) ;
Internal : : CheckoutWizardDialog * dialog ;
2009-07-21 11:14:48 +02:00
QList < QWizardPage * > parameterPages ;
2009-07-17 17:19:23 +02:00
QString checkoutPath ;
2013-08-29 13:37:45 +03:00
QString progressTitle ;
QString startedStatus ;
2009-07-17 17:19:23 +02:00
} ;
void BaseCheckoutWizardPrivate : : clear ( )
{
2009-07-21 11:14:48 +02:00
parameterPages . clear ( ) ;
2009-07-17 17:19:23 +02:00
dialog = 0 ;
checkoutPath . clear ( ) ;
}
2011-12-08 13:07:00 +01:00
} // namespace Internal
2014-02-13 14:56:14 +01:00
BaseCheckoutWizard : : BaseCheckoutWizard ( ) :
2011-12-08 13:07:00 +01:00
d ( new Internal : : BaseCheckoutWizardPrivate )
2009-07-17 17:19:23 +02:00
{
2013-09-20 15:12:44 +02:00
setWizardKind ( IWizard : : ProjectWizard ) ;
setCategory ( QLatin1String ( ProjectExplorer : : Constants : : IMPORT_WIZARD_CATEGORY ) ) ;
setDisplayCategory ( QCoreApplication : : translate ( " ProjectExplorer " ,
ProjectExplorer : : Constants : : IMPORT_WIZARD_CATEGORY_DISPLAY ) ) ;
setFlags ( Core : : IWizard : : PlatformIndependent ) ;
2009-07-17 17:19:23 +02:00
}
BaseCheckoutWizard : : ~ BaseCheckoutWizard ( )
{
delete d ;
}
2014-02-14 14:19:58 +01:00
void BaseCheckoutWizard : : runWizard ( const QString & path , QWidget * parent , const QString & platform ,
const QVariantMap & extraValues )
2009-07-17 17:19:23 +02:00
{
2014-02-14 14:19:58 +01:00
Q_UNUSED ( platform ) ;
Q_UNUSED ( extraValues ) ;
2009-07-17 17:19:23 +02:00
// Create dialog and launch
2009-07-21 11:14:48 +02:00
d - > parameterPages = createParameterPages ( path ) ;
Internal : : CheckoutWizardDialog dialog ( d - > parameterPages , parent ) ;
2013-08-29 13:37:45 +03:00
if ( ! d - > progressTitle . isEmpty ( ) )
dialog . setTitle ( d - > progressTitle ) ;
if ( ! d - > startedStatus . isEmpty ( ) )
dialog . setStartedStatus ( d - > startedStatus ) ;
2009-07-17 17:19:23 +02:00
d - > dialog = & dialog ;
connect ( & dialog , SIGNAL ( progressPageShown ( ) ) , this , SLOT ( slotProgressPageShown ( ) ) ) ;
2010-01-07 18:17:24 +01:00
dialog . setWindowTitle ( displayName ( ) ) ;
2009-07-17 17:19:23 +02:00
if ( dialog . exec ( ) ! = QDialog : : Accepted )
2010-09-16 17:09:36 +02:00
return ;
2009-07-17 17:19:23 +02:00
// Now try to find the project file and open
const QString checkoutPath = d - > checkoutPath ;
d - > clear ( ) ;
QString errorMessage ;
const QString projectFile = openProject ( checkoutPath , & errorMessage ) ;
if ( projectFile . isEmpty ( ) ) {
QMessageBox msgBox ( QMessageBox : : Warning , tr ( " Cannot Open Project " ) ,
2009-08-05 09:17:26 +02:00
tr ( " Failed to open project in '%1'. " ) . arg ( QDir : : toNativeSeparators ( checkoutPath ) ) ) ;
2009-07-17 17:19:23 +02:00
msgBox . setDetailedText ( errorMessage ) ;
2013-10-18 15:05:58 +02:00
msgBox . addButton ( QMessageBox : : Ok ) ;
2009-07-17 17:19:23 +02:00
msgBox . exec ( ) ;
}
}
2009-07-27 09:22:26 +02:00
static inline QString msgNoProjectFiles ( const QDir & dir , const QStringList & patterns )
{
2009-08-05 09:17:26 +02:00
return BaseCheckoutWizard : : tr ( " Could not find any project files matching (%1) in the directory '%2'. " ) . arg ( patterns . join ( QLatin1String ( " , " ) ) , QDir : : toNativeSeparators ( dir . absolutePath ( ) ) ) ;
2009-07-27 09:22:26 +02:00
}
// Try to find the project files in a project directory with some smartness
static QFileInfoList findProjectFiles ( const QDir & projectDir , QString * errorMessage )
{
2010-06-28 14:34:30 +02:00
const QStringList projectFilePatterns = ProjectExplorer : : ProjectExplorerPlugin : : projectFilePatterns ( ) ;
2009-07-27 09:22:26 +02:00
// Project directory
QFileInfoList projectFiles = projectDir . entryInfoList ( projectFilePatterns , QDir : : Files | QDir : : NoDotAndDotDot | QDir : : Readable ) ;
if ( ! projectFiles . empty ( ) )
return projectFiles ;
// Try a 'src' directory
QFileInfoList srcDirs = projectDir . entryInfoList ( QStringList ( QLatin1String ( " src " ) ) , QDir : : Dirs | QDir : : NoDotAndDotDot | QDir : : Readable ) ;
if ( srcDirs . empty ( ) ) {
* errorMessage = msgNoProjectFiles ( projectDir , projectFilePatterns ) ;
return QFileInfoList ( ) ;
}
const QDir srcDir = QDir ( srcDirs . front ( ) . absoluteFilePath ( ) ) ;
projectFiles = srcDir . entryInfoList ( projectFilePatterns , QDir : : Files | QDir : : NoDotAndDotDot | QDir : : Readable ) ;
if ( projectFiles . empty ( ) ) {
* errorMessage = msgNoProjectFiles ( srcDir , projectFilePatterns ) ;
return QFileInfoList ( ) ;
}
2013-09-03 18:48:02 +02:00
return projectFiles ;
2009-07-27 09:22:26 +02:00
}
2009-07-17 17:19:23 +02:00
QString BaseCheckoutWizard : : openProject ( const QString & path , QString * errorMessage )
{
ProjectExplorer : : ProjectExplorerPlugin * pe = ProjectExplorer : : ProjectExplorerPlugin : : instance ( ) ;
if ( ! pe ) {
* errorMessage = tr ( " The Project Explorer is not available. " ) ;
return QString ( ) ;
}
// Search the directory for project files
const QDir dir ( path ) ;
if ( ! dir . exists ( ) ) {
2010-07-05 09:52:32 +02:00
* errorMessage = tr ( " '%1' does not exist. " ) .
arg ( QDir : : toNativeSeparators ( path ) ) ; // Should not happen
2009-07-17 17:19:23 +02:00
return QString ( ) ;
}
2009-07-27 09:22:26 +02:00
QFileInfoList projectFiles = findProjectFiles ( dir , errorMessage ) ;
if ( projectFiles . empty ( ) )
2009-07-17 17:19:23 +02:00
return QString ( ) ;
2009-07-27 09:22:26 +02:00
// Open. Do not use a busy cursor here as additional wizards might pop up
2009-07-17 17:19:23 +02:00
const QString projectFile = projectFiles . front ( ) . absoluteFilePath ( ) ;
2012-01-07 03:35:54 +01:00
if ( ! pe - > openProject ( projectFile , errorMessage ) )
2009-07-17 17:19:23 +02:00
return QString ( ) ;
2012-01-07 03:35:54 +01:00
2009-07-17 17:19:23 +02:00
return projectFile ;
}
2013-08-29 13:37:45 +03:00
void BaseCheckoutWizard : : setCustomLabels ( const QString & progressTitle , const QString & startedStatus )
{
d - > progressTitle = progressTitle ;
d - > startedStatus = startedStatus ;
}
2009-07-17 17:19:23 +02:00
void BaseCheckoutWizard : : slotProgressPageShown ( )
{
2013-08-28 21:27:47 +03:00
Command * command = createCommand ( d - > parameterPages , & ( d - > checkoutPath ) ) ;
d - > dialog - > start ( command ) ;
2009-07-17 17:19:23 +02:00
}
2012-01-07 12:31:48 +01:00
} // namespace VcsBase