aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-04-11 23:30:59 +0200
committerThomas White <taw@bitwiz.me.uk>2018-04-11 23:30:59 +0200
commitd3e79cd94482e720c155c85745988b67df5136c1 (patch)
tree7f2a319f34f7af43d6c90e02cacbd7a0cfbaee16 /src
parentcb766cf30b2eee06948c2b90ffa012d9df2d835e (diff)
Replace p->filename with p->uri, get rid of p->titlebar, and use g_file_get_basename()
Diffstat (limited to 'src')
-rw-r--r--src/narrative_window.c10
-rw-r--r--src/presentation.c52
-rw-r--r--src/presentation.h3
3 files changed, 16 insertions, 49 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 1b26b62..17885e1 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -144,11 +144,11 @@ static void save_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
NarrativeWindow *nw = vp;
GFile *file;
- if ( nw->p->filename == NULL ) {
+ if ( nw->p->uri == NULL ) {
return saveas_sig(NULL, NULL, nw);
}
- file = g_file_new_for_uri(nw->p->filename);
+ file = g_file_new_for_uri(nw->p->uri);
save_presentation(nw->p, file);
g_object_unref(file);
}
@@ -660,14 +660,14 @@ static void start_slideshow_sig(GSimpleAction *action, GVariant *parameter,
static void nw_update_titlebar(NarrativeWindow *nw)
{
- get_titlebar_string(nw->p);
+ char *tb = get_titlebar_string(nw->p);
if ( nw->p->slidewindow != NULL ) {
char *title;
- title = malloc(strlen(nw->p->titlebar)+14);
- sprintf(title, "%s - Colloquium", nw->p->titlebar);
+ title = malloc(strlen(tb)+14);
+ sprintf(title, "%s - Colloquium", tb);
gtk_window_set_title(GTK_WINDOW(nw->window), title);
free(title);
diff --git a/src/presentation.c b/src/presentation.c
index bc0089f..576768d 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -44,7 +44,7 @@ void free_presentation(struct presentation *p)
int final = 0;
/* FIXME: Loads of stuff leaks here */
- free(p->filename);
+ free(p->uri);
imagestore_destroy(p->is);
free(p);
@@ -54,46 +54,15 @@ void free_presentation(struct presentation *p)
}
-static char *safe_basename(const char *in)
-{
- int i;
- char *cpy;
- char *res;
-
- cpy = strdup(in);
-
- /* Get rid of any trailing slashes */
- for ( i=strlen(cpy)-1; i>0; i-- ) {
- if ( cpy[i] == '/' ) {
- cpy[i] = '\0';
- } else {
- break;
- }
- }
-
- /* Find the base name */
- for ( i=strlen(cpy)-1; i>0; i-- ) {
- if ( cpy[i] == '/' ) {
- i++;
- break;
- }
- }
-
- res = strdup(cpy+i);
- /* If we didn't find a previous slash, i==0 so res==cpy */
-
- free(cpy);
-
- return res;
-}
-
-
char *get_titlebar_string(struct presentation *p)
{
- if ( p == NULL || p->filename == NULL ) {
+ if ( p == NULL || p->uri == NULL ) {
return strdup("(untitled)");
} else {
- return safe_basename(p->filename);
+ GFile *f = g_file_new_for_uri(p->uri);
+ char *bn = g_file_get_basename(f);
+ g_object_unref(f);
+ return bn;
}
}
@@ -105,8 +74,7 @@ struct presentation *new_presentation(const char *imagestore)
new = calloc(1, sizeof(struct presentation));
if ( new == NULL ) return NULL;
- new->filename = NULL;
- new->titlebar = get_titlebar_string(new);
+ new->uri = NULL;
new->scblocks = NULL;
@@ -142,7 +110,7 @@ int save_presentation(struct presentation *p, GFile *file)
if ( r ) return 1;
imagestore_set_parent(p->is, g_file_get_parent(file));
- p->filename = g_file_get_uri(file);
+ p->uri = g_file_get_uri(file);
p->saved = 1;
update_titlebar(p->narrative_window);
return 0;
@@ -359,8 +327,8 @@ int load_presentation(struct presentation *p, GFile *file)
install_stylesheet(p);
set_slide_size_from_stylesheet(p);
- assert(p->filename == NULL);
- p->filename = g_file_get_uri(file);
+ assert(p->uri == NULL);
+ p->uri = g_file_get_uri(file);
imagestore_set_parent(p->is, g_file_get_parent(file));
return 0;
diff --git a/src/presentation.h b/src/presentation.h
index ccf696d..ed8a188 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -39,8 +39,7 @@ struct menu_pl;
struct presentation
{
- char *filename;
- char *titlebar; /* basename(filename) or "(untitled)" */
+ char *uri;
int completely_empty;
int saved;
PangoLanguage *lang;