static void file_chooser_dialog_response_cb (GtkDialog *dialog, int response, gpointer user_data) { GthSlideshowPreferences *self = user_data; switch (response) { case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_CANCEL: gtk_widget_destroy (GTK_WIDGET (dialog)); break; case GTK_RESPONSE_OK: { GSList *files; GthIconCache *icon_cache; GtkListStore *list_store; GSList *scan; files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog)); icon_cache = gth_icon_cache_new_for_widget(GTK_WIDGET (self), GTK_ICON_SIZE_MENU); list_store = (GtkListStore *) gtk_builder_get_object (self->priv->builder, "files_liststore"); for (scan = files; scan; scan = scan->next) { GFile *file = scan->data; GIcon *icon; GdkPixbuf *pixbuf; char *uri; char *name; GtkTreeIter iter; icon = g_content_type_get_icon ("audio"); pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon); uri = g_file_get_uri (file); name = _g_file_get_display_name (file); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, FILE_COLUMN_ICON, pixbuf, FILE_COLUMN_NAME, name, FILE_COLUMN_URI, uri, -1); g_free (name); g_free (uri); g_object_unref (pixbuf); } gth_icon_cache_free (icon_cache); g_slist_foreach (files, (GFunc) g_object_unref, NULL); g_slist_free (files); } gtk_widget_destroy (GTK_WIDGET (dialog)); break; } }
static void fr_file_selector_dialog_unrealize (GtkWidget *widget) { FrFileSelectorDialog *self; self = FR_FILE_SELECTOR_DIALOG (widget); gth_icon_cache_free (self->priv->icon_cache); self->priv->icon_cache = NULL; GTK_WIDGET_CLASS (fr_file_selector_dialog_parent_class)->unrealize (widget); }
void gth_slideshow_preferences_set_audio (GthSlideshowPreferences *self, char **files) { GthIconCache *icon_cache; GtkListStore *list_store; int i; icon_cache = gth_icon_cache_new_for_widget(GTK_WIDGET (self), GTK_ICON_SIZE_MENU); list_store = (GtkListStore *) gtk_builder_get_object (self->priv->builder, "files_liststore"); gtk_list_store_clear (list_store); for (i = 0; files[i] != NULL; i++) { GIcon *icon; GdkPixbuf *pixbuf; GFile *file; char *name; GtkTreeIter iter; icon = g_content_type_get_icon ("audio"); pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon); file = g_file_new_for_uri (files[i]); name = _g_file_get_display_name (file); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, FILE_COLUMN_ICON, pixbuf, FILE_COLUMN_NAME, name, FILE_COLUMN_URI, files[i], -1); g_free (name); g_object_unref (file); g_object_unref (pixbuf); } gth_icon_cache_free (icon_cache); }
void dlg_resize_images (GthBrowser *browser, GList *file_list) { DialogData *data; GArray *savers; GthFileData *first_file_data; GthUnit unit; int default_width_in_pixels; int default_height_in_pixels; if (gth_browser_get_dialog (browser, "resize_images") != NULL) { gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "resize_images"))); return; } data = g_new0 (DialogData, 1); data->browser = browser; data->builder = _gtk_builder_new_from_file ("resize-images.ui", "resize_images"); data->settings = g_settings_new (GTHUMB_RESIZE_IMAGES_SCHEMA); data->file_list = gth_file_data_list_dup (file_list); data->use_destination = TRUE; /* Get the widgets. */ data->dialog = _gtk_builder_get_widget (data->builder, "resize_images_dialog"); gth_browser_set_dialog (browser, "resize_images", data->dialog); g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data); /* Set widgets data. */ first_file_data = (GthFileData *) data->file_list->data; _gtk_file_chooser_set_file_parent (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")), first_file_data->file, NULL); unit = g_settings_get_enum (data->settings, PREF_RESIZE_IMAGES_UNIT); gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")), unit); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_ratio_checkbutton")), g_settings_get_boolean (data->settings, PREF_RESIZE_IMAGES_KEEP_RATIO)); default_width_in_pixels = DEFAULT_WIDTH_PIXELS; default_height_in_pixels = DEFAULT_HEIGHT_PIXELS; if (data->file_list->next == NULL) { GthMetadataProvider *provider; int width; int height; provider = g_object_new (GTH_TYPE_METADATA_PROVIDER_IMAGE, NULL); gth_metadata_provider_read (provider, first_file_data, "image::width,image::height", NULL); width = g_file_info_get_attribute_int32 (first_file_data->info, "image::width"); height = g_file_info_get_attribute_int32 (first_file_data->info, "image::height"); if ((width > 0) && (height > 0)) { data->known_ratio = TRUE; data->ratio = (double) width / height; default_width_in_pixels = width; default_height_in_pixels = height; } g_object_unref (provider); } if (unit == GTH_UNIT_PERCENTAGE) { data->latest_width_in_pixel = default_width_in_pixels; data->latest_height_in_pixel = default_height_in_pixels; data->latest_width_in_percentage = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_WIDTH); data->latest_height_in_percentage = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_HEIGHT); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("width_spinbutton")), data->latest_width_in_percentage); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("height_spinbutton")), data->latest_height_in_percentage); } else if (unit == GTH_UNIT_PIXELS) { data->latest_width_in_percentage = DEFAULT_WIDTH_PERCENTAGE; data->latest_height_in_percentage = DEFAULT_HEIGHT_PERCENTAGE; data->latest_width_in_pixel = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_WIDTH); data->latest_height_in_pixel = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_HEIGHT); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("width_spinbutton")), data->latest_width_in_pixel); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("height_spinbutton")), data->latest_height_in_pixel); } savers = gth_main_get_type_set ("image-saver"); if (savers != NULL) { GtkListStore *list_store; GtkTreeIter iter; char *default_mime_type; GthIconCache *icon_cache; int i; list_store = (GtkListStore *) GET_WIDGET ("mime_type_liststore"); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, MIME_TYPE_COLUMN_ICON, NULL, MIME_TYPE_COLUMN_TYPE, NULL, MIME_TYPE_COLUMN_DESCRIPTION, _("Keep the original format"), -1); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter); default_mime_type = g_settings_get_string (data->settings, PREF_RESIZE_IMAGES_MIME_TYPE); icon_cache = gth_icon_cache_new_for_widget (data->dialog, GTK_ICON_SIZE_MENU); for (i = 0; i < savers->len; i++) { GType saver_type; GthImageSaver *saver; const char *mime_type; GdkPixbuf *pixbuf; saver_type = g_array_index (savers, GType, i); saver = g_object_new (saver_type, NULL); mime_type = gth_image_saver_get_mime_type (saver); pixbuf = gth_icon_cache_get_pixbuf (icon_cache, g_content_type_get_icon (mime_type)); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, MIME_TYPE_COLUMN_ICON, pixbuf, MIME_TYPE_COLUMN_TYPE, mime_type, MIME_TYPE_COLUMN_DESCRIPTION, g_content_type_get_description (mime_type), -1); if (strcmp (default_mime_type, mime_type) == 0) gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter); g_object_unref (pixbuf); g_object_unref (saver); } gth_icon_cache_free (icon_cache); g_free (default_mime_type); } /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (destroy_cb), data); g_signal_connect (GET_WIDGET ("ok_button"), "clicked", G_CALLBACK (ok_clicked_cb), data); g_signal_connect (GET_WIDGET ("help_button"), "clicked", G_CALLBACK (help_clicked_cb), data); g_signal_connect_swapped (GET_WIDGET ("cancel_button"), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (data->dialog)); g_signal_connect (GET_WIDGET ("unit_combobox"), "changed", G_CALLBACK (unit_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("use_destination_checkbutton"), "toggled", G_CALLBACK (use_destination_checkbutton_toggled_cb), data); data->width_spinbutton_event = g_signal_connect (GET_WIDGET ("width_spinbutton"), "value-changed", G_CALLBACK (width_spinbutton_value_changed_cb), data); data->height_spinbutton_event = g_signal_connect (GET_WIDGET ("height_spinbutton"), "value-changed", G_CALLBACK (height_spinbutton_value_changed_cb), data); /* Run dialog. */ update_width_height_properties (data); width_spinbutton_value_changed_cb (NULL, data); if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))) gtk_widget_hide (GET_WIDGET ("use_destination_checkbutton")); gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_widget_show (data->dialog); }