Пример #1
0
int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(preload);
    QGuiApplication app (argc, argv);

    if (app.arguments().count() != 2) {
        return 10;
    }

    QmlModule::registerTypes();
    QString source = app.arguments().at(1);

    QmlRuntime::Ptr runtime (QmlRuntimeFactory::create());
    bool preloaded = runtime->preload(QUrl(QLatin1String("qrc:/preload.qml")));
    Q_ASSERT(preloaded);
    Q_UNUSED(preloaded);
    runtime->execute(QUrl(source));
    return app.exec();
}
Пример #2
0
int main(int argc, char *argv[])
{
    /* Workaround Qt platform integration plugin not advertising itself
       as having the following capabilities:
        - QPlatformIntegration::ThreadedOpenGL
        - QPlatformIntegration::BufferQueueingOpenGL
    */
    setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
    setenv("QML_FIXED_ANIMATION_STEP", "1", 1);

    // ignore favorites in unity-scopes-shell plugin
    setenv("UNITY_SCOPES_NO_FAVORITES", "1", 1);

    QGuiApplication::setApplicationName("Unity Scope Tool");
    QGuiApplication *application;
    application = new QGuiApplication(argc, argv);

    QCommandLineParser parser;
    parser.setApplicationDescription("Unity Scope Tool\n\n"
    "This tool allows development and testing of scopes. Running it without\n"
    "any arguments will open a session to all scopes available on the system.\n"
    "Otherwise passing a path to a scope config file will open a session with\n"
    "only that scope (assuming that the binary implementing the scope can be\n"
    "found in the same directory as the config file).");
    QCommandLineOption helpOption = parser.addHelpOption();
    parser.addPositionalArgument("scopes", "Paths to scope config files to spawn, optionally.", "[scopes...]");

    QCommandLineOption includeSystemScopes("include-system-scopes",
        "Initialize the registry with scopes installed on this system");
    QCommandLineOption includeServerScopes("include-server-scopes",
        "Initialize the registry with scopes on the default server");

    parser.addOption(includeServerScopes);
    parser.addOption(includeSystemScopes);

    parser.parse(application->arguments());

    if (parser.isSet(helpOption)) {
        parser.showHelp();
    }

    QStringList extraScopes = parser.positionalArguments();

    QScopedPointer<RegistryTracker> tracker;
    if (!extraScopes.isEmpty()) {
        bool systemScopes = parser.isSet(includeSystemScopes);
        bool serverScopes = parser.isSet(includeServerScopes);
        tracker.reset(new RegistryTracker(extraScopes, systemScopes, serverScopes));
    }

    bindtextdomain("unity8", translationDirectory().toUtf8().data());
    textdomain("unity8");

    QQuickView* view = new QQuickView();
    view->setResizeMode(QQuickView::SizeRootObjectToView);
    view->setTitle(QGuiApplication::applicationName());
    view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));

    QUrl source(::qmlDirectory() + "/ScopeTool.qml");
    prependImportPaths(view->engine(), ::overrideImportPaths());
    prependImportPaths(view->engine(), ::nonMirImportPaths());
    appendImportPaths(view->engine(), ::fallbackImportPaths());

    view->setSource(source);

    view->show();

    UnixSignalHandler signal_handler([]{
        QGuiApplication::exit(0);
    });
    signal_handler.setupUnixSignalHandlers();

    int result = application->exec();

    delete view;
    delete application;

    return result;
}