[gtk+/wip/csoriano/cloud-providers] f



commit be293106fb786bd307eb9112fa334449604ea2ef
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Jun 18 16:18:07 2015 +0200

    f

 docs/reference/gtk/gtk3-sections.txt             |    8 +++
 gtk/gtkcloudprovider.c                           |   56 ++++++++++++++++----
 gtk/gtkcloudprovider.h                           |   11 +++-
 gtk/gtkcloudprovidermanager.c                    |   62 +++++++++++++++++-----
 gtk/gtkcloudprovidermanager.h                    |   11 +++-
 gtk/gtkfilechooser.c                             |    3 +-
 tests/org.gtk.CloudProviderServerExample.ini     |    2 +-
 tests/org.gtk.CloudProviderServerExample.service |    3 +
 tests/testcloudproviderclient.c                  |    5 ++
 tests/testpopover.c                              |    1 +
 10 files changed, 130 insertions(+), 32 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 273799f..1e8d1aa 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -2631,6 +2631,14 @@ gtk_paned_get_type
 </SECTION>
 
 <SECTION>
+<FILE>gtkcloudprovidermanager</FILE>
+<TITLE>GtkCloudProviderManager</TITLE>
+GtkCloudProviderManager
+gtk_cloud_provider_manager_dup_singleton
+gtk_cloud_provider_manager_get_providers
+</SECTION>
+
+<SECTION>
 <FILE>gtkplacessidebar</FILE>
 <TITLE>GtkPlacesSidebar</TITLE>
 GtkPlacesSidebar
diff --git a/gtk/gtkcloudprovider.c b/gtk/gtkcloudprovider.c
index 002e0c9..2c97725 100644
--- a/gtk/gtkcloudprovider.c
+++ b/gtk/gtkcloudprovider.c
@@ -16,6 +16,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "config.h"
 #include "gtkcloudprovider.h"
 #include <gio/gio.h>
 
@@ -32,7 +33,7 @@ static const gchar introspection_xml[] =
   "</node>";
 
 
-struct _GtkCloudProviderPrivate
+typedef struct
 {
   gchar *name;
   GtkCloudProviderStatus status;
@@ -42,7 +43,7 @@ struct _GtkCloudProviderPrivate
   GDBusProxy *proxy;
   gchar *bus_name;
   gchar *object_path;
-};
+} GtkCloudProviderPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkCloudProvider, gtk_cloud_provider, G_TYPE_OBJECT)
 
@@ -60,20 +61,53 @@ static GParamSpec *gParamSpecs [LAST_PROP];
 static guint gSignals [LAST_SIGNAL];
 
 static void
+on_get_name (GObject      *source_object,
+             GAsyncResult *res,
+             gpointer      user_data)
+{
+  GtkCloudProvider *self = GTK_CLOUD_PROVIDER (user_data);
+  GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
+  GError *error = NULL;
+  GVariant *variant;
+
+  variant = g_dbus_proxy_call_finish (priv->proxy, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Error getting the provider name %s", error->message);
+    }
+  g_print ("variant %s\n", g_variant_get_type (variant));
+  priv->name = g_variant_dup_string (variant, NULL);
+
+  g_print ("name %s\n", priv->name);
+
+  g_signal_emit_by_name (self, "changed");
+}
+
+static void
 on_proxy_created (GObject      *source_object,
                   GAsyncResult *res,
                   gpointer      user_data)
 {
-  GError *error;
-  GtkCloudProvider *self = GTK_CLOUD_PROVIDER (source_object);
+  GError *error = NULL;
+  GtkCloudProvider *self = GTK_CLOUD_PROVIDER (user_data);
+  GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
 
   g_print ("creating proxy\n");
-  self->priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
-  if (error)
-    g_warning ("Error creating proxy for cloud provider");
-  else
-    g_signal_emit_by_name (self, "changed");
+  priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Error creating proxy for cloud provider %s", error->message);
+      return;
+    }
 
+  g_dbus_proxy_call (priv->proxy,
+                     "GetName",
+                     g_variant_new ("()"),
+                     G_DBUS_CALL_FLAGS_NONE,
+                     -1,
+                     NULL,
+                     (GAsyncReadyCallback) on_get_name,
+                     self);
 }
 
 GtkCloudProvider*
