mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-27 01:56:32 -05:00
Multiple fixes to custom icon downloading
* Fixes #904, icons are saved at or below 128x128 * Fixes #403, crash occurs due to dialog on non-gui thread * Fixes #232, icon hashes calculated and compared against
This commit is contained in:
parent
2e4f1a21b4
commit
cb0b948603
4 changed files with 64 additions and 24 deletions
|
|
@ -68,7 +68,7 @@ EditWidgetIcons::EditWidgetIcons(QWidget* parent)
|
|||
this, SLOT(updateWidgetsDefaultIcons(bool)));
|
||||
connect(m_ui->customIconsRadio, SIGNAL(toggled(bool)),
|
||||
this, SLOT(updateWidgetsCustomIcons(bool)));
|
||||
connect(m_ui->addButton, SIGNAL(clicked()), SLOT(addCustomIcon()));
|
||||
connect(m_ui->addButton, SIGNAL(clicked()), SLOT(addCustomIconFromFile()));
|
||||
connect(m_ui->deleteButton, SIGNAL(clicked()), SLOT(removeCustomIcon()));
|
||||
connect(m_ui->faviconButton, SIGNAL(clicked()), SLOT(downloadFavicon()));
|
||||
|
||||
|
|
@ -185,15 +185,7 @@ void EditWidgetIcons::fetchFavicon(const QUrl& url)
|
|||
image.loadFromData(response->collectedData());
|
||||
|
||||
if (!image.isNull()) {
|
||||
//Set the image
|
||||
Uuid uuid = Uuid::random();
|
||||
m_database->metadata()->addCustomIcon(uuid, image.scaled(16, 16));
|
||||
m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(),
|
||||
m_database->metadata()->customIconsOrder());
|
||||
QModelIndex index = m_customIconModel->indexFromUuid(uuid);
|
||||
m_ui->customIconsView->setCurrentIndex(index);
|
||||
m_ui->customIconsRadio->setChecked(true);
|
||||
|
||||
addCustomIcon(image);
|
||||
resetFaviconDownload();
|
||||
} else {
|
||||
fetchFaviconFromGoogle(url.host());
|
||||
|
|
@ -226,7 +218,9 @@ void EditWidgetIcons::fetchFavicon(const QUrl& url)
|
|||
QUrl tempurl = QUrl(m_url);
|
||||
if (tempurl.scheme() == "http") {
|
||||
resetFaviconDownload();
|
||||
MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon.") + "\n" + tr("Hint: You can enable Google as a fallback under Tools>Settings>Security"));
|
||||
emit messageEditEntry(tr("Unable to fetch favicon.") + "\n" +
|
||||
tr("Hint: You can enable Google as a fallback under Tools>Settings>Security"),
|
||||
MessageWidget::Error);
|
||||
} else {
|
||||
tempurl.setScheme("http");
|
||||
m_url = tempurl.url();
|
||||
|
|
@ -248,7 +242,7 @@ void EditWidgetIcons::fetchFaviconFromGoogle(const QString& domain)
|
|||
fetchFavicon(faviconUrl);
|
||||
} else {
|
||||
resetFaviconDownload();
|
||||
MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon."));
|
||||
emit messageEditEntry(tr("Unable to fetch favicon."), MessageWidget::Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,7 +263,7 @@ void EditWidgetIcons::resetFaviconDownload(bool clearRedirect)
|
|||
}
|
||||
#endif
|
||||
|
||||
void EditWidgetIcons::addCustomIcon()
|
||||
void EditWidgetIcons::addCustomIconFromFile()
|
||||
{
|
||||
if (m_database) {
|
||||
QString filter = QString("%1 (%2);;%3 (*)").arg(tr("Images"),
|
||||
|
|
@ -278,22 +272,41 @@ void EditWidgetIcons::addCustomIcon()
|
|||
QString filename = QFileDialog::getOpenFileName(
|
||||
this, tr("Select Image"), "", filter);
|
||||
if (!filename.isEmpty()) {
|
||||
QImage image(filename);
|
||||
if (!image.isNull()) {
|
||||
Uuid uuid = Uuid::random();
|
||||
m_database->metadata()->addCustomIcon(uuid, image.scaled(16, 16));
|
||||
m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(),
|
||||
m_database->metadata()->customIconsOrder());
|
||||
QModelIndex index = m_customIconModel->indexFromUuid(uuid);
|
||||
m_ui->customIconsView->setCurrentIndex(index);
|
||||
}
|
||||
else {
|
||||
auto icon = QImage(filename);
|
||||
if (!icon.isNull()) {
|
||||
addCustomIcon(QImage(filename));
|
||||
} else {
|
||||
emit messageEditEntry(tr("Can't read icon"), MessageWidget::Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditWidgetIcons::addCustomIcon(const QImage &icon)
|
||||
{
|
||||
if (m_database) {
|
||||
Uuid uuid = m_database->metadata()->findCustomIcon(icon);
|
||||
if (uuid.isNull()) {
|
||||
uuid = Uuid::random();
|
||||
// Don't add an icon larger than 128x128, but retain original size if smaller
|
||||
if (icon.width() > 128 || icon.height() > 128) {
|
||||
m_database->metadata()->addCustomIcon(uuid, icon.scaled(128, 128));
|
||||
} else {
|
||||
m_database->metadata()->addCustomIcon(uuid, icon);
|
||||
}
|
||||
|
||||
m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(),
|
||||
m_database->metadata()->customIconsOrder());
|
||||
} else {
|
||||
emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information);
|
||||
}
|
||||
|
||||
// Select the new or existing icon
|
||||
QModelIndex index = m_customIconModel->indexFromUuid(uuid);
|
||||
m_ui->customIconsView->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void EditWidgetIcons::removeCustomIcon()
|
||||
{
|
||||
if (m_database) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ private slots:
|
|||
void fetchFaviconFromGoogle(const QString& domain);
|
||||
void resetFaviconDownload(bool clearRedirect = true);
|
||||
#endif
|
||||
void addCustomIcon();
|
||||
void addCustomIconFromFile();
|
||||
void addCustomIcon(const QImage& icon);
|
||||
void removeCustomIcon();
|
||||
void updateWidgetsDefaultIcons(bool checked);
|
||||
void updateWidgetsCustomIcons(bool checked);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue