Skip to content
This repository was archived by the owner on Aug 23, 2021. It is now read-only.

Commit dbc9071

Browse files
committed
Add command line options. WE GOING 1.0
1 parent 92fa351 commit dbc9071

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

main.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,54 @@
11
#include "mainwindow.hpp"
22
#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+
}
332

433
int main(int argc, char *argv[])
534
{
35+
qInstallMessageHandler(handler);
636
QApplication a(argc, argv);
737
a.setApplicationName("KShare");
838
a.setOrganizationName("ArsenArsen");
939
a.setApplicationVersion("1.0");
1040

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+
1151
MainWindow w;
12-
w.show();
52+
if (!parser.isSet(h)) w.show();
1353
return a.exec();
1454
}

0 commit comments

Comments
 (0)