File indexing completed on 2024-11-17 05:15:20
0001 /* 0002 * Copyright 2020 Han Young <hanyoung@protonmail.com> 0003 * Copyright 2020 Devin Lin <espidev@gmail.com> 0004 * Copyright 2019 Nick Reitemeyer <nick.reitemeyer@web.de> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "alarmmodel.h" 0010 #include "kclockdsettings.h" 0011 #include "kclocksettingsadaptor.h" 0012 #include "timermodel.h" 0013 #include "utilities.h" 0014 #include "version.h" 0015 #include "xdgportal.h" 0016 0017 #include <KAboutData> 0018 #include <KConfig> 0019 #include <KLocalizedContext> 0020 #include <KLocalizedString> 0021 0022 #include <QApplication> 0023 #include <QCommandLineParser> 0024 0025 #include <KDBusService> 0026 0027 QCommandLineParser *createParser() 0028 { 0029 QCommandLineParser *parser = new QCommandLineParser; 0030 parser->addOption(QCommandLineOption(QStringLiteral("no-powerdevil"), i18n("Don't use PowerDevil for alarms if it is available"))); 0031 parser->addHelpOption(); 0032 return parser; 0033 } 0034 0035 int main(int argc, char *argv[]) 0036 { 0037 QApplication app(argc, argv); 0038 0039 KLocalizedString::setApplicationDomain("kclockd"); 0040 KAboutData aboutData(QStringLiteral("kclockd"), 0041 QStringLiteral("KClock daemon"), 0042 QStringLiteral(KCLOCK_VERSION_STRING), 0043 QStringLiteral("KClock daemon"), 0044 KAboutLicense::GPL, 0045 i18n("© 2020-2022 KDE Community")); 0046 aboutData.addAuthor(i18n("Devin Lin"), QLatin1String(), QStringLiteral("devin@kde.org")); 0047 aboutData.addAuthor(i18n("Han Young"), QLatin1String(), QStringLiteral("hanyoung@protonmail.com")); 0048 KAboutData::setApplicationData(aboutData); 0049 0050 // ~~~~ Parse command line arguments ~~~~ 0051 { 0052 QScopedPointer<QCommandLineParser> parser(createParser()); 0053 parser->process(app); 0054 0055 if (parser->isSet(QStringLiteral("no-powerdevil"))) { 0056 Utilities::disablePowerDevil(true); 0057 } 0058 } 0059 0060 // only allow one instance 0061 KDBusService service(KDBusService::Unique); 0062 0063 qDebug() << "Starting kclockd" << KCLOCK_VERSION_STRING; 0064 0065 // call org.freedesktop.portal.Background for autostart in flatpak 0066 XDGPortal *portalInterface = new XDGPortal(); 0067 portalInterface->requestBackground(); 0068 0069 // initialize models 0070 new KClockSettingsAdaptor(KClockSettings::self()); 0071 QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"), KClockSettings::self()); 0072 0073 // save config 0074 QObject::connect(KClockSettings::self(), &KClockSettings::timeFormatChanged, KClockSettings::self(), &KClockSettings::save); 0075 0076 // start alarm polling 0077 AlarmModel::instance()->configureWakeups(); 0078 TimerModel::instance(); 0079 0080 return app.exec(); 0081 }