Add error message from opening database

This commit is contained in:
Stefan Forstenlechner 2024-06-19 13:59:55 +02:00
parent c908081421
commit 85ed0e0f70
3 changed files with 11 additions and 10 deletions

View File

@ -2446,7 +2446,7 @@ The command has to exit. In case of `sftp` as last command `exit` has to be sent
<translation type="unfinished"></translation>
</message>
<message>
<source>Download finished, but file failed KeePass header check. File is not a KeePass file or it&apos;s an unsupported version</source>
<source>Downloaded file is not a KeePass file or it&apos;s an unsupported version: %1</source>
<translation type="unfinished"></translation>
</message>
<message>

View File

@ -187,12 +187,12 @@ void DatabaseSettingsWidgetRemote::testDownload()
params->downloadInput = m_ui->inputForDownload->toPlainText();
params->downloadTimeoutMsec = m_ui->downloadTimeoutSec->value() * 1000;
QScopedPointer<RemoteHandler> remoteHandler(new RemoteHandler(this));
if (params->downloadCommand.isEmpty()) {
m_ui->messageWidget->showMessage(tr("Download command cannot be empty."), MessageWidget::Warning);
return;
}
QScopedPointer<RemoteHandler> remoteHandler(new RemoteHandler(this));
RemoteHandler::RemoteResult result = remoteHandler->download(params);
if (!result.success) {
m_ui->messageWidget->showMessage(tr("Download failed with error: %1").arg(result.errorMessage),
@ -206,19 +206,20 @@ void DatabaseSettingsWidgetRemote::testDownload()
return;
}
if (!hasValidPublicHeaders(result.filePath)) {
m_ui->messageWidget->showMessage(tr("Download finished, but file failed KeePass header check. File is not a "
"KeePass file or it's an unsupported version"),
MessageWidget::Error);
QString error;
if (!hasValidPublicHeader(result.filePath, &error)) {
m_ui->messageWidget->showMessage(
tr("Downloaded file is not a KeePass file or it's an unsupported version: %1").arg(error),
MessageWidget::Error);
return;
}
m_ui->messageWidget->showMessage(tr("Download successful."), MessageWidget::Positive);
}
bool DatabaseSettingsWidgetRemote::hasValidPublicHeaders(QString& filePath) {
bool DatabaseSettingsWidgetRemote::hasValidPublicHeader(QString& filePath, QString* error)
{
// Read public headers
QString error;
QScopedPointer<Database> db(new Database());
return db->open(filePath, nullptr, &error);
return db->open(filePath, nullptr, error);
}

View File

@ -56,7 +56,7 @@ private:
QListWidgetItem* findItemByName(const QString& name);
void clearFields();
bool hasValidPublicHeaders(QString& filePath);
bool hasValidPublicHeader(QString& filePath, QString* error);
QScopedPointer<RemoteSettings> m_remoteSettings;
const QScopedPointer<Ui::DatabaseSettingsWidgetRemote> m_ui;