2017-12-02 10:50:30 +01:00
|
|
|
#include <QApplication>
|
2017-12-05 20:43:56 +01:00
|
|
|
#include <QTranslator>
|
|
|
|
|
#include <QMessageBox>
|
2017-12-02 10:50:30 +01:00
|
|
|
#include <QSplashScreen>
|
|
|
|
|
#include <QPixmap>
|
2017-12-05 20:43:56 +01:00
|
|
|
#include <QDir>
|
2017-12-02 10:50:30 +01:00
|
|
|
#include <QInputDialog>
|
2017-12-05 21:16:46 +01:00
|
|
|
#include <QStringBuilder>
|
2017-12-05 20:39:44 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2017-12-03 22:22:07 +01:00
|
|
|
#include "zeiterfassungsettings.h"
|
2017-12-05 20:39:44 +01:00
|
|
|
#include "dialogs/languageselectiondialog.h"
|
2017-12-02 10:50:30 +01:00
|
|
|
#include "zeiterfassung.h"
|
|
|
|
|
#include "eventloopwithstatus.h"
|
|
|
|
|
#include "dialogs/authenticationdialog.h"
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
2017-12-05 20:43:56 +01:00
|
|
|
bool loadAndInstallTranslator(QTranslator &translator,
|
|
|
|
|
const QLocale &locale,
|
|
|
|
|
const QString &filename,
|
|
|
|
|
const QString &prefix = QString(),
|
|
|
|
|
const QString &directory = QString(),
|
|
|
|
|
const QString &suffix = QString())
|
|
|
|
|
{
|
|
|
|
|
if(!translator.load(locale, filename, prefix, directory, suffix))
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "could not load translation" << filename;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!QCoreApplication::installTranslator(&translator))
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "could not install translation" << filename;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
QApplication app(argc, argv);
|
2017-12-02 21:37:26 +01:00
|
|
|
|
|
|
|
|
qSetMessagePattern("%{time dd.MM.yyyy HH:mm:ss.zzz} "
|
|
|
|
|
"["
|
|
|
|
|
"%{if-debug}D%{endif}"
|
|
|
|
|
"%{if-info}I%{endif}"
|
|
|
|
|
"%{if-warning}W%{endif}"
|
|
|
|
|
"%{if-critical}C%{endif}"
|
|
|
|
|
"%{if-fatal}F%{endif}"
|
|
|
|
|
"] "
|
|
|
|
|
"%{function}(): "
|
|
|
|
|
"%{message}");
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
QCoreApplication::setOrganizationDomain(QStringLiteral("brunner.ninja"));
|
|
|
|
|
QCoreApplication::setOrganizationName(QStringLiteral("db-software"));
|
|
|
|
|
QCoreApplication::setApplicationName(QStringLiteral("zeiterfassung"));
|
2017-12-05 21:36:47 +01:00
|
|
|
QCoreApplication::setApplicationVersion(QStringLiteral("1.2"));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
QSplashScreen splashScreen(QPixmap(":/zeiterfassung/images/splash.png"));
|
2017-12-05 21:16:46 +01:00
|
|
|
splashScreen.showMessage(QCoreApplication::translate("main", "Loading settings..."));
|
2017-12-02 10:50:30 +01:00
|
|
|
splashScreen.show();
|
|
|
|
|
|
2017-12-03 22:22:07 +01:00
|
|
|
ZeiterfassungSettings settings(&app);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 20:39:44 +01:00
|
|
|
if(settings.language() == QLocale::AnyLanguage)
|
|
|
|
|
{
|
|
|
|
|
LanguageSelectionDialog dialog(&splashScreen);
|
|
|
|
|
|
|
|
|
|
again0:
|
|
|
|
|
if(dialog.exec() != QDialog::Accepted)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if(dialog.language() == QLocale::AnyLanguage)
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Invalid language selection!"),
|
|
|
|
|
QCoreApplication::translate("main", "Invalid language selection!") % "\n\n" %
|
2017-12-05 21:36:47 +01:00
|
|
|
QCoreApplication::translate("main", "You did not select a valid language!"));
|
2017-12-05 20:39:44 +01:00
|
|
|
goto again0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings.setLanguage(dialog.language());
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 20:49:35 +01:00
|
|
|
QLocale locale(settings.language(), QLocale::Austria);
|
|
|
|
|
QLocale::setDefault(locale);
|
2017-12-05 20:39:44 +01:00
|
|
|
|
2017-12-05 20:43:56 +01:00
|
|
|
QTranslator qtTranslator(&app);
|
2017-12-05 20:49:35 +01:00
|
|
|
loadAndInstallTranslator(qtTranslator, locale, QStringLiteral("qt"), QStringLiteral("_"),
|
2017-12-05 20:43:56 +01:00
|
|
|
QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations"));
|
|
|
|
|
|
|
|
|
|
QTranslator zeiterfassungTranslator(&app);
|
2017-12-05 20:49:35 +01:00
|
|
|
loadAndInstallTranslator(zeiterfassungTranslator, locale, QStringLiteral("zeiterfassung"),
|
2017-12-05 20:43:56 +01:00
|
|
|
QStringLiteral("_"), QStringLiteral(":/zeiterfassung/translations"));
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
splashScreen.showMessage(QCoreApplication::translate("main", "Loading login page..."));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-03 22:22:07 +01:00
|
|
|
Zeiterfassung erfassung(settings.url(), &app);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
|
|
|
|
QObject::connect(&erfassung, &Zeiterfassung::loginPageFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
|
|
|
|
|
|
|
|
|
again1:
|
|
|
|
|
erfassung.doLoginPage();
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(!eventLoop.success())
|
|
|
|
|
{
|
|
|
|
|
bool ok;
|
2017-12-05 21:16:46 +01:00
|
|
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not access Zeiterfassung!"),
|
|
|
|
|
QCoreApplication::translate("main", "Could not access Zeiterfassung!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
auto url = QInputDialog::getText(&splashScreen, QCoreApplication::translate("main", "Base url"),
|
|
|
|
|
QCoreApplication::translate("main", "Please enter the base url to the Zeiterfassung:"),
|
2017-12-03 22:22:07 +01:00
|
|
|
QLineEdit::Normal, settings.url(), &ok);
|
2017-12-02 10:50:30 +01:00
|
|
|
if(!ok)
|
|
|
|
|
return -1;
|
2017-12-03 22:22:07 +01:00
|
|
|
settings.setUrl(url);
|
2017-12-02 10:50:30 +01:00
|
|
|
erfassung.setUrl(url);
|
|
|
|
|
goto again1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
splashScreen.showMessage(QCoreApplication::translate("main", "Authenticating..."));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-03 22:22:07 +01:00
|
|
|
if(settings.username().isNull() || settings.password().isNull())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
|
|
|
|
AuthenticationDialog dialog(&splashScreen);
|
|
|
|
|
if(dialog.exec() != QDialog::Accepted)
|
|
|
|
|
return -1;
|
2017-12-03 22:22:07 +01:00
|
|
|
settings.setUsername(dialog.username());
|
|
|
|
|
settings.setPassword(dialog.password());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
|
|
|
|
QObject::connect(&erfassung, &Zeiterfassung::loginFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
|
|
|
|
|
|
|
|
|
again2:
|
2017-12-03 22:22:07 +01:00
|
|
|
erfassung.doLogin(settings.username(), settings.password());
|
2017-12-02 10:50:30 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(!eventLoop.success())
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not authenticate with Zeiterfassung!"),
|
|
|
|
|
QCoreApplication::translate("main", "Could not authenticate with Zeiterfassung!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
AuthenticationDialog dialog(&splashScreen);
|
2017-12-03 22:22:07 +01:00
|
|
|
dialog.setUsername(settings.username());
|
|
|
|
|
dialog.setPassword(settings.password());
|
2017-12-02 10:50:30 +01:00
|
|
|
if(dialog.exec() != QDialog::Accepted)
|
|
|
|
|
return -1;
|
2017-12-03 22:22:07 +01:00
|
|
|
settings.setUsername(dialog.username());
|
|
|
|
|
settings.setPassword(dialog.password());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
goto again2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
splashScreen.showMessage(QCoreApplication::translate("main", "Getting user information..."));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
Zeiterfassung::UserInfo userInfo;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
EventLoopWithStatus eventLoop;
|
|
|
|
|
QObject::connect(&erfassung, &Zeiterfassung::userInfoFinished,
|
|
|
|
|
[&](bool success, const QString &message, const Zeiterfassung::UserInfo &_userInfo) {
|
|
|
|
|
Q_UNUSED(message)
|
|
|
|
|
if(success)
|
|
|
|
|
userInfo = _userInfo;
|
|
|
|
|
});
|
|
|
|
|
QObject::connect(&erfassung, &Zeiterfassung::userInfoFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus);
|
|
|
|
|
|
|
|
|
|
erfassung.doUserInfo();
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
|
|
|
|
|
if(!eventLoop.success())
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not get user information!"),
|
|
|
|
|
QCoreApplication::translate("main", "Could not get user information!") % "\n\n" % eventLoop.message());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow mainWindow(settings, erfassung, userInfo);
|
|
|
|
|
mainWindow.show();
|
|
|
|
|
|
|
|
|
|
splashScreen.finish(&mainWindow);
|
|
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|