@@ -101,7 +135,7 @@ gtk_cloud_provider_new (const gchar *bus_name,
                             "org.gtk.CloudProvider",
                             NULL,
                             on_proxy_created,
-                            NULL);
+                            self);
 
   return self;
 }
diff --git a/gtk/gtkcloudprovider.h b/gtk/gtkcloudprovider.h
index cc1fc79..198a321 100644
--- a/gtk/gtkcloudprovider.h
+++ b/gtk/gtkcloudprovider.h
@@ -19,6 +19,10 @@
 #ifndef GTK_CLOUD_PROVIDER_H
 #define GTK_CLOUD_PROVIDER_H
 
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
 #include <gio/gio.h>
 #include <gdk/gdk.h>
 
@@ -39,20 +43,21 @@ typedef enum {
 
 typedef struct _GtkCloudProvider GtkCloudProvider;
 typedef struct _GtkCloudProviderClass GtkCloudProviderClass;
-typedef struct _GtkCloudProviderPrivate GtkCloudProviderPrivate;
 
 
 struct _GtkCloudProviderClass
 {
-  GObjectClass parent;
+  GObjectClass parent_class;
 };
 
 struct _GtkCloudProvider
 {
-  GtkCloudProviderPrivate *priv;
+  GObject parent_instance;
 };
 
 GDK_AVAILABLE_IN_3_18
+GType          gtk_cloud_provider_get_type          (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_3_18
 GtkCloudProvider *gtk_cloud_provider_new (const gchar *bus_name,
                                           const gchar *object_path);
 GDK_AVAILABLE_IN_3_18
diff --git a/gtk/gtkcloudprovidermanager.c b/gtk/gtkcloudprovidermanager.c
index 650cf99..4536c3a 100644
--- a/gtk/gtkcloudprovidermanager.c
+++ b/gtk/gtkcloudprovidermanager.c
@@ -15,6 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
+#include "config.h"
+
 #include "gtkcloudprovidermanager.h"
 #include "gtkcloudprovider.h"
 #include <glib.h>
@@ -22,10 +25,10 @@
 
 #define KEY_FILE_GROUP "Gtk Cloud Provider"
 
-struct _GtkCloudProviderManagerPrivate
+typedef struct
 {
   GList *providers;
-};
+} GtkCloudProviderManagerPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkCloudProviderManager, gtk_cloud_provider_manager, G_TYPE_OBJECT)
 
@@ -43,6 +46,10 @@ enum
 static GParamSpec *gParamSpecs [LAST_PROP];
 static guint gSignals [LAST_SIGNAL];
 
