Allow non-host-platform libraries in Add Library wizard

Since much of the available UI and behavior depends on which platform's
library we start with, let the user choose a platform filter.
Default is the host OS.

Task-number: QTCREATORBUG-17995
Change-Id: Ic8bec7ac30eecf08c1684da4f2823a8add8f6d20
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2018-09-24 12:26:46 +02:00
parent 1785b0f561
commit f5647cc2c4
4 changed files with 94 additions and 56 deletions

View File

@@ -655,6 +655,7 @@ QString PathChooser::promptDialogTitle() const
void PathChooser::setPromptDialogFilter(const QString &filter) void PathChooser::setPromptDialogFilter(const QString &filter)
{ {
d->m_dialogFilter = filter; d->m_dialogFilter = filter;
d->m_lineEdit->validate();
} }
QString PathChooser::promptDialogFilter() const QString PathChooser::promptDialogFilter() const

View File

@@ -43,6 +43,16 @@ using namespace ProjectExplorer;
using namespace QmakeProjectManager; using namespace QmakeProjectManager;
using namespace QmakeProjectManager::Internal; using namespace QmakeProjectManager::Internal;
static void fillLibraryPlatformTypes(QComboBox *comboBox)
{
comboBox->clear();
comboBox->addItem("Windows (*.lib lib*.a)", int(Utils::OsTypeWindows));
comboBox->addItem("Linux (lib*.so lib*.a)", int(Utils::OsTypeLinux));
comboBox->addItem("macOS (*.dylib *.a *.framework)", int(Utils::OsTypeMac));
const int currentIndex = comboBox->findData(int(Utils::HostOsInfo::hostOs()));
comboBox->setCurrentIndex(std::max(0, currentIndex));
}
LibraryDetailsController::LibraryDetailsController( LibraryDetailsController::LibraryDetailsController(
Ui::LibraryDetailsWidget *libraryDetails, Ui::LibraryDetailsWidget *libraryDetails,
const QString &proFile, QObject *parent) : const QString &proFile, QObject *parent) :
@@ -73,6 +83,8 @@ LibraryDetailsController::LibraryDetailsController(
this, &LibraryDetailsController::slotPlatformChanged); this, &LibraryDetailsController::slotPlatformChanged);
connect(m_libraryDetailsWidget->winCheckBox, &QAbstractButton::clicked, connect(m_libraryDetailsWidget->winCheckBox, &QAbstractButton::clicked,
this, &LibraryDetailsController::slotPlatformChanged); this, &LibraryDetailsController::slotPlatformChanged);
fillLibraryPlatformTypes(m_libraryDetailsWidget->libraryTypeComboBox);
} }
Ui::LibraryDetailsWidget *LibraryDetailsController::libraryDetailsWidget() const Ui::LibraryDetailsWidget *LibraryDetailsController::libraryDetailsWidget() const
@@ -95,6 +107,16 @@ AddLibraryWizard::MacLibraryType LibraryDetailsController::macLibraryType() cons
return m_macLibraryType; return m_macLibraryType;
} }
Utils::OsType LibraryDetailsController::libraryPlatformType() const
{
return Utils::OsType(m_libraryDetailsWidget->libraryTypeComboBox->currentData().value<int>());
}
QString LibraryDetailsController::libraryPlatformFilter() const
{
return m_libraryDetailsWidget->libraryTypeComboBox->currentText();
}
void LibraryDetailsController::updateGui() void LibraryDetailsController::updateGui()
{ {
// read values from gui // read values from gui
@@ -249,6 +271,8 @@ void LibraryDetailsController::setMacLibraryGroupVisible(bool ena)
void LibraryDetailsController::setLibraryPathChooserVisible(bool ena) void LibraryDetailsController::setLibraryPathChooserVisible(bool ena)
{ {
libraryDetailsWidget()->libraryTypeComboBox->setVisible(ena);
libraryDetailsWidget()->libraryTypeLabel->setVisible(ena);
libraryDetailsWidget()->libraryPathChooser->setVisible(ena); libraryDetailsWidget()->libraryPathChooser->setVisible(ena);
libraryDetailsWidget()->libraryFileLabel->setVisible(ena); libraryDetailsWidget()->libraryFileLabel->setVisible(ena);
} }
@@ -578,29 +602,6 @@ NonInternalLibraryDetailsController::NonInternalLibraryDetailsController(
setLibraryComboBoxVisible(false); setLibraryComboBoxVisible(false);
setLibraryPathChooserVisible(true); setLibraryPathChooserVisible(true);
if (Utils::HostOsInfo::isWindowsHost()) {
libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter(
QLatin1String("Library file (*.lib lib*.a)"));
setLinkageRadiosVisible(true);
setRemoveSuffixVisible(true);
} else {
setLinkageRadiosVisible(false);
setRemoveSuffixVisible(false);
}
if (Utils::HostOsInfo::isLinuxHost())
libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter(
QLatin1String("Library file (lib*.so lib*.a)"));
if (Utils::HostOsInfo::isMacHost()) {
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);
}
connect(libraryDetailsWidget()->libraryPathChooser, &Utils::PathChooser::validChanged, connect(libraryDetailsWidget()->libraryPathChooser, &Utils::PathChooser::validChanged,
this, &LibraryDetailsController::completeChanged); this, &LibraryDetailsController::completeChanged);
connect(libraryDetailsWidget()->libraryPathChooser, &Utils::PathChooser::rawPathChanged, connect(libraryDetailsWidget()->libraryPathChooser, &Utils::PathChooser::rawPathChanged,
@@ -611,12 +612,15 @@ NonInternalLibraryDetailsController::NonInternalLibraryDetailsController(
this, &NonInternalLibraryDetailsController::slotLinkageTypeChanged); this, &NonInternalLibraryDetailsController::slotLinkageTypeChanged);
connect(libraryDetailsWidget()->staticRadio, &QAbstractButton::clicked, connect(libraryDetailsWidget()->staticRadio, &QAbstractButton::clicked,
this, &NonInternalLibraryDetailsController::slotLinkageTypeChanged); this, &NonInternalLibraryDetailsController::slotLinkageTypeChanged);
connect(libraryDetailsWidget()->libraryTypeComboBox, &QComboBox::currentTextChanged,
this, &NonInternalLibraryDetailsController::slotLibraryTypeChanged);
slotLibraryTypeChanged();
} }
AddLibraryWizard::LinkageType NonInternalLibraryDetailsController::suggestedLinkageType() const AddLibraryWizard::LinkageType NonInternalLibraryDetailsController::suggestedLinkageType() const
{ {
AddLibraryWizard::LinkageType type = AddLibraryWizard::NoLinkage; AddLibraryWizard::LinkageType type = AddLibraryWizard::NoLinkage;
if (!Utils::HostOsInfo::isWindowsHost()) { if (libraryPlatformType() != Utils::OsTypeWindows) {
if (libraryDetailsWidget()->libraryPathChooser->isValid()) { if (libraryDetailsWidget()->libraryPathChooser->isValid()) {
QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path());
if (fi.suffix() == QLatin1String("a")) if (fi.suffix() == QLatin1String("a"))
@@ -631,7 +635,7 @@ AddLibraryWizard::LinkageType NonInternalLibraryDetailsController::suggestedLink
AddLibraryWizard::MacLibraryType NonInternalLibraryDetailsController::suggestedMacLibraryType() const AddLibraryWizard::MacLibraryType NonInternalLibraryDetailsController::suggestedMacLibraryType() const
{ {
AddLibraryWizard::MacLibraryType type = AddLibraryWizard::NoLibraryType; AddLibraryWizard::MacLibraryType type = AddLibraryWizard::NoLibraryType;
if (Utils::HostOsInfo::isMacHost()) { if (libraryPlatformType() == Utils::OsTypeMac) {
if (libraryDetailsWidget()->libraryPathChooser->isValid()) { if (libraryDetailsWidget()->libraryPathChooser->isValid()) {
QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path());
if (fi.suffix() == QLatin1String("framework")) if (fi.suffix() == QLatin1String("framework"))
@@ -665,7 +669,7 @@ QString NonInternalLibraryDetailsController::suggestedIncludePath() const
void NonInternalLibraryDetailsController::updateWindowsOptionsEnablement() void NonInternalLibraryDetailsController::updateWindowsOptionsEnablement()
{ {
bool ena = platforms() & (AddLibraryWizard::WindowsMinGWPlatform | AddLibraryWizard::WindowsMSVCPlatform); bool ena = platforms() & (AddLibraryWizard::WindowsMinGWPlatform | AddLibraryWizard::WindowsMSVCPlatform);
if (Utils::HostOsInfo::isWindowsHost()) { if (libraryPlatformType() == Utils::OsTypeWindows) {
libraryDetailsWidget()->addSuffixCheckBox->setEnabled(ena); libraryDetailsWidget()->addSuffixCheckBox->setEnabled(ena);
ena = true; ena = true;
} }
@@ -695,9 +699,26 @@ void NonInternalLibraryDetailsController::slotRemoveSuffixChanged(bool ena)
} }
} }
void NonInternalLibraryDetailsController::slotLibraryTypeChanged()
{
libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter(libraryPlatformFilter());
const bool isMacOs = libraryPlatformType() == Utils::OsTypeMac;
const bool isWindows = libraryPlatformType() == Utils::OsTypeWindows;
libraryDetailsWidget()->libraryPathChooser->setExpectedKind(isMacOs ? Utils::PathChooser::Any
: Utils::PathChooser::File);
setMacLibraryRadiosVisible(!isMacOs);
setLinkageRadiosVisible(isWindows);
setRemoveSuffixVisible(isWindows);
updateWindowsOptionsEnablement();
slotLibraryPathChanged();
slotLinkageTypeChanged();
libraryDetailsWidget()->detailsLayout->parentWidget()->window()->adjustSize();
}
void NonInternalLibraryDetailsController::slotLibraryPathChanged() void NonInternalLibraryDetailsController::slotLibraryPathChanged()
{ {
if (Utils::HostOsInfo::isWindowsHost()) { if (libraryPlatformType() == Utils::OsTypeWindows) {
bool subfoldersEnabled = true; bool subfoldersEnabled = true;
bool removeSuffixEnabled = true; bool removeSuffixEnabled = true;
if (libraryDetailsWidget()->libraryPathChooser->isValid()) { if (libraryDetailsWidget()->libraryPathChooser->isValid()) {
@@ -739,13 +760,13 @@ QString NonInternalLibraryDetailsController::snippet() const
QString libName; QString libName;
const bool removeSuffix = isWindowsGroupVisible() const bool removeSuffix = isWindowsGroupVisible()
&& libraryDetailsWidget()->removeSuffixCheckBox->isChecked(); && libraryDetailsWidget()->removeSuffixCheckBox->isChecked();
if (Utils::HostOsInfo::isWindowsHost()) { if (libraryPlatformType() == Utils::OsTypeWindows) {
libName = fi.completeBaseName(); libName = fi.completeBaseName();
if (removeSuffix && !libName.isEmpty()) // remove last letter which needs to be "d" if (removeSuffix && !libName.isEmpty()) // remove last letter which needs to be "d"
libName = libName.left(libName.size() - 1); libName = libName.left(libName.size() - 1);
if (fi.completeSuffix() == QLatin1String("a")) // the mingw lib case if (fi.completeSuffix() == QLatin1String("a")) // the mingw lib case
libName = libName.mid(3); // cut the "lib" prefix libName = libName.mid(3); // cut the "lib" prefix
} else if (Utils::HostOsInfo::isMacHost()) { } else if (libraryPlatformType() == Utils::OsTypeMac) {
if (macLibraryType() == AddLibraryWizard::FrameworkType) if (macLibraryType() == AddLibraryWizard::FrameworkType)
libName = fi.completeBaseName(); libName = fi.completeBaseName();
else else
@@ -759,7 +780,7 @@ QString NonInternalLibraryDetailsController::snippet() const
if (isWindowsGroupVisible()) { if (isWindowsGroupVisible()) {
// when we are on Win but we don't generate the code for Win // when we are on Win but we don't generate the code for Win
// we still need to remove "debug" or "release" subfolder // we still need to remove "debug" or "release" subfolder
const bool useSubfoldersCondition = (Utils::HostOsInfo::isWindowsHost()) const bool useSubfoldersCondition = (libraryPlatformType() == Utils::OsTypeWindows)
? true : platforms() & (AddLibraryWizard::WindowsMinGWPlatform ? true : platforms() & (AddLibraryWizard::WindowsMinGWPlatform
| AddLibraryWizard::WindowsMSVCPlatform); | AddLibraryWizard::WindowsMSVCPlatform);
if (useSubfoldersCondition) if (useSubfoldersCondition)
@@ -774,7 +795,7 @@ QString NonInternalLibraryDetailsController::snippet() const
QFileInfo pfi(proFile()); QFileInfo pfi(proFile());
QDir pdir = pfi.absoluteDir(); QDir pdir = pfi.absoluteDir();
QString absoluteLibraryPath = fi.absolutePath(); QString absoluteLibraryPath = fi.absolutePath();
if (Utils::HostOsInfo::isWindowsHost() && useSubfolders) { // drop last subfolder which needs to be "debug" or "release" if (libraryPlatformType() == Utils::OsTypeWindows && useSubfolders) { // drop last subfolder which needs to be "debug" or "release"
QFileInfo libfi(absoluteLibraryPath); QFileInfo libfi(absoluteLibraryPath);
absoluteLibraryPath = libfi.absolutePath(); absoluteLibraryPath = libfi.absolutePath();
} }
@@ -889,12 +910,10 @@ void ExternalLibraryDetailsController::updateWindowsOptionsEnablement()
{ {
NonInternalLibraryDetailsController::updateWindowsOptionsEnablement(); NonInternalLibraryDetailsController::updateWindowsOptionsEnablement();
if (!Utils::HostOsInfo::isWindowsHost())
return;
bool subfoldersEnabled = true; bool subfoldersEnabled = true;
bool removeSuffixEnabled = true; bool removeSuffixEnabled = true;
if (libraryDetailsWidget()->libraryPathChooser->isValid()) { if (libraryPlatformType() == Utils::OsTypeWindows
&& libraryDetailsWidget()->libraryPathChooser->isValid()) {
QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path()); QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path());
QFileInfo dfi(fi.absolutePath()); QFileInfo dfi(fi.absolutePath());
const QString parentFolderName = dfi.fileName().toLower(); const QString parentFolderName = dfi.fileName().toLower();
@@ -905,7 +924,6 @@ void ExternalLibraryDetailsController::updateWindowsOptionsEnablement()
if (baseName.isEmpty() || baseName.at(baseName.size() - 1).toLower() != QLatin1Char('d')) if (baseName.isEmpty() || baseName.at(baseName.size() - 1).toLower() != QLatin1Char('d'))
removeSuffixEnabled = false; removeSuffixEnabled = false;
} }
libraryDetailsWidget()->useSubfoldersCheckBox->setEnabled(subfoldersEnabled); libraryDetailsWidget()->useSubfoldersCheckBox->setEnabled(subfoldersEnabled);
libraryDetailsWidget()->removeSuffixCheckBox->setEnabled(removeSuffixEnabled); libraryDetailsWidget()->removeSuffixCheckBox->setEnabled(removeSuffixEnabled);

View File

@@ -52,6 +52,8 @@ protected:
AddLibraryWizard::Platforms platforms() const; AddLibraryWizard::Platforms platforms() const;
AddLibraryWizard::LinkageType linkageType() const; AddLibraryWizard::LinkageType linkageType() const;
AddLibraryWizard::MacLibraryType macLibraryType() const; AddLibraryWizard::MacLibraryType macLibraryType() const;
Utils::OsType libraryPlatformType() const;
QString libraryPlatformFilter() const;
QString proFile() const; QString proFile() const;
bool isIncludePathChanged() const; bool isIncludePathChanged() const;
bool guiSignalsIgnored() const; bool guiSignalsIgnored() const;
@@ -127,6 +129,7 @@ protected:
private: private:
void slotLinkageTypeChanged(); void slotLinkageTypeChanged();
void slotRemoveSuffixChanged(bool ena); void slotRemoveSuffixChanged(bool ena);
void slotLibraryTypeChanged();
void slotLibraryPathChanged(); void slotLibraryPathChanged();
}; };

View File

@@ -6,13 +6,23 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>455</width> <width>456</width>
<height>370</height> <height>438</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="libraryFileLabel">
<property name="text">
<string>Library file:</string>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="libraryLabel"> <widget class="QLabel" name="libraryLabel">
<property name="text"> <property name="text">
@@ -20,30 +30,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="4" column="0">
<widget class="QComboBox" name="libraryComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="libraryFileLabel">
<property name="text">
<string>Library file:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::PathChooser" name="libraryPathChooser" native="true"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="includeLabel"> <widget class="QLabel" name="includeLabel">
<property name="text"> <property name="text">
<string>Include path:</string> <string>Include path:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="4" column="1">
<widget class="Utils::PathChooser" name="includePathChooser" native="true"/> <widget class="Utils::PathChooser" name="includePathChooser" native="true"/>
</item> </item>
<item row="2" column="0"> <item row="3" column="1">
<widget class="QLineEdit" name="packageLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="packageLabel"> <widget class="QLabel" name="packageLabel">
<property name="text"> <property name="text">
<string>Package:</string> <string>Package:</string>
@@ -51,7 +51,20 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="packageLineEdit"/> <widget class="Utils::PathChooser" name="libraryPathChooser" native="true"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="libraryComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="libraryTypeLabel">
<property name="text">
<string>Library type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="libraryTypeComboBox"/>
</item> </item>
</layout> </layout>
</item> </item>
@@ -115,7 +128,10 @@
</layout> </layout>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="detailsLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item> <item>
<widget class="QGroupBox" name="linkageGroupBox"> <widget class="QGroupBox" name="linkageGroupBox">
<property name="title"> <property name="title">