2022-04-17 15:37:04 +03:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "autostart.h"
|
|
|
|
|
#include "runguard.h"
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
|
#include <QTranslator>
|
|
|
|
|
#include <QFileInfo>
|
2022-12-11 08:42:19 +03:00
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
|
|
#if defined(TARGET_LINUX)
|
|
|
|
|
# include <syslog.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Handler for Qt log messages that sends output to syslog as well as standard error.
|
|
|
|
|
void SyslogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(context)
|
|
|
|
|
std::string timePrefix = QDateTime::currentDateTime().toString().toStdString();
|
|
|
|
|
|
|
|
|
|
QByteArray localMsg = msg.toLocal8Bit();
|
|
|
|
|
switch (type) {
|
|
|
|
|
case QtDebugMsg:
|
|
|
|
|
fprintf(stderr, "debug: %s %s\n", timePrefix.c_str(), localMsg.constData());
|
|
|
|
|
#if defined(TARGET_LINUX)
|
|
|
|
|
syslog(LOG_DEBUG, "debug: %s", localMsg.constData());
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case QtInfoMsg:
|
|
|
|
|
fprintf(stderr, "info: %s %s\n", timePrefix.c_str(), localMsg.constData());
|
|
|
|
|
#if defined(TARGET_LINUX)
|
|
|
|
|
syslog(LOG_INFO, "info: %s", localMsg.constData());
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case QtWarningMsg:
|
|
|
|
|
fprintf(stderr, "warning: %s %s\n", timePrefix.c_str(), localMsg.constData());
|
|
|
|
|
#if defined(TARGET_LINUX)
|
|
|
|
|
syslog(LOG_WARNING, "warning: %s", localMsg.constData());
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case QtCriticalMsg:
|
|
|
|
|
fprintf(stderr, "critical: %s %s\n", timePrefix.c_str(), localMsg.constData());
|
|
|
|
|
#if defined(TARGET_LINUX)
|
|
|
|
|
syslog(LOG_CRIT, "critical: %s", localMsg.constData());
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case QtFatalMsg:
|
|
|
|
|
fprintf(stderr, "fatal: %s %s\n", timePrefix.c_str(), localMsg.constData());
|
|
|
|
|
#if defined(TARGET_LINUX)
|
|
|
|
|
syslog(LOG_ALERT, "fatal: %s", localMsg.constData());
|
|
|
|
|
#endif
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 15:37:04 +03:00
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2022-11-28 21:21:44 +03:00
|
|
|
RunGuard guard("QBreak app - runguard");
|
2022-04-17 15:37:04 +03:00
|
|
|
if ( !guard.tryToRun() )
|
|
|
|
|
return 0;
|
|
|
|
|
|
2022-12-11 08:42:19 +03:00
|
|
|
// Needed to enable logging to syslog or journald.
|
|
|
|
|
qInstallMessageHandler(SyslogMessageHandler);
|
|
|
|
|
|
2022-04-17 15:37:04 +03:00
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
2022-11-27 19:37:46 +03:00
|
|
|
QCoreApplication::setOrganizationName("voipobjects.com");
|
|
|
|
|
QCoreApplication::setOrganizationDomain("voipobjects.com");
|
2022-04-17 15:37:04 +03:00
|
|
|
QCoreApplication::setApplicationName("QBreak");
|
|
|
|
|
|
|
|
|
|
QTranslator translator;
|
|
|
|
|
bool ok = translator.load(":/i18n/strings_" + QLocale::system().name());
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
app.installTranslator(&translator);
|
|
|
|
|
|
|
|
|
|
app.setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Put itself into app menu
|
2022-12-11 08:42:19 +03:00
|
|
|
auto exe_path = QCoreApplication::applicationFilePath();
|
2022-09-20 11:19:03 +03:00
|
|
|
const char* appimage = std::getenv("APPIMAGE");
|
|
|
|
|
if (appimage != nullptr)
|
|
|
|
|
exe_path = appimage;
|
|
|
|
|
|
|
|
|
|
appmenu::install(exe_path.toStdString());
|
2022-04-17 15:37:04 +03:00
|
|
|
|
|
|
|
|
// Main window is full screen window, so start with tray icon only
|
|
|
|
|
MainWindow w;
|
|
|
|
|
w.hide();
|
|
|
|
|
|
|
|
|
|
int retcode = app.exec();
|
|
|
|
|
|
|
|
|
|
return retcode;
|
|
|
|
|
}
|