From: Marco Pesenti Gritti Date: Sat, 24 Sep 2005 10:01:47 +0000 (+0000) Subject: Refactor window title building while fixing it for password documents. X-Git-Tag: EVINCE_0_5_0~136 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=eb5323824d3ea421f1bdfa803a9ce968894d8d81;p=evince.git Refactor window title building while fixing it for password documents. 2005-09-24 Marco Pesenti Gritti * shell/ev-window-title.c: (get_filename_from_uri), (ev_window_title_sanitize_extension), (ev_window_title_update), (ev_window_title_set_document), (ev_window_title_set_uri), (ev_window_title_free): * shell/ev-window-title.h: * shell/ev-window.c: (ev_window_setup_document), (ev_window_popup_password_dialog): Refactor window title building while fixing it for password documents. --- diff --git a/ChangeLog b/ChangeLog index 572be0c4..d91b7acb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-09-24 Marco Pesenti Gritti + + * shell/ev-window-title.c: (get_filename_from_uri), + (ev_window_title_sanitize_extension), (ev_window_title_update), + (ev_window_title_set_document), (ev_window_title_set_uri), + (ev_window_title_free): + * shell/ev-window-title.h: + * shell/ev-window.c: (ev_window_setup_document), + (ev_window_popup_password_dialog): + + Refactor window title building while fixing it for + password documents. + 2005-09-24 Marco Pesenti Gritti * pdf/ev-poppler.cc: diff --git a/shell/ev-window-title.c b/shell/ev-window-title.c index cfa013e2..1dcd5312 100644 --- a/shell/ev-window-title.c +++ b/shell/ev-window-title.c @@ -32,9 +32,9 @@ typedef struct struct _EvWindowTitle { EvWindow *window; - EvDocument *document; EvWindowTitleType type; - char *title; + EvDocument *document; + char *uri; }; static const BadExtensionEntry bad_extensions[] = { @@ -54,33 +54,6 @@ ev_window_title_new (EvWindow *window) return window_title; } -static void -ev_window_title_update (EvWindowTitle *window_title) -{ - GtkWindow *window = GTK_WINDOW (window_title->window); - char *password_title; - - switch (window_title->type) { - case EV_WINDOW_TITLE_DOCUMENT: - gtk_window_set_title (window, window_title->title); - break; - case EV_WINDOW_TITLE_PASSWORD: - password_title = g_strdup_printf (_("%s - Password Required"), - window_title->title); - gtk_window_set_title (window, password_title); - g_free (password_title); - break; - } -} - -void -ev_window_title_set_type (EvWindowTitle *window_title, EvWindowTitleType type) -{ - window_title->type = type; - - ev_window_title_update (window_title); -} - static char * get_filename_from_uri (const char *uri) { @@ -94,67 +67,100 @@ get_filename_from_uri (const char *uri) return filename; } -void -ev_window_title_set_document (EvWindowTitle *window_title, - EvDocument *document, - const char *uri) -{ - EvPageCache *page_cache; - const char *title; +/* Some docs report titles with confusing extensions (ex. .doc for pdf). + Let's show the filename in this case */ +static void +ev_window_title_sanitize_extension (EvWindowTitle *window_title, char **title) { + EvBackend backend; int i; - window_title->document = document; - - g_free (window_title->title); - - if (document == NULL) { - window_title->title = NULL; - return; - } - - page_cache = ev_page_cache_get (document); - g_return_if_fail (page_cache != NULL); + backend = ev_document_factory_get_backend (window_title->document); + for (i = 0; i < G_N_ELEMENTS (bad_extensions); i++) { + if (bad_extensions[i].backend == backend && + g_str_has_suffix (*title, bad_extensions[i].ext)) { + char *new_title; + char *filename = get_filename_from_uri (window_title->uri); - title = ev_page_cache_get_title (page_cache); + new_title = g_strdup_printf ("%s (%s)", *title, filename); + g_free (*title); + *title = new_title; - /* Make sure we get a valid title back */ - if (title && title[0] != '\000' && g_utf8_validate (title, -1, NULL)) { - window_title->title = g_strdup (title); + g_free (filename); + } } +} - if (window_title->title) { - char *p; +static void +ev_window_title_update (EvWindowTitle *window_title) +{ + GtkWindow *window = GTK_WINDOW (window_title->window); + char *title = NULL, *password_title, *p; + EvPageCache *page_cache; - /* Some docs report titles with confusing extensions (ex. .doc for pdf). - Let's show the filename in this case */ - for (i = 0; i < G_N_ELEMENTS (bad_extensions); i++) { - if (bad_extensions[i].backend == ev_document_factory_get_backend (document) && - g_str_has_suffix (window_title->title, bad_extensions[i].ext)) { - char *new_title; - char *filename = get_filename_from_uri (uri); + if (window_title->document != NULL) { + const char *doc_title; - new_title = g_strdup_printf ("%s (%s)", window_title->title, filename); - g_free (window_title->title); - window_title->title = new_title; + page_cache = ev_page_cache_get (window_title->document); + g_return_if_fail (page_cache != NULL); + doc_title = ev_page_cache_get_title (page_cache); - g_free (filename); - } + /* Make sure we get a valid title back */ + if (doc_title && doc_title[0] != '\000' && + g_utf8_validate (doc_title, -1, NULL)) { + title = g_strdup (doc_title); } + } - for (p = window_title->title; *p; ++p) { - /* an '\n' byte is always ASCII, no need for UTF-8 special casing */ - if (*p == '\n') - *p = ' '; + if (title) { + ev_window_title_sanitize_extension (window_title, &title); + } else { + if (window_title->uri) { + title = get_filename_from_uri (window_title->uri); + } else { + title = g_strdup (_("Document Viewer")); } } - if (window_title->title == NULL && uri) { - window_title->title = get_filename_from_uri (uri); + for (p = title; *p; ++p) { + /* an '\n' byte is always ASCII, no need for UTF-8 special casing */ + if (*p == '\n') *p = ' '; } - if (window_title->title == NULL) { - window_title->title = g_strdup (_("Document Viewer")); + switch (window_title->type) { + case EV_WINDOW_TITLE_DOCUMENT: + gtk_window_set_title (window, title); + break; + case EV_WINDOW_TITLE_PASSWORD: + password_title = g_strdup_printf (_("%s - Password Required"), title); + gtk_window_set_title (window, password_title); + g_free (password_title); + break; } +} + +void +ev_window_title_set_type (EvWindowTitle *window_title, EvWindowTitleType type) +{ + window_title->type = type; + + ev_window_title_update (window_title); +} + +void +ev_window_title_set_document (EvWindowTitle *window_title, + EvDocument *document) +{ + window_title->document = document; + + ev_window_title_update (window_title); +} + +void +ev_window_title_set_uri (EvWindowTitle *window_title, + const char *uri) +{ + g_free (window_title->uri); + window_title->uri = g_strdup (uri); ev_window_title_update (window_title); } @@ -162,6 +168,6 @@ ev_window_title_set_document (EvWindowTitle *window_title, void ev_window_title_free (EvWindowTitle *window_title) { - g_free (window_title->title); + g_free (window_title->uri); g_free (window_title); } diff --git a/shell/ev-window-title.h b/shell/ev-window-title.h index b2035e20..900344eb 100644 --- a/shell/ev-window-title.h +++ b/shell/ev-window-title.h @@ -37,8 +37,9 @@ EvWindowTitle *ev_window_title_new (EvWindow *window); void ev_window_title_set_type (EvWindowTitle *window_title, EvWindowTitleType type); void ev_window_title_set_document (EvWindowTitle *window_title, - EvDocument *document, - const char *uri); + EvDocument *document); +void ev_window_title_set_uri (EvWindowTitle *window_title, + const char *uri); void ev_window_title_free (EvWindowTitle *window_title); G_END_DECLS diff --git a/shell/ev-window.c b/shell/ev-window.c index 19b78f33..9acf5056 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -689,7 +689,8 @@ ev_window_setup_document (EvWindow *ev_window) ev_view_set_document (view, document); } - ev_window_title_set_document (ev_window->priv->title, document, ev_window->priv->uri); + ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri); + ev_window_title_set_document (ev_window->priv->title, document); action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION); ev_page_action_set_document (EV_PAGE_ACTION (action), document); update_action_sensitivity (ev_window); @@ -762,6 +763,7 @@ ev_window_popup_password_dialog (EvWindow *ev_window) gtk_widget_set_sensitive (ev_window->priv->password_view, FALSE); + ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->password_uri); ev_window_title_set_type (ev_window->priv->title, EV_WINDOW_TITLE_PASSWORD); if (ev_window->priv->password_dialog == NULL) {