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,
/*
* currently attached note
*/
- Note *current_note;
+ Resource *current_note;
/*
* some actions might trigger unwanted selection events
UiContext *ctx;
const CxAllocator *note_allocator;
- Note *parent_note;
+ Resource *parent_note;
int64_t resource_id;
AttachmentType type;
// 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
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);
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) {
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);
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;
-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;
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);
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);
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
}
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);
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);
}
-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
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);
*
* 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;
}
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);
typedef struct NoteDeleteOp {
NotebookModel *notebook;
- Note *note;
+ Resource *note;
} NoteDeleteOp;
static void note_deleted(UiEvent *event, int error, void *userdata) {
// 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) {
*/
}
-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;
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
"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;
typedef struct SaveNoteJob {
- Note *note;
+ Resource *note;
execresult_func resultcb;
void *userdata;
int error;
}
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);
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;
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;
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 {
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;
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;
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
}
"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) {
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);
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);
}
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 {
CxList *children;
};
-struct Note {
- int64_t note_id;
+struct Resource {
+ int64_t resource_id;
int64_t parent_id;
char *name;
char *title;
// 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
}
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;
}
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));
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;