2121
2222#include " Application.h"
2323
24+ #include " Common.h"
25+ #include " Configuration.h"
2426#include " MainWindow.h"
2527#include " QSigner.h"
2628#include " QSmartCard.h"
@@ -40,7 +42,6 @@ class MacMenuBar {};
4042#include " dialogs/WarningDialog.h"
4143#include " effects/Overlay.h"
4244
43- #include < common/Configuration.h>
4445#include < optional>
4546
4647#include < digidocpp/Container.h>
@@ -308,13 +309,35 @@ class Application::Private
308309};
309310
310311Application::Application ( int &argc, char **argv )
311- #ifdef Q_OS_MAC
312- : Common(argc, argv, QStringLiteral(" qdigidoc4" ), QStringLiteral(" :/images/Icon.svg" ))
313- #else
314- : Common(argc, argv, QStringLiteral(" qdigidoc4" ), QStringLiteral(" :/images/digidoc_128.png" ))
315- #endif
312+ : BaseApplication(argc, argv)
316313 , d(new Private)
317314{
315+ setApplicationName (QStringLiteral (" qdigidoc4" ));
316+ setApplicationVersion (QStringLiteral (" %1.%2.%3.%4" )
317+ .arg ( MAJOR_VER ).arg ( MINOR_VER ).arg ( RELEASE_VER ).arg ( BUILD_VER ) );
318+ setOrganizationDomain (QStringLiteral (" ria.ee" ));
319+ setOrganizationName (QStringLiteral (" RIA" ));
320+ setWindowIcon (QIcon (QStringLiteral (" :/images/Icon.svg" )));
321+ if (QFile::exists (QStringLiteral (" %1/%2.log" ).arg (QDir::tempPath (), applicationName ())))
322+ qInstallMessageHandler (msgHandler);
323+
324+ Q_INIT_RESOURCE (common_tr);
325+ #if defined(Q_OS_WIN)
326+ AllowSetForegroundWindow ( ASFW_ANY );
327+ #ifdef NDEBUG
328+ setLibraryPaths ({ applicationDirPath () });
329+ #endif
330+ #elif defined(Q_OS_MAC)
331+ qputenv (" OPENSSL_CONF" , applicationDirPath ().toUtf8 () + " ../Resources/openssl.cnf" );
332+ #ifdef NDEBUG
333+ setLibraryPaths ({ applicationDirPath () + " /../PlugIns" });
334+ #endif
335+ #endif
336+ setStyleSheet (QStringLiteral (
337+ " QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 0; }\n " ));
338+
339+ QNetworkProxyFactory::setUseSystemConfiguration (true );
340+
318341 QStringList args = arguments ();
319342 args.removeFirst ();
320343#ifndef Q_OS_MAC
@@ -432,7 +455,7 @@ Application::Application( int &argc, char **argv )
432455 updateTSLCache (QDateTime::currentDateTimeUtc ().addDays (-7 ));
433456
434457 digidoc::initialize (applicationName ().toUtf8 ().constData (), QStringLiteral (" %1/%2 (%3)" )
435- .arg (applicationName (), applicationVersion (), applicationOs ()).toUtf8 ().constData (),
458+ .arg (applicationName (), applicationVersion (), Common:: applicationOs ()).toUtf8 ().constData (),
436459 [](const digidoc::Exception *ex) {
437460 qDebug () << " TSL loading finished" ;
438461 Q_EMIT qApp->TSLLoadingFinished ();
@@ -627,9 +650,9 @@ bool Application::event(QEvent *event)
627650 // Load here because cocoa NSApplication overides events
628651 case QEvent::ApplicationActivate:
629652 initMacEvents ();
630- return Common ::event (event);
653+ return BaseApplication ::event (event);
631654#endif
632- default : return Common ::event (event);
655+ default : return BaseApplication ::event (event);
633656 }
634657}
635658
@@ -756,6 +779,32 @@ QWidget* Application::mainWindow()
756779 return nullptr ;
757780}
758781
782+ void Application::msgHandler (QtMsgType type, const QMessageLogContext &ctx, const QString &msg)
783+ {
784+ QFile f (QStringLiteral (" %1/%2.log" ).arg (QDir::tempPath (), applicationName ()));
785+ if (!f.open ( QFile::Append ))
786+ return ;
787+ f.write (QDateTime::currentDateTime ().toString (QStringLiteral (" yyyy-MM-dd hh:mm:ss " )).toUtf8 ());
788+ switch (type)
789+ {
790+ case QtDebugMsg: f.write (" D" ); break ;
791+ case QtWarningMsg: f.write (" W" ); break ;
792+ case QtCriticalMsg: f.write (" C" ); break ;
793+ case QtFatalMsg: f.write (" F" ); break ;
794+ default : f.write (" I" ); break ;
795+ }
796+ f.write (QStringLiteral (" %1 " ).arg (QLatin1String (ctx.category )).toUtf8 ());
797+ if (ctx.line > 0 )
798+ {
799+ f.write (QStringLiteral (" %1:%2 \" %3\" " )
800+ .arg (QFileInfo (QString::fromLatin1 (ctx.file )).fileName ())
801+ .arg (ctx.line )
802+ .arg (QLatin1String (ctx.function )).toUtf8 ());
803+ }
804+ f.write (msg.toUtf8 ());
805+ f.write (" \n " );
806+ }
807+
759808bool Application::notify (QObject *object, QEvent *event)
760809{
761810 try
0 commit comments