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();
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);
}
"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;"
}
}
+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);
}
-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);
}
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);
}
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();
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,