57
57
#include <unistd.h>
58
58
#include <stdexcept>
60
QUrl UbuntuComponentsPlugin::m_baseUrl = QUrl();
61
63
* Type registration functions.
64
static QObject *registerPickerPanel(QQmlEngine *engine, QJSEngine *scriptEngine)
66
Q_UNUSED(scriptEngine)
67
return UbuntuComponentsPlugin::registerQmlSingletonType(engine,
68
"Ubuntu.Components", "Pickers/PickerPanel.qml");
71
66
static QObject *registerClipboard(QQmlEngine *engine, QJSEngine *scriptEngine)
98
static QObject *registerUbuntuColors10(QQmlEngine *engine, QJSEngine *scriptEngine)
100
Q_UNUSED(scriptEngine)
101
return UbuntuComponentsPlugin::registerQmlSingletonType(engine,
102
"Ubuntu.Components", "Colors/UbuntuColors10.qml");
105
static QObject *registerUbuntuColors11(QQmlEngine *engine, QJSEngine *scriptEngine)
107
Q_UNUSED(scriptEngine)
108
return UbuntuComponentsPlugin::registerQmlSingletonType(engine,
109
"Ubuntu.Components", "Colors/UbuntuColors.qml");
112
QUrl UbuntuComponentsPlugin::baseUrl(const QStringList& importPathList, const char* uri)
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
117
QString pluginRelativePath = QString::fromUtf8(uri).replace(".", "/").prepend("/").append("/");
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.
124
Ref.: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1197293
126
if (QFile(pluginPath + "libUbuntuComponents.so").exists()) {
127
return QUrl::fromLocalFile(pluginPath);
134
QObject *UbuntuComponentsPlugin::registerQmlSingletonType(QQmlEngine *engine, const char* uri, const char* qmlFile)
136
QUrl url = baseUrl(engine->importPathList(), uri).resolved(QUrl::fromLocalFile(qmlFile));
93
QObject *UbuntuComponentsPlugin::registerQmlSingletonType(QQmlEngine *engine, const char* qmlFile)
95
QUrl url = m_baseUrl.resolved(QUrl::fromLocalFile(qmlFile));
137
96
return QuickUtils::instance().createQmlObject(url, engine);
165
124
void UbuntuComponentsPlugin::registerTypesToVersion(const char *uri, int major, int minor)
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);
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);
202
157
// register custom event
203
158
ForwardedEvent::registerForwardedEvent();
218
173
void UbuntuComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
175
// initialize baseURL
176
m_baseUrl = QUrl(baseUrl().toString() + '/');
220
178
QQmlExtensionPlugin::initializeEngine(engine, uri);
221
179
QQmlContext* context = engine->rootContext();