1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2005 Red Hat, Inc
5 * Evince is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * Evince is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20 #include "ev-window-title.h"
22 #include <glib/gi18n.h>
23 #include <libgnomevfs/gnome-vfs-utils.h>
29 EvWindowTitleType type;
34 ev_window_title_new (EvWindow *window)
36 EvWindowTitle *window_title;
38 window_title = g_new0 (EvWindowTitle, 1);
39 window_title->window = window;
40 window_title->type = EV_WINDOW_TITLE_DOCUMENT;
46 ev_window_title_update (EvWindowTitle *window_title)
48 GtkWindow *window = GTK_WINDOW (window_title->window);
51 switch (window_title->type) {
52 case EV_WINDOW_TITLE_DOCUMENT:
53 gtk_window_set_title (window, window_title->title);
55 case EV_WINDOW_TITLE_PASSWORD:
56 password_title = g_strdup_printf (_("%s - Password Required"),
58 gtk_window_set_title (window, password_title);
59 g_free (password_title);
65 ev_window_title_set_type (EvWindowTitle *window_title, EvWindowTitleType type)
67 window_title->type = type;
69 ev_window_title_update (window_title);
73 ev_window_title_set_document (EvWindowTitle *window_title,
77 EvPageCache *page_cache;
80 window_title->document = document;
82 g_free (window_title->title);
84 if (document == NULL) {
85 window_title->title = NULL;
89 page_cache = ev_page_cache_get (document);
90 g_return_if_fail (page_cache != NULL);
92 title = ev_page_cache_get_title (page_cache);
94 /* Make sure we get a valid title back */
95 if (title && title[0] != '\000' && g_utf8_validate (title, -1, NULL)) {
96 window_title->title = g_strdup (title);
99 if (window_title->title) {
102 for (p = window_title->title; *p; ++p) {
103 /* an '\n' byte is always ASCII, no need for UTF-8 special casing */
109 if (window_title->title == NULL && uri) {
112 display_name = gnome_vfs_format_uri_for_display (uri);
113 window_title->title = g_path_get_basename (display_name);
114 g_free (display_name);
117 if (window_title->title == NULL) {
118 window_title->title = g_strdup (_("Document Viewer"));
121 ev_window_title_update (window_title);
125 ev_window_title_free (EvWindowTitle *window_title)
127 g_free (window_title->title);
128 g_free (window_title);