Skip to content

Commit

Permalink
Download all favicons
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed May 24, 2019
1 parent 7ce6f9d commit 4222a37
Show file tree
Hide file tree
Showing 14 changed files with 896 additions and 176 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ set(keepassx_SOURCES
gui/DatabaseTabWidget.cpp
gui/DatabaseWidget.cpp
gui/DatabaseWidgetStateSync.cpp
gui/DownloadIcon.cpp
gui/EntryPreviewWidget.cpp
gui/DialogyWidget.cpp
gui/DragTabBar.cpp
Expand All @@ -96,6 +97,7 @@ set(keepassx_SOURCES
gui/EditWidgetProperties.cpp
gui/FileDialog.cpp
gui/Font.cpp
gui/IconDownloaderDialog.cpp
gui/IconModels.cpp
gui/KeePass1OpenWidget.cpp
gui/KMessageWidget.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/gui/ApplicationSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)
connect(m_generalUi->toolbarHideCheckBox, SIGNAL(toggled(bool)), SLOT(toolbarSettingsToggled(bool)));
connect(m_generalUi->rememberLastDatabasesCheckBox, SIGNAL(toggled(bool)), SLOT(rememberDatabasesToggled(bool)));

connect(m_generalUi->downloadFaviconCheckBox, SIGNAL(toggled(bool)),
m_generalUi->downloadFaviconSpinBox, SLOT(setEnabled(bool)));
connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
connect(m_secUi->lockDatabaseIdleCheckBox, SIGNAL(toggled(bool)),
Expand Down Expand Up @@ -152,6 +154,8 @@ void ApplicationSettingsWidget::loadSettings()
m_generalUi->autoTypeEntryTitleMatchCheckBox->setChecked(config()->get("AutoTypeEntryTitleMatch").toBool());
m_generalUi->autoTypeEntryURLMatchCheckBox->setChecked(config()->get("AutoTypeEntryURLMatch").toBool());
m_generalUi->ignoreGroupExpansionCheckBox->setChecked(config()->get("IgnoreGroupExpansion").toBool());
m_generalUi->downloadFaviconCheckBox->setChecked(config()->get("DownloadFavicon").toBool());
m_generalUi->downloadFaviconSpinBox->setValue(config()->get("DownloadFaviconTimeout").toInt());

m_generalUi->languageComboBox->clear();
QList<QPair<QString, QString>> languages = Translator::availableLanguages();
Expand Down Expand Up @@ -252,6 +256,8 @@ void ApplicationSettingsWidget::saveSettings()
config()->set("AutoTypeEntryTitleMatch", m_generalUi->autoTypeEntryTitleMatchCheckBox->isChecked());
config()->set("AutoTypeEntryURLMatch", m_generalUi->autoTypeEntryURLMatchCheckBox->isChecked());
int currentLangIndex = m_generalUi->languageComboBox->currentIndex();
config()->set("DownloadFavicon", m_generalUi->downloadFaviconCheckBox->isChecked());
config()->set("DownloadFaviconTimeout", m_generalUi->downloadFaviconSpinBox->value());

config()->set("GUI/Language", m_generalUi->languageComboBox->itemData(currentLangIndex).toString());

Expand Down
44 changes: 44 additions & 0 deletions src/gui/ApplicationSettingsWidgetGeneral.ui
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,50 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Timeouts</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="formAlignment">
<set>Qt::AlignLeft|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="downloadFaviconCheckBox">
<property name="text">
<string>Favicon download timeout</string>
</property>
</widget>
</item>
<item row="0" column="1" alignment="Qt::AlignLeft">
<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>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down
83 changes: 83 additions & 0 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QSplitter>

#include "autotype/AutoType.h"
#include "core/AsyncTask.h"
#include "core/Config.h"
#include "core/Database.h"
#include "core/EntrySearcher.h"
Expand Down Expand Up @@ -61,6 +62,10 @@
#include "keeshare/KeeShare.h"
#include "touchid/TouchID.h"

#ifdef WITH_XC_NETWORKING
#include "gui/IconDownloaderDialog.h"
#endif

#ifdef Q_OS_LINUX
#include <sys/vfs.h>
#endif
Expand Down Expand Up @@ -89,6 +94,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent)
, m_groupView(new GroupView(m_db.data(), m_mainSplitter))
, m_saveAttempts(0)
, m_fileWatcher(new DelayingFileWatcher(this))
, m_iconDownloaderState(IconDownloaderState::Idle)
{
m_messageWidget->setHidden(true);

Expand Down Expand Up @@ -650,6 +656,73 @@ void DatabaseWidget::openUrl()
}
}

