2017-04-23 15:05:48 +02:00
|
|
|
#include "mainwindow.hpp"
|
2017-05-24 16:51:14 +02:00
|
|
|
#include "screenshotutil.hpp"
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QApplication>
|
2017-04-27 13:57:42 +02:00
|
|
|
#include <QCommandLineParser>
|
2017-04-27 14:24:04 +02:00
|
|
|
#include <QtGlobal>
|
2017-05-29 22:42:10 +02:00
|
|
|
#include <iostream>
|
2017-05-22 15:56:47 +02:00
|
|
|
#include <notifications.hpp>
|
2017-05-31 17:24:17 +02:00
|
|
|
#include <screenareaselector/screenareaselector.hpp>
|
2017-04-27 13:57:42 +02:00
|
|
|
#include <stdio.h>
|
2017-05-29 22:42:10 +02:00
|
|
|
#include <worker/worker.hpp>
|
2017-04-27 13:57:42 +02:00
|
|
|
|
|
|
|
bool verbose = false;
|
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
|
2017-05-29 22:42:10 +02:00
|
|
|
std::string stdMsg = msg.toStdString();
|
2017-05-09 17:26:00 +02:00
|
|
|
switch (type) {
|
|
|
|
case QtDebugMsg:
|
2017-05-29 22:42:10 +02:00
|
|
|
if (verbose) std::cout << "DEBUG: " << stdMsg << "\n";
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
2017-05-29 22:42:10 +02:00
|
|
|
std::cout << "INFO: " << stdMsg << "\n";
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
2017-05-29 22:42:10 +02:00
|
|
|
std::cerr << "WARN: " << stdMsg << "\n";
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
2017-05-29 22:42:10 +02:00
|
|
|
std::cerr << "CRIT: " << stdMsg << "\n";
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
2017-05-29 22:42:10 +02:00
|
|
|
std::cerr << "FATAL: " << stdMsg << "\n";
|
2017-05-22 15:56:47 +02:00
|
|
|
notifications::notify("KShare Fatal Error", msg, QSystemTrayIcon::Critical);
|
2017-05-09 17:26:00 +02:00
|
|
|
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[]) {
|
2017-05-09 17:26:00 +02:00
|
|
|
qInstallMessageHandler(handler);
|
|
|
|
QApplication a(argc, argv);
|
2017-05-24 16:51:14 +02:00
|
|
|
a.setQuitOnLastWindowClosed(false);
|
2017-05-09 17:26:00 +02:00
|
|
|
a.setApplicationName("KShare");
|
|
|
|
a.setOrganizationName("ArsenArsen");
|
2017-05-13 19:21:15 +02:00
|
|
|
a.setApplicationVersion("3.0");
|
2017-04-26 22:00:13 +02:00
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addHelpOption();
|
2017-04-27 13:57:42 +02:00
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray.");
|
|
|
|
QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs");
|
2017-05-13 19:31:55 +02:00
|
|
|
QCommandLineOption ver({ "ver", "version" }, "Prints KShare version");
|
2017-05-09 17:26:00 +02:00
|
|
|
parser.addOption(h);
|
|
|
|
parser.addOption(v);
|
2017-05-13 19:31:55 +02:00
|
|
|
parser.addOption(ver);
|
2017-05-09 17:26:00 +02:00
|
|
|
parser.process(a);
|
2017-05-13 19:31:55 +02:00
|
|
|
|
|
|
|
if (parser.isSet(ver)) {
|
|
|
|
printf("%s %s\n", a.applicationName().toLocal8Bit().constData(), a.applicationVersion().toLocal8Bit().constData());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
verbose = parser.isSet(v);
|
2017-04-27 13:57:42 +02:00
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
MainWindow w;
|
2017-05-29 22:42:10 +02:00
|
|
|
Worker::init();
|
2017-05-30 15:51:25 +02:00
|
|
|
a.connect(&a, &QApplication::aboutToQuit, Worker::end);
|
2017-05-14 19:32:55 +02:00
|
|
|
if (!parser.isSet(h)) w.show();
|
2017-05-31 17:24:17 +02:00
|
|
|
(new ScreenAreaSelector())->show();
|
2017-05-09 17:26:00 +02:00
|
|
|
return a.exec();
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|