File indexing completed on 2022-09-27 16:31:47

0001 /*
0002     SPDX-FileCopyrightText: 2015-2022 Laurent Montel <montel@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 */
0007 
0008 #include <QApplication>
0009 
0010 #include "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 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0025     QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
0026     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
0027 #endif
0028 
0029     QApplication app(argc, argv);
0030 
0031     KAboutData aboutData(QStringLiteral("kdebugsettings"),
0032                          i18n("KDebugSettings"),
0033                          QStringLiteral(KDEBUGSETTINGS_VERSION),
0034                          i18n("Configure debug settings"),
0035                          KAboutLicense::GPL_V2,
0036                          i18n("(c) 2015-%1 kdebugsettings authors", QStringLiteral("2022")));
0037     aboutData.addAuthor(i18n("Laurent Montel"), i18n("Maintainer"), QStringLiteral("montel@kde.org"));
0038     KAboutData::setApplicationData(aboutData);
0039 
0040     QCommandLineParser parser;
0041     aboutData.setupCommandLine(&parser);
0042 
0043     const QCommandLineOption testModeOption(QStringLiteral("test-mode"), i18n("Enable QStandardPaths test mode, i.e. read/write settings used by unittests"));
0044     parser.addOption(testModeOption);
0045 
0046     const QCommandLineOption switchFullDebugOption(QStringLiteral("enable-full-debug"), i18n("Activate full debug for all modules."));
0047     parser.addOption(switchFullDebugOption);
0048     const QCommandLineOption switchOffDebugOption(QStringLiteral("disable-full-debug"), i18n("Disable full debug for all modules."));
0049     parser.addOption(switchOffDebugOption);
0050 
0051     const QCommandLineOption changeDebugSettingOption(QStringLiteral("debug-mode"),
0052                                                       i18n("Change debug mode as console (in console)"),
0053                                                       QStringLiteral("Full|Info|Warning|Critical|Off"));
0054     parser.addOption(changeDebugSettingOption);
0055     parser.addPositionalArgument(QStringLiteral("logging category name"),
0056                                  i18n("Specify logging category name that you want to change debug mode (in console)"));
0057 
0058     parser.process(app);
0059     aboutData.processCommandLine(&parser);
0060 
0061     if (parser.isSet(testModeOption)) {
0062         QStandardPaths::setTestModeEnabled(true);
0063     }
0064 
0065     if (parser.isSet(switchFullDebugOption)) {
0066         ChangeDebugModeJob job;
0067         job.setDebugMode(QStringLiteral("Full"));
0068         job.setWithoutArguments(true);
0069         if (!job.start()) {
0070             std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl;
0071         }
0072 
0073         return 1;
0074     }
0075     if (parser.isSet(switchOffDebugOption)) {
0076         ChangeDebugModeJob job;
0077         job.setDebugMode(QStringLiteral("Off"));
0078         job.setWithoutArguments(true);
0079         if (!job.start()) {
0080             std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl;
0081         }
0082         return 1;
0083     }
0084     const QString changeModeValue = parser.value(changeDebugSettingOption);
0085     if (!changeModeValue.isEmpty() && !parser.positionalArguments().isEmpty()) {
0086         ChangeDebugModeJob job;
0087         job.setDebugMode(changeModeValue);
0088         job.setLoggingCategoriesName(parser.positionalArguments());
0089         if (!job.start()) {
0090             std::cout << i18n("Impossible to change debug mode").toLocal8Bit().data() << std::endl;
0091         }
0092         return 1;
0093     } else {
0094         KDBusService service(KDBusService::Unique);
0095         auto dialog = new KDebugSettingsDialog;
0096         const int ret = dialog->exec();
0097         delete dialog;
0098         return ret;
0099     }
0100 }