File indexing completed on 2024-04-21 16:11:00

0001 /*
0002  *   SPDX-FileCopyrightText: 2022 Bart Ribbers <bribbers@disroot.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "controllermanager.h"
0008 #include "evdev/evdevcontroller.h"
0009 
0010 #ifdef HAS_LIBCEC
0011 #include "libcec/ceccontroller.h"
0012 #endif
0013 #ifdef HAS_XWIIMOTE
0014 # include "wiimote/wiimotecontroller.h"
0015 #endif // HAS_XWIIMOTE
0016 
0017 #include <QApplication>
0018 #include <QCommandLineParser>
0019 #include <QDebug>
0020 #include <QDBusConnection>
0021 #include <KLocalizedString>
0022 
0023 #include <KAboutData>
0024 #include <KDBusService>
0025 #include <fcntl.h>
0026 #include <unistd.h>
0027 
0028 int main(int argc, char *argv[])
0029 {
0030     // KStatusNotifierItem needs a QApplication
0031     QApplication app(argc, argv);
0032     KLocalizedString::setApplicationDomain("plasma-remotecontrollers");
0033 
0034     KAboutData about(QStringLiteral("plasma-remotecontrollers"),
0035                      i18n("Plasma Remote Controllers"), PROJECT_VERSION,
0036                      i18n("System update status notifier"), KAboutLicense::GPL,
0037                      i18n("© 2022 Plasma Development Team"));
0038     about.setProductName("Plasma Bigscreen/Remote Controllers");
0039     about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"),
0040                         i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0041 
0042     KAboutData::setApplicationData(about);
0043 
0044     KDBusService::StartupOptions startup = {};
0045     {
0046         QCommandLineParser parser;
0047         QCommandLineOption replaceOption({QStringLiteral("replace")},
0048                                         i18n("Replace an existing instance"));
0049         parser.addOption(replaceOption);
0050         about.setupCommandLine(&parser);
0051         parser.process(app);
0052         about.processCommandLine(&parser);
0053 
0054         if (parser.isSet(replaceOption)) {
0055             startup |= KDBusService::Replace;
0056         }
0057     }
0058 
0059     KDBusService service(KDBusService::Unique | startup);
0060 
0061     new EvdevController();
0062 
0063 #ifdef HAS_LIBCEC
0064     new CECController();
0065 #endif
0066     
0067 #ifdef HAS_XWIIMOTE
0068     new WiimoteController();
0069 #endif // HAS_XWIIMOTE
0070 
0071     if (!QDBusConnection::sessionBus().isConnected()) {
0072         qWarning() << "Cannot connect to the D-Bus session bus.\nPlease check your system settings and try again.";
0073         return 1;
0074     }
0075 
0076     return app.exec();
0077 }