~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/designer/src/lib/shared/pluginmanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the Qt Designer of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22
23
**
23
 
** In addition, as a special exception, Nokia gives you certain
24
 
** additional rights. These rights are described in the Nokia Qt LGPL
25
 
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26
 
** package.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
24
** In addition, as a special exception, Nokia gives you certain additional
 
25
** rights.  These rights are described in the Nokia Qt LGPL Exception
 
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
27
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
72
72
static const char *customwidgetElementC = "customwidget";
73
73
static const char *extendsElementC = "extends";
74
74
static const char *addPageMethodC = "addpagemethod";
 
75
static const char *propertySpecsC = "propertyspecifications";
 
76
static const char *stringPropertySpecC = "stringpropertyspecification";
 
77
static const char *stringPropertyNameAttrC = "name";
 
78
static const char *stringPropertyTypeAttrC = "type";
 
79
static const char *stringPropertyNoTrAttrC = "notr";
75
80
static const char *jambiLanguageC = "jambi";
76
81
 
77
82
enum { debugPluginManager = 0 };
141
146
 
142
147
class QDesignerCustomWidgetSharedData : public QSharedData {
143
148
public:
 
149
    // Type of a string property
 
150
    typedef QPair<qdesigner_internal::TextPropertyValidationMode, bool> StringPropertyType;
 
151
    typedef QHash<QString, StringPropertyType> StringPropertyTypeMap;
 
152
 
144
153
    explicit QDesignerCustomWidgetSharedData(const QString &thePluginPath) : pluginPath(thePluginPath) {}
145
154
    void clearXML();
146
155
 
152
161
    QString xmlAddPageMethod;
153
162
    QString xmlExtends;
154
163
 
 
164
    StringPropertyTypeMap xmlStringPropertyTypeMap;
155
165
};
156
166
 
157
167
void QDesignerCustomWidgetSharedData::clearXML()
161
171
    xmlLanguage.clear();
162
172
    xmlAddPageMethod.clear();
163
173
    xmlExtends.clear();
 
174
    xmlStringPropertyTypeMap.clear();
164
175
}
165
176
 
166
177
// ----------------  QDesignerCustomWidgetData
220
231
    return m_d->pluginPath;
221
232
}
222
233
 
 
234
bool QDesignerCustomWidgetData::xmlStringPropertyType(const QString &name, StringPropertyType *type) const
 
235
{
 
236
    QDesignerCustomWidgetSharedData::StringPropertyTypeMap::const_iterator it = m_d->xmlStringPropertyTypeMap.constFind(name);
 
237
    if (it == m_d->xmlStringPropertyTypeMap.constEnd()) {
 
238
        *type = StringPropertyType(qdesigner_internal::ValidationRichText, true);
 
239
        return false;
 
240
    }
 
241
    *type = it.value();
 
242
    return true;
 
243
}
 
244
 
223
245
// Wind a QXmlStreamReader  until it finds an element. Returns index or one of FindResult
224
246
enum FindResult { FindError = -2, ElementNotFound = -1 };
225
247
 
249
271
    return QDesignerPluginManager::tr("An XML error was encountered when parsing the XML of the custom widget %1: %2").arg(name, errorMessage);
250
272
}
251
273
 
 
274
static inline QString msgAttributeMissing(const QString &name)
 
275
{
 
276
    return QDesignerPluginManager::tr("A required attribute ('%1') is missing.").arg(name);
 
277
}
 
278
 
 
279
static qdesigner_internal::TextPropertyValidationMode typeStringToType(const QString &v, bool *ok)
 
280
{
 
281
    *ok = true;
 
282
    if (v  == QLatin1String("multiline"))
 
283
        return qdesigner_internal::ValidationMultiLine;
 
284
    if (v  == QLatin1String("richtext"))
 
285
        return qdesigner_internal::ValidationRichText;
 
286
    if (v  == QLatin1String("stylesheet"))
 
287
        return qdesigner_internal::ValidationStyleSheet;
 
288
    if (v  == QLatin1String("singleline"))
 
289
        return qdesigner_internal::ValidationSingleLine;
 
290
    if (v  == QLatin1String("objectname"))
 
291
        return qdesigner_internal::ValidationObjectName;
 
292
    if (v  == QLatin1String("objectnamescope"))
 
293
        return qdesigner_internal::ValidationObjectNameScope;
 
294
    if (v  == QLatin1String("url"))
 
295
        return qdesigner_internal::ValidationURL;
 
296
    *ok = false;
 
297
    return qdesigner_internal::ValidationRichText;
 
298
}
 
299
 
 
300
static  bool parsePropertySpecs(QXmlStreamReader &sr,
 
301
                                   QDesignerCustomWidgetSharedData::StringPropertyTypeMap *rc,
 
302
                                   QString *errorMessage)
 
