2009-02-25 09:15:00 +01:00
/**************************************************************************
2008-12-02 12:01:29 +01:00
* *
* * This file is part of Qt Creator
* *
2009-02-25 09:15:00 +01:00
* * Copyright ( c ) 2009 Nokia Corporation and / or its subsidiary ( - ies ) .
2008-12-02 12:01:29 +01:00
* *
2009-06-17 00:01:27 +10:00
* * Contact : Nokia Corporation ( qt - info @ nokia . com )
2008-12-02 12:01:29 +01:00
* *
2009-02-25 09:15:00 +01:00
* * Commercial Usage
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * Licensees holding valid Qt Commercial licenses may use this file in
* * accordance with the Qt Commercial License Agreement provided with the
* * Software or , alternatively , in accordance with the terms contained in
* * a written agreement between you and Nokia .
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * GNU Lesser General Public License Usage
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01: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.
2008-12-02 14:17:16 +01:00
* *
2009-02-25 09:15:00 +01:00
* * If you are unsure which license is appropriate for your use , please
2009-08-14 09:30:56 +02:00
* * contact the sales department at http : //qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
* *
2009-02-25 09:15:00 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-12-02 12:01:29 +01:00
# include "projectloadwizard.h"
2008-12-02 16:19:05 +01:00
2008-12-02 12:01:29 +01:00
# include "qt4project.h"
# include "qt4projectmanager.h"
# include "qmakestep.h"
# include "makestep.h"
2008-12-02 16:19:05 +01:00
2009-04-22 16:51:38 +02:00
# include <extensionsystem/pluginmanager.h>
2008-12-02 12:01:29 +01:00
# include <QtGui/QCheckBox>
# include <QtGui/QHeaderView>
# include <QtGui/QLabel>
# include <QtGui/QVBoxLayout>
# include <QtGui/QWizardPage>
using namespace Qt4ProjectManager ;
using namespace Qt4ProjectManager : : Internal ;
ProjectLoadWizard : : ProjectLoadWizard ( Qt4Project * project , QWidget * parent , Qt : : WindowFlags flags )
: QWizard ( parent , flags ) , m_project ( project ) , m_importVersion ( 0 ) , m_temporaryVersion ( false )
{
2009-10-27 18:10:52 +01:00
setWindowTitle ( tr ( " Import existing build settings " ) ) ;
2009-04-28 12:43:04 +02:00
QtVersionManager * vm = QtVersionManager : : instance ( ) ;
2008-12-02 12:01:29 +01:00
QString directory = QFileInfo ( project - > file ( ) - > fileName ( ) ) . absolutePath ( ) ;
2009-09-03 19:16:22 +02:00
QString importVersion = QtVersionManager : : findQMakeBinaryFromMakefile ( directory ) ;
2008-12-02 12:01:29 +01:00
if ( ! importVersion . isNull ( ) ) {
// This also means we have a build in there
// First get the qt version
2009-09-03 19:16:22 +02:00
m_importVersion = vm - > qtVersionForQMakeBinary ( importVersion ) ;
2008-12-02 12:01:29 +01:00
// Okay does not yet exist, create
if ( ! m_importVersion ) {
2009-09-03 19:16:22 +02:00
m_importVersion = new QtVersion ( importVersion ) ;
2008-12-02 12:01:29 +01:00
m_temporaryVersion = true ;
}
2009-10-13 13:44:13 +02:00
QPair < QtVersion : : QmakeBuildConfigs , QStringList > result =
2009-07-22 16:52:44 +02:00
QtVersionManager : : scanMakeFile ( directory , m_importVersion - > defaultBuildConfig ( ) ) ;
m_importBuildConfig = result . first ;
2009-10-22 14:22:16 +02:00
m_additionalArguments = Qt4Project : : removeSpecFromArgumentList ( result . second ) ;
2009-11-09 18:59:11 +01:00
QString parsedSpec = Qt4Project : : extractSpecFromArgumentList ( result . second , directory , m_importVersion ) ;
QString versionSpec = m_importVersion - > mkspec ( ) ;
// Compare mkspecs and add to additional arguments
if ( parsedSpec . isEmpty ( ) | | parsedSpec = = versionSpec | | parsedSpec = = " default " ) {
// using the default spec, don't modify additional arguments
} else {
m_additionalArguments . prepend ( parsedSpec ) ;
m_additionalArguments . prepend ( " -spec " ) ;
}
2008-12-02 12:01:29 +01:00
}
// So now we have the version and the configuration for that version
// If buildAll we create debug and release configurations,
// if not then just either debug or release
// The default buildConfiguration depends on QmakeBuildConfig::DebugBuild
// Also if the qt version is not yet in the Tools Options dialog we offer to add it there
if ( m_importVersion )
2009-07-22 16:52:44 +02:00
setupImportPage ( m_importVersion , m_importBuildConfig , m_additionalArguments ) ;
2008-12-02 12:01:29 +01:00
setOptions ( options ( ) | QWizard : : NoCancelButton | QWizard : : NoBackButtonOnLastPage ) ;
}
// We don't want to actually show the dialog if we don't show the import page
// We used to simply call ::exec() on the dialog
void ProjectLoadWizard : : execDialog ( )
{
if ( m_importVersion )
exec ( ) ;
else
done ( QDialog : : Accepted ) ;
}
ProjectLoadWizard : : ~ ProjectLoadWizard ( )
{
}
void ProjectLoadWizard : : done ( int result )
{
2009-04-28 12:43:04 +02:00
QtVersionManager * vm = QtVersionManager : : instance ( ) ;
2008-12-02 12:01:29 +01:00
QWizard : : done ( result ) ;
// This normally happens on showing the final page, but since we
// don't show it anymore, do it here
if ( m_importVersion & & importCheckbox - > isChecked ( ) ) {
2009-03-31 18:12:28 +02:00
// Importing
2008-12-02 12:01:29 +01:00
if ( m_temporaryVersion )
2009-04-22 16:51:38 +02:00
vm - > addVersion ( m_importVersion ) ;
2008-12-02 12:01:29 +01:00
// Import the existing stuff
// qDebug()<<"Creating m_buildconfiguration entry from imported stuff";
// qDebug()<<((m_importBuildConfig& QtVersion::BuildAll)? "debug_and_release" : "")<<((m_importBuildConfig & QtVersion::DebugBuild)? "debug" : "release");
bool debug = m_importBuildConfig & QtVersion : : DebugBuild ;
2009-10-09 18:14:12 +02:00
m_project - > addQt4BuildConfiguration ( debug ? " Debug " : " Release " , m_importVersion , m_importBuildConfig , m_additionalArguments ) ;
2008-12-02 12:01:29 +01:00
if ( m_importBuildConfig & QtVersion : : BuildAll ) {
// Also create the other configuration
2009-10-13 13:44:13 +02:00
QtVersion : : QmakeBuildConfigs otherBuildConfiguration = m_importBuildConfig ;
2008-12-02 12:01:29 +01:00
if ( debug )
2009-10-13 13:44:13 +02:00
otherBuildConfiguration = otherBuildConfiguration & ~ QtVersion : : DebugBuild ;
2008-12-02 12:01:29 +01:00
else
2009-10-13 13:44:13 +02:00
otherBuildConfiguration = otherBuildConfiguration | QtVersion : : DebugBuild ;
2008-12-02 12:01:29 +01:00
2009-10-09 18:14:12 +02:00
m_project - > addQt4BuildConfiguration ( debug ? " Release " : " Debug " , m_importVersion , otherBuildConfiguration , m_additionalArguments ) ;
2008-12-02 12:01:29 +01:00
}
} else {
2009-03-31 18:12:28 +02:00
// Not importing
2008-12-02 12:01:29 +01:00
if ( m_temporaryVersion )
delete m_importVersion ;
2009-09-24 16:02:02 +02:00
// Create default
2009-03-31 18:12:28 +02:00
bool buildAll = false ;
2009-04-22 16:51:38 +02:00
QtVersion * defaultVersion = vm - > version ( 0 ) ;
2009-03-31 18:12:28 +02:00
if ( defaultVersion & & defaultVersion - > isValid ( ) & & ( defaultVersion - > defaultBuildConfig ( ) & QtVersion : : BuildAll ) )
buildAll = true ;
if ( buildAll ) {
2009-10-13 13:44:13 +02:00
m_project - > addQt4BuildConfiguration ( " Debug " , 0 , QtVersion : : BuildAll | QtVersion : : DebugBuild , m_additionalArguments ) ;
2009-10-09 18:14:12 +02:00
m_project - > addQt4BuildConfiguration ( " Release " , 0 , QtVersion : : BuildAll , m_additionalArguments ) ;
2009-03-31 18:12:28 +02:00
} else {
2009-10-09 18:14:12 +02:00
m_project - > addQt4BuildConfiguration ( " Debug " , 0 , QtVersion : : DebugBuild , m_additionalArguments ) ;
m_project - > addQt4BuildConfiguration ( " Release " , 0 , QtVersion : : QmakeBuildConfig ( 0 ) , m_additionalArguments ) ;
2009-03-31 18:12:28 +02:00
}
2008-12-02 12:01:29 +01:00
}
if ( ! m_project - > buildConfigurations ( ) . isEmpty ( ) )
m_project - > setActiveBuildConfiguration ( m_project - > buildConfigurations ( ) . at ( 0 ) ) ;
}
// This function used to do the commented stuff instead of having only one page
int ProjectLoadWizard : : nextId ( ) const
{
return - 1 ;
}
2009-10-13 13:44:13 +02:00
void ProjectLoadWizard : : setupImportPage ( QtVersion * version , QtVersion : : QmakeBuildConfigs buildConfig , QStringList addtionalArguments )
2008-12-02 12:01:29 +01:00
{
resize ( 605 , 490 ) ;
// Import Page
importPage = new QWizardPage ( this ) ;
2009-10-27 18:10:52 +01:00
importPage - > setTitle ( tr ( " Import existing build settings " ) ) ;
2008-12-02 12:01:29 +01:00
QVBoxLayout * importLayout = new QVBoxLayout ( importPage ) ;
importLabel = new QLabel ( importPage ) ;
2009-09-03 19:16:22 +02:00
QString versionString = version - > name ( ) + " ( " + QDir : : toNativeSeparators ( version - > qmakeCommand ( ) ) + " ) " ;
2008-12-02 12:01:29 +01:00
QString buildConfigString = ( buildConfig & QtVersion : : BuildAll ) ? QLatin1String ( " debug_and_release " ) : QLatin1String ( " " ) ;
buildConfigString . append ( ( buildConfig & QtVersion : : DebugBuild ) ? QLatin1String ( " debug " ) : QLatin1String ( " release " ) ) ;
importLabel - > setTextFormat ( Qt : : RichText ) ;
importLabel - > setText ( tr ( " Qt Creator has found an already existing build in the source directory.<br><br> "
" <b>Qt Version:</b> %1<br> "
2009-07-22 16:52:44 +02:00
" <b>Build configuration:</b> %2<br> "
" <b>Additional QMake Arguments:</b>%3 " )
2008-12-02 12:01:29 +01:00
. arg ( versionString )
2009-07-22 16:52:44 +02:00
. arg ( buildConfigString )
. arg ( ProjectExplorer : : Environment : : joinArgumentList ( addtionalArguments ) ) ) ;
2008-12-02 12:01:29 +01:00
importLayout - > addWidget ( importLabel ) ;
importCheckbox = new QCheckBox ( importPage ) ;
2009-04-17 21:11:52 +02:00
importCheckbox - > setText ( tr ( " Import existing build settings. " ) ) ;
2008-12-02 12:01:29 +01:00
importCheckbox - > setChecked ( true ) ;
importLayout - > addWidget ( importCheckbox ) ;
import2Label = new QLabel ( importPage ) ;
import2Label - > setTextFormat ( Qt : : RichText ) ;
if ( m_temporaryVersion )
2009-09-03 19:16:22 +02:00
import2Label - > setText ( tr ( " <b>Note:</b> Importing the settings will automatically add the Qt Version identified by <br><b>%1</b> to the list of Qt versions. " )
. arg ( QDir : : toNativeSeparators ( m_importVersion - > qmakeCommand ( ) ) ) ) ;
2008-12-02 12:01:29 +01:00
importLayout - > addWidget ( import2Label ) ;
addPage ( importPage ) ;
}