Add favicon fetch button next to entry's url edit textbox (#2439)

When WITH_XC_NETWORKING is defined, create a QToolButton beside the Edit Entry -> Entry -> URL, which when pressed, acts as though the Edit Entry -> Icon -> Download Favicon button is pressed.  This button is disabled (grayed-out) when the URL text is empty, and enabled when the text is present.

Fixes #936

* Add favicon download button 
* Remove the progress dialog that appears when
downloading an entry's URL's favicon since (when working correctly) it disappears before it can be read. When downloading icons from the button
located next to the URL text box, display a message panel that confirms the download was a success.

* Do not show successful icon download msg if icon alread exists
This commit is contained in:
Kyle Kneitinger authored and Jonathan White committed 2018-11-24 17:30:55 -05:00
1 parent 3c362ac822
commit a90a577ee1
9 files changed
+44 -46

No files matched your search

+3 -31
View File
@@ -39,25 +39,6 @@ IconStruct::IconStruct()
{
}
UrlFetchProgressDialog::UrlFetchProgressDialog(const QUrl &url, QWidget *parent)
: QProgressDialog(parent)
{
setWindowTitle(tr("Download Progress"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setLabelText(tr("Downloading %1.").arg(url.toDisplayString()));
setMinimumDuration(0);
setMinimumSize(QSize(400, 75));
}
void UrlFetchProgressDialog::networkReplyProgress(qint64 bytesRead, qint64 totalBytes)
{
if (totalBytes > 0) {
setValue(static_cast<int>(bytesRead / totalBytes));
} else {
setValue(0);
}
}
EditWidgetIcons::EditWidgetIcons(QWidget* parent)
: QWidget(parent)
, m_ui(new Ui::EditWidgetIcons())
@@ -268,14 +249,14 @@ void EditWidgetIcons::fetchFinished()
// No redirect, and we theoretically have some icon data now.
image.loadFromData(m_bytesReceived);
}
} else {
UrlFetchProgressDialog *progress = findChild<UrlFetchProgressDialog *>(url.toString());
progress->close();
}
if (!image.isNull()) {
if (!addCustomIcon(image)) {
emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information);
} else if (!this->isVisible()) {
// Show confirmation message if triggered from Entry tab download button
emit messageEditEntry(tr("Custom icon successfully downloaded"), MessageWidget::Positive);
}
} else if (!m_urlsToTry.empty()) {
m_redirects = 0;
@@ -316,15 +297,6 @@ void EditWidgetIcons::startFetchFavicon(const QUrl& url)
m_reply = m_netMgr.get(request);
connect(m_reply, &QNetworkReply::finished, this, &EditWidgetIcons::fetchFinished);
connect(m_reply, &QIODevice::readyRead, this, &EditWidgetIcons::fetchReadyRead);
UrlFetchProgressDialog *progress = new UrlFetchProgressDialog(url, this);
progress->setObjectName(url.toString());
progress->setAttribute(Qt::WA_DeleteOnClose);
connect(m_reply, &QNetworkReply::finished, progress, &QProgressDialog::hide);
connect(m_reply, &QNetworkReply::downloadProgress, progress, &UrlFetchProgressDialog::networkReplyProgress);
connect(progress, &QProgressDialog::canceled, this, &EditWidgetIcons::fetchCanceled);
progress->show();
#else
Q_UNUSED(url);
#endif