File indexing completed on 2024-05-12 17:08:27
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "coloreditor.h" 0008 #include "themelistmodel.h" 0009 #include "thememodel.h" 0010 #include <QApplication> 0011 0012 #include <QQuickItem> 0013 #include <klocalizedstring.h> 0014 #include <qcommandlineoption.h> 0015 #include <qcommandlineparser.h> 0016 0017 #include <KAboutData> 0018 #include <QQmlContext> 0019 #include <QQmlEngine> 0020 #include <QQmlExpression> 0021 #include <QQmlProperty> 0022 #include <QQuickWindow> 0023 #include <kdeclarative/qmlobject.h> 0024 #include <kpackage/package.h> 0025 #include <kpackage/packageloader.h> 0026 0027 int main(int argc, char **argv) 0028 { 0029 QApplication app(argc, argv); 0030 0031 app.setApplicationVersion(PROJECT_VERSION); 0032 app.setDesktopFileName(QStringLiteral("org.kde.plasma.themeexplorer")); 0033 0034 QCommandLineParser parser; 0035 parser.addVersionOption(); 0036 parser.addHelpOption(); 0037 parser.setApplicationDescription(i18n("Plasma Theme Explorer")); 0038 0039 QCommandLineOption themeOption(QCommandLineOption(QStringList() << "t" 0040 << "theme", 0041 i18n("The theme to open"), 0042 "theme")); 0043 0044 parser.addOption(themeOption); 0045 0046 parser.process(app); 0047 0048 const QString packagePath("org.kde.plasma.themeexplorer"); 0049 0050 // usually we have an ApplicationWindow here, so we do not need to create a window by ourselves 0051 KDeclarative::QmlObject *obj = new KDeclarative::QmlObject(); 0052 obj->setTranslationDomain(packagePath); 0053 obj->setInitializationDelayed(true); 0054 obj->engine()->rootContext()->setContextProperty("commandlineArguments", parser.positionalArguments()); 0055 0056 QObject::connect(obj->engine(), &QQmlEngine::quit, &app, &QApplication::quit); 0057 0058 qmlRegisterAnonymousType<ThemeListModel>("org.kde.plasma.sdk", 1); 0059 qmlRegisterAnonymousType<ColorEditor>("org.kde.plasma.sdk", 1); 0060 0061 KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML")); 0062 package.setPath(packagePath); 0063 obj->setSource(QUrl::fromLocalFile(package.filePath("mainscript"))); 0064 const KPluginMetaData data = package.metadata(); 0065 ThemeModel *themeModel = new ThemeModel(package); 0066 if (parser.isSet(themeOption)) { 0067 themeModel->setTheme(parser.value(themeOption)); 0068 obj->engine()->rootContext()->setContextProperty("commandlineTheme", parser.value(themeOption)); 0069 } else { 0070 themeModel->setTheme(parser.value("default")); 0071 obj->engine()->rootContext()->setContextProperty("commandlineTheme", "default"); 0072 } 0073 obj->engine()->rootContext()->setContextProperty("themeModel", QVariant::fromValue(themeModel)); 0074 0075 obj->completeInitialization(); 0076 0077 if (!data.isValid()) { 0078 return -1; 0079 } 0080 0081 // About data 0082 KAboutData aboutData(data.pluginId(), data.name(), data.version(), data.description(), KAboutLicense::byKeyword(data.license()).key()); 0083 0084 for (auto author : data.authors()) { 0085 aboutData.addAuthor(author.name(), author.task(), author.emailAddress(), author.webAddress(), author.ocsUsername()); 0086 } 0087 0088 // The root is not a window? 0089 // have to use a normal QQuickWindow since the root item is already created 0090 QWindow *window = qobject_cast<QWindow *>(obj->rootObject()); 0091 if (window) { 0092 window->setTitle(data.name()); 0093 window->setIcon(QIcon::fromTheme(data.iconName())); 0094 } else { 0095 qWarning() << "Error loading the ApplicationWindow"; 0096 } 0097 0098 return app.exec(); 0099 }