2009-07-17 17:19:23 +02:00
/**************************************************************************
* *
* * This file is part of Qt Creator
* *
2011-01-11 16:28:15 +01:00
* * Copyright ( c ) 2011 Nokia Corporation and / or its subsidiary ( - ies ) .
2009-07-17 17:19:23 +02:00
* *
2011-11-02 15:59:12 +01:00
* * Contact : Nokia Corporation ( qt - info @ nokia . com )
2009-07-17 17:19:23 +02:00
* *
* *
* * GNU Lesser General Public License Usage
* *
2011-04-13 08:42:33 +02:00
* * 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.
2009-07-17 17:19:23 +02:00
* *
2010-12-17 16:01:08 +01:00
* * In addition , as a special exception , Nokia gives you certain additional
2011-04-13 08:42:33 +02:00
* * rights . These rights are described in the Nokia Qt LGPL Exception
2010-12-17 16:01:08 +01:00
* * version 1.1 , included in the file LGPL_EXCEPTION . txt in this package .
* *
2011-04-13 08:42:33 +02:00
* * 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 .
* *
2010-12-17 16:01:08 +01:00
* * If you have questions regarding the use of this file , please contact
2011-11-02 15:59:12 +01:00
* * Nokia at qt - info @ nokia . com .
2009-07-17 17:19:23 +02:00
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "basecheckoutwizard.h"
# include "vcsbaseconstants.h"
# include "checkoutwizarddialog.h"
# include "checkoutjobs.h"
# include <projectexplorer/projectexplorer.h>
2011-11-18 12:54:41 +01:00
# include <projectexplorer/projectexplorerconstants.h>
2009-07-17 17:19:23 +02:00
# include <QtCore/QCoreApplication>
# include <QtCore/QFileInfo>
# include <QtCore/QDir>
# include <QtGui/QMessageBox>
2011-03-28 14:19:17 +02:00
/*!
\ class VCSBase : : BaseCheckoutWizard
\ brief A Core : : IWizard implementing a wizard for initially checking out a project using
a version control system .
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 .
\ sa VCSBase : : BaseCheckoutWizardPage
*/
2009-07-17 17:19:23 +02: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 ;
2009-11-27 10:33:24 +01:00
QString id ;
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
2009-07-17 17:19:23 +02:00
BaseCheckoutWizard : : BaseCheckoutWizard ( QObject * parent ) :
Core : : IWizard ( parent ) ,
2011-12-08 13:07:00 +01:00
d ( new Internal : : BaseCheckoutWizardPrivate )
2009-07-17 17:19:23 +02:00
{
}
BaseCheckoutWizard : : ~ BaseCheckoutWizard ( )
{
delete d ;
}
2010-01-14 14:14:39 +01:00
Core : : IWizard : : WizardKind BaseCheckoutWizard : : kind ( ) const
2009-07-17 17:19:23 +02:00
{
2009-11-27 10:33:24 +01:00
return Core : : IWizard : : ProjectWizard ;
2009-07-17 17:19:23 +02:00
}
QString BaseCheckoutWizard : : category ( ) const
{
2011-11-18 12:54:41 +01:00
return QLatin1String ( ProjectExplorer : : Constants : : IMPORT_WIZARD_CATEGORY ) ;
2009-07-17 17:19:23 +02:00
}
2010-01-07 18:17:24 +01:00
QString BaseCheckoutWizard : : displayCategory ( ) const
2009-07-17 17:19:23 +02:00
{
2011-11-18 12:54:41 +01:00
return QCoreApplication : : translate ( " ProjectExplorer " , ProjectExplorer : : Constants : : IMPORT_WIZARD_CATEGORY_DISPLAY ) ;
2009-11-27 10:33:24 +01:00
}
QString BaseCheckoutWizard : : id ( ) const
{
return d - > id ;
}
void BaseCheckoutWizard : : setId ( const QString & id )
{
d - > id = id ;
2009-07-17 17:19:23 +02:00
}
2010-09-16 17:09:36 +02:00
void BaseCheckoutWizard : : runWizard ( const QString & path , QWidget * parent )
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 ) ;
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 ) ;
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 ( ) ;
}
return projectFiles ; ;
}
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 ( ) ;
2011-09-05 13:47:29 +02:00
if ( ! pe - > openProject ( projectFile , errorMessage ) ) {
2009-07-17 17:19:23 +02:00
return QString ( ) ;
}
return projectFile ;
}
void BaseCheckoutWizard : : slotProgressPageShown ( )
{
2009-07-21 11:14:48 +02:00
const QSharedPointer < AbstractCheckoutJob > job = createJob ( d - > parameterPages , & ( d - > checkoutPath ) ) ;
2009-07-17 17:19:23 +02:00
if ( ! job . isNull ( ) )
d - > dialog - > start ( job ) ;
}
} // namespace VCSBase