/* This function is added as a very low priority idle function to start the
   thread to create any needed thumbnails. It is added with a very low priority
   so that it doesn't delay showing the directory in the icon/list views.
   We want to show the files in the directory as quickly as possible. */
static gboolean
thumbnail_thread_starter_cb (gpointer data)
{
	pthread_attr_t thread_attributes;
	pthread_t thumbnail_thread;

	/* Don't do this in thread, since g_object_ref is not threadsafe */
	if (thumbnail_factory == NULL) {
		thumbnail_factory = get_thumbnail_factory ();
	}

	/* We create the thread in the detached state, as we don't need/want
	   to join with it at any point. */
	pthread_attr_init (&thread_attributes);
	pthread_attr_setdetachstate (&thread_attributes,
				     PTHREAD_CREATE_DETACHED);
#ifdef _POSIX_THREAD_ATTR_STACKSIZE
	pthread_attr_setstacksize (&thread_attributes, 128*1024);
#endif
#ifdef DEBUG_THUMBNAILS
	g_message ("(Main Thread) Creating thumbnails thread\n");
#endif
	/* We set a flag to indicate the thread is running, so we don't create
	   a new one. We don't need to lock a mutex here, as the thumbnail
	   thread isn't running yet. And we know we won't create the thread
	   twice, as we also check thumbnail_thread_starter_id before
	   scheduling this idle function. */
	thumbnail_thread_is_running = TRUE;
	pthread_create (&thumbnail_thread, &thread_attributes,
			thumbnail_thread_start, NULL);

	thumbnail_thread_starter_id = 0;

	return FALSE;
}
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);
}
Esempio n. 3
0
/* This function is added as a very low priority idle function to start the
   thread to create any needed thumbnails. It is added with a very low priority
   so that it doesn't delay showing the directory in the icon/list views.
   We want to show the files in the directory as quickly as possible. */
static gboolean
thumbnail_thread_starter_cb (gpointer data)
{
    GTask *task;

    /* Don't do this in thread, since g_object_ref is not threadsafe */
    if (thumbnail_factory == NULL)
    {
        thumbnail_factory = get_thumbnail_factory ();
    }

#ifdef DEBUG_THUMBNAILS
    g_message ("(Main Thread) Creating thumbnails thread\n");
#endif
    /* We set a flag to indicate the thread is running, so we don't create
       a new one. We don't need to lock a mutex here, as the thumbnail
       thread isn't running yet. And we know we won't create the thread
       twice, as we also check thumbnail_thread_starter_id before
       scheduling this idle function. */
    thumbnail_thread_is_running = TRUE;
    task = g_task_new (NULL, NULL, NULL, NULL);
    g_task_run_in_thread (task, thumbnail_thread_func);

    thumbnail_thread_starter_id = 0;

    g_object_unref (task);

    return FALSE;
}
gboolean
nautilus_has_valid_failed_thumbnail (NautilusFile *file)
{
	GnomeThumbnailFactory *factory;
	char *uri;
	gboolean res;

	factory = get_thumbnail_factory ();

	uri = nautilus_file_get_uri (file);
	res = gnome_thumbnail_factory_has_valid_failed_thumbnail (factory, uri, file->details->mtime);
	g_free (uri);

	return res;
}
gboolean
nautilus_can_thumbnail (NautilusFile *file)
{
	GnomeDesktopThumbnailFactory *factory;
	gboolean res;
	char *uri;
	time_t mtime;
	char *mime_type;
		
	uri = nautilus_file_get_uri (file);
	mime_type = nautilus_file_get_mime_type (file);
	mtime = nautilus_file_get_mtime (file);
	
	factory = get_thumbnail_factory ();
	res = gnome_desktop_thumbnail_factory_can_thumbnail (factory,
							     uri,
							     mime_type,
							     mtime);
	g_free (mime_type);
	g_free (uri);

	return res;
}
Esempio n. 6
0
gboolean
caja_can_thumbnail (CajaFile *file)
{
    MateDesktopThumbnailFactory *factory;
    gboolean res;
    char *uri;
    time_t mtime;
    char *mime_type;

    uri = caja_file_get_uri (file);
    mime_type = caja_file_get_mime_type (file);
    mtime = caja_file_get_mtime (file);

    factory = get_thumbnail_factory ();
    res = mate_desktop_thumbnail_factory_can_thumbnail (factory,
            uri,
            mime_type,
            mtime);
    g_free (mime_type);
    g_free (uri);

    return res;
}
void
nautilus_update_thumbnail_file_copied (const char *source_file_uri,
				       const char *destination_file_uri)
{
	char *old_thumbnail_path;
	GdkPixbuf *pixbuf;
	GFileInfo *file_info;
	GnomeThumbnailFactory *factory;
	GFile *destination_file;
	
	old_thumbnail_path = gnome_thumbnail_path_for_uri (source_file_uri, GNOME_THUMBNAIL_SIZE_NORMAL);
	if (old_thumbnail_path != NULL &&
	    g_file_test (old_thumbnail_path, G_FILE_TEST_EXISTS)) {
		destination_file = g_file_new_for_uri (destination_file_uri);
		file_info = g_file_query_info (destination_file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL);
		g_object_unref (destination_file);
		if (file_info != NULL) {
			pixbuf = gdk_pixbuf_new_from_file (old_thumbnail_path, NULL);
			
			if (pixbuf && gnome_thumbnail_has_uri (pixbuf, source_file_uri)) {
				factory = get_thumbnail_factory ();
				gnome_thumbnail_factory_save_thumbnail (factory,
									pixbuf,
									destination_file_uri,
									g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED));
			}
			
			if (pixbuf) {
				g_object_unref (pixbuf);
			}
			g_object_unref (file_info);
		}
	}

	g_free (old_thumbnail_path);
}
Esempio n. 8
0
gboolean
nemo_thumbnail_factory_check_status (void)
{
    return gnome_desktop_thumbnail_cache_check_permissions (get_thumbnail_factory (), TRUE);
}