From e44c3bca2829a613383678b5acc5a63d05034c63 Mon Sep 17 00:00:00 2001 From: codestation Date: Thu, 29 Aug 2013 12:28:40 -0430 Subject: [PATCH] Process correctly the return value of the confirm dialog. Update the backup usage label after deleting an entry. Update the parent metadata size after deleting a node. --- backupmanagerform.cpp | 18 +++++++++++------- backupmanagerform.h | 1 + cmaobject.cpp | 3 ++- cmaobject.h | 2 +- database.cpp | 2 ++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/backupmanagerform.cpp b/backupmanagerform.cpp index 839fe3c..5c0f539 100644 --- a/backupmanagerform.cpp +++ b/backupmanagerform.cpp @@ -61,12 +61,7 @@ void BackupManagerForm::removeEntry(BackupItem *item) msgBox.setMessageText(tr("Are you sure to remove the backup of the following entry?"), item->title); msgBox.setMessagePixmap(*item->getIconPixmap(), item->getIconWidth()); - switch(msgBox.exec()) { - case QDialogButtonBox::Ok: - break; - case QDialogButtonBox::Cancel: - return; - default: + if(msgBox.exec() == 0) { return; } @@ -78,6 +73,15 @@ void BackupManagerForm::removeEntry(BackupItem *item) db->remove(obj); } ui->tableWidget->removeRow(item->row); + obj = db->ohfiToObject(obj->metadata.ohfiParent); + if(obj) { + setBackupUsage(obj->metadata.size); + } +} + +void BackupManagerForm::setBackupUsage(quint64 size) +{ + ui->usageLabel->setText(tr("Backup disk usage: %1").arg(readable_size(size, true))); } void BackupManagerForm::loadBackupListing(int index) @@ -138,7 +142,7 @@ void BackupManagerForm::loadBackupListing(int index) horiz_header->setResizeMode(QHeaderView::Stretch); CMAObject *obj = db->ohfiToObject(ohfi); - ui->usageLabel->setText(tr("Backup disk usage: %1").arg(readable_size(obj->metadata.size, true))); + setBackupUsage(obj->metadata.size); QList item_list; diff --git a/backupmanagerform.h b/backupmanagerform.h index b914098..d892eae 100644 --- a/backupmanagerform.h +++ b/backupmanagerform.h @@ -41,6 +41,7 @@ public: private: void setupForm(); + void setBackupUsage(quint64 size); Ui::BackupManagerForm *ui; diff --git a/cmaobject.cpp b/cmaobject.cpp index 07b505f..9bde3c7 100644 --- a/cmaobject.cpp +++ b/cmaobject.cpp @@ -184,11 +184,12 @@ bool CMAObject::removeReferencedObject() } } -void CMAObject::updateObjectSize(unsigned long size) +void CMAObject::updateObjectSize(qint64 size) { if(parent) { parent->updateObjectSize(size); } + //FIXME: size should be quint64 metadata.size += size; } diff --git a/cmaobject.h b/cmaobject.h index 47011b8..8411314 100644 --- a/cmaobject.h +++ b/cmaobject.h @@ -37,7 +37,7 @@ public: void rename(const QString &name); bool removeReferencedObject(); void initObject(const QFileInfo &file); - void updateObjectSize(unsigned long size); + void updateObjectSize(qint64 size); bool hasParent(const CMAObject *obj); bool operator==(const CMAObject &obj); diff --git a/database.cpp b/database.cpp index ccb32c4..edd407d 100644 --- a/database.cpp +++ b/database.cpp @@ -181,6 +181,8 @@ bool Database::removeInternal(root_list &list, const CMAObject *obj) while(it != list.end()) { if(!found && (*it) == obj) { + // update the size of the parent objects + (*it)->updateObjectSize(-(*it)->metadata.size); it = list.erase(it); found = true; } else if(found && (*it)->metadata.ohfiParent == obj->metadata.ohfi) {