aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-10-21 18:03:01 +0200
committerThomas White <taw@bitwiz.me.uk>2018-10-21 18:03:01 +0200
commit27e08c96c71183edea9be3e189d7152c19b1beac (patch)
tree428735ad37dbfcb9598c4ae3854252a4092d3f8f
parenta85c7fd76dd50d82841e01018b532ad790f8c564 (diff)
Try <documentname>.ss for stylesheet
-rw-r--r--src/narrative_window.c8
-rw-r--r--src/presentation.c20
-rw-r--r--src/sc_interp.c2
-rw-r--r--src/stylesheet.c14
-rw-r--r--src/stylesheet.h4
5 files changed, 40 insertions, 8 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index ead78bd..b287f61 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -190,12 +190,12 @@ static gint load_ss_response_sig(GtkWidget *d, gint response,
{
if ( response == GTK_RESPONSE_ACCEPT ) {
- char *filename;
+ GFile *file;
Stylesheet *new_ss;
- filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
+ file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(d));
- new_ss = stylesheet_load(filename);
+ new_ss = stylesheet_load(file);
if ( new_ss != NULL ) {
stylesheet_free(nw->p->stylesheet);
@@ -209,7 +209,7 @@ static gint load_ss_response_sig(GtkWidget *d, gint response,
fprintf(stderr, _("Failed to load\n"));
}
- g_free(filename);
+ g_object_unref(file);
}
diff --git a/src/presentation.c b/src/presentation.c
index 1aa126a..a33a541 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -245,6 +245,8 @@ int load_presentation(struct presentation *p, GFile *file)
{
int r = 0;
char *everything;
+ GFile *ssfile;
+ gchar *ssuri;
assert(p->completely_empty);
@@ -266,7 +268,23 @@ int load_presentation(struct presentation *p, GFile *file)
return r; /* Error */
}
- p->stylesheet = stylesheet_load("stylesheet.json"); /* FIXME: ! */
+ p->stylesheet = NULL;
+ ssuri = g_file_get_uri(file);
+ if ( ssuri != NULL ) {
+ size_t l = strlen(ssuri);
+ if ( ssuri[l-3] == '.' && ssuri[l-2] == 's' && ssuri[l-1] =='c' ) {
+ ssuri[l-1] = 's';
+ ssfile = g_file_new_for_uri(ssuri);
+ p->stylesheet = stylesheet_load(ssfile);
+ g_object_unref(ssfile);
+ g_free(ssuri);
+ }
+ }
+ if ( p->stylesheet == NULL ) {
+ ssfile = g_file_new_for_path("./stylesheet.json");
+ p->stylesheet = stylesheet_load(ssfile);
+ g_object_unref(ssfile);
+ }
set_slide_size_from_stylesheet(p);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 780663f..010b100 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -945,6 +945,8 @@ static void apply_style(SCInterpreter *scin, Stylesheet *ss, const char *path)
return;
}
+ if ( ss == NULL ) return;
+
/* Font */
strcpy(fullpath, path);
strcat(fullpath, ".font");
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 228c331..020107e 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -29,8 +29,10 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <gio/gio.h>
#include "stylesheet.h"
+#include "utils.h"
struct _stylesheet {
@@ -38,19 +40,27 @@ struct _stylesheet {
};
-Stylesheet *stylesheet_load(const char *filename)
+Stylesheet *stylesheet_load(GFile *file)
{
JsonParser *parser;
gboolean r;
GError *err = NULL;
Stylesheet *ss;
+ char *everything;
+ gsize len;
ss = calloc(1, sizeof(Stylesheet));
if ( ss == NULL ) return NULL;
parser = json_parser_new();
- r = json_parser_load_from_file(parser, filename, &err);
+ if ( !g_file_load_contents(file, NULL, &everything, &len, NULL, NULL) ) {
+ fprintf(stderr, _("Failed to load stylesheet '%s'\n"),
+ g_file_get_uri(file));
+ return NULL;
+ }
+
+ r = json_parser_load_from_data(parser, everything, len, &err);
if ( r == FALSE ) {
fprintf(stderr, "Failed to load style sheet: '%s'\n", err->message);
return NULL;
diff --git a/src/stylesheet.h b/src/stylesheet.h
index 59afa7d..aa5867f 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -27,9 +27,11 @@
#include <config.h>
#endif
+#include <gio/gio.h>
+
typedef struct _stylesheet Stylesheet;
-extern Stylesheet *stylesheet_load(const char *filename);
+extern Stylesheet *stylesheet_load(GFile *file);
extern char *stylesheet_lookup(Stylesheet *ss, const char *path);
extern void stylesheet_free(Stylesheet *ss);