#include "note.h"
#include <cx/printf.h>
+#include <cx/buffer.h>
+#include <cx/streams.h>
Attachment* attachment_create(
const CxAllocator *a,
}
}
+void attachment_set_data(Attachment *attachment, cxmutstr data) {
+ attachment->bin_content = data;
+}
+
+void attachment_save(UiObject *obj, Attachment *attachment) {
+
+}
+
+
+cxmutstr attachment_file_load(const CxAllocator *a, const char *path) {
+ FILE *f = fopen(path, "rb");
+ if(!f) {
+ return (cxmutstr){NULL, 0};
+ }
+
+ CxBuffer buf;
+ cxBufferInit(&buf, NULL, 1024*128, a, CX_BUFFER_FREE_CONTENTS);
+
+ cx_stream_copy(f, &buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite);
+ fclose(f);
+
+ return cx_mutstrn(buf.space, buf.size);
+}
+
/*
* itemlist create_ui function
#include "application.h"
+#include <cx/string.h>
+
#ifdef __cplusplus
extern "C" {
#endif
void attachment_set_image(Attachment *attachment, void *img);
+void attachment_set_data(Attachment *attachment, cxmutstr data);
+
+void attachment_save(UiObject *obj, Attachment *attachment);
+
+// TODO: move this function to a separate file
+cxmutstr attachment_file_load(const CxAllocator *a, const char *path);
+
/*
* create UI for an attachment item
*/
g_object_ref(pixbuf);
attachment_set_image(attachment, pixbuf);
+ if(attachment_path) {
+ cxmutstr data = attachment_file_load(model->note_allocator, attachment_path);
+ if(data.ptr) {
+ attachment_set_data(attachment, data);
+ }
+ }
+
// insert image
GtkTextView *textview = GTK_TEXT_VIEW(editor->textview);
GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
cxListAdd(embedded_objects->objects, em);
// add attachment to note
+ note_add_attachment(note, attachment);
ui_list_append(model->attachments, attachment);
ui_list_update(model->attachments);
}
#include "editor.h"
#include "notebook.h"
+#include <cx/array_list.h>
+
static TextNoteParagraphStyles paragraph_styles[] = {
{ "Paragraph", EDITOR_STYLE_PARAGRAPH },
{ "Code", EDITOR_STYLE_CODE_BLOCK },
note_store_get_note_content_async(obj, notebook->current_notes_pool->allocator, note->resource_id, note_content_loaded, note);
}
+void note_add_attachment(Resource *note, Attachment *attachment) {
+ if(!note->attachments) {
+ note->attachments = cxArrayListCreate(note->model->note_allocator, NULL, CX_STORE_POINTERS, 8);
+ }
+ cxListAdd(note->attachments, attachment);
+}
+
void note_save(UiObject *obj, NotebookModel *notebook, Resource *note) {
NoteModel *m = note->model;
} else {
note_store_save_note_async(obj, note, NULL, NULL);
}
+
+ if(note->attachments) {
+ CxIterator i = cxListIterator(note->attachments);
+ cx_foreach(Attachment *, attachment, i) {
+ attachment_save(obj, attachment);
+ }
+ }
}
void note_update_current_style(NoteModel *note, MDActiveStyles *style) {
// 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_add_attachment(Resource *note, Attachment *attachment);
+
void note_save(UiObject *obj, NotebookModel *notebook, Resource *note);
void note_update_current_style(NoteModel *note, MDActiveStyles *style);
cxmutstr bin_content;
char *created_by;
+ /*
+ * type: Attachment*
+ */
+ CxList *attachments;
+
/*
* indicates, whether content or bin_content was queried
* content_loaded is not a column in the Notes table, however it can be
* included in a Notes query result
*/
bool content_loaded;
-
+
/*
* non-db member, UI model
*/
cxmutstr bin_content;
bool content_loaded;
+ // is the attachment content already stored persistently
+ bool content_saved;
+
+ // is the attachment persistently connected to a note
+ bool saved;
+
// ui
AttachmentModel *ui;
};