Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ void Application::showClient(QStringList files, bool crypto, bool sign, bool new
QMetaObject::invokeMethod(w, [&] {
using enum ria::qdigidoc4::Pages;
w->selectPage(crypto && !sign ? CryptoIntro : SignIntro);
w->openFiles(files, false, sign);
w->openFiles(std::move(files), false, sign);
});
}

Expand Down
1 change: 0 additions & 1 deletion client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
LdapSearch.cpp
LdapSearch.h
MainWindow.cpp
MainWindow_MyEID.cpp
MainWindow.h
MainWindow.ui
PrintSheet.cpp
Expand Down
16 changes: 2 additions & 14 deletions client/CryptoDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,16 @@ bool CDocumentModel::addFile(const QString &file, const QString &mime)
return false;

QFileInfo info(file);
if(info.size() == 0)
{
WarningDialog::show(DocumentModel::tr("Cannot add empty file to the container."));
if(!addFileCheck(d->fileName, info))
return false;
}

if(d->cdoc->version() == 1 && info.size() > 120*1024*1024)
{
WarningDialog::show(tr("Added file(s) exceeds the maximum size limit of the container (∼120MB). "
"<a href='https://www.id.ee/en/article/encrypting-large-120-mb-files/'>Read more about it</a>"));
return false;
}

QString fileName(info.fileName());
if(std::any_of(d->cdoc->files.cbegin(), d->cdoc->files.cend(),
[&fileName](const auto &containerFile) { return containerFile.name == fileName; }))
{
WarningDialog::show(DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.")
.arg(FileDialog::normalized(fileName)));
return false;
}

auto data = std::make_unique<QFile>(file);
if(!data->open(QFile::ReadOnly))
return false;
Expand Down Expand Up @@ -196,7 +185,6 @@ bool CDocumentModel::removeRow(int row)
}

d->cdoc->files.erase(d->cdoc->files.cbegin() + row);
emit removed(row);
return true;
}

Expand Down
15 changes: 1 addition & 14 deletions client/DigiDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,26 +289,14 @@ SDocumentModel::SDocumentModel(DigiDoc *container)
bool SDocumentModel::addFile(const QString &file, const QString &mime)
{
QFileInfo info(file);
if(info.size() == 0)
{
WarningDialog::show(DocumentModel::tr("Cannot add empty file to the container."));
if(!addFileCheck(doc->fileName(), info))
return false;
}
QString fileName(info.fileName());
if(fileName == QStringLiteral("mimetype"))
{
WarningDialog::show(DocumentModel::tr("Cannot add file with name 'mimetype' to the envelope."));
return false;
}
for(int row = 0; row < rowCount(); row++)
{
if(fileName == from(doc->b->dataFiles().at(size_t(row))->fileName()))
{
WarningDialog::show(DocumentModel::tr("Cannot add the file to the envelope. File '%1' is already in container.")
.arg(FileDialog::normalized(fileName)));
return false;
}
}
if(doc->addFile(file, mime))
{
emit added(FileDialog::normalized(fileName));
Expand Down Expand Up @@ -372,7 +360,6 @@ bool SDocumentModel::removeRow(int row)
{
doc->b->removeDataFile(unsigned(row));
doc->modified = true;
emit removed(row);
return true;
}
catch( const Exception &e ) { DigiDoc::setLastError(tr("Failed remove document from container"), e); }
Expand Down
31 changes: 31 additions & 0 deletions client/DocumentModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@
#include <QtCore/QFileInfo>
#include <QtCore/QProcessEnvironment>

bool DocumentModel::addFileCheck(const QString &container, QFileInfo file)
{
// Check that container is not dropped into itself
if(QFileInfo(container) == file)
{
auto *dlg = new WarningDialog(tr("Cannot add container to same container\n%1")
.arg(FileDialog::normalized(container)));
dlg->setCancelText(WarningDialog::Cancel);
dlg->open();
return false;
}

if(file.size() == 0)
{
WarningDialog::show(tr("Cannot add empty file to the container."));
return false;
}
QString fileName = file.fileName();
for(int row = 0; row < rowCount(); row++)
{
if(fileName == data(row))
{
WarningDialog::show(tr("Cannot add the file to the envelope. File '%1' is already in container.")
.arg(FileDialog::normalized(fileName)));
return false;
}
}

return true;
}

void DocumentModel::addTempFiles(const QStringList &files)
{
for(const QString &file: files)
Expand Down
4 changes: 3 additions & 1 deletion client/DocumentModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <QObject>

class QFileInfo;

class DocumentModel: public QObject
{
Q_OBJECT
Expand All @@ -40,8 +42,8 @@ class DocumentModel: public QObject

signals:
void added(const QString &file);
void removed(int row);

protected:
bool addFileCheck(const QString &container, QFileInfo file);
static bool verifyFile(const QString &f);
};
Loading
Loading