Beispiel #1
0
int main(int argc, char *argv[])
{
	QCoreApplication app(argc, argv);

	initLogger(QsLogging::InfoLevel);

	bool expectVerbosity = false;
	bool expectDBusAddress = false;
	QString portName;
	QString dbusAddress = "system";
	QStringList args = app.arguments();
	args.pop_front();
	foreach (QString arg, args) {
		if (expectVerbosity) {
			QsLogging::Logger &logger = QsLogging::Logger::instance();
			QsLogging::Level logLevel = static_cast<QsLogging::Level>(qBound(
				static_cast<int>(QsLogging::TraceLevel),
				arg.toInt(),
				static_cast<int>(QsLogging::OffLevel)));
			logger.setLoggingLevel(logLevel);
			expectVerbosity = false;
		} else if (expectDBusAddress) {
			dbusAddress = arg;
			expectDBusAddress = false;
		} else if (arg == "-h" || arg == "--help") {
			QLOG_INFO() << app.arguments().first();
			QLOG_INFO() << "\t-h, --help";
			QLOG_INFO() << "\t Show this message.";
			QLOG_INFO() << "\t-V, --version";
			QLOG_INFO() << "\t Show the application version.";
			QLOG_INFO() << "\t-d level, --debug level";
			QLOG_INFO() << "\t Set log level";
			QLOG_INFO() << "\t-b, --dbus";
			QLOG_INFO() << "\t dbus address or 'session' or 'system'";
			QLOG_INFO() << "\t <Port Name>";
			QLOG_INFO() << "\t Name of communication port (eg. /dev/ttyUSB0)";
			exit(1);
		} else if (arg == "-V" || arg == "--version") {
			QLOG_INFO() << VERSION;
			exit(0);
		} else if (arg == "-d" || arg == "--debug") {
			expectVerbosity = true;
		} else if (arg == "-t" || arg == "--timestamp") {
			QsLogging::Logger &logger = QsLogging::Logger::instance();
			logger.setIncludeTimestamp(true);
		} else if (arg == "-b" || arg == "--dbus") {
			expectDBusAddress = true;
		} else if (!arg.startsWith('-')) {
			portName = arg;
		}
	}

	if (portName.isEmpty()) {
		QLOG_ERROR() << "No communication port specified on command line";
		exit(2);
	} else {
		QLOG_INFO() << "Connecting to" << portName;
	}

	initDBus(dbusAddress);

	DBusRedflow a(portName);

	app.connect(&a, SIGNAL(connectionLost()), &app, SLOT(quit()));

	return app.exec();
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    Utils::printTimeInfo(QStringLiteral("main"));

    // qputenv("QML_DISABLE_DISTANCEFIELD", "1");
#ifdef Q_OS_WIN
    // qputenv("QT_QPA_PLATFORM","windows:fontengine=freetype");
#endif
#ifndef Q_OS_ANDROID
    qInstallMessageHandler(flowMessageHandler);
#endif
#ifdef FLOW_STATIC_BUILD
    Q_INIT_RESOURCE(shellscriptplugin);
    Q_INIT_RESOURCE(hostsplugin);
#endif

    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    Application app(argc, argv);
    Utils::printTimeInfo(QStringLiteral("main: created QApplication"));
    app.setOrganizationName(QStringLiteral("KDAB"));
    app.setApplicationName(QStringLiteral("flow"));

    QTranslator translator;
    translator.load(QStringLiteral(":/translations/flow_%1").arg(QLocale::system().name())); // export LANG="pt_PT" to change
    app.installTranslator(&translator);
    Utils::printTimeInfo(QStringLiteral("main: installed QTranslator"));

    RuntimeConfiguration runtimeConfig;
    runtimeConfig.setDataFileName(defaultDataFileName());
    runtimeConfig.setMobileUI(Utils::platformRequiresMobileUI() || qApp->arguments().contains("--mobile"));
    runtimeConfig.setSaveEnabled(!qApp->arguments().contains("--read-only"));

    Kernel kernel(runtimeConfig);
    kernel.storage()->load();

    // app.connect(&app, &Application::focusObjectChanged, &onFocusObjectChanged);

    Utils::printTimeInfo(QStringLiteral("main: created Kernel::instance()"));
    QuickView window(&kernel);
    Utils::printTimeInfo(QStringLiteral("main: created QuickView"));
    initDBus(&kernel);
    Utils::printTimeInfo(QStringLiteral("main: initialized dbus"));

    if (runtimeConfig.isMobileUI()) {
        window.showMaximized(); // Don't use fullscreen on android
    } else {
        window.show();
    }

    if (logsDebugToFile()) { // Logging to file, so lets be a bit more verbose
        for (auto screen : QGuiApplication::screens()) {
            if (screen) {
                qDebug() << "Logical DPI=" << screen->logicalDotsPerInch()
                         << "; Physical DPI=" << screen->physicalDotsPerInch()
                         << "; Physical DPI X=" << screen->physicalDotsPerInchX()
                         << "; Resolution=" << screen->size()
                         << "; Name=" << screen->name();
            } else {
                qWarning() << "Null screen";
            }
        }
    }

    Utils::printTimeInfo(QStringLiteral("main: starting app.exec()"));
    return app.exec();
}