From: Nickolay V. Shmyrev Date: Fri, 6 Jan 2006 13:23:27 +0000 (+0000) Subject: Don't add pixbuf mime types if pixbuf backend is disabled. X-Git-Tag: EVINCE_0_5_0~15 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=d2291de1b6c2226d9ac294ace75ad4450d6e5cff;p=evince.git Don't add pixbuf mime types if pixbuf backend is disabled. * backend/ev-document-factory.c: (gdk_pixbuf_mime_type_list), (mime_type_supported_by_gdk_pixbuf), (ev_document_factory_get_mime_types), (ev_document_factory_get_all_mime_types): Don't add pixbuf mime types if pixbuf backend is disabled. * shell/ev-application.c: (ev_application_get_uri_window): Fix for the bug 325815 - unhandled MIME type message doesn't appear a second time. * shell/ev-document-types.c: (ev_document_types_add_filters): * shell/ev-window.c: (page_changed_cb), (ev_window_setup_document), (password_dialog_response), (ev_window_popup_password_dialog), (ev_window_load_job_cb), (ev_window_sidebar_position_change_cb), (ev_window_run_fullscreen), (ev_window_stop_fullscreen), (ev_window_run_presentation), (ev_window_stop_presentation), (save_sizing_mode), (ev_window_zoom_changed_cb), (ev_window_continuous_changed_cb), (ev_window_rotation_changed_cb), (ev_window_dual_mode_changed_cb), (ev_window_sidebar_current_page_changed_cb), (ev_window_sidebar_visibility_changed_cb), (ev_window_dispose), (window_state_event_cb), (window_configure_event_cb): Cleanup additional uris holded by EvWindow. --- diff --git a/ChangeLog b/ChangeLog index d72ffc72..ae4c3042 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2006-01-06 Nickolay V. Shmyrev + + * backend/ev-document-factory.c: (gdk_pixbuf_mime_type_list), + (mime_type_supported_by_gdk_pixbuf), + (ev_document_factory_get_mime_types), + (ev_document_factory_get_all_mime_types): + + Don't add pixbuf mime types if pixbuf backend is disabled. + + * shell/ev-application.c: (ev_application_get_uri_window): + + Fix for the bug 325815 - unhandled MIME type message doesn't + appear a second time. + + * shell/ev-document-types.c: (ev_document_types_add_filters): + * shell/ev-window.c: (page_changed_cb), (ev_window_setup_document), + (password_dialog_response), (ev_window_popup_password_dialog), + (ev_window_load_job_cb), (ev_window_sidebar_position_change_cb), + (ev_window_run_fullscreen), (ev_window_stop_fullscreen), + (ev_window_run_presentation), (ev_window_stop_presentation), + (save_sizing_mode), (ev_window_zoom_changed_cb), + (ev_window_continuous_changed_cb), (ev_window_rotation_changed_cb), + (ev_window_dual_mode_changed_cb), + (ev_window_sidebar_current_page_changed_cb), + (ev_window_sidebar_visibility_changed_cb), (ev_window_dispose), + (window_state_event_cb), (window_configure_event_cb): + + Cleanup additional uris holded by EvWindow. + 2006-01-06 Nickolay V. Shmyrev * shell/ev-view.c: (ev_view_scroll), (ev_view_previous_page), diff --git a/backend/ev-document-factory.c b/backend/ev-document-factory.c index a695c452..38054ba1 100644 --- a/backend/ev-document-factory.c +++ b/backend/ev-document-factory.c @@ -85,17 +85,17 @@ const EvDocumentType document_types[] = { }; #ifdef ENABLE_PIXBUF -/* Would be nice to have this in gdk-pixbuf */ -static gboolean -mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) + +static GList* +gdk_pixbuf_mime_type_list () { GSList *formats, *list; - gboolean retval = FALSE; + GList *result; formats = gdk_pixbuf_get_formats (); + result = NULL; - list = formats; - while (list) { + for (list = formats; list != NULL; list = list->next) { GdkPixbufFormat *format = list->data; int i; gchar **mime_types; @@ -106,19 +106,32 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) mime_types = gdk_pixbuf_format_get_mime_types (format); for (i = 0; mime_types[i] != NULL; i++) { - if (strcmp (mime_types[i], mime_type) == 0) { - retval = TRUE; - break; - } + result = g_list_append (result, mime_types[i]); } + } + g_slist_free (formats); - if (retval) - break; + return result; +} - list = list->next; +/* Would be nice to have this in gdk-pixbuf */ +static gboolean +mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) +{ + GList *mime_types; + GList *list; + gboolean retval = FALSE; + + mime_types = gdk_pixbuf_mime_type_list (); + for (list = mime_types; list; list = list->next) { + if (strcmp ((char *)list->data, mime_type) == 0) { + retval = TRUE; + break; + } } - - g_slist_free (formats); + + g_list_foreach (mime_types, (GFunc)g_free, NULL); + g_list_free (mime_types); return retval; } @@ -183,6 +196,12 @@ ev_document_factory_get_mime_types (EvBackend backend) GList *types = NULL; int i; +#ifdef ENABLE_PIXBUF + if (backend == EV_BACKEND_PIXBUF) { + return gdk_pixbuf_mime_type_list (); + } +#endif + for (i = 0; i < G_N_ELEMENTS (document_types); i++) { if (document_types[i].backend == backend) { types = g_list_append (types, g_strdup (document_types[i].mime_type)); @@ -201,6 +220,10 @@ ev_document_factory_get_all_mime_types (void) for (i = 0; i < G_N_ELEMENTS (document_types); i++) { types = g_list_append (types, g_strdup (document_types[i].mime_type)); } + +#ifdef ENABLE_PIXBUF + types = g_list_concat (types, gdk_pixbuf_mime_type_list ()); +#endif return types; } diff --git a/shell/ev-application.c b/shell/ev-application.c index eed7be8b..e633ce43 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -214,7 +214,7 @@ ev_application_get_uri_window (EvApplication *application, const char *uri) EvWindow *window = EV_WINDOW (l->data); const char *window_uri = ev_window_get_uri (window); - if (window_uri && strcmp (window_uri, uri) == 0) { + if (window_uri && strcmp (window_uri, uri) == 0 && !ev_window_is_empty (window)) { uri_window = window; break; } diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c index d6634f3c..23d940c2 100644 --- a/shell/ev-document-types.c +++ b/shell/ev-document-types.c @@ -133,7 +133,6 @@ ev_document_types_add_filters (GtkWidget *chooser, EvDocument *document) gtk_file_filter_set_name (filter, _("All Documents")); mime_types = ev_document_factory_get_all_mime_types (); file_filter_add_mime_list_and_free (filter, mime_types); - gtk_file_filter_add_pixbuf_formats (filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); #ifdef ENABLE_PS @@ -158,7 +157,8 @@ ev_document_types_add_filters (GtkWidget *chooser, EvDocument *document) if (document == NULL || backend == EV_BACKEND_PIXBUF) { default_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("Images")); - gtk_file_filter_add_pixbuf_formats (filter); + mime_types = ev_document_factory_get_mime_types (EV_BACKEND_PIXBUF); + file_filter_add_mime_list_and_free (filter, mime_types); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); } #endif diff --git a/shell/ev-window.c b/shell/ev-window.c index 1d6d4ef2..fe2d0a87 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -129,8 +129,6 @@ struct _EvWindowPrivate { /* Document */ char *uri; char *local_uri; - char *loaded_uri; - char *password_uri; EvDocument *document; EvDocument *password_document; @@ -595,7 +593,8 @@ page_changed_cb (EvPageCache *page_cache, EvWindow *ev_window) { update_action_sensitivity (ev_window); - ev_metadata_manager_set_int (ev_window->priv->loaded_uri, "page", page); + if (!ev_window_is_empty (ev_window)) + ev_metadata_manager_set_int (ev_window->priv->uri, "page", page); } static void @@ -803,12 +802,12 @@ ev_window_setup_document (EvWindow *ev_window) ev_window, 0); } - ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT); ev_sidebar_set_document (sidebar, document); if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) { ev_view_set_document (view, document); } + ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT); ev_window_title_set_document (ev_window->priv->title, document); ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri); @@ -837,8 +836,6 @@ password_dialog_response (GtkWidget *password_dialog, char *password; if (response_id == GTK_RESPONSE_OK) { - EvDocument *document; - gchar *uri; password = ev_password_dialog_get_password (EV_PASSWORD_DIALOG (password_dialog)); if (password) { @@ -851,21 +848,14 @@ password_dialog_response (GtkWidget *password_dialog, ev_password_dialog_save_password (EV_PASSWORD_DIALOG (password_dialog)); - document = ev_window->priv->password_document; - uri = ev_window->priv->password_uri; - + g_object_unref (ev_window->priv->password_document); ev_window->priv->password_document = NULL; - ev_window->priv->password_uri = NULL; ev_window_title_set_type (ev_window->priv->title, EV_WINDOW_TITLE_DOCUMENT); - ev_job_queue_add_job (ev_window->priv->load_job, EV_JOB_PRIORITY_HIGH); gtk_widget_destroy (password_dialog); - g_object_unref (document); - g_free (uri); - return; } @@ -881,16 +871,15 @@ static void ev_window_popup_password_dialog (EvWindow *ev_window) { g_assert (ev_window->priv->password_document); - g_assert (ev_window->priv->password_uri); 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_uri (ev_window->priv->title, ev_window->priv->uri); ev_window_title_set_type (ev_window->priv->title, EV_WINDOW_TITLE_PASSWORD); if (ev_window->priv->password_dialog == NULL) { ev_window->priv->password_dialog = - g_object_new (EV_TYPE_PASSWORD_DIALOG, "uri", ev_window->priv->password_uri, NULL); + g_object_new (EV_TYPE_PASSWORD_DIALOG, "uri", ev_window->priv->uri, NULL); gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->password_dialog), GTK_WINDOW (ev_window)); g_object_add_weak_pointer (G_OBJECT (ev_window->priv->password_dialog), @@ -969,24 +958,16 @@ ev_window_load_job_cb (EvJobLoad *job, g_object_unref (ev_window->priv->password_document); ev_window->priv->password_document = NULL; } - if (ev_window->priv->password_uri) { - g_free (ev_window->priv->password_uri); - ev_window->priv->password_uri = NULL; - } /* Success! */ if (job->error == NULL) { + if (ev_window->priv->document) g_object_unref (ev_window->priv->document); ev_window->priv->document = g_object_ref (document); - ev_window_setup_document (ev_window); - - ev_window_add_recent (ev_window, ev_window->priv->uri); - - if (ev_window->priv->loaded_uri) - g_free (ev_window->priv->loaded_uri); - ev_window->priv->loaded_uri = g_strdup (ev_window->priv->uri); + ev_window_setup_document (ev_window); + ev_window_add_recent (ev_window, ev_window->priv->uri); ev_window_clear_jobs (ev_window); return; @@ -997,7 +978,6 @@ ev_window_load_job_cb (EvJobLoad *job, gchar *base_name, *file_name; ev_window->priv->password_document = g_object_ref (document); - ev_window->priv->password_uri = g_strdup (job->uri); file_name = gnome_vfs_format_uri_for_display (job->uri); base_name = g_path_get_basename (file_name); @@ -1528,8 +1508,9 @@ static void ev_window_sidebar_position_change_cb (GObject *object, GParamSpec *pspec, EvWindow *ev_window) { - ev_metadata_manager_set_int (ev_window->priv->loaded_uri, "sidebar_size", - gtk_paned_get_position (GTK_PANED (object))); + if (!ev_window_is_empty (ev_window)) + ev_metadata_manager_set_int (ev_window->priv->uri, "sidebar_size", + gtk_paned_get_position (GTK_PANED (object))); } static void @@ -1746,7 +1727,8 @@ ev_window_run_fullscreen (EvWindow *window) gtk_window_fullscreen (GTK_WINDOW (window)); ev_window_update_fullscreen_popup (window); - ev_metadata_manager_set_boolean (window->priv->loaded_uri, "fullscreen", TRUE); + if (!ev_window_is_empty (window)) + ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", TRUE); } static void @@ -1775,7 +1757,8 @@ ev_window_stop_fullscreen (EvWindow *window) update_chrome_visibility (window); update_sidebar_visibility (window); - ev_metadata_manager_set_boolean (window->priv->loaded_uri, "fullscreen", FALSE); + if (!ev_window_is_empty (window)) + ev_metadata_manager_set_boolean (window->priv->uri, "fullscreen", FALSE); } static void @@ -1822,7 +1805,8 @@ ev_window_run_presentation (EvWindow *window) update_chrome_visibility (window); gtk_widget_hide (window->priv->sidebar); - ev_metadata_manager_set_boolean (window->priv->loaded_uri, "presentation", TRUE); + if (!ev_window_is_empty (window)) + ev_metadata_manager_set_boolean (window->priv->uri, "presentation", TRUE); } static void @@ -1840,7 +1824,8 @@ ev_window_stop_presentation (EvWindow *window) update_chrome_visibility (window); update_sidebar_visibility (window); - ev_metadata_manager_set_boolean (window->priv->loaded_uri, "presentation", FALSE); + if (!ev_window_is_empty (window)) + ev_metadata_manager_set_boolean (window->priv->uri, "presentation", FALSE); } static void @@ -2201,8 +2186,9 @@ save_sizing_mode (EvWindow *window) mode = ev_view_get_sizing_mode (EV_VIEW (window->priv->view)); enum_value = g_enum_get_value (EV_SIZING_MODE_CLASS, mode); - ev_metadata_manager_set_string (window->priv->loaded_uri, "sizing_mode", - enum_value->value_nick); + if (!ev_window_is_empty (window)) + ev_metadata_manager_set_string (window->priv->uri, "sizing_mode", + enum_value->value_nick); } static void @@ -2259,8 +2245,8 @@ ev_window_zoom_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window) { update_action_sensitivity (ev_window); - if (ev_view_get_sizing_mode (view) == EV_SIZING_FREE) { - ev_metadata_manager_set_double (ev_window->priv->loaded_uri, "zoom", + if (ev_view_get_sizing_mode (view) == EV_SIZING_FREE && !ev_window_is_empty (ev_window)) { + ev_metadata_manager_set_double (ev_window->priv->uri, "zoom", ev_view_get_zoom (view)); } } @@ -2297,8 +2283,10 @@ static void ev_window_continuous_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window) { ev_window_update_continuous_action (ev_window); - ev_metadata_manager_set_boolean (ev_window->priv->loaded_uri, "continuous", - ev_view_get_continuous (EV_VIEW (ev_window->priv->view))); + + if (!ev_window_is_empty (ev_window)) + ev_metadata_manager_set_boolean (ev_window->priv->uri, "continuous", + ev_view_get_continuous (EV_VIEW (ev_window->priv->view))); } static void @@ -2308,8 +2296,9 @@ ev_window_rotation_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *window rotation = ev_view_get_rotation (EV_VIEW (window->priv->view)); - ev_metadata_manager_set_int (window->priv->loaded_uri, "rotation", - rotation); + if (!ev_window_is_empty (window)) + ev_metadata_manager_set_int (window->priv->uri, "rotation", + rotation); ev_sidebar_thumbnails_refresh (EV_SIDEBAR_THUMBNAILS (window->priv->sidebar_thumbs), rotation); @@ -2325,8 +2314,10 @@ static void ev_window_dual_mode_changed_cb (EvView *view, GParamSpec *pspec, EvWindow *ev_window) { ev_window_update_dual_page_action (ev_window); - ev_metadata_manager_set_boolean (ev_window->priv->loaded_uri, "dual-page", - ev_view_get_dual_page (EV_VIEW (ev_window->priv->view))); + + if (!ev_window_is_empty (ev_window)) + ev_metadata_manager_set_boolean (ev_window->priv->uri, "dual-page", + ev_view_get_dual_page (EV_VIEW (ev_window->priv->view))); } static char * @@ -2457,7 +2448,9 @@ ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar, } g_object_unref (current_page); - ev_metadata_manager_set_string (ev_window->priv->loaded_uri, "sidebar_page", id); + + if (!ev_window_is_empty (ev_window)) + ev_metadata_manager_set_string (ev_window->priv->uri, "sidebar_page", id); } static void @@ -2477,8 +2470,9 @@ ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspe (action, G_CALLBACK (ev_window_view_sidebar_cb), ev_window); if (!ev_view_get_presentation (view) && - !ev_view_get_fullscreen (view)) { - ev_metadata_manager_set_boolean (ev_window->priv->loaded_uri, "sidebar_visibility", + !ev_view_get_fullscreen (view) && + !ev_window_is_empty (ev_window)) { + ev_metadata_manager_set_boolean (ev_window->priv->uri, "sidebar_visibility", GTK_WIDGET_VISIBLE (ev_sidebar)); } } @@ -2720,11 +2714,6 @@ ev_window_dispose (GObject *object) priv->password_document = NULL; } - if (priv->password_uri) { - g_free (priv->password_uri); - priv->password_uri = NULL; - } - ev_window_close_dialogs (window); if (priv->link) { @@ -2740,11 +2729,6 @@ ev_window_dispose (GObject *object) priv->find_bar = NULL; } - if (priv->loaded_uri) { - g_free (priv->loaded_uri); - priv->loaded_uri = NULL; - } - if (priv->uri) { g_free (priv->uri); priv->uri = NULL; @@ -3158,7 +3142,8 @@ window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer du gboolean maximized; maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED; - ev_metadata_manager_set_boolean (window->priv->loaded_uri, "window_maximized", maximized); + if (!ev_window_is_empty (window)) + ev_metadata_manager_set_boolean (window->priv->uri, "window_maximized", maximized); } return FALSE; @@ -3167,7 +3152,7 @@ window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer du static gboolean window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy) { - char *uri = window->priv->loaded_uri; + char *uri = window->priv->uri; GdkWindowState state; int x, y, width, height; @@ -3177,10 +3162,12 @@ window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer gtk_window_get_position (GTK_WINDOW (window), &x, &y); gtk_window_get_size (GTK_WINDOW (window), &width, &height); - ev_metadata_manager_set_int (uri, "window_x", x); - ev_metadata_manager_set_int (uri, "window_y", y); - ev_metadata_manager_set_int (uri, "window_width", width); - ev_metadata_manager_set_int (uri, "window_height", height); + if (!ev_window_is_empty (window)) { + ev_metadata_manager_set_int (uri, "window_x", x); + ev_metadata_manager_set_int (uri, "window_y", y); + ev_metadata_manager_set_int (uri, "window_width", width); + ev_metadata_manager_set_int (uri, "window_height", height); + } } return FALSE;