KShare/main.cpp

96 lines
3.2 KiB
C++
Raw Normal View History

2017-04-23 15:05:48 +02:00
#include "mainwindow.hpp"
#include "screenshotutil.hpp"
2017-06-27 12:46:35 +02:00
#include "ui_mainwindow.h"
2017-04-23 15:05:48 +02:00
#include <QApplication>
2017-04-27 13:57:42 +02:00
#include <QCommandLineParser>
#include <QDebug>
#include <QScreen>
2017-04-27 14:24:04 +02:00
#include <QtGlobal>
#include <formatter.hpp>
#include <iostream>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
#include <QListWidget>
2017-05-22 15:56:47 +02:00
#include <notifications.hpp>
#include <platformbackend.hpp>
#include <worker/worker.hpp>
2017-04-27 13:57:42 +02:00
bool verbose = false;
// I've experiments to run
// There is research to be done
// On the people who are
// still alive
bool stillAlive = true;
#define LOGACT(lvl) \
std::cout << lvl << stdMsg << "\n"; \
if (stillAlive && MainWindow::inst() && MainWindow::inst()->valid()) { \
MainWindow::inst()->ui->logBox->addItem(lvl + msg); \
}
2017-05-06 13:21:12 +02:00
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
if (!verbose && msg.startsWith("QPixmap::fromWinHBITMAP")) return;
std::string stdMsg = msg.toStdString();
switch (type) {
case QtDebugMsg:
if (verbose) {
LOGACT("DEBUG: ")
}
break;
case QtInfoMsg:
LOGACT("INFO: ")
if (stillAlive) notifications::notifyNolog("KShare", msg);
break;
case QtWarningMsg:
LOGACT("WARN: ")
if (stillAlive) notifications::notifyNolog("KShare Warning", msg, QSystemTrayIcon::Warning);
break;
case QtCriticalMsg:
LOGACT("CRIT: ")
if (stillAlive) notifications::notifyNolog("KShare Critical Error", msg, QSystemTrayIcon::Critical);
break;
case QtFatalMsg:
LOGACT("FATAL: ")
if (stillAlive) notifications::notifyNolog("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[]) {
av_register_all();
qInstallMessageHandler(handler);
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);
a.setApplicationName("KShare");
a.setOrganizationName("ArsenArsen");
2017-07-04 20:58:13 +02:00
a.setApplicationVersion("4.1");
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);
MainWindow w;
Worker::init();
2017-05-30 15:51:25 +02:00
a.connect(&a, &QApplication::aboutToQuit, Worker::end);
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
2017-07-09 21:04:21 +02:00
screenshotutil::renderText("DICKS").save("/home/arsen/test.png");
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
}