Skip to content

Commit

Permalink
Show window, then activate window and delay parameter command parsing (
Browse files Browse the repository at this point in the history
…open-eid#1156)

IB-7526, IB-7513

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Feb 10, 2023
1 parent e4dc9f5 commit a35d33c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 65 deletions.
67 changes: 31 additions & 36 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class MacMenuBar {};
#include <MAPI.h>
#endif

using namespace std::chrono;

const QStringList Application::CONTAINER_EXT {
QStringLiteral("asice"), QStringLiteral("sce"),
QStringLiteral("asics"), QStringLiteral("scs"),
Expand Down Expand Up @@ -170,7 +172,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent

std::vector<digidoc::X509Cert> TSCerts() const final
{
std::vector<digidoc::X509Cert> list = toCerts(QStringLiteral("CERT-BUNDLE"));
std::vector<digidoc::X509Cert> list = toCerts(QLatin1String("CERT-BUNDLE"));
if(digidoc::X509Cert cert = toCert(fromBase64(s.value(QStringLiteral("TSA-CERT")))))
list.push_back(cert);
return list;
Expand All @@ -188,7 +190,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent
std::string TSLUrl() const final { return valueSystemScope(QStringLiteral("TSL-URL"), digidoc::XmlConfCurrent::TSLUrl()); }
std::vector<digidoc::X509Cert> TSLCerts() const final
{
std::vector<digidoc::X509Cert> tslcerts = toCerts(QStringLiteral("TSL-CERTS"));
std::vector<digidoc::X509Cert> tslcerts = toCerts(QLatin1String("TSL-CERTS"));
return tslcerts.empty() ? digidoc::XmlConfCurrent::TSLCerts() : tslcerts;
}

Expand All @@ -201,7 +203,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent
}
std::vector<digidoc::X509Cert> verifyServiceCerts() const final
{
std::vector<digidoc::X509Cert> list = toCerts(QStringLiteral("CERT-BUNDLE"));
std::vector<digidoc::X509Cert> list = toCerts(QLatin1String("CERT-BUNDLE"));
if(digidoc::X509Cert cert = verifyServiceCert())
list.push_back(cert);
return list;
Expand Down Expand Up @@ -297,7 +299,7 @@ class DigidocConf final: public digidoc::XmlConfCurrent
return digidoc::X509Cert((const unsigned char*)der.constData(), size_t(der.size()));
}

std::vector<digidoc::X509Cert> toCerts(const QString &key) const
std::vector<digidoc::X509Cert> toCerts(QLatin1String key) const
{
std::vector<digidoc::X509Cert> certs;
for(const auto &cert: obj.value(key).toArray())
Expand All @@ -319,7 +321,7 @@ class Application::Private
{
public:
Configuration *conf {};
QAction *closeAction {}, *newClientAction {}, *newCryptoAction {}, *helpAction {};
QAction *closeAction {}, *newClientAction {}, *helpAction {};
MacMenuBar *bar {};
QSigner *signer {};

Expand All @@ -344,7 +346,7 @@ Application::Application( int &argc, char **argv )
d->conf = new Configuration(this);
connect(d->conf, &Configuration::updateReminder,
[&](bool /* expired */, const QString & /* title */, const QString &message){
WarningDialog(message, qApp->activeWindow()).exec();
WarningDialog::show(qApp->activeWindow(), message);
});
#endif

Expand Down Expand Up @@ -389,18 +391,16 @@ Application::Application( int &argc, char **argv )
// This is needed to release application from memory (Windows)
setQuitOnLastWindowClosed( true );
d->lastWindowTimer.setSingleShot(true);
connect(&d->lastWindowTimer, &QTimer::timeout, []{ if(topLevelWindows().isEmpty()) quit(); });
connect(this, &Application::lastWindowClosed, [&]{ d->lastWindowTimer.start(10*1000); });
connect(&d->lastWindowTimer, &QTimer::timeout, this, []{ if(topLevelWindows().isEmpty()) quit(); });
connect(this, &Application::lastWindowClosed, this, [&]{ d->lastWindowTimer.start(10s); });

#ifdef Q_OS_MAC
d->bar = new MacMenuBar;
d->bar->addAction( MacMenuBar::AboutAction, this, SLOT(showAbout()) );
d->bar->addAction( MacMenuBar::PreferencesAction, this, SLOT(showSettings()) );
d->bar->fileMenu()->addAction( d->newClientAction );
d->bar->fileMenu()->addAction( d->newCryptoAction );
d->bar->fileMenu()->addAction( d->closeAction );
d->bar->dockMenu()->addAction( d->newClientAction );
d->bar->dockMenu()->addAction( d->newCryptoAction );
d->helpAction = d->bar->helpMenu()->addAction(tr("DigiDoc4 Client Help"), this, &Application::openHelp);
#endif

Expand Down Expand Up @@ -454,7 +454,7 @@ Application::Application( int &argc, char **argv )
#ifdef Q_OS_MAC
if(QSettings().value(QStringLiteral("plugins")).isNull())
{
WarningDialog *dlg = new WarningDialog(tr(
auto *dlg = new WarningDialog(tr(
"In order to authenticate and sign in e-services with an ID-card you need to install the web browser components."), parent);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setCancelText(tr("Ignore forever").toUpper());
Expand All @@ -474,7 +474,7 @@ Application::Application( int &argc, char **argv )
if(QSettings().value(QStringLiteral("showIntro"), true).toBool())
{
QSettings().setValue(QStringLiteral("showIntro"), false);
FirstRun *dlg = new FirstRun(parent);
auto *dlg = new FirstRun(parent);
connect(dlg, &FirstRun::langChanged, this, [this](const QString& lang) { loadTranslation( lang ); });
dlg->open();
}
Expand All @@ -500,7 +500,7 @@ Application::~Application()
delete d;
return;
}
if( QtLocalPeer *obj = findChild<QtLocalPeer*>() )
if(auto *obj = findChild<QtLocalPeer*>())
delete obj;
#else
deinitMacEvents();
Expand Down Expand Up @@ -536,9 +536,9 @@ void Application::activate( QWidget *w )
w->setWindowState(Qt::WindowActive);
#endif
w->addAction( d->closeAction );
w->activateWindow();
w->show();
w->raise();
w->activateWindow();
}

#ifdef Q_OS_WIN
Expand Down Expand Up @@ -566,7 +566,7 @@ void Application::clearConfValue( ConfParameter parameter )
{
try
{
digidoc::XmlConfCurrent *i = dynamic_cast<digidoc::XmlConfCurrent*>(digidoc::Conf::instance());
auto *i = dynamic_cast<digidoc::XmlConfCurrent*>(digidoc::Conf::instance());
if(!i)
return;
switch( parameter )
Expand Down Expand Up @@ -600,7 +600,7 @@ void Application::closeWindow()
w->close();
else
#endif
if( QDialog *d = qobject_cast<QDialog*>(activeWindow()) )
if(auto *d = qobject_cast<QDialog*>(activeWindow()))
d->reject();
else if(QWidget *w = activeWindow())
w->close();
Expand All @@ -613,7 +613,7 @@ Configuration* Application::conf()

QVariant Application::confValue( ConfParameter parameter, const QVariant &value )
{
DigidocConf *i = static_cast<DigidocConf*>(digidoc::Conf::instance());
auto *i = static_cast<DigidocConf*>(digidoc::Conf::instance());

QByteArray r;
switch( parameter )
Expand Down Expand Up @@ -656,7 +656,7 @@ bool Application::event(QEvent *event)
case QEvent::FileOpen:
{
QString fileName = static_cast<QFileOpenEvent*>(event)->file().normalized(QString::NormalizationForm_C);
QTimer::singleShot(0, [this, fileName] {
QTimer::singleShot(0, this, [this, fileName] {
parseArgs({ fileName });
});
return true;
Expand Down Expand Up @@ -691,7 +691,6 @@ void Application::loadTranslation( const QString &lang )
void(d->qtTranslator.load(QStringLiteral(":/translations/qt_") + lang));
if( d->closeAction ) d->closeAction->setText( tr("Close Window") );
if( d->newClientAction ) d->newClientAction->setText( tr("New Window") );
if( d->newCryptoAction ) d->newCryptoAction->setText( tr("New Crypto window") );
if(d->helpAction) d->helpAction->setText(tr("DigiDoc4 Client Help"));
}

Expand Down Expand Up @@ -787,7 +786,7 @@ QWidget* Application::mainWindow()
QWidget* root = nullptr;

if (!win)
{
{
// Prefer main window; on Mac also the menu is top level window
for (QWidget *widget: topLevelWidgets())
{
Expand Down Expand Up @@ -891,7 +890,7 @@ void Application::migrateSettings()

if(oldOrgSettings.contains(oldKey)){
newSettings.setValue(newKey, oldOrgSettings.value(oldKey));

#ifdef Q_OS_MAC
if(oldKey != newKey)
oldAppSettings.remove(oldKey);
Expand Down Expand Up @@ -963,11 +962,7 @@ bool Application::notify(QObject *object, QEvent *event)

void Application::openHelp()
{
QString lang = language();
QUrl u(QStringLiteral("https://www.id.ee/id-abikeskus/"));
if(lang == QLatin1String("en")) u = QStringLiteral("https://www.id.ee/en/id-help/");
if(lang == QLatin1String("ru")) u = QStringLiteral("https://www.id.ee/ru/id-pomoshh/");
QDesktopServices::openUrl(u);
QDesktopServices::openUrl(QUrl(tr("https://www.id.ee/en/id-help/")));
}

void Application::parseArgs( const QString &msg )
Expand Down Expand Up @@ -1028,7 +1023,7 @@ void Application::setConfValue( ConfParameter parameter, const QVariant &value )
{
try
{
digidoc::XmlConfCurrent *i = dynamic_cast<digidoc::XmlConfCurrent*>(digidoc::Conf::instance());
auto *i = dynamic_cast<digidoc::XmlConfCurrent*>(digidoc::Conf::instance());
if(!i)
return;
QByteArray v = value.toString().toUtf8();
Expand Down Expand Up @@ -1058,13 +1053,13 @@ void Application::setConfValue( ConfParameter parameter, const QVariant &value )

void Application::showAbout()
{
if(MainWindow *w = qobject_cast<MainWindow*>(mainWindow()))
if(auto *w = qobject_cast<MainWindow*>(mainWindow()))
w->showSettings(SettingsDialog::LicenseSettings);
}

void Application::showSettings()
{
if(MainWindow *w = qobject_cast<MainWindow*>(mainWindow()))
if(auto *w = qobject_cast<MainWindow*>(mainWindow()))
w->showSettings(SettingsDialog::GeneralSettings);
}

Expand All @@ -1081,7 +1076,7 @@ void Application::showClient(const QStringList &params, bool crypto, bool sign,
else if(!newWindow)
{
// else select first window with no open files
MainWindow *main = qobject_cast<MainWindow*>(uniqueRoot());
auto *main = qobject_cast<MainWindow*>(uniqueRoot());
if(main && main->windowFilePath().isEmpty())
w = main;
}
Expand Down Expand Up @@ -1111,9 +1106,9 @@ void Application::showClient(const QStringList &params, bool crypto, bool sign,
}
#endif
}
activate(w);
if( !params.isEmpty() )
QMetaObject::invokeMethod(w, "open", Q_ARG(QStringList,params), Q_ARG(bool,crypto), Q_ARG(bool,sign));
activate( w );
}

void Application::showTSLWarning(QEventLoop *e)
Expand Down Expand Up @@ -1146,9 +1141,9 @@ QWidget* Application::uniqueRoot()
MainWindow* root = nullptr;

// Return main window if only one main window is opened
for(auto w : topLevelWidgets())
for(auto *w : topLevelWidgets())
{
if(MainWindow *r = qobject_cast<MainWindow*>(w))
if(auto *r = qobject_cast<MainWindow*>(w))
{
if(root)
return nullptr;
Expand All @@ -1172,7 +1167,7 @@ void Application::waitForTSL( const QString &file )
p.setWindowFlags( (Qt::Dialog | Qt::CustomizeWindowHint | Qt::MSWindowsFixedSizeDialogHint ) & ~Qt::WindowTitleHint );
p.setWindowModality(Qt::WindowModal);
p.setFixedSize( p.size() );
if( QProgressBar *bar = p.findChild<QProgressBar*>() )
if(auto *bar = p.findChild<QProgressBar*>())
bar->setTextVisible( false );
p.setMinimumWidth( 300 );
p.setRange( 0, 100 );
Expand All @@ -1182,9 +1177,9 @@ void Application::waitForTSL( const QString &file )
if(p.value() + 1 == p.maximum())
p.setValue(0);
p.setValue( p.value() + 1 );
t.start( 100 );
t.start(100ms);
});
t.start( 100 );
t.start(100ms);
QEventLoop e;
connect(this, &Application::TSLLoadingFinished, &e, &QEventLoop::quit);
if( !d->ready )
Expand Down
33 changes: 16 additions & 17 deletions client/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,47 +64,46 @@ class Application final: public Common
#endif
Configuration *conf();
void loadTranslation( const QString &lang );
QWidget* mainWindow();
bool notify(QObject *object, QEvent *event ) final;
void openHelp();
QSigner* signer() const;
int run();
void waitForTSL( const QString &file );

static void initDiagnosticConf();
static uint readTSLVersion(const QString &path);
static void addRecent( const QString &file );
static QVariant confValue(ConfParameter parameter, const QVariant &value = {});
static void clearConfValue( ConfParameter parameter );
static void initDiagnosticConf();
static QWidget* mainWindow();
static void openHelp();
static uint readTSLVersion(const QString &path);
static void setConfValue( ConfParameter parameter, const QVariant &value );

public Q_SLOTS:
void showAbout();
void showSettings();
void showClient(const QStringList &params = {}, bool crypto = false, bool sign = false, bool newWindow = false);
void showWarning(const QString &msg, const QString &details = {});
static void showWarning(const QString &msg, const QString &details = {});

private Q_SLOTS:
void browse( const QUrl &url );
void closeWindow();
void mailTo( const QUrl &url );
void parseArgs(const QString &msg = {});
void parseArgs( const QStringList &args );
void showTSLWarning( QEventLoop *e );
void parseArgs(const QStringList &args);
static void browse(const QUrl &url);
static void mailTo(const QUrl &url);
static void showAbout();
static void showSettings();
static void showTSLWarning( QEventLoop *e );

Q_SIGNALS:
void TSLLoadingFinished();

private:
void activate( QWidget *w );
bool event(QEvent *event) final;
void migrateSettings();
static void closeWindow();
static void migrateSettings();
static void showWarning(const QString &msg, const digidoc::Exception &e);
QWidget* uniqueRoot();

static QWidget* uniqueRoot();
#if defined(Q_OS_MAC)
void initMacEvents();
void deinitMacEvents();
static void initMacEvents();
static void deinitMacEvents();
#endif

static const QStringList CONTAINER_EXT;
Expand Down
8 changes: 4 additions & 4 deletions client/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@
<source>Caught exception!</source>
<translation>Caught exception!</translation>
</message>
<message>
<source>New Crypto window</source>
<translation>New Crypto window</translation>
</message>
<message>
<source>The renewal of Trust Service status List, used for digital signature validation, has failed. Please check your internet connection and make sure you have the latest ID-software version installed. An expired Trust Service List (TSL) will be used for signature validation. &lt;a href=&quot;https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/&quot;&gt;Additional information&lt;/a&gt;</source>
<translation>The renewal of Trust Service status List, used for digital signature validation, has failed. Please check your internet connection and make sure you have the latest ID-software version installed. An expired Trust Service List (TSL) will be used for signature validation. &lt;a href=&quot;https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/&quot;&gt;Additional information&lt;/a&gt;</translation>
Expand Down Expand Up @@ -253,6 +249,10 @@
<source>https://www.id.ee/en/article/install-id-software/</source>
<translation>https://www.id.ee/en/article/install-id-software/</translation>
</message>
<message>
<source>https://www.id.ee/en/id-help/</source>
<translation>https://www.id.ee/en/id-help/</translation>
</message>
</context>
<context>
<name>CDocumentModel</name>
Expand Down
8 changes: 4 additions & 4 deletions client/translations/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@
<source>Caught exception!</source>
<translation>Tekkis viga!</translation>
</message>
<message>
<source>New Crypto window</source>
<translation>Ava uus Krüpto aken</translation>
</message>
<message>
<source>The renewal of Trust Service status List, used for digital signature validation, has failed. Please check your internet connection and make sure you have the latest ID-software version installed. An expired Trust Service List (TSL) will be used for signature validation. &lt;a href=&quot;https://www.id.ee/en/article/digidoc4-message-updating-the-list-of-trusted-certificates-was-unsuccessful/&quot;&gt;Additional information&lt;/a&gt;</source>
<translation>Digiallkirjade kehtivuse kontrollimiseks kasutatava sertifikaatide usaldusnimekirja uuendamine ebaõnnestus. Palun kontrolli oma arvuti internetiühendust ja seda, kas arvutis on kõige uuem ID-tarkvara versioon. Allkirjade verifitseerimiseks kasutatakse aegunud nimekirja. &lt;a href=&quot;https://www.id.ee/artikkel/digidoc4-teade-sertifikaatide-usaldusnimekirja-uuendamine-ebaonnestus/&quot;&gt;Lisainfo&lt;/a&gt;</translation>
Expand Down Expand Up @@ -253,6 +249,10 @@
<source>https://www.id.ee/en/article/install-id-software/</source>
<translation>https://www.id.ee/artikkel/paigalda-id-tarkvara/</translation>
</message>
<message>
<source>https://www.id.ee/en/id-help/</source>
<translation>https://www.id.ee/id-abikeskus/</translation>
</message>
</context>
<context>
<name>CDocumentModel</name>
Expand Down
Loading

0 comments on commit a35d33c

Please sign in to comment.