added a command line interface

This commit is contained in:
Patrick von Reth 2014-08-11 22:04:11 +02:00
parent 088a54c255
commit 34f9689720
4 changed files with 107 additions and 8 deletions

View File

@ -1,5 +1,6 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/core)
add_subdirectory(core)
add_subdirectory(snore-send)
if(WITH_SNORE_DEAMON)
@ -10,8 +11,6 @@ if(WITH_SNORE_DEAMON)
target_link_libraries( snorenotify KF5::CoreAddons KF5::I18n)
endif()
add_dependencies(snorenotify libsnore)
install(TARGETS snorenotify RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

View File

@ -1,21 +1,28 @@
#include "snorenotify.h"
#include "core/log.h"
#include "core/version.h"
#include <QApplication>
#ifdef HAVE_KDE5
#include "core/version.h"
#include <KAboutData>
#include <KI18n/KLocalizedString>
#endif
int main ( int argc, char *argv[] )
{
QApplication app ( argc, argv );
app.setApplicationName("SnoreNotify");
app.setOrganizationName("SnoreNotify");
app.setApplicationVersion(Snore::Version::version());
#ifdef HAVE_KDE5
KAboutData about("SnoreNotify",i18n("SnoreNotify"),Snore::Version::version(),
KAboutData about("SnoreNotify","SnoreNotify",Snore::Version::version(),
i18n("A notification deamon."),KAboutLicense::LGPL_V3, i18n("Copyright (c) 2010-2014 Patrick von Reth <vonreth@kde.org>"));
KAboutData::setApplicationData(about);

96
src/snore-send/main.cpp Normal file
View File

@ -0,0 +1,96 @@
#include "core/snore.h"
#include "core/notification/notification.h"
#include "core/log.h"
#include "core/version.h"
#include <QApplication>
#include <QCommandLineParser>
#ifdef HAVE_KDE5
#include <KAboutData>
#include <KI18n/KLocalizedString>
#endif
#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());
#ifdef HAVE_KDE5
KAboutData about("snore-send", "snore-send",Snore::Version::version(),
i18n("A command line interface for Snorenotify."),KAboutLicense::LGPL_V3, i18n("Copyright (c) 2014 Patrick von Reth <vonreth@kde.org>"));
KAboutData::setApplicationData(about);
#endif
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);
}

View File

@ -29,7 +29,6 @@
#include <QSystemTrayIcon>
#include <QSettings>
#include <iostream>
#include <stdlib.h>
@ -38,8 +37,6 @@ using namespace Snore;
SnoreNotify::SnoreNotify():
m_settings("SnoreNotify","SnoreNotify")
{
qApp->setApplicationName("SnoreNotify");
qApp->setOrganizationName("SnoreNotify");
m_trayIcon = new TrayIcon();
m_snore = new SnoreCore(m_trayIcon->trayIcon());
m_snore->loadPlugins(SnorePlugin::ALL);