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
44 changes: 12 additions & 32 deletions client/CryptoDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include <QtCore/QFileInfo>
#include <QtCore/QRegularExpression>
#include <QtCore/QThread>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <QtGui/QDesktopServices>
#include <QtNetwork/QSslKey>
#include <QtWidgets/QMessageBox>

Expand Down Expand Up @@ -74,7 +71,6 @@ struct CryptoDoc::Private
QString fileName;
int version = -1;
CDocumentModel *documents = new CDocumentModel(this);
QStringList tempFiles;

// libcdoc handlers
DDConfiguration conf;
Expand Down Expand Up @@ -144,9 +140,9 @@ bool CDocumentModel::addFile(const QString &file, const QString &mime)
return true;
}

void CDocumentModel::addTempReference(const QString &file)
QString CDocumentModel::containerName() const
{
d->tempFiles.append(file);
return d->fileName;
}

QString CDocumentModel::copy(int row, const QString &dst) const
Expand Down Expand Up @@ -181,19 +177,8 @@ QString CDocumentModel::mime(int row) const

void CDocumentModel::open(int row)
{
if(d->isEncrypted())
return;
QString path = FileDialog::tempPath(FileDialog::safeName(data(row)));
if(!verifyFile(path))
return;
if(copy(row, path).isEmpty())
return;
d->tempFiles.append(path);
FileDialog::setReadOnly(path);
if(FileDialog::isSignedPDF(path))
Application::showClient({ std::move(path) }, false, false, true);
else
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
if(!d->isEncrypted())
DocumentModel::open(row);
}

bool CDocumentModel::removeRow(int row)
Expand All @@ -210,6 +195,7 @@ bool CDocumentModel::removeRow(int row)
return false;
}

removeTempFile(data(row));
d->files.erase(d->files.cbegin() + row);
return true;
}
Expand All @@ -223,10 +209,10 @@ QString CDocumentModel::save(int row, const QString &path) const
{
if(d->isEncrypted())
return {};

if(QFileInfo::exists(path))
return path;
QString fileName = copy(row, path);
QFileInfo f(fileName);
if(!f.exists())
if(!QFileInfo::exists(fileName))
return {};
FileDialog::setFileZone(fileName, d->fileName);
return fileName;
Expand Down Expand Up @@ -279,13 +265,7 @@ bool CryptoDoc::canDecrypt(const QSslCertificate &cert) {

void CryptoDoc::clear(const QString &file, int version)
{
for(const QString &f: qAsConst(d->tempFiles))
{
// reset read-only attribute to enable delete file
FileDialog::setReadOnly(f, false);
QFile::remove(f);
}
d->tempFiles.clear();
d->documents->clearTempFolder();
d->reader.reset();
d->files.clear();
d->fileName = file;
Expand Down Expand Up @@ -394,13 +374,13 @@ bool CryptoDoc::decrypt(const libcdoc::Lock *lock, const QByteArray& secret)
str = tr("Cannot read file.");
break;
case DDCryptoBackend::PIN_CANCELED:
str = tr("PIN entry canceled");
str = QCryptoBackend::tr("PIN Canceled");
break;
case DDCryptoBackend::PIN_INCORRECT:
str = tr("PIN incorrect");
str = QCryptoBackend::tr("PIN Incorrect");
break;
case DDCryptoBackend::PIN_LOCKED:
str = tr("PIN locked");
str = QCryptoBackend::tr("PIN locked");
break;
default:
str = tr("Please check your internet connection and network settings.");
Expand Down
2 changes: 1 addition & 1 deletion client/CryptoDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class CDocumentModel final: public DocumentModel
Q_OBJECT
public:
bool addFile(const QString &file, const QString &mime = QStringLiteral("application/octet-stream")) final;
void addTempReference(const QString &file) final;
QString data(int row) const final;
quint64 fileSize(int row) const final;
QString mime(int row) const final;
Expand All @@ -100,6 +99,7 @@ class CDocumentModel final: public DocumentModel
CDocumentModel(CryptoDoc::Private *doc);
Q_DISABLE_COPY(CDocumentModel)

QString containerName() const final;
QString copy(int row, const QString &dst) const;

CryptoDoc::Private *d;
Expand Down
54 changes: 14 additions & 40 deletions client/DigiDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <QtCore/QDateTime>
#include <QtCore/QFileInfo>
#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include <QtGui/QDesktopServices>
#include <QtWidgets/QMessageBox>

#include <algorithm>
Expand Down Expand Up @@ -313,9 +311,9 @@ bool SDocumentModel::addFile(const QString &file, const QString &mime)
return false;
}

void SDocumentModel::addTempReference(const QString &file)
QString SDocumentModel::containerName() const
{
doc->m_tempFiles.append(file);
return doc->fileName();
}

QString SDocumentModel::data(int row) const
Expand All @@ -342,30 +340,14 @@ QString SDocumentModel::mime(int row) const
return from(doc->b->dataFiles().at(size_t(row))->mediaType());
}

void SDocumentModel::open(int row)
{
if(row >= rowCount())
return;
QString path = FileDialog::tempPath(FileDialog::safeName(from(doc->b->dataFiles().at(size_t(row))->fileName())));
if(!verifyFile(path))
return;
if(!QFileInfo::exists(save(row, path)))
return;
doc->m_tempFiles.append(path);
FileDialog::setReadOnly(path);
if(!doc->fileName().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive) && FileDialog::isSignedPDF(path))
qApp->showClient({ std::move(path) }, false, false, true);
else
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}

