[gtk+/wip/csoriano/cloud-providers: 31/31] cloud providers
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/csoriano/cloud-providers: 31/31] cloud providers
- Date: Thu, 18 Jun 2015 19:52:25 +0000 (UTC)
commit 2eb2deee21a7404ce9bd9e1b517b3ac0dfcdd9fb
Author: Carlos Soriano <csoriano gnome org>
Date: Wed Jun 17 20:30:46 2015 +0200
cloud providers
docs/reference/gtk/gtk3-sections.txt | 8 +
gtk/Makefile.am | 4 +
gtk/gtk.h | 2 +
gtk/gtkcloudprovider.c | 246 ++++++++++++++++++++
gtk/gtkcloudprovider.h | 74 ++++++
gtk/gtkcloudprovidermanager.c | 245 +++++++++++++++++++
gtk/gtkcloudprovidermanager.h | 61 +++++
gtk/gtkfilechooser.c | 3 +-
tests/Makefile.am | 20 ++
tests/org.gtk.CloudProviderServerExample.ini | 4 +
tests/org.gtk.CloudProviderServerExample.service | 3 +
.../org.gtk.CloudProviderServerExample.service.in | 3 +
tests/testcloudproviderclient.c | 31 +++
tests/testcloudproviderserver.c | 184 +++++++++++++++
tests/testpopover.c | 1 +
15 files changed, 888 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 1967110..edb5318 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/Makefile.am b/gtk/Makefile.am
index 50e8efb..b5f1c05 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -164,6 +164,8 @@ gtk_public_h_sources = \
gtkcontainer.h \
gtkcssprovider.h \
gtkcsssection.h \
+ gtkcloudprovider.h \
+ gtkcloudprovidermanager.h \
gtkdebug.h \
gtkdialog.h \
gtkdnd.h \
@@ -663,6 +665,8 @@ gtk_base_c_sources = \
gtkcsstypes.c \
gtkcssvalue.c \
gtkcsswidgetnode.c \
+ gtkcloudprovider.c \
+ gtkcloudprovidermanager.c \
gtkdialog.c \
gtkdrawingarea.c \
gtkeditable.c \
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 3cbd13f..0ec9af3 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -71,6 +71,8 @@
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkcheckmenuitem.h>
#include <gtk/gtkclipboard.h>
+#include <gtk/gtkcloudprovider.h>
+#include <gtk/gtkcloudprovidermanager.h>
#include <gtk/gtkcolorbutton.h>
#include <gtk/gtkcolorchooser.h>
#include <gtk/gtkcolorchooserdialog.h>
diff --git a/gtk/gtkcloudprovider.c b/gtk/gtkcloudprovider.c
new file mode 100644
index 0000000..2c97725
--- /dev/null
+++ b/gtk/gtkcloudprovider.c
@@ -0,0 +1,246 @@
+/* gtkcloudprovider.c
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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 "gtkcloudprovider.h"
+#include <gio/gio.h>
+
+static const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.gtk.CloudProvider'>"
+ " <method name='GetName'>"
+ " <arg type='s' name='name' direction='out'/>"
+ " </method>"
+ " <method name='GetStatus'>"
+ " <arg type='i' name='name' direction='out'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+
+typedef struct
+{
+ gchar *name;
+ GtkCloudProviderStatus status;
+ GIcon *icon;
+ GMenuModel *menu;
+
+ GDBusProxy *proxy;
+ gchar *bus_name;
+ gchar *object_path;
+} GtkCloudProviderPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkCloudProvider, gtk_cloud_provider, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ LAST_PROP
+};
+
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+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 = NULL;
+ GtkCloudProvider *self = GTK_CLOUD_PROVIDER (user_data);
+ GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
+
+ g_print ("creating proxy\n");
+ 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*
+gtk_cloud_provider_new (const gchar *bus_name,
+ const gchar *object_path)
+{
+ GtkCloudProvider *self;
+ GtkCloudProviderPrivate *priv;
+ GDBusNodeInfo *proxy_info;
+ GDBusInterfaceInfo *interface_info;
+ GError *error = NULL;
+
+ self = g_object_new (GTK_TYPE_CLOUD_PROVIDER, NULL);
+ priv = gtk_cloud_provider_get_instance_private (self);
+
+ proxy_info = g_dbus_node_info_new_for_xml (introspection_xml, &error);
+ interface_info = g_dbus_node_info_lookup_interface (proxy_info, "org.gtk.CloudProvider");
+ priv->bus_name = g_strdup (bus_name);
+ priv->object_path = g_strdup (object_path);
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ interface_info,
+ bus_name,
+ object_path,
+ "org.gtk.CloudProvider",
+ NULL,
+ on_proxy_created,
+ self);
+
+ return self;
+}
+
+static void
+gtk_cloud_provider_finalize (GObject *object)
+{
+ GtkCloudProvider *self = (GtkCloudProvider *)object;
+ GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
+
+ g_free (priv->name);
+ g_clear_object (&priv->icon);
+ g_clear_object (&priv->menu);
+ g_clear_object (&priv->proxy);
+ g_free (priv->bus_name);
+ g_free (priv->object_path);
+
+ G_OBJECT_CLASS (gtk_cloud_provider_parent_class)->finalize (object);
+}
+
+static void
+gtk_cloud_provider_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkCloudProvider *self = GTK_CLOUD_PROVIDER (object);
+
+ switch (prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtk_cloud_provider_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkCloudProvider *self = GTK_CLOUD_PROVIDER (object);
+
+ switch (prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtk_cloud_provider_class_init (GtkCloudProviderClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gtk_cloud_provider_finalize;
+ object_class->get_property = gtk_cloud_provider_get_property;
+ object_class->set_property = gtk_cloud_provider_set_property;
+
+ gSignals [CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 0);
+}
+
+static void
+gtk_cloud_provider_init (GtkCloudProvider *self)
+{
+}
+
+const gchar*
+gtk_cloud_provider_get_name (GtkCloudProvider *self)
+{
+ GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
+
+ return priv->name;
+}
+
+GtkCloudProviderStatus
+gtk_cloud_provider_get_status (GtkCloudProvider *self)
+{
+ GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
+
+ return priv->status;
+}
+
+GIcon*
+gtk_cloud_provider_get_icon (GtkCloudProvider *self)
+{
+ GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
+
+ return priv->icon;
+}
+
+GMenuModel*
+gtk_cloud_provider_get_menu (GtkCloudProvider *self)
+{
+ GtkCloudProviderPrivate *priv = gtk_cloud_provider_get_instance_private (self);
+
+ return priv->menu;
+}
+
diff --git a/gtk/gtkcloudprovider.h b/gtk/gtkcloudprovider.h
new file mode 100644
index 0000000..198a321
--- /dev/null
+++ b/gtk/gtkcloudprovider.h
@@ -0,0 +1,74 @@
+/* gtkcloudprovider.h
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#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>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ GTK_CLOUD_PROVIDER_STATUS_IDLE,
+ GTK_CLOUD_PROVIDER_STATUS_SYNCING,
+ GTK_CLOUD_PROVIDER_STATUS_ERROR
+} GtkCloudProviderStatus;
+
+#define GTK_TYPE_CLOUD_PROVIDER (gtk_cloud_provider_get_type())
+#define GTK_CLOUD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CLOUD_PROVIDER,
GtkCloudProvider))
+#define GTK_CLOUD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CLOUD_PROVIDER,
GtkCloudProviderClass))
+#define GTK_IS_CLOUD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CLOUD_PROVIDER))
+#define GTK_IS_CLOUD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CLOUD_PROVIDER))
+#define GTK_CLOUD_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CLOUD_PROVIDER,
GtkCloudProviderClass))
+
+typedef struct _GtkCloudProvider GtkCloudProvider;
+typedef struct _GtkCloudProviderClass GtkCloudProviderClass;
+
+
+struct _GtkCloudProviderClass
+{
+ GObjectClass parent_class;
+};
+
+struct _GtkCloudProvider
+{
+ 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
+const gchar* gtk_cloud_provider_get_name (GtkCloudProvider *self);
+GDK_AVAILABLE_IN_3_18
+GtkCloudProviderStatus gtk_cloud_provider_get_status (GtkCloudProvider *self);
+GDK_AVAILABLE_IN_3_18
+GIcon *gtk_cloud_provider_get_icon (GtkCloudProvider *self);
+GDK_AVAILABLE_IN_3_18
+GMenuModel *gtk_cloud_provider_get_menu (GtkCloudProvider *self);
+
+G_END_DECLS
+
+#endif /* GTK_CLOUD_PROVIDER_H */
diff --git a/gtk/gtkcloudprovidermanager.c b/gtk/gtkcloudprovidermanager.c
new file mode 100644
index 0000000..4536c3a
--- /dev/null
+++ b/gtk/gtkcloudprovidermanager.c
@@ -0,0 +1,245 @@
+/* gtkcloudprovidermanager.c
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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>
+#include <glib/gprintf.h>
+
+#define KEY_FILE_GROUP "Gtk Cloud Provider"
+
+typedef struct
+{
+ GList *providers;
+} GtkCloudProviderManagerPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkCloudProviderManager, gtk_cloud_provider_manager, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ LAST_PROP
+};
+
+enum
+{
+ CHANGED,
+ LAST_SIGNAL
+};
+
+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)
+{
+ static GObject *self = NULL;
+
+ if (self == NULL)
+ {
+ self = g_object_new (GTK_TYPE_CLOUD_PROVIDER_MANAGER, NULL);
+ return GTK_CLOUD_PROVIDER_MANAGER (self);
+ }
+ else
+ {
+ return g_object_ref (self);
+ }
+}
+
+static void
+gtk_cloud_provider_manager_finalize (GObject *object)
+{
+ GtkCloudProviderManager *self = (GtkCloudProviderManager *)object;
+
+ G_OBJECT_CLASS (gtk_cloud_provider_manager_parent_class)->finalize (object);
+}
+
+static void
+gtk_cloud_provider_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkCloudProviderManager *self = GTK_CLOUD_PROVIDER_MANAGER (object);
+
+ switch (prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtk_cloud_provider_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkCloudProviderManager *self = GTK_CLOUD_PROVIDER_MANAGER (object);
+
+ switch (prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtk_cloud_provider_manager_class_init (GtkCloudProviderManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gtk_cloud_provider_manager_finalize;
+ object_class->get_property = gtk_cloud_provider_manager_get_property;
+ object_class->set_property = gtk_cloud_provider_manager_set_property;
+
+ gSignals [CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 0);
+}
+
+static void
+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 *manager)
+{
+ GtkCloudProviderManagerPrivate *priv = gtk_cloud_provider_manager_get_instance_private (manager);
+
+ return priv->providers;
+}
+
+static void
+load_cloud_provider (GtkCloudProviderManager *self,
+ GFile *file)
+{
+ GtkCloudProviderManagerPrivate *priv = gtk_cloud_provider_manager_get_instance_private (self);
+ GKeyFile *key_file;
+ gchar *path;
+ 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;
+
+ bus_name = g_key_file_get_string (key_file, KEY_FILE_GROUP, "BusName", &error);
+ if (error != NULL)
+ goto out;
+ object_path = g_key_file_get_string (key_file, KEY_FILE_GROUP, "ObjectPath", &error);
+ 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);
+
+ success = TRUE;
+out:
+ if (!success)
+ g_warning ("Error while loading cloud provider key file at %s", path);
+ g_key_file_free (key_file);
+}
+
+/**
+ * gtk_cloud_provider_manager_update
+ * @manager: A GtkCloudProviderManager
+ */
+void
+gtk_cloud_provider_manager_update (GtkCloudProviderManager *manager)
+{
+ 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 = 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_file = g_file_new_for_path (key_files_directory_path);
+ file_enumerator = g_file_enumerate_children (key_files_directory_file,
+ "standard::name,standard::type",
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+ if (error)
+ {
+ 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);
+ 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 (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
new file mode 100644
index 0000000..560d5ff
--- /dev/null
+++ b/gtk/gtkcloudprovidermanager.h
@@ -0,0 +1,61 @@
+/* gtkcloudprovidermanager.h
+ *
+ * Copyright (C) 2015 Carlos Soriano <csoriano gnome org>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#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>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CLOUD_PROVIDER_MANAGER (gtk_cloud_provider_manager_get_type())
+#define GTK_CLOUD_PROVIDER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_TYPE_CLOUD_PROVIDER_MANAGER, GtkCloudProviderManager))
+#define GTK_CLOUD_PROVIDER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_TYPE_CLOUD_PROVIDER_MANAGER, GtkCloudProviderManagerClass))
+#define GTK_IS_CLOUD_PROVIDER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_TYPE_CLOUD_PROVIDER_MANAGER))
+#define GTK_IS_CLOUD_PROVIDER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_TYPE_CLOUD_PROVIDER_MANAGER))
+#define GTK_CLOUD_PROVIDER_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_TYPE_CLOUD_PROVIDER_MANAGER, GtkCloudProviderManagerClass))
+
+typedef struct _GtkCloudProviderManager GtkCloudProviderManager;
+typedef struct _GtkCloudProviderManagerClass GtkCloudProviderManagerClass;
+
+struct _GtkCloudProviderManagerClass
+{
+ GObjectClass parent_class;
+};
+
+struct _GtkCloudProviderManager
+{
+ 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);
+GDK_AVAILABLE_IN_3_18
+GList *gtk_cloud_provider_manager_get_providers (GtkCloudProviderManager *self);
+
+G_END_DECLS
+
+#endif /* GTK_CLOUD_PROVIDER_MANAGER_H */
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/Makefile.am b/tests/Makefile.am
index 95ac80f..61ec3c6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,6 +30,18 @@ if OS_LINUX
fontconfig_programs = testfontchooserdialog
endif
+cloudproviderdir = $(datadir)/gtk+/cloud-providers
+dist_cloudprovider_DATA = org.gtk.CloudProviderServerExample.ini
+
+servicedir = $(datadir)/dbus-1/services
+service_in_files = org.gtk.CloudProviderServerExample.service.in
+service_DATA = $(service_in_files:.service.in=.service)
+
+org.gtk.CloudProviderServerExample.service: org.gtk.CloudProviderServerExample.service.in
+ $(AM_V_GEN) \
+ [ -d $(@D) ] || $(mkdir_p) $(@D) ; \
+ sed -e "s|\ bindir\@|$(bindir)|" $< > $ tmp && mv $ tmp $@
+
noinst_PROGRAMS = $(TEST_PROGS) \
overlayscroll \
syncscroll \
@@ -165,6 +177,8 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testactionbar \
testwindowsize \
testpopover \
+ testcloudproviderserver \
+ testcloudproviderclient \
gdkgears \
$(NULL)
@@ -304,6 +318,8 @@ teststack_DEPENDENCIES = $(TEST_DEPS)
testrevealer_DEPENDENCIES = $(TEST_DEPS)
testtitlebar_DEPENDENCIES = $(TEST_DEPS)
testwindowsize_DEPENDENCIES = $(TEST_DEPS)
+testcloudproviderserver_DEPENDENCIES = $(TEST_DEPS)
+testcloudproviderclient_DEPENDENCIES = $(TEST_DEPS)
animated_resizing_SOURCES = \
animated-resizing.c \
@@ -523,6 +539,10 @@ testtitlebar_SOURCES = testtitlebar.c
testwindowsize_SOURCES = testwindowsize.c
+testcloudproviderserver_SOURCES = testcloudproviderserver.c
+
+testcloudproviderclient_SOURCES = testcloudproviderclient.c
+
gdkgears_SOURCES = \
gdkgears.c \
gtkgears.c \
diff --git a/tests/org.gtk.CloudProviderServerExample.ini b/tests/org.gtk.CloudProviderServerExample.ini
new file mode 100644
index 0000000..424b2eb
--- /dev/null
+++ b/tests/org.gtk.CloudProviderServerExample.ini
@@ -0,0 +1,4 @@
+[Gtk Cloud Provider]
+BusName=org.gtk.CloudProviderServerExample
+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/org.gtk.CloudProviderServerExample.service.in
b/tests/org.gtk.CloudProviderServerExample.service.in
new file mode 100644
index 0000000..2a8b5e6
--- /dev/null
+++ b/tests/org.gtk.CloudProviderServerExample.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gtk.CloudProviderServerExample
+Exec= bindir@/testcloudprovider
diff --git a/tests/testcloudproviderclient.c b/tests/testcloudproviderclient.c
new file mode 100644
index 0000000..bfc60ba
--- /dev/null
+++ b/tests/testcloudproviderclient.c
@@ -0,0 +1,31 @@
+#include "config.h"
+#include <glib.h>
+#include <gtk/gtk.h>
+
+static void
+on_manager_changed (GtkCloudProviderManager *manager)
+{
+
+ g_print ("Manager changed\n");
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ GtkCloudProviderManager *manager;
+ GMainLoop *loop;
+
+ g_set_prgname ("my-program");
+ g_set_application_name ("My-program");
+
+
+ manager = gtk_cloud_provider_manager_dup_singleton ();
+ 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/testcloudproviderserver.c b/tests/testcloudproviderserver.c
new file mode 100644
index 0000000..91c350f
--- /dev/null
+++ b/tests/testcloudproviderserver.c
@@ -0,0 +1,184 @@
+#include <gio/gio.h>
+#include <stdlib.h>
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+enum {
+ IDDLE,
+ SYNCING,
+ ERROR
+};
+
+/* The object we want to export */
+typedef struct _CloudProviderClass CloudProviderClass;
+typedef struct _CloudProvider CloudProvider;
+
+struct _CloudProviderClass
+{
+ GObjectClass parent_class;
+};
+
+struct _CloudProvider
+{
+ GObject parent_instance;
+
+ gchar *name;
+ gint status;
+};
+
+
+static GType cloud_provider_get_type (void);
+G_DEFINE_TYPE (CloudProvider, cloud_provider, G_TYPE_OBJECT);
+
+static void
+cloud_provider_finalize (GObject *object)
+{
+ CloudProvider *self = (CloudProvider*)object;
+
+ g_free (self->name);
+
+ G_OBJECT_CLASS (cloud_provider_parent_class)->finalize (object);
+}
+
+static void
+cloud_provider_init (CloudProvider *self)
+{
+ self->name = "cloud provider";
+ self->status = IDDLE;
+}
+
+static void
+cloud_provider_class_init (CloudProviderClass *class)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+
+ gobject_class->finalize = cloud_provider_finalize;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GDBusNodeInfo *introspection_data = NULL;
+
+/* Introspection data for the service we are exporting */
+static const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.gtk.CloudProvider'>"
+ " <method name='GetName'>"
+ " <arg type='s' name='name' direction='out'/>"
+ " </method>"
+ " <method name='GetStatus'>"
+ " <arg type='i' name='name' direction='out'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+
+static void
+handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ CloudProvider *cloud_provider = user_data;
+
+ g_print ("handling method call\n");
+#if 0
+ if (g_strcmp0 (method_name, "ChangeCount") == 0)
+ {
+ gint change;
+ g_variant_get (parameters, "(i)", &change);
+
+ my_object_change_count (myobj, change);
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+#endif
+ if (g_strcmp0 (method_name, "GetName") == 0)
+ {
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(s)", cloud_provider->name));
+ }
+ else if (g_strcmp0 (method_name, "GetStatus") == 0)
+ {
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(s)", cloud_provider->status));
+ }
+}
+
+static const GDBusInterfaceVTable interface_vtable =
+{
+ handle_method_call,
+};
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ CloudProvider *cloud_provider = user_data;
+ guint registration_id;
+
+ g_print ("registring\n");
+ registration_id = g_dbus_connection_register_object (connection,
+ "/org/gtk/CloudProviderServerExample",
+ introspection_data->interfaces[0],
+ &interface_vtable,
+ cloud_provider,
+ NULL, /* user_data_free_func */
+ NULL); /* GError** */
+ g_assert (registration_id > 0);
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ exit (1);
+}
+
+int
+main (int argc, char *argv[])
+{
+ GMainLoop *loop;
+ CloudProvider *cloud_provider;
+ guint owner_id;
+
+ introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+ g_assert (introspection_data != NULL);
+
+ cloud_provider = g_object_new (cloud_provider_get_type (), NULL);
+
+ owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ "org.gtk.CloudProviderServerExample",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ cloud_provider,
+ NULL);
+
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+
+ g_bus_unown_name (owner_id);
+
+ g_dbus_node_info_unref (introspection_data);
+
+ g_object_unref (cloud_provider);
+
+ 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]