~zsombi/ubuntu-ui-toolkit/10-viewitem

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/plugin/plugin.cpp

prereq merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
#include <unistd.h>
58
58
#include <stdexcept>
59
59
 
 
60
QUrl UbuntuComponentsPlugin::m_baseUrl = QUrl();
 
61
 
60
62
/*
61
63
 * Type registration functions.
62
64
 */
63
65
 
64
 
static QObject *registerPickerPanel(QQmlEngine *engine, QJSEngine *scriptEngine)
65
 
{
66
 
    Q_UNUSED(scriptEngine)
67
 
    return UbuntuComponentsPlugin::registerQmlSingletonType(engine,
68
 
           "Ubuntu.Components", "Pickers/PickerPanel.qml");
69
 
}
70
 
 
71
66
static QObject *registerClipboard(QQmlEngine *engine, QJSEngine *scriptEngine)
72
67
{
73
68
    Q_UNUSED(engine)
95
90
    return uriHandler;
96
91
}
97
92
 
98
 
static QObject *registerUbuntuColors10(QQmlEngine *engine, QJSEngine *scriptEngine)
99
 
{
100
 
    Q_UNUSED(scriptEngine)
101
 
    return UbuntuComponentsPlugin::registerQmlSingletonType(engine,
102
 
           "Ubuntu.Components", "Colors/UbuntuColors10.qml");
103
 
}
104
 
 
105
 
static QObject *registerUbuntuColors11(QQmlEngine *engine, QJSEngine *scriptEngine)
106
 
{
107
 
    Q_UNUSED(scriptEngine)
108
 
    return UbuntuComponentsPlugin::registerQmlSingletonType(engine,
109
 
           "Ubuntu.Components", "Colors/UbuntuColors.qml");
110
 
}
111
 
 
112
 
QUrl UbuntuComponentsPlugin::baseUrl(const QStringList& importPathList, const char* uri)
113
 
{
114
 
    /* FIXME: remove when migrating to Qt 5.1 and use QQmlExtensionPlugin::baseUrl()
115
 
       http://doc-snapshot.qt-project.org/qt5-stable/qtqml/qqmlextensionplugin.html#baseUrl
116
 
    */
117
 
    QString pluginRelativePath = QString::fromUtf8(uri).replace(".", "/").prepend("/").append("/");
118
 
    QString pluginPath;
119
 
    Q_FOREACH (QString importPath, importPathList) {
120
 
        pluginPath = importPath.append(pluginRelativePath);
121
 
        /* We verify that the directory ending in Ubuntu/Components contains the
122
 
           file libUbuntuComponents.so therefore proving it's the right directory.
123
 
 
124
 
           Ref.: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1197293
125
 
        */
126
 
        if (QFile(pluginPath + "libUbuntuComponents.so").exists()) {
127
 
            return QUrl::fromLocalFile(pluginPath);
128
 
        }
129
 
    }
130
 
 
131
 
    return QUrl();
132
 
}
133
 
 
134
 
QObject *UbuntuComponentsPlugin::registerQmlSingletonType(QQmlEngine *engine, const char* uri, const char* qmlFile)
135
 
{
136
 
    QUrl url = baseUrl(engine->importPathList(), uri).resolved(QUrl::fromLocalFile(qmlFile));
 
93
QObject *UbuntuComponentsPlugin::registerQmlSingletonType(QQmlEngine *engine, const char* qmlFile)
 
94
{
 
95
    QUrl url = m_baseUrl.resolved(QUrl::fromLocalFile(qmlFile));
137
96
    return QuickUtils::instance().createQmlObject(url, engine);
138
97
}
139
98
 
165
124
void UbuntuComponentsPlugin::registerTypesToVersion(const char *uri, int major, int minor)
166
125
{
167
126
    qmlRegisterType<UCStyledItemBase>(uri, major, minor, "StyledItemBase");
168
 
    qmlRegisterSingletonType<QObject>(uri, major, minor, "UbuntuColors", registerUbuntuColors10);
169
127
    qmlRegisterUncreatableType<UbuntuI18n>(uri, major, minor, "i18n", "Singleton object");
170
128
    qmlRegisterExtendedType<QQuickImageBase, UCQQuickImageExtension>(uri, major, minor, "QQuickImageBase");
171
129
    qmlRegisterUncreatableType<UCUnits>(uri, major, minor, "UCUnits", "Not instantiable");
186
144
    qmlRegisterSingletonType<UCUriHandler>(uri, major, minor, "UriHandler", registerUriHandler);
187
145
    qmlRegisterType<UCMouse>(uri, major, minor, "Mouse");
188
146
    qmlRegisterType<UCInverseMouse>(uri, major, minor, "InverseMouse");
189
 
    // register QML singletons
190
 
    qmlRegisterSingletonType<QObject>(uri, major, minor, "PickerPanel", registerPickerPanel);
191
147
}
192
148
 
193
149
void UbuntuComponentsPlugin::registerTypes(const char *uri)
197
153
    // register 0.1 for backward compatibility
198
154
    registerTypesToVersion(uri, 0, 1);
199
155
    registerTypesToVersion(uri, 1, 0);
200
 
    qmlRegisterSingletonType<QObject>(uri, 1, 1, "UbuntuColors", registerUbuntuColors11);
201
156
 
202
157
    // register custom event
203
158
    ForwardedEvent::registerForwardedEvent();
217
172
 
218
173
void UbuntuComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
219
174
{
 
175
    // initialize baseURL
 
176
    m_baseUrl = QUrl(baseUrl().toString() + '/');
 
177
 
220
178
    QQmlExtensionPlugin::initializeEngine(engine, uri);
221
179
    QQmlContext* context = engine->rootContext();
222
180