Skip to content

Commit

Permalink
Add support for downloading multiple favicons from the context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed May 22, 2019
1 parent 60ab999 commit d88e382
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
30 changes: 27 additions & 3 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,16 +659,40 @@ 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()));
connect(iconDownloader,
SIGNAL(messageEditEntry(QString,MessageWidget::MessageType)),
SLOT(showMessage(QString,MessageWidget::MessageType)));

Entry* currentEntry = m_entryView->currentEntry();
if (currentEntry) {
iconDownloader->downloadFavicon(m_db, currentEntry);
if (selectedEntries.count() == 1) {
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
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/IconDownloaderDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ IconDownloaderDialog::IconDownloaderDialog(QWidget* parent)
setAttribute(Qt::WA_DeleteOnClose);
m_ui->tableView->setModel(m_dataModel);
m_ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
m_ui->progressBar->setMinimumHeight(20);
m_dataModel->clear();
m_dataModel->setHorizontalHeaderLabels({"URL", "Status"});
}
Expand Down
20 changes: 13 additions & 7 deletions src/gui/IconDownloaderDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="abortButton">
<property name="sizePolicy">
Expand All @@ -51,6 +51,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Abort</string>
</property>
Expand Down
3 changes: 2 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionEntryCopyTotp->setEnabled(singleEntrySelected && dbWidget->currentEntryHasTotp());
m_ui->actionEntrySetupTotp->setEnabled(singleEntrySelected);
m_ui->actionEntryTotpQRCode->setEnabled(singleEntrySelected && dbWidget->currentEntryHasTotp());
m_ui->actionEntryDownloadIcon->setEnabled(singleEntrySelected && !dbWidget->currentEntryHasIconSet() && dbWidget->currentEntryHasUrl());
m_ui->actionEntryDownloadIcon->setEnabled((entriesSelected && !singleEntrySelected) ||
(singleEntrySelected && !dbWidget->currentEntryHasIconSet() && dbWidget->currentEntryHasUrl()));
m_ui->actionGroupNew->setEnabled(groupSelected);
m_ui->actionGroupEdit->setEnabled(groupSelected);
m_ui->actionGroupDelete->setEnabled(groupSelected && dbWidget->canDeleteCurrentGroup());
Expand Down

0 comments on commit d88e382

Please sign in to comment.