2012-05-15 07:02:05 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2012-05-15 07:02:05 -04:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "EditWidgetIcons.h"
|
|
|
|
#include "ui_EditWidgetIcons.h"
|
|
|
|
|
2016-10-05 23:10:06 -04:00
|
|
|
#include <QFileDialog>
|
2018-03-31 16:01:30 -04:00
|
|
|
#include <QMessageBox>
|
2012-05-15 07:02:05 -04:00
|
|
|
|
2017-06-28 18:32:47 -04:00
|
|
|
#include "core/Config.h"
|
2012-05-15 07:02:05 -04:00
|
|
|
#include "core/Group.h"
|
|
|
|
#include "core/Metadata.h"
|
|
|
|
#include "core/Tools.h"
|
|
|
|
#include "gui/IconModels.h"
|
2013-10-08 16:09:20 -04:00
|
|
|
#include "gui/MessageBox.h"
|
2018-01-16 18:56:47 -05:00
|
|
|
#ifdef WITH_XC_NETWORKING
|
2019-07-07 15:29:11 -04:00
|
|
|
#include "core/IconDownloader.h"
|
2017-03-02 18:44:01 -05:00
|
|
|
#endif
|
2017-02-15 14:23:06 -05:00
|
|
|
|
2012-05-15 07:02:05 -04:00
|
|
|
IconStruct::IconStruct()
|
2018-03-22 17:56:05 -04:00
|
|
|
: uuid(QUuid())
|
2012-05-15 07:02:05 -04:00
|
|
|
, number(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-15 12:51:45 -04:00
|
|
|
EditWidgetIcons::EditWidgetIcons(QWidget* parent)
|
2012-05-15 07:02:05 -04:00
|
|
|
: QWidget(parent)
|
2012-07-19 07:57:55 -04:00
|
|
|
, m_ui(new Ui::EditWidgetIcons())
|
2018-11-22 05:47:31 -05:00
|
|
|
, m_db(nullptr)
|
2019-06-19 10:02:07 -04:00
|
|
|
, m_applyIconTo(ApplyIconToOptions::THIS_ONLY)
|
2012-07-19 07:57:55 -04:00
|
|
|
, m_defaultIconModel(new DefaultIconModel(this))
|
|
|
|
, m_customIconModel(new CustomIconModel(this))
|
2019-07-07 15:29:11 -04:00
|
|
|
#ifdef WITH_XC_NETWORKING
|
|
|
|
, m_downloader(new IconDownloader())
|
|
|
|
#endif
|
2012-05-15 07:02:05 -04:00
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
|
|
m_ui->defaultIconsView->setModel(m_defaultIconModel);
|
|
|
|
m_ui->customIconsView->setModel(m_customIconModel);
|
|
|
|
|
2019-06-19 10:02:07 -04:00
|
|
|
m_ui->applyIconToPushButton->setMenu(createApplyIconToMenu());
|
|
|
|
|
2018-10-31 23:27:38 -04:00
|
|
|
// clang-format off
|
2018-03-31 16:01:30 -04:00
|
|
|
connect(m_ui->defaultIconsView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateRadioButtonDefaultIcons()));
|
|
|
|
connect(m_ui->customIconsView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateRadioButtonCustomIcons()));
|
|
|
|
connect(m_ui->defaultIconsRadio, SIGNAL(toggled(bool)), this, SLOT(updateWidgetsDefaultIcons(bool)));
|
|
|
|
connect(m_ui->customIconsRadio, SIGNAL(toggled(bool)), this, SLOT(updateWidgetsCustomIcons(bool)));
|
2017-09-24 17:53:42 -04:00
|
|
|
connect(m_ui->addButton, SIGNAL(clicked()), SLOT(addCustomIconFromFile()));
|
2012-05-15 07:02:05 -04:00
|
|
|
connect(m_ui->deleteButton, SIGNAL(clicked()), SLOT(removeCustomIcon()));
|
2016-10-05 23:10:06 -04:00
|
|
|
connect(m_ui->faviconButton, SIGNAL(clicked()), SLOT(downloadFavicon()));
|
2019-06-19 10:02:07 -04:00
|
|
|
connect(m_ui->applyIconToPushButton->menu(), SIGNAL(triggered(QAction*)), SLOT(confirmApplyIconTo(QAction*)));
|
2016-10-05 23:10:06 -04:00
|
|
|
|
2018-03-10 22:31:43 -05:00
|
|
|
connect(m_ui->defaultIconsRadio, SIGNAL(toggled(bool)), this, SIGNAL(widgetUpdated()));
|
2018-10-31 23:27:38 -04:00
|
|
|
connect(m_ui->defaultIconsView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
|
|
|
this, SIGNAL(widgetUpdated()));
|
|
|
|
connect(m_ui->customIconsView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
|
|
|
this, SIGNAL(widgetUpdated()));
|
2019-07-07 15:29:11 -04:00
|
|
|
#ifdef WITH_XC_NETWORKING
|
|
|
|
connect(m_downloader.data(),
|
|
|
|
SIGNAL(finished(const QString&, const QImage&)),
|
|
|
|
SLOT(iconReceived(const QString&, const QImage&)));
|
|
|
|
#endif
|
2018-10-31 23:27:38 -04:00
|
|
|
// clang-format on
|
2018-03-10 22:31:43 -05:00
|
|
|
|
2016-10-05 23:10:06 -04:00
|
|
|
m_ui->faviconButton->setVisible(false);
|
2018-06-03 12:42:33 -04:00
|
|
|
m_ui->addButton->setEnabled(true);
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EditWidgetIcons::~EditWidgetIcons()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-05 23:10:06 -04:00
|
|
|
IconStruct EditWidgetIcons::state()
|
2012-05-15 07:02:05 -04:00
|
|
|
{
|
2018-11-22 05:47:31 -05:00
|
|
|
Q_ASSERT(m_db);
|
2016-10-05 23:10:06 -04:00
|
|
|
Q_ASSERT(!m_currentUuid.isNull());
|
|
|
|
|
2012-05-15 07:02:05 -04:00
|
|
|
IconStruct iconStruct;
|
|
|
|
if (m_ui->defaultIconsRadio->isChecked()) {
|
|
|
|
QModelIndex index = m_ui->defaultIconsView->currentIndex();
|
|
|
|
if (index.isValid()) {
|
|
|
|
iconStruct.number = index.row();
|
2018-02-07 07:10:56 -05:00
|
|
|
} else {
|
2012-05-15 10:50:42 -04:00
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
2018-02-07 07:10:56 -05:00
|
|
|
} else {
|
2012-05-15 07:02:05 -04:00
|
|
|
QModelIndex index = m_ui->customIconsView->currentIndex();
|
|
|
|
if (index.isValid()) {
|
|
|
|
iconStruct.uuid = m_customIconModel->uuidFromIndex(m_ui->customIconsView->currentIndex());
|
2018-02-07 07:10:56 -05:00
|
|
|
} else {
|
2012-05-15 10:50:42 -04:00
|
|
|
iconStruct.number = -1;
|
|
|
|
}
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
2017-02-15 14:23:06 -05:00
|
|
|
|
2019-06-19 10:02:07 -04:00
|
|
|
iconStruct.applyTo = m_applyIconTo;
|
|
|
|
|
2016-07-31 17:53:26 -04:00
|
|
|
return iconStruct;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditWidgetIcons::reset()
|
|
|
|
{
|
2018-11-22 05:47:31 -05:00
|
|
|
m_db.reset();
|
2018-03-22 17:56:05 -04:00
|
|
|
m_currentUuid = QUuid();
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
void EditWidgetIcons::load(const QUuid& currentUuid,
|
2019-01-17 00:39:53 -05:00
|
|
|
const QSharedPointer<Database>& database,
|
2018-11-22 05:47:31 -05:00
|
|
|
const IconStruct& iconStruct,
|
|
|
|
const QString& url)
|
2012-05-15 07:02:05 -04:00
|
|
|
{
|
2012-05-15 10:50:42 -04:00
|
|
|
Q_ASSERT(database);
|
|
|
|
Q_ASSERT(!currentUuid.isNull());
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
m_db = database;
|
2012-05-15 07:02:05 -04:00
|
|
|
m_currentUuid = currentUuid;
|
2016-10-05 23:10:06 -04:00
|
|
|
setUrl(url);
|
2012-05-15 07:02:05 -04:00
|
|
|
|
2016-01-24 13:03:50 -05:00
|
|
|
m_customIconModel->setIcons(database->metadata()->customIconsScaledPixmaps(),
|
2012-05-15 10:50:42 -04:00
|
|
|
database->metadata()->customIconsOrder());
|
2012-05-15 07:02:05 -04:00
|
|
|
|
2018-03-22 17:56:05 -04:00
|
|
|
QUuid iconUuid = iconStruct.uuid;
|
2012-05-15 10:50:42 -04:00
|
|
|
if (iconUuid.isNull()) {
|
|
|
|
int iconNumber = iconStruct.number;
|
|
|
|
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0));
|
|
|
|
m_ui->defaultIconsRadio->setChecked(true);
|
2018-02-07 07:10:56 -05:00
|
|
|
} else {
|
2012-05-15 10:50:42 -04:00
|
|
|
QModelIndex index = m_customIconModel->indexFromUuid(iconUuid);
|
|
|
|
if (index.isValid()) {
|
|
|
|
m_ui->customIconsView->setCurrentIndex(index);
|
|
|
|
m_ui->customIconsRadio->setChecked(true);
|
2018-02-07 07:10:56 -05:00
|
|
|
} else {
|
2012-05-15 10:50:42 -04:00
|
|
|
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(0, 0));
|
|
|
|
m_ui->defaultIconsRadio->setChecked(true);
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
}
|
2019-06-19 10:02:07 -04:00
|
|
|
|
|
|
|
m_applyIconTo = ApplyIconToOptions::THIS_ONLY;
|
|
|
|
m_ui->applyIconToPushButton->menu()->defaultAction()->activate(QAction::Trigger);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditWidgetIcons::setShowApplyIconToButton(bool state)
|
|
|
|
{
|
|
|
|
m_ui->applyIconToPushButton->setVisible(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu* EditWidgetIcons::createApplyIconToMenu()
|
|
|
|
{
|
|
|
|
auto* applyIconToMenu = new QMenu(this);
|
|
|
|
QAction* defaultAction = applyIconToMenu->addAction(tr("Apply to this only"));
|
|
|
|
defaultAction->setData(QVariant::fromValue(ApplyIconToOptions::THIS_ONLY));
|
|
|
|
applyIconToMenu->setDefaultAction(defaultAction);
|
|
|
|
applyIconToMenu->addSeparator();
|
|
|
|
applyIconToMenu->addAction(tr("Also apply to child groups"))
|
|
|
|
->setData(QVariant::fromValue(ApplyIconToOptions::CHILD_GROUPS));
|
|
|
|
applyIconToMenu->addAction(tr("Also apply to child entries"))
|
|
|
|
->setData(QVariant::fromValue(ApplyIconToOptions::CHILD_ENTRIES));
|
|
|
|
applyIconToMenu->addAction(tr("Also apply to all children"))
|
|
|
|
->setData(QVariant::fromValue(ApplyIconToOptions::ALL_CHILDREN));
|
|
|
|
return applyIconToMenu;
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
|
2017-02-15 14:23:06 -05:00
|
|
|
void EditWidgetIcons::setUrl(const QString& url)
|
2016-10-05 23:10:06 -04:00
|
|
|
{
|
2018-01-16 18:56:47 -05:00
|
|
|
#ifdef WITH_XC_NETWORKING
|
2019-07-07 15:29:11 -04:00
|
|
|
m_url = url;
|
2016-10-05 23:10:06 -04:00
|
|
|
m_ui->faviconButton->setVisible(!url.isEmpty());
|
2017-03-02 18:44:01 -05:00
|
|
|
#else
|
2017-03-10 08:28:26 -05:00
|
|
|
Q_UNUSED(url);
|
2017-03-02 18:44:01 -05:00
|
|
|
m_ui->faviconButton->setVisible(false);
|
|
|
|
#endif
|
2016-10-05 23:10:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditWidgetIcons::downloadFavicon()
|
|
|
|
{
|
2018-01-16 18:56:47 -05:00
|
|
|
#ifdef WITH_XC_NETWORKING
|
2019-07-07 15:29:11 -04:00
|
|
|
if (!m_url.isEmpty()) {
|
|
|
|
m_downloader->setUrl(m_url);
|
|
|
|
m_downloader->download();
|
2019-03-17 09:45:37 -04:00
|
|
|
}
|
2018-04-04 22:18:58 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-07 15:29:11 -04:00
|
|
|
void EditWidgetIcons::iconReceived(const QString& url, const QImage& icon)
|
2018-04-04 22:18:58 -04:00
|
|
|
{
|
|
|
|
#ifdef WITH_XC_NETWORKING
|
2019-07-07 15:29:11 -04:00
|
|
|
Q_UNUSED(url);
|
|
|
|
if (icon.isNull()) {
|
|
|
|
QString message(tr("Unable to fetch favicon."));
|
|
|
|
if (!config()->get("security/IconDownloadFallback", false).toBool()) {
|
|
|
|
message.append("\n").append(
|
|
|
|
tr("You can enable the DuckDuckGo website icon service under Tools -> Settings -> Security"));
|
2018-06-03 12:42:33 -04:00
|
|
|
}
|
2019-07-07 15:29:11 -04:00
|
|
|
emit messageEditEntry(message, MessageWidget::Error);
|
2018-04-04 22:18:58 -04:00
|
|
|
return;
|
2018-02-07 07:10:56 -05:00
|
|
|
}
|
2017-02-15 14:23:06 -05:00
|
|
|
|
2019-07-07 15:29:11 -04:00
|
|
|
if (!addCustomIcon(icon)) {
|
|
|
|
emit messageEditEntry(tr("Existing icon selected."), MessageWidget::Information);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
Q_UNUSED(url);
|
|
|
|
Q_UNUSED(icon);
|
2018-02-07 07:10:56 -05:00
|
|
|
#endif
|
2016-10-05 23:10:06 -04:00
|
|
|
}
|
|
|
|
|
2019-03-17 09:45:37 -04:00
|
|
|
void EditWidgetIcons::abortRequests()
|
2016-10-11 18:04:44 -04:00
|
|
|
{
|
2018-04-04 22:18:58 -04:00
|
|
|
#ifdef WITH_XC_NETWORKING
|
2019-07-07 15:29:11 -04:00
|
|
|
if (m_downloader) {
|
|
|
|
m_downloader->abortDownload();
|
2018-05-20 21:12:06 -04:00
|
|
|
}
|
2018-04-04 22:18:58 -04:00
|
|
|
#endif
|
2016-10-11 18:04:44 -04:00
|
|
|
}
|
|
|
|
|
2017-09-24 17:53:42 -04:00
|
|
|
void EditWidgetIcons::addCustomIconFromFile()
|
2012-05-15 07:02:05 -04:00
|
|
|
{
|
2019-07-07 15:29:11 -04:00
|
|
|
if (!m_db) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString filter = QString("%1 (%2);;%3 (*)").arg(tr("Images"), Tools::imageReaderFilter(), tr("All files"));
|
|
|
|
|
|
|
|
auto filenames = QFileDialog::getOpenFileNames(this, tr("Select Image(s)"), "", filter);
|
|
|
|
if (!filenames.empty()) {
|
|
|
|
QStringList errornames;
|
|
|
|
int numexisting = 0;
|
|
|
|
for (const auto& filename : filenames) {
|
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
auto icon = QImage(filename);
|
|
|
|
if (icon.isNull()) {
|
|
|
|
errornames << filename;
|
|
|
|
} else if (!addCustomIcon(icon)) {
|
|
|
|
// Icon already exists in database
|
|
|
|
++numexisting;
|
2018-05-30 22:23:39 -04:00
|
|
|
}
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
2019-07-07 15:29:11 -04:00
|
|
|
}
|
2018-06-03 12:42:33 -04:00
|
|
|
|
2019-07-07 15:29:11 -04:00
|
|
|
int numloaded = filenames.size() - errornames.size() - numexisting;
|
|
|
|
QString msg;
|
2018-06-03 12:42:33 -04:00
|
|
|
|
2019-07-07 15:29:11 -04:00
|
|
|
if (numloaded > 0) {
|
|
|
|
msg = tr("Successfully loaded %1 of %n icon(s)", "", filenames.size()).arg(numloaded);
|
|
|
|
} else {
|
|
|
|
msg = tr("No icons were loaded");
|
|
|
|
}
|
2018-06-03 12:42:33 -04:00
|
|
|
|
2019-07-07 15:29:11 -04:00
|
|
|
if (numexisting > 0) {
|
|
|
|
msg += "\n" + tr("%n icon(s) already exist in the database", "", numexisting);
|
|
|
|
}
|
2018-06-03 12:42:33 -04:00
|
|
|
|
2019-07-07 15:29:11 -04:00
|
|
|
if (!errornames.empty()) {
|
|
|
|
// Show the first 8 icons that failed to load
|
|
|
|
errornames = errornames.mid(0, 8);
|
|
|
|
emit messageEditEntry(msg + "\n" + tr("The following icon(s) failed:", "", errornames.size()) + "\n"
|
|
|
|
+ errornames.join("\n"),
|
|
|
|
MessageWidget::Error);
|
|
|
|
} else if (numloaded > 0) {
|
|
|
|
emit messageEditEntry(msg, MessageWidget::Positive);
|
|
|
|
} else {
|
|
|
|
emit messageEditEntry(msg, MessageWidget::Information);
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 12:42:33 -04:00
|
|
|
bool EditWidgetIcons::addCustomIcon(const QImage& icon)
|
2017-09-24 17:53:42 -04:00
|
|
|
{
|
2018-06-03 12:42:33 -04:00
|
|
|
bool added = false;
|
2018-11-22 05:47:31 -05:00
|
|
|
if (m_db) {
|
2018-06-03 12:42:33 -04:00
|
|
|
// Don't add an icon larger than 128x128, but retain original size if smaller
|
|
|
|
auto scaledicon = icon;
|
|
|
|
if (icon.width() > 128 || icon.height() > 128) {
|
|
|
|
scaledicon = icon.scaled(128, 128);
|
|
|
|
}
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
QUuid uuid = m_db->metadata()->findCustomIcon(scaledicon);
|
2017-09-24 17:53:42 -04:00
|
|
|
if (uuid.isNull()) {
|
2018-03-22 17:56:05 -04:00
|
|
|
uuid = QUuid::createUuid();
|
2018-11-22 05:47:31 -05:00
|
|
|
m_db->metadata()->addCustomIcon(uuid, scaledicon);
|
|
|
|
m_customIconModel->setIcons(m_db->metadata()->customIconsScaledPixmaps(),
|
|
|
|
m_db->metadata()->customIconsOrder());
|
2018-06-03 12:42:33 -04:00
|
|
|
added = true;
|
2017-09-24 17:53:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Select the new or existing icon
|
2017-10-07 08:49:14 -04:00
|
|
|
updateRadioButtonCustomIcons();
|
2017-09-24 17:53:42 -04:00
|
|
|
QModelIndex index = m_customIconModel->indexFromUuid(uuid);
|
|
|
|
m_ui->customIconsView->setCurrentIndex(index);
|
2018-03-10 22:31:43 -05:00
|
|
|
|
|
|
|
emit widgetUpdated();
|
2017-09-24 17:53:42 -04:00
|
|
|
}
|
2018-06-03 12:42:33 -04:00
|
|
|
|
|
|
|
return added;
|
2017-09-24 17:53:42 -04:00
|
|
|
}
|
|
|
|
|
2012-05-15 07:02:05 -04:00
|
|
|
void EditWidgetIcons::removeCustomIcon()
|
|
|
|
{
|
2018-11-22 05:47:31 -05:00
|
|
|
if (m_db) {
|
2012-05-15 07:02:05 -04:00
|
|
|
QModelIndex index = m_ui->customIconsView->currentIndex();
|
|
|
|
if (index.isValid()) {
|
2018-03-22 17:56:05 -04:00
|
|
|
QUuid iconUuid = m_customIconModel->uuidFromIndex(index);
|
2012-05-15 07:02:05 -04:00
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
const QList<Entry*> allEntries = m_db->rootGroup()->entriesRecursive(true);
|
2017-02-28 22:45:40 -05:00
|
|
|
QList<Entry*> entriesWithSameIcon;
|
2012-05-15 10:00:30 -04:00
|
|
|
QList<Entry*> historyEntriesWithSameIcon;
|
|
|
|
|
2016-09-02 13:51:51 -04:00
|
|
|
for (Entry* entry : allEntries) {
|
2012-05-15 10:00:30 -04:00
|
|
|
if (iconUuid == entry->iconUuid()) {
|
2017-02-28 22:45:40 -05:00
|
|
|
// Check if this is a history entry (no assigned group)
|
|
|
|
if (!entry->group()) {
|
2012-05-15 10:00:30 -04:00
|
|
|
historyEntriesWithSameIcon << entry;
|
2017-02-28 22:45:40 -05:00
|
|
|
} else if (m_currentUuid != entry->uuid()) {
|
|
|
|
entriesWithSameIcon << entry;
|
2012-05-15 10:00:30 -04:00
|
|
|
}
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
const QList<Group*> allGroups = m_db->rootGroup()->groupsRecursive(true);
|
2017-02-28 22:45:40 -05:00
|
|
|
QList<Group*> groupsWithSameIcon;
|
|
|
|
|
|
|
|
for (Group* group : allGroups) {
|
2012-05-15 07:02:05 -04:00
|
|
|
if (iconUuid == group->iconUuid() && m_currentUuid != group->uuid()) {
|
2017-02-28 22:45:40 -05:00
|
|
|
groupsWithSameIcon << group;
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-28 22:45:40 -05:00
|
|
|
int iconUseCount = entriesWithSameIcon.size() + groupsWithSameIcon.size();
|
|
|
|
if (iconUseCount > 0) {
|
2018-12-19 23:14:11 -05:00
|
|
|
|
|
|
|
auto result = MessageBox::question(this,
|
|
|
|
tr("Confirm Delete"),
|
|
|
|
tr("This icon is used by %n entry(s), and will be replaced "
|
|
|
|
"by the default icon. Are you sure you want to delete it?",
|
|
|
|
"",
|
|
|
|
iconUseCount),
|
|
|
|
MessageBox::Delete | MessageBox::Cancel,
|
|
|
|
MessageBox::Cancel);
|
|
|
|
|
|
|
|
if (result == MessageBox::Cancel) {
|
2017-02-28 22:45:40 -05:00
|
|
|
// Early out, nothing is changed
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Revert matched entries to the default entry icon
|
|
|
|
for (Entry* entry : asConst(entriesWithSameIcon)) {
|
|
|
|
entry->setIcon(Entry::DefaultIconNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Revert matched groups to the default group icon
|
|
|
|
for (Group* group : asConst(groupsWithSameIcon)) {
|
|
|
|
group->setIcon(Group::DefaultIconNumber);
|
|
|
|
}
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
}
|
2017-02-28 22:45:40 -05:00
|
|
|
|
|
|
|
// Remove the icon from history entries
|
|
|
|
for (Entry* entry : asConst(historyEntriesWithSameIcon)) {
|
|
|
|
entry->setUpdateTimeinfo(false);
|
|
|
|
entry->setIcon(0);
|
|
|
|
entry->setUpdateTimeinfo(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the icon from the database
|
2018-11-22 05:47:31 -05:00
|
|
|
m_db->metadata()->removeCustomIcon(iconUuid);
|
|
|
|
m_customIconModel->setIcons(m_db->metadata()->customIconsScaledPixmaps(),
|
|
|
|
m_db->metadata()->customIconsOrder());
|
2017-02-28 22:45:40 -05:00
|
|
|
|
|
|
|
// Reset the current icon view
|
|
|
|
updateRadioButtonDefaultIcons();
|
|
|
|
|
2018-11-22 05:47:31 -05:00
|
|
|
if (m_db->rootGroup()->findEntryByUuid(m_currentUuid) != nullptr) {
|
2017-02-28 22:45:40 -05:00
|
|
|
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(Entry::DefaultIconNumber));
|
|
|
|
} else {
|
|
|
|
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(Group::DefaultIconNumber));
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
2018-03-10 22:31:43 -05:00
|
|
|
|
|
|
|
emit widgetUpdated();
|
2012-05-15 07:02:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditWidgetIcons::updateWidgetsDefaultIcons(bool check)
|
|
|
|
{
|
|
|
|
if (check) {
|
|
|
|
QModelIndex index = m_ui->defaultIconsView->currentIndex();
|
|
|
|
if (!index.isValid()) {
|
|
|
|
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(0, 0));
|
2018-02-07 07:10:56 -05:00
|
|
|
} else {
|
2012-05-15 07:02:05 -04:00
|
|
|
m_ui->defaultIconsView->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
m_ui->customIconsView->selectionModel()->clearSelection();
|
|
|
|
m_ui->deleteButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditWidgetIcons::updateWidgetsCustomIcons(bool check)
|
|
|
|
{
|
|
|
|
if (check) {
|
|
|
|
QModelIndex index = m_ui->customIconsView->currentIndex();
|
|
|
|
if (!index.isValid()) {
|
|
|
|
m_ui->customIconsView->setCurrentIndex(m_customIconModel->index(0, 0));
|
2018-02-07 07:10:56 -05:00
|
|
|
} else {
|
2012-05-15 07:02:05 -04:00
|
|
|
m_ui->customIconsView->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
m_ui->defaultIconsView->selectionModel()->clearSelection();
|
|
|
|
m_ui->deleteButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditWidgetIcons::updateRadioButtonDefaultIcons()
|
|
|
|
{
|
|
|
|
m_ui->defaultIconsRadio->setChecked(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditWidgetIcons::updateRadioButtonCustomIcons()
|
|
|
|
{
|
|
|
|
m_ui->customIconsRadio->setChecked(true);
|
|
|
|
}
|
2019-06-19 10:02:07 -04:00
|
|
|
|
|
|
|
void EditWidgetIcons::confirmApplyIconTo(QAction* action)
|
|
|
|
{
|
|
|
|
m_applyIconTo = action->data().value<ApplyIconToOptions>();
|
|
|
|
m_ui->applyIconToPushButton->setText(action->text());
|
|
|
|
}
|