diff options
author | Carlos Soriano <csoriano@gnome.org> | 2017-10-30 21:38:41 +0100 |
---|---|---|
committer | Carlos Soriano <csoriano@gnome.org> | 2017-11-13 16:55:10 +0100 |
commit | f54e7712c53f914dc1bd04b7ebaaef30dc2ce86c (patch) | |
tree | 77c9e24900fb06b2f3e6460e3bfe6b80b8ba5153 /gtk/gtksidebarrow.c | |
parent | 2ff175938d9541b991a2aa9ee7abda441a32e1c7 (diff) | |
download | gtk+-f54e7712c53f914dc1bd04b7ebaaef30dc2ce86c.tar.gz |
gtkplacessidebar: Adapt to libcloudproviders 0.2.x
And a few improvements on the way.
https://bugzilla.gnome.org/show_bug.cgi?id=786123
Diffstat (limited to 'gtk/gtksidebarrow.c')
-rw-r--r-- | gtk/gtksidebarrow.c | 90 |
1 files changed, 76 insertions, 14 deletions
diff --git a/gtk/gtksidebarrow.c b/gtk/gtksidebarrow.c index 65a69f5048..26bce9b3b6 100644 --- a/gtk/gtksidebarrow.c +++ b/gtk/gtksidebarrow.c @@ -30,7 +30,7 @@ #include "gtkselection.h" #ifdef HAVE_CLOUDPROVIDERS -#include <cloudproviders/cloudprovideraccount.h> +#include <cloudproviders/cloudprovidersaccount.h> #endif struct _GtkSidebarRow @@ -52,7 +52,7 @@ struct _GtkSidebarRow GDrive *drive; GVolume *volume; GMount *mount; - GObject *cloud_provider; + GObject *cloud_provider_account; gboolean placeholder; GtkPlacesSidebar *sidebar; GtkWidget *revealer; @@ -76,13 +76,58 @@ enum PROP_DRIVE, PROP_VOLUME, PROP_MOUNT, - PROP_CLOUD_PROVIDER, + PROP_CLOUD_PROVIDER_ACCOUNT, PROP_PLACEHOLDER, LAST_PROP }; static GParamSpec *properties [LAST_PROP]; +#ifdef HAVE_CLOUDPROVIDERS + +static void +cloud_row_update (GtkSidebarRow *self) +{ + CloudProvidersAccount *account; + GIcon *end_icon; + gint provider_status; + + account = CLOUD_PROVIDERS_ACCOUNT (self->cloud_provider_account); + provider_status = cloud_providers_account_get_status (account); + switch (provider_status) + { + case CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE: + end_icon = NULL; + break; + + case CLOUD_PROVIDERS_ACCOUNT_STATUS_SYNCING: + end_icon = g_themed_icon_new ("emblem-synchronizing-symbolic"); + break; + + case CLOUD_PROVIDERS_ACCOUNT_STATUS_ERROR: + end_icon = g_themed_icon_new ("dialog-warning-symbolic"); + break; + + default: + return; + } + + g_object_set (self, + "label", cloud_providers_account_get_name (account), + NULL); + g_object_set (self, + "tooltip", cloud_providers_account_get_status_details (account), + NULL); + g_object_set (self, + "end-icon", end_icon, + NULL); + + if (end_icon != NULL) + g_object_unref (end_icon); +} + +#endif + static void gtk_sidebar_row_get_property (GObject *object, guint prop_id, @@ -145,8 +190,8 @@ gtk_sidebar_row_get_property (GObject *object, g_value_set_object (value, self->mount); break; - case PROP_CLOUD_PROVIDER: - g_value_set_object (value, self->cloud_provider); + case PROP_CLOUD_PROVIDER_ACCOUNT: + g_value_set_object (value, self->cloud_provider_account); break; case PROP_PLACEHOLDER: @@ -265,9 +310,22 @@ gtk_sidebar_row_set_property (GObject *object, g_set_object (&self->mount, g_value_get_object (value)); break; - case PROP_CLOUD_PROVIDER: + case PROP_CLOUD_PROVIDER_ACCOUNT: #ifdef HAVE_CLOUDPROVIDERS - g_set_object (&self->cloud_provider, g_value_get_object (value)); + if (self->cloud_provider_account != NULL) + g_signal_handlers_disconnect_by_data (self->cloud_provider_account, self); + + self->cloud_provider_account = g_value_dup_object (value); + + if (self->cloud_provider_account != NULL) + { + g_signal_connect_swapped (self->cloud_provider_account, "notify::name", + G_CALLBACK (cloud_row_update), self); + g_signal_connect_swapped (self->cloud_provider_account, "notify::status", + G_CALLBACK (cloud_row_update), self); + g_signal_connect_swapped (self->cloud_provider_account, "notify::status-details", + G_CALLBACK (cloud_row_update), self); + } #endif break; @@ -291,7 +349,7 @@ gtk_sidebar_row_set_property (GObject *object, g_clear_object (&self->drive); g_clear_object (&self->volume); g_clear_object (&self->mount); - g_clear_object (&self->cloud_provider); + g_clear_object (&self->cloud_provider_account); gtk_container_foreach (GTK_CONTAINER (self), (GtkCallback) gtk_widget_destroy, @@ -398,7 +456,11 @@ gtk_sidebar_row_finalize (GObject *object) g_clear_object (&self->drive); g_clear_object (&self->volume); g_clear_object (&self->mount); - g_clear_object (&self->cloud_provider); +#ifdef HAVE_CLOUDPROVIDERS + if (self->cloud_provider_account != NULL) + g_signal_handlers_disconnect_by_data (self->cloud_provider_account, self); + g_clear_object (&self->cloud_provider_account); +#endif G_OBJECT_CLASS (gtk_sidebar_row_parent_class)->finalize (object); } @@ -530,10 +592,10 @@ gtk_sidebar_row_class_init (GtkSidebarRowClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - properties [PROP_CLOUD_PROVIDER] = - g_param_spec_object ("cloud-provider", - "CloudProviderAccount", - "CloudProviderAccount", + properties [PROP_CLOUD_PROVIDER_ACCOUNT] = + g_param_spec_object ("cloud-provider-account", + "CloudProvidersAccount", + "CloudProvidersAccount", G_TYPE_OBJECT, (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); @@ -579,7 +641,7 @@ gtk_sidebar_row_clone (GtkSidebarRow *self) "drive", self->drive, "volume", self->volume, "mount", self->mount, - "cloud-provider", self->cloud_provider, + "cloud-provider-account", self->cloud_provider_account, NULL); } |