Skip to content

Commit

Permalink
Dont delay widget deletion and cleanup code (open-eid#1140)
Browse files Browse the repository at this point in the history
IB-7583

Signed-off-by: Raul Metsma <[email protected]>

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Dec 19, 2022
1 parent 76de835 commit e8fae17
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 73 deletions.
4 changes: 2 additions & 2 deletions client/dialogs/AddRecipients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ AddRecipients::AddRecipients(ItemList* itemList, QWidget *parent)
setWindowFlags( Qt::Dialog | Qt::CustomizeWindowHint );
new Overlay(this, parent->topLevelWidget());

ui->leftPane->init(ria::qdigidoc4::ToAddAdresses, QStringLiteral("Add recipients"));
ui->leftPane->init(ria::qdigidoc4::ToAddAdresses, QT_TRANSLATE_NOOP("ItemList", "Add recipients"));
ui->leftPane->setFont(Styles::font(Styles::Regular, 20));
ui->rightPane->init(ria::qdigidoc4::AddedAdresses, QStringLiteral("Added recipients"));
ui->rightPane->init(ria::qdigidoc4::AddedAdresses, QT_TRANSLATE_NOOP("ItemList", "Added recipients"));
ui->rightPane->setFont(Styles::font(Styles::Regular, 20));

ui->fromCard->setFont(Styles::font(Styles::Condensed, 12));
Expand Down
20 changes: 10 additions & 10 deletions client/widgets/ContainerPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void ContainerPage::setHeader(const QString &file)
elideFileName();
}

void ContainerPage::showRightPane(ItemType itemType, const QString &header)
void ContainerPage::showRightPane(ItemType itemType, const char *header)
{
ui->rightPane->init(itemType, header);
ui->rightPane->show();
Expand Down Expand Up @@ -323,7 +323,7 @@ void ContainerPage::transition(DigiDoc* container)

if(!container->timestamps().isEmpty())
{
ui->rightPane->addHeader(QStringLiteral("Container timestamps"));
ui->rightPane->addHeader(QT_TRANSLATE_NOOP("ItemList", "Container timestamps"));

for(const DigiDocSignature &c: container->timestamps())
{
Expand Down Expand Up @@ -404,7 +404,7 @@ void ContainerPage::updatePanes(ContainerState state)
ui->changeLocation->show();
ui->rightPane->clear();
hideRightPane();
ui->leftPane->init(fileName, QStringLiteral("Container files"));
ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Container files"));
showSigningButton();
setButtonsVisible({ ui->cancel, ui->convert, ui->save }, true);
setButtonsVisible({ ui->saveAs, ui->email, ui->summary }, false);
Expand All @@ -413,20 +413,20 @@ void ContainerPage::updatePanes(ContainerState state)
cancelText = QT_TR_NOOP("STARTING");

ui->changeLocation->show();
ui->leftPane->init(fileName, QStringLiteral("Container files"));
ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Container files"));
if( showPrintSummary )
setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email, ui->summary }, true);
else
setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email }, true);
setButtonsVisible({ ui->save }, false);
showRightPane( ItemSignature, QStringLiteral("Container is not signed"));
showRightPane( ItemSignature, QT_TRANSLATE_NOOP("ItemList", "Container is not signed"));
break;
case SignedContainer:
cancelText = QT_TR_NOOP("STARTING");

ui->changeLocation->hide();
ui->leftPane->init(fileName, QStringLiteral("Container files"));
showRightPane(ItemSignature, QStringLiteral("Container signatures"));
ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Container files"));
showRightPane(ItemSignature, QT_TRANSLATE_NOOP("ItemList", "Container signatures"));
if( showPrintSummary )
setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email, ui->summary }, true);
else
Expand All @@ -439,7 +439,7 @@ void ContainerPage::updatePanes(ContainerState state)

