Commit 573006f3 authored by Jarek Kobus's avatar Jarek Kobus
Browse files

Add "Add library wizard" to the pro file editor


Reviewed-by: default avatardt <qtc-committer@nokia.com>
Task-number: QTCREATORBUG-125
parent 8cd3b549
......@@ -173,13 +173,27 @@ void PathChooser::slotBrowse()
newPath = QFileDialog::getExistingDirectory(this,
makeDialogTitle(tr("Choose Directory")), predefined);
break;
case PathChooser::File: // fall through
case PathChooser::Command:
newPath = QFileDialog::getOpenFileName(this,
makeDialogTitle(tr("Choose File")), predefined,
m_d->m_dialogFilter);
break;
case PathChooser::Any: {
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setWindowTitle(makeDialogTitle(tr("Choose File")));
QFileInfo fi(predefined);
if (fi.exists())
dialog.setDirectory(fi.absolutePath());
dialog.setNameFilter(m_d->m_dialogFilter); // fix QFileDialog so that it filters properly: lib*.a
if (dialog.exec() == QDialog::Accepted) { // probably loop here until the *.framework dir match
QStringList paths = dialog.selectedFiles();
if (!paths.isEmpty())
newPath = paths.at(0);
}
break;
}
default:
;
......@@ -255,6 +269,9 @@ bool PathChooser::validatePath(const QString &path, QString *errorMessage)
// i.e. search $PATH for a matching file
break;
case PathChooser::Any:
break;
default:
;
}
......
......@@ -62,8 +62,8 @@ public:
enum Kind {
Directory,
File,
Command
// ,Any
Command,
Any
};
// Default is <Directory>
......
#include "addlibrarywizard.h"
#include "ui_librarydetailswidget.h"
#include "librarydetailscontroller.h"
#include <QtGui/QVBoxLayout>
#include <QtGui/QRadioButton>
#include <QtGui/QLabel>
#include <QtCore/QFileInfo>
#include <QDebug>
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
const char *qt_file_dialog_filter_reg_exp =
"^(.*)\\(([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);
}
LibraryPathChooser::LibraryPathChooser(QWidget *parent)
: Utils::PathChooser(parent)
{
}
bool LibraryPathChooser::validatePath(const QString &path, QString *errorMessage)
{
bool result = PathChooser::validatePath(path, errorMessage);
if (!result)
return false;
QFileInfo fi(path);
if (!fi.exists())
return false;
const QString fileName = fi.fileName();
QStringList filters = qt_clean_filter_list(promptDialogFilter());
for (int i = 0; i < filters.count(); i++) {
QRegExp regExp(filters.at(i));
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"));
setAutomaticProgressCreationEnabled(false);
m_libraryTypePage = new LibraryTypePage(this);
m_detailsPage = new DetailsPage(this);
m_summaryPage = new SummaryPage(this);
setPage(LibraryTypePageId, m_libraryTypePage);
setPage(DetailsPageId, m_detailsPage);
setPage(SummaryPageId, m_summaryPage);
Utils::WizardProgress *progress = wizardProgress();
Utils::WizardProgressItem *kindItem = progress->addItem(tr("Kind"));
Utils::WizardProgressItem *detailsItem = progress->addItem(tr("Details"));
Utils::WizardProgressItem *summaryItem = progress->addItem(tr("Summary"));
kindItem->addPage(LibraryTypePageId);
detailsItem->addPage(DetailsPageId);
summaryItem->addPage(SummaryPageId);
kindItem->setNextItems(QList<Utils::WizardProgressItem *>() << detailsItem);
detailsItem->setNextItems(QList<Utils::WizardProgressItem *>() << summaryItem);
setStartId(LibraryTypePageId);
}
AddLibraryWizard::~AddLibraryWizard()
{
}
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)
{
setTitle(tr("Kind of Library"));
setSubTitle(tr("Choose the kind of library which you want to link against"));
QVBoxLayout *layout = new QVBoxLayout(this);
m_systemRadio = new QRadioButton(tr("System Library"), this);
m_systemRadio->setChecked(true);
layout->addWidget(m_systemRadio);
QLabel *systemLabel = new QLabel(tr("Adds linkage against system "
"library.\nNeither the path to the "
"selected library nor the path to its "
"includes is added to the pro file."));
systemLabel->setWordWrap(true);
systemLabel->setAttribute(Qt::WA_MacSmallSize, true);
layout->addWidget(systemLabel);
m_externalRadio = new QRadioButton(tr("External Library"), this);
layout->addWidget(m_externalRadio);
QLabel *externalLabel = new QLabel(tr("Adds linkage against external "
"library which is not a part of your "
"build tree.\nIt also adds the library "
"and include paths to the pro file."));
externalLabel->setWordWrap(true);
externalLabel->setAttribute(Qt::WA_MacSmallSize, true);
layout->addWidget(externalLabel);
m_internalRadio = new QRadioButton(tr("Internal Library"), this);
layout->addWidget(m_internalRadio);
QLabel *internalLabel = new QLabel(tr("Adds linkage against internal "
"library which is a part of your build "
"tree.\nIt also adds the library and "
"include paths to the pro file."));
internalLabel->setWordWrap(true);
internalLabel->setAttribute(Qt::WA_MacSmallSize, true);
layout->addWidget(internalLabel);
}
AddLibraryWizard::LibraryKind LibraryTypePage::libraryKind() const
{
if (m_internalRadio->isChecked())
return AddLibraryWizard::InternalLibrary;
if (m_systemRadio->isChecked())
return AddLibraryWizard::SystemLibrary;
return AddLibraryWizard::ExternalLibrary;
}
int LibraryTypePage::nextId() const
{
return AddLibraryWizard::DetailsPageId;
}
/////////////
DetailsPage::DetailsPage(AddLibraryWizard *parent)
: QWizardPage(parent), m_libraryWizard(parent), m_libraryDetailsController(0)
{
m_libraryDetailsWidget = new Ui::LibraryDetailsWidget();
m_libraryDetailsWidget->setupUi(this);
}
bool DetailsPage::isComplete() const
{
if (m_libraryDetailsController)
return m_libraryDetailsController->isComplete();
return false;
}
int DetailsPage::nextId() const
{
return AddLibraryWizard::SummaryPageId;
}
QString DetailsPage::snippet() const
{
if (m_libraryDetailsController)
return m_libraryDetailsController->snippet();
return QString();
}
void DetailsPage::initializePage()
{
if (m_libraryDetailsController) {
delete m_libraryDetailsController;
m_libraryDetailsController = 0;
}
QString title;
QString subTitle;
switch (m_libraryWizard->libraryKind()) {
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);
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);
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);
break;
default:
break;
}
setTitle(title);
setSubTitle(subTitle);
if (m_libraryDetailsController) {
m_libraryDetailsController->setProFile(m_libraryWizard->proFile());
connect(m_libraryDetailsController, SIGNAL(completeChanged()),
this, SIGNAL(completeChanged()));
}
}
/////////////
SummaryPage::SummaryPage(AddLibraryWizard *parent)
: QWizardPage(parent), m_libraryWizard(parent)
{
setTitle(tr("Summary"));
setFinalPage(true);
QVBoxLayout *layout = new QVBoxLayout(this);
m_summaryLabel = new QLabel(this);
m_snippetLabel = new QLabel(this);
layout->addWidget(m_summaryLabel);
layout->addWidget(m_snippetLabel);
m_summaryLabel->setTextFormat(Qt::RichText);
m_snippetLabel->setTextFormat(Qt::RichText);
m_snippetLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
}
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>"));
str << text;
str << "</code>";
}
m_snippetLabel->setText(richSnippet);
}
QString SummaryPage::snippet() const
{
return m_snippet;
}
#ifndef ADDLIBRARYWIZARD_H
#define ADDLIBRARYWIZARD_H
#include <utils/wizard.h>
#include <utils/pathchooser.h>
QT_BEGIN_NAMESPACE
class QRadioButton;
class QCheckBox;
class QLabel;
QT_END_NAMESPACE
namespace Qt4ProjectManager {
namespace Internal {
class LibraryDetailsWidget;
class LibraryDetailsController;
class LibraryTypePage;
class DetailsPage;
class SummaryPage;
namespace Ui {
class LibraryDetailsWidget;
}
class AddLibraryWizard : public Utils::Wizard
{
Q_OBJECT
public:
enum PageId {
LibraryTypePageId,
DetailsPageId,
SummaryPageId
};
enum LibraryKind {
SystemLibrary,
ExternalLibrary,
InternalLibrary
};
enum LinkageType {
DynamicLinkage,
StaticLinkage,
NoLinkage
};
enum MacLibraryType {
FrameworkType,
LibraryType,
NoLibraryType
};
enum Platform {
LinuxPlatform = 0x01,
MacPlatform = 0x02,
WindowsPlatform = 0x04,
SymbianPlatform = 0x08
};
Q_DECLARE_FLAGS(Platforms, Platform)
explicit AddLibraryWizard(const QString &fileName, QWidget *parent = 0);
~AddLibraryWizard();
LibraryKind libraryKind() const;
QString proFile() const;
QString snippet() const;
signals:
private:
LibraryTypePage *m_libraryTypePage;
DetailsPage *m_detailsPage;
SummaryPage *m_summaryPage;
QString m_proFile;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(AddLibraryWizard::Platforms)
class LibraryTypePage : public QWizardPage
{
Q_OBJECT
public:
LibraryTypePage(AddLibraryWizard *parent);
AddLibraryWizard::LibraryKind libraryKind() const;
virtual int nextId() const;
private:
QRadioButton *m_systemRadio;
QRadioButton *m_externalRadio;
QRadioButton *m_internalRadio;
};
class DetailsPage : public QWizardPage
{
Q_OBJECT
public:
DetailsPage(AddLibraryWizard *parent);
virtual void initializePage();
virtual int nextId() const;
virtual bool isComplete() const;
QString snippet() const;
private:
AddLibraryWizard *m_libraryWizard;
Ui::LibraryDetailsWidget *m_libraryDetailsWidget;
LibraryDetailsController *m_libraryDetailsController;
};
class SummaryPage : public QWizardPage
{
Q_OBJECT
public:
SummaryPage(AddLibraryWizard *parent);
virtual void initializePage();
QString snippet() const;
private:
AddLibraryWizard *m_libraryWizard;
QLabel *m_summaryLabel;
QLabel *m_snippetLabel;
QString m_snippet;
};
class LibraryPathChooser : public Utils::PathChooser
{
Q_OBJECT
public:
LibraryPathChooser(QWidget *parent);
virtual bool validatePath(const QString &path, QString *errorMessage);
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // ADDLIBRARYWIZARD_H
#include "findqt4profiles.h"
#include "qt4nodes.h"
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
QList<Qt4ProFileNode *> FindQt4ProFiles::operator()(ProjectExplorer::ProjectNode *root)
{
m_proFiles.clear();
root->accept(this);
return m_proFiles;
}
void FindQt4ProFiles::visitProjectNode(ProjectExplorer::ProjectNode *projectNode)
{
if (Qt4ProFileNode *pro = qobject_cast<Qt4ProFileNode *>(projectNode))
m_proFiles.append(pro);
}
#ifndef FINDQT4PROFILES_H
#define FINDQT4PROFILES_H
#include <projectexplorer/nodesvisitor.h>
namespace Qt4ProjectManager {
namespace Internal {
class Qt4ProFileNode;
class FindQt4ProFiles: protected ProjectExplorer::NodesVisitor {
public:
QList<Qt4ProFileNode *> operator()(ProjectExplorer::ProjectNode *root);
protected:
virtual void visitProjectNode(ProjectExplorer::ProjectNode *projectNode);
private:
QList<Qt4ProFileNode *> m_proFiles;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // FINDQT4PROFILES_H
This diff is collapsed.
#ifndef LIBRARYDETAILSCONTROLLER_H
#define LIBRARYDETAILSCONTROLLER_H
#include <QtGui/QWidget>
#include "addlibrarywizard.h"
namespace Qt4ProjectManager {
namespace Internal {
namespace Ui {
class LibraryDetailsWidget;
}
class Qt4ProFileNode;
class LibraryDetailsController : public QObject
{
Q_OBJECT
public:
explicit LibraryDetailsController(Ui::LibraryDetailsWidget *libraryDetails,
QObject *parent = 0);
virtual bool isComplete() const = 0;
void setProFile(const QString &proFile);
virtual QString snippet() const = 0;
signals:
void completeChanged();
protected:
Ui::LibraryDetailsWidget *libraryDetailsWidget() const;
AddLibraryWizard::Platforms platforms() const;
AddLibraryWizard::LinkageType linkageType() const;
AddLibraryWizard::MacLibraryType macLibraryType() const;
QString proFile() const;
bool isIncludePathChanged() const;
bool guiSignalsIgnored() const;
virtual void proFileChanged() {}
void updateGui();
virtual AddLibraryWizard::LinkageType suggestedLinkageType() const = 0;
virtual AddLibraryWizard::MacLibraryType suggestedMacLibraryType() const = 0;
virtual QString suggestedIncludePath() const = 0;
virtual void updateWindowsOptionsEnablement() = 0;
void setIgnoreGuiSignals(bool ignore);
void setLinkageRadiosVisible(bool ena);
void setMacLibraryRadiosVisible(bool ena);
void setLibraryPathChooserVisible(bool ena);
void setLibraryComboBoxVisible(bool ena);
void setIncludePathVisible(bool ena);
void setWindowsGroupVisible(bool ena);
void setRemoveSuffixVisible(bool ena);
bool isMacLibraryRadiosVisible() const;
bool isIncludePathVisible() const;
bool isWindowsGroupVisible() const;
private slots:
void slotIncludePathChanged();
void slotPlatformChanged();
void slotMacLibraryTypeChanged();
void slotUseSubfoldersChanged(bool ena);
void slotAddSuffixChanged(bool ena);
private:
void showLinkageType(AddLibraryWizard::LinkageType linkageType);
void showMacLibraryType(AddLibraryWizard::MacLibraryType libType);
AddLibraryWizard::Platforms m_platforms;
AddLibraryWizard::LinkageType m_linkageType;
AddLibraryWizard::MacLibraryType m_macLibraryType;
QString m_proFile;
bool m_ignoreGuiSignals;
bool m_includePathChanged;
bool m_linkageRadiosVisible;
bool m_macLibraryRadiosVisible;
bool m_includePathVisible;
bool m_windowsGroupVisible;
Ui::LibraryDetailsWidget *m_libraryDetailsWidget;
};
class NonInternalLibraryDetailsController : public LibraryDetailsController
{
Q_OBJECT
public:
explicit NonInternalLibraryDetailsController(Ui::LibraryDetailsWidget *libraryDetails,
QObject *parent = 0);
virtual bool isComplete() const;
virtual QString snippet() const;