Exemple #1
0
static void
date_optionmenu_changed_cb (GtkOptionMenu *option_menu,
			    DialogData    *data)
{
	char *first_image = data->file_list->data;
	int   idx = gtk_option_menu_get_history (option_menu);

	gtk_widget_set_sensitive (data->date_dateedit, idx == FOLLOWING_DATE);

	switch (idx) {
	case NO_DATE:
	case FOLLOWING_DATE:
	case NO_CHANGE:
		break;
	case CURRENT_DATE:
		gnome_date_edit_set_time (GNOME_DATE_EDIT (data->date_dateedit),
					  time (NULL));

		break;
	case IMAGE_CREATION_DATE:
		gnome_date_edit_set_time (GNOME_DATE_EDIT (data->date_dateedit), 
					  get_file_ctime (first_image));
		break;
	case LAST_MODIFIED_DATE:
		gnome_date_edit_set_time (GNOME_DATE_EDIT (data->date_dateedit), 
					  get_file_mtime (first_image));
		break;
	case EXIF_DATE:
		gnome_date_edit_set_time (GNOME_DATE_EDIT (data->date_dateedit),
					  get_metadata_time (NULL, first_image));
		break;
	}
}
void
nautilus_update_thumbnail_file_copied (const char *source_file_uri,
				       const char *destination_file_uri)
{
	char *old_thumbnail_path;
	time_t mtime;
	GdkPixbuf *pixbuf;
	GnomeDesktopThumbnailFactory *factory;
	
	old_thumbnail_path = gnome_desktop_thumbnail_path_for_uri (source_file_uri, GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
	if (old_thumbnail_path != NULL &&
	    g_file_test (old_thumbnail_path, G_FILE_TEST_EXISTS)) {
		if (get_file_mtime (destination_file_uri, &mtime)) {
			pixbuf = gdk_pixbuf_new_from_file (old_thumbnail_path, NULL);
			
			if (pixbuf && gnome_desktop_thumbnail_has_uri (pixbuf, source_file_uri)) {
				factory = get_thumbnail_factory ();
				gnome_desktop_thumbnail_factory_save_thumbnail (factory,
										pixbuf,
										destination_file_uri,
										mtime);
			}
			
			if (pixbuf) {
				g_object_unref (pixbuf);
			}
		}
	}

	g_free (old_thumbnail_path);
}
Exemple #3
0
static time_t
get_requested_time (DialogData *data, 
		    const char *filename)
{
	int idx  = gtk_option_menu_get_history (GTK_OPTION_MENU (data->date_optionmenu));
	time_t t = (time_t)0;

	switch (idx) {
	case NO_DATE:
		break;
	case FOLLOWING_DATE:
		t = gnome_date_edit_get_time (GNOME_DATE_EDIT (data->date_dateedit));
		break;
	case CURRENT_DATE:
		t = time (NULL);
		break;
	case EXIF_DATE:
		t = get_metadata_time (NULL, filename);
		break;
	case LAST_MODIFIED_DATE:
		t = get_file_mtime (filename);
		break;
	case IMAGE_CREATION_DATE:
		t = get_file_ctime (filename);
		break;
	}

	return t;
}
Exemple #4
0
static gboolean
core_watchdir_idle (gpointer gcore)
{
  GSList * l;
  GSList * changing = NULL;
  GSList * unchanging = NULL;
  TrCore * core = TR_CORE (gcore);
  const time_t now = tr_time ();
  struct TrCorePrivate * p = core->priv;

  /* separate the files into two lists: changing and unchanging */
  for (l=p->monitor_files; l!=NULL; l=l->next)
    {
      GFile * file = l->data;
      const time_t mtime = get_file_mtime (file);
      if (mtime + 2 >= now)
        changing = g_slist_prepend (changing, file);
      else
        unchanging = g_slist_prepend (unchanging, file);
    }

  /* add the files that have stopped changing */
  if (unchanging != NULL)
    {
      const gboolean do_start = gtr_pref_flag_get (TR_KEY_start_added_torrents);
      const gboolean do_prompt = gtr_pref_flag_get (TR_KEY_show_options_window);

      core->priv->adding_from_watch_dir = TRUE;
      gtr_core_add_files (core, unchanging, do_start, do_prompt, TRUE);
      g_slist_foreach (unchanging, (GFunc)rename_torrent_and_unref_file, NULL);
      g_slist_free (unchanging);
      core->priv->adding_from_watch_dir = FALSE;
    }

  /* keep monitoring the ones that are still changing */
  g_slist_free (p->monitor_files);
  p->monitor_files = changing;

  /* if monitor_files is nonempty, keep checking every second */
  if (core->priv->monitor_files)
    return G_SOURCE_CONTINUE;
  core->priv->monitor_idle_tag = 0;
  return G_SOURCE_REMOVE;
}
Exemple #5
0
void
cache_copy (const char *src,
	    const char *dest)
{
	char   *cache_src;
	time_t  dest_mtime = get_file_mtime (dest);

	cache_src = cache_get_nautilus_cache_name (src);
	if (path_is_file (cache_src)) {
		char *cache_dest = cache_get_nautilus_cache_name (dest);

		if (path_is_file (cache_dest))
			file_unlink (cache_dest);
		if (file_copy (cache_src, cache_dest))
			set_file_mtime (cache_dest, dest_mtime);

		g_free (cache_dest);
	}
	g_free (cache_src);
}
void
nautilus_create_thumbnail (NautilusFile *file)
{
	time_t file_mtime = 0;
	NautilusThumbnailInfo *info;
	NautilusThumbnailInfo *existing_info;
	GList *existing, *node;

	nautilus_file_set_is_thumbnailing (file, TRUE);

	info = g_new0 (NautilusThumbnailInfo, 1);
	info->image_uri = nautilus_file_get_uri (file);
	info->mime_type = nautilus_file_get_mime_type (file);
	
	/* Hopefully the NautilusFile will already have the image file mtime,
	   so we can just use that. Otherwise we have to get it ourselves. */
	if (file->details->got_file_info &&
	    file->details->file_info_is_up_to_date &&
	    file->details->mtime != 0) {
		file_mtime = file->details->mtime;
	} else {
		get_file_mtime (info->image_uri, &file_mtime);
	}
	
	info->original_file_mtime = file_mtime;


#ifdef DEBUG_THUMBNAILS
	g_message ("(Main Thread) Locking mutex\n");
#endif
	pthread_mutex_lock (&thumbnails_mutex);
	
	/*********************************
	 * MUTEX LOCKED
	 *********************************/

	if (thumbnails_to_make_hash == NULL) {
		thumbnails_to_make_hash = g_hash_table_new (g_str_hash,
							    g_str_equal);
	}

	/* Check if it is already in the list of thumbnails to make. */
	existing = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
	if (existing == NULL) {
		/* Add the thumbnail to the list. */
#ifdef DEBUG_THUMBNAILS
		g_message ("(Main Thread) Adding thumbnail: %s\n",
			   info->image_uri);
#endif
		g_queue_push_tail ((GQueue *)&thumbnails_to_make, info);
		node = g_queue_peek_tail_link ((GQueue *)&thumbnails_to_make);
		g_hash_table_insert (thumbnails_to_make_hash,
				     info->image_uri,
				     node);
		/* If the thumbnail thread isn't running, and we haven't
		   scheduled an idle function to start it up, do that now.
		   We don't want to start it until all the other work is done,
		   so the GUI will be updated as quickly as possible.*/
		if (thumbnail_thread_is_running == FALSE &&
		    thumbnail_thread_starter_id == 0) {
			thumbnail_thread_starter_id = g_idle_add_full (G_PRIORITY_LOW, thumbnail_thread_starter_cb, NULL, NULL);
		}
	} else {
#ifdef DEBUG_THUMBNAILS
		g_message ("(Main Thread) Updating non-current mtime: %s\n",
			   info->image_uri);
#endif
		/* The file in the queue might need a new original mtime */
		existing_info = existing->data;
		existing_info->original_file_mtime = info->original_file_mtime;
		free_thumbnail_info (info);
	}   

	/*********************************
	 * MUTEX UNLOCKED
	 *********************************/

#ifdef DEBUG_THUMBNAILS
	g_message ("(Main Thread) Unlocking mutex\n");
#endif
	pthread_mutex_unlock (&thumbnails_mutex);
}
Exemple #7
0
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;
}
Exemple #8
0
void
dlg_prop (FrWindow *window)
{
	DialogData       *data;
	GtkWidget        *ok_button;
	GtkWidget        *help_button;
	GtkWidget        *label_label;
	GtkWidget        *label;
	char             *s;
	goffset           size, uncompressed_size;
	char             *utf8_name;
	char             *title_txt;
	double            ratio;

	data = g_new (DialogData, 1);

	data->builder = _gtk_builder_new_from_file ("properties.ui");
	if (data->builder == NULL) {
		g_free (data);
		return;
	}

	/* Get the widgets. */

	data->dialog = _gtk_builder_get_widget (data->builder, "prop_dialog");
	ok_button = _gtk_builder_get_widget (data->builder, "p_ok_button");
	help_button = _gtk_builder_get_widget (data->builder, "p_help_button");

	/* Set widgets data. */

	label_label = _gtk_builder_get_widget (data->builder, "p_path_label_label");
	/* Translators: after the colon there is a folder name. */
	set_label (label_label, _("Location:"));

	label = _gtk_builder_get_widget (data->builder, "p_path_label");
	s = remove_level_from_path (fr_window_get_archive_uri (window));
	utf8_name = g_filename_display_name (s);
	gtk_label_set_text (GTK_LABEL (label), utf8_name);
	g_free (utf8_name);
	g_free (s);

	/**/

	label_label = _gtk_builder_get_widget (data->builder, "p_name_label_label");
	set_label (label_label, C_("File", "Name:"));

	label = _gtk_builder_get_widget (data->builder, "p_name_label");
	utf8_name = g_uri_display_basename (fr_window_get_archive_uri (window));
	gtk_label_set_text (GTK_LABEL (label), utf8_name);

	title_txt = g_strdup_printf (_("%s Properties"), utf8_name);
	gtk_window_set_title (GTK_WINDOW (data->dialog), title_txt);
	g_free (title_txt);

	g_free (utf8_name);

	/**/

	label_label = _gtk_builder_get_widget (data->builder, "p_date_label_label");
	set_label (label_label, _("Last modified:"));

	label = _gtk_builder_get_widget (data->builder, "p_date_label");
	s = get_time_string (get_file_mtime (fr_window_get_archive_uri (window)));
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	label_label = _gtk_builder_get_widget (data->builder, "p_size_label_label");
	set_label (label_label, _("Archive size:"));

	label = _gtk_builder_get_widget (data->builder, "p_size_label");
	size = get_file_size (fr_window_get_archive_uri (window));
	s = g_format_size (size);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	label_label = _gtk_builder_get_widget (data->builder, "p_uncomp_size_label_label");
	set_label (label_label, _("Content size:"));

	uncompressed_size = 0;
	if (fr_window_archive_is_present (window)) {
		int i;

		for (i = 0; i < window->archive->command->files->len; i++) {
			FileData *fd = g_ptr_array_index (window->archive->command->files, i);
			uncompressed_size += fd->size;
		}
	}

	label = _gtk_builder_get_widget (data->builder, "p_uncomp_size_label");
	s = g_format_size (uncompressed_size);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	label_label = _gtk_builder_get_widget (data->builder, "p_cratio_label_label");
	set_label (label_label, _("Compression ratio:"));

	label = _gtk_builder_get_widget (data->builder, "p_cratio_label");

	if (uncompressed_size != 0)
		ratio = (double) uncompressed_size / size;
	else
		ratio = 0.0;
	s = g_strdup_printf ("%0.2f", ratio);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/**/

	label_label = _gtk_builder_get_widget (data->builder, "p_files_label_label");
	set_label (label_label, _("Number of files:"));

	label = _gtk_builder_get_widget (data->builder, "p_files_label");
	s = g_strdup_printf ("%d", window->archive->command->n_regular_files);
	gtk_label_set_text (GTK_LABEL (label), s);
	g_free (s);

	/* Set the signals handlers. */

	g_signal_connect (G_OBJECT (data->dialog),
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  data);
	g_signal_connect_swapped (G_OBJECT (ok_button),
				  "clicked",
				  G_CALLBACK (gtk_widget_destroy),
				  G_OBJECT (data->dialog));
	g_signal_connect (G_OBJECT (help_button),
			  "clicked",
			  G_CALLBACK (help_cb),
			  data);

	/* Run dialog. */

	gtk_window_set_transient_for (GTK_WINDOW (data->dialog),
				      GTK_WINDOW (window));
	gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE);

	gtk_widget_show (data->dialog);
}