Skip to content

Commit

Permalink
Build dialog before showing
Browse files Browse the repository at this point in the history
IB-7840

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Dec 11, 2023
1 parent 4384a8c commit b135c78
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 51 deletions.
5 changes: 3 additions & 2 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ Application::Application( int &argc, char **argv )
#ifdef Q_OS_MAC
if(!Settings::PLUGINS.isSet())
{
auto *dlg = WarningDialog::show(tr(
"In order to authenticate and sign in e-services with an ID-card you need to install the web browser components."));
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."), mainWindow());
dlg->setCancelText(tr("Ignore forever").toUpper());
dlg->addButton(tr("Remind later").toUpper(), QMessageBox::Ignore);
dlg->addButton(tr("Install").toUpper(), QMessageBox::Open);
Expand All @@ -473,6 +473,7 @@ Application::Application( int &argc, char **argv )
default: Settings::PLUGINS = QStringLiteral("ignore");
}
});
dlg->open();
}
#endif
if(Settings::SHOW_INTRO)
Expand Down
18 changes: 8 additions & 10 deletions client/DocumentModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ void DocumentModel::addTempFiles(const QStringList &files)
QStringList DocumentModel::tempFiles() const
{
QStringList copied;
int rows = rowCount();
for(int i = 0; i < rows; ++i)
for(int i = 0, rows = rowCount(); i < rows; ++i)
{
QFileInfo f(save(i, FileDialog::tempPath(data(i))));
if(f.exists())
if(QFileInfo f(save(i, FileDialog::tempPath(data(i)))); f.exists())
copied.append(f.absoluteFilePath());
}
return copied;
Expand All @@ -59,10 +57,10 @@ bool DocumentModel::verifyFile(const QString &f)
QStringLiteral("gif"), QStringLiteral("ico"), QStringLiteral("ps"), QStringLiteral("psd"), QStringLiteral("tif"), QStringLiteral("tiff"), QStringLiteral("csv")};

QJsonArray allowedExts = Application::confValue(QLatin1String("ALLOWED-EXTENSIONS")).toArray(defaultArray);
if(!allowedExts.contains(QJsonValue(QFileInfo(f).suffix().toLower()))){
WarningDialog::show(tr("A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it."))->setCancelText(WarningDialog::OK);
return false;
}

return true;
if(allowedExts.contains(QJsonValue(QFileInfo(f).suffix().toLower())))
return true;
auto *dlg = new WarningDialog(tr("A file with this extension cannot be opened in the DigiDoc4 Client. Download the file to view it."));
dlg->setCancelText(WarningDialog::OK);
dlg->open();
return false;
}
10 changes: 6 additions & 4 deletions client/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ void MainWindow::removeSignature(int index)
if(!digiDoc)
return;
WaitDialogHolder waitDialog(this, tr("Removing signature"));
digiDoc->removeSignature(index);
digiDoc->removeSignature(unsigned(index));
save();
ui->signContainerPage->transition(digiDoc);
adjustDrops();
Expand Down Expand Up @@ -1030,15 +1030,17 @@ bool MainWindow::validateFiles(const QString &container, const QStringList &file
if(std::none_of(files.cbegin(), files.cend(),
[containerInfo] (const QString &file) { return containerInfo == QFileInfo(file); }))
return true;
WarningDialog::show(this, tr("Cannot add container to same container\n%1")
.arg(FileDialog::normalized(container)))->setCancelText(WarningDialog::Cancel);
auto *dlg = new WarningDialog(tr("Cannot add container to same container\n%1")
.arg(FileDialog::normalized(container)), this);
dlg->setCancelText(WarningDialog::Cancel);
dlg->open();
return false;
}

