static void set_entry(JamDoc *doc, LJEntry *entry) { #ifdef HAVE_GTK GtkTextIter start, end; #endif /* HAVE_GTK */ lj_entry_free(doc->entry); if (entry) doc->entry = entry; else entry = doc->entry = lj_entry_new(); #ifdef HAVE_GTK /* block the buffer signal so we don't rapidly flip to dirty and back. */ g_signal_handler_block(doc->buffer, doc->buffer_signal); gtk_text_buffer_get_bounds(doc->buffer, &start, &end); gtk_text_buffer_delete(doc->buffer, &start, &end); if (entry->event) gtk_text_buffer_insert(doc->buffer, &start, entry->event, -1); g_signal_handler_unblock(doc->buffer, doc->buffer_signal); #endif /* HAVE_GTK */ jam_doc_set_dirty(doc, FALSE); #ifdef HAVE_GTK /* since the buffer signal was blocked, we need to do this manually. */ gtk_text_buffer_set_modified(doc->buffer, FALSE); #endif /* HAVE_GTK */ }
static gboolean load_items(DraftStoreUI *dsui) { LJEntry *entry; entry = lj_entry_new(); draft_store_each_header(dsui->ds, entry, load_item_cb, dsui); lj_entry_free(entry); return TRUE; }
gboolean jam_doc_save_as_draft(JamDoc *doc, const char *title, JamAccount *acc, GError **err) { LJEntry *entry; entry = jam_doc_get_entry(doc); string_replace(&entry->subject, g_strdup(title)); entry->itemid = 0; if (!save_draft(entry, acc, err)) { lj_entry_free(entry); return FALSE; } /* retrieve the new draft id. */ doc->entry->itemid = entry->itemid; lj_entry_free(entry); string_replace(&doc->filename, NULL); jam_doc_set_dirty(doc, FALSE); return TRUE; }
gboolean jam_doc_save_as_file(JamDoc *doc, const char *filename, GError **err) { LJEntry *entry; entry = jam_doc_get_entry(doc); /* always save to files without an itemid. */ entry->itemid = 0; if (!lj_entry_to_xml_file(entry, filename, err)) { lj_entry_free(entry); return FALSE; } lj_entry_free(entry); doc->entry->itemid = 0; string_replace(&doc->filename, g_strdup(filename)); jam_doc_set_dirty(doc, FALSE); return TRUE; }
LJEntry* lj_entry_new_from_file(FILE *f, LJEntryFileType type, LJEntryFileType *typeret, GError **err) { GString *str = g_string_new(NULL); char buf[1024]; int len; LJEntry *entry; while ((len = (int)fread(buf, 1, 1024, f)) > 0) g_string_append_len(str, buf, len); entry = lj_entry_new(); if (!lj_entry_load(entry, str->str, str->len, type, typeret, err)) { lj_entry_free(entry); entry = NULL; } g_string_free(str, TRUE); return entry; }