~bzoltan/kubuntu-packaging/decouple_cmake_plugin

« back to all changes in this revision

Viewing changes to src/plugins/qt4projectmanager/wizards/librarywizarddialog.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-12-02 09:16:15 UTC
  • mfrom: (1.1.29)
  • Revision ID: timo.jyrinki@canonical.com-20131202091615-xbj1os1f604ber1m
New upstream release candidate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
 
** Contact: http://www.qt-project.org/legal
5
 
**
6
 
** This file is part of Qt Creator.
7
 
**
8
 
** Commercial License Usage
9
 
** Licensees holding valid commercial Qt licenses may use this file in
10
 
** accordance with the commercial license agreement provided with the
11
 
** Software or, alternatively, in accordance with the terms contained in
12
 
** a written agreement between you and Digia.  For licensing terms and
13
 
** conditions see http://qt.digia.com/licensing.  For further information
14
 
** use the contact form at http://qt.digia.com/contact-us.
15
 
**
16
 
** GNU Lesser General Public License Usage
17
 
** Alternatively, this file may be used under the terms of the GNU Lesser
18
 
** General Public License version 2.1 as published by the Free Software
19
 
** Foundation and appearing in the file LICENSE.LGPL included in the
20
 
** packaging of this file.  Please review the following information to
21
 
** ensure the GNU Lesser General Public License version 2.1 requirements
22
 
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
 
**
24
 
** In addition, as a special exception, Digia gives you certain additional
25
 
** rights.  These rights are described in the Digia Qt LGPL Exception
26
 
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
 
**
28
 
****************************************************************************/
29
 
 
30
 
#include "librarywizarddialog.h"
31
 
#include "filespage.h"
32
 
#include "libraryparameters.h"
33
 
#include "modulespage.h"
34
 
#include "mobilelibrarywizardoptionpage.h"
35
 
#include "mobilelibraryparameters.h"
36
 
 
37
 
#include <utils/projectintropage.h>
38
 
#include <projectexplorer/projectexplorerconstants.h>
39
 
 
40
 
#include <QDebug>
41
 
 
42
 
#include <QComboBox>
43
 
#include <QLabel>
44
 
 
45
 
enum { debugLibWizard = 0 };
46
 
 
47
 
namespace QmakeProjectManager {
48
 
namespace Internal {
49
 
 
50
 
struct PluginBaseClasses {
51
 
    const char *name;
52
 
    const char *module;
53
 
    // blank separated list or 0
54
 
    const char *dependentModules;
55
 
    const char *targetDirectory;
56
 
    const char *pluginInterface;
57
 
};
58
 
 
59
 
static const PluginBaseClasses pluginBaseClasses[] =
60
 
{
61
 
    { "QAccessiblePlugin", "QtGui", "QtCore", "accessible", "QAccessibleFactoryInterface" },
62
 
    { "QDecorationPlugin", "QtGui", "QtCore", 0, 0 }, // Qt 4 only.
63
 
    { "QGenericPlugin", "QtGui", "QtCore", "generic", "QGenericPluginFactoryInterface" },
64
 
    { "QIconEnginePluginV2", "QtGui", "QtCore", "imageformats", 0 }, // Qt 4 only.
65
 
    { "QIconEnginePlugin", "QtGui", "QtCore", "imageformats", "QIconEngineFactoryInterface" },
66
 
    { "QImageIOPlugin", "QtGui", "QtCore", "imageformats",  "QImageIOHandlerFactoryInterface" },
67
 
    { "QScriptExtensionPlugin", "QtScript", "QtCore", 0, "QScriptExtensionInterface" },
68
 
    { "QSqlDriverPlugin", "QtSql", "QtCore", "sqldrivers", "QSqlDriverFactoryInterface" },
69
 
    { "QStylePlugin", "QtGui", "QtCore", "styles", "QStyleFactoryInterface" },
70
 
    { "QTextCodecPlugin", "QtCore", 0, "codecs", 0 } // Qt 4 only.
71
 
};
72
 
 
73
 
enum { defaultPluginBaseClass = 2 };
74
 
 
75
 
static const PluginBaseClasses *findPluginBaseClass(const QString &name)
76
 
{
77
 
    const int pluginBaseClassCount = sizeof(pluginBaseClasses)/sizeof(PluginBaseClasses);
78
 
    for (int i = 0; i < pluginBaseClassCount; i++)
79
 
        if (name == QLatin1String(pluginBaseClasses[i].name))
80
 
            return pluginBaseClasses + i;
81
 
    return 0;
82
 
}
83
 
 
84
 
// return dependencies of a plugin as a line ready for the 'QT=' line in a pro
85
 
// file
86
 
static QStringList pluginDependencies(const PluginBaseClasses *plb)
87
 
{
88
 
    QStringList dependencies;
89
 
    const QChar blank = QLatin1Char(' ');
90
 
    // Find the module names and convert to ids
91
 
    QStringList pluginModules= plb->dependentModules ?
92
 
                               QString(QLatin1String(plb->dependentModules)).split(blank) :
93
 
                               QStringList();
94
 
    pluginModules.push_back(QLatin1String(plb->module));
95
 
    foreach (const QString &module, pluginModules) {
96
 
        dependencies.append(ModulesPage::idOfModule(module));
97
 
    }
98
 
    return dependencies;
99
 
}
100
 
 
101
 
// A Project intro page with an additional type chooser.
102
 
class LibraryIntroPage : public Utils::ProjectIntroPage
103
 
{
104
 
public:
105
 
    explicit LibraryIntroPage(QWidget *parent = 0);
106
 
 
107
 
    QtProjectParameters::Type type() const;
108
 
 
109
 
private:
110
 
    QComboBox *m_typeCombo;
111
 
};
112
 
 
113
 
LibraryIntroPage::LibraryIntroPage(QWidget *parent) :
114
 
