File indexing completed on 2024-04-21 03:56:29
0001 /* 0002 SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QCommandLineParser> 0008 #include <QCoreApplication> 0009 #include <QDBusConnection> 0010 #include <QDBusMessage> 0011 #include <QTimer> 0012 0013 int main(int argc, char *argv[]) 0014 { 0015 QCoreApplication app(argc, argv); 0016 0017 QCommandLineParser parser; 0018 parser.addHelpOption(); 0019 parser.addVersionOption(); 0020 0021 // for simplicity we'll just send along progress-visible true whenever progress is set and otherwise false 0022 QCommandLineOption progressOption(QStringLiteral("progress"), QStringLiteral("Show progress, 0-100"), QStringLiteral("progress")); 0023 parser.addOption(progressOption); 0024 // same for count 0025 QCommandLineOption countOption(QStringLiteral("count"), QStringLiteral("Show count badge, number"), QStringLiteral("count")); 0026 parser.addOption(countOption); 0027 0028 QCommandLineOption urgentOption(QStringLiteral("urgent"), QStringLiteral("Set urgent hint, flash task bar entry")); 0029 parser.addOption(urgentOption); 0030 0031 parser.addPositionalArgument(QStringLiteral("desktop-filename"), QStringLiteral("Desktop file name for the application")); 0032 0033 parser.process(app); 0034 0035 if (parser.positionalArguments().count() != 1) { 0036 parser.showHelp(1); // never returns 0037 } 0038 0039 QString launcherId = parser.positionalArguments().constFirst(); 0040 if (!launcherId.startsWith(QLatin1String("application://"))) { 0041 launcherId.prepend(QLatin1String("application://")); 0042 } 0043 if (!launcherId.endsWith(QLatin1String(".desktop"))) { 0044 launcherId.append(QLatin1String(".desktop")); 0045 } 0046 0047 QVariantMap properties; 0048 0049 if (parser.isSet(progressOption)) { 0050 properties.insert(QStringLiteral("progress"), parser.value(progressOption).toInt() / 100.0); 0051 properties.insert(QStringLiteral("progress-visible"), true); 0052 } else { 0053 properties.insert(QStringLiteral("progress-visible"), false); 0054 } 0055 0056 if (parser.isSet(countOption)) { 0057 properties.insert(QStringLiteral("count"), parser.value(countOption).toInt()); 0058 properties.insert(QStringLiteral("count-visible"), true); 0059 } else { 0060 properties.insert(QStringLiteral("count-visible"), false); 0061 } 0062 0063 properties.insert(QStringLiteral("urgent"), parser.isSet(urgentOption)); 0064 0065 QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/org/knotifications/UnityLauncherTest"), 0066 QStringLiteral("com.canonical.Unity.LauncherEntry"), 0067 QStringLiteral("Update")); 0068 message.setArguments({launcherId, properties}); 0069 QDBusConnection::sessionBus().send(message); 0070 0071 // FIXME can we detect that the message was sent to the bus? 0072 QTimer::singleShot(500, &app, QCoreApplication::quit); 0073 0074 return app.exec(); 0075 }