From 5a1e588c3fbdce549e0b3c487e2671c679890675 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 30 Mar 2019 17:32:24 +0100 Subject: Get rid of Presentation structure It doesn't have any reason to exist. A Narrative defines the top-level object already. This is, after all, a narrative-based presentation system. This removes a lot of faff surrounding retrieving the Narrative from the Presentation. It also removes a gigantic place for bugs to hide in keeping the Presentation's view of the slides in sync with the Narrative's opinion. What was that quote? "Code is terrible, and we want as little of it as possible in our program." --- libstorycode/narrative.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 2 deletions(-) (limited to 'libstorycode/narrative.c') diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c index 5dfe117..19797e3 100644 --- a/libstorycode/narrative.c +++ b/libstorycode/narrative.c @@ -28,9 +28,23 @@ #include #include #include +#include +#include +#ifdef HAVE_PANGO +#include +#endif + +#ifdef HAVE_CAIRO +#include +#endif + +#include "stylesheet.h" +#include "slide.h" #include "narrative.h" #include "narrative_priv.h" +#include "imagestore.h" +#include "storycode.h" Narrative *narrative_new() { @@ -39,6 +53,14 @@ Narrative *narrative_new() if ( n == NULL ) return NULL; n->n_items = 0; n->items = NULL; + n->stylesheet = NULL; + n->imagestore = NULL; + n->saved = 1; +#ifdef HAVE_PANGO + n->language = pango_language_to_string(pango_language_get_default()); +#else + n->language = NULL; +#endif return n; } @@ -70,6 +92,74 @@ void narrative_free(Narrative *n) } +Narrative *narrative_load(GFile *file) +{ + GBytes *bytes; + const char *text; + size_t len; + Narrative *n; + + bytes = g_file_load_bytes(file, NULL, NULL, NULL); + if ( bytes == NULL ) return NULL; + + text = g_bytes_get_data(bytes, &len); + n = storycode_parse_presentation(text); + g_bytes_unref(bytes); + if ( n == NULL ) return NULL; + + n->imagestore = imagestore_new("."); /* FIXME: From app config */ + imagestore_set_parent(n->imagestore, g_file_get_parent(file)); + return n; +} + + +int narrative_save(Narrative *n, GFile *file) +{ + /* FIXME: Implementation */ + return 1; +} + + +void narrative_set_unsaved(Narrative *n) +{ + n->saved = 0; +} + + +int narrative_get_unsaved(Narrative *n) +{ + return !n->saved; +} + + +void narrative_add_stylesheet(Narrative *n, Stylesheet *ss) +{ + assert(n->stylesheet == NULL); + n->stylesheet = ss; +} + + +Stylesheet *narrative_get_stylesheet(Narrative *n) +{ + if ( n == NULL ) return NULL; + return n->stylesheet; +} + + +const char *narrative_get_language(Narrative *n) +{ + if ( n == NULL ) return NULL; + return n->language; +} + + +ImageStore *narrative_get_imagestore(Narrative *n) +{ + if ( n == NULL ) return NULL; + return n->imagestore; +} + + static void init_item(struct narrative_item *item) { item->layout = NULL; @@ -265,6 +355,17 @@ int narrative_get_num_items(Narrative *n) } +int narrative_get_num_slides(Narrative *n) +{ + int i; + int ns = 0; + for ( i=0; in_items; i++ ) { + if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) ns++; + } + return ns; +} + + Slide *narrative_get_slide(Narrative *n, int para) { if ( para >= n->n_items ) return NULL; @@ -273,12 +374,40 @@ Slide *narrative_get_slide(Narrative *n, int para) } -int narrative_get_slide_number(Narrative *n, int para) +int narrative_get_slide_number_for_para(Narrative *n, int para) { int i; int ns = 0; - for ( i=0; in_items; i++ ) { + for ( i=0; iitems[i].type == NARRATIVE_ITEM_SLIDE ) ns++; } return ns; } + + +int narrative_get_slide_number_for_slide(Narrative *n, Slide *s) +{ + int i; + int ns = 0; + for ( i=0; in_items; i++ ) { + if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) { + if ( n->items[i].slide == s ) return ns; + ns++; + } + } + return n->n_items; +} + + +Slide *narrative_get_slide_by_number(Narrative *n, int pos) +{ + int i; + int ns = 0; + for ( i=0; in_items; i++ ) { + if ( n->items[i].type == NARRATIVE_ITEM_SLIDE ) { + if ( ns == pos ) return n->items[i].slide; + ns++; + } + } + return NULL; +} -- cgit v1.2.3