    Utils::ProjectIntroPage(parent),
115
 
    m_typeCombo(new QComboBox)
116
 
{
117
 
    m_typeCombo->setEditable(false);
118
 
    m_typeCombo->addItem(LibraryWizardDialog::tr("Shared Library"),
119
 
                         QVariant(QtProjectParameters::SharedLibrary));
120
 
    m_typeCombo->addItem(LibraryWizardDialog::tr("Statically Linked Library"),
121
 
                         QVariant(QtProjectParameters::StaticLibrary));
122
 
    m_typeCombo->addItem(LibraryWizardDialog::tr("Qt Plugin"),
123
 
                         QVariant(QtProjectParameters::Qt4Plugin));
124
 
    insertControl(0, new QLabel(LibraryWizardDialog::tr("Type")), m_typeCombo);
125
 
}
126
 
 
127
 
QtProjectParameters::Type LibraryIntroPage::type() const
128
 
{
129
 
    return static_cast<QtProjectParameters::Type>(m_typeCombo->itemData(m_typeCombo->currentIndex()).toInt());
130
 
}
131
 
 
132
 
// ------------------- LibraryWizardDialog
133
 
LibraryWizardDialog::LibraryWizardDialog(const QString &templateName,
134
 
                                         const QIcon &icon,
135
 
                                         bool showModulesPage,
136
 
                                         QWidget *parent,
137
 
                                         const Core::WizardDialogParameters &parameters) :
138
 
    BaseQt4ProjectWizardDialog(showModulesPage, new LibraryIntroPage, -1, parent, parameters),
139
 
    m_filesPage(new FilesPage),
140
 
    m_mobilePage(new MobileLibraryWizardOptionPage),
141
 
    m_pluginBaseClassesInitialized(false),
142
 
    m_filesPageId(-1), m_modulesPageId(-1), m_targetPageId(-1),
143
 
    m_mobilePageId(-1)
144
 
{
145
 
    setWindowIcon(icon);
146
 
    setWindowTitle(templateName);
147
 
    setSelectedModules(QLatin1String("core"));
148
 
 
149
 
    // Note that QWizard::currentIdChanged() is emitted at strange times.
150
 
    // Use the intro page instead, set up initially
151
 
    setIntroDescription(tr("This wizard generates a C++ library project."));
152
 
 
153
 
    if (!parameters.extraValues().contains(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS))) {
154
 
        m_targetPageId = addTargetSetupPage();
155
 
        m_mobilePageId = addPage(m_mobilePage);
156
 
    }
157
 
 
158
 
    m_modulesPageId = addModulesPage();
159
 
 
160
 
    m_filesPage->setNamespacesEnabled(true);
161
 
    m_filesPage->setFormFileInputVisible(false);
162
 
    m_filesPage->setClassTypeComboVisible(false);
163
 
 
164
 
    m_filesPageId = addPage(m_filesPage);
165
 
 
166
 
    Utils::WizardProgressItem *introItem = wizardProgress()->item(startId());
167
 
    Utils::WizardProgressItem *targetItem = 0;
168
 
    Utils::WizardProgressItem *mobileItem = 0;
169
 
    if (m_targetPageId != -1)
170
 
        targetItem = wizardProgress()->item(m_targetPageId);
171
 
    if (m_mobilePageId != -1)
172
 
        mobileItem = wizardProgress()->item(m_mobilePageId);
173
 
    Utils::WizardProgressItem *modulesItem = wizardProgress()->item(m_modulesPageId);
174
 
    Utils::WizardProgressItem *filesItem = wizardProgress()->item(m_filesPageId);
175
 
    filesItem->setTitle(tr("Details"));
176
 
 
177
 
