KShare/main.cpp

61 lines
1.8 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-27 14:24:04 +02:00
#include <QtGlobal>
2017-05-22 15:56:47 +02:00
#include <notifications.hpp>
2017-04-27 13:57:42 +02:00
#include <stdio.h>
bool verbose = false;
2017-05-06 13:21:12 +02:00
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
2017-05-19 22:32:23 +02:00
if (verbose) fprintf(stdout, "DEBUG: %s\n", localMsg.constData());
break;
case QtInfoMsg:
2017-05-19 22:32:23 +02:00
fprintf(stdout, "INFO: %s\n", localMsg.constData());
break;
case QtWarningMsg:
fprintf(stderr, "WARN: %s\n", localMsg.constData());
break;
case QtCriticalMsg:
fprintf(stderr, "CRIT: %s\n", localMsg.constData());
break;
case QtFatalMsg:
fprintf(stderr, "FATAL: %s\n", localMsg.constData());
2017-05-22 15:56:47 +02:00
notifications::notify("KShare Fatal Error", msg, QSystemTrayIcon::Critical);
break;
}
2017-04-27 13:57:42 +02:00
}
2017-04-23 15:05:48 +02:00
2017-05-06 13:21:12 +02:00
int main(int argc, char *argv[]) {
qInstallMessageHandler(handler);
QApplication a(argc, argv);
a.setApplicationName("KShare");
a.setOrganizationName("ArsenArsen");
a.setApplicationVersion("3.0");
2017-04-26 22:00:13 +02:00
QCommandLineParser parser;
parser.addHelpOption();
2017-04-27 13:57:42 +02:00
QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray.");
QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs");
QCommandLineOption ver({ "ver", "version" }, "Prints KShare version");
parser.addOption(h);
parser.addOption(v);
parser.addOption(ver);
parser.process(a);
if (parser.isSet(ver)) {
printf("%s %s\n", a.applicationName().toLocal8Bit().constData(), a.applicationVersion().toLocal8Bit().constData());
return 0;
}
verbose = parser.isSet(v);
2017-04-27 13:57:42 +02:00
MainWindow w;
2017-05-14 19:32:55 +02:00
if (!parser.isSet(h)) w.show();
return a.exec();
2017-04-23 15:05:48 +02:00
}