+/**
+ * gtk_cloud_provider_manager_dup_singleton
+ * Returns: (transfer none): A manager singleton
+ */
 GtkCloudProviderManager *
 gtk_cloud_provider_manager_dup_singleton (void)
 {
@@ -123,10 +130,15 @@ gtk_cloud_provider_manager_init (GtkCloudProviderManager *self)
 {
 }
 
+/**
+ * gtk_cloud_provider_manager_get_providers
+ * @manager: A GtkCloudProviderManager
+ * Returns: (transfer none): The list of providers.
+ */
 GList*
-gtk_cloud_provider_manager_get_providers (GtkCloudProviderManager *self)
+gtk_cloud_provider_manager_get_providers (GtkCloudProviderManager *manager)
 {
-  GtkCloudProviderManagerPrivate *priv = gtk_cloud_provider_manager_get_instance_private (self);
+  GtkCloudProviderManagerPrivate *priv = gtk_cloud_provider_manager_get_instance_private (manager);
 
   return priv->providers;
 }
@@ -138,15 +150,18 @@ load_cloud_provider (GtkCloudProviderManager *self,
   GtkCloudProviderManagerPrivate *priv = gtk_cloud_provider_manager_get_instance_private (self);
   GKeyFile *key_file;
   gchar *path;
-  GError *error;
+  GError *error = NULL;
   gchar *bus_name;
   gchar *object_path;
   gboolean success = FALSE;
   GtkCloudProvider *cloud_provider;
 
+  g_print ("load cloud provider %s\n", g_file_get_path (file));
   key_file = g_key_file_new ();
   path = g_file_get_path (file);
   g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error);
+  if (error != NULL)
+    goto out;
 
   if (!g_key_file_has_group (key_file, KEY_FILE_GROUP))
     goto out;
@@ -158,6 +173,7 @@ load_cloud_provider (GtkCloudProviderManager *self,
   if (error != NULL)
     goto out;
 
+  g_print ("cloud provider found %s %s\n", bus_name, object_path);
   cloud_provider = gtk_cloud_provider_new (bus_name, object_path);
   priv->providers = g_list_append (priv->providers, cloud_provider);
 
@@ -165,31 +181,37 @@ load_cloud_provider (GtkCloudProviderManager *self,
 out:
   if (!success)
     g_warning ("Error while loading cloud provider key file at %s", path);
-  g_object_unref (key_file);
+  g_key_file_free (key_file);
 }
 
+/**
+ * gtk_cloud_provider_manager_update
+ * @manager: A GtkCloudProviderManager
+ */
 void
-gtk_cloud_manager_update (GtkCloudProviderManager *self)
+gtk_cloud_provider_manager_update (GtkCloudProviderManager *manager)
 {
-  GtkCloudProviderManagerPrivate *priv = gtk_cloud_provider_manager_get_instance_private (self);
+  GtkCloudProviderManagerPrivate *priv = gtk_cloud_provider_manager_get_instance_private (manager);
   const gchar* const *data_dirs;
   gint i;
   gint len;
   gchar *key_files_directory_path;
   GFile *key_files_directory_file;
-  GError *error;
+  GError *error = NULL;
   GFileEnumerator *file_enumerator;
 
+
   g_list_free_full (priv->providers, g_object_unref);
 
   data_dirs = g_get_system_data_dirs ();
   len = g_strv_length ((gchar **)data_dirs);
 
+  g_print ("updating manager with %d providers\n", len);
   for (i = 0; i < len; i++)
     {
       GFileInfo *info;
 
-      key_files_directory_path = g_build_filename (data_dirs[i], "gtk", "cloud-providers", NULL);
+      key_files_directory_path = g_build_filename (data_dirs[i], "gtk+", "cloud-providers", NULL);
       key_files_directory_file = g_file_new_for_path (key_files_directory_path);
       file_enumerator = g_file_enumerate_children (key_files_directory_file,
                                                    "standard::name,standard::type",
@@ -197,12 +219,26 @@ gtk_cloud_manager_update (GtkCloudProviderManager *self)
                                                    NULL,
                                                    &error);
       if (error)
-        continue;
+        {
+          g_warning ("Error while updating manager %s error: %s\n", key_files_directory_path, 
error->message);
+          error = NULL;
+          continue;
+        }
 
       info = g_file_enumerator_next_file (file_enumerator, NULL, &error);
-      while (info != NULL && error != NULL)
+      if (error)
+        {
+          g_warning ("Error while enumerating file %s error: %s\n", key_files_directory_path, 
error->message);
+          error = NULL;
+          continue;
+        }
+      if (info == NULL)
+        {
+          g_print ("no info\n");
+        }
+      while (info != NULL && error == NULL)
         {
-           load_cloud_provider (self, g_file_enumerator_get_child (file_enumerator, info));
+           load_cloud_provider (manager, g_file_enumerator_get_child (file_enumerator, info));
            info = g_file_enumerator_next_file (file_enumerator, NULL, &error);
         }
     }
diff --git a/gtk/gtkcloudprovidermanager.h b/gtk/gtkcloudprovidermanager.h
index 1b6f2b0..560d5ff 100644
--- a/gtk/gtkcloudprovidermanager.h
+++ b/gtk/gtkcloudprovidermanager.h
@@ -18,6 +18,10 @@
 #ifndef GTK_CLOUD_PROVIDER_MANAGER_H
 #define GTK_CLOUD_PROVIDER_MANAGER_H
 
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
 #include <gio/gio.h>
 #include <gdk/gdk.h>
 
@@ -32,19 +36,20 @@ G_BEGIN_DECLS
 
 typedef struct _GtkCloudProviderManager GtkCloudProviderManager;
 typedef struct _GtkCloudProviderManagerClass GtkCloudProviderManagerClass;
-typedef struct _GtkCloudProviderManagerPrivate GtkCloudProviderManagerPrivate;
 
 struct _GtkCloudProviderManagerClass
 {
-  GObjectClass parent;
+  GObjectClass parent_class;
 };
 
 struct _GtkCloudProviderManager
 {
-  GtkCloudProviderManagerPrivate *priv;
+  GObject parent_instance;
 };
 
 GDK_AVAILABLE_IN_3_18
+GType          gtk_cloud_provider_manager_get_type          (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_3_18
 GtkCloudProviderManager *gtk_cloud_provider_manager_dup_singleton (void);
 GDK_AVAILABLE_IN_3_18
 void gtk_cloud_provider_manager_update (GtkCloudProviderManager *self);
diff --git a/gtk/gtkfilechooser.c b/gtk/gtkfilechooser.c
index 969eae2..853330a 100644
--- a/gtk/gtkfilechooser.c
+++ b/gtk/gtkfilechooser.c
@@ -23,6 +23,7 @@
 #include "gtktypebuiltins.h"
 #include "gtkprivate.h"
 #include "gtkmarshalers.h"
+#include "gtkcloudprovidermanager.h"
 
 
 /**
@@ -181,7 +182,7 @@ static void
 gtk_file_chooser_default_init (GtkFileChooserInterface *iface)
 {
   GType iface_type = G_TYPE_FROM_INTERFACE (iface);
-
+  gtk_cloud_provider_manager_dup_singleton ();
   /**
    * GtkFileChooser::current-folder-changed:
    * @chooser: the object which received the signal.
diff --git a/tests/org.gtk.CloudProviderServerExample.ini b/tests/org.gtk.CloudProviderServerExample.ini
index c7d7c8a..424b2eb 100644
--- a/tests/org.gtk.CloudProviderServerExample.ini
+++ b/tests/org.gtk.CloudProviderServerExample.ini
@@ -1,4 +1,4 @@
 [Gtk Cloud Provider]
 BusName=org.gtk.CloudProviderServerExample
-ObjectPath=/org/gtk/CloudProvider
+ObjectPath=/org/gtk/CloudProviderServerExample
 Version=1
diff --git a/tests/org.gtk.CloudProviderServerExample.service 
b/tests/org.gtk.CloudProviderServerExample.service
new file mode 100644
index 0000000..52e93bf
--- /dev/null
+++ b/tests/org.gtk.CloudProviderServerExample.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gtk.CloudProviderServerExample
+Exec=/home/csoriano/jhbuild/install/bin/testcloudprovider 
diff --git a/tests/testcloudproviderclient.c b/tests/testcloudproviderclient.c
index add0f85..bfc60ba 100644
--- a/tests/testcloudproviderclient.c
+++ b/tests/testcloudproviderclient.c
@@ -14,6 +14,8 @@ main (gint   argc,
       gchar *argv[])
 {
   GtkCloudProviderManager *manager;
+  GMainLoop *loop;
+
   g_set_prgname ("my-program");
   g_set_application_name ("My-program");
 
@@ -22,5 +24,8 @@ main (gint   argc,
   g_signal_connect (manager, "changed", G_CALLBACK (on_manager_changed), NULL);
   gtk_cloud_provider_manager_update (manager);
 
+  loop = g_main_loop_new (NULL, FALSE);
+  g_main_loop_run (loop);
+
   return 0;
 }
diff --git a/tests/testpopover.c b/tests/testpopover.c
index 306e7c9..e132521 100644
--- a/tests/testpopover.c
+++ b/tests/testpopover.c
@@ -145,6 +145,7 @@ main (int argc, char *argv[])
   gtk_grid_attach (GTK_GRID (grid), label , 1, 5, 1, 1);
   gtk_grid_attach (GTK_GRID (grid), combo, 2, 5, 1, 1);
 
+  gtk_cloud_provider_manager_dup_singleton ();
 
   gtk_widget_show_all (win);
 


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