    if (m_targetPageId != -1) {
178
 
        targetItem->setNextItems(QList<Utils::WizardProgressItem *>()
179
 
                                 << mobileItem << modulesItem << filesItem);
180
 
        targetItem->setNextShownItem(0);
181
 
        mobileItem->setNextItems(QList<Utils::WizardProgressItem *>()
182
 
                                 << modulesItem << filesItem);
183
 
        mobileItem->setNextShownItem(0);
184
 
    } else if (m_mobilePageId != -1) {
185
 
        introItem->setNextItems(QList<Utils::WizardProgressItem *>()
186
 
                                 << mobileItem);
187
 
        mobileItem->setNextItems(QList<Utils::WizardProgressItem *>()
188
 
                                 << modulesItem << filesItem);
189
 
        mobileItem->setNextShownItem(0);
190
 
    } else {
191
 
        introItem->setNextItems(QList<Utils::WizardProgressItem *>()
192
 
                                 << modulesItem << filesItem);
193
 
        introItem->setNextShownItem(0);
194
 
    }
195
 
 
196
 
    connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
197
 
 
198
 
    addExtensionPages(parameters.extensionPages());
199
 
}
200
 
 
201
 
void LibraryWizardDialog::setSuffixes(const QString &header, const QString &source,  const QString &form)
202
 
{
203
 
    m_filesPage->setSuffixes(header, source, form);
204
 
}
205
 
 
206
 
void LibraryWizardDialog::setLowerCaseFiles(bool l)
207
 
{
208
 
    m_filesPage->setLowerCaseFiles(l);
209
 
}
210
 
 
211
 
QtProjectParameters::Type  LibraryWizardDialog::type() const
212
 
{
213
 
    return static_cast<const LibraryIntroPage*>(introPage())->type();
214
 
}
215
 
 
216
 
bool LibraryWizardDialog::isModulesPageSkipped() const
217
 
{
218
 
    // When leaving the intro, target or mobile page, the modules page is skipped
219
 
    // in the case of a plugin since it knows its dependencies by itself.
220
 
    return type() == QtProjectParameters::Qt4Plugin;
221
 
}
222
 
 
223
 
int LibraryWizardDialog::skipModulesPageIfNeeded() const
224
 
{
225
 
    if (isModulesPageSkipped())
226
 
        return m_filesPageId;
227
 
    return m_modulesPageId;
228
 
}
229
 
 
230
 
int LibraryWizardDialog::nextId() const
231
 
{
232
 
    if (m_targetPageId != -1) {
233
 
        if (currentId() == m_targetPageId) {
234
 
 
235
 
            int next = m_modulesPageId;
236
 
 
237
 
            if (next == m_modulesPageId)
238
 
                return skipModulesPageIfNeeded();
239
 
 
240
 
            return next;
241
 
        } else if (currentId() == m_mobilePageId) {
242
 
            return skipModulesPageIfNeeded();
243
 
        }
244
 
    } else if (currentId() == startId()) {
245
 
        return skipModulesPageIfNeeded();
246
 
    } else if (currentId() == m_mobilePageId) {
247
 
        return skipModulesPageIfNeeded();
248
 
    }
249
 
 
250
 
    return BaseQt4ProjectWizardDialog::nextId();
251
 
}
252
 
 
253
 
void LibraryWizardDialog::initializePage(int id)
254
 
{
255
 
    if (m_targetPageId != -1 && (id == m_targetPageId || id == m_mobilePageId)) {
256
 
        Utils::WizardProgressItem *mobileItem = wizardProgress()->item(m_mobilePageId);
257
 
        Utils::WizardProgressItem *modulesItem = wizardProgress()->item(m_modulesPageId);
258
 
        Utils::WizardProgressItem *filesItem = wizardProgress()->item(m_filesPageId);
259
 
        if (isModulesPageSkipped())
260
 
            mobileItem->setNextShownItem(filesItem);
261
 
        else
262
 
            mobileItem->setNextShownItem(modulesItem);
263
 
 
264
 
    }
265
 
    BaseQt4ProjectWizardDialog::initializePage(id);
266
 
}
267
 
 
268
 
void LibraryWizardDialog::cleanupPage(int id)
269
 
{
270
 
    if (m_targetPageId != -1 && (id == m_targetPageId || id == m_mobilePageId)) {
271
 
        Utils::WizardProgressItem *mobileItem = wizardProgress()->item(m_mobilePageId);
272
 
        mobileItem->setNextShownItem(0);
273
 
    }
274
 
    BaseQt4ProjectWizardDialog::cleanupPage(id);
275
 
}
276
 
 
277
 
QtProjectParameters LibraryWizardDialog::parameters() const
278
 
{
279
 
    QtProjectParameters rc;
280
 
    rc.type = type();
281
 
    rc.fileName = projectName();
282
 
    rc.path = path();
283
 
    if (rc.type == QtProjectParameters::Qt4Plugin) {
284
 
        // Plugin: Dependencies & Target directory
285
 
        if (const PluginBaseClasses *plb = findPluginBaseClass(m_filesPage->baseClassName())) {
286
 
            rc.selectedModules = pluginDependencies(plb);
287
 
            if (plb->targetDirectory) {
288
 
                rc.targetDirectory = QLatin1String("$$[QT_INSTALL_PLUGINS]/");
289
 
                rc.targetDirectory += QLatin1String(plb->targetDirectory);
290
 
            }
291
 
        }
292
 
    } else {
293
 
        // Modules from modules page
294
 
        rc.selectedModules = selectedModulesList();
295
 
        rc.deselectedModules = deselectedModulesList();
296
 
    }
297
 
    return rc;
298
 
}
299
 
 
300
 
void LibraryWizardDialog::slotCurrentIdChanged(int id)
301
 
{
302
 
    if (debugLibWizard)
303
 
        qDebug() << Q_FUNC_INFO << id;
304
 
    if (id == m_filesPageId)
305
 
        setupFilesPage();// Switching to files page: Set up base class accordingly (plugin)
306
 
    else if (id == m_mobilePageId
307
 
             || (currentPage() && currentPage()->isFinalPage()))
308
 
        setupMobilePage();
309
 
}
310
 
 
311
 
void LibraryWizardDialog::setupFilesPage()
312
 
{
313
 
    switch (type()) {
314
 
    case QtProjectParameters::Qt4Plugin:
315
 
        if (!m_pluginBaseClassesInitialized) {
316
 
            if (debugLibWizard)
317
 
                qDebug("initializing for plugins");
318
 
            QStringList baseClasses;
319
 
            const int pluginBaseClassCount = sizeof(pluginBaseClasses)/sizeof(PluginBaseClasses);
320
 
            Q_ASSERT(defaultPluginBaseClass < pluginBaseClassCount);
321
 
            for (int i = 0; i < pluginBaseClassCount; i++)
322
 
                baseClasses.push_back(QLatin1String(pluginBaseClasses[i].name));
323
 
            m_filesPage->setBaseClassChoices(baseClasses);
324
 
            m_filesPage->setBaseClassName(baseClasses.at(defaultPluginBaseClass));
325
 
            m_pluginBaseClassesInitialized = true;
326
 
        }
327
 
        m_filesPage->setBaseClassInputVisible(true);
328
 
        break;
329
 
    default: {
330
 
        // Urrm, figure out a good class name. Use project name this time
331
 
        QString className = projectName();
332
 
        if (!className.isEmpty())
333
 
            className[0] = className.at(0).toUpper();
334
 
        m_filesPage->setClassName(className);
335
 
        m_filesPage->setBaseClassInputVisible(false);
336
 
    }
337
 
        break;
338
 
    }
339
 
}
340
 
 
341
 
void LibraryWizardDialog::setupMobilePage()
342
 
{
343
 
    if (type() == QtProjectParameters::Qt4Plugin)
344
 
        m_mobilePage->setQtPluginDirectory(projectName());
345
 
    m_mobilePage->setLibraryType(type());
346
 
}
347
 
 
348
 
LibraryParameters LibraryWizardDialog::libraryParameters() const
349
 
{
350
 
    LibraryParameters rc;
351
 
    rc.className = m_filesPage->className();
352
 
    rc.baseClassName = m_filesPage->baseClassName();
353
 
    rc.sourceFileName = m_filesPage->sourceFileName();
354
 
    rc.headerFileName = m_filesPage->headerFileName();
355
 
    return rc;
356
 
}
357
 
 
358
 
QString LibraryWizardDialog::pluginInterface(const QString &baseClass)
359
 
{
360
 
    if (const PluginBaseClasses *plb = findPluginBaseClass(baseClass))
361
 
        if (plb->pluginInterface)
362
 
            return QLatin1String("org.qt-project.Qt.") + QLatin1String(plb->pluginInterface);
363
 
    return QString();
364
 
}
365
 
 
366
 
MobileLibraryParameters LibraryWizardDialog::mobileLibraryParameters() const
367
 
{
368
 
    MobileLibraryParameters mlp;
369
 
    mlp.libraryType = type();
370
 
    mlp.fileName = projectName();
371
 
 
372
 
    // Maemo stuff should always be added to pro file. Even if no mobile target is specified
373
 
    mlp.type |= MobileLibraryParameters::Linux;
374
 
 
375
 
    return mlp;
376
 
}
377
 
 
378
 
} // namespace Internal
379
 
} // namespace QmakeProjectManager