[maemo-commits] [maemo-commits] r14475 - in projects/haf/trunk/hildon-home-webshortcut: . plugin

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Oct 17 15:53:12 EEST 2007
Author: jobi
Date: 2007-10-17 15:53:10 +0300 (Wed, 17 Oct 2007)
New Revision: 14475

Modified:
   projects/haf/trunk/hildon-home-webshortcut/ChangeLog
   projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c
   projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.h
   projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c
Log:

2007-10-17  Johan Bilien  <johan.bilien at nokia.com>

	* plugin/hhws-background.c
	- (hhws_background_cancel): actually cancel the DBus method call
	- (hhws_background_class_{init,finalize): have the proxy
	as class variable.
	* plugin/hildon-home-webshortcut.c:
	- keep a pointer to the last set background
	- (hhws_destroy): cancel all ongoing background setting.
	Fixes: NB#73353



Modified: projects/haf/trunk/hildon-home-webshortcut/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-home-webshortcut/ChangeLog	2007-10-17 12:51:26 UTC (rev 14474)
+++ projects/haf/trunk/hildon-home-webshortcut/ChangeLog	2007-10-17 12:53:10 UTC (rev 14475)
@@ -1,3 +1,14 @@
+2007-10-17  Johan Bilien  <johan.bilien at nokia.com>
+
+	* plugin/hhws-background.c
+	- (hhws_background_cancel): actually cancel the DBus method call
+	- (hhws_background_class_{init,finalize): have the proxy
+	as class variable.
+	* plugin/hildon-home-webshortcut.c:
+	- keep a pointer to the last set background
+	- (hhws_destroy): cancel all ongoing background setting.
+	Fixes: NB#73353
+
 2007-10-01  Johan Bilien  <johan.bilien at nokia.com>
 
 	* configure.ac: 2.0.0

Modified: projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c
===================================================================
--- projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c	2007-10-17 12:51:26 UTC (rev 14474)
+++ projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.c	2007-10-17 12:53:10 UTC (rev 14475)
@@ -52,14 +52,29 @@
 #define HHWS_GCONF_IMAGE_URI    "/apps/osso/apps/hhws/image_uri"
 #define HHWS_GCONF_IMAGE_CACHE  "/apps/osso/apps/hhws/image_cache"
 
+struct cb_data
+{
+  HHWSBackground                     *background;
+  HildonDesktopBackgroundApplyCallback  callback;
+  gpointer                              user_data;
+  GdkWindow                            *window;
+  gchar                                *new_cache;
+  Picture                               picture;
+};
+
+
 static void
 hhws_background_class_init (HHWSBackgroundClass *klass);
+static void
+hhws_background_class_finalize (HHWSBackgroundClass *klass);
 
 static void
 hhws_background_init (HHWSBackground *background);
 
 struct _HHWSBackgroundPrivate {
-  gboolean      cancelled;
+  gboolean              cancelled;
+  struct cb_data       *data;
+  DBusGProxyCall       *call;
 };
 
 static GType background_type = 0;
@@ -77,7 +92,7 @@
   NULL,       /* base_init */
   NULL,       /* base_finalize */
   (GClassInitFunc) hhws_background_class_init,
-  NULL,       /* class_finalize */
+  (GClassFinalizeFunc) hhws_background_class_finalize,
   NULL,       /* class_data */
   sizeof (HHWSBackground),
   0,  /* n_preallocs */
@@ -355,17 +370,7 @@
 
 }
 
-struct cb_data
-{
-  HHWSBackground                     *background;
-  HildonDesktopBackgroundApplyCallback  callback;
-  gpointer                              user_data;
-  GdkWindow                            *window;
-  gchar                                *new_cache;
-  Picture                               picture;
-};
 
-
 static void
 hhws_background_apply_async_dbus_callback (DBusGProxy       *proxy,
                                            GError           *error,
@@ -409,11 +414,8 @@
                                 HildonDesktopBackgroundApplyCallback   cb,
                                 gpointer                        user_data)
 {
-  HHWSBackgroundPrivate  *priv;
-  DBusGProxy               *background_manager_proxy;
-  DBusGConnection          *connection;
-  GError                   *local_error = NULL;
-  struct cb_data           *data;
+  HHWSBackgroundPrivate    *priv;
+  HHWSBackgroundClass      *klass;
   gchar                    *filename;
   gchar                    *cache;
   gchar                    *new_cache = NULL;
@@ -424,22 +426,13 @@
 
   g_return_if_fail (HHWS_IS_BACKGROUND (background) && window);
   priv = HHWS_BACKGROUND (background)->priv;
+  klass = HHWS_BACKGROUND_GET_CLASS (background);
 
-  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &local_error);
-  if (local_error)
-    {
-      if (cb)
-        cb (HILDON_DESKTOP_BACKGROUND (background), 0, local_error, user_data);
-      g_error_free (local_error);
-      return;
-    }
+  if (!klass->background_manager_proxy)
+  {
+    return;
+  }
 
-  background_manager_proxy =
-      dbus_g_proxy_new_for_name (connection,
-                                 HILDON_BACKGROUND_MANAGER_SERVICE,
-                                 HILDON_BACKGROUND_MANAGER_OBJECT_PATH,
-                                 HILDON_BACKGROUND_MANAGER_INTERFACE);
-
   g_object_get (background,
                 "filename", &filename,
                 "cache", &cache,
@@ -473,42 +466,62 @@
 
   gdk_drawable_get_size (window, &width, &height);
 
-  data = g_new (struct cb_data, 1);
+  priv->data = g_new (struct cb_data, 1);
 
-  data->callback = cb;
-  data->background = g_object_ref (background);
-  data->user_data = user_data;
-  data->window = window;
-  data->new_cache = new_cache;
-  data->picture = hildon_desktop_picture_from_color (color,
-                                                     width,
-                                                     height);
-  g_return_if_fail (data->picture != None);
+  priv->data->callback = cb;
+  priv->data->background = g_object_ref (background);
+  priv->data->user_data = user_data;
+  priv->data->window = window;
+  priv->data->new_cache = new_cache;
+  priv->data->picture = hildon_desktop_picture_from_color (color,
+                                                           width,
+                                                           height);
+  g_return_if_fail (priv->data->picture != None);
 
   priv->cancelled = FALSE;
 
   /* Here goes */
 #define S(string) (string?string:"")
-  org_maemo_hildon_background_manager_set_background_async
-                                                (background_manager_proxy,
-                                                 data->picture,
+  priv->call = org_maemo_hildon_background_manager_set_background_async
+                                                (klass->background_manager_proxy,
+                                                 priv->data->picture,
                                                  width,
                                                  height,
                                                  S(file_to_use),
                                                  S(cache),
                                                  mode,
                                                  (org_maemo_hildon_background_manager_set_background_reply) hhws_background_apply_async_dbus_callback,
-                                                 data);
+                                                 priv->data);
 #undef S
 }
 
 static void
 hhws_background_cancel (HildonDesktopBackground *background)
 {
+  HHWSBackgroundClass          *klass;
+  HHWSBackgroundPrivate        *priv;
   g_return_if_fail (HHWS_IS_BACKGROUND (background));
 
-  HHWS_BACKGROUND (background)->priv->cancelled = TRUE;
+  klass = HHWS_BACKGROUND_GET_CLASS (background);
+  priv = HHWS_BACKGROUND (background)->priv;
 
+  priv->cancelled = TRUE;
+
+  if (priv->call)
+  {
+    dbus_g_proxy_cancel_call (klass->background_manager_proxy,
+                              priv->call);
+    priv->call = NULL;
+  }
+
+  if (priv->data)
+  {
+    g_object_unref (priv->data->background);
+    XRenderFreePicture (GDK_DISPLAY (), priv->data->picture);
+    g_free (priv->data);
+    priv->data = NULL;
+  }
+
 }
 
 static HildonDesktopBackground *
@@ -551,6 +564,7 @@
                 "mode", HILDON_DESKTOP_BACKGROUND_CENTERED,
                 "color", &white,
                 NULL);
