Skip to content

Commit 4408306

Browse files
committed
Cleanup warning handling
IB-8462 Signed-off-by: Raul Metsma <[email protected]>
1 parent 01676a9 commit 4408306

19 files changed

+221
-326
lines changed

client/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
6565
LdapSearch.cpp
6666
LdapSearch.h
6767
MainWindow.cpp
68-
MainWindow_MyEID.cpp
6968
MainWindow.h
7069
MainWindow.ui
7170
PrintSheet.cpp

client/CryptoDoc.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,16 @@ bool CDocumentModel::addFile(const QString &file, const QString &mime)
100100
return false;
101101

102102
QFileInfo info(file);
103-
if(info.size() == 0)
104-
{
105-
WarningDialog::show(DocumentModel::tr("Cannot add empty file to the container."));
103+
if(!addFileCheck(d->fileName, info))
106104
return false;
107-
}
105+
108106
if(d->cdoc->version() == 1 && info.size() > 120*1024*1024)
109107
{
110108
WarningDialog::show(tr("Added file(s) exceeds the maximum size limit of the container (∼120MB). "
111109
"<a href='https://www.id.ee/en/article/encrypting-large-120-mb-files/'>Read more about it</a>"));
112110
return false;
113111
}
114112

115-
QString fileName(info.fileName());
116-
if(std::any_of(d->cdoc->files.cbegin(), d->cdoc->files.cend(),
117-
[&fileName](const auto &containerFile) { return containerFile.name == fileName; }))
118-
{
119-
WarningDialog::show(DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.")
120-
.arg(FileDialog::normalized(fileName)));
121-
return false;
122-
}
123-
124113
auto data = std::make_unique<QFile>(file);
125114
if(!data->open(QFile::ReadOnly))
126115
return false;
@@ -196,7 +185,6 @@ bool CDocumentModel::removeRow(int row)
196185
}
197186

198187
d->cdoc->files.erase(d->cdoc->files.cbegin() + row);
199-
emit removed(row);
200188
return true;
201189
}
202190

client/DigiDoc.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,26 +289,14 @@ SDocumentModel::SDocumentModel(DigiDoc *container)
289289
bool SDocumentModel::addFile(const QString &file, const QString &mime)
290290
{
291291
QFileInfo info(file);
292-
if(info.size() == 0)
293-
{
294-
WarningDialog::show(DocumentModel::tr("Cannot add empty file to the container."));
292+
if(!addFileCheck(doc->fileName(), info))
295293
return false;
296-
}
297294
QString fileName(info.fileName());
298295
if(fileName == QStringLiteral("mimetype"))
299296
{
300297
WarningDialog::show(DocumentModel::tr("Cannot add file with name 'mimetype' to the envelope."));
301298
return false;
302299
}
303-
for(int row = 0; row < rowCount(); row++)
304-
{
305-
if(fileName == from(doc->b->dataFiles().at(size_t(row))->fileName()))
306-
{
307-
WarningDialog::show(DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.")
308-
.arg(FileDialog::normalized(fileName)));
309-
return false;
310-
}
311-
}
312300
if(doc->addFile(file, mime))
313301
{
314302
emit added(FileDialog::normalized(fileName));
@@ -372,7 +360,6 @@ bool SDocumentModel::removeRow(int row)
372360
{
373361
doc->b->removeDataFile(unsigned(row));
374362
doc->modified = true;
375-
emit removed(row);
376363
return true;
377364
}
378365
catch( const Exception &e ) { DigiDoc::setLastError(tr("Failed remove document from container"), e); }

client/DocumentModel.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@
2727
#include <QtCore/QFileInfo>
2828
#include <QtCore/QProcessEnvironment>
2929

30+
bool DocumentModel::addFileCheck(const QString &container, QFileInfo file)
31+
{
32+
// Check that container is not dropped into itself
33+
if(QFileInfo(container) == file)
34+
{
35+
auto *dlg = new WarningDialog(tr("Cannot add container to same container\n%1")
36+
.arg(FileDialog::normalized(container)));
37+
dlg->setCancelText(WarningDialog::Cancel);
38+
dlg->open();
39+
return false;
40+
}
41+
42+
if(file.size() == 0)
43+
{
44+
WarningDialog::show(tr("Cannot add empty file to the container."));
45+
return false;
46+
}
47+
QString fileName = file.fileName();
48+
for(int row = 0; row < rowCount(); row++)
49+
{
50+
if(fileName == data(row))
51+
{
52+
WarningDialog::show(tr("Cannot add the file to the envelope. File '%1' is already in container.")
53+
.arg(FileDialog::normalized(fileName)));
54+
return false;
55+
}
56+
}
57+
58+
return true;
59+
}
60+
3061
void DocumentModel::addTempFiles(const QStringList &files)
3162
{
3263
for(const QString &file: files)

client/DocumentModel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <QObject>
2222

23+
class QFileInfo;
24+
2325
class DocumentModel: public QObject
2426
{
2527
Q_OBJECT
@@ -40,8 +42,8 @@ class DocumentModel: public QObject
4042

4143
signals:
4244
void added(const QString &file);
43-
void removed(int row);
4445

4546
protected:
47+
bool addFileCheck(const QString &container, QFileInfo file);
4648
static bool verifyFile(const QString &f);
4749
};

0 commit comments

Comments
 (0)