Skip to content

Commit

Permalink
Add favicon fetch button next to entry's url edit textbox (keepassxre…
Browse files Browse the repository at this point in the history
…boot#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 keepassxreboot#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
  • Loading branch information
kneitinger authored and droidmonkey committed Nov 24, 2018
1 parent 3c362ac commit a90a577
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 46 deletions.
6 changes: 6 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ Copyright: 2003-2004, David Vignoni <[email protected]>
License: LGPL-2.1
Comment: based on Nuvola icon theme

Files: share/icons/application/*/actions/favicon-download.png
Copyright: 2003-2004, David Vignoni <[email protected]>
2018, Kyle Kneitinger <[email protected]>
License: LGPL-2.1
Comment: based on Nuvola icon theme

Files: share/icons/application/*/actions/application-exit.png
share/icons/application/*/actions/chronometer.png
share/icons/application/*/actions/configure.png
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 3 additions & 31 deletions src/gui/EditWidgetIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions src/gui/EditWidgetIcons.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define KEEPASSX_EDITWIDGETICONS_H

#include <QSet>
#include <QProgressDialog>
#include <QUrl>
#include <QWidget>
#include <QNetworkAccessManager>
Expand Down Expand Up @@ -50,17 +49,6 @@ struct IconStruct
int number;
};

class UrlFetchProgressDialog : public QProgressDialog
{
Q_OBJECT

public:
explicit UrlFetchProgressDialog(const QUrl &url, QWidget *parent = nullptr);

public slots:
void networkReplyProgress(qint64 bytesRead, qint64 totalBytes);
};

class EditWidgetIcons : public QWidget
{
Q_OBJECT
Expand Down
21 changes: 21 additions & 0 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,19 @@ void EditEntryWidget::setupMain()

m_mainUi->togglePasswordButton->setIcon(filePath()->onOffIcon("actions", "password-show"));
m_mainUi->togglePasswordGeneratorButton->setIcon(filePath()->icon("actions", "password-generator"));
#ifdef WITH_XC_NETWORKING
m_mainUi->fetchFaviconButton->setIcon(filePath()->icon("actions", "favicon-download"));
m_mainUi->fetchFaviconButton->setDisabled(true);
#else
m_mainUi->fetchFaviconButton->setVisible(false);
#endif


connect(m_mainUi->togglePasswordButton, SIGNAL(toggled(bool)), m_mainUi->passwordEdit, SLOT(setShowPassword(bool)));
connect(m_mainUi->togglePasswordGeneratorButton, SIGNAL(toggled(bool)), SLOT(togglePasswordGeneratorButton(bool)));
#ifdef WITH_XC_NETWORKING
connect(m_mainUi->fetchFaviconButton, SIGNAL(clicked()), m_iconsWidget, SLOT(downloadFavicon()));
#endif
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
connect(m_mainUi->notesEnabled, SIGNAL(toggled(bool)), this, SLOT(toggleHideNotes(bool)));
m_mainUi->passwordRepeatEdit->enableVerifyMode(m_mainUi->passwordEdit);
Expand Down Expand Up @@ -241,6 +252,9 @@ void EditEntryWidget::setupEntryUpdate()
connect(m_mainUi->passwordEdit, SIGNAL(textChanged(QString)), this, SLOT(setUnsavedChanges()));
connect(m_mainUi->passwordRepeatEdit, SIGNAL(textChanged(QString)), this, SLOT(setUnsavedChanges()));
connect(m_mainUi->urlEdit, SIGNAL(textChanged(QString)), this, SLOT(setUnsavedChanges()));
#ifdef WITH_XC_NETWORKING
connect(m_mainUi->urlEdit, SIGNAL(textChanged(const QString&)), this, SLOT(updateFaviconButtonEnable(const QString&)));
#endif
connect(m_mainUi->expireCheck, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
connect(m_mainUi->notesEnabled, SIGNAL(stateChanged(int)), this, SLOT(setUnsavedChanges()));
connect(m_mainUi->expireDatePicker, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setUnsavedChanges()));
Expand Down Expand Up @@ -995,6 +1009,13 @@ void EditEntryWidget::setGeneratedPassword(const QString& password)
m_mainUi->togglePasswordGeneratorButton->setChecked(false);
}

#ifdef WITH_XC_NETWORKING
void EditEntryWidget::updateFaviconButtonEnable(const QString& url)
{
m_mainUi->fetchFaviconButton->setDisabled(url.isEmpty());
}
#endif

void EditEntryWidget::insertAttribute()
{
Q_ASSERT(!m_history);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/entry/EditEntryWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private slots:
void cancel();
void togglePasswordGeneratorButton(bool checked);
void setGeneratedPassword(const QString& password);
#ifdef WITH_XC_NETWORKING
void updateFaviconButtonEnable(const QString& url);
#endif
void insertAttribute();
void editCurrentAttribute();
void removeCurrentAttribute();
Expand Down
14 changes: 11 additions & 3 deletions src/gui/entry/EditEntryWidgetMain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLineEdit" name="urlEdit"/>
</item>
<item>
<widget class="QToolButton" name="fetchFaviconButton">
</widget>
</item>
</layout>
</item>
<item row="4" column="1">
<widget class="PasswordGeneratorWidget" name="passwordGenerator" native="true"/>
</item>
Expand Down Expand Up @@ -155,9 +166,6 @@
<item row="1" column="1">
<widget class="QLineEdit" name="usernameEdit"/>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="urlEdit"/>
</item>
<item row="7" column="0" alignment="Qt::AlignRight">
<widget class="QCheckBox" name="expireCheck">
<property name="text">
Expand Down

0 comments on commit a90a577

Please sign in to comment.