[libcloudproviders/wip/rename-exporter: 2/2] WIP: cloudproviderexporter: Add menus/actions to the corresponding account



commit 4eabec02746d58e60e02fc6a77b95a19cddbd54e
Author: Julius Härtl <jus bitgrid net>
Date:   Fri Sep 1 20:47:06 2017 +0200

    WIP: cloudproviderexporter: Add menus/actions to the corresponding account

 src/cloudprovideraccountexporter.c     | 46 ++++++++++++++++++++++++++++++++++
 src/cloudprovideraccountexporter.h     | 12 +++++++++
 src/cloudprovideraccountexporterpriv.h |  6 +++++
 src/cloudproviderexporter.c            | 20 ++++++++++++++-
 test/testcloudproviderserver.c         | 20 +++++++--------
 5 files changed, 93 insertions(+), 11 deletions(-)
---
diff --git a/src/cloudprovideraccountexporter.c b/src/cloudprovideraccountexporter.c
index 97bd6dd..81570ed 100644
--- a/src/cloudprovideraccountexporter.c
+++ b/src/cloudprovideraccountexporter.c
@@ -24,6 +24,8 @@ typedef struct
 {
   gchar *object_name;
   CloudProviderAccount1 *skeleton;
+  GMenuModel *menu_model;
+  GActionGroup *action_group;
 } CloudProviderAccountExporterPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderAccountExporter, cloud_provider_account_exporter, G_TYPE_OBJECT)
@@ -35,6 +37,20 @@ cloud_provider_account_exporter_get_object_name (CloudProviderAccountExporter *s
   return priv->object_name;
 }
 
+GMenuModel *
+cloud_provider_account_exporter_get_menu_model (CloudProviderAccountExporter *self)
+{
+  CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self);
+  return priv->menu_model;
+}
+
+GActionGroup *
+cloud_provider_account_exporter_get_action_group (CloudProviderAccountExporter *self)
+{
+  CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self);
+  return priv->action_group;
+}
+
 GDBusInterfaceSkeleton*
 cloud_provider_account_exporter_get_skeleton (CloudProviderAccountExporter *self)
 {
@@ -120,6 +136,36 @@ cloud_provider_account_exporter_new (const gchar *object_name)
   return self;
 }
 
