aboutsummaryrefslogtreecommitdiff
path: root/src/presentation.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-10-27 23:54:56 +0200
committerThomas White <taw@bitwiz.me.uk>2018-10-27 23:54:56 +0200
commit05e29e56ce7accdf7216566a5698caac96e8bd43 (patch)
tree97a96f042b1672a9cb9d992d91f5a26c9d1998c4 /src/presentation.c
parent7e36b2a0fc2180d8d319b54159a6680801247ba4 (diff)
Handle condition of no stylesheet, and load default stylesheet for empty presentation
Diffstat (limited to 'src/presentation.c')
-rw-r--r--src/presentation.c99
1 files changed, 56 insertions, 43 deletions
diff --git a/src/presentation.c b/src/presentation.c
index 4d01db8..eab0f5a 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -67,6 +67,59 @@ char *get_titlebar_string(struct presentation *p)
}
+static void find_and_load_stylesheet(struct presentation *p, GFile *file)
+{
+ GFile *ssfile;
+ GFile *parent;
+ gchar *ssuri;
+
+ if ( file != NULL ) {
+
+ /* First choice: /same/directory/<presentation>.ss */
+ 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);
+ }
+ }
+
+ /* Second choice: /same/directory/stylesheet.ss */
+ if ( p->stylesheet == NULL ) {
+ parent = g_file_get_parent(file);
+ if ( parent != NULL ) {
+ ssfile = g_file_get_child(parent, "stylesheet.ss");
+ if ( ssfile != NULL ) {
+ p->stylesheet = stylesheet_load(ssfile);
+ g_object_unref(ssfile);
+ }
+ }
+ }
+
+ }
+
+ /* Third choice: <cwd>/stylesheet.ss */
+ if ( p->stylesheet == NULL ) {
+ ssfile = g_file_new_for_path("./stylesheet.ss");
+ p->stylesheet = stylesheet_load(ssfile);
+ g_object_unref(ssfile);
+ }
+
+ /* Fourth choice: internal default stylesheet */
+ if ( p->stylesheet == NULL ) {
+ ssfile = g_file_new_for_uri("resource:///uk/me/bitwiz/Colloquium/default.ss");
+ p->stylesheet = stylesheet_load(ssfile);
+ g_object_unref(ssfile);
+ }
+
+ /* Last resort is NULL stylesheet and SCInterpreter's defaults */
+}
+
+
struct presentation *new_presentation(const char *imagestore)
{
struct presentation *new;
@@ -89,6 +142,8 @@ struct presentation *new_presentation(const char *imagestore)
new->lang = pango_language_get_default();
+ find_and_load_stylesheet(new, NULL);
+
return new;
}
@@ -245,9 +300,6 @@ int load_presentation(struct presentation *p, GFile *file)
{
int r = 0;
char *everything;
- GFile *ssfile;
- GFile *parent;
- gchar *ssuri;
assert(p->completely_empty);
@@ -271,46 +323,7 @@ int load_presentation(struct presentation *p, GFile *file)
p->stylesheet = NULL;
- /* First choice: /same/directory/<presentation>.ss */
- 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);
- }
- }
-
- /* Second choice: /same/directory/stylesheet.ss */
- if ( p->stylesheet == NULL ) {
- parent = g_file_get_parent(file);
- if ( parent != NULL ) {
- ssfile = g_file_get_child(parent, "stylesheet.ss");
- if ( ssfile != NULL ) {
- p->stylesheet = stylesheet_load(ssfile);
- g_object_unref(ssfile);
- }
- }
- }
-
- /* Third choice: <cwd>/stylesheet.ss */
- if ( p->stylesheet == NULL ) {
- ssfile = g_file_new_for_path("./stylesheet.ss");
- p->stylesheet = stylesheet_load(ssfile);
- g_object_unref(ssfile);
- }
-
- /* Fourth choice: internal default stylesheet */
- if ( p->stylesheet == NULL ) {
- ssfile = g_file_new_for_uri("resource:///uk/me/bitwiz/Colloquium/default.ss");
- p->stylesheet = stylesheet_load(ssfile);
- g_object_unref(ssfile);
- }
-
- /* Last resort is NULL stylesheet and SCInterpreter's defaults */
+ find_and_load_stylesheet(p, file);
set_slide_size_from_stylesheet(p);