From dbc90714f5d3b759abd1276fe10ad6a75d2be2cc Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Thu, 27 Apr 2017 13:57:42 +0200 Subject: [PATCH] Add command line options. WE GOING 1.0 --- main.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a11870b..9adbdc2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,14 +1,54 @@ #include "mainwindow.hpp" #include +#include +#include +#include + +bool verbose = false; + +void handler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + QByteArray localMsg = msg.toLocal8Bit(); + switch (type) + { + case QtDebugMsg: + if (verbose) + fprintf(stdout, "DEBUG %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); + break; + case QtInfoMsg: + fprintf(stdout, "INFO %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); + break; + case QtWarningMsg: + fprintf(stderr, "WARN %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); + break; + case QtCriticalMsg: + fprintf(stderr, "CRIT %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); + break; + case QtFatalMsg: + fprintf(stderr, "FATAL %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); + break; + } +} int main(int argc, char *argv[]) { + qInstallMessageHandler(handler); QApplication a(argc, argv); a.setApplicationName("KShare"); a.setOrganizationName("ArsenArsen"); a.setApplicationVersion("1.0"); + QCommandLineParser parser; + parser.addHelpOption(); + + QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray."); + QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs"); + parser.addOption(h); + parser.addOption(v); + parser.process(a); + verbose = parser.isSet(v); + MainWindow w; - w.show(); + if (!parser.isSet(h)) w.show(); return a.exec(); }