]> uap-core.de Git - note.git/commitdiff
use new Note struct in case of Resource
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 5 May 2025 19:05:31 +0000 (21:05 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 5 May 2025 19:05:31 +0000 (21:05 +0200)
17 files changed:
application/application.c
application/application.h
application/attachment.c
application/attachment.h
application/editor.c
application/editor.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 24203429e5ffc83f0036e47e5790e955f2ec2ab4..df3096cc64b06bffc6e93a2fc05ca43a59577235 100644 (file)
@@ -143,8 +143,8 @@ static void delete_result(UiEvent *event, void *data) {
 
 void action_note_delete(UiEvent *event, void *data) {
     NotebookModel *notebook = event->document;
-    Resource *note = notebook->current_note;
-    cxmutstr msg = cx_asprintf("Delete note %s?", note_get_title(note));
+    Note *note = notebook->current_note;
+    cxmutstr msg = cx_asprintf("Delete note %s?", note_get_title(note->resource));
     ui_dialog(
             event->obj,
             .title = "Delete Note",
index a70fab80723e256dc70241ae052b917b761c6c16..6fb9817c670dcc5566f5192bff74e939d2bed1b4 100644 (file)
@@ -117,7 +117,7 @@ struct NotebookModel {
     /*
      * currently attached note
      */
-    Resource *current_note;
+    Note *current_note;
     
     /*
      * some actions might trigger unwanted selection events
@@ -163,7 +163,7 @@ typedef struct AttachmentModel {
     UiContext *ctx;
     const CxAllocator *note_allocator;
     
-    Resource *parent_note;
+    Note *parent_note;
     
     UiGeneric *img;
 } AttachmentModel;
@@ -171,7 +171,7 @@ typedef struct AttachmentModel {
 typedef struct AttachmentWindow {
     UiObject *obj;
     
-    Resource *resource;
+    Note *note;
     UiList *attachments;
     int current_index;
     
index be271fd8e57259e30e319eb40f9a2a2d2b38dfb7..c5cf9ba7fd1c032722548bc697c9f063117978cc 100644 (file)
@@ -48,7 +48,7 @@ Attachment* attachment_create(
     return attachment;
 }
 
-void attachment_create_ui_model(UiContext *ctx, Attachment *attachment, Resource *resource) {
+void attachment_create_ui_model(UiContext *ctx, Attachment *attachment, Note *note) {
     if(attachment->ui) {
         return;
     }
@@ -61,9 +61,9 @@ void attachment_create_ui_model(UiContext *ctx, Attachment *attachment, Resource
         model->img = ui_generic_new(ctx, NULL);
     }
     model->ctx = ctx;
-    model->note_allocator = resource->model->note_allocator;
+    model->note_allocator = note->model->note_allocator;
     
-    model->parent_note = resource;
+    model->parent_note = note;
 }
 
 /*
@@ -172,12 +172,12 @@ void action_attachment_clicked(UiEvent *event, void *userdata) {
  * selected_attachment (optional): if non null, this attachment will be  pre-
  *                                 selected in the window
  */
-UiObject* attachment_window_create(Resource *resource, Attachment *selected_attachment) {
-    cxmutstr title = cx_asprintf("%s - attachments", note_get_title(resource));
+UiObject* attachment_window_create(Note *note, Attachment *selected_attachment) {
+    cxmutstr title = cx_asprintf("%s - attachments", note_get_title(note->resource));
     UiObject *obj = ui_simple_window(title.ptr, NULL);
     free(title.ptr);
     
-    AttachmentWindow *wdata = attachment_window_create_data(obj, resource);
+    AttachmentWindow *wdata = attachment_window_create_data(obj, note);
     obj->window = wdata;
     
     // create UI
@@ -218,17 +218,17 @@ static void update_attachments(AttachmentWindow *wdata, NoteModel *model) {
 /*
  * creates and initializes the AttachmentWindow window data object
  */
-AttachmentWindow* attachment_window_create_data(UiObject *obj, Resource *resource) {
+AttachmentWindow* attachment_window_create_data(UiObject *obj, Note *note) {
     AttachmentWindow *wdata = ui_malloc(obj->ctx, sizeof(AttachmentWindow));
     memset(wdata, 0, sizeof(AttachmentWindow));
     
     wdata->obj = obj;
-    wdata->resource = resource;
+    wdata->note = note;
     wdata->attachments = ui_list_new(obj->ctx, NULL);
     wdata->image = ui_generic_new(obj->ctx, NULL);
     wdata->current_index = -1;
     
-    update_attachments(wdata, resource->model);
+    update_attachments(wdata, note->model);
     
     return wdata;
 }
index 377628626aba53c8fc7c7edf8297a9dbfa4dd495..b738fb7fdd427729dcdf7eee52ac12c3d250a1e3 100644 (file)
@@ -42,7 +42,7 @@ Attachment* attachment_create(
         AttachmentType type,
         const char *name);
 
-void attachment_create_ui_model(UiContext *ctx, Attachment *attachment, Resource *resource);
+void attachment_create_ui_model(UiContext *ctx, Attachment *attachment, Note *note);
 
 void attachment_set_image(Attachment *attachment, void *img);
 
@@ -62,9 +62,9 @@ void attachment_item(UiObject *obj, int index, void *elm, void *userdata);
 
 void action_attachment_clicked(UiEvent *event, void *userdata);
 
-UiObject* attachment_window_create(Resource *resource, Attachment *selected_attachment);
+UiObject* attachment_window_create(Note *note, Attachment *selected_attachment);
 
-AttachmentWindow* attachment_window_create_data(UiObject *obj, Resource *resource);
+AttachmentWindow* attachment_window_create_data(UiObject *obj, Note *note);
 
 void attachment_window_set_image(AttachmentWindow *wdata, Attachment *attachment);
 
index a1fedec8aec67206f9074a364ee5d500cea2bb09..00da427a65111e652f2433781f771dd9216dd525 100644 (file)
@@ -36,7 +36,7 @@
 #include <libidav/utils.h> // url encoding/decoding
 
 
-void editor_load_markdown(Resource *note, UIWIDGET textview, cxmutstr markdown) {
+void editor_load_markdown(Note *note, UIWIDGET textview, cxmutstr markdown) {
     UiText *text = note->model->text;
     // make sure the textbuf is initialized
     editor_init_textbuf(text);
index 41c03ddfccf50090ca97ace857aa23ebfe8878c4..7069a50c103177b84c67a88f06329d94327916d7 100644 (file)
@@ -118,7 +118,7 @@ struct MDActiveStyles {
     
 void editor_init(UiText *text);
     
-void editor_load_markdown(Resource *note, UIWIDGET textview, cxmutstr markdown);
+void editor_load_markdown(Note *note, UIWIDGET textview, cxmutstr markdown);
 
 MDDoc* parse_markdown(cxstring markdown);
 void mddoc_free(MDDoc *doc);
@@ -133,7 +133,7 @@ MDDocLinear mddoc_linearization(MDDoc *doc);
 void editor_global_init();
 void editor_init_textview(UiObject *obj, UIWIDGET textview);
 void editor_init_textbuf(UiText *text);
-void editor_apply_styles(Resource *note, UIWIDGET textview, UiText *text, CxList /* MDDocStyleSection */ *styles);
+void editor_apply_styles(Note *note, UIWIDGET textview, UiText *text, CxList /* MDDocStyleSection */ *styles);
 cxmutstr editor_get_markdown(UiText *text, const CxAllocator *a);
 
 UiBool editor_set_style(UiText *text, const char *style, UiBool enabled);
index f876044bf5a1f69940501882ca3f3ed8d377c265..cd896fd1f2fba1523ea7cacfebed83d57dee005a 100644 (file)
@@ -364,7 +364,7 @@ static void editor_insert_image(NoteEditor *editor, Attachment *attachment, GtkT
 
 static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf, char *attachment_path) {
     MainWindow *wdata = editor->obj->window;
-    Resource *note = wdata->current_notebook->current_note;
+    Note *note = wdata->current_notebook->current_note;
     NoteModel *model = note->model;
     
     // create attachment
@@ -837,7 +837,7 @@ void init_tagtable(GtkTextTagTable *table) {
 /*
  * Applies all styles from the MDDocStyleSection list to the text buffer
  */
-void editor_apply_styles(Resource *note, UIWIDGET textview, UiText *text, CxList /* MDDocStyleSection */ *styles) {
+void editor_apply_styles(Note *note, UIWIDGET textview, UiText *text, CxList /* MDDocStyleSection */ *styles) {
     GtkTextBuffer *buffer = text->data1;
     GtkTextTagTable *tagtable = gtk_text_buffer_get_tag_table(buffer);
     NoteEditor *editor = g_object_get_data(G_OBJECT(textview), "editor");
@@ -878,7 +878,7 @@ void editor_apply_styles(Resource *note, UIWIDGET textview, UiText *text, CxList
         GtkTextIter iter;
         gtk_text_buffer_get_iter_at_offset(buffer, &iter, sec->pos);
         if(sec->length == MDDocStyleSection_IMAGE) {
-            Attachment *attachment = note_get_attachment(note, sec->link);
+            Attachment *attachment = note_get_attachment(note->resource, sec->link);
             if(attachment && attachment->ui->img->value) {  
                 editor_insert_image(editor, attachment, &iter);
             } else {
index ffa0d94faa09b612ce6c1e82537a870680f8678f..e19cd270919ce9882747e215276e8a27663ce456 100644 (file)
@@ -87,34 +87,32 @@ NoteModel* notemodel_create(const CxAllocator *note_allocator) {
     return model;
 }
 
-void notemodel_set_note(NoteModel *model, Resource *note) {
+void notemodel_set_note(NoteModel *model, Note *note) {
     note->model = model;
     
-    ui_set(model->title, note->displayname);
+    ui_set(model->title, note->resource->displayname);
     
-    if(note->content_loaded) {
+    if(note->resource->content_loaded) {
         // TODO: when multiple note types are implemented, check contenttype
         //       and set model->text, model->html or something else
-        if(!note->contenttype) {
-            ui_set(model->text, note->content.ptr);
-        }
+        ui_set(model->text, note->resource->content.ptr);
     }
 }
 
 typedef struct LoadNoteContent {
-    Resource *note;
+    Note *note;
     UiBool content;
     UiBool attachments;
 } LoadNoteContent;
 
 static void note_loading_completed(UiObject *obj, LoadNoteContent *op) {
-    Resource *note = op->note;
+    Note *note = op->note;
     MainWindow *wdata = obj->window;
     free(op);
     
     if(note->model) {
         // fill attachment model
-        CxIterator i = cxListIterator(note->attachments);
+        CxIterator i = cxListIterator(note->resource->attachments);
         cx_foreach(Attachment *, attachment, i) {
             ui_list_append(note->model->attachments, attachment);
             if(attachment_set_image_from_data(attachment, attachment->content)) {
@@ -127,14 +125,14 @@ static void note_loading_completed(UiObject *obj, LoadNoteContent *op) {
             ui_set_group(obj->ctx, APP_STATE_NOTE_HAS_ATTACHMENTS);
         }
         
-        editor_load_markdown(note, wdata->textview, note->content);
+        editor_load_markdown(note, wdata->textview, note->resource->content);
     }
-    note->content_loaded = TRUE;
+    note->resource->content_loaded = TRUE;
 }
 
 static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) {
     LoadNoteContent *op = userdata;
-    op->note->content = result;
+    op->note->resource->content = result;
     printf("note content: %s\n", result.ptr);
     op->content = TRUE;
     if(op->attachments) {
@@ -146,8 +144,8 @@ static void note_attachments_loaded(UiEvent *event, int error, void *userdata) {
     LoadNoteContent *op = userdata;
     op->attachments = TRUE;
     
-    if(op->note->attachments) {
-        CxIterator i = cxListIterator(op->note->attachments);
+    if(op->note->resource->attachments) {
+        CxIterator i = cxListIterator(op->note->resource->attachments);
         cx_foreach(Attachment *, attachment, i) {
             attachment_create_ui_model(op->note->model->ctx, attachment, op->note);
             if(attachment->content.length > 0) {
@@ -162,7 +160,7 @@ static void note_attachments_loaded(UiEvent *event, int error, void *userdata) {
     }
 }
 
-void note_load_content(UiObject *obj, NotebookModel *notebook, Resource *note) {
+void note_load_content(UiObject *obj, NotebookModel *notebook, Note *note) {
     LoadNoteContent *op = malloc(sizeof(LoadNoteContent));
     op->note = note;
     op->content = FALSE;
@@ -172,28 +170,28 @@ void note_load_content(UiObject *obj, NotebookModel *notebook, Resource *note) {
     note_store_load_note_attachments_async(obj, note, note_attachments_loaded, op);
 }
 
-void note_add_attachment(Resource *note, Attachment *attachment) {
-    if(!note->attachments) {
-        note->attachments = cxArrayListCreate(note->model->note_allocator, NULL, CX_STORE_POINTERS, 8);
+void note_add_attachment(Note *note, Attachment *attachment) {
+    if(!note->resource->attachments) {
+        note->resource->attachments = cxArrayListCreate(note->model->note_allocator, NULL, CX_STORE_POINTERS, 8);
     }
-    cxListAdd(note->attachments, attachment);
+    cxListAdd(note->resource->attachments, attachment);
 }
 
-void note_save(UiObject *obj, NotebookModel *notebook, Resource *note) {
+void note_save(UiObject *obj, NotebookModel *notebook, Note *note) {
     NoteModel *m = note->model;
     
     char *title = ui_get(m->title);
     const CxAllocator *a = notebook->current_notes_pool->allocator;
     
-    cxFree(a, note->displayname);
-    note->displayname = cx_strdup_a(a, cx_str(title)).ptr;
+    cxFree(a, note->resource->displayname);
+    note->resource->displayname = cx_strdup_a(a, cx_str(title)).ptr;
     
-    cxFree(a, note->nodename);
-    note->nodename = cx_strdup_a(a, cx_str(title)).ptr;
+    cxFree(a, note->resource->nodename);
+    note->resource->nodename = cx_strdup_a(a, cx_str(title)).ptr;
     
     cxmutstr content = editor_get_markdown(m->text, a);
-    cxFree(a, note->content.ptr);
-    note->content = content;
+    cxFree(a, note->resource->content.ptr);
+    note->resource->content = content;
     
     if(note->resource_id == 0) {
         // new note
@@ -202,8 +200,8 @@ void note_save(UiObject *obj, NotebookModel *notebook, Resource *note) {
         note_store_save_note_async(obj, note, NULL, NULL);
     }
     
-    if(note->attachments) {
-        CxIterator i = cxListIterator(note->attachments);
+    if(note->resource->attachments) {
+        CxIterator i = cxListIterator(note->resource->attachments);
         cx_foreach(Attachment *, attachment, i) {
             attachment_save(obj, attachment, TRUE);
         }
@@ -257,7 +255,7 @@ void note_insert_list(NoteModel *note, UiBool ordered) {
 
 
 
-void note_update_title(NotebookModel *notebook, Resource *note) {
+void note_update_title(NotebookModel *notebook, Note *note) {
     int index = notebookmode_get_note_index(notebook, note);
     if(index < 0) {
         return;
@@ -266,8 +264,8 @@ void note_update_title(NotebookModel *notebook, Resource *note) {
     m->modified = TRUE;
     
     char *title = ui_get(m->title);
-    cxFree(m->note_allocator, note->displayname);
-    note->displayname = cx_strdup_a(m->note_allocator, cx_str(title)).ptr;
+    cxFree(m->note_allocator, note->resource->displayname);
+    note->resource->displayname = cx_strdup_a(m->note_allocator, cx_str(title)).ptr;
     
     notebook->notes->update(notebook->notes, index);
 }
@@ -276,7 +274,9 @@ const char* note_get_title(Resource *note) {
     return note->displayname ? note->displayname : note->nodename;
 }
 
-void note_destroy(const CxAllocator *a, Resource *note) {
+void note_destroy(const CxAllocator *a, Note *note) {
+    // TODO
+    /*
     cxFree(a, note->nodename);
     cxFree(a, note->displayname);
     cxFree(a, note->contenttype);
@@ -285,6 +285,7 @@ void note_destroy(const CxAllocator *a, Resource *note) {
     if(note->model) {
         // TODO: destroy model->context
     }
+    */
 }
 
 Attachment* note_get_attachment(Resource *note, const char *path) {
index f3024fa8ae87ce21223048a902add95b6efb2054..190d1d50b953fde6e40144ac0a72a0999dc16968 100644 (file)
@@ -44,14 +44,14 @@ typedef struct TextNoteParagraphStyles {
 NoteModel *notemodel_current(UiObject *obj);
   
 NoteModel* notemodel_create(const CxAllocator *note_allocator);
-void notemodel_set_note(NoteModel *model, Resource *note);
+void notemodel_set_note(NoteModel *model, Note *note);
 
 // TODO: the interface is weird, but we need the NotebookModel for the allocator
-void note_load_content(UiObject *obj, NotebookModel *notebook, Resource *note);
+void note_load_content(UiObject *obj, NotebookModel *notebook, Note *note);
 
-void note_add_attachment(Resource *note, Attachment *attachment);
+void note_add_attachment(Note *note, Attachment *attachment);
 
-void note_save(UiObject *obj, NotebookModel *notebook, Resource *note);
+void note_save(UiObject *obj, NotebookModel *notebook, Note *note);
 
 void note_update_current_style(NoteModel *note, MDActiveStyles *style);
 
@@ -62,10 +62,10 @@ void note_text_style_set_underline(NoteModel *note, UiBool enabled);
 void note_text_style_set_code(NoteModel *note, UiBool enabled);
 void note_insert_list(NoteModel *note, UiBool ordered);
 
-void note_update_title(NotebookModel *notebook, Resource *note);
+void note_update_title(NotebookModel *notebook, Note *note);
 
 const char* note_get_title(Resource *note);
-void note_destroy(const CxAllocator *a, Resource *note);
+void note_destroy(const CxAllocator *a, Note *note);
 
 Attachment* note_get_attachment(Resource *note, const char *path);
 
index 5b92dd390314edeeb6cba15025278f5962ff8db5..966a61c86e5e37359bf1cfa22a2141d781f7ec1f 100644 (file)
@@ -44,7 +44,7 @@ NotebookModel* notebookmodel_create() {
     return model;
 }
     
-static void notelist_select_note(NotebookModel *model, Resource *note) {
+static void notelist_select_note(NotebookModel *model, Note *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(Resource *, note, i) {
+        cx_foreach(Note *, 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, Resource *note) {
+void notebookmodel_attach_note(NotebookModel *model, Note *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, Resource *note) {
         ui_set_group(model->window->obj->ctx, APP_STATE_NOTE_HAS_ATTACHMENTS);
     }
     
-    if(!note->content_loaded) {
+    if(!note->resource->content_loaded) {
         note_load_content(model->window->obj, model, note);
     }
     
@@ -160,7 +160,7 @@ void notebookmodel_attach_note(NotebookModel *model, Resource *note) {
 
 void notebookmodel_detach_current_note(NotebookModel *model) {
     if(model->current_note) {
-        Resource *current_note = model->current_note;
+        Note *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);
@@ -197,10 +197,15 @@ Resource* notebookmodel_get_note_by_id(NotebookModel *model, int64_t note_id, si
 
 
 void notebookmodel_new_note(NotebookModel *model) {
-    Resource *new_note = cxMalloc(model->current_notes_pool->allocator, sizeof(Resource));
-    memset(new_note, 0, sizeof(Resource));
+    Note *new_note = cxMalloc(model->current_notes_pool->allocator, sizeof(Note));
+    memset(new_note, 0, sizeof(Note));
     
-    new_note->parent_id = model->collection->resource_id;
+    Resource *new_resource = cxMalloc(model->current_notes_pool->allocator, sizeof(Resource));
+    memset(new_resource, 0, sizeof(Resource));
+    
+    new_note->resource = new_resource;
+    
+    new_resource->parent_id = model->collection->resource_id;
     notebookmodel_attach_note(model, new_note);
     new_note->model->modified = TRUE;
     // initialize note content
@@ -213,7 +218,7 @@ void notebookmodel_new_note(NotebookModel *model) {
 
 typedef struct NoteDeleteOp {
     NotebookModel *notebook;
-    Resource *note;
+    Note *note;
 } NoteDeleteOp;
 
 static void note_deleted(UiEvent *event, int error, void *userdata) {
@@ -284,7 +289,7 @@ void notebookmodel_add2navstack(NotebookModel *model) {
     */
 }
 
-int notebookmode_get_note_index(NotebookModel *model, Resource *note) {
+int notebookmode_get_note_index(NotebookModel *model, Note *note) {
     CxList *list = model->notes->data;
     size_t index = cxListFind(list, note);
     return cxListIndexValid(list, index) ? index : -1;
index e031863439beb2f7108c39567d785827b11638e0..3524016f2624883b2ccd0cd157df103d202c8c75 100644 (file)
@@ -46,7 +46,7 @@ void notebookmodel_set_collection(NotebookModel *model, Resource *collection);
 
 void notebookmodel_reload(UiObject *obj, NotebookModel *model);
 
-void notebookmodel_attach_note(NotebookModel *model, Resource *note);
+void notebookmodel_attach_note(NotebookModel *model, Note *note);
 void notebookmodel_detach_current_note(NotebookModel *model);
 
 Resource* notebookmodel_get_note_by_id(NotebookModel *model, int64_t note_id, size_t *index);
@@ -56,7 +56,7 @@ void notebookmodel_delete_note(NotebookModel *model);
 
 void notebookmodel_add2navstack(NotebookModel *model);
 
-int notebookmode_get_note_index(NotebookModel *model, Resource *note);
+int notebookmode_get_note_index(NotebookModel *model, Note *note);
 
 
 #ifdef __cplusplus
index 6b92ff68d6deb429f52a9ee048683c428960da45..1400393d570f9ce02f22f18860482d6caf0ee258 100644 (file)
@@ -56,7 +56,7 @@
     "select * from cols\n" \
     "order by path;"
 
-#define SQL_NOTEBOOK_GET_NOTES "select r.resource_id, r.parent_id, r.nodename, r.displayname, r.lastmodified, r.creationdate, r.iscollection, r.contenttype from resources r inner join notes n on r.resource_id = n.resource_id where parent_id = ? ;"
+#define SQL_NOTEBOOK_GET_NOTES "select n.*, NULL as [__resources__resource_id], r.resource_id, r.parent_id, r.nodename, r.displayname, r.lastmodified, r.creationdate, r.iscollection, r.contenttype from resources r inner join notes n on r.resource_id = n.resource_id where parent_id = ? ;"
 
 #define SQL_NOTE_GET_CONTENT "select content from resources where resource_id = ? ;"
 
@@ -371,7 +371,7 @@ CxList* note_store_get_notes(const CxAllocator *a, int64_t parent_collection_id)
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTEBOOK_GET_NOTES);
     dbuQuerySetParamInt64(q, 1, parent_collection_id);
-    DBUObjectBuilder *builder = dbuObjectBuilder(resource_class, q, a);
+    DBUObjectBuilder *builder = dbuObjectBuilder(note_class, q, a);
     CxList *notes = dbuObjectBuilderGetList(builder);
     dbuObjectBuilderDestroy(builder);
     return notes;
@@ -487,7 +487,7 @@ void note_store_get_note_content_async(UiObject *obj, const CxAllocator *a, int6
 
 
 typedef struct SaveNoteJob {
-    Resource *note;
+    Note *note;
     execresult_func resultcb;
     void *userdata;
     int error;
@@ -501,7 +501,7 @@ static void uithr_save_note_finished(UiEvent *event, SaveNoteJob *job) {
 }
 
 static int qthr_new_note(SaveNoteJob *job) {
-    Resource *n = job->note;
+    Resource *n = job->note->resource;
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTE_RESOURCE_NEW);
     dbuQuerySetParamInt64(q, 1, n->parent_id);
@@ -525,7 +525,7 @@ static int qthr_new_note(SaveNoteJob *job) {
                 dbuQuerySetParamInt64(q2, 2, 0);
                 if(dbuQueryExec(q2)) {
                     job->error = 3;
-                }
+                } // TODO: save note_id in the Note object
                 dbuQueryFree(q2);
             }
         } else {
@@ -538,7 +538,7 @@ static int qthr_new_note(SaveNoteJob *job) {
     return 0;
 }
 
-void note_store_new_note_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata) {
+void note_store_new_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) {
     SaveNoteJob *job = malloc(sizeof(SaveNoteJob));
     job->note = note;
     job->resultcb = resultcb;
@@ -549,7 +549,7 @@ void note_store_new_note_async(UiObject *obj, Resource *note, execresult_func re
 
 
 static int qthr_save_note(SaveNoteJob *job) {
-    Resource *n = job->note;
+    Resource *n = job->note->resource;
     DBUQuery *q = connection->createQuery(connection, NULL);
     dbuQuerySetSQL(q, SQL_NOTE_SAVE);
     dbuQuerySetParamString(q, 1, cx_str(n->displayname));
@@ -570,7 +570,7 @@ static int qthr_save_note(SaveNoteJob *job) {
     return 0;
 }
 
-void note_store_save_note_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata) {
+void note_store_save_note_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) {
     SaveNoteJob *job = malloc(sizeof(SaveNoteJob));
     job->note = note;
     job->resultcb = resultcb;
@@ -612,7 +612,7 @@ static void uithr_delete_finished(UiEvent *event, DeleteNoteJob *job) {
     free(job);
 }
 
-void note_store_delete_async(UiObject *obj, Resource *note, UiBool move_to_trash, execresult_func resultcb, void *userdata) {
+void note_store_delete_async(UiObject *obj, Note *note, UiBool move_to_trash, execresult_func resultcb, void *userdata) {
     DeleteNoteJob *job = malloc(sizeof(DeleteNoteJob));
     job->note_id = note->resource_id;
     job->move_to_trash = move_to_trash;
@@ -703,7 +703,7 @@ void note_store_save_attachment_async(UiObject *obj, Attachment *attachment, exe
 
 
 typedef struct LoadAttachmentsJob {
-    Resource *note;
+    Note *note;
     CxMempool *temp_mp;
     CxList *result;
     execresult_func resultcb;
@@ -733,7 +733,7 @@ static void uithr_load_attachments_finished(UiEvent *event, LoadAttachmentsJob *
     if(job->result) {
         CxMempool *note_mp = job->note->model->note_allocator->data;
         cxMempoolTransfer(job->temp_mp, note_mp);
-        job->note->attachments = job->result;
+        job->note->resource->attachments = job->result;
     }
     cxMempoolFree(job->temp_mp);
     
@@ -743,7 +743,7 @@ static void uithr_load_attachments_finished(UiEvent *event, LoadAttachmentsJob *
     free(job);
 }
 
-void note_store_load_note_attachments_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata) {
+void note_store_load_note_attachments_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata) {
     LoadAttachmentsJob *job = malloc(sizeof(LoadAttachmentsJob));
     job->note = note;
     job->temp_mp = NULL;
index 84405b341af115b6e09500962bdf23eebea9a599..4314efd2226d8154fd41469bee58db25a9affa49 100644 (file)
@@ -87,14 +87,14 @@ void note_store_get_notes_async(UiObject *obj, int64_t parent_resource_id, listr
 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, 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_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_delete_async(UiObject *obj, Resource *note, UiBool move_to_trash, 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_save_attachment_async(UiObject *obj, Attachment *attachment, execresult_func resultcb, void *userdata);
 
-void note_store_load_note_attachments_async(UiObject *obj, Resource *note, execresult_func resultcb, void *userdata);
+void note_store_load_note_attachments_async(UiObject *obj, Note *note, execresult_func resultcb, void *userdata);
 
 #ifdef __cplusplus
 }
index fc2cc0db3c2539dbcf7d3acb1b2ab9da7db9887c..5f9bf5766507ab5cf772551ade8fbfba203d7d59 100644 (file)
@@ -76,7 +76,7 @@
     "type                    integer, " \
     "status                  text, " \
     "targetdate              integer, " \
-    "foreign key (resource_id) references resources(resource_id) " \
+    "foreign key (resource_id) references resources(resource_id) on delete cascade " \
     ");"
 #define SQL_CREATE_TABLE_ATTACHMENTS "create table attachments( " \
     "attachment_id           integer primary key, " \
index b4f6a77e7046311d94a990558621fc0b6c38e09f..57db2a7cbfdf0668a13c5b7a7af32119f2311e35 100644 (file)
@@ -69,6 +69,7 @@ void register_types() {
     dbuClassAdd(note_class, Note, type);
     dbuClassAdd(note_class, Note, status);
     dbuClassAdd(note_class, Note, targetdate);
+    dbuClassAddObj(note_class, "resource_id", offsetof(Note, resource), resource_class);
     
     repository_class = dbuRegisterClass(ctx, "repositories", Repository, repository_id);
     dbuClassAdd(repository_class, Repository, name);
index 431e7a9f9e9e80fbe1247de26f9e9d32bf937620..9692cad6c77ebdf3164d7862e11876e1df63816a 100644 (file)
@@ -99,11 +99,6 @@ struct Resource {
      * included in a Notes query result
      */
     bool       content_loaded;
-     
-    /*
-     * non-db member, UI model
-     */
-    NoteModel  *model;
 };
 
 struct Notebook {
@@ -119,6 +114,13 @@ struct Note {
     int        type;
     char       *status;
     time_t     targetdate;
+    
+    Resource   *resource;
+    
+    /*
+     * non-db member, UI model
+     */
+    NoteModel  *model;
 };
 
 typedef enum AttachmentType {
index dfd99120626c9f10fe46e341d7b9b219c28a9947..a4552e691449a59e99a2fac7d20c1664f3d4975d 100644 (file)
@@ -203,10 +203,11 @@ void update_sublists(UiContext *ctx, UiList *sublists) {
 }
 
 void* window_notelist_getvalue(void *data, int col) {
-    Resource *note = data;
+    Note *note = data;
+    Resource *resource = note->resource;
     switch(col) {
         case 0: {
-            return note->displayname ? note->displayname : note->nodename;
+            return resource->displayname ? resource->displayname : resource->nodename;
         }
         case 1: {
             //return note->lastmodified ? strdup(note->lastmodified) : NULL;
@@ -370,7 +371,7 @@ static int select_note(UiEvent *event) {
         return 0;
     }
     
-    Resource *note = ui_list_get(notebook->notes, sel->rows[0]);
+    Note *note = ui_list_get(notebook->notes, sel->rows[0]);
     notebookmodel_attach_note(notebook, note);
     
     return 1;