Skip to content

Commit

Permalink
Fix message showing and add timeout for favicon download
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed May 23, 2019
1 parent d88e382 commit 4c77859
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/gui/ApplicationSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)

connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
connect(m_secUi->downloadFaviconCheckBox, SIGNAL(toggled(bool)),
m_secUi->downloadFaviconSpinBox, SLOT(setEnabled(bool)));
connect(m_secUi->lockDatabaseIdleCheckBox, SIGNAL(toggled(bool)),
m_secUi->lockDatabaseIdleSpinBox, SLOT(setEnabled(bool)));
connect(m_secUi->touchIDResetCheckBox, SIGNAL(toggled(bool)),
Expand Down Expand Up @@ -203,6 +205,9 @@ void ApplicationSettingsWidget::loadSettings()
m_secUi->clearClipboardCheckBox->setChecked(config()->get("security/clearclipboard").toBool());
m_secUi->clearClipboardSpinBox->setValue(config()->get("security/clearclipboardtimeout").toInt());

m_secUi->downloadFaviconCheckBox->setChecked(config()->get("security/downloadFavicon").toBool());
m_secUi->downloadFaviconSpinBox->setValue(config()->get("security/downloadFaviconTimeout").toInt());

m_secUi->lockDatabaseIdleCheckBox->setChecked(config()->get("security/lockdatabaseidle").toBool());
m_secUi->lockDatabaseIdleSpinBox->setValue(config()->get("security/lockdatabaseidlesec").toInt());
m_secUi->lockDatabaseMinimizeCheckBox->setChecked(config()->get("security/lockdatabaseminimize").toBool());
Expand Down Expand Up @@ -282,6 +287,9 @@ void ApplicationSettingsWidget::saveSettings()
config()->set("security/clearclipboard", m_secUi->clearClipboardCheckBox->isChecked());
config()->set("security/clearclipboardtimeout", m_secUi->clearClipboardSpinBox->value());

config()->set("security/downloadFavicon", m_secUi->downloadFaviconCheckBox->isChecked());
config()->set("security/downloadFaviconTimeout", m_secUi->downloadFaviconSpinBox->value());

config()->set("security/lockdatabaseidle", m_secUi->lockDatabaseIdleCheckBox->isChecked());
config()->set("security/lockdatabaseidlesec", m_secUi->lockDatabaseIdleSpinBox->value());
config()->set("security/lockdatabaseminimize", m_secUi->lockDatabaseMinimizeCheckBox->isChecked());
Expand Down
32 changes: 32 additions & 0 deletions src/gui/ApplicationSettingsWidgetSecurity.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,38 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="downloadFaviconCheckBox">
<property name="text">
<string>Favicon download timeout</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="downloadFaviconSpinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string comment="Seconds"> sec</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>60</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="lockDatabaseIdleCheckBox">
<property name="sizePolicy">
Expand Down
9 changes: 3 additions & 6 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,11 @@ void DatabaseWidget::downloadFavicon()

auto* iconDownloader = new IconDownloaderDialog(this);
connect(iconDownloader, SIGNAL(entryUpdated()), SIGNAL(databaseModified()));
connect(iconDownloader,
SIGNAL(messageEditEntry(QString,MessageWidget::MessageType)),
SLOT(showMessage(QString,MessageWidget::MessageType)));

if (selectedEntries.count() == 1) {
connect(iconDownloader,
SIGNAL(messageEditEntry(QString,MessageWidget::MessageType)),
SLOT(showMessage(QString,MessageWidget::MessageType)));
iconDownloader->downloadFavicon(m_db, selectedEntries.first());
return;
}
Expand All @@ -706,9 +706,6 @@ void DatabaseWidget::downloadAllFavicons()

auto* iconDownloader = new IconDownloaderDialog(this);
connect(iconDownloader, SIGNAL(entryUpdated()), SIGNAL(databaseModified()));
connect(iconDownloader,
SIGNAL(messageEditEntry(QString,MessageWidget::MessageType)),
SLOT(showMessage(QString,MessageWidget::MessageType)));

Group* currentGroup = m_groupView->currentGroup();
Q_ASSERT(currentGroup);
Expand Down
10 changes: 2 additions & 8 deletions src/gui/DownloadIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ void DownloadIcon::downloadFavicon(Entry* entry)
// Use the first URL to start the download process
// If a favicon is not found, the next URL will be tried
startFetchFavicon(m_urlsToTry.takeFirst());
#else
Q_UNUSED(entry);
#endif
}

