]> www.fi.muni.cz Git - evince.git/commitdiff
Refactor window title building while fixing it for password documents.
authorMarco Pesenti Gritti <mpg@redhat.com>
Sat, 24 Sep 2005 10:01:47 +0000 (10:01 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Sat, 24 Sep 2005 10:01:47 +0000 (10:01 +0000)
2005-09-24  Marco Pesenti Gritti  <mpg@redhat.com>

        * 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.

ChangeLog
shell/ev-window-title.c
shell/ev-window-title.h
shell/ev-window.c

index 572be0c4a37d4ab9ed02d56ac56fbde28fcbd316..d91b7acb59bd870cf69139e14bccdcd314baed8c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-09-24  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * 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  <mpg@redhat.com>
 
        * pdf/ev-poppler.cc:
index cfa013e270f8d38df081a85b3dcfda49708d8fee..1dcd5312c8b06535b4e49ddbe0ef3c42ad01707e 100644 (file)
@@ -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);
 }
index b2035e20531a713c3e2f9906c8294b9bec738e7b..900344eb73b8080fe356966f044b290706389716 100644 (file)
@@ -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
index 19b78f33f203de36e7b6dd5a412b31a7c481f989..9acf50567134d089902c6e0607ddd9eb170ade4b 100644 (file)
@@ -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) {