Changeset View
Changeset View
Standalone View
Standalone View
cuttlefish/src/main.cpp
| Show All 18 Lines | |||||
| 19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
| 20 | 20 | | |||
| 21 | // Qt | 21 | // Qt | ||
| 22 | #include <QApplication> | 22 | #include <QApplication> | ||
| 23 | #include <QCommandLineParser> | 23 | #include <QCommandLineParser> | ||
| 24 | #include <QCommandLineOption> | 24 | #include <QCommandLineOption> | ||
| 25 | #include <QDebug> | 25 | #include <QDebug> | ||
| 26 | #include <QQmlEngine> | 26 | #include <QQmlEngine> | ||
| 27 | #include <QQmlApplicationEngine> | ||||
| 28 | #include <QQmlContext> | ||||
| 27 | 29 | | |||
| 28 | // Frameworks | 30 | // Frameworks | ||
| 29 | #include <KConfigGroup> | 31 | #include <KConfigGroup> | ||
| 32 | #include <KDeclarative/KDeclarative> | ||||
| 30 | #include <KLocalizedString> | 33 | #include <KLocalizedString> | ||
| 34 | #include <KPackage/PackageLoader> | ||||
| 31 | #include <Plasma/Theme> | 35 | #include <Plasma/Theme> | ||
| 32 | 36 | | |||
| 33 | // Own | 37 | // Own | ||
| 34 | #include "view.h" | 38 | #include "iconmodel.h" | ||
| 39 | | ||||
| 40 | void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) | ||||
| 41 | { | ||||
| 42 | if ((msg.contains("qt.svg") && msg.contains("Could not resolve property: #linearGradient")) || msg.contains("Could not resolve property: #pattern")) { | ||||
| 43 | return; | ||||
| 44 | } | ||||
| 45 | | ||||
| 46 | QByteArray localMsg = msg.toLocal8Bit(); | ||||
| 47 | const char *file = context.file ? context.file : ""; | ||||
| 48 | const char *function = context.function ? context.function : ""; | ||||
| 49 | switch (type) { | ||||
| 50 | case QtDebugMsg: | ||||
| 51 | fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function); | ||||
| 52 | break; | ||||
| 53 | case QtInfoMsg: | ||||
| 54 | fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function); | ||||
| 55 | break; | ||||
| 56 | case QtWarningMsg: | ||||
| 57 | fprintf(stderr, "\u001b[33mWarning\u001b[0m: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function); | ||||
| 58 | break; | ||||
| 59 | case QtCriticalMsg: | ||||
| 60 | fprintf(stderr, "\u001b[33;1mCritical\u001b[0m: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function); | ||||
| 61 | break; | ||||
| 62 | case QtFatalMsg: | ||||
| 63 | fprintf(stderr, "\u001b[31;1mFatal\u001b[0m: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function); | ||||
| 64 | break; | ||||
| 65 | } | ||||
| 66 | } | ||||
| 35 | 67 | | |||
| 36 | int main(int argc, char **argv) | 68 | int main(int argc, char **argv) | ||
| 37 | { | 69 | { | ||
| 70 | qInstallMessageHandler(messageOutput); | ||||
| 71 | | ||||
| 38 | QApplication app(argc, argv); | 72 | QApplication app(argc, argv); | ||
| 39 | KLocalizedString::setApplicationDomain("cuttlefish"); | 73 | KLocalizedString::setApplicationDomain("cuttlefish"); | ||
| 40 | 74 | | |||
| 41 | app.setApplicationVersion(PROJECT_VERSION); | 75 | app.setApplicationVersion(PROJECT_VERSION); | ||
| 42 | app.setDesktopFileName(QStringLiteral("org.kde.cuttlefish")); | 76 | app.setDesktopFileName(QStringLiteral("org.kde.cuttlefish")); | ||
| 43 | 77 | | |||
| 78 | app.setOrganizationName("KDE"); | ||||
| 79 | app.setOrganizationDomain("org.kde"); | ||||
| 80 | app.setApplicationName("Cuttlefish"); | ||||
| 81 | | ||||
| 44 | const static auto _category = QStringLiteral("category"); | 82 | const static auto _category = QStringLiteral("category"); | ||
| 45 | QCommandLineOption category = QCommandLineOption(QStringList() << QStringLiteral("c") << _category, | 83 | QCommandLineOption category = QCommandLineOption(QStringList() << QStringLiteral("c") << _category, | ||
| 46 | i18n("Start with category"), i18n("category")); | 84 | i18n("Start with category"), i18n("category")); | ||
| 47 | 85 | | |||
| 48 | const static auto _f = QStringLiteral("fullscreen"); | 86 | const static auto _f = QStringLiteral("fullscreen"); | ||
| 49 | QCommandLineOption fullscreen = QCommandLineOption(QStringList() << QStringLiteral("f") << _f, | 87 | QCommandLineOption fullscreen = QCommandLineOption(QStringList() << QStringLiteral("f") << _f, | ||
| 50 | i18n("Start full-screen")); | 88 | i18n("Start full-screen")); | ||
| 51 | 89 | | |||
| 52 | const static auto _p = QStringLiteral("picker"); | 90 | const static auto _p = QStringLiteral("picker"); | ||
| 53 | QCommandLineOption picker = QCommandLineOption(QStringList() << QStringLiteral("p") << _p, | 91 | QCommandLineOption picker = QCommandLineOption(QStringList() << QStringLiteral("p") << _p, | ||
| 54 | i18n("Run in icon-picker mode")); | 92 | i18n("Run in icon-picker mode")); | ||
| 55 | 93 | | |||
| 56 | QCommandLineParser parser; | 94 | QCommandLineParser parser; | ||
| 57 | parser.addVersionOption(); | 95 | parser.addVersionOption(); | ||
| 58 | parser.setApplicationDescription("Cuttlefish Icon Browser"); | 96 | parser.setApplicationDescription("Cuttlefish Icon Browser"); | ||
| 59 | parser.addHelpOption(); | 97 | parser.addHelpOption(); | ||
| 60 | parser.addOption(category); | 98 | parser.addOption(category); | ||
| 61 | parser.addOption(fullscreen); | 99 | parser.addOption(fullscreen); | ||
| 62 | parser.addOption(picker); | 100 | parser.addOption(picker); | ||
| 63 | 101 | | |||
| 64 | parser.process(app); | 102 | parser.process(app); | ||
| 65 | 103 | | |||
| 66 | QString _cc = parser.value(category); | 104 | QString _cc = parser.value(category); | ||
| 67 | 105 | | |||
| 68 | auto settingsapp = new CuttleFish::View(_cc, parser); | 106 | QQmlApplicationEngine engine; | ||
| 69 | QObject::connect(settingsapp->engine(), &QQmlEngine::quit, &app, &QApplication::quit); | | |||
| 70 | 107 | | |||
| 71 | if (parser.isSet(fullscreen)) { | 108 | KDeclarative::KDeclarative kdeclarative; | ||
| 72 | settingsapp->setVisibility(QWindow::FullScreen); | 109 | kdeclarative.setDeclarativeEngine(qobject_cast<QQmlEngine *>(&engine)); | ||
| 110 | kdeclarative.setTranslationDomain(QStringLiteral("cuttlefish")); | ||||
| 111 | kdeclarative.setupBindings(); | ||||
| 112 | | ||||
| 113 | auto package = KPackage::PackageLoader::self()->loadPackage("Plasma/Generic"); | ||||
| 114 | package.setPath("org.kde.plasma.cuttlefish"); | ||||
| 115 | | ||||
| 116 | if (!package.isValid() || !package.metadata().isValid()) { | ||||
| 117 | qWarning() << "Could not load package org.kde.plasma.cuttlefish:" << package.path(); | ||||
| 118 | return -1; | ||||
| 73 | } | 119 | } | ||
| 74 | 120 | | |||
| 121 | engine.load(QUrl::fromLocalFile(package.filePath("mainscript"))); | ||||
| 122 | if (engine.rootObjects().isEmpty()) | ||||
| 123 | return -1; | ||||
| 124 | | ||||
| 125 | auto iconModel = new CuttleFish::IconModel(engine.rootContext()); | ||||
| 126 | engine.rootContext()->setContextProperty("iconModel", iconModel); | ||||
| 127 | engine.rootContext()->setContextProperty("pickerMode", parser.isSet("picker")); | ||||
| 128 | qmlRegisterType<CuttleFish::IconModel>(); | ||||
| 129 | | ||||
| 75 | return app.exec(); | 130 | return app.exec(); | ||
| 76 | } | 131 | } | ||