Ejemplo n.º 1
0
static void
ev_window_title_update (EvWindowTitle *window_title)
{
	GtkWindow *window = GTK_WINDOW (window_title->window);
	char *title = NULL, *password_title, *p;

	if (window_title->document != NULL) {
		gchar *doc_title;

		doc_title = g_strdup (ev_document_get_title (window_title->document));

		/* Make sure we get a valid title back */
		if (doc_title != NULL) {
			doc_title = g_strstrip (doc_title);

			if (doc_title[0] != '\0' &&
			    g_utf8_validate (doc_title, -1, NULL)) {
				title = g_strdup (doc_title);
			}

			g_free (doc_title);
		}
	}

	if (title && window_title->uri) {
		char *tmp_title;
		char *filename = get_filename_from_uri (window_title->uri);

		ev_window_title_sanitize_title (window_title, &title);
		tmp_title = g_strdup_printf ("%s — %s", filename, title);

		g_free (title);
		g_free (filename);
		title = tmp_title;
	} else if (window_title->uri) {
		title = get_filename_from_uri (window_title->uri);
	} else if (!title) {
		title = g_strdup (_("Document Viewer"));
	}

	for (p = title; *p; ++p) {
		/* an '\n' byte is always ASCII, no need for UTF-8 special casing */
		if (*p == '\n')	*p = ' ';
	}

	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;
	}

	g_free (title);
}
Ejemplo n.º 2
0
/* Some docs report titles with confusing extensions (ex. .doc for pdf).
	   Erase the confusing extension of the title */
static void
ev_window_title_sanitize_title (EvWindowTitle *window_title, char **title) {
	const gchar *backend;
	int i;

	backend = G_OBJECT_TYPE_NAME (window_title->document);

	for (i = 0; i < G_N_ELEMENTS (bad_extensions); i++) {
		if (g_ascii_strcasecmp (bad_extensions[i].backend, backend) == 0 && 
		    g_str_has_suffix (*title, bad_extensions[i].text)) {
			char *new_title;
			char *filename = get_filename_from_uri (window_title->uri);

			new_title = g_strndup (*title, strlen(*title) - strlen(bad_extensions[i].text));
			g_free (*title);
			*title = new_title;

			g_free (filename);
		}
	}
	for (i = 0; i < G_N_ELEMENTS (bad_prefixes); i++) {
		if (g_ascii_strcasecmp (bad_prefixes[i].backend, backend) == 0 &&
		    g_str_has_prefix (*title, bad_prefixes[i].text)) {
			char *new_title;
			int len = strlen(bad_prefixes[i].text);
			
			new_title = g_strdup_printf ("%s", (*title) + len);
			g_free (*title);
			*title = new_title;
		}
	}
}
Ejemplo n.º 3
0
/**
 * e_book_backend_db_cache_exists:
 * @uri: URI for the cache
 *
 * Checks if an #EBookBackendCache exists at @uri.
 *
 * Returns: %TRUE if cache exists, %FALSE if not.
 **/
gboolean
e_book_backend_db_cache_exists (const gchar *uri)
{
	gchar *file_name;
	gboolean exists = FALSE;
	file_name = get_filename_from_uri (uri);

	if (file_name && g_file_test (file_name, G_FILE_TEST_EXISTS))
		exists = TRUE;

	g_free (file_name);

	return exists;
}
Ejemplo n.º 4
0
static void
ev_window_title_update (EvWindowTitle *window_title)
{
	GtkWindow *window = GTK_WINDOW (window_title->window);
	GtkHeaderBar *toolbar = GTK_HEADER_BAR (ev_window_get_toolbar (EV_WINDOW (window)));
	char *title = NULL, *p;
	char *subtitle = NULL, *title_header = NULL;

        if (window_title->type == EV_WINDOW_TITLE_RECENT) {
                gtk_header_bar_set_subtitle (toolbar, NULL);
                gtk_window_set_title (window, _("Recent Documents"));
                return;
        }

	if (window_title->doc_title && window_title->uri) {
                title = g_strdup (window_title->doc_title);
                ev_window_title_sanitize_title (window_title, &title);

		subtitle = get_filename_from_uri (window_title->uri);

		title_header = title;
		title = g_strdup_printf ("%s — %s", subtitle, title);

                for (p = title; *p; ++p) {
                        /* an '\n' byte is always ASCII, no need for UTF-8 special casing */
                        if (*p == '\n')
                                *p = ' ';
                }
	} else if (window_title->uri) {
		title = get_filename_from_uri (window_title->uri);
	} else if (!title) {
		title = g_strdup (_("Document Viewer"));
	}

	switch (window_title->type) {
	case EV_WINDOW_TITLE_DOCUMENT:
		gtk_window_set_title (window, title);
		if (title_header && subtitle) {
			gtk_header_bar_set_title (toolbar, title_header);
			gtk_header_bar_set_subtitle (toolbar, subtitle);
		}
		break;
	case EV_WINDOW_TITLE_PASSWORD: {
                gchar *password_title;

		password_title = g_strdup_printf ("%s — %s", title, _("Password Required"));
		gtk_window_set_title (window, password_title);
		g_free (password_title);

                gtk_header_bar_set_title (toolbar, _("Password Required"));
                gtk_header_bar_set_subtitle (toolbar, title);
        }
		break;
        case EV_WINDOW_TITLE_RECENT:
                g_assert_not_reached ();
                break;
	}

	g_free (title);
	g_free (subtitle);
	g_free (title_header);
}