diff --git a/src/plugins/qt4projectmanager/addlibrarywizard.cpp b/src/plugins/qt4projectmanager/addlibrarywizard.cpp index da99e2889ac80db2b966651a668d8d7f3caa4d30..8cc4e178e1181277ee4b4ac9da08c843be0ed30f 100644 --- a/src/plugins/qt4projectmanager/addlibrarywizard.cpp +++ b/src/plugins/qt4projectmanager/addlibrarywizard.cpp @@ -196,17 +196,20 @@ void DetailsPage::initializePage() case AddLibraryWizard::SystemLibrary: title = tr("System Library"); subTitle = tr("Specify the library which you want to link against"); - m_libraryDetailsController = new SystemLibraryDetailsController(m_libraryDetailsWidget, this); + m_libraryDetailsController = new SystemLibraryDetailsController( + m_libraryDetailsWidget, m_libraryWizard->proFile(), this); break; case AddLibraryWizard::ExternalLibrary: title = tr("External Library"); subTitle = tr("Specify the library which you want to link against and the includes path"); - m_libraryDetailsController = new ExternalLibraryDetailsController(m_libraryDetailsWidget, this); + m_libraryDetailsController = new ExternalLibraryDetailsController( + m_libraryDetailsWidget, m_libraryWizard->proFile(), this); break; case AddLibraryWizard::InternalLibrary: title = tr("Internal Library"); subTitle = tr("Choose the project file of the library which you want to link against"); - m_libraryDetailsController = new InternalLibraryDetailsController(m_libraryDetailsWidget, this); + m_libraryDetailsController = new InternalLibraryDetailsController( + m_libraryDetailsWidget, m_libraryWizard->proFile(), this); break; default: break; @@ -214,7 +217,6 @@ void DetailsPage::initializePage() setTitle(title); setSubTitle(subTitle); if (m_libraryDetailsController) { - m_libraryDetailsController->setProFile(m_libraryWizard->proFile()); connect(m_libraryDetailsController, SIGNAL(completeChanged()), this, SIGNAL(completeChanged())); } diff --git a/src/plugins/qt4projectmanager/librarydetailscontroller.cpp b/src/plugins/qt4projectmanager/librarydetailscontroller.cpp index e78b5b494b1505803c252e816122e38a4d588f5f..e7d094ba158e85733c37b76f23d91f01615105ce 100644 --- a/src/plugins/qt4projectmanager/librarydetailscontroller.cpp +++ b/src/plugins/qt4projectmanager/librarydetailscontroller.cpp @@ -2,6 +2,7 @@ #include "ui_librarydetailswidget.h" #include "findqt4profiles.h" #include "qt4nodes.h" +#include "qt4buildconfiguration.h" #include <projectexplorer/projectexplorer.h> #include <projectexplorer/session.h> @@ -16,7 +17,8 @@ using namespace Qt4ProjectManager; using namespace Qt4ProjectManager::Internal; LibraryDetailsController::LibraryDetailsController( - Ui::LibraryDetailsWidget *libraryDetails, QObject *parent) : + Ui::LibraryDetailsWidget *libraryDetails, + const QString &proFile, QObject *parent) : QObject(parent), m_platforms(AddLibraryWizard::LinuxPlatform | AddLibraryWizard::MacPlatform @@ -24,6 +26,7 @@ LibraryDetailsController::LibraryDetailsController( | AddLibraryWizard::SymbianPlatform), m_linkageType(AddLibraryWizard::NoLinkage), m_macLibraryType(AddLibraryWizard::NoLibraryType), + m_proFile(proFile), m_ignoreGuiSignals(false), m_includePathChanged(false), m_linkageRadiosVisible(true), @@ -33,13 +36,29 @@ LibraryDetailsController::LibraryDetailsController( m_libraryDetailsWidget(libraryDetails) { #ifdef Q_OS_MAC - setMacLibraryRadiosVisible(false); + m_creatorPlatform = CreatorMac; #endif +#ifdef Q_OS_LINUX + m_creatorPlatform = CreatorLinux; +#endif +#ifdef Q_OS_WIN + m_creatorPlatform = CreatorWindows; -#ifndef Q_OS_WIN - setLinkageRadiosVisible(false); + // project for which we are going to insert the snippet + const ProjectExplorer::Project *project = + ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForFile(proFile); + Qt4BuildConfiguration *qt4BuildConfiguration = + qobject_cast<Qt4BuildConfiguration *>(project->activeTarget()->activeBuildConfiguration()); + if (qt4BuildConfiguration && qt4BuildConfiguration->toolChainType() == ProjectExplorer::ToolChain::GCC_MAEMO) + m_creatorPlatform = CreatorLinux; #endif + if (creatorPlatform() == CreatorMac) + setMacLibraryRadiosVisible(false); + + if (creatorPlatform() != CreatorWindows) + setLinkageRadiosVisible(false); + connect(m_libraryDetailsWidget->includePathChooser, SIGNAL(changed(QString)), this, SLOT(slotIncludePathChanged())); connect(m_libraryDetailsWidget->frameworkRadio, SIGNAL(clicked(bool)), @@ -60,13 +79,9 @@ LibraryDetailsController::LibraryDetailsController( this, SLOT(slotPlatformChanged())); } -void LibraryDetailsController::setProFile(const QString &proFile) +LibraryDetailsController::CreatorPlatform LibraryDetailsController::creatorPlatform() const { - m_proFile = proFile; - proFileChanged(); - updateGui(); - - emit completeChanged(); + return m_creatorPlatform; } Ui::LibraryDetailsWidget *LibraryDetailsController::libraryDetailsWidget() const @@ -491,35 +506,35 @@ static QString generatePreTargetDepsSnippet(AddLibraryWizard::Platforms platform } NonInternalLibraryDetailsController::NonInternalLibraryDetailsController( - Ui::LibraryDetailsWidget *libraryDetails, QObject *parent) : - LibraryDetailsController(libraryDetails, parent) + Ui::LibraryDetailsWidget *libraryDetails, + const QString &proFile, QObject *parent) : + LibraryDetailsController(libraryDetails, proFile, parent) { setLibraryComboBoxVisible(false); setLibraryPathChooserVisible(true); -#ifdef Q_OS_WIN - libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter( - QLatin1String("Library file (*.lib)")); - setLinkageRadiosVisible(true); - setRemoveSuffixVisible(true); -#else - setLinkageRadiosVisible(false); - setRemoveSuffixVisible(false); -#endif + if (creatorPlatform() == CreatorWindows) { + libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter( + QLatin1String("Library file (*.lib)")); + setLinkageRadiosVisible(true); + setRemoveSuffixVisible(true); + } else { + setLinkageRadiosVisible(false); + setRemoveSuffixVisible(false); + } -#ifdef Q_OS_LINUX - libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter( - QLatin1String("Library file (lib*.so lib*.a)")); -#endif + if (creatorPlatform() == CreatorLinux) + libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter( + QLatin1String("Library file (lib*.so lib*.a)")); -#ifdef Q_OS_MAC - libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter( - QLatin1String("Library file (*.dylib *.a *.framework)")); + if (creatorPlatform() == CreatorMac) { + libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter( + QLatin1String("Library file (*.dylib *.a *.framework)")); // QLatin1String("Library file (lib*.dylib lib*.a *.framework)")); - libraryDetailsWidget()->libraryPathChooser->setExpectedKind(Utils::PathChooser::Any); -#else - libraryDetailsWidget()->libraryPathChooser->setExpectedKind(Utils::PathChooser::File); -#endif + libraryDetailsWidget()->libraryPathChooser->setExpectedKind(Utils::PathChooser::Any); + } else { + libraryDetailsWidget()->libraryPathChooser->setExpectedKind(Utils::PathChooser::File); + } connect(libraryDetailsWidget()->libraryPathChooser, SIGNAL(validChanged()), this, SIGNAL(completeChanged())); @@ -536,30 +551,30 @@ NonInternalLibraryDetailsController::NonInternalLibraryDetailsController( AddLibraryWizard::LinkageType NonInternalLibraryDetailsController::suggestedLinkageType() const { AddLibraryWizard::LinkageType type = AddLibraryWizard::NoLinkage; -#ifndef Q_OS_WIN - if (libraryDetailsWidget()->libraryPathChooser->isValid()) { - QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); - if (fi.suffix() == QLatin1String("a")) - type = AddLibraryWizard::StaticLinkage; - else - type = AddLibraryWizard::DynamicLinkage; + if (creatorPlatform() != CreatorWindows) { + if (libraryDetailsWidget()->libraryPathChooser->isValid()) { + QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); + if (fi.suffix() == QLatin1String("a")) + type = AddLibraryWizard::StaticLinkage; + else + type = AddLibraryWizard::DynamicLinkage; + } } -#endif return type; } AddLibraryWizard::MacLibraryType NonInternalLibraryDetailsController::suggestedMacLibraryType() const { AddLibraryWizard::MacLibraryType type = AddLibraryWizard::NoLibraryType; -#ifdef Q_OS_MAC - if (libraryDetailsWidget()->libraryPathChooser->isValid()) { - QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); - if (fi.suffix() == QLatin1String("framework")) - type = AddLibraryWizard::FrameworkType; - else - type = AddLibraryWizard::LibraryType; + if (creatorPlatform() == CreatorMac) { + if (libraryDetailsWidget()->libraryPathChooser->isValid()) { + QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); + if (fi.suffix() == QLatin1String("framework")) + type = AddLibraryWizard::FrameworkType; + else + type = AddLibraryWizard::LibraryType; + } } -#endif return type; } @@ -585,10 +600,10 @@ QString NonInternalLibraryDetailsController::suggestedIncludePath() const void NonInternalLibraryDetailsController::updateWindowsOptionsEnablement() { bool ena = platforms() & AddLibraryWizard::WindowsPlatform; -#ifdef Q_OS_WIN - libraryDetailsWidget()->addSuffixCheckBox->setEnabled(ena); - ena = true; -#endif + if (creatorPlatform() == CreatorWindows) { + libraryDetailsWidget()->addSuffixCheckBox->setEnabled(ena); + ena = true; + } libraryDetailsWidget()->winGroupBox->setEnabled(ena); } @@ -617,29 +632,29 @@ void NonInternalLibraryDetailsController::slotRemoveSuffixChanged(bool ena) void NonInternalLibraryDetailsController::slotLibraryPathChanged() { -#ifdef Q_OS_WIN - bool subfoldersEnabled = true; - bool removeSuffixEnabled = true; - if (libraryDetailsWidget()->libraryPathChooser->isValid()) { - QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); - QFileInfo dfi(fi.absolutePath()); - const QString parentFolderName = dfi.fileName().toLower(); - if (parentFolderName != QLatin1String("debug") && + if (creatorPlatform() == CreatorWindows) { + bool subfoldersEnabled = true; + bool removeSuffixEnabled = true; + if (libraryDetailsWidget()->libraryPathChooser->isValid()) { + QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); + QFileInfo dfi(fi.absolutePath()); + const QString parentFolderName = dfi.fileName().toLower(); + if (parentFolderName != QLatin1String("debug") && parentFolderName != QLatin1String("release")) - subfoldersEnabled = false; - const QString baseName = fi.baseName(); - - if (baseName.isEmpty() || baseName.at(baseName.size() - 1).toLower() != QLatin1Char('d')) - removeSuffixEnabled = false; - - if (subfoldersEnabled) - libraryDetailsWidget()->useSubfoldersCheckBox->setChecked(true); - else if (removeSuffixEnabled) - libraryDetailsWidget()->removeSuffixCheckBox->setChecked(true); - else - libraryDetailsWidget()->addSuffixCheckBox->setChecked(true); + subfoldersEnabled = false; + const QString baseName = fi.baseName(); + + if (baseName.isEmpty() || baseName.at(baseName.size() - 1).toLower() != QLatin1Char('d')) + removeSuffixEnabled = false; + + if (subfoldersEnabled) + libraryDetailsWidget()->useSubfoldersCheckBox->setChecked(true); + else if (removeSuffixEnabled) + libraryDetailsWidget()->removeSuffixCheckBox->setChecked(true); + else + libraryDetailsWidget()->addSuffixCheckBox->setChecked(true); + } } -#endif updateGui(); @@ -659,29 +674,28 @@ QString NonInternalLibraryDetailsController::snippet() const QString libName; const bool removeSuffix = isWindowsGroupVisible() && libraryDetailsWidget()->removeSuffixCheckBox->isChecked(); -#if defined (Q_OS_WIN) - libName = fi.baseName(); - if (removeSuffix && !libName.isEmpty()) // remove last letter which needs to be "d" - libName = libName.left(libName.size() - 1); -#elif defined (Q_OS_MAC) - if (macLibraryType() == AddLibraryWizard::FrameworkType) + if (creatorPlatform() == CreatorWindows) { libName = fi.baseName(); - else + if (removeSuffix && !libName.isEmpty()) // remove last letter which needs to be "d" + libName = libName.left(libName.size() - 1); + } else if (creatorPlatform() == CreatorMac) { + if (macLibraryType() == AddLibraryWizard::FrameworkType) + libName = fi.baseName(); + else + libName = fi.baseName().mid(3); // cut the "lib" prefix + } else { libName = fi.baseName().mid(3); // cut the "lib" prefix -#else - libName = fi.baseName().mid(3); // cut the "lib" prefix -#endif + } + QString targetRelativePath; QString includeRelativePath; bool useSubfolders = false; bool addSuffix = false; if (isWindowsGroupVisible()) { - const bool useSubfoldersCondition = -#ifdef Q_OS_WIN - true; // we are on Win but we in case don't generate the code for Win we still need to remove "debug" or "release" subfolder -#else - platforms() & AddLibraryWizard::WindowsPlatform; -#endif + // when we are on Win but we don't generate the code for Win + // we still need to remove "debug" or "release" subfolder + const bool useSubfoldersCondition = (creatorPlatform() == CreatorWindows) + ? true : platforms() & AddLibraryWizard::WindowsPlatform; if (useSubfoldersCondition) useSubfolders = libraryDetailsWidget()->useSubfoldersCheckBox->isChecked(); if (platforms() & AddLibraryWizard::WindowsPlatform) @@ -691,12 +705,10 @@ QString NonInternalLibraryDetailsController::snippet() const QFileInfo pfi(proFile()); QDir pdir = pfi.absoluteDir(); QString absoluteLibraryPath = fi.absolutePath(); -#if defined (Q_OS_WIN) - if (useSubfolders) { // drop last subfolder which needs to be "debug" or "release" + if (creatorPlatform() == CreatorWindows && useSubfolders) { // drop last subfolder which needs to be "debug" or "release" QFileInfo libfi(absoluteLibraryPath); absoluteLibraryPath = libfi.absolutePath(); } -#endif // Q_OS_WIN targetRelativePath = appendSeparator(pdir.relativeFilePath(absoluteLibraryPath)); const QString includePath = libraryDetailsWidget()->includePathChooser->path(); @@ -722,27 +734,36 @@ QString NonInternalLibraryDetailsController::snippet() const ///////////// SystemLibraryDetailsController::SystemLibraryDetailsController( - Ui::LibraryDetailsWidget *libraryDetails, QObject *parent) - : NonInternalLibraryDetailsController(libraryDetails, parent) + Ui::LibraryDetailsWidget *libraryDetails, + const QString &proFile, QObject *parent) + : NonInternalLibraryDetailsController(libraryDetails, proFile, parent) { setIncludePathVisible(false); setWindowsGroupVisible(false); + + updateGui(); } ///////////// ExternalLibraryDetailsController::ExternalLibraryDetailsController( - Ui::LibraryDetailsWidget *libraryDetails, QObject *parent) - : NonInternalLibraryDetailsController(libraryDetails, parent) + Ui::LibraryDetailsWidget *libraryDetails, + const QString &proFile, QObject *parent) + : NonInternalLibraryDetailsController(libraryDetails, proFile, parent) { setIncludePathVisible(true); setWindowsGroupVisible(true); + + updateGui(); } void ExternalLibraryDetailsController::updateWindowsOptionsEnablement() { NonInternalLibraryDetailsController::updateWindowsOptionsEnablement(); -#ifdef Q_OS_WIN + + if (creatorPlatform() != CreatorWindows) + return; + bool subfoldersEnabled = true; bool removeSuffixEnabled = true; if (libraryDetailsWidget()->libraryPathChooser->isValid()) { @@ -760,14 +781,14 @@ void ExternalLibraryDetailsController::updateWindowsOptionsEnablement() } libraryDetailsWidget()->useSubfoldersCheckBox->setEnabled(subfoldersEnabled); libraryDetailsWidget()->removeSuffixCheckBox->setEnabled(removeSuffixEnabled); -#endif } ///////////// InternalLibraryDetailsController::InternalLibraryDetailsController( - Ui::LibraryDetailsWidget *libraryDetails, QObject *parent) - : LibraryDetailsController(libraryDetails, parent) + Ui::LibraryDetailsWidget *libraryDetails, + const QString &proFile, QObject *parent) + : LibraryDetailsController(libraryDetails, proFile, parent) { setLinkageRadiosVisible(false); setLibraryPathChooserVisible(false); @@ -776,12 +797,14 @@ InternalLibraryDetailsController::InternalLibraryDetailsController( setWindowsGroupVisible(true); setRemoveSuffixVisible(false); -#ifdef Q_OS_WIN - libraryDetailsWidget()->useSubfoldersCheckBox->setEnabled(true); -#endif + if (creatorPlatform() == CreatorWindows) + libraryDetailsWidget()->useSubfoldersCheckBox->setEnabled(true); connect(libraryDetailsWidget()->libraryComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentLibraryChanged())); + + updateProFile(); + updateGui(); } AddLibraryWizard::LinkageType InternalLibraryDetailsController::suggestedLinkageType() const @@ -829,14 +852,13 @@ QString InternalLibraryDetailsController::suggestedIncludePath() const void InternalLibraryDetailsController::updateWindowsOptionsEnablement() { -#ifdef Q_OS_WIN - libraryDetailsWidget()->addSuffixCheckBox->setEnabled(true); -#endif + if (creatorPlatform() == CreatorWindows) + libraryDetailsWidget()->addSuffixCheckBox->setEnabled(true); libraryDetailsWidget()->winGroupBox->setEnabled(platforms() & AddLibraryWizard::WindowsPlatform); } -void InternalLibraryDetailsController::proFileChanged() +void InternalLibraryDetailsController::updateProFile() { m_rootProjectPath.clear(); m_proFileNodes.clear(); @@ -884,14 +906,14 @@ void InternalLibraryDetailsController::slotCurrentLibraryChanged() currentIndex, Qt::ToolTipRole).toString()); Qt4ProFileNode *proFileNode = m_proFileNodes.at(currentIndex); const QStringList configVar = proFileNode->variableValue(ConfigVar); -#ifdef Q_OS_WIN - bool useSubfolders = false; - if (configVar.contains(QLatin1String("debug_and_release")) + if (creatorPlatform() == CreatorWindows) { + bool useSubfolders = false; + if (configVar.contains(QLatin1String("debug_and_release")) && configVar.contains(QLatin1String("debug_and_release_target"))) - useSubfolders = true; - libraryDetailsWidget()->useSubfoldersCheckBox->setChecked(useSubfolders); - libraryDetailsWidget()->addSuffixCheckBox->setChecked(!useSubfolders); -#endif // Q_OS_WIN + useSubfolders = true; + libraryDetailsWidget()->useSubfoldersCheckBox->setChecked(useSubfolders); + libraryDetailsWidget()->addSuffixCheckBox->setChecked(!useSubfolders); + } } if (guiSignalsIgnored()) diff --git a/src/plugins/qt4projectmanager/librarydetailscontroller.h b/src/plugins/qt4projectmanager/librarydetailscontroller.h index a240dcba1474e7e2a110523be130a51eed36bf2f..e0afd57091f99196621af3bd3033f3975f128ec4 100644 --- a/src/plugins/qt4projectmanager/librarydetailscontroller.h +++ b/src/plugins/qt4projectmanager/librarydetailscontroller.h @@ -18,14 +18,22 @@ class LibraryDetailsController : public QObject Q_OBJECT public: explicit LibraryDetailsController(Ui::LibraryDetailsWidget *libraryDetails, + const QString &proFile, QObject *parent = 0); virtual bool isComplete() const = 0; - void setProFile(const QString &proFile); virtual QString snippet() const = 0; signals: void completeChanged(); protected: + enum CreatorPlatform { + CreatorLinux, + CreatorMac, + CreatorWindows + }; + + CreatorPlatform creatorPlatform() const; + Ui::LibraryDetailsWidget *libraryDetailsWidget() const; AddLibraryWizard::Platforms platforms() const; @@ -35,8 +43,6 @@ protected: bool isIncludePathChanged() const; bool guiSignalsIgnored() const; - virtual void proFileChanged() {} - void updateGui(); virtual AddLibraryWizard::LinkageType suggestedLinkageType() const = 0; virtual AddLibraryWizard::MacLibraryType suggestedMacLibraryType() const = 0; @@ -74,6 +80,8 @@ private: QString m_proFile; + CreatorPlatform m_creatorPlatform; + bool m_ignoreGuiSignals; bool m_includePathChanged; @@ -90,6 +98,7 @@ class NonInternalLibraryDetailsController : public LibraryDetailsController Q_OBJECT public: explicit NonInternalLibraryDetailsController(Ui::LibraryDetailsWidget *libraryDetails, + const QString &proFile, QObject *parent = 0); virtual bool isComplete() const; virtual QString snippet() const; @@ -109,7 +118,8 @@ class SystemLibraryDetailsController : public NonInternalLibraryDetailsControlle Q_OBJECT public: explicit SystemLibraryDetailsController(Ui::LibraryDetailsWidget *libraryDetails, - QObject *parent = 0); + const QString &proFile, + QObject *parent = 0); }; class ExternalLibraryDetailsController : public NonInternalLibraryDetailsController @@ -117,7 +127,8 @@ class ExternalLibraryDetailsController : public NonInternalLibraryDetailsControl Q_OBJECT public: explicit ExternalLibraryDetailsController(Ui::LibraryDetailsWidget *libraryDetails, - QObject *parent = 0); + const QString &proFile, + QObject *parent = 0); protected: virtual void updateWindowsOptionsEnablement(); }; @@ -127,7 +138,8 @@ class InternalLibraryDetailsController : public LibraryDetailsController Q_OBJECT public: explicit InternalLibraryDetailsController(Ui::LibraryDetailsWidget *libraryDetails, - QObject *parent = 0); + const QString &proFile, + QObject *parent = 0); virtual bool isComplete() const; virtual QString snippet() const; protected: @@ -135,9 +147,9 @@ protected: virtual AddLibraryWizard::MacLibraryType suggestedMacLibraryType() const; virtual QString suggestedIncludePath() const; virtual void updateWindowsOptionsEnablement(); - virtual void proFileChanged(); private slots: void slotCurrentLibraryChanged(); + void updateProFile(); private: QString m_rootProjectPath; QVector<Qt4ProFileNode *> m_proFileNodes;