mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-14 16:57:32 -05:00
Prevent deletion of custom icon if it is still used by other entries.
Refs #22
This commit is contained in:
parent
15fa09167b
commit
e4b6289c0b
@ -359,7 +359,7 @@ const QList<Entry*>& Group::entries() const
|
|||||||
return m_entries;
|
return m_entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Entry*> Group::entriesRecursive(bool includeHistoryItems)
|
QList<Entry*> Group::entriesRecursive(bool includeHistoryItems) const
|
||||||
{
|
{
|
||||||
QList<Entry*> entryList;
|
QList<Entry*> entryList;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public:
|
|||||||
const QList<Group*>& children() const;
|
const QList<Group*>& children() const;
|
||||||
QList<Entry*> entries();
|
QList<Entry*> entries();
|
||||||
const QList<Entry*>& entries() const;
|
const QList<Entry*>& entries() const;
|
||||||
QList<Entry*> entriesRecursive(bool includeHistoryItems = false);
|
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
|
||||||
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
@ -415,3 +415,8 @@ void Metadata::removeCustomField(const QString& key)
|
|||||||
m_customFields.remove(key);
|
m_customFields.remove(key);
|
||||||
Q_EMIT modified();
|
Q_EMIT modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Database* Metadata::database() const
|
||||||
|
{
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
@ -68,6 +68,7 @@ public:
|
|||||||
int historyMaxItems() const;
|
int historyMaxItems() const;
|
||||||
int historyMaxSize() const;
|
int historyMaxSize() const;
|
||||||
QHash<QString, QString> customFields() const;
|
QHash<QString, QString> customFields() const;
|
||||||
|
const Database* database() const;
|
||||||
|
|
||||||
static const int defaultHistoryMaxItems;
|
static const int defaultHistoryMaxItems;
|
||||||
static const int defaultHistoryMaxSize;
|
static const int defaultHistoryMaxSize;
|
||||||
|
@ -450,9 +450,27 @@ void EditEntryWidget::removeCustomIcon()
|
|||||||
if (m_metadata) {
|
if (m_metadata) {
|
||||||
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
|
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
// TODO: check if the icon is used in history items or other entries
|
QList<Entry*> allEntries = m_metadata->database()->rootGroup()->entriesRecursive(true);
|
||||||
m_metadata->removeCustomIcon(m_customIconModel->uuidFromIndex(index));
|
Uuid uuid = m_customIconModel->uuidFromIndex(index);
|
||||||
m_customIconModel->setIcons(m_metadata->customIcons());
|
|
||||||
|
int iconUsedCount = 0;
|
||||||
|
QListIterator<Entry*> i(allEntries);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
Entry* entry = i.next();
|
||||||
|
if (uuid == entry->iconUuid() && entry != m_entry) {
|
||||||
|
iconUsedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iconUsedCount == 0) {
|
||||||
|
m_metadata->removeCustomIcon(uuid);
|
||||||
|
m_customIconModel->setIcons(m_metadata->customIcons());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::information(this, tr("Icon still used!"),
|
||||||
|
tr("Can't delete icon. Still used by %1 entries.")
|
||||||
|
.arg(iconUsedCount));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user