+void
+cloud_provider_account_exporter_add_menu_model (CloudProviderAccountExporter *self,
+                                                GMenuModel                   *menu_model)
+{
+  CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self);
+  priv->menu_model = menu_model;
+}
+
+void
+cloud_provider_account_exporter_remove_menu (CloudProviderAccountExporter *self)
+{
+  CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self);
+  priv->menu_model = NULL;
+}
+
+void
+cloud_provider_account_exporter_add_action_group (CloudProviderAccountExporter *self,
+                                                  GActionGroup                 *action_group)
+{
+  CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self);
+  priv->action_group = action_group;
+}
+
+void
+cloud_provider_account_exporter_remove_action_group (CloudProviderAccountExporter *self)
+{
+  CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self);
+  priv->action_group = NULL;
+}
+
 static void
 cloud_provider_account_exporter_finalize (GObject *object)
 {
diff --git a/src/cloudprovideraccountexporter.h b/src/cloudprovideraccountexporter.h
index 0879de9..37cbde0 100644
--- a/src/cloudprovideraccountexporter.h
+++ b/src/cloudprovideraccountexporter.h
@@ -51,6 +51,18 @@ cloud_provider_account_exporter_emit_changed (CloudProviderAccountExporter *clou
 CloudProviderAccountExporter*
 cloud_provider_account_exporter_new (const gchar *account_object_name);
 
+void
+cloud_provider_account_exporter_add_menu_model (CloudProviderAccountExporter *self,
+                                                GMenuModel                   *menu_model);
+void
+cloud_provider_account_exporter_remove_menu (CloudProviderAccountExporter *self);
+
+void
+cloud_provider_account_exporter_add_action_group (CloudProviderAccountExporter *self,
+                                                  GActionGroup                 *action_group);
+void
+cloud_provider_account_exporter_remove_action_group (CloudProviderAccountExporter *self);
+
 G_END_DECLS
 
 #endif /* CLOUD_PROVIDER_ACCOUNT_EXPORTER_H */
diff --git a/src/cloudprovideraccountexporterpriv.h b/src/cloudprovideraccountexporterpriv.h
index 01f256b..1bb0968 100644
--- a/src/cloudprovideraccountexporterpriv.h
+++ b/src/cloudprovideraccountexporterpriv.h
@@ -29,4 +29,10 @@ cloud_provider_account_exporter_get_skeleton (CloudProviderAccountExporter *self
 gchar *
 cloud_provider_account_exporter_get_object_name (CloudProviderAccountExporter *self);
 
+GMenuModel *
+cloud_provider_account_exporter_get_menu_model (CloudProviderAccountExporter *self);
+
+GActionGroup *
+cloud_provider_account_exporter_get_action_group (CloudProviderAccountExporter *self);
+
 #endif
diff --git a/src/cloudproviderexporter.c b/src/cloudproviderexporter.c
index 3a04107..a5898b6 100644
--- a/src/cloudproviderexporter.c
+++ b/src/cloudproviderexporter.c
@@ -63,10 +63,28 @@ cloud_provider_exporter_add_account (CloudProviderExporter        *cloud_provide
 {
   CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(cloud_provider);
   CloudProviderObjectSkeleton *object;
-  gchar *object_path = g_strconcat (priv->object_path, "/", cloud_provider_account_exporter_get_object_name 
(account), NULL);
+  gchar *object_name = cloud_provider_account_exporter_get_object_name (account);
+  gchar *object_path = g_strconcat (priv->object_path, "/", object_name, NULL);
   object = cloud_provider_object_skeleton_new(object_path);
   cloud_provider_object_skeleton_set_account1(object, CLOUD_PROVIDER_ACCOUNT1 
(cloud_provider_account_exporter_get_skeleton (account)));
   g_dbus_object_manager_server_export (priv->manager, G_DBUS_OBJECT_SKELETON(object));
+
+  /* export menus/actiongroups that are coupled with the account */
+  GMenuModel *menu = cloud_provider_account_exporter_get_menu_model (account);
+  GActionGroup *action_group = cloud_provider_account_exporter_get_action_group (account);
+  if (menu != NULL)
+  {
+    cloud_provider_exporter_export_menu (cloud_provider,
+                                         object_name,
+                                         menu);
+  }
+  if (action_group != NULL)
+  {
+    cloud_provider_exporter_export_action_group (cloud_provider,
+                                                 object_name,
+                                                 action_group);
+  }
+
   g_free(object_path);
 }
 
diff --git a/test/testcloudproviderserver.c b/test/testcloudproviderserver.c
index 19d0853..0481365 100644
--- a/test/testcloudproviderserver.c
+++ b/test/testcloudproviderserver.c
@@ -310,16 +310,16 @@ on_bus_acquired (GDBusConnection *connection,
       gchar *account_object_name = g_strdup_printf ("MyCloud%d", n);
       gchar *account_name = g_strdup_printf ("MyCloud %d", n);
 
-      CloudProviderAccountExporter *cloud_provider_account_exporter = 
cloud_provider_account_exporter_new(account_object_name);
-      g_signal_connect(cloud_provider_account_exporter, "handle_get_name", G_CALLBACK (on_get_name), 
account_name);
-      g_signal_connect(cloud_provider_account_exporter, "handle_get_icon", G_CALLBACK (on_get_icon), self);
-      g_signal_connect(cloud_provider_account_exporter, "handle_get_path", G_CALLBACK (on_get_path), self);
-      g_signal_connect(cloud_provider_account_exporter, "handle_get_status", G_CALLBACK (on_get_status), 
self);
-      g_signal_connect(cloud_provider_account_exporter, "handle_get_status_details", G_CALLBACK 
(on_get_status_details), self);
-
-      cloud_provider_exporter_add_account(self->cloud_provider, cloud_provider_account_exporter);
-      cloud_provider_exporter_export_menu (self->cloud_provider, account_object_name, get_model ());
-      cloud_provider_exporter_export_action_group (self->cloud_provider, account_object_name, 
get_action_group ());
+      CloudProviderAccountExporter *account = cloud_provider_account_exporter_new(account_object_name);
+      g_signal_connect (account, "handle_get_name", G_CALLBACK (on_get_name), account_name);
+      g_signal_connect (account, "handle_get_icon", G_CALLBACK (on_get_icon), self);
+      g_signal_connect (account, "handle_get_path", G_CALLBACK (on_get_path), self);
+      g_signal_connect (account, "handle_get_status", G_CALLBACK (on_get_status), self);
+      g_signal_connect (account, "handle_get_status_details", G_CALLBACK (on_get_status_details), self);
+      cloud_provider_account_exporter_add_menu_model (account, get_model ());
+      cloud_provider_account_exporter_add_action_group (account, get_action_group ());
+
+      cloud_provider_exporter_add_account(self->cloud_provider, account);
 
       g_free(account_object_name);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]