ui->changeLocation->show();
ui->leftPane->init(fileName);
showRightPane(ItemAddress, QStringLiteral("Recipients"));
showRightPane(ItemAddress, QT_TRANSLATE_NOOP("ItemList", "Recipients"));
showMainAction({ EncryptContainer });
setButtonsVisible({ ui->cancel, ui->convert }, true);
setButtonsVisible({ ui->save, ui->saveAs, ui->email, ui->summary }, false);
Expand All @@ -449,8 +449,8 @@ void ContainerPage::updatePanes(ContainerState state)
convertText = QT_TR_NOOP("SIGN");

ui->changeLocation->hide();
ui->leftPane->init(fileName, QStringLiteral("Encrypted files"));
showRightPane(ItemAddress, QStringLiteral("Recipients"));
ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Encrypted files"));
showRightPane(ItemAddress, QT_TRANSLATE_NOOP("ItemList", "Recipients"));
updateDecryptionButton();
setButtonsVisible({ ui->save, ui->summary }, false);
setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email }, true);
Expand Down
2 changes: 1 addition & 1 deletion client/widgets/ContainerPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ContainerPage final : public QWidget
void hideRightPane();
void initContainer( const QString &file, const QString &suffix );
void showMainAction(const QList<ria::qdigidoc4::Actions> &actions);
void showRightPane(ria::qdigidoc4::ItemType itemType, const QString &header);
void showRightPane(ria::qdigidoc4::ItemType itemType, const char *header);
void showSigningButton();
void updateDecryptionButton();
void updatePanes(ria::qdigidoc4::ContainerState state);
Expand Down
29 changes: 4 additions & 25 deletions client/widgets/FileList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,12 @@ void FileList::addFile( const QString& file )
updateDownload();
}

void FileList::changeEvent(QEvent* event)
{
ItemList::changeEvent(event);
if(!ui->count->isHidden())
ui->count->setText(QString::number(count()));
}

void FileList::clear()
{
ItemList::clear();
documentModel = nullptr;
}

int FileList::count() const
{
return findChildren<FileItem*>().size();
}

bool FileList::eventFilter(QObject *obj, QEvent *event)
{
if(!qobject_cast<FileItem*>(obj))
Expand Down Expand Up @@ -121,26 +109,18 @@ bool FileList::eventFilter(QObject *obj, QEvent *event)
return ItemList::eventFilter(obj, event);
}

void FileList::init(const QString &container, const QString &label)
void FileList::init(const QString &container, const char *label)
{
ItemList::init(ItemFile, label);
this->container = container;
}

void FileList::open(FileItem *item) const
{
int i;
if(documentModel && (i = index(item)) != -1)
if(int i = index(item); documentModel && i != -1)
documentModel->open(i);
}

void FileList::remove(Item *item)
{
int i;
if(documentModel && (i = index(item)) != -1)
emit removed(i);
}

