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" | ||
35 | 39 | | |||
36 | int main(int argc, char **argv) | 40 | int main(int argc, char **argv) | ||
37 | { | 41 | { | ||
38 | QApplication app(argc, argv); | 42 | QApplication app(argc, argv); | ||
39 | KLocalizedString::setApplicationDomain("cuttlefish"); | 43 | KLocalizedString::setApplicationDomain("cuttlefish"); | ||
40 | 44 | | |||
41 | app.setApplicationVersion(PROJECT_VERSION); | 45 | app.setApplicationVersion(PROJECT_VERSION); | ||
42 | app.setDesktopFileName(QStringLiteral("org.kde.cuttlefish")); | 46 | app.setDesktopFileName(QStringLiteral("org.kde.cuttlefish")); | ||
43 | 47 | | |||
48 | app.setOrganizationName("KDE"); | ||||
49 | app.setOrganizationDomain("org.kde"); | ||||
50 | app.setApplicationName("Cuttlefish"); | ||||
51 | | ||||
44 | const static auto _category = QStringLiteral("category"); | 52 | const static auto _category = QStringLiteral("category"); | ||
45 | QCommandLineOption category = QCommandLineOption(QStringList() << QStringLiteral("c") << _category, | 53 | QCommandLineOption category = QCommandLineOption(QStringList() << QStringLiteral("c") << _category, | ||
46 | i18n("Start with category"), i18n("category")); | 54 | i18n("Start with category"), i18n("category")); | ||
47 | 55 | | |||
48 | const static auto _f = QStringLiteral("fullscreen"); | 56 | const static auto _f = QStringLiteral("fullscreen"); | ||
49 | QCommandLineOption fullscreen = QCommandLineOption(QStringList() << QStringLiteral("f") << _f, | 57 | QCommandLineOption fullscreen = QCommandLineOption(QStringList() << QStringLiteral("f") << _f, | ||
50 | i18n("Start full-screen")); | 58 | i18n("Start full-screen")); | ||
51 | 59 | | |||
52 | const static auto _p = QStringLiteral("picker"); | 60 | const static auto _p = QStringLiteral("picker"); | ||
53 | QCommandLineOption picker = QCommandLineOption(QStringList() << QStringLiteral("p") << _p, | 61 | QCommandLineOption picker = QCommandLineOption(QStringList() << QStringLiteral("p") << _p, | ||
54 | i18n("Run in icon-picker mode")); | 62 | i18n("Run in icon-picker mode")); | ||
55 | 63 | | |||
56 | QCommandLineParser parser; | 64 | QCommandLineParser parser; | ||
57 | parser.addVersionOption(); | 65 | parser.addVersionOption(); | ||
58 | parser.setApplicationDescription("Cuttlefish Icon Browser"); | 66 | parser.setApplicationDescription("Cuttlefish Icon Browser"); | ||
59 | parser.addHelpOption(); | 67 | parser.addHelpOption(); | ||
60 | parser.addOption(category); | 68 | parser.addOption(category); | ||
61 | parser.addOption(fullscreen); | 69 | parser.addOption(fullscreen); | ||
62 | parser.addOption(picker); | 70 | parser.addOption(picker); | ||
63 | 71 | | |||
64 | parser.process(app); | 72 | parser.process(app); | ||
65 | 73 | | |||
66 | QString _cc = parser.value(category); | 74 | QString _cc = parser.value(category); | ||
67 | 75 | | |||
68 | auto settingsapp = new CuttleFish::View(_cc, parser); | 76 | QQmlApplicationEngine engine; | ||
69 | QObject::connect(settingsapp->engine(), &QQmlEngine::quit, &app, &QApplication::quit); | | |||
70 | 77 | | |||
71 | if (parser.isSet(fullscreen)) { | 78 | KDeclarative::KDeclarative kdeclarative; | ||
72 | settingsapp->setVisibility(QWindow::FullScreen); | 79 | kdeclarative.setDeclarativeEngine(qobject_cast<QQmlEngine *>(&engine)); | ||
80 | kdeclarative.setTranslationDomain(QStringLiteral("cuttlefish")); | ||||
81 | kdeclarative.setupBindings(); | ||||
82 | | ||||
83 | auto package = KPackage::PackageLoader::self()->loadPackage("Plasma/Generic"); | ||||
84 | package.setPath("org.kde.plasma.cuttlefish"); | ||||
85 | | ||||
86 | if (!package.isValid() || !package.metadata().isValid()) { | ||||
87 | qWarning() << "Could not load package org.kde.plasma.cuttlefish:" << package.path(); | ||||
88 | return -1; | ||||
73 | } | 89 | } | ||
74 | 90 | | |||
91 | engine.load(QUrl::fromLocalFile(package.filePath("mainscript"))); | ||||
92 | if (engine.rootObjects().isEmpty()) | ||||
93 | return -1; | ||||
94 | | ||||
95 | auto iconModel = new CuttleFish::IconModel(engine.rootContext()); | ||||
96 | engine.rootContext()->setContextProperty("iconModel", iconModel); | ||||
97 | engine.rootContext()->setContextProperty("pickerMode", parser.isSet("picker")); | ||||
98 | qmlRegisterType<CuttleFish::IconModel>(); | ||||
99 | | ||||
75 | return app.exec(); | 100 | return app.exec(); | ||
76 | } | 101 | } |