/*
* Copyright (C) 2013-2014 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "plugin.h"
#include "ApplicationInfo.h"
#include "ApplicationManager.h"
#include "ApplicationScreenshotProvider.h"
#include "Session.h"
#include "MirSurfaceItem.h"
#include "MirSurfaceItemModel.h"
#include "SurfaceManager.h"
#include "SessionManager.h"
#include "ApplicationTestInterface.h"
#include "UbuntuKeyboardInfo.h"
#include
#include
static QObject* applicationManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return ApplicationManager::singleton();
}
static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return SurfaceManager::singleton();
}
static QObject* sessionManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return SessionManager::singleton();
}
static QObject* ubuntuKeyboardInfoSingleton(QQmlEngine*, QJSEngine*) {
return UbuntuKeyboardInfo::singleton();
}
ApplicationTestInterface* s_appTestInterface = nullptr;
static QObject* applicationTestInterface(QQmlEngine* engine, QJSEngine* scriptEngine) {
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
if (!s_appTestInterface) {
s_appTestInterface = new ApplicationTestInterface(engine);
}
return s_appTestInterface;
}
void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
{
qRegisterMetaType("Session*");
qRegisterMetaType("ApplicationInfo*");
qRegisterMetaType("SessionModel*");
qRegisterMetaType("MirSurfaceItem*");
qRegisterMetaType("MirSurfaceItemModel*");
qmlRegisterUncreatableType(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML");
qmlRegisterUncreatableType(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML");
qmlRegisterUncreatableType(uri, 0, 1, "Session", "Session can't be instantiated from QML");
qmlRegisterUncreatableType(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
qmlRegisterType(uri, 0, 1, "ApplicationInfo");
qmlRegisterSingletonType(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
qmlRegisterSingletonType(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
qmlRegisterSingletonType(uri, 0, 1, "SessionManager", sessionManagerSingleton);
qmlRegisterSingletonType(uri, 0, 1, "ApplicationTest", applicationTestInterface);
qmlRegisterSingletonType(uri, 0, 1, "UbuntuKeyboardInfo", ubuntuKeyboardInfoSingleton);
qRegisterMetaType("MirSurfaceItem::Type");
qRegisterMetaType("MirSurfaceItem::State");
}
void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
QQmlExtensionPlugin::initializeEngine(engine, uri);
engine->addImageProvider(QLatin1String("application"), new ApplicationScreenshotProvider(ApplicationManager::singleton()));
// make sure we initialise our test interface.
applicationTestInterface(engine, nullptr);
}