gtkplacessidebar: Adapt to libcloudproviders 0.2.0

And a few improvements on the way.

https://bugzilla.gnome.org/show_bug.cgi?id=786123
parent b654130b
......@@ -64,7 +64,7 @@ m4_define([wayland_protocols_required_version], [1.9])
m4_define([mirclient_required_version], [0.22.0])
m4_define([mircookie_required_version], [0.17.0])
m4_define([epoxy_required_version], [1.0])
m4_define([cloudproviders_required_version], [0.2.0])
m4_define([cloudproviders_required_version], [0.2.5])
GLIB_REQUIRED_VERSION=glib_required_version
PANGO_REQUIRED_VERSION=pango_required_version
ATK_REQUIRED_VERSION=atk_required_version
......
......@@ -25,8 +25,9 @@
#include <gio/gio.h>
#ifdef HAVE_CLOUDPROVIDERS
#include <cloudproviders/cloudproviders.h>
#include <cloudproviders/cloudprovideraccount.h>
#include <cloudproviders/cloudproviderscollector.h>
#include <cloudproviders/cloudprovidersaccount.h>
#include <cloudproviders/cloudprovidersprovider.h>
#endif
#include "gtkplacessidebarprivate.h"
......@@ -127,8 +128,8 @@ struct _GtkPlacesSidebar {
GtkBookmarksManager *bookmarks_manager;
#ifdef HAVE_CLOUDPROVIDERS
CloudProviders *cloud_manager;
GList *cloud_rows;
CloudProvidersCollector *cloud_manager;
GList *unready_accounts;
#endif
GVolumeMonitor *volume_monitor;
......@@ -477,7 +478,7 @@ add_place (GtkPlacesSidebar *sidebar,
GVolume *volume,
GMount *mount,
#ifdef HAVE_CLOUDPROVIDERS
CloudProviderAccount *cloud_provider_account,
CloudProvidersAccount *cloud_provider_account,
#else
gpointer *cloud_provider_account,
#endif
......@@ -513,7 +514,7 @@ add_place (GtkPlacesSidebar *sidebar,
"volume", volume,
"mount", mount,
#ifdef HAVE_CLOUDPROVIDERS
"cloud-provider", cloud_provider_account,
"cloud-provider-account", cloud_provider_account,
#endif
NULL);
......@@ -935,61 +936,80 @@ update_trash_icon (GtkPlacesSidebar *sidebar)
}
#ifdef HAVE_CLOUDPROVIDERS
static void
cloud_row_update (CloudProviderAccount *cloud_provider_account,
GtkWidget *cloud_row)
static gboolean
create_cloud_provider_account_row (GtkPlacesSidebar *sidebar,
CloudProvidersAccount *account)
{
GIcon *end_icon;
gint provider_status;
provider_status = cloud_provider_account_get_status (cloud_provider_account);
switch (provider_status)
GIcon *start_icon;
gchar *mount_uri;
gchar *name;
gchar *tooltip;
guint provider_account_status;
start_icon = cloud_providers_account_get_icon (account);
name = cloud_providers_account_get_name (account);
provider_account_status = cloud_providers_account_get_status (account);
mount_uri = cloud_providers_account_get_path (account);
if (start_icon != NULL
&& name != NULL
&& provider_account_status != CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID
&& mount_uri != NULL)
{
case CLOUD_PROVIDER_STATUS_IDLE:
end_icon = NULL;
break;
switch (provider_account_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_PROVIDER_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;
case CLOUD_PROVIDER_STATUS_ERROR:
end_icon = g_themed_icon_new ("dialog-warning-symbolic");
break;
default:
return FALSE;
}
default:
return;
}
mount_uri = g_strconcat ("file://", mount_uri, NULL);
gtk_sidebar_row_set_end_icon (GTK_SIDEBAR_ROW (cloud_row), end_icon);
if (end_icon != NULL)
g_object_unref (end_icon);
/* translators: %s is the name of a cloud provider for files */
tooltip = g_strdup_printf (_("Open %s"), name);
g_object_set (cloud_row,
"label", cloud_provider_account_get_name (cloud_provider_account),
NULL);
g_object_set (cloud_row,
"tooltip", cloud_provider_account_get_status_details (cloud_provider_account),
NULL);
add_place (sidebar, PLACES_BUILT_IN,
SECTION_CLOUD,
name, start_icon, end_icon, mount_uri,
NULL, NULL, NULL, account, 0,
tooltip);
return TRUE;
}
else
{
return FALSE;
}
}
void
cloud_row_destroy (GtkWidget *object,
gpointer user_data)
static void
on_account_updated (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
CloudProviderAccount *cloud_provider_account = NULL;
g_object_get (GTK_SIDEBAR_ROW (object), "cloud-provider", &cloud_provider_account, NULL);
if (cloud_provider_account != NULL)
{
g_signal_handlers_disconnect_matched (cloud_provider_account,
G_SIGNAL_MATCH_DATA,
0, 0, 0, cloud_row_update, object);
g_object_unref (object);
g_object_unref (cloud_provider_account);
}
sidebar->cloud_rows = g_list_remove (sidebar->cloud_rows, object);
CloudProvidersAccount *account = CLOUD_PROVIDERS_ACCOUNT (object);
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
if (create_cloud_provider_account_row (sidebar, account))
{
g_signal_handlers_disconnect_by_data (account, sidebar);
sidebar->unready_accounts = g_list_remove (sidebar->unready_accounts, account);
g_object_unref (account);
}
}
#endif
static void
......@@ -1012,9 +1032,10 @@ update_places (GtkPlacesSidebar *sidebar)
GList *network_mounts, *network_volumes;
GIcon *new_bookmark_icon;
#ifdef HAVE_CLOUDPROVIDERS
GIcon *end_icon;
GList *cloud_provider_proxies;
guint provider_status;
GList *cloud_providers;
GList *cloud_providers_accounts;
CloudProvidersAccount *cloud_provider_account;
CloudProvidersProvider *cloud_provider;
#endif
GtkStyleContext *context;
......@@ -1125,52 +1146,39 @@ update_places (GtkPlacesSidebar *sidebar)
/* Cloud providers */
#ifdef HAVE_CLOUDPROVIDERS
cloud_provider_proxies = cloud_providers_get_providers (sidebar->cloud_manager);
for (l = cloud_provider_proxies; l != NULL; l = l->next)
{
start_icon = cloud_provider_account_get_icon (l->data);
name = cloud_provider_account_get_name (l->data);
provider_status = cloud_provider_account_get_status (l->data);
mount_uri = cloud_provider_account_get_path (l->data);
if (start_icon == NULL
|| name == NULL
|| provider_status == CLOUD_PROVIDER_STATUS_INVALID
|| mount_uri == NULL)
continue;
mount_uri = g_strconcat ("file://", cloud_provider_account_get_path (l->data), NULL);
switch (provider_status)
cloud_providers = cloud_providers_collector_get_providers (sidebar->cloud_manager);
for (l = sidebar->unready_accounts; l != NULL; l = l->next)
{
g_signal_handlers_disconnect_by_data (l->data, sidebar);
}
g_list_free_full (sidebar->unready_accounts, g_object_unref);
sidebar->unready_accounts = NULL;
for (l = cloud_providers; l != NULL; l = l->next)
{
cloud_provider = CLOUD_PROVIDERS_PROVIDER (l->data);
g_signal_connect_swapped (cloud_provider, "accounts-changed",
G_CALLBACK (update_places), sidebar);
cloud_providers_accounts = cloud_providers_provider_get_accounts (cloud_provider);
for (ll = cloud_providers_accounts; ll != NULL; ll = ll->next)
{
case CLOUD_PROVIDER_STATUS_IDLE:
end_icon = NULL;
break;
case CLOUD_PROVIDER_STATUS_SYNCING:
end_icon = g_themed_icon_new ("emblem-synchronizing-symbolic");
break;
cloud_provider_account = CLOUD_PROVIDERS_ACCOUNT (ll->data);
if (!create_cloud_provider_account_row (sidebar, cloud_provider_account))
{
case CLOUD_PROVIDER_STATUS_ERROR:
end_icon = g_themed_icon_new ("dialog-warning-symbolic");
break;
g_signal_connect (cloud_provider_account, "notify::name",
G_CALLBACK (on_account_updated), sidebar);
g_signal_connect (cloud_provider_account, "notify::status",
G_CALLBACK (on_account_updated), sidebar);
g_signal_connect (cloud_provider_account, "notify::status-details",
G_CALLBACK (on_account_updated), sidebar);
g_signal_connect (cloud_provider_account, "notify::path",
G_CALLBACK (on_account_updated), sidebar);
sidebar->unready_accounts = g_list_append (sidebar->unready_accounts,
g_object_ref (cloud_provider_account));
continue;
}
default:
continue;
}
/* translators: %s is the name of a cloud provider for files */
tooltip = g_strdup_printf (_("Open %s"), name);
GtkWidget *cloud_row = NULL;
cloud_row = add_place (sidebar, PLACES_BUILT_IN,
SECTION_CLOUD,
name, start_icon, end_icon, mount_uri,
NULL, NULL, NULL, l->data, 0,
tooltip);
g_signal_connect (l->data, "changed", G_CALLBACK (cloud_row_update), cloud_row);
g_signal_connect (cloud_row, "destroy", G_CALLBACK (cloud_row_destroy), sidebar);
g_object_ref (cloud_row);
g_object_ref (l->data);
sidebar->cloud_rows = g_list_append (sidebar->cloud_rows, cloud_row);
}
#endif
......@@ -3567,17 +3575,17 @@ on_row_popover_destroy (GtkWidget *row_popover,
static void
build_popup_menu_using_gmenu (GtkSidebarRow *row)
{
CloudProviderAccount *cloud_provider_account;
CloudProvidersAccount *cloud_provider_account;
GtkPlacesSidebar *sidebar;
GMenuModel *cloud_provider_menu;
GActionGroup *cloud_provider_action_group;
g_object_get (row,
"sidebar", &sidebar,
"cloud-provider", &cloud_provider_account,
"cloud-provider-account", &cloud_provider_account,
NULL);
/* Cloud provider */
/* Cloud provider account */
if (cloud_provider_account)
{
GMenu *menu = g_menu_new ();
......@@ -3591,19 +3599,23 @@ build_popup_menu_using_gmenu (GtkSidebarRow *row)
item = g_menu_item_new (_("Open in New _Window"), "row.open-other");
g_menu_item_set_action_and_target_value (item, "row.open-other", g_variant_new_int32(GTK_PLACES_OPEN_NEW_WINDOW));
g_menu_append_item (menu, item);
cloud_provider_menu = cloud_provider_account_get_menu_model (cloud_provider_account);
g_menu_append_section (menu, NULL, cloud_provider_menu);
cloud_provider_action_group = cloud_provider_account_get_action_group (cloud_provider_account);
gtk_widget_insert_action_group (GTK_WIDGET (sidebar),
"cloudprovider",
G_ACTION_GROUP (cloud_provider_action_group));
cloud_provider_menu = cloud_providers_account_get_menu_model (cloud_provider_account);
cloud_provider_action_group = cloud_providers_account_get_action_group (cloud_provider_account);
if (cloud_provider_menu != NULL && cloud_provider_action_group != NULL)
{
g_menu_append_section (menu, NULL, cloud_provider_menu);
gtk_widget_insert_action_group (GTK_WIDGET (sidebar),
"cloudprovider",
G_ACTION_GROUP (cloud_provider_action_group));
}
add_actions (sidebar);
if (sidebar->popover)
gtk_widget_destroy (sidebar->popover);
sidebar->popover = gtk_popover_new_from_model (GTK_WIDGET (sidebar),
G_MENU_MODEL (menu));
g_signal_connect (sidebar->popover, "destroy", G_CALLBACK (on_row_popover_destroy), sidebar);
g_signal_connect (sidebar->popover, "destroy",
G_CALLBACK (on_row_popover_destroy), sidebar);
g_object_unref (sidebar);
g_object_unref (cloud_provider_account);
}
......@@ -3619,14 +3631,15 @@ create_row_popover (GtkPlacesSidebar *sidebar,
GtkWidget *box;
#ifdef HAVE_CLOUDPROVIDERS
CloudProviderAccount *cloud_provider_account;
CloudProvidersAccount *cloud_provider_account;
g_object_get (row, "cloud-provider", &cloud_provider_account, NULL);
g_object_get (row, "cloud-provider-account", &cloud_provider_account, NULL);
if (cloud_provider_account) {
build_popup_menu_using_gmenu (row);
return;
}
if (cloud_provider_account)
{
build_popup_menu_using_gmenu (row);
return;
}
#endif
sidebar->popover = gtk_popover_new (GTK_WIDGET (sidebar));
......@@ -4127,13 +4140,11 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
/* Cloud providers */
#ifdef HAVE_CLOUDPROVIDERS
sidebar->cloud_rows = NULL;
sidebar->cloud_manager = cloud_providers_dup_singleton ();
sidebar->cloud_manager = cloud_providers_collector_dup_singleton ();
g_signal_connect_swapped (sidebar->cloud_manager,
"owners-changed",
"providers-changed",
G_CALLBACK (update_places),
sidebar);
cloud_providers_update (sidebar->cloud_manager);
#endif
/* populate the sidebar */
......@@ -4274,6 +4285,9 @@ static void
gtk_places_sidebar_dispose (GObject *object)
{
GtkPlacesSidebar *sidebar;
#ifdef HAVE_CLOUDPROVIDERS
GList *l;
#endif
sidebar = GTK_PLACES_SIDEBAR (object);
......@@ -4359,12 +4373,35 @@ gtk_places_sidebar_dispose (GObject *object)
sidebar->shortcuts = NULL;
#ifdef HAVE_CLOUDPROVIDERS
g_clear_object (&sidebar->cloud_manager);
for (l = cloud_providers_collector_get_providers (sidebar->cloud_manager);
l != NULL; l = l->next)
{
g_signal_handlers_disconnect_by_data (l->data, sidebar);
}
for (l = sidebar->unready_accounts; l != NULL; l = l->next)
{
g_signal_handlers_disconnect_by_data (l->data, sidebar);
}
g_list_free_full (sidebar->unready_accounts, g_object_unref);
sidebar->unready_accounts = NULL;
#endif
G_OBJECT_CLASS (gtk_places_sidebar_parent_class)->dispose (object);
}
static void
gtk_places_sidebar_finalize (GObject *object)
{
GtkPlacesSidebar *sidebar;
sidebar = GTK_PLACES_SIDEBAR (object);
#ifdef HAVE_CLOUDPROVIDERS
g_clear_object (&sidebar->cloud_manager);
#endif
G_OBJECT_CLASS (gtk_places_sidebar_parent_class)->finalize (object);
}
static void
gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
{
......@@ -4373,6 +4410,7 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
gobject_class->dispose = gtk_places_sidebar_dispose;
gobject_class->finalize = gtk_places_sidebar_finalize;
gobject_class->set_property = gtk_places_sidebar_set_property;
gobject_class->get_property = gtk_places_sidebar_get_property;
......
......@@ -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 *event_box;
......@@ -77,13 +77,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,
......@@ -146,8 +191,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:
......@@ -266,9 +311,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;
......@@ -292,7 +350,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,
......@@ -399,7 +457,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);
}
......@@ -531,10 +593,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));
......@@ -581,7 +643,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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment