X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=main.cpp;h=42e4a7c17062f863e987a4d68d81c313663d062f;hb=5045f16d20921a6befc0c367a77a1cb838d9278e;hp=fef53247deb71820a424050f899f31f7a297f350;hpb=9b5099b654d1d631ef6f46b10f0d85b2994916d1;p=pulseview.git diff --git a/main.cpp b/main.cpp index fef5324..42e4a7c 100644 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,6 @@ */ #include /* First, so we avoid a _POSIX_C_SOURCE warning. */ -#include #include #include @@ -28,13 +27,11 @@ #include #include +#include "signalhandler.h" #include "pv/mainwindow.h" #include "config.h" -// Global pointer to our QApplication -QApplication *g_app = NULL; - void usage() { fprintf(stdout, @@ -48,31 +45,13 @@ void usage() "\n", PV_BIN_NAME, PV_DESCRIPTION); } -/* - * SIGINT handler (likely received Ctrl-C from terminal) - */ -void sigint_handler(int param) -{ - (void)param; - - qDebug("Received SIGINT."); - - if (g_app) - g_app->quit(); -} - int main(int argc, char *argv[]) { int ret = 0; struct sr_context *sr_ctx = NULL; const char *open_file = NULL; - // Register a SIGINT handler - signal(SIGINT, sigint_handler); - QApplication a(argc, argv); - // Now we have an application to populate our global pointer - g_app = &a; // Set some application metadata QApplication::setApplicationVersion(PV_VERSION_STRING); @@ -148,6 +127,20 @@ int main(int argc, char *argv[]) pv::MainWindow w(open_file); w.show(); + if(SignalHandler::prepare_signals()) { + SignalHandler *const handler = + new SignalHandler(&w); + QObject::connect(handler, + SIGNAL(int_received()), + &w, SLOT(close())); + QObject::connect(handler, + SIGNAL(term_received()), + &w, SLOT(close())); + } else { + qWarning() << + "Could not prepare signal handler."; + } + // Run the application ret = a.exec(); }