mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-14 00:39:53 -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;
|
||||
}
|
||||
|
||||
QList<Entry*> Group::entriesRecursive(bool includeHistoryItems)
|
||||
QList<Entry*> Group::entriesRecursive(bool includeHistoryItems) const
|
||||
{
|
||||
QList<Entry*> entryList;
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
const QList<Group*>& children() const;
|
||||
QList<Entry*> entries();
|
||||
const QList<Entry*>& entries() const;
|
||||
QList<Entry*> entriesRecursive(bool includeHistoryItems = false);
|
||||
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -415,3 +415,8 @@ void Metadata::removeCustomField(const QString& key)
|
||||
m_customFields.remove(key);
|
||||
Q_EMIT modified();
|
||||
}
|
||||
|
||||
const Database* Metadata::database() const
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
int historyMaxItems() const;
|
||||
int historyMaxSize() const;
|
||||
QHash<QString, QString> customFields() const;
|
||||
const Database* database() const;
|
||||
|
||||
static const int defaultHistoryMaxItems;
|
||||
static const int defaultHistoryMaxSize;
|
||||
|
@ -450,9 +450,27 @@ void EditEntryWidget::removeCustomIcon()
|
||||
if (m_metadata) {
|
||||
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
|
||||
if (index.isValid()) {
|
||||
// TODO: check if the icon is used in history items or other entries
|
||||
m_metadata->removeCustomIcon(m_customIconModel->uuidFromIndex(index));
|
||||
m_customIconModel->setIcons(m_metadata->customIcons());
|
||||
QList<Entry*> allEntries = m_metadata->database()->rootGroup()->entriesRecursive(true);
|
||||
Uuid uuid = m_customIconModel->uuidFromIndex(index);
|
||||
|
||||
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