2015-09-06 20:33:09 +02:00
|
|
|
#include "./initiategui.h"
|
2015-04-22 19:30:09 +02:00
|
|
|
|
2015-12-05 22:52:00 +01:00
|
|
|
#include "./gui/mainwindow.h"
|
|
|
|
|
2015-12-08 08:37:18 +01:00
|
|
|
#include "resources/config.h"
|
2019-06-16 15:56:34 +02:00
|
|
|
#include "resources/qtconfig.h"
|
2015-04-22 19:30:09 +02:00
|
|
|
|
2024-04-08 12:39:46 +02:00
|
|
|
#include <QApplication> // ensure QGuiApplication is defined before resources.h for desktop file name
|
|
|
|
|
2017-05-01 03:26:04 +02:00
|
|
|
#include <qtutilities/resources/importplugin.h>
|
2015-09-01 20:18:13 +02:00
|
|
|
#include <qtutilities/resources/qtconfigarguments.h>
|
2015-04-22 19:30:09 +02:00
|
|
|
#include <qtutilities/resources/resources.h>
|
2016-08-16 00:37:17 +02:00
|
|
|
#include <qtutilities/settingsdialog/qtsettings.h>
|
2015-04-22 19:30:09 +02:00
|
|
|
|
2019-09-14 19:38:06 +02:00
|
|
|
#include <passwordfile/util/openssl.h>
|
|
|
|
|
2017-02-20 19:55:48 +01:00
|
|
|
#include <QFile>
|
2023-02-18 19:00:05 +01:00
|
|
|
#include <QMessageBox>
|
2017-05-01 03:26:04 +02:00
|
|
|
#include <QSettings>
|
2015-04-22 19:30:09 +02:00
|
|
|
|
2019-06-10 22:44:59 +02:00
|
|
|
using namespace CppUtilities;
|
|
|
|
using namespace QtUtilities;
|
2019-09-14 19:38:06 +02:00
|
|
|
using namespace Util;
|
2015-09-01 20:18:13 +02:00
|
|
|
|
2015-04-22 19:30:09 +02:00
|
|
|
namespace QtGui {
|
|
|
|
|
2015-09-01 20:18:13 +02:00
|
|
|
int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs, const QString &file)
|
2015-04-22 19:30:09 +02:00
|
|
|
{
|
2015-08-25 19:14:49 +02:00
|
|
|
SET_QT_APPLICATION_INFO;
|
2019-09-14 19:38:06 +02:00
|
|
|
|
|
|
|
// init OpenSSL
|
|
|
|
OpenSsl::init();
|
|
|
|
|
2015-04-22 19:30:09 +02:00
|
|
|
// init application
|
2024-04-01 13:59:22 +02:00
|
|
|
auto application = QApplication(argc, argv);
|
|
|
|
QObject::connect(&application, &QCoreApplication::aboutToQuit, &OpenSsl::clean);
|
2019-09-14 19:38:06 +02:00
|
|
|
|
2016-08-16 00:37:17 +02:00
|
|
|
// restore Qt settings
|
2022-08-20 16:25:07 +02:00
|
|
|
auto qtSettings = QtSettings();
|
|
|
|
auto settings = QtUtilities::getSettings(QStringLiteral(PROJECT_NAME));
|
2023-02-18 19:00:05 +01:00
|
|
|
auto settingsError = QtUtilities::errorMessageForSettings(*settings);
|
2023-03-30 00:04:39 +02:00
|
|
|
qtSettings.disableNotices();
|
2022-08-20 16:25:07 +02:00
|
|
|
qtSettings.restore(*settings);
|
2016-08-16 00:37:17 +02:00
|
|
|
qtSettings.apply();
|
2019-09-14 19:38:06 +02:00
|
|
|
|
2015-09-01 20:18:13 +02:00
|
|
|
// apply settings specified via command line args
|
2016-08-27 15:19:49 +02:00
|
|
|
qtConfigArgs.applySettings(qtSettings.hasCustomFont());
|
2015-08-25 19:14:49 +02:00
|
|
|
LOAD_QT_TRANSLATIONS;
|
2019-09-14 19:38:06 +02:00
|
|
|
|
2015-04-22 19:30:09 +02:00
|
|
|
// init widgets GUI
|
2023-02-18 19:00:05 +01:00
|
|
|
if (!settingsError.isEmpty()) {
|
|
|
|
QMessageBox::critical(nullptr, QCoreApplication::applicationName(), settingsError);
|
|
|
|
}
|
2022-08-20 16:25:07 +02:00
|
|
|
auto w = MainWindow(*settings, &qtSettings);
|
2015-04-22 19:30:09 +02:00
|
|
|
w.show();
|
2017-05-01 03:26:04 +02:00
|
|
|
if (!file.isEmpty()) {
|
2015-04-22 19:30:09 +02:00
|
|
|
w.openFile(file);
|
|
|
|
}
|
2019-09-14 19:38:06 +02:00
|
|
|
|
2015-04-22 19:30:09 +02:00
|
|
|
// start event loop
|
2023-02-18 19:00:05 +01:00
|
|
|
auto res = application.exec();
|
|
|
|
|
|
|
|
// save settings to disk
|
|
|
|
settings->sync();
|
|
|
|
if (settingsError.isEmpty()) {
|
|
|
|
settingsError = QtUtilities::errorMessageForSettings(*settings);
|
|
|
|
if (!settingsError.isEmpty()) {
|
|
|
|
QMessageBox::critical(nullptr, QCoreApplication::applicationName(), settingsError);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2015-04-22 19:30:09 +02:00
|
|
|
}
|
2017-09-29 17:17:12 +02:00
|
|
|
} // namespace QtGui
|