added silent option to not print to stdout

This commit is contained in:
Patrick von Reth 2014-08-12 17:13:11 +02:00
parent fb1c93e4b2
commit 7e36686d1a
1 changed files with 14 additions and 8 deletions

View File

@ -43,9 +43,12 @@ int main ( int argc, char *argv[] )
QCommandLineOption backend(QStringList() << "b" << "backend", "Set the notification backend.","backend");
parser.addOption(backend);
QCommandLineOption silent(QStringList() << "silent", "Don't print to stdout.");
parser.addOption(silent);
parser.process(app);
snoreDebug( SNORE_DEBUG ) << parser.positionalArguments();
if(parser.isSet(title) && parser.isSet(message))
{
SnoreCore core;
@ -53,7 +56,7 @@ int main ( int argc, char *argv[] )
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;
std::cerr << "Failed to set backend: " << qPrintable(parser.value(backend)) << " avalible backends: " << qPrintable(core.notificationBackends().join(", ")) << std::endl;
return 1;
}
Icon icon(parser.value(iconPath));
@ -67,12 +70,15 @@ int main ( int argc, char *argv[] )
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();
});
if(!parser.isSet(silent))
{
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;