|
1 | 1 | #include "mainwindow.hpp" |
2 | 2 | #include <QApplication> |
| 3 | +#include <QCommandLineParser> |
| 4 | +#include <QDebug> |
| 5 | +#include <stdio.h> |
| 6 | + |
| 7 | +bool verbose = false; |
| 8 | + |
| 9 | +void handler(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
| 10 | +{ |
| 11 | + QByteArray localMsg = msg.toLocal8Bit(); |
| 12 | + switch (type) |
| 13 | + { |
| 14 | + case QtDebugMsg: |
| 15 | + if (verbose) |
| 16 | + fprintf(stdout, "DEBUG %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); |
| 17 | + break; |
| 18 | + case QtInfoMsg: |
| 19 | + fprintf(stdout, "INFO %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); |
| 20 | + break; |
| 21 | + case QtWarningMsg: |
| 22 | + fprintf(stderr, "WARN %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); |
| 23 | + break; |
| 24 | + case QtCriticalMsg: |
| 25 | + fprintf(stderr, "CRIT %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); |
| 26 | + break; |
| 27 | + case QtFatalMsg: |
| 28 | + fprintf(stderr, "FATAL %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData()); |
| 29 | + break; |
| 30 | + } |
| 31 | +} |
3 | 32 |
|
4 | 33 | int main(int argc, char *argv[]) |
5 | 34 | { |
| 35 | + qInstallMessageHandler(handler); |
6 | 36 | QApplication a(argc, argv); |
7 | 37 | a.setApplicationName("KShare"); |
8 | 38 | a.setOrganizationName("ArsenArsen"); |
9 | 39 | a.setApplicationVersion("1.0"); |
10 | 40 |
|
| 41 | + QCommandLineParser parser; |
| 42 | + parser.addHelpOption(); |
| 43 | + |
| 44 | + QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray."); |
| 45 | + QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs"); |
| 46 | + parser.addOption(h); |
| 47 | + parser.addOption(v); |
| 48 | + parser.process(a); |
| 49 | + verbose = parser.isSet(v); |
| 50 | + |
11 | 51 | MainWindow w; |
12 | | - w.show(); |
| 52 | + if (!parser.isSet(h)) w.show(); |
13 | 53 | return a.exec(); |
14 | 54 | } |
0 commit comments