From: Olaf Wintermann Date: Mon, 19 Jan 2026 19:17:00 +0000 (+0100) Subject: add note_store_collection_get_size_async X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=c9f5e1e219500989e2992a77c7c977e68a298fe8;p=note.git add note_store_collection_get_size_async --- diff --git a/application/nbconfig.c b/application/nbconfig.c index aa93411..47822e0 100644 --- a/application/nbconfig.c +++ b/application/nbconfig.c @@ -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); } diff --git a/application/nbconfig.h b/application/nbconfig.h index 942a899..84fc334 100644 --- a/application/nbconfig.h +++ b/application/nbconfig.h @@ -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); diff --git a/application/store.c b/application/store.c index 7484d40..382ffd4 100644 --- a/application/store.c +++ b/application/store.c @@ -124,6 +124,9 @@ "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); } diff --git a/application/store.h b/application/store.h index 319e9c3..99afa5d 100644 --- a/application/store.h +++ b/application/store.h @@ -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,