bool SDocumentModel::removeRow(int row)
{
if(!doc->b)
return false;

try
{
removeTempFile(data(row));
doc->b->removeDataFile(unsigned(row));
doc->modified = true;
return true;
Expand All @@ -383,9 +365,11 @@ QString SDocumentModel::save(int row, const QString &path) const
{
if(row >= rowCount())
return {};

QFile::remove( path );
if(QFileInfo::exists(path))
return path;
doc->b->dataFiles().at(size_t(row))->saveAs(path.toStdString());
if(!QFileInfo::exists(path))
return {};
FileDialog::setFileZone(path, doc->fileName());
return path;
}
Expand Down Expand Up @@ -420,14 +404,7 @@ void DigiDoc::clear()
m_signatures.clear();
m_timestamps.clear();
m_fileName.clear();
for(const QString &file: m_tempFiles)
{
//reset read-only attribute to enable delete file
FileDialog::setReadOnly(file, false);
QFile::remove(file);
}

m_tempFiles.clear();
m_documentModel->clearTempFolder();
modified = false;
}

Expand Down Expand Up @@ -512,19 +489,17 @@ bool DigiDoc::open( const QString &file )
try {
WaitDialogHolder waitDialog(parent, tr("Opening"), false);
return waitFor([&] {
m_fileName = file;
b = Container::openPtr(to(file), &cb);
if(b && b->mediaType() == "application/vnd.etsi.asic-s+zip" &&
b->dataFiles().size() == 1 &&
b->signatures().size() == 1)
{
const DataFile *f = b->dataFiles().at(0);
if(from(f->fileName()).endsWith(QStringLiteral(".ddoc"), Qt::CaseInsensitive))
if(from(b->dataFiles().at(0)->fileName()).endsWith(QStringLiteral(".ddoc"), Qt::CaseInsensitive))
{
const QString tmppath = FileDialog::tempPath(FileDialog::safeName(from(f->fileName())));
f->saveAs(to(tmppath));
if(QFileInfo::exists(tmppath))
const QString tmppath = m_documentModel->saveTemp(0);
if(!tmppath.isEmpty())
{
m_tempFiles.append(tmppath);
try {
parentContainer = std::exchange(b, Container::openPtr(to(tmppath), &cb));
} catch(const Exception &) {}
Expand All @@ -540,7 +515,6 @@ bool DigiDoc::open( const QString &file )
m_timestamps.append(DigiDocSignature(signature, this));
}
Application::addRecent(file);
m_fileName = file;
containerState = signatures().isEmpty() ? ContainerState::UnsignedSavedContainer : ContainerState::SignedContainer;
return true;
});
Expand Down Expand Up @@ -672,7 +646,7 @@ void DigiDoc::setLastError(const QString &title, const Exception &e)
case Exception::PINFailed:
dlg->withText(tr("PIN Login failed")); break;
case Exception::PINIncorrect:
dlg->withText(tr("PIN Incorrect")); break;
dlg->withText(QCryptoBackend::tr("PIN Incorrect")); break;
case Exception::PINLocked:
dlg->withText(tr("PIN Locked. Unblock to reuse PIN.")); break;
case Exception::NetworkError:
Expand Down Expand Up @@ -721,7 +695,7 @@ bool DigiDoc::sign(const QString &city, const QString &state, const QString &zip
case Exception::PINIncorrect:
WarningDialog::create()
->withTitle(tr("Failed to sign container"))
->withText(tr("PIN Incorrect"))
->withText(QCryptoBackend::tr("PIN Incorrect"))
->exec();
return sign(city, state, zip, country, role, signer);
case Exception::InvalidUrl:
Expand Down
5 changes: 2 additions & 3 deletions client/DigiDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ class SDocumentModel final: public DocumentModel

public:
bool addFile(const QString &file, const QString &mime = QStringLiteral("application/octet-stream")) final;
void addTempReference(const QString &file) final;
QString data(int row) const final;
quint64 fileSize(int row) const final;
QString mime(int row) const final;
void open(int row) final;
bool removeRow(int row) final;
int rowCount() const final;
QString save(int row, const QString &path) const final;
Expand All @@ -106,6 +104,8 @@ class SDocumentModel final: public DocumentModel
SDocumentModel(DigiDoc *container);
Q_DISABLE_COPY(SDocumentModel)

QString containerName() const final;

DigiDoc *doc;
friend class DigiDoc;
};
Expand Down Expand Up @@ -159,7 +159,6 @@ class DigiDoc: public QObject
QList<DigiDocSignature> m_signatures, m_timestamps;
bool modified = false;
QString m_fileName;
QStringList m_tempFiles;

friend class DigiDocSignature;
friend class SDocumentModel;
Expand Down
Loading
Loading