static void update_image_preview (GtkFileChooser *chooser, GtkImage *image) { GdkPixbuf *image_pixbuf, *temp; static GdkPixbuf *emblem_pixbuf = NULL; gchar *filename; GdkPixmap *pixmap; gint width, height; if (emblem_pixbuf == NULL) { emblem_pixbuf = gdk_pixbuf_new_from_file (FYRE_DATADIR "/metadata-emblem.png", NULL); if (!emblem_pixbuf) emblem_pixbuf = gdk_pixbuf_new_from_file (BR_DATADIR ("/fyre/metadata-emblem.png"), NULL); } filename = gtk_file_chooser_get_filename (chooser); if (filename == NULL) { gtk_file_chooser_set_preview_widget_active (chooser, FALSE); return; } image_pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 112, 112, NULL); if (image_pixbuf == NULL) { gtk_file_chooser_set_preview_widget_active (chooser, FALSE); return; } width = gdk_pixbuf_get_width (image_pixbuf); height = gdk_pixbuf_get_height (image_pixbuf); pixmap = gdk_pixmap_new (GTK_WIDGET (image)->window, width + 16, height + 16, -1); gdk_draw_rectangle (pixmap, GTK_WIDGET (image)->style->bg_gc[GTK_STATE_NORMAL], TRUE, 0, 0, width + 16, height + 16); gdk_draw_pixbuf (pixmap, NULL, image_pixbuf, 0, 0, 0, 0, width - 1, height - 1, GDK_RGB_DITHER_NONE, 0, 0); temp = gdk_pixbuf_new_from_file (filename, NULL); if (temp) { if (gdk_pixbuf_get_option (temp, "tEXt::fyre_params")) gdk_draw_pixbuf (pixmap, NULL, emblem_pixbuf, 0, 0, width - 16, height - 16, 31, 31, GDK_RGB_DITHER_NONE, 0, 0); else if (gdk_pixbuf_get_option (temp, "tEXt::de_jong_params")) gdk_draw_pixbuf (pixmap, NULL, emblem_pixbuf, 0, 0, width - 16, height - 16, 31, 31, GDK_RGB_DITHER_NONE, 0, 0); gdk_pixbuf_unref (temp); } if (image_pixbuf) gdk_pixbuf_unref (image_pixbuf); gtk_image_set_from_pixmap (GTK_IMAGE (image), pixmap, NULL); gdk_pixmap_unref (pixmap); gtk_file_chooser_set_preview_widget_active (chooser, TRUE); }
void GtkFileChooserDialog_::set_preview_widget_active(Php::Parameters ¶meters) { gboolean active = (gboolean)parameters[0]; gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER(instance), active); }
static void update_preview_cb (GtkFileChooser *file_chooser, gpointer data) { GtkWidget *preview; gchar *filename, *file_contents = NULL; GdkPixbuf *pixbuf = NULL; gboolean have_preview; gsize length = 0; preview = GTK_WIDGET (data); filename = gtk_file_chooser_get_preview_filename (file_chooser); have_preview = filename && prepare_image (filename, &file_contents, &length, &pixbuf, FALSE); if (have_preview) { g_free (file_contents); have_preview = pixbuf != NULL; } g_free (filename); gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); if (pixbuf) g_object_unref (pixbuf); gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview); }
gboolean images_set_file_chooser_preview_image(GtkImage *preview_image, GtkFileChooser *file_chooser){ gchar *filename=gtk_file_chooser_get_preview_filename(file_chooser); if(G_STR_EMPTY(filename)){ if(filename) uber_free(filename); filename=gtk_file_chooser_get_filename(file_chooser); if(G_STR_EMPTY(filename)){ if(filename) uber_free(filename); return FALSE; } } GdkPixbuf *pixbuf=gdk_pixbuf_new_from_file_at_size(filename, 128, 128, NULL); uber_free(filename); if(!pixbuf) return FALSE; gtk_image_set_from_pixbuf(preview_image, pixbuf); uber_object_unref(pixbuf); gtk_file_chooser_set_preview_widget_active(file_chooser, TRUE); return TRUE; }/*images_set_file_chooser_preview_image(preview_image, file_chooser);*/
static void panel_properties_dialog_chooser_preview_update (GtkFileChooser *file_chooser, gpointer data) { GtkWidget *preview; char *filename; GdkPixbuf *pixbuf; gboolean have_preview; preview = GTK_WIDGET (data); filename = gtk_file_chooser_get_preview_filename (file_chooser); if (filename == NULL) return; pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL); have_preview = (pixbuf != NULL); g_free (filename); gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); if (pixbuf) g_object_unref (pixbuf); gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview); }
JNIEXPORT void JNICALL Java_org_gnome_gtk_GtkFileChooser_gtk_1file_1chooser_1set_1preview_1widget_1active ( JNIEnv* env, jclass cls, jlong _self, jboolean _active ) { GtkFileChooser* self; gboolean active; // convert parameter self self = (GtkFileChooser*) _self; // convert parameter active active = (gboolean) _active; // call function gtk_file_chooser_set_preview_widget_active(self, active); // cleanup parameter self // cleanup parameter active }
static void update_image_preview (GtkFileChooser *chooser) { GtkWidget *image; gchar *file; image = gtk_file_chooser_get_preview_widget (GTK_FILE_CHOOSER (chooser)); file = gtk_file_chooser_get_preview_uri (chooser); if (file != NULL) { GdkPixbuf *pixbuf = NULL; pixbuf = create_preview_pixbuf (file); g_free (file); if (pixbuf != NULL) { gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); g_object_unref (pixbuf); } else { gtk_image_set_from_stock (GTK_IMAGE (image), "gtk-dialog-question", GTK_ICON_SIZE_DIALOG); } } gtk_file_chooser_set_preview_widget_active (chooser, file != NULL); }
static void avatar_chooser_update_preview_cb (GtkFileChooser *file_chooser, EmpathyAvatarChooser *chooser) { gchar *filename; filename = gtk_file_chooser_get_preview_filename (file_chooser); if (filename) { GtkWidget *image; GdkPixbuf *pixbuf = NULL; GdkPixbuf *scaled_pixbuf; pixbuf = gdk_pixbuf_new_from_file (filename, NULL); image = gtk_file_chooser_get_preview_widget (file_chooser); if (pixbuf) { scaled_pixbuf = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_SAVE); gtk_image_set_from_pixbuf (GTK_IMAGE (image), scaled_pixbuf); g_object_unref (scaled_pixbuf); g_object_unref (pixbuf); } else { gtk_image_set_from_stock (GTK_IMAGE (image), "gtk-dialog-question", GTK_ICON_SIZE_DIALOG); } g_free (filename); } gtk_file_chooser_set_preview_widget_active (file_chooser, TRUE); }
static void update_preview_cb (GtkFileChooser *file_chooser, gpointer data) { GtkImage *preview = GTK_IMAGE (data); g_autofree char *filename = gtk_file_chooser_get_preview_filename (file_chooser); gint preview_width = 0; gint preview_height = 0; struct g_stat st_buf; g_autoptr(GdkPixbuf) pixbuf = NULL; GdkPixbufFormat *preview_format = gdk_pixbuf_get_file_info (filename, &preview_width, &preview_height); if (!filename || g_stat (filename, &st_buf) || (!S_ISREG (st_buf.st_mode))) { gtk_file_chooser_set_preview_widget_active (file_chooser, FALSE); return; // stat failed or file is not regular } if (!preview_format || preview_width <= 0 || preview_height <= 0 || preview_width > MAX_PREVIEW_SOURCE_SIZE || preview_height > MAX_PREVIEW_SOURCE_SIZE) { gtk_file_chooser_set_preview_widget_active (file_chooser, FALSE); return; // unpreviewable, 0px, or unsafely large } if (preview_width > MAX_PREVIEW_SIZE || preview_height > MAX_PREVIEW_SIZE) { pixbuf = gdk_pixbuf_new_from_file_at_size (filename, MAX_PREVIEW_SIZE, MAX_PREVIEW_SIZE, NULL); } else { pixbuf = gdk_pixbuf_new_from_file (filename, NULL); } pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf); gtk_widget_set_size_request (GTK_WIDGET (preview), gdk_pixbuf_get_width (pixbuf) + 6, gdk_pixbuf_get_height (pixbuf) + 6); gtk_image_set_from_pixbuf (preview, pixbuf); gtk_file_chooser_set_preview_widget_active (file_chooser, pixbuf != NULL); }
void XojOpenDlg::updatePreviewCallback(GtkFileChooser* fileChooser, void* userData) { gchar* filename = gtk_file_chooser_get_preview_filename(fileChooser); if (!filename) { gtk_file_chooser_set_preview_widget_active(fileChooser, false); return; } string filepath = filename; g_free(filename); filename = NULL; if (filepath.size() <= 4 || filepath.substr(filepath.size() - 4) != ".xoj") { gtk_file_chooser_set_preview_widget_active(fileChooser, false); return; } XojPreviewExtractor extractor; PreviewExtractResult result = extractor.readFile(filepath); if (result != PREVIEW_RESULT_IMAGE_READ) { gtk_file_chooser_set_preview_widget_active(fileChooser, false); return; } GError* error = NULL; GInputStream* in = g_memory_input_stream_new_from_data(extractor.getData().c_str(), extractor.getData().length(), NULL); GdkPixbuf* pixbuf = gdk_pixbuf_new_from_stream(in, NULL, &error); g_input_stream_close(in, NULL, &error); if (pixbuf) { GtkWidget * image = gtk_file_chooser_get_preview_widget(fileChooser); gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); g_object_unref(pixbuf); gtk_file_chooser_set_preview_widget_active(fileChooser, true); } }
void update_preview(GtkFileChooser * fc, gchar * filename, GtkImage * img) { GdkPixbuf * pixbuf; gboolean have_preview; pixbuf = gdk_pixbuf_new_from_file(filename,NULL); have_preview = (pixbuf != NULL); gtk_image_set_from_pixbuf(GTK_IMAGE(img),pixbuf); if (pixbuf) g_object_unref(pixbuf); gtk_file_chooser_set_preview_widget_active(fc,have_preview); }
static void update_preview (GtkFileChooser *chooser, GnomeDesktopThumbnailFactory *thumb_factory) { gchar *uri; uri = gtk_file_chooser_get_preview_uri (chooser); if (uri) { GdkPixbuf *pixbuf = NULL; const gchar *mime_type = NULL; GFile *file; GFileInfo *file_info; GtkWidget *preview; preview = gtk_file_chooser_get_preview_widget (chooser); file = g_file_new_for_uri (uri); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (file_info != NULL) { mime_type = g_file_info_get_content_type (file_info); g_object_unref (file_info); } if (mime_type) { pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumb_factory, uri, mime_type); } gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT, (pixbuf != NULL)); if (pixbuf != NULL) { gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); g_object_unref (pixbuf); } else { gtk_image_set_from_stock (GTK_IMAGE (preview), GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); } g_free (uri); } gtk_file_chooser_set_preview_widget_active (chooser, TRUE); }
static void on_update_img_preview( GtkFileChooser *chooser, GtkImage* img ) { char* file = gtk_file_chooser_get_preview_filename(chooser); GdkPixbuf* pix = NULL; if(file) { pix = gdk_pixbuf_new_from_file_at_scale( file, 128, 128, TRUE, NULL ); g_free( file ); } if(pix) { gtk_file_chooser_set_preview_widget_active(chooser, TRUE); gtk_image_set_from_pixbuf(img, pix); g_object_unref(pix); } else { gtk_image_clear(img); gtk_file_chooser_set_preview_widget_active(chooser, FALSE); } }
static void update_preview_cb (GtkFileChooser *chooser) { gchar *filename = gtk_file_chooser_get_preview_filename (chooser); gboolean have_preview = FALSE; if (filename) { GdkPixbuf *pixbuf; GError *error = NULL; pixbuf = my_new_from_file_at_size (filename, 128, 128, &error); if (pixbuf) { gtk_image_set_from_pixbuf (GTK_IMAGE (preview_image), pixbuf); g_object_unref (pixbuf); gtk_widget_show (preview_image); gtk_widget_hide (preview_label); have_preview = TRUE; } else { struct stat buf; if (g_stat (filename, &buf) == 0) { gchar *preview_text; gchar *size_str; gchar *modified_time; size_str = format_size (buf.st_size); modified_time = format_time (buf.st_mtime); preview_text = g_strdup_printf ("<i>Modified:</i>\t%s\n" "<i>Size:</i>\t%s\n", modified_time, size_str); gtk_label_set_markup (GTK_LABEL (preview_label), preview_text); g_free (modified_time); g_free (size_str); g_free (preview_text); gtk_widget_hide (preview_image); gtk_widget_show (preview_label); have_preview = TRUE; } } g_free (filename); } gtk_file_chooser_set_preview_widget_active (chooser, have_preview); }
static void UpdateFilePreviewWidget(GtkFileChooser *file_chooser, gpointer preview_widget_voidptr) { GtkImage *preview_widget = GTK_IMAGE(preview_widget_voidptr); char *image_filename = gtk_file_chooser_get_preview_filename(file_chooser); if (!image_filename) { gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE); return; } // We do this so GTK scales down images that are too big, but not scale up images that are too small GdkPixbuf *preview_pixbuf = gdk_pixbuf_new_from_file(image_filename, NULL); if (!preview_pixbuf) { g_free(image_filename); gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE); return; } if (gdk_pixbuf_get_width(preview_pixbuf) > MAX_PREVIEW_SIZE || gdk_pixbuf_get_height(preview_pixbuf) > MAX_PREVIEW_SIZE) { g_object_unref(preview_pixbuf); preview_pixbuf = gdk_pixbuf_new_from_file_at_size(image_filename, MAX_PREVIEW_SIZE, MAX_PREVIEW_SIZE, NULL); } g_free(image_filename); if (!preview_pixbuf) { gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE); return; } // This is the easiest way to do center alignment without worrying about containers // Minimum 3px padding each side (hence the 6) just to make things nice gint x_padding = (MAX_PREVIEW_SIZE + 6 - gdk_pixbuf_get_width(preview_pixbuf)) / 2; gtk_misc_set_padding(GTK_MISC(preview_widget), x_padding, 0); gtk_image_set_from_pixbuf(preview_widget, preview_pixbuf); g_object_unref(preview_pixbuf); gtk_file_chooser_set_preview_widget_active(file_chooser, TRUE); }
void onUpdatePreview() { // Disable preview because we don't know if we will be able to // load/generate the preview successfully. gtk_file_chooser_set_preview_widget_active(m_chooser, false); const char* fn = gtk_file_chooser_get_filename(m_chooser); if (fn && base::is_file(fn)) { GError* err = nullptr; GdkPixbuf* previewPixbuf = gdk_pixbuf_new_from_file_at_scale(fn, 256, 256, true, &err); if (previewPixbuf) { gtk_image_set_from_pixbuf(GTK_IMAGE(m_preview), previewPixbuf); g_object_unref(previewPixbuf); // Now we can enable the preview panel as the preview was // generated. gtk_file_chooser_set_preview_widget_active(m_chooser, true); } if (err) g_error_free(err); } }
static void update_image_preview(void *filechooser, void *image) { #define MAX_PREVIEW_SIZE 256 char *filename = gtk_file_chooser_get_preview_filename(filechooser); if (!filename) return; // load preview void *pixbuf = gdk_pixbuf_new_from_file(filename, NULL); if (!pixbuf) { g_free_utox(filename); gtk_file_chooser_set_preview_widget_active(filechooser, false); return; } // if preview too big load smaller if (gdk_pixbuf_get_width(pixbuf) > MAX_PREVIEW_SIZE || gdk_pixbuf_get_height(pixbuf) > MAX_PREVIEW_SIZE) { g_object_unref(pixbuf); pixbuf = gdk_pixbuf_new_from_file_at_size(filename, MAX_PREVIEW_SIZE, MAX_PREVIEW_SIZE, NULL); } g_free_utox(filename); if (!pixbuf) { gtk_file_chooser_set_preview_widget_active(filechooser, false); return; } // pad to MAX_PREVIEW_SIZE + 3px margins int margin = (MAX_PREVIEW_SIZE + 6 - gdk_pixbuf_get_width(pixbuf)) / 2; gtk_widget_set_margin_left(image, margin); gtk_widget_set_margin_right(image, margin); // set preview gtk_image_set_from_pixbuf(image, pixbuf); g_object_unref(pixbuf); gtk_file_chooser_set_preview_widget_active(filechooser, true); }
static void gtkFileDlgUpdatePreview(GtkFileChooser *file_chooser, Ihandle* ih) { char *filename = gtk_file_chooser_get_preview_filename(file_chooser); IFnss cb = (IFnss)IupGetCallback(ih, "FILE_CB"); if (iupdrvIsFile(filename)) cb(ih, iupgtkStrConvertFromFilename(filename), "SELECT"); else cb(ih, iupgtkStrConvertFromFilename(filename), "OTHER"); g_free (filename); gtk_file_chooser_set_preview_widget_active(file_chooser, TRUE); }
static void wp_update_preview (GtkFileChooser *chooser, AppearanceData *data) { gchar *uri; uri = gtk_file_chooser_get_preview_uri (chooser); if (uri) { GdkPixbuf *pixbuf = NULL; const gchar *mime_type = NULL; GFile *file; GFileInfo *file_info; file = g_file_new_for_uri (uri); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (file_info != NULL) { mime_type = g_file_info_get_content_type (file_info); g_object_unref (file_info); } if (mime_type) { pixbuf = mate_desktop_thumbnail_factory_generate_thumbnail (data->thumb_factory, uri, mime_type); } if (pixbuf != NULL) { gtk_image_set_from_pixbuf (GTK_IMAGE (data->wp_image), pixbuf); g_object_unref (pixbuf); } else { gtk_image_set_from_stock (GTK_IMAGE (data->wp_image), "gtk-dialog-question", GTK_ICON_SIZE_DIALOG); } } gtk_file_chooser_set_preview_widget_active (chooser, TRUE); }
int clip_GTK_FILECHOOSERSETPREVIEWWIDGETACTIVE(ClipMachine * ClipMachineMemory) { C_object *cchooser = _fetch_co_arg(ClipMachineMemory); gboolean set = _clip_parl(ClipMachineMemory, 2); CHECKCOBJ(cchooser, GTK_IS_FILE_CHOOSER(cchooser->object)); CHECKARG(2, LOGICAL_type_of_ClipVarType); gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(cchooser->object), set); return 0; err: return 1; }
static void update_preview_cb(GtkFileChooser *file_chooser, GtkWidget *preview) { gboolean have_preview = FALSE; if (auto filename = gtk_file_chooser_get_preview_filename(file_chooser)) { GError* error = nullptr; auto pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, &error); if (!error) { gtk_image_set_from_pixbuf(GTK_IMAGE(preview), pixbuf); g_object_unref(pixbuf); have_preview = TRUE; } else { // nothing to do, the file is probably not a picture } g_free (filename); } gtk_file_chooser_set_preview_widget_active(file_chooser, have_preview); }
static void gtk_filedialog_update_preview_callback(GtkFileChooser *chooser, gpointer user_data) { GtkWidget *preview = GTK_WIDGET(user_data); wxGtkString filename(gtk_file_chooser_get_preview_filename(chooser)); if ( !filename ) return; GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 128, 128, NULL); gboolean have_preview = pixbuf != NULL; gtk_image_set_from_pixbuf(GTK_IMAGE(preview), pixbuf); if ( pixbuf ) g_object_unref (pixbuf); gtk_file_chooser_set_preview_widget_active(chooser, have_preview); }
/** * exo_gtk_file_chooser_add_thumbnail_preview: * @chooser : a #GtkFileChooser. * * This is a convenience function that adds a preview widget to the @chooser, * which displays thumbnails for the selected filenames using the thumbnail * database. The preview widget is also able to generate thumbnails for all * image formats supported by #GdkPixbuf. * * Use this function whenever you display a #GtkFileChooser to ask the user * to select an image file from the file system. * * The preview widget also supports URIs other than file:-URIs to a certain * degree, but this support is rather limited currently, so you may want to * use gtk_file_chooser_set_local_only() to ensure that the user can only * select files from the local file system. * * When @chooser is configured to select multiple image files - using the * gtk_file_chooser_set_select_multiple() method - the behaviour of the * preview widget is currently undefined, in that it is not defined for * which of the selected files the preview will be displayed. * * Since: 0.3.1.9 **/ void exo_gtk_file_chooser_add_thumbnail_preview (GtkFileChooser *chooser) { GtkWidget *thumbnail_preview; g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); /* add the preview to the file chooser */ thumbnail_preview = _exo_thumbnail_preview_new (); gtk_file_chooser_set_preview_widget (chooser, thumbnail_preview); gtk_file_chooser_set_preview_widget_active (chooser, TRUE); gtk_file_chooser_set_use_preview_label (chooser, FALSE); gtk_widget_show (thumbnail_preview); /* update the preview as necessary */ g_signal_connect (G_OBJECT (chooser), "update-preview", G_CALLBACK (update_preview), thumbnail_preview); /* initially update the preview, in case the file chooser is already setup */ update_preview (chooser, EXO_THUMBNAIL_PREVIEW (thumbnail_preview)); }
void ImageOpenDlg::updatePreviewCallback(GtkFileChooser * fileChooser, void * userData) { gchar * filename = gtk_file_chooser_get_preview_filename(fileChooser); if (filename) { GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(filename, NULL); GtkWidget * image = gtk_file_chooser_get_preview_widget(fileChooser); if (pixbuf) { GdkPixbuf * scaled_pixbuf = pixbufScaleDownIfNecessary(pixbuf, 256); gtk_image_set_from_pixbuf(GTK_IMAGE(image), scaled_pixbuf); g_object_unref(scaled_pixbuf); g_object_unref(pixbuf); } else { gtk_image_set_from_stock(GTK_IMAGE(image), "gtk-dialog-question", GTK_ICON_SIZE_DIALOG); } g_free(filename); } gtk_file_chooser_set_preview_widget_active(fileChooser, true); }
static void cb_gimmix_covers_plugin_cover_file_preview (GtkFileChooser *file_chooser, gpointer data) { GtkWidget *preview = NULL; char *filename = NULL; GdkPixbuf *pixbuf = NULL; gboolean have_preview; preview = GTK_WIDGET (data); filename = gtk_file_chooser_get_preview_filename (file_chooser); pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL); have_preview = (pixbuf != NULL); g_free (filename); gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); if (pixbuf != NULL) { g_object_unref (pixbuf); } gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview); return; }
/** * update the preview of the log file chooser * * \param file_chooser * \param preview * * \return FALSE * */ static gboolean preferences_view_update_preview_logo ( GtkFileChooser *file_chooser, GtkWidget *preview ) { char *filename; GdkPixbuf *pixbuf; gboolean have_preview; filename = gtk_file_chooser_get_preview_filename (file_chooser); if (!filename) return FALSE; pixbuf = gdk_pixbuf_new_from_file_at_size ( filename, LOGO_WIDTH, LOGO_HEIGHT, NULL ); have_preview = ( pixbuf != NULL ); g_free (filename); gtk_image_set_from_pixbuf ( GTK_IMAGE ( preview ), pixbuf ); if ( pixbuf ) g_object_unref ( pixbuf ); gtk_file_chooser_set_preview_widget_active ( file_chooser, have_preview ); return FALSE; }
void XAP_UnixDialog_FileOpenSaveAs::runModal(XAP_Frame * pFrame) { const XAP_StringSet * pSS = m_pApp->getStringSet(); std::string szTitle; std::string szFileTypeLabel; switch (m_id) { case XAP_DIALOG_ID_INSERT_PICTURE: { pSS->getValueUTF8(XAP_STRING_ID_DLG_IP_Title, szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel, szFileTypeLabel); m_bSave = false; break; } case XAP_DIALOG_ID_FILE_OPEN: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_OpenTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel); m_bSave = false; break; } case XAP_DIALOG_ID_FILE_IMPORT: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ImportTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel); m_bSave = false; break; } case XAP_DIALOG_ID_INSERTMATHML: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertMath,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileInsertMath,szFileTypeLabel); m_bSave = false; break; } case XAP_DIALOG_ID_INSERTOBJECT: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertObject,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileInsertObject,szFileTypeLabel); m_bSave = false; break; } case XAP_DIALOG_ID_INSERT_FILE: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel); m_bSave = false; break; } case XAP_DIALOG_ID_FILE_SAVEAS: case XAP_DIALOG_ID_FILE_SAVE_IMAGE: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_SaveAsTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileSaveTypeLabel,szFileTypeLabel); m_bSave = true; break; } case XAP_DIALOG_ID_FILE_EXPORT: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ExportTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileSaveTypeLabel,szFileTypeLabel); m_bSave = true; break; } case XAP_DIALOG_ID_PRINTTOFILE: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_PrintToFileTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FilePrintTypeLabel,szFileTypeLabel); m_bSave = true; break; } case XAP_DIALOG_ID_RECORDTOFILE: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_RecordToFileTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_RecordToFileLabel,szFileTypeLabel); m_bSave = true; break; } case XAP_DIALOG_ID_REPLAYFROMFILE: { pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ReplayFromFileTitle,szTitle); pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ReplayFromFileLabel,szFileTypeLabel); m_bSave = false; break; } default: UT_ASSERT(UT_SHOULD_NOT_HAPPEN); m_bSave = false; break; } // NOTE: we use our string mechanism to localize the dialog's // NOTE: title and the error/confirmation message boxes. we // NOTE: let GTK take care of the localization of the actual // NOTE: buttons and labels on the FileSelection dialog. // Get the GtkWindow of the parent frame XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl()); GtkWidget * parent = pUnixFrameImpl->getTopLevelWindow(); if(parent && (GTK_WIDGET_TOPLEVEL(parent) != TRUE)) { parent = gtk_widget_get_toplevel (parent); } #if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON m_FC = GTK_FILE_CHOOSER( hildon_file_chooser_dialog_new(GTK_WINDOW(parent), (!m_bSave ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE)) ); #else m_FC = GTK_FILE_CHOOSER( gtk_file_chooser_dialog_new (szTitle.c_str(), GTK_WINDOW(parent), (!m_bSave ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, (m_bSave ? GTK_STOCK_SAVE : GTK_STOCK_OPEN), GTK_RESPONSE_ACCEPT, (gchar*)NULL) ); #endif gtk_file_chooser_set_local_only(m_FC, FALSE); abiSetupModalDialog(GTK_DIALOG(m_FC), pFrame, this, GTK_RESPONSE_ACCEPT); GtkWidget * filetypes_pulldown = NULL; std::string s; /* Add a drop-down list of known types to facilitate a file-types selection. We store an indexer in the user data for each menu item in the popup, so we can read the type we need to return. */ if (m_id == XAP_DIALOG_ID_INSERT_PICTURE) { GtkWidget * preview = createDrawingArea (); gtk_widget_show (preview); m_preview = preview; gtk_widget_set_size_request (preview, PREVIEW_WIDTH, PREVIEW_HEIGHT); // place the preview area inside a container to get a nice border GtkWidget * preview_hbox = gtk_hbox_new(FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER(preview_hbox), 4); gtk_box_pack_start(GTK_BOX(preview_hbox), preview, TRUE, TRUE, 0); // attach the preview area to the dialog gtk_file_chooser_set_preview_widget (m_FC, preview_hbox); gtk_file_chooser_set_preview_widget_active (m_FC, true); // connect some signals g_signal_connect (m_FC, "update_preview", G_CALLBACK (file_selection_changed), static_cast<gpointer>(this)); g_signal_connect (preview, "expose_event", G_CALLBACK (s_preview_exposed), static_cast<gpointer>(this)); } #if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON filetypes_pulldown = gtk_combo_box_new(); gtk_widget_show(filetypes_pulldown); GtkWidget * pulldown_hbox = filetypes_pulldown; #else // hbox for our pulldown menu (GTK does its pulldown this way */ GtkWidget * pulldown_hbox = gtk_hbox_new(FALSE, 15); gtk_widget_show(pulldown_hbox); // pulldown label GtkWidget * filetypes_label = gtk_label_new_with_mnemonic(convertMnemonics(szFileTypeLabel).c_str()); gtk_label_set_justify(GTK_LABEL(filetypes_label), GTK_JUSTIFY_RIGHT); gtk_misc_set_alignment(GTK_MISC(filetypes_label), 1.0, 0.5); gtk_widget_show(filetypes_label); gtk_box_pack_start(GTK_BOX(pulldown_hbox), filetypes_label, TRUE, TRUE, 0); // pulldown menu filetypes_pulldown = gtk_combo_box_new(); gtk_widget_show(filetypes_pulldown); gtk_box_pack_end(GTK_BOX(pulldown_hbox), filetypes_pulldown, TRUE, TRUE, 0); gtk_label_set_mnemonic_widget(GTK_LABEL(filetypes_label), filetypes_pulldown); #endif // // add the filters to the dropdown list // GtkComboBox* combo = GTK_COMBO_BOX(filetypes_pulldown); XAP_makeGtkComboBoxText(combo, G_TYPE_INT); // Auto-detect is always an option, but a special one, so we use // a pre-defined constant for the type, and don't use the user-supplied // types yet. pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileTypeAutoDetect,s); XAP_appendComboBoxTextAndInt(combo, s.c_str(), XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO); UT_sint32 activeItemIndex = -1; // add list items { UT_ASSERT(g_strv_length((gchar **) m_szSuffixes) == g_strv_length((gchar **) m_szDescriptions)); // measure one list, they should all be the same length UT_uint32 end = g_strv_length((gchar **) m_szDescriptions); for (UT_uint32 i = 0; i < end; i++) { // If this type is default, save its index (i) for later use if (m_nTypeList[i] == m_nDefaultFileType) activeItemIndex = i; XAP_appendComboBoxTextAndInt(combo, m_szDescriptions[i], m_nTypeList[i]); // // Attach a callback when it is activated to change the file suffix // // g_signal_connect(G_OBJECT(thismenuitem), "activate", // G_CALLBACK(s_filetypechanged), // reinterpret_cast<gpointer>(this)); } } m_wFileTypes_PullDown = filetypes_pulldown; // dialog; open dialog always does auto-detect // TODO: should this also apply to the open dialog? if (m_id == XAP_DIALOG_ID_FILE_SAVEAS || m_id == XAP_DIALOG_ID_FILE_SAVE_IMAGE) { gtk_combo_box_set_active(combo, activeItemIndex + 1); } else { gtk_combo_box_set_active(combo, 0); } #if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON hildon_file_chooser_dialog_add_extra ((HildonFileChooserDialog*)m_FC, pulldown_hbox); #else gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(m_FC), pulldown_hbox); #endif // connect the signals for OK and CANCEL and the requisite clean-close signals g_signal_connect(G_OBJECT(m_FC), "delete-event", G_CALLBACK(s_delete_clicked), this); g_signal_connect(G_OBJECT(m_FC), "key_press_event", G_CALLBACK(fsel_key_event), &m_answer); g_signal_connect (G_OBJECT (m_FC), "response", G_CALLBACK(dialog_response), &m_answer); g_signal_connect (G_OBJECT (m_FC), "file-activated", G_CALLBACK(s_file_activated), &m_answer); g_signal_connect(G_OBJECT(filetypes_pulldown), "changed", G_CALLBACK(s_filetypechanged), reinterpret_cast<gpointer>(this)); // use the persistence info and/or the suggested filename // to properly seed the dialog. gchar * szPersistDirectory = NULL; // we must g_free this if (!m_szInitialPathname || !*m_szInitialPathname) { // the caller did not supply initial pathname // (or supplied an empty one). see if we have // some persistent info. UT_ASSERT(!m_bSuggestName); if (m_szPersistPathname) { // we have a pathname from a previous use, // extract the directory portion and start // the dialog there (but without a filename). szPersistDirectory = UT_go_dirname_from_uri(m_szPersistPathname, FALSE); gtk_file_chooser_set_current_folder_uri(m_FC, szPersistDirectory); } else { // no initial pathname given and we don't have // a pathname from a previous use, so just let // it come up in the current working directory. } } else { // we have an initial pathname (the name of the document // in the frame that we were invoked on). if the caller // wanted us to suggest a filename, use the initial // pathname as is. if not, use the directory portion of // it. if (m_bSuggestName) { xxx_UT_DEBUGMSG(("Iniitial filename is %s \n",m_szInitialPathname)); #if 0 if (!g_path_is_absolute (m_szInitialPathname)) { // DAL: todo: is this correct? gchar *dir = g_get_current_dir (); gchar *file = m_szInitialPathname; gchar *filename = g_build_filename (dir, file, (gchar *)NULL); m_szInitialPathname = UT_go_filename_to_uri(filename); g_free(filename); g_free (dir); g_free (file); } #endif if(m_id == XAP_DIALOG_ID_FILE_SAVEAS) { std::string szInitialSuffix = UT_pathSuffix(m_szInitialPathname); std::string szSaveTypeSuffix = IE_Exp::preferredSuffixForFileType(m_nDefaultFileType).utf8_str(); if(!szInitialSuffix.empty() && !szSaveTypeSuffix.empty() && (szSaveTypeSuffix != szInitialSuffix)) { std::string sFileName = m_szInitialPathname; std::string::size_type i = sFileName.find_last_of('.'); if(i != std::string::npos) { // erase to the end() sFileName.erase(i); sFileName += szSaveTypeSuffix; FREEP(m_szInitialPathname); m_szInitialPathname = g_strdup(sFileName.c_str()); } } } if (UT_go_path_is_uri(m_szInitialPathname) || UT_go_path_is_path(m_szInitialPathname)) { gtk_file_chooser_set_uri(m_FC, m_szInitialPathname); } } else { if (UT_go_path_is_uri(m_szInitialPathname) || UT_go_path_is_path(m_szInitialPathname)) { szPersistDirectory = UT_go_dirname_from_uri(m_szInitialPathname, FALSE); gtk_file_chooser_set_current_folder_uri(m_FC, szPersistDirectory); } else { // we are dealing with a plain filename, not an URI or path, so // just let it come up in the current working directory. } } } // center the dialog xxx_UT_DEBUGMSG(("before center IS WIDGET_TOP_LEVL %d \n",(GTK_WIDGET_TOPLEVEL(parent)))); xxx_UT_DEBUGMSG(("before center IS WIDGET WINDOW %d \n",(GTK_IS_WINDOW(parent)))); centerDialog(parent, GTK_WIDGET(m_FC)); xxx_UT_DEBUGMSG(("After center IS WIDGET WINDOW %d \n",(GTK_IS_WINDOW(parent)))); gtk_widget_show(GTK_WIDGET(m_FC)); gtk_grab_add(GTK_WIDGET(m_FC)); bool bResult = _run_gtk_main(pFrame,filetypes_pulldown); if (bResult) { UT_ASSERT(m_szFinalPathnameCandidate); // store final path name and file type m_szFinalPathname = g_strdup(m_szFinalPathnameCandidate); FREEP(m_szFinalPathnameCandidate); // what a long ugly line of code m_nFileType = XAP_comboBoxGetActiveInt(GTK_COMBO_BOX(filetypes_pulldown)); } if (m_FC != NULL) { gtk_grab_remove (GTK_WIDGET(m_FC)); gtk_widget_destroy (GTK_WIDGET(m_FC)); m_FC = NULL; FREEP(szPersistDirectory); } return; }
/***************************************************************************** * create_session_save_dialog() *****************************************************************************/ void create_session_save_dialog(void) { GError *error = NULL; GtkWidget *hbox; GtkWidget *label; int new_adj = (session_io_start_adj == NULL); /* this should only need to happen once */ if (session_save_dialog == NULL) { /* create dialog */ session_save_dialog = gtk_file_chooser_dialog_new("PHASEX - Save Session", GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_window_set_wmclass(GTK_WINDOW(session_save_dialog), "phasex", "phasex-save"); gtk_window_set_role(GTK_WINDOW(session_save_dialog), "session-save"); gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER(session_save_dialog), FALSE); /* create spinbutton control of session number */ hbox = gtk_hbox_new(FALSE, 8); label = gtk_label_new("Save into session #:"); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8); if (new_adj) { session_io_start_adj = gtk_adjustment_new(0, 1, PATCH_BANK_SIZE, 1, 8, 0); } session_save_start_spin = gtk_spin_button_new(GTK_ADJUSTMENT(session_io_start_adj), 0, 0); gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(session_save_start_spin), TRUE); gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(session_save_start_spin), GTK_UPDATE_IF_VALID); gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(session_save_start_spin), TRUE); gtk_adjustment_set_value(GTK_ADJUSTMENT(session_io_start_adj), (session_io_start + 1)); gtk_box_pack_start(GTK_BOX(hbox), session_save_start_spin, FALSE, FALSE, 8); if (new_adj) { g_signal_connect(GTK_OBJECT(session_save_start_spin), "value_changed", GTK_SIGNAL_FUNC(set_session_io_start), (gpointer) session_io_start_adj); } gtk_widget_show_all(hbox); gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(session_save_dialog), hbox); /* realize the file chooser before telling it about files */ gtk_widget_realize(session_save_dialog); #if GTK_CHECK_VERSION(2, 8, 0) /* this can go away once manual overwrite checks are proven to work properly */ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER(session_save_dialog), TRUE); #endif #if GTK_CHECK_VERSION(2, 6, 0) gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(session_save_dialog), TRUE); #endif /* add user session dir as shortcut folder (user cannot write to sys) */ gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(session_save_dialog), user_session_dir, &error); if (error != NULL) { PHASEX_ERROR("Error %d: %s\n", error->code, error->message); g_error_free(error); } /* start in user session dir (usually ~/.phasex/user-sessions) */ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(session_save_dialog), user_session_dir); } }
// maybe this should be (partly) in common/imageio.[c|h]? static void _lib_import_update_preview(GtkFileChooser *file_chooser, gpointer data) { GtkWidget *preview; char *filename; GdkPixbuf *pixbuf = NULL; gboolean have_preview = FALSE, no_preview_fallback = FALSE; preview = GTK_WIDGET(data); filename = gtk_file_chooser_get_preview_filename(file_chooser); if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { no_preview_fallback = TRUE; } else { // don't create dng thumbnails to avoid crashes in libtiff when these are hdr: char *c = filename + strlen(filename); while(c > filename && *c != '.') c--; if(!strcasecmp(c, ".dng")) no_preview_fallback = TRUE; } // unfortunately we can not use following, because frequently it uses wrong orientation // pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 128, 128, NULL); have_preview = (pixbuf != NULL); if(!have_preview && !no_preview_fallback) { uint8_t *buffer = NULL; size_t size; char *mime_type = NULL; if(!dt_exif_get_thumbnail(filename, &buffer, &size, &mime_type)) { // Scale the image to the correct size GdkPixbuf *tmp; GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); if (!gdk_pixbuf_loader_write(loader, buffer, size, NULL)) goto cleanup; if (!(tmp = gdk_pixbuf_loader_get_pixbuf(loader))) goto cleanup; float ratio = 1.0 * gdk_pixbuf_get_height(tmp) / gdk_pixbuf_get_width(tmp); int width = 128, height = 128 * ratio; pixbuf = gdk_pixbuf_scale_simple(tmp, width, height, GDK_INTERP_BILINEAR); have_preview = TRUE; cleanup: gdk_pixbuf_loader_close(loader, NULL); free(mime_type); free(buffer); g_object_unref(loader); // This should clean up tmp as well } } if(have_preview && !no_preview_fallback) { // get image orientation dt_image_t img = { 0 }; (void)dt_exif_read(&img, filename); // Rotate the image to the correct orientation GdkPixbuf *tmp = pixbuf; if(img.orientation == ORIENTATION_ROTATE_CCW_90_DEG) { tmp = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); } else if(img.orientation == ORIENTATION_ROTATE_CW_90_DEG) { tmp = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE); } else if(img.orientation == ORIENTATION_ROTATE_180_DEG) { tmp = gdk_pixbuf_rotate_simple(pixbuf, GDK_PIXBUF_ROTATE_UPSIDEDOWN); } if(pixbuf != tmp) { g_object_unref(pixbuf); pixbuf = tmp; } } if(no_preview_fallback || !have_preview) { guint8 *image_buffer = NULL; /* load the dt logo as a brackground */ char filename[PATH_MAX] = { 0 }; char datadir[PATH_MAX] = { 0 }; char *logo; dt_logo_season_t season = get_logo_season(); if(season != DT_LOGO_SEASON_NONE) logo = g_strdup_printf("%%s/pixmaps/idbutton-%d.svg", (int)season); else logo = g_strdup("%s/pixmaps/idbutton.svg"); dt_loc_get_datadir(datadir, sizeof(datadir)); snprintf(filename, sizeof(filename), logo, datadir); g_free(logo); RsvgHandle *svg = rsvg_handle_new_from_file(filename, NULL); if(svg) { cairo_surface_t *surface; cairo_t *cr; RsvgDimensionData dimension; rsvg_handle_get_dimensions(svg, &dimension); float svg_size = MAX(dimension.width, dimension.height); float final_size = 128; float factor = final_size / svg_size; float final_width = dimension.width * factor * darktable.gui->ppd, final_height = dimension.height * factor * darktable.gui->ppd; int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, final_width); image_buffer = (guint8 *)calloc(stride * final_height, sizeof(guint8)); surface = dt_cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_ARGB32, final_width, final_height, stride); if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { free(image_buffer); image_buffer = NULL; } else { cr = cairo_create(surface); cairo_scale(cr, factor, factor); rsvg_handle_render_cairo(svg, cr); cairo_surface_flush(surface); pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, final_width / darktable.gui->ppd, final_height / darktable.gui->ppd); } g_object_unref(svg); } have_preview = TRUE; } if(have_preview) gtk_image_set_from_pixbuf(GTK_IMAGE(preview), pixbuf); if(pixbuf) g_object_unref(pixbuf); g_free(filename); gtk_file_chooser_set_preview_widget_active(file_chooser, have_preview); }
// TODO: use orientation to correctly rotate the image. // maybe this should be (partly) in common/imageio.[c|h]? static void _lib_import_update_preview(GtkFileChooser *file_chooser, gpointer data) { GtkWidget *preview; char *filename; GdkPixbuf *pixbuf = NULL; gboolean have_preview = FALSE; preview = GTK_WIDGET(data); filename = gtk_file_chooser_get_preview_filename(file_chooser); if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) goto no_preview_fallback; // don't create dng thumbnails to avoid crashes in libtiff when these are hdr: char *c = filename + strlen(filename); while(c > filename && *c != '.') c--; if(!strcasecmp(c, ".dng")) goto no_preview_fallback; pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 128, 128, NULL); have_preview = (pixbuf != NULL); if(!have_preview) { // raw image thumbnail int ret; libraw_data_t *raw = libraw_init(0); libraw_processed_image_t *image = NULL; ret = libraw_open_file(raw, filename); if(ret) goto libraw_fail; ret = libraw_unpack_thumb(raw); if(ret) goto libraw_fail; ret = libraw_adjust_sizes_info_only(raw); if(ret) goto libraw_fail; image = libraw_dcraw_make_mem_thumb(raw, &ret); if(!image || ret) goto libraw_fail; // const int orientation = raw->sizes.flip; GdkPixbuf *tmp; GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); have_preview = gdk_pixbuf_loader_write(loader, image->data, image->data_size, NULL); tmp = gdk_pixbuf_loader_get_pixbuf(loader); gdk_pixbuf_loader_close(loader, NULL); float ratio; if(image->type == LIBRAW_IMAGE_JPEG) { // jpeg dt_imageio_jpeg_t jpg; if(dt_imageio_jpeg_decompress_header(image->data, image->data_size, &jpg)) goto libraw_fail; ratio = 1.0*jpg.height/jpg.width; } else { // bmp -- totally untested ratio = 1.0*image->height/image->width; } int width = 128, height = 128*ratio; pixbuf = gdk_pixbuf_scale_simple(tmp, width, height, GDK_INTERP_BILINEAR); if(loader) g_object_unref(loader); // clean up raw stuff. libraw_recycle(raw); libraw_close(raw); free(image); if(0) { libraw_fail: // fprintf(stderr,"[imageio] %s: %s\n", filename, libraw_strerror(ret)); libraw_close(raw); have_preview = FALSE; } } if(!have_preview) { no_preview_fallback: pixbuf = gdk_pixbuf_new_from_inline(-1, dt_logo_128x128, FALSE, NULL); have_preview = TRUE; } if(have_preview) gtk_image_set_from_pixbuf(GTK_IMAGE(preview), pixbuf); if(pixbuf) g_object_unref(pixbuf); g_free(filename); gtk_file_chooser_set_preview_widget_active(file_chooser, have_preview); }