File indexing completed on 2024-05-12 05:52:32

0001 /*
0002     SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.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 "kdebugsettingsdialog.h"
0012 #include <config-kdebugsettings.h>
0013 
0014 #include <KAboutData>
0015 #include <KDBusService>
0016 #include <KLocalizedString>
0017 #include <QCommandLineParser>
0018 #include <QStandardPaths>
0019 
0020 #include <iostream>
0021 
0022 int main(int argc, char **argv)
0023 {
0024     QApplication app(argc, argv);
0025 
0026     KAboutData aboutData(QStringLiteral("kdebugsettings"),
0027                          i18n("KDebugSettings"),
0028                          QStringLiteral(KDEBUGSETTINGS_VERSION),
0029                          i18n("Configure debug settings"),
0030                          KAboutLicense::GPL_V2,
0031                          i18n("(c) 2015-%1 kdebugsettings authors", QStringLiteral("2024")));
0032     aboutData.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org"));
0033     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("debug-run")));
0034     KAboutData::setApplicationData(aboutData);
0035 
0036     QCommandLineParser parser;
0037     aboutData.setupCommandLine(&parser);
0038 
0039     const QCommandLineOption testModeOption(QStringLiteral("test-mode"), i18n("Enable QStandardPaths test mode, i.e. read/write settings used by unittests"));
0040     parser.addOption(testModeOption);
0041 
0042     const QCommandLineOption switchFullDebugOption(QStringLiteral("enable-full-debug"), i18n("Activate full debug for all modules."));
0043     parser.addOption(switchFullDebugOption);
0044     const QCommandLineOption switchOffDebugOption(QStringLiteral("disable-full-debug"), i18n("Disable full debug for all modules."));
0045     parser.addOption(switchOffDebugOption);
0046 
0047     const QCommandLineOption changeDebugSettingOption(QStringLiteral("debug-mode"),
0048                                                       i18n("Change debug mode as console (in console)"),
0049                                                       QStringLiteral("Full|Info|Warning|Critical|Off"));
0050     parser.addOption(changeDebugSettingOption);
0051     parser.addPositionalArgument(QStringLiteral("logging category name"),
0052                                  i18n("Specify logging category name that you want to change debug mode (in console)"));
0053 
0054     parser.process(app);
0055     aboutData.processCommandLine(&parser);
0056 
0057     if (parser.isSet(testModeOption)) {
0058         QStandardPaths::setTestModeEnabled(true);
0059     }
0060 
0061     if (parser.isSet(switchFullDebugOption)) {
0062         ChangeDebugModeJob job;
0063         job.setDebugMode(QStringLiteral("Full"));
0064         job.setWithoutArguments(true);
0065         if (!job.start()) {
0066             std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl;
0067         }
0068 
0069         return 1;
0070     }
0071     if (parser.isSet(switchOffDebugOption)) {
0072         ChangeDebugModeJob job;
0073         job.setDebugMode(QStringLiteral("Off"));
0074         job.setWithoutArguments(true);
0075         if (!job.start()) {
0076             std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl;
0077         }
0078         return 1;
0079     }
0080     const QString changeModeValue = parser.value(changeDebugSettingOption);
0081     if (!changeModeValue.isEmpty() && !parser.positionalArguments().isEmpty()) {
0082         ChangeDebugModeJob job;
0083         job.setDebugMode(changeModeValue);
0084         job.setLoggingCategoriesName(parser.positionalArguments());
0085         if (!job.start()) {
0086             std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl;
0087         }
0088         return 1;
0089     } else {
0090         KDBusService service(KDBusService::Unique);
0091         auto dialog = new KDebugSettingsDialog;
0092         const int ret = dialog->exec();
0093         delete dialog;
0094         return ret;
0095     }
0096 }