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
2014-05-05 15:21:29 +02:00
# include "basecheckoutwizardfactory.h"
2014-05-05 15:48:15 +02:00
# include "basecheckoutwizard.h"
2009-07-17 17:19:23 +02:00
2013-03-27 08:29:38 +01:00
# include <coreplugin/featureprovider.h>
2009-07-17 17:19:23 +02:00
# include <projectexplorer/projectexplorer.h>
2014-05-05 16:24:00 +02:00
# include <utils/qtcassert.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
2014-05-05 15:56:15 +02:00
class BaseCheckoutWizardFactoryPrivate
2011-12-08 13:07:00 +01:00
{
public :
2014-05-05 15:56:15 +02:00
BaseCheckoutWizardFactoryPrivate ( ) : wizard ( 0 ) { }
2009-07-17 17:19:23 +02:00
void clear ( ) ;
2014-05-05 15:56:15 +02:00
BaseCheckoutWizard * wizard ;
2009-07-21 11:14:48 +02:00
QList < QWizardPage * > parameterPages ;
2009-07-17 17:19:23 +02:00
QString checkoutPath ;
} ;
2014-05-05 15:56:15 +02:00
void BaseCheckoutWizardFactoryPrivate : : clear ( )
2009-07-17 17:19:23 +02:00
{
2009-07-21 11:14:48 +02:00
parameterPages . clear ( ) ;
2014-05-05 16:17:21 +02:00
delete wizard ;
2014-05-05 15:56:15 +02:00
wizard = 0 ;
2009-07-17 17:19:23 +02:00
checkoutPath . clear ( ) ;
}
2011-12-08 13:07:00 +01:00
} // namespace Internal
2014-05-05 14:47:44 +02:00
BaseCheckoutWizardFactory : : BaseCheckoutWizardFactory ( ) :
2014-05-05 15:56:15 +02:00
d ( new Internal : : BaseCheckoutWizardFactoryPrivate )
2009-07-17 17:19:23 +02:00
{
2014-05-02 17:38:42 +02:00
setWizardKind ( IWizardFactory : : ProjectWizard ) ;
2013-09-20 15:12:44 +02:00
setCategory ( QLatin1String ( ProjectExplorer : : Constants : : IMPORT_WIZARD_CATEGORY ) ) ;
setDisplayCategory ( QCoreApplication : : translate ( " ProjectExplorer " ,
ProjectExplorer : : Constants : : IMPORT_WIZARD_CATEGORY_DISPLAY ) ) ;
2014-05-02 17:38:42 +02:00
setFlags ( Core : : IWizardFactory : : PlatformIndependent ) ;
2009-07-17 17:19:23 +02:00
}
2014-05-05 14:47:44 +02:00
BaseCheckoutWizardFactory : : ~ BaseCheckoutWizardFactory ( )
2009-07-17 17:19:23 +02:00
{
delete d ;
}
2014-05-05 14:47:44 +02:00
void BaseCheckoutWizardFactory : : runWizard ( const QString & path , QWidget * parent , const QString & platform ,
2014-02-14 14:19:58 +01:00
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 ) ;
2014-05-05 16:24:00 +02:00
QTC_ASSERT ( ! d - > wizard , return ) ;
2009-07-17 17:19:23 +02:00
// Create dialog and launch
2014-05-05 15:51:59 +02:00
2009-07-21 11:14:48 +02:00
d - > parameterPages = createParameterPages ( path ) ;
2014-05-05 16:24:00 +02:00
d - > wizard = create ( d - > parameterPages , parent ) ;
connect ( d - > wizard , SIGNAL ( progressPageShown ( ) ) , this , SLOT ( slotProgressPageShown ( ) ) ) ;
d - > wizard - > setWindowTitle ( displayName ( ) ) ;
2014-05-05 17:24:35 +02:00
if ( d - > wizard - > exec ( ) ! = QDialog : : Accepted ) {
d - > clear ( ) ;
2010-09-16 17:09:36 +02:00
return ;
2014-05-05 17:24:35 +02:00
}
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 " ) ,
2014-04-17 14:09:47 +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 )
{
2014-05-05 14:47:44 +02:00
return BaseCheckoutWizardFactory : : 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
}
2014-05-05 14:47:44 +02:00
QString BaseCheckoutWizardFactory : : openProject ( const QString & path , QString * errorMessage )
2009-07-17 17:19:23 +02:00
{
// Search the directory for project files
const QDir dir ( path ) ;
if ( ! dir . exists ( ) ) {
2014-04-17 14:09:47 +02:00
* errorMessage = tr ( " \" %1 \" does not exist. " ) .
2010-07-05 09:52:32 +02:00
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 ( ) ;
2014-05-02 16:37:04 +02:00
if ( ! ProjectExplorer : : ProjectExplorerPlugin : : instance ( ) - > 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 ;
}
2014-05-05 14:47:44 +02:00
void BaseCheckoutWizardFactory : : slotProgressPageShown ( )
2009-07-17 17:19:23 +02:00
{
2013-08-28 21:27:47 +03:00
Command * command = createCommand ( d - > parameterPages , & ( d - > checkoutPath ) ) ;
2014-05-05 15:56:15 +02:00
d - > wizard - > start ( command ) ;
2009-07-17 17:19:23 +02:00
}
2012-01-07 12:31:48 +01:00
} // namespace VcsBase