void DatabaseWidget::downloadFavicon()
{
#ifdef WITH_XC_NETWORKING
const QModelIndexList selected = m_entryView->selectionModel()->selectedRows();
if (selected.isEmpty()) {
return;
}

QList<Entry*> selectedEntries;
for (const QModelIndex& index : selected) {
selectedEntries.append(m_entryView->entryFromIndex(index));
}

if (selectedEntries.isEmpty()) {
return;
}

auto* iconDownloader = new IconDownloaderDialog(this);
connect(iconDownloader, SIGNAL(entryUpdated()), SIGNAL(databaseModified()));

if (selectedEntries.count() == 1) {
connect(iconDownloader,
SIGNAL(messageEditEntry(QString,MessageWidget::MessageType)),
SLOT(showMessage(QString,MessageWidget::MessageType)));
iconDownloader->downloadFavicon(m_db, selectedEntries.first());
return;
}

m_iconDownloaderState = IconDownloaderState::Downloading;
iconDownloader->raiseWindow();
iconDownloader->show();
iconDownloader->activateWindow();
iconDownloader->raise();
auto result = AsyncTask::runAndWaitForFuture(
[&]() { return iconDownloader->downloadAllFavicons(m_db, selectedEntries); });
Q_UNUSED(result);
m_iconDownloaderState = IconDownloaderState::Idle;
#endif
}

void DatabaseWidget::downloadAllFavicons()
{
#ifdef WITH_XC_NETWORKING
if (m_iconDownloaderState == IconDownloaderState::Downloading) {
return;
}
m_iconDownloaderState = IconDownloaderState::Downloading;

auto* iconDownloader = new IconDownloaderDialog(this);
connect(iconDownloader, SIGNAL(entryUpdated()), SIGNAL(databaseModified()));

Group* currentGroup = m_groupView->currentGroup();
Q_ASSERT(currentGroup);
if (currentGroup) {
auto entries = currentGroup->entries();
iconDownloader->raiseWindow();
iconDownloader->show();
iconDownloader->activateWindow();
iconDownloader->raise();
auto result = AsyncTask::runAndWaitForFuture(
[&]() { return iconDownloader->downloadAllFavicons(m_db, entries); });
Q_UNUSED(result);
}
m_iconDownloaderState = IconDownloaderState::Idle;
#endif
}

void DatabaseWidget::openUrlForEntry(Entry* entry)
{
Q_ASSERT(entry);
Expand Down Expand Up @@ -1489,6 +1562,16 @@ bool DatabaseWidget::currentEntryHasTotp()
return currentEntry->hasTotp();
}

bool DatabaseWidget::currentEntryHasIconSet()
{
Entry* currentEntry = m_entryView->currentEntry();
Q_ASSERT(currentEntry);
if (!currentEntry) {
return false;
}
return !currentEntry->iconUuid().isNull();
}

bool DatabaseWidget::currentEntryHasNotes()
{
Entry* currentEntry = m_entryView->currentEntry();
Expand Down
12 changes: 11 additions & 1 deletion src/gui/DatabaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "gui/MessageWidget.h"
#include "gui/csvImport/CsvImportWizard.h"
#include "gui/entry/EntryModel.h"

#include "config-keepassx.h"

class DatabaseOpenWidget;
Expand Down Expand Up @@ -107,6 +106,7 @@ class DatabaseWidget : public QStackedWidget
bool currentEntryHasUrl();
bool currentEntryHasNotes();
bool currentEntryHasTotp();
bool currentEntryHasIconSet();

void blockAutoReload(bool block = true);

Expand Down Expand Up @@ -164,6 +164,8 @@ public slots:
void setupTotp();
void performAutoType();
void openUrl();
void downloadFavicon();
void downloadAllFavicons();
void openUrlForEntry(Entry* entry);
void createGroup();
void deleteGroup();
Expand Down Expand Up @@ -221,6 +223,12 @@ private slots:
void restoreGroupEntryFocus(const QUuid& groupUuid, const QUuid& EntryUuid);

private:
enum IconDownloaderState
{
Idle,
Downloading
};

int addChildWidget(QWidget* w);
void setClipboardTextAndMinimize(const QString& text);
void setIconFromParent();
Expand Down Expand Up @@ -263,6 +271,8 @@ private slots:
// Autoreload
QPointer<DelayingFileWatcher> m_fileWatcher;
bool m_blockAutoSave;

IconDownloaderState m_iconDownloaderState;
};

#endif // KEEPASSX_DATABASEWIDGET_H
Loading

0 comments on commit 4222a37

Please sign in to comment.