void MainWindow::warningClicked(const QString &link)
{
if(link == QLatin1String("#unblock-PIN1"))
ui->accordion->changePin1Clicked (false, true);
ui->accordion->changePin1Clicked(false, true);
else if(link == QLatin1String("#unblock-PIN2"))
ui->accordion->changePin2Clicked (false, true);
else if(link.startsWith(QLatin1String("http")))
Expand Down
11 changes: 1 addition & 10 deletions client/common_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

#pragma once

namespace ria {
namespace qdigidoc4 {
namespace ria::qdigidoc4 {

enum ContainerState {
Uninitialized = (1 << 0),
Expand All @@ -37,8 +36,6 @@ enum ContainerState {
};

enum Actions {
AddressAdd,

ContainerCancel,
ContainerConvert,
ContainerEncrypt,
Expand All @@ -53,15 +50,10 @@ enum Actions {
DecryptContainer,
DecryptToken,

FileAdd,
FileRemove,

SignatureAdd,
SignatureMobile,
SignatureSmartID,
SignatureToken,
SignatureRemove,
SignatureWarning,
ClearSignatureWarning
};

Expand Down Expand Up @@ -101,4 +93,3 @@ enum WarningType {
};

}
}
2 changes: 1 addition & 1 deletion client/widgets/AddressItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon)

ui->remove->setIcons(QStringLiteral("/images/icon_remove.svg"), QStringLiteral("/images/icon_remove_hover.svg"),
QStringLiteral("/images/icon_remove_pressed.svg"), 17, 17);
ui->remove->init(LabelButton::White, {}, 0);
ui->remove->init(LabelButton::White);
connect(ui->add, &QToolButton::clicked, this, [this]{ emit add(this);});
connect(ui->remove, &LabelButton::clicked, this, [this]{ emit remove(this);});

Expand Down
4 changes: 2 additions & 2 deletions client/widgets/FileItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ FileItem::FileItem(QString file, ContainerState state, QWidget *parent)
ui->setupUi(this);
ui->fileName->setFont(Styles::font(Styles::Regular, 14));
ui->download->setIcons(QStringLiteral("/images/icon_download.svg"), QStringLiteral("/images/icon_download_hover.svg"), QStringLiteral("/images/icon_download_pressed.svg"), 17, 17);
ui->download->init(LabelButton::White, {}, 0);
ui->download->init(LabelButton::White);
ui->remove->setIcons(QStringLiteral("/images/icon_remove.svg"), QStringLiteral("/images/icon_remove_hover.svg"), QStringLiteral("/images/icon_remove_pressed.svg"), 17, 17);
ui->remove->init(LabelButton::White, {}, 0);
ui->remove->init(LabelButton::White);

stateChange(state);

Expand Down
2 changes: 1 addition & 1 deletion client/widgets/FileList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FileList::FileList(QWidget *parent)
{
ui->download->setIcons(QStringLiteral("/images/icon_download.svg"), QStringLiteral("/images/icon_download_hover.svg"),
QStringLiteral("/images/icon_download_pressed.svg"), 17, 17);
ui->download->init(LabelButton::White, QString(), 0);
ui->download->init(LabelButton::White);
ui->download->installEventFilter(
new ButtonHoverFilter(QStringLiteral(":/images/icon_download.svg"), QStringLiteral(":/images/icon_download_hover.svg"), this));
connect(ui->add, &LabelButton::clicked, this, &FileList::selectFile);
Expand Down
2 changes: 1 addition & 1 deletion client/widgets/ItemList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void ItemList::init(ItemType item, const char *header)
}
else
{
ui->add->init(LabelButton::DeepCeruleanWithLochmara, addLabel(), itemType == ItemFile ? FileAdd : AddressAdd);
ui->add->init(LabelButton::DeepCeruleanWithLochmara, addLabel());
ui->add->setFont(Styles::font(Styles::Condensed, 12));
}

Expand Down
2 changes: 1 addition & 1 deletion client/widgets/LabelButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class LabelButton : public QToolButton

explicit LabelButton(QWidget *parent = nullptr);

void init( Style style, const QString &label, int code );
void init(Style style, const QString &label = {}, int code = 0);
void setIcons(const QString &normalIcon, const QString &hoverIcon, const QString &pressedIcon, int w, int h);

signals:
Expand Down
33 changes: 15 additions & 18 deletions client/widgets/SignatureItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QtGui/QFontMetrics>
#include <QtGui/QKeyEvent>
#include <QtGui/QTextDocument>
#include <QtWidgets/QMessageBox>
#include <QSvgWidget>

using namespace ria::qdigidoc4;
Expand Down Expand Up @@ -62,9 +63,21 @@ SignatureItem::SignatureItem(DigiDocSignature s, ContainerState /*state*/, QWidg
ui->role->installEventFilter(this);
ui->remove->setIcons(QStringLiteral("/images/icon_remove.svg"), QStringLiteral("/images/icon_remove_hover.svg"),
QStringLiteral("/images/icon_remove_pressed.svg"), 17, 17);
ui->remove->init(LabelButton::White, {}, 0);
ui->remove->init(LabelButton::White);
ui->remove->setVisible(ui->signature.container()->isSupported());
connect(ui->remove, &LabelButton::clicked, this, &SignatureItem::removeSignature);
connect(ui->remove, &LabelButton::clicked, this, [this]{
const SslCertificate c = ui->signature.cert();
auto *dlg = new WarningDialog(tr("Remove signature %1?")
.arg(c.toString(c.showCN() ? QStringLiteral("CN serialNumber") : QStringLiteral("GN SN serialNumber"))), this);
dlg->setCancelText(WarningDialog::Cancel);
dlg->resetCancelStyle();
dlg->addButton(WarningDialog::OK, QMessageBox::Ok, true);
connect(dlg, &WarningDialog::finished, this, [this](int result) {
if(result == QMessageBox::Ok)
emit remove(this);
});
dlg->open();
});
init();
}

Expand Down Expand Up @@ -194,22 +207,6 @@ QWidget* SignatureItem::lastTabWidget()
return ui->remove;
}

void SignatureItem::removeSignature()
{
const SslCertificate c = ui->signature.cert();
QString msg = tr("Remove signature %1?")
.arg(c.toString(c.showCN() ? QStringLiteral("CN serialNumber") : QStringLiteral("GN SN serialNumber")));

auto *dlg = WarningDialog::show(this, msg);
dlg->setCancelText(WarningDialog::Cancel);
dlg->resetCancelStyle();
dlg->addButton(WarningDialog::OK, SignatureRemove, true);
connect(dlg, &WarningDialog::finished, this, [this](int result) {
if(result == SignatureRemove)
emit remove(this);
});
}

void SignatureItem::updateNameField()
{
QTextDocument doc;
Expand Down
1 change: 0 additions & 1 deletion client/widgets/SignatureItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SignatureItem final : public Item
bool event(QEvent *event) final;
bool eventFilter(QObject *o, QEvent *e) final;
void init();
void removeSignature();
void updateNameField();

class Private;
Expand Down
3 changes: 3 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Build-Depends:
libldap2-dev,
libpcsclite-dev,
libssl-dev,
libflatbuffers-dev,
flatbuffers-compiler-dev,
zlib1g-dev,
qt6-tools-dev | qttools5-dev,
qt6-l10n-tools | qttools5-dev-tools,
libqt6svg6-dev | libqt5svg5-dev
Expand Down

0 comments on commit b135c78

Please sign in to comment.