From fb1c93e4b2cfdc5b61c974d007e25681bf41f8d5 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 12 Aug 2014 14:14:56 +0200 Subject: [PATCH] moved from snorenotify --- CMakeLists.txt | 26 +++++++++++++++ src/CMakeLists.txt | 6 ++++ src/main.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..399fc93 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +project( snore-send ) +cmake_minimum_required( VERSION 2.8.12 ) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +include(GenerateExportHeader) + + +set(SNORE_VERSION_MAJOR 0) +set(SNORE_VERSION_MINOR 1) +set(SNORE_VERSION_PATCH 0) +set(SNORE_VERSION_SUFFIX "alpha") + + +find_package(ECM 0.0.9 NO_MODULE) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) +include(KDECompilerSettings) + +find_package(LibsnoreQt5 REQUIRED) + + + +add_subdirectory(src) + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..19420a8 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable( snore-send main.cpp) +target_link_libraries( snore-send Snore::Libsnore) + +install(TARGETS snore-send RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..cf5d65c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,83 @@ + +#include +#include +#include +#include + +#include +#include + +#include + +using namespace Snore; + + +int main ( int argc, char *argv[] ) +{ + QApplication app ( argc, argv ); + app.setApplicationName("snore-send"); + app.setOrganizationName("snore-send"); + app.setApplicationVersion(Snore::Version::version()); + + QCommandLineParser parser; + parser.setApplicationDescription("A command line interface for Snorenotify."); + parser.addHelpOption(); + parser.addVersionOption(); + + QCommandLineOption title(QStringList() << "t" << "title", "Set the notification title.", "title"); + parser.addOption(title); + + QCommandLineOption message(QStringList() << "m" << "message", "Set the notification body.", "message"); + parser.addOption(message); + + QCommandLineOption applicationName(QStringList() << "a" << "application", "Set the notification applicattion.", "application", app.applicationName()); + parser.addOption(applicationName); + + + QCommandLineOption alertName(QStringList() << "c" << "alert", "Set the notification alert class.","alert", "Default"); + parser.addOption(alertName); + + QCommandLineOption iconPath(QStringList() << "i" << "icon", "Set the notification icon.","icon", ":/root/snore.png"); + parser.addOption(iconPath); + + QCommandLineOption backend(QStringList() << "b" << "backend", "Set the notification backend.","backend"); + parser.addOption(backend); + + + parser.process(app); + snoreDebug( SNORE_DEBUG ) << parser.positionalArguments(); + if(parser.isSet(title) && parser.isSet(message)) + { + SnoreCore core; + + core.loadPlugins(SnorePlugin::BACKEND); + if(parser.isSet(backend)?!core.setPrimaryNotificationBackend(parser.value(backend)):!core.setPrimaryNotificationBackend()) + { + std::cout << "Failed to set backend: " << qPrintable(parser.value(backend)) << " avalible backends: " << qPrintable(core.notificationBackends().join(", ")) << std::endl; + return 1; + } + Icon icon(parser.value(iconPath)); + Application application(parser.value(applicationName),icon); + Alert alert(parser.value(alertName),icon); + application.addAlert(alert); + + core.registerApplication(application); + + Notification n(application, alert, parser.value(title), parser.value(message),icon); + + core.broadcastNotification(n); + int returnCode = -1; + app.connect(&core, &SnoreCore::notificationClosed, [&returnCode](Notification noti){ + QString reason; + QDebug(&reason) << noti.closeReason(); + std::cout << qPrintable(reason) << std::endl; + returnCode = noti.closeReason(); + }); + app.connect(&core, &SnoreCore::notificationClosed, &app, &QApplication::quit); + app.exec(); + return returnCode; + } + parser.showHelp(1); +} + +