Files
Stacer/stacer/main.cpp
Kimberly 9357ed5595 Update main.cpp
1. Bug fix when attempting to use "--hide" originally, since QT was not made aware of "--hide" via addOption, the check for "--hide" later was never going to be called.  This fixes that so "--hide" now works
2.  Added "--nosplash" for those who want to optionally hide the splash when hiding on startup.
2022-04-20 18:23:36 -04:00

107 lines
2.6 KiB
C++

#include <QApplication>
#include <QSplashScreen>
#include <QDebug>
#include <QFontDatabase>
#include "app.h"
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
Q_UNUSED(context)
QString level;
switch (type) {
case QtDebugMsg:
level = "DEBUG"; break;
case QtInfoMsg:
level = "INFO"; break;
case QtWarningMsg:
level = "WARNING"; break;
case QtCriticalMsg:
level = "CRITICAL"; break;
case QtFatalMsg:
level = "FATAL"; break;
default:
level = "UNDEFIEND"; break;
}
if (type != QtWarningMsg) {
QString text = QString("[%1] [%2] %3")
.arg(QDateTime::currentDateTime().toString("dd-MM-yyyy hh:mm:ss"))
.arg(level)
.arg(message);
static QString logPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QFile file(logPath + "/stacer.log");
QIODevice::OpenMode openMode = file.size() > (1L << 20) ? QIODevice::Truncate : QIODevice::Append;
if (file.open(QIODevice::WriteOnly | openMode)) {
QTextStream stream(&file);
stream << text << endl;
file.close();
}
}
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qApp->setApplicationName("stacer");
qApp->setApplicationDisplayName("Stacer");
qApp->setApplicationVersion("1.1.0");
qApp->setWindowIcon(QIcon(":/static/logo.png"));
{
QCommandLineOption hideOption("hide", "Hide Stacer while launching.");
QCommandLineOption noSplashOption("nosplash", "Hide splash screen while launching.");
QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(hideOption);
parser.addOption(noSplashOption);
parser.process(app);
}
bool isHide = false;
bool isNoSplash = false;
QLatin1String hideOption("--hide");
QLatin1String noSplashOption("--nosplash");
for (size_t i = 1; i < argc; ++i) {
if (QString(argv[i]) == hideOption)
isHide = true;
else if (QString(argv[i]) == noSplashOption)
isNoSplash = true;
}
QFontDatabase::addApplicationFont(":/static/font/Ubuntu-R.ttf");
QPixmap pixSplash(":/static/splashscreen.png");
QSplashScreen *splash = new QSplashScreen(pixSplash);
if (!isNoSplash) splash->show();
app.processEvents();
App w;
if (argc < 2 || !isHide) {
w.show();
}
splash->finish(&w);
delete splash;
return app.exec();
}