Esempio n. 1
0
static void
_gth_media_viewer_page_update_caption (GthMediaViewerPage *self)
{
	if (self->priv->caption_layout == NULL)
		return;

	if (self->priv->file_data != NULL) {
		GString     *description;
		GthMetadata *metadata;

		description = g_string_new ("");
		metadata = (GthMetadata *) g_file_info_get_attribute_object (self->priv->file_data->info, "general::title");
		if (metadata != NULL) {
			g_string_append (description, gth_metadata_get_formatted (metadata));
			metadata = (GthMetadata *) g_file_info_get_attribute_object (self->priv->file_data->info, "audio-video::general::artist");
			if (metadata != NULL) {
				g_string_append (description, "\n");
				g_string_append (description, gth_metadata_get_formatted (metadata));
			}
		}
		else
			g_string_append (description, g_file_info_get_display_name (self->priv->file_data->info));

		pango_layout_set_text (self->priv->caption_layout, description->str, -1);

		g_string_free (description, TRUE);
	}
	else
		pango_layout_set_text (self->priv->caption_layout, "", -1);

	gtk_widget_queue_draw (GTK_WIDGET (self->priv->area));
}
Esempio n. 2
0
void
gth_map_view_real_set_file (GthPropertyView *base,
		 	    GthFileData     *file_data)
{
	GthMapView *self = GTH_MAP_VIEW (base);
	int         coordinates_available;
	double      latitude;
	double      longitude;

	coordinates_available = 0;

	if (file_data != NULL) {
		GthMetadata *metadata;

		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "Exif::GPSInfo::GPSLatitude");
		if (metadata != NULL) {
			latitude = exif_coordinate_to_decimal (gth_metadata_get_raw (metadata));

			metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "Exif::GPSInfo::GPSLatitudeRef");
			if (metadata != NULL) {
				if (g_strcmp0 (gth_metadata_get_raw (metadata), "S") == 0)
					latitude = - latitude;
			}

			coordinates_available++;
		}

		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "Exif::GPSInfo::GPSLongitude");
		if (metadata != NULL) {
			longitude = exif_coordinate_to_decimal (gth_metadata_get_raw (metadata));

			metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "Exif::GPSInfo::GPSLongitudeRef");
			if (metadata != NULL) {
				if (g_strcmp0 (gth_metadata_get_raw (metadata), "W") == 0)
					longitude = - longitude;
			}

			coordinates_available++;
		}
	}

	if (coordinates_available == 2) {
		char *position;

		gtk_widget_hide (self->priv->no_gps_label);
		gtk_widget_show (self->priv->embed);

		position = decimal_coordinates_to_string (latitude, longitude);
		champlain_label_set_text (CHAMPLAIN_LABEL (self->priv->marker), position);
		g_free (position);

		champlain_location_set_location (CHAMPLAIN_LOCATION (self->priv->marker), latitude, longitude);
		champlain_view_center_on (CHAMPLAIN_VIEW (self->priv->map_view), latitude, longitude);
	}
	else {
		gtk_widget_hide (self->priv->embed);
		gtk_widget_show (self->priv->no_gps_label);
	}
}
Esempio n. 3
0
static void
_gth_media_viewer_page_update_caption (GthMediaViewerPage *self)
{
	if (self->priv->caption_layout == NULL)
		return;

	if (self->priv->file_data != NULL) {
		const char  *text;
		GthMetadata *metadata;

		text = NULL;
		metadata = (GthMetadata *) g_file_info_get_attribute_object (self->priv->file_data->info, "general::title");
		if (metadata != NULL)
			text = gth_metadata_get_formatted (metadata);
		else
			text = g_file_info_get_display_name (self->priv->file_data->info);

		if (text != NULL)
			pango_layout_set_text (self->priv->caption_layout, text, -1);
	}
	else
		pango_layout_set_text (self->priv->caption_layout, "", -1);

	gtk_widget_queue_draw (GTK_WIDGET (self->priv->area));
}
static int
flickr_photo_position_func (GthFileData *a,
		            GthFileData *b)
{
	FlickrPhoto *photo_a;
	FlickrPhoto *photo_b;

	photo_a = (FlickrPhoto *) g_file_info_get_attribute_object (a->info, "flickr::object");
	photo_b = (FlickrPhoto *) g_file_info_get_attribute_object (b->info, "flickr::object");

	if (photo_a->position == photo_b->position)
		return strcmp (photo_a->title, photo_b->title);
	else if (photo_a->position > photo_b->position)
		return 1;
	else
		return -1;
}
Esempio n. 5
0
static int
picasa_web_photo_position_func (GthFileData *a,
			        GthFileData *b)
{
	PicasaWebPhoto *photo_a;
	PicasaWebPhoto *photo_b;

	photo_a = (PicasaWebPhoto *) g_file_info_get_attribute_object (a->info, "gphoto::object");
	photo_b = (PicasaWebPhoto *) g_file_info_get_attribute_object (b->info, "gphoto::object");

	if (photo_a->position == photo_b->position)
		return strcmp (photo_a->title, photo_b->title);
	else if (photo_a->position > photo_b->position)
		return 1;
	else
		return -1;
}
Esempio n. 6
0
static int
facebook_photo_position_func (GthFileData *a,
			      GthFileData *b)
{
	FacebookPhoto *photo_a;
	FacebookPhoto *photo_b;

	photo_a = (FacebookPhoto *) g_file_info_get_attribute_object (a->info, "facebook::object");
	photo_b = (FacebookPhoto *) g_file_info_get_attribute_object (b->info, "facebook::object");

	if (photo_a->position == photo_b->position)
		return strcmp (photo_a->id, photo_b->id);
	else if (photo_a->position > photo_b->position)
		return 1;
	else
		return -1;
}
Esempio n. 7
0
static GthImage *
facebook_thumbnail_loader (GInputStream  *istream,
			   GthFileData   *file_data,
			   int            requested_size,
			   int           *original_width,
			   int           *original_height,
			   gboolean      *loaded_original,
			   gpointer       user_data,
			   GCancellable  *cancellable,
			   GError       **error)
{
	GthImage      *image = NULL;
	FacebookPhoto *photo;
	const char    *uri;

	photo = (FacebookPhoto *) g_file_info_get_attribute_object (file_data->info, "facebook::object");

	uri = facebook_photo_get_thumbnail_url (photo, requested_size);
	if (uri == NULL)
		uri = facebook_photo_get_original_url (photo);

	if (uri != NULL) {
		GFile *file;
		void  *buffer;
		gsize  size;

		file = g_file_new_for_uri (uri);
		if (_g_file_load_in_buffer (file, &buffer, &size, cancellable, error)) {
			GInputStream *stream;
			GdkPixbuf    *pixbuf;

			stream = g_memory_input_stream_new_from_data (buffer, size, g_free);
			pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, error);
			if (pixbuf != NULL) {
				GdkPixbuf *rotated;

				rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf);
				g_object_unref (pixbuf);
				pixbuf = rotated;

				image = gth_image_new_for_pixbuf (pixbuf);
			}

			g_object_unref (pixbuf);
			g_object_unref (stream);
		}

		g_object_unref (file);
	}
	else
		*error = g_error_new_literal (GTH_ERROR, 0, "cannot generate the thumbnail");

	return image;
}
Esempio n. 8
0
void
gth_edit_iptc_page_real_set_file_list (GthEditCommentPage *base,
		 		        GList              *file_data_list)
{
	GthEditIptcPage *self;
	GList            *scan;
	GthMetadata      *metadata;

	self = GTH_EDIT_IPTC_PAGE (base);

	self->priv->supported = TRUE;
	for (scan = file_data_list; self->priv->supported && scan; scan = scan->next) {
		GthFileData *file_data = scan->data;
		self->priv->supported = exiv2_supports_writes (gth_file_data_get_mime_type (file_data));
	}

	if (! self->priv->supported) {
		gtk_widget_hide (GTK_WIDGET (base));
		return;
	}

	_g_object_unref (self->priv->info);
	self->priv->info = gth_file_data_list_get_common_info (file_data_list, "Iptc::Application2::Copyright,Iptc::Application2::Credit,Iptc::Application2::Byline,Iptc::Application2::BylineTitle,Iptc::Application2::CountryName,Iptc::Application2::CountryCode,Iptc::Application2::City,Iptc::Application2::Language,Iptc::Application2::ObjectName,Iptc::Application2::Source,Iptc::Envelope::Destination,Iptc::Application2::Urgency,Iptc::Application2:ProvinceState");

	set_entry_value (self, self->priv->info, "Iptc::Application2::Copyright", "copyright_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::Credit", "credit_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::Byline", "byline_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::BylineTitle", "byline_title_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::CountryName", "country_name_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::CountryCode", "country_code_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::ProvinceState", "state_name_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::City", "city_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::Language", "language_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::ObjectName", "object_name_entry");
	set_entry_value (self, self->priv->info, "Iptc::Application2::Source", "source_entry");
	set_entry_value (self, self->priv->info, "Iptc::Envelope::Destination", "destination_entry");

	metadata = (GthMetadata *) g_file_info_get_attribute_object (self->priv->info, "Iptc::Application2::Urgency");
	if (metadata != NULL) {
		float v;

		if (sscanf (gth_metadata_get_formatted (metadata), "%f", &v) == 1)
			gtk_adjustment_set_value (GTK_ADJUSTMENT (GET_WIDGET ("urgency_adjustment")), (double) v);
		else
			gtk_adjustment_set_value (GTK_ADJUSTMENT (GET_WIDGET ("urgency_adjustment")), 0.0);
	}
	else
		gtk_adjustment_set_value (GTK_ADJUSTMENT (GET_WIDGET ("urgency_adjustment")), 0.0);

	gtk_widget_show (GTK_WIDGET (base));
}
Esempio n. 9
0
static void
set_entry_value (GthEditIptcPage *self,
		 GFileInfo        *info,
		 const char       *attribute,
		 const char       *widget_id)
{
	GthMetadata *metadata;

	metadata = (GthMetadata *) g_file_info_get_attribute_object (info, attribute);
	if (metadata != NULL)
		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET (widget_id)), gth_metadata_get_formatted (metadata));
	else
		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET (widget_id)), "");
}
Esempio n. 10
0
static void
gth_file_store_get_value (GtkTreeModel *tree_model,
			  GtkTreeIter  *iter,
			  int           column,
			  GValue       *value)
{
	GthFileStore *file_store;
	GthFileRow   *row;

	g_return_if_fail ((column >= 0) && (column < GTH_FILE_STORE_N_COLUMNS));

	file_store = (GthFileStore *) tree_model;

	g_return_if_fail (VALID_ITER (iter, file_store));

	row = (GthFileRow*) iter->user_data;

	switch (column) {
	case GTH_FILE_STORE_FILE_DATA_COLUMN:
		g_value_init (value, GTH_TYPE_FILE_DATA);
		g_value_set_object (value, row->file_data);
		break;
	case GTH_FILE_STORE_THUMBNAIL_COLUMN:
		g_value_init (value, GTH_TYPE_CAIRO_SURFACE);
		g_value_set_boxed (value, row->thumbnail);
		break;
	case GTH_FILE_STORE_IS_ICON_COLUMN:
		g_value_init (value, G_TYPE_BOOLEAN);
		g_value_set_boolean (value, row->is_icon);
		break;
	case GTH_FILE_STORE_EMBLEMS_COLUMN:
		g_value_init (value, G_TYPE_STRING);
		g_value_set_object (value, g_file_info_get_attribute_object (row->file_data->info, GTH_FILE_ATTRIBUTE_EMBLEMS));
		break;
	}
}
static void
gth_metadata_provider_comment_write (GthMetadataProvider   *self,
				     GthMetadataWriteFlags  flags,
				     GthFileData           *file_data,
				     const char            *attributes,
				     GCancellable          *cancellable)
{
	GthComment    *comment;
	GthMetadata   *metadata;
	const char    *text;
	char          *data;
	gsize          length;
	GthStringList *categories;
	GFile         *comment_file;
	GFile         *comment_folder;

	comment = gth_comment_new ();

	/* caption */

	text = NULL;
	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::title");
	if (metadata != NULL)
		text = gth_metadata_get_raw (metadata);
	gth_comment_set_caption (comment, text);

	/* comment */

	text = NULL;
	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::description");
	if (metadata != NULL)
		text = gth_metadata_get_raw (metadata);
	gth_comment_set_note (comment, text);

	/* location */

	text = NULL;
	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::location");
	if (metadata != NULL)
		text = gth_metadata_get_raw (metadata);
	gth_comment_set_place (comment, text);

	/* time */

	text = NULL;
	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::datetime");
	if (metadata != NULL)
		text = gth_metadata_get_raw (metadata);
	gth_comment_set_time_from_exif_format (comment, text);

	/* keywords */

	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::tags");
	categories = gth_metadata_get_string_list (metadata);
	if (categories != NULL) {
		GList *list;
		GList *scan;

		list = gth_string_list_get_list (categories);
		for (scan = list; scan; scan = scan->next)
			gth_comment_add_category (comment, (char *) scan->data);
	}

	/* rating */

	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::rating");
	if (metadata != NULL) {
		int rating;

		sscanf (gth_metadata_get_raw (metadata), "%d", &rating);
		gth_comment_set_rating (comment, rating);
	}

	data = gth_comment_to_data (comment, &length);
	comment_file = gth_comment_get_comment_file (file_data->file);
	comment_folder = g_file_get_parent (comment_file);

	g_file_make_directory (comment_folder, NULL, NULL);
	_g_file_write (comment_file, FALSE, 0, data, length, cancellable, NULL);

	g_object_unref (comment_folder);
	g_object_unref (comment_file);
	g_free (data);
	g_object_unref (comment);
}
Esempio n. 12
0
static GthImage *
flickr_thumbnail_loader (GInputStream  *istream,
			 GthFileData   *file_data,
			 int            requested_size,
			 int           *original_width,
			 int           *original_height,
			 gboolean      *loaded_original,
			 gpointer       user_data,
			 GCancellable  *cancellable,
		         GError       **error)
{
	GthImage       *image = NULL;
	GthThumbLoader *thumb_loader = user_data;
	FlickrPhoto    *photo;
	const char     *uri = NULL;

	photo = (FlickrPhoto *) g_file_info_get_attribute_object (file_data->info, "flickr::object");
	requested_size = gth_thumb_loader_get_requested_size (thumb_loader);
	if (requested_size == FLICKR_SIZE_SMALL_SQUARE)
		uri = photo->url[FLICKR_URL_SQ];
	else if (requested_size == FLICKR_SIZE_THUMBNAIL)
		uri = photo->url[FLICKR_URL_T];
	else if (requested_size == FLICKR_SIZE_SMALL)
		uri = photo->url[FLICKR_URL_S];
	else if (requested_size == FLICKR_SIZE_MEDIUM)
		uri = photo->url[FLICKR_URL_M];

	if (uri == NULL)
		uri = photo->url[FLICKR_URL_O];

	if (uri != NULL) {
		GFile *file;
		void  *buffer;
		gsize  size;

		file = g_file_new_for_uri (uri);
		if (_g_file_load_in_buffer (file, &buffer, &size, cancellable, error)) {
			GInputStream *stream;
			GdkPixbuf    *pixbuf;

			stream = g_memory_input_stream_new_from_data (buffer, size, g_free);
			pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, error);
			if (pixbuf != NULL) {
				GdkPixbuf *rotated;

				rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf);
				g_object_unref (pixbuf);
				pixbuf = rotated;

				image = gth_image_new_for_pixbuf (pixbuf);
			}

			g_object_unref (pixbuf);
			g_object_unref (stream);
		}

		g_object_unref (file);
	}
	else
		*error = g_error_new_literal (GTH_ERROR, 0, "cannot generate the thumbnail");

	return image;
}
Esempio n. 13
0
static void
for_each_file_func (GFile     *file,
		    GFileInfo *info,
		    gpointer   user_data)
{
	GthOrganizeTask *self = user_data;
	GthFileData     *file_data;
	char            *key;
	GTimeVal         timeval;
	GthCatalog      *catalog;

	if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
		return;

	key = NULL;
	file_data = gth_file_data_new (file, info);
	switch (self->priv->group_policy) {
	case GTH_GROUP_POLICY_DIGITALIZED_DATE:
		{
			GObject *metadata;

			metadata = g_file_info_get_attribute_object (info, "Embedded::Photo::DateTimeOriginal");
			if (metadata != NULL) {
				if (_g_time_val_from_exif_date (gth_metadata_get_raw (GTH_METADATA (metadata)), &timeval))
					key = _g_time_val_strftime (&timeval, KEY_FORMAT);
			}
		}
		break;
	case GTH_GROUP_POLICY_MODIFIED_DATE:
		timeval = *gth_file_data_get_modification_time (file_data);
		key = _g_time_val_strftime (&timeval, KEY_FORMAT);
		break;
	}

	if (key == NULL)
		return;

	catalog = g_hash_table_lookup (self->priv->catalogs, key);
	if (catalog == NULL) {
		GthDateTime *date_time;
		GFile       *catalog_file;
		char        *name;
		GtkTreeIter  iter;

		date_time = gth_datetime_new ();
		gth_datetime_from_timeval (date_time, &timeval);

		catalog_file = gth_catalog_get_file_for_date (date_time);
		catalog = gth_catalog_load_from_file (catalog_file);
		if (catalog == NULL)
			catalog = gth_catalog_new ();
		gth_catalog_set_for_date (catalog, date_time);

		g_hash_table_insert (self->priv->catalogs, g_strdup (key), catalog);

		name = gth_datetime_strftime (date_time, "%x");
		gtk_list_store_append (self->priv->results_liststore, &iter);
		gtk_list_store_set (self->priv->results_liststore, &iter,
				    KEY_COLUMN, key,
				    NAME_COLUMN, name,
				    CARDINALITY_COLUMN, 0,
				    CREATE_CATALOG_COLUMN, TRUE,
				    ICON_COLUMN, self->priv->icon_pixbuf,
				    -1);
		self->priv->n_catalogs++;

		g_free (name);
		g_object_unref (catalog_file);
		gth_datetime_free (date_time);
	}

	if (catalog != NULL) {
		GtkTreeIter iter;
		int         n = 0;

		if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->results_liststore), &iter)) {
			do {
				char *k;

				gtk_tree_model_get (GTK_TREE_MODEL (self->priv->results_liststore),
						    &iter,
						    KEY_COLUMN, &k,
						    CARDINALITY_COLUMN, &n,
						    -1);
				if (g_strcmp0 (k, key) == 0) {
					gtk_list_store_set (self->priv->results_liststore, &iter,
							    CARDINALITY_COLUMN, n + 1,
							    -1);
					self->priv->n_files++;

					g_free (k);
					break;
				}

				g_free (k);
			}
			while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->results_liststore), &iter));
		}

		gth_catalog_insert_file (catalog, file_data->file, -1);
	}

	g_object_unref (file_data);
	g_free (key);
}
Esempio n. 14
0
static void
post_photo_file_buffer_ready_cb (void     **buffer,
				 gsize      count,
				 GError    *error,
				 gpointer   user_data)
{
	PicasaWebService   *self = user_data;
	OAuthAccount       *account;
	GthFileData        *file_data;
	SoupMultipart      *multipart;
	const char         *filename;
	char               *value;
	GObject            *metadata;
	DomDocument        *doc;
	DomElement         *entry;
	char               *entry_buffer;
	gsize               entry_len;
	SoupMessageHeaders *headers;
	SoupBuffer         *body;
	void               *resized_buffer;
	gsize               resized_count;
	char               *url;
	SoupMessage        *msg;

	if (error != NULL) {
		post_photos_done (self, error);
		return;
	}

	account = web_service_get_current_account (WEB_SERVICE (self));
	file_data = self->priv->post_photos->current->data;
	multipart = soup_multipart_new ("multipart/related");

	/* the metadata part */

	doc = dom_document_new ();
	entry = dom_document_create_element (doc, "entry",
					     "xmlns", "http://www.w3.org/2005/Atom",
					     "xmlns:gphoto", "http://schemas.google.com/photos/2007",
					     "xmlns:media", "http://search.yahoo.com/mrss/",
					     NULL);

	filename = g_file_info_get_display_name (file_data->info);
	dom_element_append_child (entry,
				  dom_document_create_element_with_text (doc, filename, "title", NULL));

	value = gth_file_data_get_attribute_as_string (file_data, "general::description");
	if (value == NULL)
		value = gth_file_data_get_attribute_as_string (file_data, "general::title");
	dom_element_append_child (entry,
				  dom_document_create_element_with_text (doc, value, "summary", NULL));

	value = gth_file_data_get_attribute_as_string (file_data, "general::location");
	if (value != NULL)
		dom_element_append_child (entry,
					  dom_document_create_element_with_text (doc, value, "gphoto:location", NULL));

	metadata = g_file_info_get_attribute_object (file_data->info, "general::tags");
	if (metadata != NULL)
		value = gth_string_list_join (GTH_STRING_LIST (gth_metadata_get_string_list (GTH_METADATA (metadata))), ", ");
	if (value != NULL) {
		DomElement *group;

		group = dom_document_create_element (doc, "media:group", NULL);
		dom_element_append_child (group,
					  dom_document_create_element_with_text (doc, value, "media:keywords", NULL));
		dom_element_append_child (entry, group);

		g_free (value);
	}

	dom_element_append_child (entry,
				  dom_document_create_element (doc, "category",
							       "scheme", "http://schemas.google.com/g/2005#kind",
							       "term", "http://schemas.google.com/photos/2007#photo",
							       NULL));
	dom_element_append_child (DOM_ELEMENT (doc), entry);
	entry_buffer = dom_document_dump (doc, &entry_len);

	headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_REQUEST);
	soup_message_headers_append (headers, "Content-Type", "application/atom+xml");
	body = soup_buffer_new (SOUP_MEMORY_TAKE, entry_buffer, entry_len);
	soup_multipart_append_part (multipart, headers, body);

	soup_buffer_free (body);
	soup_message_headers_free (headers);
	g_object_unref (doc);

	/* the file part */

	if (_g_buffer_resize_image (*buffer,
				    count,
				    file_data,
				    self->priv->post_photos->max_width,
				    self->priv->post_photos->max_height,
				    &resized_buffer,
				    &resized_count,
				    self->priv->post_photos->cancellable,
				    &error))
	{
		body = soup_buffer_new (SOUP_MEMORY_TAKE, resized_buffer, resized_count);
	}
	else if (error == NULL) {
		body = soup_buffer_new (SOUP_MEMORY_TEMPORARY, *buffer, count);
	}
	else {
		soup_multipart_free (multipart);
		post_photos_done (self, error);
		return;
	}

	soup_multipart_append_form_file (multipart,
					 "file",
					 NULL,
					 gth_file_data_get_mime_type (file_data),
					 body);

	soup_buffer_free (body);

	/* send the file */

	self->priv->post_photos->wrote_body_data_size = 0;
	url = g_strconcat ("https://picasaweb.google.com/data/feed/api/user/",
			   account->id,
			   "/albumid/",
			   self->priv->post_photos->album->id,
			   NULL);
	msg = soup_form_request_new_from_multipart (url, multipart);
	g_signal_connect (msg,
			  "wrote-body-data",
			  (GCallback) upload_photo_wrote_body_data_cb,
			  self);

	_picasa_web_service_add_headers (self, msg);
	_web_service_send_message (WEB_SERVICE (self),
				   msg,
				   self->priv->post_photos->cancellable,
				   self->priv->post_photos->callback,
				   self->priv->post_photos->user_data,
				   picasa_web_service_post_photos,
				   post_photo_ready_cb,
				   self);

	g_free (url);
	soup_multipart_free (multipart);
}
Esempio n. 15
0
char *
gvfs_file_info_marshal (GFileInfo *info,
			gsize     *size)
{
  GOutputStream *memstream;
  GDataOutputStream *out;
  GFileAttributeType type;
  GFileAttributeStatus status;
  GObject *obj;
  char **attrs, *attr;
  char *data;
  int i;

  memstream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);

  out = g_data_output_stream_new (memstream);
  g_object_unref (memstream);

  attrs = g_file_info_list_attributes (info, NULL);

  g_data_output_stream_put_uint32 (out,
				   g_strv_length (attrs),
				   NULL, NULL);

  for (i = 0; attrs[i] != NULL; i++)
    {
      attr = attrs[i];

      type = g_file_info_get_attribute_type  (info, attr);
      status = g_file_info_get_attribute_status  (info, attr);
      
      put_string (out, attr);
      g_data_output_stream_put_byte (out, type, 
				     NULL, NULL);
      g_data_output_stream_put_byte (out, status, 
				     NULL, NULL);

      switch (type)
	{
	case G_FILE_ATTRIBUTE_TYPE_STRING:
	  put_string (out, g_file_info_get_attribute_string (info, attr));
	  break;
	case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
	  put_string (out, g_file_info_get_attribute_byte_string (info, attr));
	  break;
	case G_FILE_ATTRIBUTE_TYPE_STRINGV:
	  put_stringv (out, g_file_info_get_attribute_stringv (info, attr));
	  break;
	case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
	  g_data_output_stream_put_byte (out,
					 g_file_info_get_attribute_boolean (info, attr),
					 NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_UINT32:
	  g_data_output_stream_put_uint32 (out,
					   g_file_info_get_attribute_uint32 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_INT32:
	  g_data_output_stream_put_int32 (out,
					  g_file_info_get_attribute_int32 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_UINT64:
	  g_data_output_stream_put_uint64 (out,
					   g_file_info_get_attribute_uint64 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_INT64:
	  g_data_output_stream_put_int64 (out,
					  g_file_info_get_attribute_int64 (info, attr),
					  NULL, NULL);
	  break;
	case G_FILE_ATTRIBUTE_TYPE_OBJECT:
          obj = g_file_info_get_attribute_object (info, attr);
	  if (obj == NULL)
	    {
	      g_data_output_stream_put_byte (out, 0,
					     NULL, NULL);
	    }
	  else if (G_IS_ICON (obj))
	    {
	      char *icon_str;

	      icon_str = g_icon_to_string (G_ICON (obj));
	      g_data_output_stream_put_byte (out, 1,
					     NULL, NULL);
	      put_string (out, icon_str);
	      g_free (icon_str);
	    }
	  else
	    {
	      g_warning ("Unsupported GFileInfo object type %s\n",
			 g_type_name_from_instance ((GTypeInstance *)obj));
	      g_data_output_stream_put_byte (out, 0,
					     NULL, NULL);
	    }
	  break;
	case G_FILE_ATTRIBUTE_TYPE_INVALID:
	default:
	  break;
	}
    }

  data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (memstream));
  *size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (memstream));
  g_object_unref (out);
  g_strfreev (attrs);
  return data;
}
Esempio n. 16
0
static GthImage *
picasa_web_thumbnail_loader (GInputStream  *istream,
			     GthFileData   *file_data,
			     int            requested_size,
			     int           *original_width,
			     int           *original_height,
			     gboolean      *loaded_original,
			     gpointer       user_data,
			     GCancellable  *cancellable,
			     GError       **error)
{
	GthImage       *image = NULL;
	GthThumbLoader *thumb_loader = user_data;
	PicasaWebPhoto *photo;
	const char     *uri;

	photo = (PicasaWebPhoto *) g_file_info_get_attribute_object (file_data->info, "gphoto::object");
	requested_size = gth_thumb_loader_get_requested_size (thumb_loader);
	if (requested_size == 72)
		uri = photo->thumbnail_72;
	else if (requested_size == 144)
		uri = photo->thumbnail_144;
	else if (requested_size == 288)
		uri = photo->thumbnail_288;
	else
		uri = NULL;

	if (uri == NULL)
		uri = photo->uri;

	if (uri != NULL) {
		GFile *file;
		void  *buffer;
		gsize  size;

		file = g_file_new_for_uri (uri);
		if (_g_file_load_in_buffer (file, &buffer, &size, cancellable, error)) {
			GInputStream *stream;
			GdkPixbuf    *pixbuf;

			stream = g_memory_input_stream_new_from_data (buffer, size, g_free);
			pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, error);
			if (pixbuf != NULL) {
				GdkPixbuf *rotated;

				rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf);
				g_object_unref (pixbuf);
				pixbuf = rotated;

				image = gth_image_new_for_pixbuf (pixbuf);
			}

			g_object_unref (pixbuf);
			g_object_unref (stream);
		}

		g_object_unref (file);
	}
	else
		*error = g_error_new_literal (GTH_ERROR, 0, "cannot generate the thumbnail");

	return image;
}