File indexing completed on 2024-05-12 05:52:35
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include <QApplication> 0009 0010 #include "jobs/changedebugmodejob.h" 0011 #include "loggingmanager.h" 0012 #include "model/categorytypeproxymodel.h" 0013 #include "model/customloggingcategorymodel.h" 0014 #include "model/customloggingcategoryproxymodel.h" 0015 #include "model/kdeapplicationloggingcategorymodel.h" 0016 #include "model/kdeapplicationloggingcategoryproxymodel.h" 0017 #include <config-kdebugsettings.h> 0018 0019 #include <KAboutData> 0020 #include <KDBusService> 0021 #include <KLocalizedString> 0022 #include <QCommandLineParser> 0023 #include <QStandardPaths> 0024 0025 #include <QQmlApplicationEngine> 0026 #include <QUrl> 0027 #include <QtQml> 0028 0029 #include <iostream> 0030 0031 int main(int argc, char **argv) 0032 { 0033 QApplication app(argc, argv); 0034 KLocalizedString::setApplicationDomain(QByteArrayLiteral("kdebugsettings")); 0035 KAboutData aboutData(QStringLiteral("kdebugsettingsquick"), 0036 i18n("KDebugSettings"), 0037 QStringLiteral(KDEBUGSETTINGS_VERSION), 0038 i18n("Configure debug settings"), 0039 KAboutLicense::GPL_V2, 0040 i18n("(c) %1 kdebugsettings authors", QStringLiteral("2023"))); 0041 aboutData.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org")); 0042 KAboutData::setApplicationData(aboutData); 0043 0044 QCommandLineParser parser; 0045 aboutData.setupCommandLine(&parser); 0046 0047 const QCommandLineOption testModeOption(QStringLiteral("test-mode"), i18n("Enable QStandardPaths test mode, i.e. read/write settings used by unittests")); 0048 parser.addOption(testModeOption); 0049 0050 const QCommandLineOption switchFullDebugOption(QStringLiteral("enable-full-debug"), i18n("Activate full debug for all modules.")); 0051 parser.addOption(switchFullDebugOption); 0052 const QCommandLineOption switchOffDebugOption(QStringLiteral("disable-full-debug"), i18n("Disable full debug for all modules.")); 0053 parser.addOption(switchOffDebugOption); 0054 0055 const QCommandLineOption changeDebugSettingOption(QStringLiteral("debug-mode"), 0056 i18n("Change debug mode as console (in console)"), 0057 QStringLiteral("Full|Info|Warning|Critical|Off")); 0058 parser.addOption(changeDebugSettingOption); 0059 parser.addPositionalArgument(QStringLiteral("logging category name"), 0060 i18n("Specify logging category name that you want to change debug mode (in console)")); 0061 0062 parser.process(app); 0063 aboutData.processCommandLine(&parser); 0064 0065 if (parser.isSet(testModeOption)) { 0066 QStandardPaths::setTestModeEnabled(true); 0067 } 0068 0069 if (parser.isSet(switchFullDebugOption)) { 0070 ChangeDebugModeJob job; 0071 job.setDebugMode(QStringLiteral("Full")); 0072 job.setWithoutArguments(true); 0073 if (!job.start()) { 0074 std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl; 0075 } 0076 0077 return 1; 0078 } 0079 if (parser.isSet(switchOffDebugOption)) { 0080 ChangeDebugModeJob job; 0081 job.setDebugMode(QStringLiteral("Off")); 0082 job.setWithoutArguments(true); 0083 if (!job.start()) { 0084 std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl; 0085 } 0086 return 1; 0087 } 0088 const QString changeModeValue = parser.value(changeDebugSettingOption); 0089 if (!changeModeValue.isEmpty() && !parser.positionalArguments().isEmpty()) { 0090 ChangeDebugModeJob job; 0091 job.setDebugMode(changeModeValue); 0092 job.setLoggingCategoriesName(parser.positionalArguments()); 0093 if (!job.start()) { 0094 std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl; 0095 } 0096 return 1; 0097 } else { 0098 KDBusService service(KDBusService::Unique); 0099 QQmlApplicationEngine engine; 0100 0101 qmlRegisterSingletonInstance("org.kde.kdebugsettings", 1, 0, "LoggingManager", &LoggingManager::self()); 0102 qRegisterMetaType<CustomLoggingCategoryModel *>("CustomLoggingCategoryModel *"); 0103 qRegisterMetaType<KDEApplicationLoggingCategoryModel *>("KDEApplicationLoggingCategoryModel *"); 0104 qmlRegisterType<CategoryTypeProxyModel>("org.kde.kdebugsettings", 1, 0, "CategoryTypeProxyModel"); 0105 qmlRegisterType<CustomLoggingCategoryProxyModel>("org.kde.kdebugsettings", 1, 0, "CustomLoggingCategoryProxyModel"); 0106 qmlRegisterType<KDEApplicationLoggingCategoryProxyModel>("org.kde.kdebugsettings", 1, 0, "KDEApplicationLoggingCategoryProxyModel"); 0107 0108 qmlRegisterSingletonType("org.kde.kdebugsettings", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue { 0109 return engine->toScriptValue(KAboutData::applicationData()); 0110 }); 0111 0112 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0113 engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); 0114 // Exit on QML load error. 0115 if (engine.rootObjects().isEmpty()) { 0116 qDebug() << " Error during loading main.qml"; 0117 return 1; 0118 } 0119 return app.exec(); 0120 } 0121 } 0122 #include "main.moc"