Prevent deletion of custom icon if it is still used by other entries.

Refs #22
This commit is contained in:
Florian Geyer 2012-05-12 00:01:58 +02:00
parent 15fa09167b
commit e4b6289c0b
5 changed files with 29 additions and 5 deletions

View File

@ -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;

View File

@ -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:

View File

@ -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;
}

View File

@ -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;

View File

@ -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));
}
}
}
}