static void gth_media_viewer_page_real_view (GthViewerPage *base, GthFileData *file_data) { GthMediaViewerPage *self; char *uri; self = (GthMediaViewerPage*) base; g_return_if_fail (file_data != NULL); if (! gstreamer_init ()) return; gth_viewer_page_focus (GTH_VIEWER_PAGE (self)); if ((self->priv->file_data != NULL) && g_file_equal (file_data->file, self->priv->file_data->file) && (gth_file_data_get_mtime (file_data) == gth_file_data_get_mtime (self->priv->file_data))) { return; } /**/ _g_object_unref (self->priv->file_data); self->priv->file_data = gth_file_data_dup (file_data); self->priv->duration = 0; _g_object_unref (self->priv->icon); self->priv->icon = NULL; _gth_media_viewer_page_update_caption (self); /**/ gth_viewer_page_file_loaded (GTH_VIEWER_PAGE (self), TRUE); g_signal_handlers_block_by_func(GET_WIDGET ("adjustment_position"), position_value_changed_cb, self); gtk_adjustment_set_value (GTK_ADJUSTMENT (GET_WIDGET ("adjustment_position")), 0.0); g_signal_handlers_unblock_by_func(GET_WIDGET ("adjustment_position"), position_value_changed_cb, self); reset_player_state (self); if (self->priv->playbin == NULL) return; gst_element_set_state (self->priv->playbin, GST_STATE_NULL); uri = g_file_get_uri (self->priv->file_data->file); g_object_set (G_OBJECT (self->priv->playbin), "uri", uri, NULL); gdk_threads_add_idle (set_to_paused, self); g_free (uri); }
static void gth_media_viewer_page_real_view (GthViewerPage *base, GthFileData *file_data) { GthMediaViewerPage *self; char *uri; self = (GthMediaViewerPage*) base; g_return_if_fail (file_data != NULL); if (! gstreamer_init ()) return; gth_viewer_page_focus (GTH_VIEWER_PAGE (self)); if ((self->priv->file_data != NULL) && g_file_equal (file_data->file, self->priv->file_data->file) && (gth_file_data_get_mtime (file_data) == gth_file_data_get_mtime (self->priv->file_data))) { return; } /**/ _g_object_unref (self->priv->file_data); self->priv->file_data = gth_file_data_dup (file_data); self->priv->duration = 0; self->priv->has_audio = FALSE; self->priv->has_video = FALSE; _g_object_unref (self->priv->icon); self->priv->icon = NULL; _gth_media_viewer_page_update_caption (self); /**/ g_signal_handlers_block_by_func(GET_WIDGET ("position_adjustment"), position_value_changed_cb, self); gtk_adjustment_set_value (GTK_ADJUSTMENT (GET_WIDGET ("position_adjustment")), 0.0); g_signal_handlers_unblock_by_func(GET_WIDGET ("position_adjustment"), position_value_changed_cb, self); reset_player_state (self); create_playbin (self); if (self->priv->playbin == NULL) return; uri = g_file_get_uri (self->priv->file_data->file); _gth_media_viewer_page_set_uri (self, uri, self->priv->visible ? GST_STATE_PLAYING : GST_STATE_PAUSED); g_free (uri); }
static GthImage * dcraw_pixbuf_animation_new_from_file (GInputStream *istream, GthFileData *file_data, int requested_size, int *original_width, int *original_height, gpointer user_data, GCancellable *cancellable, GError **error) { GthImage *image = NULL; GdkPixbuf *pixbuf; gboolean is_thumbnail; gboolean is_raw; gboolean is_hdr; char *local_file; char *local_file_md5; char *cache_file; char *cache_file_esc; char *local_file_esc; char *command = NULL; if (file_data == NULL) { if (error != NULL) *error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, "Could not load file"); return NULL; } is_thumbnail = requested_size > 0; is_raw = _g_mime_type_is_raw (gth_file_data_get_mime_type (file_data)); is_hdr = _g_mime_type_is_hdr (gth_file_data_get_mime_type (file_data)); /* The output filename, and its persistence, depend on the input file * type, and whether or not a thumbnail has been requested. */ local_file = g_file_get_path (file_data->file); local_file_md5 = gnome_desktop_thumbnail_md5 (local_file); if (is_raw && !is_thumbnail) /* Full-sized converted RAW file */ cache_file = get_cache_full_path (local_file_md5, "conv.pnm"); else if (is_raw && is_thumbnail) /* RAW: thumbnails generated in pnm format. The converted file is later removed. */ cache_file = get_cache_full_path (local_file_md5, "conv-thumb.pnm"); else if (is_hdr && is_thumbnail) /* HDR: thumbnails generated in tiff format. The converted file is later removed. */ cache_file = get_cache_full_path (local_file_md5, "conv-thumb.tiff"); else /* Full-sized converted HDR files */ cache_file = get_cache_full_path (local_file_md5, "conv.tiff"); g_free (local_file_md5); if (cache_file == NULL) { g_free (local_file); return NULL; } local_file_esc = g_shell_quote (local_file); cache_file_esc = g_shell_quote (cache_file); /* Do nothing if an up-to-date converted file is already in the cache */ if (! g_file_test (cache_file, G_FILE_TEST_EXISTS) || (gth_file_data_get_mtime (file_data) > get_file_mtime (cache_file))) { if (is_raw) { if (is_thumbnail) { char *first_part; char *jpg_thumbnail; char *tiff_thumbnail; char *ppm_thumbnail; char *thumb_command; thumb_command = g_strdup_printf ("dcraw -e %s", local_file_esc); g_spawn_command_line_sync (thumb_command, NULL, NULL, NULL, NULL); g_free (thumb_command); first_part = _g_uri_remove_extension (local_file); jpg_thumbnail = g_strdup_printf ("%s.thumb.jpg", first_part); tiff_thumbnail = g_strdup_printf ("%s.thumb.tiff", first_part); ppm_thumbnail = g_strdup_printf ("%s.thumb.ppm", first_part); if (g_file_test (jpg_thumbnail, G_FILE_TEST_EXISTS)) { g_free (cache_file); cache_file = g_strdup (jpg_thumbnail); } else if (g_file_test (tiff_thumbnail, G_FILE_TEST_EXISTS)) { g_free (cache_file); cache_file = g_strdup (tiff_thumbnail); } else if (g_file_test (ppm_thumbnail, G_FILE_TEST_EXISTS)) { g_free (cache_file); cache_file = g_strdup (ppm_thumbnail); } else { /* No embedded thumbnail. Read the whole file. */ /* Add -h option to speed up thumbnail generation. */ command = g_strdup_printf ("dcraw -w -c -h %s > %s", local_file_esc, cache_file_esc); } g_free (first_part); g_free (jpg_thumbnail); g_free (tiff_thumbnail); g_free (ppm_thumbnail); } else { /* -w option = camera-specified white balance */ command = g_strdup_printf ("dcraw -w -c %s > %s", local_file_esc, cache_file_esc); } } if (is_hdr) { /* HDR files. We can use the pfssize tool to speed up thumbnail generation considerably, so we treat thumbnailing as a special case. */ char *resize_command; if (is_thumbnail) resize_command = g_strdup_printf (" | pfssize --maxx %d --maxy %d", requested_size, requested_size); else resize_command = g_strdup_printf (" "); command = g_strconcat ( "pfsin ", local_file_esc, resize_command, " | pfsclamp --rgb | pfstmo_drago03 | pfsout ", cache_file_esc, NULL ); g_free (resize_command); } if (command != NULL) { if (system (command) == -1) { g_free (command); g_free (cache_file_esc); g_free (local_file_esc); g_free (cache_file); g_free (local_file); return NULL; } g_free (command); } } pixbuf = gdk_pixbuf_new_from_file (cache_file, NULL); /* Thumbnail files are already cached, so delete the conversion cache copies */ if (is_thumbnail) { GFile *file; file = g_file_new_for_path (cache_file); g_file_delete (file, NULL, NULL); g_object_unref (file); } if (pixbuf != NULL) { image = gth_image_new_for_pixbuf (pixbuf); g_object_unref (pixbuf); } g_free (cache_file_esc); g_free (local_file_esc); g_free (cache_file); g_free (local_file); return image; }