]> www.fi.muni.cz Git - evince.git/commitdiff
When title has a confusing extension, show also the document filename
authorMarco Pesenti Gritti <mpg@redhat.com>
Fri, 16 Sep 2005 13:15:29 +0000 (13:15 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Fri, 16 Sep 2005 13:15:29 +0000 (13:15 +0000)
2005-09-16  Marco Pesenti Gritti  <mpg@redhat.com>

        * shell/ev-window-title.c: (get_filename_from_uri),
        (ev_window_title_set_document):

        When title has a confusing extension, show also
        the document filename inside ()

ChangeLog
shell/ev-window-title.c

index 1a0f18fc405bd97ca12ef579785b0ef6290eae29..a692d4459cdf431569732b9e673852c24c36b1eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-09-16  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * shell/ev-window-title.c: (get_filename_from_uri),
+       (ev_window_title_set_document):
+
+       When title has a confusing extension, show also
+       the document filename inside ()
+
 2005-09-16  Marco Pesenti Gritti  <mpg@redhat.com>
 
        * shell/Makefile.am:
index 86f75f3205ccbdaa98f2b0cc84aaa65f58b09c18..787c585e74e3057be0485b2d2bb44e5d07ad5cdd 100644 (file)
  */
 
 #include "ev-window-title.h"
+#include "ev-document-factory.h"
 
 #include <glib/gi18n.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
 
+typedef struct
+{
+       EvBackend backend;
+       const char *ext;
+} BadExtensionEntry;
+
 struct _EvWindowTitle
 {
        EvWindow *window;
@@ -30,6 +37,11 @@ struct _EvWindowTitle
        char *title;
 };
 
+static const BadExtensionEntry bad_extensions[] = {
+       { EV_BACKEND_PS, ".dvi" },
+       { EV_BACKEND_PDF, ".doc" }
+};
+
 EvWindowTitle *
 ev_window_title_new (EvWindow *window)
 {
@@ -69,6 +81,19 @@ ev_window_title_set_type (EvWindowTitle *window_title, EvWindowTitleType type)
        ev_window_title_update (window_title);
 }
 
+static char *
+get_filename_from_uri (const char *uri)
+{
+       char *filename;
+       char *display_name;
+
+       display_name = gnome_vfs_format_uri_for_display (uri);
+       filename = g_path_get_basename (display_name);
+       g_free (display_name);
+
+       return filename;
+}
+
 void
 ev_window_title_set_document (EvWindowTitle *window_title,
                              EvDocument    *document,
@@ -76,6 +101,7 @@ ev_window_title_set_document (EvWindowTitle *window_title,
 {
        EvPageCache *page_cache;
        const char *title;
+       int i;
 
        window_title->document = document;
 
@@ -96,6 +122,22 @@ ev_window_title_set_document (EvWindowTitle *window_title,
                window_title->title = g_strdup (title);
        }
 
+       /* 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);
+
+                       new_title = g_strdup_printf ("%s (%s)", window_title->title, filename);
+                       g_free (window_title->title);
+                       window_title->title = new_title;
+
+                       g_free (filename);
+               }
+       } 
+
        if (window_title->title) {
                char *p;
 
@@ -107,11 +149,7 @@ ev_window_title_set_document (EvWindowTitle *window_title,
        }
 
        if (window_title->title == NULL && uri) {
-               char *display_name;
-
-               display_name = gnome_vfs_format_uri_for_display (uri);
-               window_title->title = g_path_get_basename (display_name);
-               g_free (display_name);
+               window_title->title = get_filename_from_uri (uri);
        }
 
        if (window_title->title == NULL) {