Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvarjolintu <sami.vanttinen@protonmail.com>2021-11-25 20:47:45 +0300
committerJonathan White <support@dmapps.us>2021-12-12 16:14:14 +0300
commit12d16f67ae433c066d29541c9576633ab222cd6d (patch)
treee826eccf33dd909d59f7927da616f4591f33ec4b /src
parentd16fc2d62a6bf75f9aadd545ec0d4bc40ec554e5 (diff)
Download favicon in the background after credential add
Diffstat (limited to 'src')
-rw-r--r--src/browser/BrowserAction.cpp4
-rw-r--r--src/browser/BrowserService.cpp5
-rw-r--r--src/browser/BrowserService.h1
-rw-r--r--src/gui/DatabaseWidget.cpp21
-rw-r--r--src/gui/DatabaseWidget.h5
-rw-r--r--src/gui/IconDownloaderDialog.cpp24
-rw-r--r--src/gui/IconDownloaderDialog.h3
7 files changed, 53 insertions, 10 deletions
diff --git a/src/browser/BrowserAction.cpp b/src/browser/BrowserAction.cpp
index c84248469..3f7665797 100644
--- a/src/browser/BrowserAction.cpp
+++ b/src/browser/BrowserAction.cpp
@@ -364,11 +364,13 @@ QJsonObject BrowserAction::handleSetLogin(const QJsonObject& json, const QString
const QString uuid = decrypted.value("uuid").toString();
const QString group = decrypted.value("group").toString();
const QString groupUuid = decrypted.value("groupUuid").toString();
+ const QString downloadFavicon = decrypted.value("downloadFavicon").toString();
const QString realm;
bool result = true;
if (uuid.isEmpty()) {
- browserService()->addEntry(id, login, password, url, submitUrl, realm, group, groupUuid);
+ auto dlFavicon = !downloadFavicon.isEmpty() && downloadFavicon.compare(TRUE_STR) == 0;
+ browserService()->addEntry(id, login, password, url, submitUrl, realm, group, groupUuid, dlFavicon);
} else {
if (!Tools::isValidUuid(uuid)) {
return getErrorReply(action, ERROR_KEEPASS_NO_VALID_UUID_PROVIDED);
diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp
index 46de0a9d3..b4b2f98f3 100644
--- a/src/browser/BrowserService.cpp
+++ b/src/browser/BrowserService.cpp
@@ -494,6 +494,7 @@ void BrowserService::addEntry(const QString& dbid,
const QString& realm,
const QString& group,
const QString& groupUuid,
+ const bool downloadFavicon,
const QSharedPointer<Database>& selectedDb)
{
// TODO: select database based on this key id
@@ -537,6 +538,10 @@ void BrowserService::addEntry(const QString& dbid,
config.setRealm(realm);
}
config.save(entry);
+
+ if (downloadFavicon && m_currentDatabaseWidget) {
+ m_currentDatabaseWidget->downloadFaviconInBackground(entry);
+ }
}
bool BrowserService::updateEntry(const QString& dbid,
diff --git a/src/browser/BrowserService.h b/src/browser/BrowserService.h
index 829f3b108..111fe9d78 100644
--- a/src/browser/BrowserService.h
+++ b/src/browser/BrowserService.h
@@ -67,6 +67,7 @@ public:
const QString& realm,
const QString& group,
const QString& groupUuid,
+ const bool downloadFavicon,
const QSharedPointer<Database>& selectedDb = {});
bool updateEntry(const QString& dbid,
const QString& uuid,
diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp
index 4e8011a92..2caacb7a0 100644
--- a/src/gui/DatabaseWidget.cpp
+++ b/src/gui/DatabaseWidget.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
+ * Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -794,15 +794,30 @@ void DatabaseWidget::downloadAllFavicons()
#endif
}
-void DatabaseWidget::performIconDownloads(const QList<Entry*>& entries, bool force)
+void DatabaseWidget::downloadFaviconInBackground(Entry* entry)
+{
+#ifdef WITH_XC_NETWORKING
+ performIconDownloads({entry}, true, true);
+#else
+ Q_UNUSED(entry);
+#endif
+}
+
+void DatabaseWidget::performIconDownloads(const QList<Entry*>& entries, bool force, bool downloadInBackground)
{
#ifdef WITH_XC_NETWORKING
auto* iconDownloaderDialog = new IconDownloaderDialog(this);
connect(this, SIGNAL(databaseLockRequested()), iconDownloaderDialog, SLOT(close()));
- iconDownloaderDialog->downloadFavicons(m_db, entries, force);
+
+ if (downloadInBackground && entries.count() > 0) {
+ iconDownloaderDialog->downloadFaviconInBackground(m_db, entries.first());
+ } else {
+ iconDownloaderDialog->downloadFavicons(m_db, entries, force);
+ }
#else
Q_UNUSED(entries);
Q_UNUSED(force);
+ Q_UNUSED(downloadInBackground);
#endif
}
diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h
index c329b98fa..f804d0518 100644
--- a/src/gui/DatabaseWidget.h
+++ b/src/gui/DatabaseWidget.h
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
+ * Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -193,6 +193,7 @@ public slots:
void openUrl();
void downloadSelectedFavicons();
void downloadAllFavicons();
+ void downloadFaviconInBackground(Entry* entry);
void openUrlForEntry(Entry* entry);
void createGroup();
void cloneGroup();
@@ -259,7 +260,7 @@ private:
void setClipboardTextAndMinimize(const QString& text);
void processAutoOpen();
void openDatabaseFromEntry(const Entry* entry, bool inBackground = true);
- void performIconDownloads(const QList<Entry*>& entries, bool force = false);
+ void performIconDownloads(const QList<Entry*>& entries, bool force = false, bool downloadInBackground = false);
bool performSave(QString& errorMessage, const QString& fileName = {});
QSharedPointer<Database> m_db;
diff --git a/src/gui/IconDownloaderDialog.cpp b/src/gui/IconDownloaderDialog.cpp
index ffb849bb8..929146bd3 100644
--- a/src/gui/IconDownloaderDialog.cpp
+++ b/src/gui/IconDownloaderDialog.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
+ * Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -102,6 +102,23 @@ void IconDownloaderDialog::downloadFavicons(const QSharedPointer<Database>& data
}
}
+void IconDownloaderDialog::downloadFaviconInBackground(const QSharedPointer<Database>& database, Entry* entry)
+{
+ m_db = database;
+ m_urlToEntries.clear();
+ abortDownloads();
+
+ auto webUrl = entry->webUrl();
+ if (!webUrl.isEmpty()) {
+ m_urlToEntries.insert(webUrl, entry);
+ }
+
+ if (m_urlToEntries.count() > 0) {
+ m_activeDownloaders.append(createDownloader(webUrl));
+ m_activeDownloaders.first()->download();
+ }
+}
+
IconDownloader* IconDownloaderDialog::createDownloader(const QString& url)
{
auto downloader = new IconDownloader();
@@ -131,9 +148,10 @@ void IconDownloaderDialog::downloadFinished(const QString& url, const QImage& ic
if (m_db && !icon.isNull()) {
// Don't add an icon larger than 128x128, but retain original size if smaller
+ constexpr auto maxIconSize = 128;
auto scaledIcon = icon;
- if (icon.width() > 128 || icon.height() > 128) {
- scaledIcon = icon.scaled(128, 128);
+ if (icon.width() > maxIconSize || icon.height() > maxIconSize) {
+ scaledIcon = icon.scaled(maxIconSize, maxIconSize);
}
QByteArray serializedIcon = Icons::saveToBytes(scaledIcon);
diff --git a/src/gui/IconDownloaderDialog.h b/src/gui/IconDownloaderDialog.h
index e0a77070f..32f18bf23 100644
--- a/src/gui/IconDownloaderDialog.h
+++ b/src/gui/IconDownloaderDialog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 KeePassXC Team <team@keepassxc.org>
+ * Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -42,6 +42,7 @@ public:
~IconDownloaderDialog() override;
void downloadFavicons(const QSharedPointer<Database>& database, const QList<Entry*>& entries, bool force = false);
+ void downloadFaviconInBackground(const QSharedPointer<Database>& database, Entry* entry);
private slots:
void downloadFinished(const QString& url, const QImage& icon);