aboutsummaryrefslogtreecommitdiffstats
path: root/qt-mobile
diff options
context:
space:
mode:
Diffstat (limited to 'qt-mobile')
-rw-r--r--qt-mobile/qml/DiveDetails.qml5
-rw-r--r--qt-mobile/qmlmanager.cpp54
-rw-r--r--qt-mobile/qmlmanager.h3
3 files changed, 59 insertions, 3 deletions
diff --git a/qt-mobile/qml/DiveDetails.qml b/qt-mobile/qml/DiveDetails.qml
index 43b6c5e88..c5fb0e4f0 100644
--- a/qt-mobile/qml/DiveDetails.qml
+++ b/qt-mobile/qml/DiveDetails.qml
@@ -63,11 +63,12 @@ MobileComponents.Page {
text: "Delete dive"
iconName: "trash-empty"
onTriggered: {
- manager.deleteDive(diveDetailsListView.currentItem.modelData.dive.id)
+ var deletedId = diveDetailsListView.currentItem.modelData.dive.id
+ manager.deleteDive(deletedId)
var notification = notificationComponent.createObject(contentItem.parent);
notification.showNotification("Dive deleted", 3000, "Undo",
function() {
- print("now I need to undo!")
+ manager.undoDelete(deletedId)
});
contextDrawer.close()
stackView.pop()
diff --git a/qt-mobile/qmlmanager.cpp b/qt-mobile/qmlmanager.cpp
index b50b3c501..9a0a97f65 100644
--- a/qt-mobile/qmlmanager.cpp
+++ b/qt-mobile/qmlmanager.cpp
@@ -43,7 +43,9 @@ extern "C" int gitProgressCB(int percent)
QMLManager::QMLManager() : m_locationServiceEnabled(false),
m_verboseEnabled(false),
m_credentialStatus(UNKNOWN),
- reply(0)
+ reply(0),
+ deletedDive(0),
+ deletedTrip(0)
{
m_instance = this;
appendTextToLog(getUserAgent());
@@ -610,6 +612,34 @@ void QMLManager::saveChanges()
mark_divelist_changed(false);
}
+void QMLManager::undoDelete(int id)
+{
+ if (!deletedDive || deletedDive->id != id) {
+ qDebug() << "can't find the deleted dive";
+ return;
+ }
+ if (deletedTrip)
+ insert_trip(&deletedTrip);
+ if (deletedDive->divetrip) {
+ struct dive_trip *trip = deletedDive->divetrip;
+ tripflag_t tripflag = deletedDive->tripflag; // this gets overwritten in add_dive_to_trip()
+ deletedDive->divetrip = NULL;
+ deletedDive->next = NULL;
+ deletedDive->pprev = NULL;
+ add_dive_to_trip(deletedDive, trip);
+ deletedDive->tripflag = tripflag;
+ }
+ record_dive(deletedDive);
+ DiveListModel::instance()->addDive(deletedDive);
+ prefs.cloud_background_sync = false;
+ prefs.git_local_only = true;
+ saveChanges();
+ prefs.cloud_background_sync = true;
+ prefs.git_local_only = false;
+ deletedDive = NULL;
+ deletedTrip = NULL;
+}
+
void QMLManager::deleteDive(int id)
{
struct dive *d = get_dive_by_uniq_id(id);
@@ -617,6 +647,28 @@ void QMLManager::deleteDive(int id)
qDebug() << "oops, trying to delete non-existing dive";
return;
}
+ // clean up (or create) the storage for the deleted dive and trip (if applicable)
+ if (!deletedDive)
+ deletedDive = alloc_dive();
+ else
+ clear_dive(deletedDive);
+ copy_dive(d, deletedDive);
+ if (!deletedTrip) {
+ deletedTrip = (struct dive_trip *)calloc(1, sizeof(struct dive_trip));
+ } else {
+ free(deletedTrip->location);
+ free(deletedTrip->notes);
+ memset(deletedTrip, 0, sizeof(struct dive_trip));
+ }
+ // if this is the last dive in that trip, remember the trip as well
+ if (d->divetrip && d->divetrip->nrdives == 1) {
+ deletedTrip = (struct dive_trip *)calloc(1, sizeof(struct dive_trip));
+ *deletedTrip = *d->divetrip;
+ deletedTrip->location = copy_string(d->divetrip->location);
+ deletedTrip->notes = copy_string(d->divetrip->notes);
+ deletedTrip->nrdives = 0;
+ deletedDive->divetrip = deletedTrip;
+ }
DiveListModel::instance()->removeDiveById(id);
delete_single_dive(get_idx_by_uniq_id(id));
prefs.cloud_background_sync = false;
diff --git a/qt-mobile/qmlmanager.h b/qt-mobile/qmlmanager.h
index 33e356940..41ca2271f 100644
--- a/qt-mobile/qmlmanager.h
+++ b/qt-mobile/qmlmanager.h
@@ -92,6 +92,7 @@ public slots:
void saveChanges();
void deleteDive(int id);
+ void undoDelete(int id);
QString addDive();
void addDiveAborted(int id);
void applyGpsData();
@@ -125,6 +126,8 @@ private:
static QMLManager *m_instance;
QNetworkReply *reply;
QNetworkRequest request;
+ struct dive *deletedDive;
+ struct dive_trip *deletedTrip;
credentialStatus_t m_credentialStatus;