File indexing completed on 2024-04-28 05:26:47
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "../DiscoverVersion.h" 0008 #include <KAboutData> 0009 #include <KConfig> 0010 #include <KConfigGroup> 0011 #include <KCrash> 0012 #include <KDBusService> 0013 #include <KLocalizedString> 0014 #include <KSharedConfig> 0015 #include <QApplication> 0016 #include <QCommandLineParser> 0017 #include <QDBusConnection> 0018 #include <QDBusConnectionInterface> 0019 #include <QDBusMessage> 0020 #include <QDebug> 0021 #include <QMenu> 0022 0023 #include "NotifierItem.h" 0024 0025 using namespace Qt::StringLiterals; 0026 0027 int main(int argc, char **argv) 0028 { 0029 QApplication app(argc, argv); 0030 app.setOrganizationDomain(QStringLiteral("kde.org")); 0031 KCrash::setFlags(KCrash::AutoRestart); 0032 0033 NotifierItem notifier; 0034 bool hide = false; 0035 KDBusService::StartupOptions startup = {}; 0036 { 0037 KAboutData about(QStringLiteral("discover.notifier"), 0038 i18n("Discover Notifier"), 0039 version, 0040 i18n("System update status notifier"), 0041 KAboutLicense::GPL, 0042 i18n("© 2010-2024 Plasma Development Team")); 0043 about.addAuthor(QStringLiteral("Aleix Pol Gonzalez"), {}, QStringLiteral("aleixpol@kde.org")); 0044 about.setProductName("discover/discover"); 0045 about.setProgramLogo(app.windowIcon()); 0046 about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails")); 0047 0048 KAboutData::setApplicationData(about); 0049 0050 QCommandLineParser parser; 0051 QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance")); 0052 parser.addOption(replaceOption); 0053 QCommandLineOption hideOption({QStringLiteral("hide")}, i18n("Do not show the notifier"), i18n("hidden"), QStringLiteral("false")); 0054 parser.addOption(hideOption); 0055 about.setupCommandLine(&parser); 0056 parser.process(app); 0057 about.processCommandLine(&parser); 0058 0059 if (parser.isSet(replaceOption)) { 0060 startup |= KDBusService::Replace; 0061 } 0062 0063 const auto config = KSharedConfig::openConfig(); 0064 KConfigGroup group(config, u"Behavior"_s); 0065 0066 if (parser.isSet(hideOption)) { 0067 hide = parser.value(hideOption) == QLatin1String("true"); 0068 group.writeEntry<bool>("Hide", hide); 0069 config->sync(); 0070 } else { 0071 hide = group.readEntry<bool>("Hide", false); 0072 } 0073 } 0074 0075 KDBusService service(KDBusService::Unique | startup); 0076 0077 // Otherwise the QEventLoopLocker in KStatusNotifierItem quits the 0078 // application when the status notifier is destroyed 0079 app.setQuitLockEnabled(false); 0080 0081 notifier.setStatusNotifierEnabled(!hide); 0082 0083 return app.exec(); 0084 }