303
{
 
304
    const QString propertySpecs = QLatin1String(propertySpecsC);
 
305
    const QString stringPropertySpec = QLatin1String(stringPropertySpecC);
 
306
    const QString stringPropertyTypeAttr = QLatin1String(stringPropertyTypeAttrC);
 
307
    const QString stringPropertyNoTrAttr = QLatin1String(stringPropertyNoTrAttrC);
 
308
    const QString stringPropertyNameAttr = QLatin1String(stringPropertyNameAttrC);
 
309
 
 
310
    while (!sr.atEnd()) {
 
311
        switch(sr.readNext()) {
 
312
        case QXmlStreamReader::StartElement: {
 
313
            if (sr.name() != stringPropertySpec) {
 
314
                *errorMessage = QDesignerPluginManager::tr("An invalid property specification ('%1') was encountered. Supported types: %2").arg(sr.name().toString(), stringPropertySpec);
 
315
                return false;
 
316
            }
 
317
            const QXmlStreamAttributes atts = sr.attributes();
 
318
            const QString name = atts.value(stringPropertyNameAttr).toString();
 
319
            const QString type = atts.value(stringPropertyTypeAttr).toString();
 
320
            const QString notrS = atts.value(stringPropertyNoTrAttr).toString(); //Optional
 
321
 
 
322
            if (type.isEmpty()) {
 
323
                *errorMessage = msgAttributeMissing(stringPropertyTypeAttr);
 
324
                return false;
 
325
            }
 
326
            if (name.isEmpty()) {
 
327
                *errorMessage = msgAttributeMissing(stringPropertyNameAttr);
 
328
                return false;
 
329
            }
 
330
            bool typeOk;
 
331
            const bool noTr = notrS == QLatin1String("true") || notrS == QLatin1String("1");
 
332
            QDesignerCustomWidgetSharedData::StringPropertyType v(typeStringToType(type, &typeOk), !noTr);
 
333
            if (!typeOk) {
 
334
                *errorMessage = QDesignerPluginManager::tr("'%1' is not a valid string property specification.").arg(type);
 
335
                return false;
 
336
            }
 
337
            rc->insert(name, v);
 
338
        }
 
339
            break;
 
340
        case QXmlStreamReader::EndElement: // Outer </stringproperties>
 
341
            if (sr.name() == propertySpecs)
 
342
                return true;
 
343
        default:
 
344
            break;
 
345
        }
 
346
    }
 
347
    return true;
 
348
}
 
349
 
252
350
QDesignerCustomWidgetData::ParseResult
253
351
                       QDesignerCustomWidgetData::parseXml(const QString &xml, const QString &name, QString *errorMessage)
254
352
{
311
409
    default:
312
410
        break;
313
411
    }
314
 
    // Find <extends>, <addPageMethod>
 
412
    // Find <extends>, <addPageMethod>, <stringproperties>
315
413
    elements.clear();
316
414
    elements.push_back(QLatin1String(extendsElementC));
317
415
    elements.push_back(QLatin1String(addPageMethodC));
 
416
    elements.push_back(QLatin1String(propertySpecsC));
318
417
    while (true) {
319
418
        switch (findElement(elements, sr)) {
320
419
        case FindError:
336
435
                return ParseError;
337
436
            }
338
437
            break;
 
438
        case 2: // <stringproperties>
 
439
            if (!parsePropertySpecs(sr, &m_d->xmlStringPropertyTypeMap, errorMessage)) {
 
440
                *errorMessage = msgXmlError(name, *errorMessage);
 
441
                return ParseError;
 
442
            }
 
443
            break;
339
444
        }
340
445
    }
341
446
    return rc;
345
450
 
346
451
class QDesignerPluginManagerPrivate {
347
452
    public:
 
453
    typedef QPair<QString, QString> ClassNamePropertyNameKey;
 
454
 
348
455
    QDesignerPluginManagerPrivate(QDesignerFormEditorInterface *core);
349
456
 
350
457
    void clearCustomWidgets();
562
669
 
563
670
    const int before = m_d->m_registeredPlugins.size();
564
671
    foreach (const QString &path, m_d->m_pluginPaths)
565
 
        registerPath(path);        
 
672
        registerPath(path);
566
673
    const bool newPluginsFound = m_d->m_registeredPlugins.size() > before;
567
674
    // We force a re-initialize as Jambi collection might return
568
675
    // different widget lists when switching projects.
654
761
    return m_d->m_customWidgetData.at(index);
655
762
}
656
763
 
 
764
QDesignerCustomWidgetData QDesignerPluginManager::customWidgetData(const QString &name) const
 
765
{
 
766
    const int count = m_d->m_customWidgets.size();
 
767
    for (int i = 0; i < count; i++)
 
768
        if (m_d->m_customWidgets.at(i)->name() == name)
 
769
            return m_d->m_customWidgetData.at(i);
 
770
    return QDesignerCustomWidgetData();
 
771
}
 
772
 
657
773
QObjectList QDesignerPluginManager::instances() const
658
774
{
659
775
    QStringList plugins = registeredPlugins();