]> uap-core.de Git - note.git/commitdiff
add note_store_collection_get_size_async
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 19 Jan 2026 19:17:00 +0000 (20:17 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 19 Jan 2026 19:17:00 +0000 (20:17 +0100)
application/nbconfig.c
application/nbconfig.h
application/store.c
application/store.h

index aa93411587f2cf5f40153ede68725646b5639c31..47822e075784ef40366fcef806fa614f25f1a3c4 100644 (file)
@@ -417,6 +417,21 @@ static void nbconfig_notebooklist_name_changed(UiEvent *event, void *userdata) {
     wdata->valuechange = FALSE;
 }
 
+static void notebook_count_children_result(UiEvent *event, int64_t num, int error, void *userdata) {
+    Resource *res = userdata;
+    if(error != 0) {
+        fprintf(stderr, "note_store_collection_get_size_async failed\n");
+        // TODO: show error
+        return;
+    }
+    
+    if(num > 0) {
+        
+    } else {
+        
+    }
+}
+
 static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) {
     NotebookConfigDialog *wdata = event->window;
     NoteStore *store = note_store_get();
@@ -424,8 +439,8 @@ static void nbconfig_notebooklist_delete(UiEvent *event, void *userdata) {
     UiListSelection sel = ui_list_getselection(wdata->tab2_notebooks);
     if(sel.count == 1) {
         CxList *list = wdata->notebooks;
-        cxListRemove(list, sel.rows[0]);
-        nbconfig_update_lists(wdata);
+        Resource *delete_res = cxListAt(list, sel.rows[0]);
+        note_store_collection_get_size_async(event->obj, delete_res, notebook_count_children_result, delete_res);
     }
     ui_listselection_free(sel);
 }
index 942a8995a9ce6abaec28664007bc20cf1e187808..84fc3343c0dd21156dc6c71c132850ba033fbff1 100644 (file)
@@ -73,7 +73,7 @@ typedef struct NotebookConfigDialog {
     // set to true if currently a textfield onchange callback is running
     UiBool valuechange;
 } NotebookConfigDialog;
-    
+  
 void nbconfig_update_list(NotebookConfigDialog *wdata, CxList *list, int index);
 void nbconfig_update_lists(NotebookConfigDialog *wdata);
 
index 7484d4006f8aeb408e3f51fd1bd69d4b3412e0c9..382ffd42ec6b91b838f351e6af00117ac9eb11d4 100644 (file)
     "end " \
     "where notebook_id in (?1, ?2);"
 
+#define SQL_NOTEBOOK_COUNT_CHILDREN \
+    "select count(*) from resources where parent_id = ?;"
+
 #define SQL_REPOSITORY_NEW \
     "insert into repositories(name, url, encryption, default_key, authmethod, local_path) " \
     "values (?, ?, ?, ?, ?, ?) repository_id;"
@@ -1148,6 +1151,50 @@ void note_store_save_notebook_async(UiObject *obj, Resource *res, int64_t prev_p
     }
 }
 
+typedef struct CountJob {
+    countresult_func resultcb;
+    void *userdata;
+    int64_t id1;
+    int64_t id2;
+    int64_t num;
+    int error;
+} CountJob;
+
+static int qthr_collection_get_size(CountJob *job) {
+    DBUResult *result = dbuSqlExecParamInt64(connection, NULL, SQL_NOTEBOOK_COUNT_CHILDREN, job->id1);
+    if(!result) {
+        job->error = 1;
+        return 0;
+    }
+    if(dbuResultAsInt64(result, &job->num)) {
+        job->error = 2;
+    }
+    return 0;
+}
+
+static void uithr_collection_get_size_finished(UiEvent *event, CountJob *job) {
+    if(job->resultcb) {
+        job->resultcb(event, job->num, job->error, job->userdata);
+    }
+    free(job);
+}
+
+void note_store_collection_get_size_async(
+        UiObject *obj,
+        Resource *res,
+        countresult_func resultcb,
+        void *userdata)
+{
+    CountJob *job = malloc(sizeof(CountJob));
+    job->resultcb = resultcb;
+    job->userdata = userdata;
+    job->id1 = res->resource_id;
+    job->id2 = -1;
+    job->num = 0;
+    job->error = 0;
+    ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_collection_get_size, job, (ui_callback)uithr_collection_get_size_finished, job);
+}
+
 static void uithr_execjob_finished(UiEvent *event, ExecJob *job) {
     job->resultcb(event, job->error, job->userdata);
     free(job);
@@ -1333,16 +1380,9 @@ void note_store_save_repository_async(UiObject *obj, Repository *repository, exe
 }
 
 
-typedef struct CountJob {
-    countresult_func resultcb;
-    void *userdata;
-    int64_t id1;
-    int64_t id2;
-    int64_t num;
-} CountJob;
 
 static void uithr_countjob_finished(UiEvent *event, CountJob *job) {
-    job->resultcb(event, job->num, job->userdata);
+    job->resultcb(event, job->num, job->error, job->userdata);
     free(job);
 }
 
@@ -1367,5 +1407,6 @@ void note_store_count_repository_usage_async(UiObject *obj, Repository *reposito
     job->id1 = repository->repository_id;
     job->id2 = 0;
     job->num = -1;
+    job->error = 0;
     ui_threadpool_job(queue, obj, (ui_threadfunc)qthr_count_repo_usage, job, (ui_callback)uithr_countjob_finished, job);
 }
index 319e9c3ce66a609b5c9822d04a1e0d003e6d8e8f..99afa5dfa752c3eb723adb95370adc8633a71933 100644 (file)
@@ -83,7 +83,7 @@ typedef void (*stringresult_func)(UiEvent *event, cxmutstr result, void *userdat
 typedef void (*execresult_func)(UiEvent *event, int error, void *userdata);
 
 typedef void (*createresult_func)(UiEvent *event, int64_t newid, int error, void *userdata);
-typedef void (*countresult_func)(UiEvent *event, int64_t n, void *userdata);
+typedef void (*countresult_func)(UiEvent *event, int64_t n, int error, void *userdata);
 
 int init_note_store();
 
@@ -142,6 +142,12 @@ void note_store_update_resource_async(UiObject *obj, Resource *res, execresult_f
 
 void note_store_save_notebook_async(UiObject *obj, Resource *res, int64_t prev_parent_id, execresult_func resultcb, void *userdata);
 
+void note_store_collection_get_size_async(
+        UiObject *obj,
+        Resource *res,
+        countresult_func resultcb,
+        void *userdata);
+
 void note_store_delete_empty_collection_async(
         UiObject *obj,
         Resource *res,