2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-18 10:36:52 +01: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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-18 10:36:52 +01:00
|
|
|
|
2010-08-16 18:23:30 +02:00
|
|
|
#include "addlibrarywizard.h"
|
|
|
|
|
#include "ui_librarydetailswidget.h"
|
|
|
|
|
#include "librarydetailscontroller.h"
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2016-08-08 15:16:24 +02:00
|
|
|
#include <utils/fileutils.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QRadioButton>
|
|
|
|
|
#include <QLabel>
|
2010-08-16 18:23:30 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
2016-08-08 15:16:24 +02:00
|
|
|
#include <QTextStream>
|
2010-08-16 18:23:30 +02:00
|
|
|
|
2013-10-16 11:02:37 +02:00
|
|
|
using namespace QmakeProjectManager;
|
|
|
|
|
using namespace QmakeProjectManager::Internal;
|
2010-08-16 18:23:30 +02:00
|
|
|
|
2013-09-26 13:01:29 +02:00
|
|
|
const char qt_file_dialog_filter_reg_exp[] =
|
2010-08-16 18:23:30 +02:00
|
|
|
"^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
|
|
|
|
|
|
|
|
|
|
// taken from qfiledialog.cpp
|
|
|
|
|
QStringList qt_clean_filter_list(const QString &filter)
|
|
|
|
|
{
|
|
|
|
|
QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
|
|
|
|
|
QString f = filter;
|
|
|
|
|
int i = regexp.indexIn(f);
|
|
|
|
|
if (i >= 0)
|
|
|
|
|
f = regexp.cap(2);
|
|
|
|
|
return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
static bool validateLibraryPath(const Utils::FilePath &filePath,
|
2016-08-08 15:16:24 +02:00
|
|
|
const Utils::PathChooser *pathChooser,
|
2015-02-27 16:24:29 +01:00
|
|
|
QString *errorMessage)
|
2010-08-16 18:23:30 +02:00
|
|
|
{
|
2015-02-27 16:24:29 +01:00
|
|
|
Q_UNUSED(errorMessage);
|
2016-08-08 15:16:24 +02:00
|
|
|
if (!filePath.exists())
|
2010-08-16 18:23:30 +02:00
|
|
|
return false;
|
|
|
|
|
|
2016-08-08 15:16:24 +02:00
|
|
|
const QString fileName = filePath.fileName();
|
2010-08-16 18:23:30 +02:00
|
|
|
|
2015-02-27 16:24:29 +01:00
|
|
|
QStringList filters = qt_clean_filter_list(pathChooser->promptDialogFilter());
|
2010-08-16 18:23:30 +02:00
|
|
|
for (int i = 0; i < filters.count(); i++) {
|
|
|
|
|
QRegExp regExp(filters.at(i));
|
2016-08-08 15:16:24 +02:00
|
|
|
regExp.setCaseSensitivity(Utils::HostOsInfo::fileNameCaseSensitivity());
|
2010-08-16 18:23:30 +02:00
|
|
|
regExp.setPatternSyntax(QRegExp::Wildcard);
|
|
|
|
|
if (regExp.exactMatch(fileName))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddLibraryWizard::AddLibraryWizard(const QString &fileName, QWidget *parent) :
|
|
|
|
|
Utils::Wizard(parent), m_proFile(fileName)
|
|
|
|
|
{
|
|
|
|
|
setWindowTitle(tr("Add Library"));
|
|
|
|
|
m_libraryTypePage = new LibraryTypePage(this);
|
2014-05-30 11:38:08 +02:00
|
|
|
addPage(m_libraryTypePage);
|
2010-08-16 18:23:30 +02:00
|
|
|
m_detailsPage = new DetailsPage(this);
|
2014-05-30 11:38:08 +02:00
|
|
|
addPage(m_detailsPage);
|
2010-08-16 18:23:30 +02:00
|
|
|
m_summaryPage = new SummaryPage(this);
|
2014-05-30 11:38:08 +02:00
|
|
|
addPage(m_summaryPage);
|
2010-08-16 18:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-12 23:59:51 +02:00
|
|
|
AddLibraryWizard::~AddLibraryWizard() = default;
|
2010-08-16 18:23:30 +02:00
|
|
|
|
|
|
|
|
QString AddLibraryWizard::proFile() const
|
|
|
|
|
{
|
|
|
|
|
return m_proFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddLibraryWizard::LibraryKind AddLibraryWizard::libraryKind() const
|
|
|
|
|
{
|
|
|
|
|
return m_libraryTypePage->libraryKind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AddLibraryWizard::snippet() const
|
|
|
|
|
{
|
|
|
|
|
return m_detailsPage->snippet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
|
|
LibraryTypePage::LibraryTypePage(AddLibraryWizard *parent)
|
|
|
|
|
: QWizardPage(parent)
|
|
|
|
|
{
|
2010-09-15 15:16:13 +02:00
|
|
|
setTitle(tr("Library Type"));
|
2010-09-16 14:39:12 +02:00
|
|
|
setSubTitle(tr("Choose the type of the library to link to"));
|
2010-08-16 18:23:30 +02:00
|
|
|
|
2018-07-12 23:59:51 +02:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
2010-08-16 18:23:30 +02:00
|
|
|
|
2010-11-10 12:50:02 +01:00
|
|
|
m_internalRadio = new QRadioButton(tr("Internal library"), this);
|
|
|
|
|
layout->addWidget(m_internalRadio);
|
2010-09-16 14:39:12 +02:00
|
|
|
|
2010-11-10 12:50:02 +01:00
|
|
|
QLabel *internalLabel = new QLabel(tr("Links to a library "
|
|
|
|
|
"that is located in your build "
|
|
|
|
|
"tree.\nAdds the library and "
|
|
|
|
|
"include paths to the .pro file."));
|
2010-09-16 14:39:12 +02:00
|
|
|
|
2010-11-10 12:50:02 +01:00
|
|
|
internalLabel->setWordWrap(true);
|
|
|
|
|
internalLabel->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
|
layout->addWidget(internalLabel);
|
2010-08-16 18:23:30 +02:00
|
|
|
|
2010-09-16 14:40:01 +02:00
|
|
|
m_externalRadio = new QRadioButton(tr("External library"), this);
|
2010-08-16 18:23:30 +02:00
|
|
|
layout->addWidget(m_externalRadio);
|
2010-09-16 14:39:12 +02:00
|
|
|
|
|
|
|
|
QLabel *externalLabel = new QLabel(tr("Links to a library "
|
|
|
|
|
"that is not located in your "
|
|
|
|
|
"build tree.\nAdds the library "
|
|
|
|
|
"and include paths to the .pro file."));
|
|
|
|
|
|
2010-08-16 18:23:30 +02:00
|
|
|
externalLabel->setWordWrap(true);
|
|
|
|
|
externalLabel->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
|
layout->addWidget(externalLabel);
|
|
|
|
|
|
2010-11-10 12:50:02 +01:00
|
|
|
m_systemRadio = new QRadioButton(tr("System library"), this);
|
|
|
|
|
layout->addWidget(m_systemRadio);
|
2010-09-16 14:39:12 +02:00
|
|
|
|
2010-11-10 12:50:02 +01:00
|
|
|
QLabel *systemLabel = new QLabel(tr("Links to a system library."
|
|
|
|
|
"\nNeither the path to the "
|
|
|
|
|
"library nor the path to its "
|
|
|
|
|
"includes is added to the .pro file."));
|
2010-09-16 14:39:12 +02:00
|
|
|
|
2010-11-10 12:50:02 +01:00
|
|
|
systemLabel->setWordWrap(true);
|
|
|
|
|
systemLabel->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
|
layout->addWidget(systemLabel);
|
|
|
|
|
|
|
|
|
|
m_packageRadio = new QRadioButton(tr("System package"), this);
|
|
|
|
|
layout->addWidget(m_packageRadio);
|
|
|
|
|
|
|
|
|
|
QLabel *packageLabel = new QLabel(tr("Links to a system library using pkg-config."));
|
|
|
|
|
|
|
|
|
|
packageLabel->setWordWrap(true);
|
|
|
|
|
packageLabel->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
|
layout->addWidget(packageLabel);
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
m_packageRadio->setVisible(false);
|
|
|
|
|
packageLabel->setVisible(false);
|
|
|
|
|
}
|
2010-11-10 12:50:02 +01:00
|
|
|
|
|
|
|
|
// select the default
|
|
|
|
|
m_internalRadio->setChecked(true);
|
2014-05-30 11:38:08 +02:00
|
|
|
|
|
|
|
|
setProperty(Utils::SHORT_TITLE_PROPERTY, tr("Type"));
|
2010-08-16 18:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddLibraryWizard::LibraryKind LibraryTypePage::libraryKind() const
|
|
|
|
|
{
|
|
|
|
|
if (m_internalRadio->isChecked())
|
|
|
|
|
return AddLibraryWizard::InternalLibrary;
|
2010-11-10 12:50:02 +01:00
|
|
|
if (m_externalRadio->isChecked())
|
|
|
|
|
return AddLibraryWizard::ExternalLibrary;
|
2010-08-16 18:23:30 +02:00
|
|
|
if (m_systemRadio->isChecked())
|
|
|
|
|
return AddLibraryWizard::SystemLibrary;
|
2010-11-10 12:50:02 +01:00
|
|
|
return AddLibraryWizard::PackageLibrary;
|
2010-08-16 18:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
|
|
DetailsPage::DetailsPage(AddLibraryWizard *parent)
|
2015-06-18 15:14:06 +02:00
|
|
|
: QWizardPage(parent), m_libraryWizard(parent)
|
2010-08-16 18:23:30 +02:00
|
|
|
{
|
|
|
|
|
m_libraryDetailsWidget = new Ui::LibraryDetailsWidget();
|
|
|
|
|
m_libraryDetailsWidget->setupUi(this);
|
2016-08-08 14:05:09 +02:00
|
|
|
|
2015-02-27 16:58:52 +01:00
|
|
|
Utils::PathChooser * const libPathChooser = m_libraryDetailsWidget->libraryPathChooser;
|
2016-08-08 14:05:09 +02:00
|
|
|
libPathChooser->setHistoryCompleter("Qmake.LibDir.History");
|
|
|
|
|
|
2015-04-28 14:49:56 +02:00
|
|
|
const auto pathValidator = [libPathChooser](Utils::FancyLineEdit *edit, QString *errorMessage) {
|
|
|
|
|
return libPathChooser->defaultValidationFunction()(edit, errorMessage)
|
2016-08-08 15:16:24 +02:00
|
|
|
&& validateLibraryPath(libPathChooser->fileName(),
|
|
|
|
|
libPathChooser, errorMessage);
|
2015-02-27 16:58:52 +01:00
|
|
|
};
|
2015-04-28 14:49:56 +02:00
|
|
|
libPathChooser->setValidationFunction(pathValidator);
|
2014-05-30 11:38:08 +02:00
|
|
|
setProperty(Utils::SHORT_TITLE_PROPERTY, tr("Details"));
|
2010-08-16 18:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DetailsPage::isComplete() const
|
|
|
|
|
{
|
|
|
|
|
if (m_libraryDetailsController)
|
|
|
|
|
return m_libraryDetailsController->isComplete();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DetailsPage::snippet() const
|
|
|
|
|
{
|
|
|
|
|
if (m_libraryDetailsController)
|
|
|
|
|
return m_libraryDetailsController->snippet();
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsPage::initializePage()
|
|
|
|
|
{
|
|
|
|
|
if (m_libraryDetailsController) {
|
|
|
|
|
delete m_libraryDetailsController;
|
2018-07-12 23:59:51 +02:00
|
|
|
m_libraryDetailsController = nullptr;
|
2010-08-16 18:23:30 +02:00
|
|
|
}
|
|
|
|
|
QString title;
|
|
|
|
|
QString subTitle;
|
|
|
|
|
switch (m_libraryWizard->libraryKind()) {
|
2010-11-10 12:50:02 +01:00
|
|
|
case AddLibraryWizard::InternalLibrary:
|
|
|
|
|
title = tr("Internal Library");
|
|
|
|
|
subTitle = tr("Choose the project file of the library to link to");
|
|
|
|
|
m_libraryDetailsController = new InternalLibraryDetailsController(
|
2010-08-24 12:47:12 +02:00
|
|
|
m_libraryDetailsWidget, m_libraryWizard->proFile(), this);
|
2010-08-16 18:23:30 +02:00
|
|
|
break;
|
|
|
|
|
case AddLibraryWizard::ExternalLibrary:
|
|
|
|
|
title = tr("External Library");
|
2010-09-16 14:39:12 +02:00
|
|
|
subTitle = tr("Specify the library to link to and the includes path");
|
2010-08-24 12:47:12 +02:00
|
|
|
m_libraryDetailsController = new ExternalLibraryDetailsController(
|
|
|
|
|
m_libraryDetailsWidget, m_libraryWizard->proFile(), this);
|
2010-08-16 18:23:30 +02:00
|
|
|
break;
|
2010-11-10 12:50:02 +01:00
|
|
|
case AddLibraryWizard::SystemLibrary:
|
|
|
|
|
title = tr("System Library");
|
|
|
|
|
subTitle = tr("Specify the library to link to");
|
|
|
|
|
m_libraryDetailsController = new SystemLibraryDetailsController(
|
|
|
|
|
m_libraryDetailsWidget, m_libraryWizard->proFile(), this);
|
|
|
|
|
break;
|
|
|
|
|
case AddLibraryWizard::PackageLibrary:
|
|
|
|
|
title = tr("System Package");
|
|
|
|
|
subTitle = tr("Specify the package to link to");
|
|
|
|
|
m_libraryDetailsController = new PackageLibraryDetailsController(
|
2010-08-24 12:47:12 +02:00
|
|
|
m_libraryDetailsWidget, m_libraryWizard->proFile(), this);
|
2010-08-16 18:23:30 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setTitle(title);
|
|
|
|
|
setSubTitle(subTitle);
|
|
|
|
|
if (m_libraryDetailsController) {
|
2016-05-24 23:21:57 +03:00
|
|
|
connect(m_libraryDetailsController, &LibraryDetailsController::completeChanged,
|
|
|
|
|
this, &QWizardPage::completeChanged);
|
2010-08-16 18:23:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
|
|
SummaryPage::SummaryPage(AddLibraryWizard *parent)
|
|
|
|
|
: QWizardPage(parent), m_libraryWizard(parent)
|
|
|
|
|
{
|
|
|
|
|
setTitle(tr("Summary"));
|
|
|
|
|
setFinalPage(true);
|
|
|
|
|
|
2018-07-12 23:59:51 +02:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
2010-08-16 18:23:30 +02:00
|
|
|
m_summaryLabel = new QLabel(this);
|
|
|
|
|
m_snippetLabel = new QLabel(this);
|
2013-10-22 12:46:12 +02:00
|
|
|
m_snippetLabel->setWordWrap(true);
|
2010-08-16 18:23:30 +02:00
|
|
|
layout->addWidget(m_summaryLabel);
|
|
|
|
|
layout->addWidget(m_snippetLabel);
|
|
|
|
|
m_summaryLabel->setTextFormat(Qt::RichText);
|
|
|
|
|
m_snippetLabel->setTextFormat(Qt::RichText);
|
|
|
|
|
m_snippetLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
2014-05-30 11:38:08 +02:00
|
|
|
|
|
|
|
|
setProperty(Utils::SHORT_TITLE_PROPERTY, tr("Summary"));
|
2010-08-16 18:23:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SummaryPage::initializePage()
|
|
|
|
|
{
|
|
|
|
|
m_snippet = m_libraryWizard->snippet();
|
|
|
|
|
QFileInfo fi(m_libraryWizard->proFile());
|
|
|
|
|
m_summaryLabel->setText(
|
|
|
|
|
tr("The following snippet will be added to the<br><b>%1</b> file:")
|
|
|
|
|
.arg(fi.fileName()));
|
|
|
|
|
QString richSnippet;
|
|
|
|
|
{
|
|
|
|
|
QTextStream str(&richSnippet);
|
|
|
|
|
str << "<code>";
|
|
|
|
|
QString text = m_snippet;
|
|
|
|
|
text.replace(QLatin1Char('\n'), QLatin1String("<br>"));
|
2010-11-10 12:50:02 +01:00
|
|
|
text.replace(QLatin1Char(' '), QLatin1String(" "));
|
2010-08-16 18:23:30 +02:00
|
|
|
str << text;
|
|
|
|
|
str << "</code>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_snippetLabel->setText(richSnippet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SummaryPage::snippet() const
|
|
|
|
|
{
|
|
|
|
|
return m_snippet;
|
|
|
|
|
}
|