summaryrefslogtreecommitdiff
path: root/src/plugins/qt4projectmanager/addlibrarywizard.cpp
blob: 8cc4e178e1181277ee4b4ac9da08c843be0ed30f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#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, 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, 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, m_libraryWizard->proFile(), this);
        break;
    default:
        break;
    }
    setTitle(title);
    setSubTitle(subTitle);
    if (m_libraryDetailsController) {
        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;
}