[gnome-photos/wip/rishi/collection: 34/35] device item
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 34/35] device item
- Date: Wed, 24 Jan 2018 14:03:21 +0000 (UTC)
commit 5d689a4ffd015922fad5c3d5b89e783793156abf
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jan 24 14:37:40 2018 +0100
device item
src/photos-device-item.c | 262 ++++++++---------------------------------------
1 file changed, 42 insertions(+), 220 deletions(-)
---
diff --git a/src/photos-device-item.c b/src/photos-device-item.c
index 49857cfd..9eafec36 100644
--- a/src/photos-device-item.c
+++ b/src/photos-device-item.c
@@ -157,39 +157,6 @@ photos_device_item_create_name_fallback (PhotosBaseItem *item)
}
-static gchar *
-photos_device_item_get_pipeline_path (PhotosDeviceItem *self)
-{
- const gchar *data_dir;
- const gchar *uri;
- g_autofree gchar *md5 = NULL;
- gchar *path;
-
- uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
- md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
- data_dir = g_get_user_data_dir ();
-
- path = g_build_filename (data_dir, PACKAGE_TARNAME, "local", md5, NULL);
-
- return path;
-}
-
-
-static gchar *
-photos_device_item_create_pipeline_path (PhotosBaseItem *item)
-{
- PhotosDeviceItem *self = PHOTOS_DEVICE_ITEM (item);
- gchar *path;
- g_autofree gchar *pipeline_dir = NULL;
-
- path = photos_device_item_get_pipeline_path (self);
- pipeline_dir = g_path_get_dirname (path);
- g_mkdir_with_parents (pipeline_dir, 0700);
-
- return path;
-}
-
-
static gboolean
photos_device_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
{
@@ -237,52 +204,41 @@ photos_device_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancell
static gchar *
photos_device_item_download (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
{
- const gchar *uri;
- gchar *path;
-
- uri = photos_base_item_get_uri (item);
- path = g_filename_from_uri (uri, NULL, error);
- return path;
+ g_assert_not_reached ();
+ return NULL;
}
static GtkWidget *
photos_device_item_get_source_widget (PhotosBaseItem *item)
{
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFile) source_link = NULL;
+ GtkWidget *label;
GtkWidget *source_widget;
+ const gchar *uri;
+ g_autofree gchar *source_path = NULL;
+ g_autofree gchar *source_uri = NULL;
- if (photos_base_item_is_collection (item))
- {
- source_widget = gtk_label_new (_("Local"));
- gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
- }
- else
- {
- g_autoptr (GFile) file = NULL;
- g_autoptr (GFile) source_link = NULL;
- GtkWidget *label;
- const gchar *uri;
- g_autofree gchar *source_path = NULL;
- g_autofree gchar *source_uri = NULL;
-
- uri = photos_base_item_get_uri (item);
- file = g_file_new_for_uri (uri);
- source_link = g_file_get_parent (file);
- source_path = g_file_get_path (source_link);
- source_uri = g_file_get_uri (source_link);
-
- source_widget = gtk_link_button_new_with_label (source_uri, source_path);
- gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
- g_signal_connect_object (source_widget,
- "activate-link",
- G_CALLBACK (photos_device_item_source_widget_activate_link),
- item,
- 0);
-
- label = gtk_bin_get_child (GTK_BIN (source_widget));
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
- }
+ g_return_val_if_fail (!photos_base_item_is_collection (item), NULL);
+
+ uri = photos_base_item_get_uri (item);
+ file = g_file_new_for_uri (uri);
+ source_link = g_file_get_parent (file);
+ source_path = g_file_get_path (source_link);
+ source_uri = g_file_get_uri (source_link);
+
+ source_widget = gtk_link_button_new_with_label (source_uri, source_path);
+ gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
+ g_signal_connect_object (source_widget,
+ "activate-link",
+ G_CALLBACK (photos_device_item_source_widget_activate_link),
+ item,
+ 0);
+
+ label = gtk_bin_get_child (GTK_BIN (source_widget));
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
return source_widget;
}
@@ -290,146 +246,21 @@ photos_device_item_get_source_widget (PhotosBaseItem *item)
static gboolean
photos_device_item_metadata_add_shared (PhotosBaseItem *item,
- const gchar *provider_type,
- const gchar *account_identity,
- const gchar *shared_id,
- GCancellable *cancellable,
- GError **error)
+ const gchar *provider_type,
+ const gchar *account_identity,
+ const gchar *shared_id,
+ GCancellable *cancellable,
+ GError **error)
{
- g_autoptr (GVariant) shared_variant = NULL;
- const GVariantType *tuple_items[] =
- {
- G_VARIANT_TYPE_STRING, /* provider-type */
- G_VARIANT_TYPE_STRING, /* account-identity */
- G_VARIANT_TYPE_STRING /* shared-id */
- };
- g_autoptr (GVariantType) array_type = NULL;
- g_autoptr (GVariantType) tuple_type = NULL;
- GExiv2Metadata *metadata = NULL; /* TODO: Use g_autoptr */
- gboolean ret_val = FALSE;
- const gchar *mime_type;
- const gchar *shared_tag = "Xmp.gnome.photos-shared";
- const gchar *version_tag = "Xmp.gnome.photos-xmp-version";
- g_autofree gchar *path = NULL;
- g_autofree gchar *tuple_type_format = NULL;
-
- mime_type = photos_base_item_get_mime_type (item);
- if (g_strcmp0 (mime_type, "image/png") != 0
- && g_strcmp0 (mime_type, "image/jp2") != 0
- && g_strcmp0 (mime_type, "image/jpeg") != 0)
- {
- ret_val = TRUE;
- goto out;
- }
-
- path = photos_base_item_download (item, cancellable, error);
- if (path == NULL)
- goto out;
-
- metadata = gexiv2_metadata_new ();
-
- if (!gexiv2_metadata_open_path (metadata, path, error))
- goto out;
-
- if (!gexiv2_metadata_set_tag_long (metadata, version_tag, 0))
- {
- g_set_error (error, PHOTOS_ERROR, 0, "Failed to update %s", version_tag);
- goto out;
- }
-
- tuple_type = g_variant_type_new_tuple (tuple_items, G_N_ELEMENTS (tuple_items));
- tuple_type_format = g_variant_type_dup_string (tuple_type);
-
- array_type = g_variant_type_new_array (tuple_type);
-
- {
- g_auto (GVariantBuilder) builder = G_VARIANT_BUILDER_INIT (array_type);
- g_autofree gchar *shared_string = NULL;
-
- g_variant_builder_add (&builder, tuple_type_format, provider_type, account_identity, shared_id);
-
- shared_string = gexiv2_metadata_get_tag_string (metadata, shared_tag);
- if (shared_string != NULL)
- {
- g_autoptr (GVariant) old_shared_variant = NULL;
- GVariant *child = NULL;
- GVariantIter iter;
-
- old_shared_variant = g_variant_parse (array_type, shared_string, NULL, NULL, error);
- if (old_shared_variant == NULL)
- goto out;
-
- g_variant_iter_init (&iter, old_shared_variant);
- child = g_variant_iter_next_value (&iter);
- while (child != NULL)
- {
- g_variant_builder_add_value (&builder, child);
- g_variant_unref (child);
- child = g_variant_iter_next_value (&iter);
- }
- }
-
- shared_variant = g_variant_builder_end (&builder);
- }
-
- {
- g_autofree gchar *shared_string = NULL;
-
- shared_string = g_variant_print (shared_variant, TRUE);
- if (!gexiv2_metadata_set_tag_string (metadata, shared_tag, shared_string))
- {
- g_set_error (error, PHOTOS_ERROR, 0, "Failed to update %s", shared_tag);
- goto out;
- }
- }
-
- if (!gexiv2_metadata_save_file (metadata, path, error))
- goto out;
-
- ret_val = TRUE;
-
- out:
- g_clear_object (&metadata);
- return ret_val;
-}
-
-
-static void
-photos_device_item_trash_finish (GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
- GFile *file = G_FILE (source_object);
-
- {
- g_autoptr (GError) error = NULL;
-
- if (!g_file_trash_finish (file, res, &error))
- {
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- {
- PhotosDeviceItem *self = PHOTOS_DEVICE_ITEM (user_data);
- const gchar *uri;
-
- uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
- g_warning ("Unable to trash %s: %s", uri, error->message);
- }
- }
- }
+ g_assert_not_reached ();
+ return FALSE;
}
static void
photos_device_item_trash (PhotosBaseItem *item)
{
- g_autoptr (GFile) file = NULL;
- const gchar *uri;
- PhotosDeviceItem *self = PHOTOS_DEVICE_ITEM (item);
-
- if (photos_base_item_is_collection (item))
- return;
-
- uri = photos_base_item_get_uri (item);
- file = g_file_new_for_uri (uri);
- g_file_trash_async (file, G_PRIORITY_DEFAULT, self->cancellable, photos_device_item_trash_finish, self);
+ g_assert_not_reached ();
}
@@ -437,20 +268,19 @@ static void
photos_device_item_constructed (GObject *object)
{
PhotosDeviceItem *self = PHOTOS_DEVICE_ITEM (object);
- g_autoptr (GAppInfo) default_app = NULL;
const gchar *mime_type;
G_OBJECT_CLASS (photos_device_item_parent_class)->constructed (object);
mime_type = photos_base_item_get_mime_type (PHOTOS_BASE_ITEM (self));
- if (mime_type == NULL)
- return;
-
- default_app = g_app_info_get_default_for_type (mime_type, FALSE);
- if (default_app == NULL)
- return;
+ if (mime_type != NULL)
+ {
+ g_autoptr (GAppInfo) default_app = NULL;
- photos_base_item_set_default_app (PHOTOS_BASE_ITEM (self), default_app);
+ default_app = g_app_info_get_default_for_type (mime_type, FALSE);
+ if (default_app != NULL)
+ photos_base_item_set_default_app (PHOTOS_BASE_ITEM (self), default_app);
+ }
}
@@ -459,12 +289,6 @@ photos_device_item_dispose (GObject *object)
{
PhotosDeviceItem *self = PHOTOS_DEVICE_ITEM (object);
- if (self->cancellable != NULL)
- {
- g_cancellable_cancel (self->cancellable);
- g_clear_object (&self->cancellable);
- }
-
G_OBJECT_CLASS (photos_device_item_parent_class)->dispose (object);
}
@@ -472,7 +296,6 @@ photos_device_item_dispose (GObject *object)
static void
photos_device_item_init (PhotosDeviceItem *self)
{
- self->cancellable = g_cancellable_new ();
}
@@ -486,7 +309,6 @@ photos_device_item_class_init (PhotosDeviceItemClass *class)
object_class->dispose = photos_device_item_dispose;
base_item_class->create_filename_fallback = photos_device_item_create_filename_fallback;
base_item_class->create_name_fallback = photos_device_item_create_name_fallback;
- base_item_class->create_pipeline_path = photos_device_item_create_pipeline_path;
base_item_class->create_thumbnail = photos_device_item_create_thumbnail;
base_item_class->download = photos_device_item_download;
base_item_class->get_source_widget = photos_device_item_get_source_widget;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]