+
 }
 
 static void
@@ -558,6 +572,8 @@
 {
   HildonDesktopBackgroundClass *background_class;
   gchar                        *cache_dir = NULL;
+  GError                       *local_error = NULL;
+  DBusGConnection              *connection = NULL;
 
   background_class = HILDON_DESKTOP_BACKGROUND_CLASS (klass);
 
@@ -574,7 +590,30 @@
                             NULL);
   g_mkdir (cache_dir, 0755);
   g_free (cache_dir);
+  g_type_class_add_private (klass, sizeof (HHWSBackgroundPrivate));
 
-  g_type_class_add_private (klass, sizeof (HHWSBackgroundPrivate));
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &local_error);
+  if (local_error)
+  {
+    return;
+  }
+
+  klass->background_manager_proxy =
+      dbus_g_proxy_new_for_name (connection,
+                                 HILDON_BACKGROUND_MANAGER_SERVICE,
+                                 HILDON_BACKGROUND_MANAGER_OBJECT_PATH,
+                                 HILDON_BACKGROUND_MANAGER_INTERFACE);
+
+
 }
 
+static void
+hhws_background_class_finalize (HHWSBackgroundClass *klass)
+{
+  if (klass->background_manager_proxy)
+  {
+    g_object_unref (klass->background_manager_proxy);
+    klass->background_manager_proxy = NULL;
+  }
+}
+

