}
}
+typedef struct LoadNoteContent {
+ Resource *note;
+ UiBool content;
+ UiBool attachments;
+} LoadNoteContent;
-static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) {
- Resource *note = userdata;
- note->content = result;
- printf("note content: %s\n", result.ptr);
+static void note_loading_completed(LoadNoteContent *op) {
+ Resource *note = op->note;
+ free(op);
+
if(note->model) {
- editor_load_markdown(note->model->text, result);
+ editor_load_markdown(note->model->text, note->content);
}
note->content_loaded = TRUE;
}
+static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) {
+ LoadNoteContent *op = userdata;
+ op->note->content = result;
+ printf("note content: %s\n", result.ptr);
+ op->content = TRUE;
+ if(op->attachments) {
+ note_loading_completed(op);
+ }
+}
+
+static void note_attachments_loaded(UiEvent *event, int error, void *userdata) {
+ LoadNoteContent *op = userdata;
+ op->attachments = TRUE;
+ if(op->content) {
+ note_loading_completed(op);
+ }
+}
+
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);
+ LoadNoteContent *op = malloc(sizeof(LoadNoteContent));
+ op->note = note;
+ op->content = FALSE;
+ op->attachments = FALSE;
+
+ note_store_get_note_content_async(obj, notebook->current_notes_pool->allocator, note->resource_id, note_content_loaded, op);
+ note_store_load_note_attachments_async(obj, note, note_attachments_loaded, op);
}
void note_add_attachment(Resource *note, Attachment *attachment) {
#define SQL_ATTACHMENTS_GET "select attachment_id, attachment_resource_id, parent_resource_id, a.type, "\
"r.name, r.bin_content from attachments a "\
- "inner join resource r on a.attachment_resource_id = r.resource_id " \
+ "inner join resources r on a.attachment_resource_id = r.resource_id " \
"where parent_resource_id = ? order by attachment_id;"
static DBUConnection *connection;
if(job->result) {
CxMempool *note_mp = job->note->model->note_allocator->data;
cxMempoolTransfer(job->temp_mp, note_mp);
- cxMempoolFree(job->temp_mp);
job->note->attachments = job->result;
}
+ cxMempoolFree(job->temp_mp);
if(job->resultcb) {
job->resultcb(event, job->error, job->userdata);