From: Olaf Wintermann Date: Sat, 29 Mar 2025 07:13:54 +0000 (+0100) Subject: rename type Note to Resource X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=b6f551cf0058b8861d59be9c6a44d548d2c148bc;p=note.git rename type Note to Resource --- diff --git a/application/application.c b/application/application.c index c6ebc21..2420342 100644 --- a/application/application.c +++ b/application/application.c @@ -143,7 +143,7 @@ static void delete_result(UiEvent *event, void *data) { void action_note_delete(UiEvent *event, void *data) { NotebookModel *notebook = event->document; - Note *note = notebook->current_note; + Resource *note = notebook->current_note; cxmutstr msg = cx_asprintf("Delete note %s?", note_get_title(note)); ui_dialog( event->obj, diff --git a/application/application.h b/application/application.h index 62a7b76..48d5e2e 100644 --- a/application/application.h +++ b/application/application.h @@ -117,7 +117,7 @@ struct NotebookModel { /* * currently attached note */ - Note *current_note; + Resource *current_note; /* * some actions might trigger unwanted selection events @@ -168,7 +168,7 @@ typedef struct AttachmentModel { UiContext *ctx; const CxAllocator *note_allocator; - Note *parent_note; + Resource *parent_note; int64_t resource_id; AttachmentType type; diff --git a/application/gtk-text.c b/application/gtk-text.c index 2f6a935..41156e9 100644 --- a/application/gtk-text.c +++ b/application/gtk-text.c @@ -305,7 +305,7 @@ static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf, char *att // add attachment to note MainWindow *wdata = editor->obj->window; - Note *note = wdata->current_notebook->current_note; + Resource *note = wdata->current_notebook->current_note; NoteModel *model = note->model; // TODO: this is just a test diff --git a/application/note.c b/application/note.c index ae02248..e8306e4 100644 --- a/application/note.c +++ b/application/note.c @@ -84,7 +84,7 @@ NoteModel* notemodel_create(const CxAllocator *note_allocator) { return model; } -void notemodel_set_note(NoteModel *model, Note *note) { +void notemodel_set_note(NoteModel *model, Resource *note) { note->model = model; ui_set(model->title, note->title); @@ -100,7 +100,7 @@ void notemodel_set_note(NoteModel *model, Note *note) { static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) { - Note *note = userdata; + Resource *note = userdata; note->content = result; printf("note content: %s\n", result.ptr); if(note->model) { @@ -109,11 +109,11 @@ static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) note->content_loaded = TRUE; } -void note_load_content(UiObject *obj, NotebookModel *notebook, Note *note) { - note_store_get_note_content_async(obj, notebook->current_notes_pool->allocator, note->note_id, note_content_loaded, note); +void note_load_content(UiObject *obj, NotebookModel *notebook, Resource *note) { + note_store_get_note_content_async(obj, notebook->current_notes_pool->allocator, note->resource_id, note_content_loaded, note); } -void note_save(UiObject *obj, NotebookModel *notebook, Note *note) { +void note_save(UiObject *obj, NotebookModel *notebook, Resource *note) { NoteModel *m = note->model; char *title = ui_get(m->title); @@ -129,7 +129,7 @@ void note_save(UiObject *obj, NotebookModel *notebook, Note *note) { cxFree(a, note->content.ptr); note->content = content; - if(note->note_id == 0) { + if(note->resource_id == 0) { // new note note_store_new_note_async(obj, note, NULL, NULL); notebook->disable_selection_events = TRUE; @@ -185,7 +185,7 @@ void note_text_style_set_code(NoteModel *note, UiBool enabled) { -void note_update_title(NotebookModel *notebook, Note *note) { +void note_update_title(NotebookModel *notebook, Resource *note) { int index = notebookmode_get_note_index(notebook, note); if(index < 0) { return; @@ -200,11 +200,11 @@ void note_update_title(NotebookModel *notebook, Note *note) { notebook->notes->update(notebook->notes, index); } -const char* note_get_title(Note *note) { +const char* note_get_title(Resource *note) { return note->title ? note->title : note->name; } -void note_destroy(const CxAllocator *a, Note *note) { +void note_destroy(const CxAllocator *a, Resource *note) { cxFree(a, note->name); cxFree(a, note->title); cxFree(a, note->lastmodified); diff --git a/application/note.h b/application/note.h index e663d1c..b3b559b 100644 --- a/application/note.h +++ b/application/note.h @@ -44,12 +44,12 @@ typedef struct TextNoteParagraphStyles { NoteModel *notemodel_current(UiObject *obj); NoteModel* notemodel_create(const CxAllocator *note_allocator); -void notemodel_set_note(NoteModel *model, Note *note); +void notemodel_set_note(NoteModel *model, Resource *note); // TODO: the interface is weird, but we need the NotebookModel for the allocator -void note_load_content(UiObject *obj, NotebookModel *notebook, Note *note); +void note_load_content(UiObject *obj, NotebookModel *notebook, Resource *note); -void note_save(UiObject *obj, NotebookModel *notebook, Note *note); +void note_save(UiObject *obj, NotebookModel *notebook, Resource *note); void note_update_current_style(NoteModel *note, MDActiveStyles *style); @@ -59,10 +59,10 @@ void note_text_style_set_emphasis(NoteModel *note, UiBool enabled); void note_text_style_set_underline(NoteModel *note, UiBool enabled); void note_text_style_set_code(NoteModel *note, UiBool enabled); -void note_update_title(NotebookModel *notebook, Note *note); +void note_update_title(NotebookModel *notebook, Resource *note); -const char* note_get_title(Note *note); -void note_destroy(const CxAllocator *a, Note *note); +const char* note_get_title(Resource *note); +void note_destroy(const CxAllocator *a, Resource *note); #ifdef __cplusplus } diff --git a/application/notebook.c b/application/notebook.c index 58ea1ac..295aed6 100644 --- a/application/notebook.c +++ b/application/notebook.c @@ -44,7 +44,7 @@ NotebookModel* notebookmodel_create() { return model; } -static void notelist_select_note(NotebookModel *model, Note *note) { +static void notelist_select_note(NotebookModel *model, Resource *note) { CxList *list = model->notes->data; // UiList uses CxList internally list->collection.cmpfunc = cx_cmp_ptr; int index = (int)cxListFind(list, note); @@ -100,7 +100,7 @@ static void notebook_loaded(UiEvent *event, AsyncListResult *result, void *data) if(result->list) { ui_list_clear(model->notes); CxIterator i = cxListIterator(result->list); - cx_foreach(Note *, note, i) { + cx_foreach(Resource *, note, i) { ui_list_append(model->notes, note); } ui_list_update(model->notes); @@ -115,7 +115,7 @@ void notebookmodel_reload(UiObject *obj, NotebookModel *model) { } -void notebookmodel_attach_note(NotebookModel *model, Note *note) { +void notebookmodel_attach_note(NotebookModel *model, Resource *note) { // TODO: enable this optimization when possible // currently, a reattaching a notebook will still have current_note // but the UI binding will not be enabled @@ -151,7 +151,7 @@ void notebookmodel_attach_note(NotebookModel *model, Note *note) { void notebookmodel_detach_current_note(NotebookModel *model) { if(model->current_note) { - Note *current_note = model->current_note; + Resource *current_note = model->current_note; // TODO: model->modified doesnt work yet, remove || 1 when it works if(current_note->model->modified || 1) { note_save(model->window->obj, model, model->current_note); @@ -171,11 +171,11 @@ void notebookmodel_detach_current_note(NotebookModel *model) { * * If index is not NULL, it is set to the index in the model->notes list */ -Note* notebookmodel_get_note_by_id(NotebookModel *model, int64_t note_id, size_t *index) { +Resource* notebookmodel_get_note_by_id(NotebookModel *model, int64_t note_id, size_t *index) { CxList *list = model->notes->data; // UiList is based on CxList CxIterator i = cxListIterator(list); - cx_foreach(Note *, note, i) { - if(note->note_id == note_id) { + cx_foreach(Resource *, note, i) { + if(note->resource_id == note_id) { if(index) { *index = i.index; } @@ -187,8 +187,8 @@ Note* notebookmodel_get_note_by_id(NotebookModel *model, int64_t note_id, size_t void notebookmodel_new_note(NotebookModel *model) { - Note *new_note = cxMalloc(model->current_notes_pool->allocator, sizeof(Note)); - memset(new_note, 0, sizeof(Note)); + Resource *new_note = cxMalloc(model->current_notes_pool->allocator, sizeof(Resource)); + memset(new_note, 0, sizeof(Resource)); new_note->parent_id = model->collection->collection_id; notebookmodel_attach_note(model, new_note); @@ -200,7 +200,7 @@ void notebookmodel_new_note(NotebookModel *model) { typedef struct NoteDeleteOp { NotebookModel *notebook; - Note *note; + Resource *note; } NoteDeleteOp; static void note_deleted(UiEvent *event, int error, void *userdata) { @@ -242,7 +242,7 @@ void notebookmodel_add2navstack(NotebookModel *model) { // init NavStack element NavStack nav; nav.collection_id = model->collection_id; - nav.note_id = model->current_note ? model->current_note->note_id : 0; + nav.note_id = model->current_note ? model->current_note->resource_id : 0; nav.view_flags = 0; if(!list_visible) { @@ -271,7 +271,7 @@ void notebookmodel_add2navstack(NotebookModel *model) { */ } -int notebookmode_get_note_index(NotebookModel *model, Note *note) { +int notebookmode_get_note_index(NotebookModel *model, Resource *note) { CxList *list = model->notes->data; size_t index = cxListFind(list, note); return cxListIndexValid(list, index) ? index : -1; diff --git a/application/notebook.h b/application/notebook.h index 245ca85..205bd2f 100644 --- a/application/notebook.h +++ b/application/notebook.h @@ -46,17 +46,17 @@ void notebookmodel_set_collection(NotebookModel *model, Collection *collection); void notebookmodel_reload(UiObject *obj, NotebookModel *model); -void notebookmodel_attach_note(NotebookModel *model, Note *note); +void notebookmodel_attach_note(NotebookModel *model, Resource *note); void notebookmodel_detach_current_note(NotebookModel *model); -Note* notebookmodel_get_note_by_id(NotebookModel *model, int64_t note_id, size_t *index); +Resource* notebookmodel_get_note_by_id(NotebookModel *model, int64_t note_id, size_t *index); void notebookmodel_new_note(NotebookModel *model); void notebookmodel_delete_note(NotebookModel *model); void notebookmodel_add2navstack(NotebookModel *model); -int notebookmode_get_note_index(NotebookModel *model, Note *note); +int notebookmode_get_note_index(NotebookModel *model, Resource *note); #ifdef __cplusplus diff --git a/application/store.c b/application/store.c index 3d6758f..1226f03 100644 --- a/application/store.c +++ b/application/store.c @@ -55,20 +55,20 @@ "select * from cols\n" \ "order by path;" -#define SQL_NOTEBOOK_GET_NOTES "select note_id, parent_id, name, title, lastmodified, creationdate, contenttype, created_by from notes where parent_id = ? ;" +#define SQL_NOTEBOOK_GET_NOTES "select resource_id, parent_id, name, title, lastmodified, creationdate, contenttype, created_by from resources where parent_id = ? ;" -#define SQL_NOTE_GET_CONTENT "select content, bin_content from notes where note_id = ? ;" +#define SQL_NOTE_GET_CONTENT "select content, bin_content from resources where resource_id = ? ;" -#define SQL_NOTE_NEW "insert into notes(parent_id, name, title, lastmodified, creationdate, content) values (?, ?, ?, datetime(), datetime(), ?) returning note_id;" +#define SQL_NOTE_NEW "insert into resources(parent_id, name, title, lastmodified, creationdate, content) values (?, ?, ?, datetime(), datetime(), ?) returning resource_id;" -#define SQL_NOTE_SAVE "update notes set name = ? ," \ +#define SQL_NOTE_SAVE "update resources set name = ? ," \ "title = ? ," \ "content = ? " \ - "where note_id = ? ;" + "where resource_id = ? ;" -#define SQL_NOTE_MOVE_TO_TRASH "update notes set parent_id = ? where note_id = ? ;" +#define SQL_NOTE_MOVE_TO_TRASH "update resources set parent_id = ? where resource_id = ? ;" -#define SQL_NOTE_DELETE "delete from notes where note_id = ? ;" +#define SQL_NOTE_DELETE "delete from resources where resource_id = ? ;" static DBUConnection *connection; @@ -477,7 +477,7 @@ void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int6 typedef struct SaveNoteJob { - Note *note; + Resource *note; execresult_func resultcb; void *userdata; int error; @@ -491,7 +491,7 @@ static void uithr_save_note_finished(UiEvent *event, SaveNoteJob *job) { } static int qthr_new_note(SaveNoteJob *job) { - Note *n = job->note; + Resource *n = job->note; DBUQuery *q = connection->createQuery(connection, NULL); dbuQuerySetSQL(q, SQL_NOTE_NEW); dbuQuerySetParamInt64(q, 1, n->parent_id); @@ -507,7 +507,7 @@ static int qthr_new_note(SaveNoteJob *job) { if(new_id_str.ptr) { long long new_id = 0; cx_strtoll(new_id_str, &new_id, 10); - n->note_id = new_id; + n->resource_id = new_id; } } else { job->error = 2; @@ -519,7 +519,7 @@ static int qthr_new_note(SaveNoteJob *job) { return 0; } -void note_store_new_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) { +void note_store_new_note_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata) { SaveNoteJob *job = malloc(sizeof(SaveNoteJob)); job->note = note; job->resultcb = resultcb; @@ -530,13 +530,13 @@ void note_store_new_note_async(UiObject *obj, Note *note, execresult_func result static int qthr_save_note(SaveNoteJob *job) { - Note *n = job->note; + Resource *n = job->note; DBUQuery *q = connection->createQuery(connection, NULL); dbuQuerySetSQL(q, SQL_NOTE_SAVE); dbuQuerySetParamString(q, 1, cx_str(n->title)); dbuQuerySetParamString(q, 2, cx_str(n->title)); dbuQuerySetParamString(q, 3, cx_strcast(n->content)); - dbuQuerySetParamInt64(q, 4, n->note_id); + dbuQuerySetParamInt64(q, 4, n->resource_id); if(dbuQueryExec(q)) { job->error = 1; } else { @@ -551,7 +551,7 @@ static int qthr_save_note(SaveNoteJob *job) { return 0; } -void note_store_save_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) { +void note_store_save_note_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata) { SaveNoteJob *job = malloc(sizeof(SaveNoteJob)); job->note = note; job->resultcb = resultcb; @@ -593,9 +593,9 @@ static void uithr_save_delete_finished(UiEvent *event, DeleteNoteJob *job) { free(job); } -void note_store_delete_async(UiObject *obj, Note *note, UiBool move_to_trash, execresult_func resultcb, void *userdata) { +void note_store_delete_async(UiObject *obj, Resource *note, UiBool move_to_trash, execresult_func resultcb, void *userdata) { DeleteNoteJob *job = malloc(sizeof(DeleteNoteJob)); - job->note_id = note->note_id; + job->note_id = note->resource_id; job->move_to_trash = move_to_trash; job->resultcb = resultcb; job->userdata = userdata; diff --git a/application/store.h b/application/store.h index 629b3b3..06527fd 100644 --- a/application/store.h +++ b/application/store.h @@ -87,10 +87,10 @@ void note_store_get_notes_async(UiObject *obj, int64_t parent_collection_id, lis cxmutstr note_store_get_note_content(const CxAllocator *a, int64_t note_id); void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int64_t note_id, stringresult_func resultcb, void *userdata); -void note_store_new_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata); -void note_store_save_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata); +void note_store_new_note_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata); +void note_store_save_note_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata); -void note_store_delete_async(UiObject *obj, Note *note, UiBool move_to_trash, execresult_func resultcb, void *userdata); +void note_store_delete_async(UiObject *obj, Resource *note, UiBool move_to_trash, execresult_func resultcb, void *userdata); #ifdef __cplusplus } diff --git a/application/store_sqlite.c b/application/store_sqlite.c index 881f2a1..aca8c82 100644 --- a/application/store_sqlite.c +++ b/application/store_sqlite.c @@ -67,8 +67,8 @@ "foreign key (default_collection_id) references collections(collection_id), " \ "unique (host, user, profile_name)" \ ");" -#define SQL_CREATE_TABLE_NOTES "create table notes( " \ - "note_id integer primary key, " \ +#define SQL_CREATE_TABLE_NOTES "create table resources( " \ + "resource_id integer primary key, " \ "parent_id integer, " \ "name text, " \ "title text, " \ @@ -83,11 +83,11 @@ ");" #define SQL_CREATE_TABLE_ATTACHMENTS "create table attachments( " \ "attachment_id integer primary key, " \ - "resource_id integer, " \ - "parent_id integer, " \ + "attachment_resource_id integer, " \ + "parent_resource_id integer, " \ "type integer , " \ - "foreign key (resource_id) references notes(note_id), " \ - "foreign key (parent_id) references notes(note_id) " \ + "foreign key (attachment_resource_id) references resources(resource_id), " \ + "foreign key (parent_resource_id) references resources(resource_id) " \ ");" int store_sqlite_init_db(DBUConnection *connection) { diff --git a/application/types.c b/application/types.c index 6bc7737..66525e9 100644 --- a/application/types.c +++ b/application/types.c @@ -58,18 +58,18 @@ void register_types() { dbuClassAdd(collection_class, Collection, display_name); dbuClassAdd(collection_class, Collection, type); - notes_class = dbuRegisterClass(ctx, "notes", Note, note_id); - dbuClassAdd(notes_class, Note, parent_id); - dbuClassAdd(notes_class, Note, name); - dbuClassAdd(notes_class, Note, title); - dbuClassAdd(notes_class, Note, lastmodified); - dbuClassAdd(notes_class, Note, creationdate); - dbuClassAdd(notes_class, Note, contenttype); - dbuClassAdd(notes_class, Note, contentlength); - dbuClassAdd(notes_class, Note, content); - dbuClassAdd(notes_class, Note, bin_content); - dbuClassAdd(notes_class, Note, created_by); - dbuClassAdd(notes_class, Note, content_loaded); + notes_class = dbuRegisterClass(ctx, "resources", Resource, resource_id); + dbuClassAdd(notes_class, Resource, parent_id); + dbuClassAdd(notes_class, Resource, name); + dbuClassAdd(notes_class, Resource, title); + dbuClassAdd(notes_class, Resource, lastmodified); + dbuClassAdd(notes_class, Resource, creationdate); + dbuClassAdd(notes_class, Resource, contenttype); + dbuClassAdd(notes_class, Resource, contentlength); + dbuClassAdd(notes_class, Resource, content); + dbuClassAdd(notes_class, Resource, bin_content); + dbuClassAdd(notes_class, Resource, created_by); + dbuClassAdd(notes_class, Resource, content_loaded); repository_class = dbuRegisterClass(ctx, "repositories", Repository, repository_id); dbuClassAdd(repository_class, Repository, name); @@ -80,7 +80,7 @@ void register_types() { dbuClassAdd(repository_class, Repository, encryption); attachments_class = dbuRegisterClass(ctx, "attachments", Attachment, attachment_id); - dbuClassAdd(attachments_class, Attachment, resource_id); - dbuClassAdd(attachments_class, Attachment, parent_id); + dbuClassAdd(attachments_class, Attachment, attachment_resource_id); + dbuClassAdd(attachments_class, Attachment, parent_resource_id); dbuClassAdd(attachments_class, Attachment, type); } diff --git a/application/types.h b/application/types.h index d95a26e..3946d73 100644 --- a/application/types.h +++ b/application/types.h @@ -44,7 +44,7 @@ typedef struct NoteModel NoteModel; typedef struct UserSettings UserSettings; typedef struct Repository Repository; typedef struct Collection Collection; -typedef struct Note Note; +typedef struct Resource Resource; typedef struct Attachment Attachment; struct UserSettings { @@ -78,8 +78,8 @@ struct Collection { CxList *children; }; -struct Note { - int64_t note_id; +struct Resource { + int64_t resource_id; int64_t parent_id; char *name; char *title; @@ -108,8 +108,8 @@ struct Attachment { // db fields int64_t attachment_id; - int64_t resource_id; - int64_t parent_id; + int64_t attachment_resource_id; + int64_t parent_resource_id; int type; // temp fields diff --git a/application/window.c b/application/window.c index 0f94585..440a480 100644 --- a/application/window.c +++ b/application/window.c @@ -197,7 +197,7 @@ void update_sublists(UiContext *ctx, UiList *sublists) { } void* window_notelist_getvalue(void *data, int col) { - Note *note = data; + Resource *note = data; switch(col) { case 0: { return note->title ? note->title : note->name; @@ -232,7 +232,7 @@ void window_navigate(MainWindow *window, NavStack *nav) { } size_t note_index; - Note *note = nav->note_id != 0 ? notebookmodel_get_note_by_id(notebook, nav->note_id, ¬e_index) : NULL; + Resource *note = nav->note_id != 0 ? notebookmodel_get_note_by_id(notebook, nav->note_id, ¬e_index) : NULL; window_notelist_setvisible(window, !(nav->view_flags & VIEW_FLAGS_NO_BROWSER)); @@ -296,7 +296,7 @@ static int select_note(UiEvent *event) { return 0; } - Note *note = ui_list_get(notebook->notes, sel->rows[0]); + Resource *note = ui_list_get(notebook->notes, sel->rows[0]); notebookmodel_attach_note(notebook, note); return 1;