Skip to content

Commit

Permalink
window-title: Save the doc title when a new document is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Garcia Campos committed Jul 26, 2014
1 parent 58ae10c commit aaa04be
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions shell/ev-window-title.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct _EvWindowTitle
EvWindowTitleType type;
EvDocument *document;
char *uri;
char *doc_title;
};

static const BadTitleEntry bad_extensions[] = {
Expand Down Expand Up @@ -112,43 +113,26 @@ ev_window_title_update (EvWindowTitle *window_title)
char *title = NULL, *p;
char *subtitle = NULL, *title_header = NULL;

if (window_title->document != NULL) {
gchar *doc_title;

doc_title = g_strdup (ev_document_get_title (window_title->document));

/* Make sure we get a valid title back */
if (doc_title != NULL) {
doc_title = g_strstrip (doc_title);
if (window_title->doc_title && window_title->uri) {
title = g_strdup (window_title->doc_title);
ev_window_title_sanitize_title (window_title, &title);

if (doc_title[0] != '\0' &&
g_utf8_validate (doc_title, -1, NULL)) {
title = g_strdup (doc_title);
}

g_free (doc_title);
}
}

if (title && window_title->uri) {
subtitle = get_filename_from_uri (window_title->uri);

ev_window_title_sanitize_title (window_title, &title);

title_header = title;
title = g_strdup_printf ("%s — %s", subtitle, title);

for (p = title; *p; ++p) {
/* an '\n' byte is always ASCII, no need for UTF-8 special casing */
if (*p == '\n')
*p = ' ';
}
} else if (window_title->uri) {
title = get_filename_from_uri (window_title->uri);
} else if (!title) {
title = g_strdup (_("Document Viewer"));
}

for (p = title; *p; ++p) {
/* an '\n' byte is always ASCII, no need for UTF-8 special casing */
if (*p == '\n') *p = ' ';
}

switch (window_title->type) {
case EV_WINDOW_TITLE_DOCUMENT:
gtk_window_set_title (window, title);
Expand Down Expand Up @@ -201,7 +185,29 @@ void
ev_window_title_set_document (EvWindowTitle *window_title,
EvDocument *document)
{
if (window_title->document == document)
return;

window_title->document = document;
g_clear_pointer (&window_title->doc_title, g_free);

if (window_title->document != NULL) {
gchar *doc_title;

doc_title = g_strdup (ev_document_get_title (window_title->document));

/* Make sure we get a valid title back */
if (doc_title != NULL) {
doc_title = g_strstrip (doc_title);

if (doc_title[0] != '\0' &&
g_utf8_validate (doc_title, -1, NULL)) {
window_title->doc_title = doc_title;
} else {
g_free (doc_title);
}
}
}

ev_window_title_update (window_title);
}
Expand All @@ -210,6 +216,9 @@ void
ev_window_title_set_uri (EvWindowTitle *window_title,
const char *uri)
{
if (g_strcmp0 (uri, window_title->uri) == 0)
return;

g_free (window_title->uri);
window_title->uri = g_strdup (uri);

Expand All @@ -219,6 +228,7 @@ ev_window_title_set_uri (EvWindowTitle *window_title,
void
ev_window_title_free (EvWindowTitle *window_title)
{
g_free (window_title->doc_title);
g_free (window_title->uri);
g_free (window_title);
}

0 comments on commit aaa04be

Please sign in to comment.