struct _EvWindowTitle
{
EvWindow *window;
- EvDocument *document;
EvWindowTitleType type;
- char *title;
+ EvDocument *document;
+ char *uri;
};
static const BadExtensionEntry bad_extensions[] = {
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)
{
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);
}
void
ev_window_title_free (EvWindowTitle *window_title)
{
- g_free (window_title->title);
+ g_free (window_title->uri);
g_free (window_title);
}