Modified: projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.h
===================================================================
--- projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.h	2007-10-17 12:51:26 UTC (rev 14474)
+++ projects/haf/trunk/hildon-home-webshortcut/plugin/hhws-background.h	2007-10-17 12:53:10 UTC (rev 14475)
@@ -26,6 +26,7 @@
 #define __HHWS_BACKGROUND_H__
 
 #include <libhildondesktop/hildon-desktop-background.h>
+#include <dbus/dbus-glib-bindings.h>
 
 G_BEGIN_DECLS
 
@@ -53,6 +54,7 @@
 {
   HildonDesktopBackgroundClass  parent_class;
 
+  DBusGProxy                   *background_manager_proxy;
 };
 
 

Modified: projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c
===================================================================
--- projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c	2007-10-17 12:51:26 UTC (rev 14474)
+++ projects/haf/trunk/hildon-home-webshortcut/plugin/hildon-home-webshortcut.c	2007-10-17 12:53:10 UTC (rev 14475)
@@ -87,6 +87,7 @@
   guint             old_width;
   guint             old_height;
   GConfClient      *gconf_client;
+  HildonDesktopBackground *pending_background;
 };
 
 HD_DEFINE_PLUGIN_WITH_CODE (Hhws, hhws, HILDON_DESKTOP_TYPE_HOME_ITEM, hhws_background_register_type (module);)
@@ -246,6 +247,8 @@
   else if ((dbus_g_error_has_name (error,
                                    "org.freedesktop.DBus.GLib.UnmappedError.GdkPixbufErrorQuark.Code5")))
     text = HHWS_CORRUPTED_TEXT;
+  else
+    g_warning ("Unhandled error when setting webshortcut image");
 
 
   if (text)
@@ -262,6 +265,12 @@
   static gboolean initial_load = TRUE;
   HhwsPrivate  *priv = hhws->priv;
 
+  if (priv->pending_background)
+  {
+    g_object_unref (priv->pending_background);
+    priv->pending_background = NULL;
+  }
+
   if (error)
   {
     if (!initial_load)
@@ -333,6 +342,13 @@
   if (!GTK_WIDGET_REALIZED (hhws))
     return;
 
+  if (hhws->priv->pending_background)
+  {
+    hildon_desktop_background_cancel (hhws->priv->pending_background);
+    g_object_unref (hhws->priv->pending_background);
+  }
+
+  hhws->priv->pending_background = g_object_ref (background);
   hildon_desktop_background_apply_async (background,
                                          GTK_WIDGET (hhws)->window,
                                          (HildonDesktopBackgroundApplyCallback)
@@ -347,6 +363,13 @@
   if (!GTK_WIDGET_REALIZED (hhws))
     return;
 
+  if (hhws->priv->pending_background)
+  {
+    hildon_desktop_background_cancel (hhws->priv->pending_background);
+    g_object_unref (hhws->priv->pending_background);
+  }
+      
+  hhws->priv->pending_background = g_object_ref (background);
   hildon_desktop_background_apply_async (background,
                                          GTK_WIDGET (hhws)->window,
                                          (HildonDesktopBackgroundApplyCallback)
@@ -719,10 +742,11 @@
   if (widget->window != event->window)
     return GTK_WIDGET_CLASS (hhws_parent_class)->button_release_event (widget,
                                                                        event);
-
   if (event->x < 0 || event->x > widget->allocation.width ||
       event->y < 0 || event->y > widget->allocation.height)
+  {
     return TRUE;
+  }
 
   if (priv->iap)
   {
@@ -912,6 +936,13 @@
     g_object_unref (priv->gconf_client);
     priv->gconf_client = NULL;
   }
+  
+  if (hhws->priv->pending_background)
+  {
+    hildon_desktop_background_cancel (priv->pending_background);
+    g_object_unref (priv->pending_background);
+    priv->pending_background = NULL;
+  }
 
   GTK_OBJECT_CLASS (hhws_parent_class)->destroy (object);
 }


More information about the maemo-commits mailing list