]> uap-core.de Git - note.git/commitdiff
rename type Note to Resource
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 29 Mar 2025 07:13:54 +0000 (08:13 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 29 Mar 2025 07:13:54 +0000 (08:13 +0100)
13 files changed:
application/application.c
application/application.h
application/gtk-text.c
application/note.c
application/note.h
application/notebook.c
application/notebook.h
application/store.c
application/store.h
application/store_sqlite.c
application/types.c
application/types.h
application/window.c

index c6ebc214800b9e167562811b621c329c7c9ae9c6..24203429e5ffc83f0036e47e5790e955f2ec2ab4 100644 (file)
@@ -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,
index 62a7b76c1656bac0506c044b62d69728b42f79de..48d5e2e4a3d6b1fce0088bd4ad28cc8550353798 100644 (file)
@@ -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;
index 2f6a93500e78ac37403380f7a051acd9bb53add3..41156e99806b51308790164a0b45a2f4cfedca06 100644 (file)
@@ -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
index ae022485f63aaeb0e0fcbaa736a5cbdfaee395a2..e8306e4a5b4c353acbc569ddd12f7a7cfc41c14f 100644 (file)
@@ -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);
index e663d1ce877251fe3a8fe79f6e3d91977600db25..b3b559b06914be2242e4a141dd36b08bfecf8efe 100644 (file)
@@ -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
 }
index 58ea1ac3c35d4cef76c53f6b981dffa5dd96d738..295aed645777ed30167294750327e12abc8718c5 100644 (file)
@@ -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;
index 245ca85125ac399ff4697dcb4fa94d069a791dd0..205bd2f09ef1636f2f070da649a00ffce85e411a 100644 (file)
@@ -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
index 3d6758f60ac7f3201fd5f74d9a59aa986da95481..1226f036b1672d4df124db94555a1e4ddc13edde 100644 (file)
     "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;
index 629b3b3826cbf8281e0eedc66fb25080769d6c40..06527fd4ab393515de530181c452064627b05c66 100644 (file)
@@ -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
 }
index 881f2a13ba20283bc8a6da9b45f9038b41c2d60b..aca8c822254f497ca8823ba29570736c981e6be4 100644 (file)
@@ -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, " \
     ");"
 #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) {
index 6bc7737a5569d330ddc643ce0dcac0f95dda393d..66525e9d9635837eed35886b901cd2de44b0a86b 100644 (file)
@@ -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);
 }
index d95a26eae4820f33930ed1b37196df11d3a41478..3946d732d5b8d239f02ed7bc82bb01f827787ba5 100644 (file)
@@ -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
index 0f9458594ecaf2c7f5c2258315367a3305af0faf..440a48041e68c827464ecefb8fd0052d389f7cca 100644 (file)
@@ -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, &note_index) : NULL;
+    Resource *note = nav->note_id != 0 ? notebookmodel_get_note_by_id(notebook, nav->note_id, &note_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;