From b07d4efe5fefe0d03e409ad948eaad653d862fff Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Wed, 30 May 2018 22:23:39 -0400 Subject: [PATCH 1/3] Allow multiple image selections when adding favicons --- src/gui/EditWidgetIcons.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index 4292234e..73af7bf7 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -325,13 +325,15 @@ void EditWidgetIcons::addCustomIconFromFile() if (m_database) { QString filter = QString("%1 (%2);;%3 (*)").arg(tr("Images"), Tools::imageReaderFilter(), tr("All files")); - QString filename = QFileDialog::getOpenFileName(this, tr("Select Image"), "", filter); - if (!filename.isEmpty()) { - auto icon = QImage(filename); - if (!icon.isNull()) { - addCustomIcon(QImage(filename)); - } else { - emit messageEditEntry(tr("Can't read icon"), MessageWidget::Error); + auto filenames = QFileDialog::getOpenFileNames(this, tr("Select Image(s)"), "", filter); + for (const auto& filename : filenames) { + if (!filename.isEmpty()) { + auto icon = QImage(filename); + if (!icon.isNull()) { + addCustomIcon(QImage(filename)); + } else { + emit messageEditEntry(tr("Can't read icon"), MessageWidget::Error); + } } } } From 2e292699b75b79b0221e9cc5b4672a4263c6405f Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 3 Jun 2018 12:42:33 -0400 Subject: [PATCH 2/3] Add more comprehensive messages when adding custom icons * Error messages now display for 15 seconds and are closable * Add button is always enabled --- src/gui/EditWidget.cpp | 10 ++++- src/gui/EditWidgetIcons.cpp | 75 ++++++++++++++++++++++++++----------- src/gui/EditWidgetIcons.h | 2 +- 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/src/gui/EditWidget.cpp b/src/gui/EditWidget.cpp index ce80c03b..a58cc6d8 100644 --- a/src/gui/EditWidget.cpp +++ b/src/gui/EditWidget.cpp @@ -125,8 +125,14 @@ void EditWidget::enableApplyButton(bool enabled) void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type) { - m_ui->messageWidget->setCloseButtonVisible(false); - m_ui->messageWidget->showMessage(text, type, 2000); + // Show error messages for a longer time to make sure the user can read them + if (type == MessageWidget::Error) { + m_ui->messageWidget->setCloseButtonVisible(true); + m_ui->messageWidget->showMessage(text, type, 15000); + } else { + m_ui->messageWidget->setCloseButtonVisible(false); + m_ui->messageWidget->showMessage(text, type, 2000); + } } void EditWidget::hideMessage() diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index 73af7bf7..8ec85f92 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -93,6 +93,7 @@ EditWidgetIcons::EditWidgetIcons(QWidget* parent) SIGNAL(widgetUpdated())); m_ui->faviconButton->setVisible(false); + m_ui->addButton->setEnabled(true); } EditWidgetIcons::~EditWidgetIcons() @@ -269,7 +270,9 @@ void EditWidgetIcons::fetchFinished() } if (!image.isNull()) { - addCustomIcon(image); + if (!addCustomIcon(image)) { + emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information); + } } else if (!m_urlsToTry.empty()) { m_redirects = 0; startFetchFavicon(m_urlsToTry.takeFirst()); @@ -326,36 +329,66 @@ void EditWidgetIcons::addCustomIconFromFile() QString filter = QString("%1 (%2);;%3 (*)").arg(tr("Images"), Tools::imageReaderFilter(), tr("All files")); auto filenames = QFileDialog::getOpenFileNames(this, tr("Select Image(s)"), "", filter); - for (const auto& filename : filenames) { - if (!filename.isEmpty()) { - auto icon = QImage(filename); - if (!icon.isNull()) { - addCustomIcon(QImage(filename)); - } else { - emit messageEditEntry(tr("Can't read icon"), MessageWidget::Error); + if (!filenames.empty()) { + QStringList errornames; + int numexisting = 0; + for (const auto& filename : filenames) { + if (!filename.isEmpty()) { + auto icon = QImage(filename); + if (!icon.isNull()) { + if (!addCustomIcon(QImage(filename))) { + ++numexisting; + } + } else { + errornames << filename; + } } } + + int numloaded = filenames.size() - errornames.size() - numexisting; + QString msg; + + if (numloaded > 0) { + msg = tr("Successfully loaded %1 of %2 icons").arg(numloaded).arg(filenames.size()); + } else { + msg = tr("No icons were loaded"); + } + + if (numexisting > 0) { + msg += ", " + tr("%1 icons already existed").arg(numexisting); + } + + if (!errornames.empty()) { + // Show the first 8 icons that failed to load + errornames = errornames.mid(0, 8); + emit messageEditEntry(msg + "\n" + tr("The following icons failed:") + "\n" + errornames.join("\n"), + MessageWidget::Error); + } else if (numloaded > 0) { + emit messageEditEntry(msg, MessageWidget::Positive); + } else { + emit messageEditEntry(msg, MessageWidget::Information); + } } } } -void EditWidgetIcons::addCustomIcon(const QImage& icon) +bool EditWidgetIcons::addCustomIcon(const QImage& icon) { + bool added = false; if (m_database) { - Uuid uuid = m_database->metadata()->findCustomIcon(icon); + // Don't add an icon larger than 128x128, but retain original size if smaller + auto scaledicon = icon; + if (icon.width() > 128 || icon.height() > 128) { + scaledicon = icon.scaled(128, 128); + } + + Uuid uuid = m_database->metadata()->findCustomIcon(scaledicon); 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_database->metadata()->addCustomIcon(uuid, scaledicon); m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(), m_database->metadata()->customIconsOrder()); - } else { - emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information); + added = true; } // Select the new or existing icon @@ -365,6 +398,8 @@ void EditWidgetIcons::addCustomIcon(const QImage& icon) emit widgetUpdated(); } + + return added; } void EditWidgetIcons::removeCustomIcon() @@ -461,7 +496,6 @@ void EditWidgetIcons::updateWidgetsDefaultIcons(bool check) m_ui->defaultIconsView->setCurrentIndex(index); } m_ui->customIconsView->selectionModel()->clearSelection(); - m_ui->addButton->setEnabled(false); m_ui->deleteButton->setEnabled(false); } } @@ -476,7 +510,6 @@ void EditWidgetIcons::updateWidgetsCustomIcons(bool check) m_ui->customIconsView->setCurrentIndex(index); } m_ui->defaultIconsView->selectionModel()->clearSelection(); - m_ui->addButton->setEnabled(true); m_ui->deleteButton->setEnabled(true); } } diff --git a/src/gui/EditWidgetIcons.h b/src/gui/EditWidgetIcons.h index 94630157..e01ae4b1 100644 --- a/src/gui/EditWidgetIcons.h +++ b/src/gui/EditWidgetIcons.h @@ -88,7 +88,7 @@ private slots: void fetchReadyRead(); void fetchCanceled(); void addCustomIconFromFile(); - void addCustomIcon(const QImage& icon); + bool addCustomIcon(const QImage& icon); void removeCustomIcon(); void updateWidgetsDefaultIcons(bool checked); void updateWidgetsCustomIcons(bool checked); From 76102ee9f0fb02797c334de22870c079f1acf5a6 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 9 Jun 2018 16:56:52 -0400 Subject: [PATCH 3/3] Correct plurals and logic gate --- src/gui/EditWidgetIcons.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index 8ec85f92..982b02d9 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -335,12 +335,11 @@ void EditWidgetIcons::addCustomIconFromFile() for (const auto& filename : filenames) { if (!filename.isEmpty()) { auto icon = QImage(filename); - if (!icon.isNull()) { - if (!addCustomIcon(QImage(filename))) { - ++numexisting; - } - } else { + if (icon.isNull()) { errornames << filename; + } else if (!addCustomIcon(icon)) { + // Icon already exists in database + ++numexisting; } } } @@ -349,20 +348,20 @@ void EditWidgetIcons::addCustomIconFromFile() QString msg; if (numloaded > 0) { - msg = tr("Successfully loaded %1 of %2 icons").arg(numloaded).arg(filenames.size()); + msg = tr("Successfully loaded %1 of %n icon(s)", "", filenames.size()).arg(numloaded); } else { msg = tr("No icons were loaded"); } if (numexisting > 0) { - msg += ", " + tr("%1 icons already existed").arg(numexisting); + msg += "\n" + tr("%n icon(s) already exist in the database", "", numexisting); } if (!errornames.empty()) { // Show the first 8 icons that failed to load errornames = errornames.mid(0, 8); - emit messageEditEntry(msg + "\n" + tr("The following icons failed:") + "\n" + errornames.join("\n"), - MessageWidget::Error); + emit messageEditEntry(msg + "\n" + tr("The following icon(s) failed:", "", errornames.size()) + + "\n" + errornames.join("\n"), MessageWidget::Error); } else if (numloaded > 0) { emit messageEditEntry(msg, MessageWidget::Positive); } else {