moved from snorenotify

This commit is contained in:
Patrick von Reth 2014-08-12 14:14:56 +02:00
parent a75abb16a2
commit fb1c93e4b2
3 changed files with 115 additions and 0 deletions

26
CMakeLists.txt Normal file
View File

@ -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)

6
src/CMakeLists.txt Normal file
View File

@ -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)

83
src/main.cpp Normal file
View File

@ -0,0 +1,83 @@
#include <snore.h>
#include <notification/notification.h>
#include <log.h>
#include <version.h>
#include <QApplication>
#include <QCommandLineParser>
#include <iostream>
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);
}