Expand Down Expand Up @@ -183,14 +185,6 @@ void DownloadIcon::fetchFinished()
#endif
}

void DownloadIcon::fetchErrored()
{
#ifdef WITH_XC_NETWORKING
emit iconError(nullptr);
emit transferDone();
#endif
}

void DownloadIcon::abortRequest()
{
#ifdef WITH_XC_NETWORKING
Expand Down
2 changes: 0 additions & 2 deletions src/gui/DownloadIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ public slots:
void iconReceived(const QImage&, Entry*);
void iconError(Entry*);
void fallbackNotEnabled();
void transferDone();

private slots:
void fetchFinished();
void fetchReadyRead();
void fetchErrored();

private:
#ifdef WITH_XC_NETWORKING
Expand Down
9 changes: 8 additions & 1 deletion src/gui/EditWidgetIcons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,15 @@ void EditWidgetIcons::downloadFavicon()
void EditWidgetIcons::iconReceived(const QImage& icon, Entry* entry)
{
#ifdef WITH_XC_NETWORKING
addCustomIcon(icon);
Q_UNUSED(entry);
if (icon.isNull()) {
emit messageEditEntry(tr("Unable to fetch favicon."), MessageWidget::Error);
return;
}

if (!addCustomIcon(icon)) {
emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information);
}
#else
Q_UNUSED(icon);
Q_UNUSED(entry);
Expand Down
13 changes: 13 additions & 0 deletions src/gui/IconDownloaderDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <QtConcurrent>
#include <QMutexLocker>
#include <QTimer>

#include "core/Config.h"
#include "core/Group.h"
Expand Down Expand Up @@ -86,10 +87,18 @@ void IconDownloaderDialog::downloadFavicon(const QSharedPointer<Database>& datab
<< new QStandardItem(tr("Loading")));
m_mutex.unlock();

QTimer timer;
connect(&timer, SIGNAL(timeout()), downloader.data(), SLOT(abortRequest()));
if (config()->get("security/downloadFavicon", false).toBool()) {
timer.start(config()->get("security/downloadFaviconTimeout").toInt() * 1000);
}

downloader->downloadFavicon(entry);

QEventLoop loop;
connect(downloader.data(), SIGNAL(iconReceived(const QImage&, Entry*)), &loop, SLOT(quit()));
loop.exec();
timer.stop();
#endif
}

Expand Down Expand Up @@ -129,6 +138,7 @@ void IconDownloaderDialog::iconReceived(const QImage& icon, Entry* entry)

if (icon.isNull() || !entry) {
updateTable(entry, tr("Error"));
emit messageEditEntry(tr("Unable to fetch favicon."), MessageWidget::Error);
return;
}

Expand Down Expand Up @@ -157,6 +167,8 @@ bool IconDownloaderDialog::addCustomIcon(const QImage& icon, Entry* entry)
m_customIconModel->setIcons(m_db->metadata()->customIconsScaledPixmaps(),
m_db->metadata()->customIconsOrder());
added = true;
} else {
emit messageEditEntry(tr("Custom icon already exists"), MessageWidget::Information);
}

if (entry) {
Expand Down Expand Up @@ -186,6 +198,7 @@ void IconDownloaderDialog::fallbackNotEnabled()
void IconDownloaderDialog::iconError(Entry* entry)
{
updateTable(entry, tr("Unable to fetch favicon."));
emit messageEditEntry(tr("Unable to fetch favicon."), MessageWidget::Error);
}

void IconDownloaderDialog::updateTable(Entry* entry, const QString& message)
Expand Down

0 comments on commit 4c77859

Please sign in to comment.