KShare/main.cpp

58 lines
1.5 KiB
C++
Raw Normal View History

2017-04-23 15:05:48 +02:00
#include "mainwindow.hpp"
#include <QApplication>
2017-04-27 13:57:42 +02:00
#include <QCommandLineParser>
2017-04-29 23:20:08 +02:00
#include <QTimer>
2017-04-27 14:24:04 +02:00
#include <QtGlobal>
2017-04-27 13:57:42 +02:00
#include <stdio.h>
bool verbose = false;
2017-05-01 11:28:54 +02:00
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg)
2017-04-27 13:57:42 +02:00
{
QByteArray localMsg = msg.toLocal8Bit();
switch (type)
{
case QtDebugMsg:
2017-05-01 11:28:54 +02:00
if (verbose) fprintf(stderr, "DEBUG: %s\n", localMsg.constData());
2017-04-27 13:57:42 +02:00
break;
case QtInfoMsg:
2017-05-01 11:28:54 +02:00
fprintf(stderr, "INFO: %s\n", localMsg.constData());
2017-04-27 13:57:42 +02:00
break;
case QtWarningMsg:
2017-05-01 11:28:54 +02:00
fprintf(stderr, "WARN: %s\n", localMsg.constData());
2017-04-27 13:57:42 +02:00
break;
case QtCriticalMsg:
2017-05-01 11:28:54 +02:00
fprintf(stderr, "CRIT: %s\n", localMsg.constData());
2017-04-27 13:57:42 +02:00
break;
case QtFatalMsg:
2017-05-01 11:28:54 +02:00
fprintf(stderr, "FATAL: %s\n", localMsg.constData());
2017-04-27 13:57:42 +02:00
break;
}
}
2017-04-23 15:05:48 +02:00
int main(int argc, char *argv[])
{
2017-04-27 13:57:42 +02:00
qInstallMessageHandler(handler);
2017-04-23 15:05:48 +02:00
QApplication a(argc, argv);
2017-04-23 20:29:24 +02:00
a.setApplicationName("KShare");
a.setOrganizationName("ArsenArsen");
2017-04-27 18:58:23 +02:00
a.setApplicationVersion("1.1");
2017-04-26 22:00:13 +02:00
2017-04-27 13:57:42 +02:00
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);
2017-04-23 15:05:48 +02:00
MainWindow w;
2017-04-29 23:00:32 +02:00
w.show();
2017-04-29 23:20:08 +02:00
QTimer::singleShot(0, [&] {
if (parser.isSet(h)) w.hide();
});
2017-04-23 15:05:48 +02:00
return a.exec();
}