2017-04-23 15:05:48 +02:00
|
|
|
#include "mainwindow.hpp"
|
|
|
|
#include <QApplication>
|
2017-04-27 13:57:42 +02:00
|
|
|
#include <QCommandLineParser>
|
2017-12-10 18:00:03 +01:00
|
|
|
#include <QDir>
|
2017-06-27 11:33:11 +02:00
|
|
|
#include <QScreen>
|
2017-04-27 14:24:04 +02:00
|
|
|
#include <QtGlobal>
|
2017-06-06 17:05:34 +02:00
|
|
|
#include <formatter.hpp>
|
2017-05-29 22:42:10 +02:00
|
|
|
#include <iostream>
|
2018-02-18 02:35:29 +01:00
|
|
|
#include <ui_mainwindow.h>
|
2017-06-11 23:56:06 +02:00
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
}
|
2017-06-22 17:41:29 +02:00
|
|
|
#include <QListWidget>
|
2017-07-29 17:22:17 +02:00
|
|
|
#include <QTranslator>
|
2019-05-12 16:03:40 +02:00
|
|
|
#include <QStyleFactory>
|
2017-05-22 15:56:47 +02:00
|
|
|
#include <notifications.hpp>
|
2017-05-29 22:42:10 +02:00
|
|
|
#include <worker/worker.hpp>
|
2017-04-27 13:57:42 +02:00
|
|
|
|
|
|
|
bool verbose = false;
|
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
// I've experiments to run
|
|
|
|
// There is research to be done
|
|
|
|
// On the people who are
|
|
|
|
// still alive
|
|
|
|
bool stillAlive = true;
|
|
|
|
|
2018-01-01 16:37:31 +01:00
|
|
|
#define LOGACT(lvl) std::cout << lvl << stdMsg << "\n" << std::flush;
|
2017-05-06 13:21:12 +02:00
|
|
|
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
|
2017-07-08 21:40:09 +02:00
|
|
|
if (!verbose && msg.startsWith("QPixmap::fromWinHBITMAP")) return;
|
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-06-22 17:41:29 +02:00
|
|
|
if (verbose) {
|
|
|
|
LOGACT("DEBUG: ")
|
|
|
|
}
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
2017-06-22 17:41:29 +02:00
|
|
|
LOGACT("INFO: ")
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
2017-06-22 17:41:29 +02:00
|
|
|
LOGACT("WARN: ")
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
2017-06-22 17:41:29 +02:00
|
|
|
LOGACT("CRIT: ")
|
2017-05-09 17:26:00 +02:00
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
2017-06-22 17:41:29 +02:00
|
|
|
LOGACT("FATAL: ")
|
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-07-29 17:22:17 +02:00
|
|
|
void loadTranslation(QString locale) {
|
2017-07-29 23:58:09 +02:00
|
|
|
QFile resource(":/translations/" + locale + ".qm");
|
2017-07-29 17:22:17 +02:00
|
|
|
if (!resource.exists()) return;
|
|
|
|
resource.open(QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
QTranslator *translator = new QTranslator;
|
|
|
|
QByteArray file = resource.readAll();
|
|
|
|
QByteArray *permFile = new QByteArray;
|
|
|
|
permFile->swap(file);
|
|
|
|
translator->load((const unsigned char *)permFile->constData(), permFile->size());
|
|
|
|
QApplication::installTranslator(translator);
|
|
|
|
}
|
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
2017-06-11 23:56:06 +02:00
|
|
|
av_register_all();
|
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-07-04 20:58:13 +02:00
|
|
|
a.setApplicationVersion("4.1");
|
2017-04-26 22:00:13 +02:00
|
|
|
|
2017-07-29 17:22:17 +02:00
|
|
|
QString locale = QLocale::system().name();
|
|
|
|
if (locale != "en_US") loadTranslation(locale);
|
|
|
|
|
2019-05-12 16:03:40 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",QSettings::NativeFormat);
|
|
|
|
if(settings.value("AppsUseLightTheme")==0){
|
|
|
|
qApp->setStyle(QStyleFactory::create("Fusion"));
|
|
|
|
QPalette darkPalette;
|
|
|
|
QColor darkColor = QColor(45,45,45);
|
|
|
|
QColor disabledColor = QColor(127,127,127);
|
|
|
|
darkPalette.setColor(QPalette::Window, darkColor);
|
|
|
|
darkPalette.setColor(QPalette::WindowText, Qt::white);
|
|
|
|
darkPalette.setColor(QPalette::Base, QColor(18,18,18));
|
|
|
|
darkPalette.setColor(QPalette::AlternateBase, darkColor);
|
|
|
|
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
|
|
|
|
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
|
|
|
|
darkPalette.setColor(QPalette::Text, Qt::white);
|
|
|
|
darkPalette.setColor(QPalette::Disabled, QPalette::Text, disabledColor);
|
|
|
|
darkPalette.setColor(QPalette::Button, darkColor);
|
|
|
|
darkPalette.setColor(QPalette::ButtonText, Qt::white);
|
|
|
|
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledColor);
|
|
|
|
darkPalette.setColor(QPalette::BrightText, Qt::red);
|
|
|
|
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
|
|
|
|
|
|
|
|
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
|
|
|
|
darkPalette.setColor(QPalette::HighlightedText, Qt::black);
|
|
|
|
darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, disabledColor);
|
|
|
|
|
|
|
|
qApp->setPalette(darkPalette);
|
|
|
|
|
|
|
|
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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);
|
|
|
|
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-06-22 17:41:29 +02:00
|
|
|
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
|
2017-07-12 20:12:17 +02:00
|
|
|
|
2017-05-14 19:32:55 +02:00
|
|
|
if (!parser.isSet(h)) w.show();
|
2017-05-09 17:26:00 +02:00
|
|
|
return a.exec();
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|