Skip to content

Commit

Permalink
Add error message from opening database
Browse files Browse the repository at this point in the history
  • Loading branch information
t-h-e committed Jun 19, 2024
1 parent 695b550 commit 7753774
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2369,7 +2369,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>
</context>
Expand Down
19 changes: 10 additions & 9 deletions src/gui/remote/DatabaseSettingsWidgetRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ void DatabaseSettingsWidgetRemote::testDownload()
params->downloadCommand = m_ui->downloadCommand->text();
params->downloadInput = m_ui->inputForDownload->toPlainText();

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),
Expand All @@ -197,19 +197,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);
}
2 changes: 1 addition & 1 deletion src/gui/remote/DatabaseSettingsWidgetRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private slots:
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;
Expand Down

0 comments on commit 7753774

Please sign in to comment.