void FileList::removeItem(int row)
{
ItemList::removeItem(row);
Expand All @@ -150,8 +130,7 @@ void FileList::removeItem(int row)

void FileList::save(FileItem *item)
{
int i;
if(documentModel && (i = index(item)) != -1)
if(int i = index(item); documentModel && i != -1)
{
QString extension = QFileInfo(item->getFile()).suffix();
QString capitalized = extension[0].toUpper() + extension.mid(1);
Expand Down Expand Up @@ -247,7 +226,7 @@ void FileList::stateChange(ria::qdigidoc4::ContainerState state)

void FileList::updateDownload()
{
int c = count();
int c = findChildren<FileItem*>().size();
ui->download->setVisible(state & (UnsignedSavedContainer | SignedContainer | UnencryptedContainer) && c);
ui->count->setVisible(state & (UnsignedSavedContainer | SignedContainer | UnencryptedContainer) && c);
ui->count->setText(QString::number(c));
Expand Down
20 changes: 8 additions & 12 deletions client/widgets/FileList.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,30 @@

class QLabel;

class FileList : public ItemList
class FileList final : public ItemList
{
Q_OBJECT

public:
explicit FileList(QWidget *parent = nullptr);

void addFile(const QString& file);
void clear() override;
void init(const QString &container, const QString &label = "Container's files");
void removeItem(int row) override;
void clear() final;
void init(const QString &container,
const char *label = QT_TRANSLATE_NOOP("ItemList", "Container files"));
void removeItem(int row) final;
void setModel(DocumentModel *documentModel);
void stateChange(ria::qdigidoc4::ContainerState state) override;
void stateChange(ria::qdigidoc4::ContainerState state) final;

signals:
void addFiles(const QStringList &files);

private slots:
private:
void open(FileItem *item) const;
void save(FileItem *item);
void saveAll();

private:
void changeEvent(QEvent* event) override;
int count() const;
bool eventFilter(QObject *obj, QEvent *event) override;
bool eventFilter(QObject *obj, QEvent *event) final;
void selectFile();
void remove(Item *item) override;
void updateDownload();

QString container;
Expand Down
29 changes: 10 additions & 19 deletions client/widgets/ItemList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ ItemList::~ItemList()
delete ui;
}

void ItemList::addHeader(const QString &label)
void ItemList::addHeader(const char *label)
{
headerText = label;

header = new QLabel(tr(qPrintable(label)), this);
header = new QLabel(tr(label), this);
header->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
header->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
header->setFocusPolicy(Qt::TabFocus);
Expand Down Expand Up @@ -110,22 +110,14 @@ void ItemList::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
{
tr("Add recipients");
tr("Added recipients");
tr("Recipients");
tr("Encrypted files");
tr("Container is not signed");
tr("Container signatures");
tr("Container timestamps");
tr("Container files");
ui->retranslateUi(this);

ui->listHeader->setText(tr(qPrintable(listText)));
ui->listHeader->setText(tr(listText));
ui->txtFind->setPlaceholderText(tr("Enter the personal code, institution or registry code"));
ui->txtFind->setAccessibleName(ui->txtFind->placeholderText());

if(header)
header->setText(tr(qPrintable(headerText)));
header->setText(tr(headerText));

ui->add->setText(addLabel());

Expand All @@ -146,7 +138,7 @@ void ItemList::clear()
header = nullptr;

for(auto it = items.begin(); it != items.end(); it = items.erase(it))
(*it)->deleteLater();
delete *it;
}

bool ItemList::eventFilter(QObject *o, QEvent *e)
Expand Down Expand Up @@ -176,11 +168,11 @@ bool ItemList::hasItem(const std::function<bool(Item* const)> &cb)
return std::any_of(items.cbegin(), items.cend(), cb);
}

void ItemList::init(ItemType item, const QString &header)
void ItemList::init(ItemType item, const char *header)
{
itemType = item;
ui->listHeader->setText(tr(qPrintable(header)));
ui->listHeader->setAccessibleName(tr(qPrintable(header)));
ui->listHeader->setText(tr(header));
ui->listHeader->setAccessibleName(tr(header));
listText = header;
ui->listHeader->setFont( Styles::font(Styles::Regular, 20));

Expand Down Expand Up @@ -234,15 +226,14 @@ void ItemList::init(ItemType item, const QString &header)

void ItemList::remove(Item *item)
{
int i = index(item);
if(i != -1)
if(int i = index(item); i != -1)
emit removed(i);
}

void ItemList::removeItem(int row)
{
if(row < items.size())
items.takeAt(row)->deleteLater();
delete items.takeAt(row);
}

void ItemList::setRecipientTooltip()
Expand Down
8 changes: 4 additions & 4 deletions client/widgets/ItemList.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ItemList : public QScrollArea
explicit ItemList(QWidget *parent = {});
~ItemList() override;

void init(ria::qdigidoc4::ItemType itemType, const QString &header);
void addHeader(const QString &label);
void init(ria::qdigidoc4::ItemType itemType, const char *header);
void addHeader(const char *label);
void addHeaderWidget(Item *widget);
void addWidget(Item *widget);
virtual void clear();
Expand Down Expand Up @@ -78,8 +78,8 @@ class ItemList : public QScrollArea
QList<Item*> items;
QLabel *header = nullptr;
ria::qdigidoc4::ItemType itemType = ria::qdigidoc4::ItemAddress;
QString headerText;
QString listText;
const char *headerText = "";
const char *listText = "";
SslCertificate cert;

friend class AddRecipients;
Expand Down

0 comments on commit e8fae17

Please sign in to comment.