[maemo-commits] [maemo-commits] r10423 - in projects/haf/trunk/hildon-desktop: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Mar 6 15:52:11 EET 2007
Author: lucasr
Date: 2007-03-06 15:52:09 +0200 (Tue, 06 Mar 2007)
New Revision: 10423

Modified:
   projects/haf/trunk/hildon-desktop/ChangeLog
   projects/haf/trunk/hildon-desktop/src/hd-desktop.c
   projects/haf/trunk/hildon-desktop/src/hd-plugin-loader-factory.c
Log:
2007-03-06  Lucas Rocha  <lucas.rocha at nokia.com>

	* src/hd-plugin-loader-factory.c: monitor plugin loader directory to
	dynamicaly load new ones without needing to restart the desktop.
	* src/hd-desktop.c: small code cleanup.


Modified: projects/haf/trunk/hildon-desktop/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-desktop/ChangeLog	2007-03-06 13:31:13 UTC (rev 10422)
+++ projects/haf/trunk/hildon-desktop/ChangeLog	2007-03-06 13:52:09 UTC (rev 10423)
@@ -1,3 +1,9 @@
+2007-03-06  Lucas Rocha  <lucas.rocha at nokia.com>
+
+	* src/hd-plugin-loader-factory.c: monitor plugin loader directory to
+	dynamicaly load new ones without needing to restart the desktop.
+	* src/hd-desktop.c: small code cleanup.
+
 2007-03-06  Johan Bilien  <johan.bilien at nokia.com>
 
 	* libhildondesktop/hildon-home-applet.[ch]:
@@ -6,7 +12,7 @@
 	- renamed class from HildonHomeApplet to HildonDesktopHomeItem
 	* ALL: Made necessary adjustments
 
-2007-03-05  Lucas Rocha  <lucas.rocha at nokia.com>
+2007-03-06  Lucas Rocha  <lucas.rocha at nokia.com>
 
 	* libhildondesktop/libhildondesktop.pc.in: added gtk+ and glib
 	dependency info.

Modified: projects/haf/trunk/hildon-desktop/src/hd-desktop.c
===================================================================
--- projects/haf/trunk/hildon-desktop/src/hd-desktop.c	2007-03-06 13:31:13 UTC (rev 10422)
+++ projects/haf/trunk/hildon-desktop/src/hd-desktop.c	2007-03-06 13:52:09 UTC (rev 10423)
@@ -444,11 +444,6 @@
 }
 
 static void 
-hd_desktop_dnotify_init () 
-{
-}
-
-static void 
 hd_desktop_load_containers (HDDesktop *desktop)
 {
   HDDesktopPrivate *priv;
@@ -795,13 +790,11 @@
 static void
 hd_desktop_init (HDDesktop *desktop)
 {
-  const gchar *home, *env_config_file;
+  const gchar *env_config_file;
 
   desktop->priv = HD_DESKTOP_GET_PRIVATE (desktop);
 
-  home = getenv ("HOME");
-
-  desktop->priv->config_path = g_build_filename (home, 
+  desktop->priv->config_path = g_build_filename (g_get_home_dir (), 
                                                  HD_DESKTOP_CONFIG_USER_PATH, 
                                                  NULL);
 
@@ -845,8 +838,6 @@
   desktop->priv->osso_context = osso_initialize (PACKAGE, VERSION, TRUE, NULL);
 #endif
   
-  hd_desktop_dnotify_init ();
-
   hd_desktop_watch_file (desktop->priv->config_file, 
                          hd_desktop_config_changed, 
                          desktop);

Modified: projects/haf/trunk/hildon-desktop/src/hd-plugin-loader-factory.c
===================================================================
--- projects/haf/trunk/hildon-desktop/src/hd-plugin-loader-factory.c	2007-03-06 13:31:13 UTC (rev 10422)
+++ projects/haf/trunk/hildon-desktop/src/hd-plugin-loader-factory.c	2007-03-06 13:52:09 UTC (rev 10423)
@@ -27,6 +27,7 @@
 #endif
 
 #include <glib-object.h>
+#include <libgnomevfs/gnome-vfs.h>
 
 #include "hd-plugin-loader-factory.h"
 #include "hd-plugin-loader.h"
@@ -49,13 +50,45 @@
 
 struct _HDPluginLoaderFactoryPrivate 
 {
-  GHashTable *registry;
-  GHashTable *modules;
-
-  gchar 	 *(*load_module)   (void);
-  HDPluginLoader *(*get_instance)    (void);
+  GHashTable            *registry;
+  GHashTable            *modules;
+  GnomeVFSMonitorHandle *monitor;
+  
+  gchar 	  *(*load_module)   (void);
+  HDPluginLoader  *(*get_instance)  (void);
 };
 
+static int callback_pending = 0;
+
+static void hd_plugin_loader_factory_load_modules (HDPluginLoaderFactory *factory);
+
+static void
+hd_plugin_loader_factory_dir_changed (GnomeVFSMonitorHandle *handle,
+                                      const gchar *monitor_uri,
+                                      const gchar *info_uri,
+                                      GnomeVFSMonitorEventType event_type,
+                                      HDPluginLoaderFactory *factory)
+{
+  if (!callback_pending) 
+  {
+    callback_pending = 1;
+
+    g_debug ("REFRESHING... %s", monitor_uri);
+    
+    g_timeout_add (500,
+                  (GSourceFunc) hd_plugin_loader_factory_load_modules, 
+                  factory);
+  }
+}
+
+static gboolean
+hd_plugin_loader_factory_remove_module (gpointer key, 
+                                        gpointer value, 
+                                        gpointer data)
+{
+  return TRUE;
+}
+        
 static void 
 hd_plugin_loader_factory_load_modules (HDPluginLoaderFactory *factory)
 {
@@ -63,14 +96,29 @@
   GDir *path_modules;
   const gchar *name;
 
+  /* FIXME: this is done because g_hash_table_remove_all is not 
+     available in glib <= 2.12 */
+  g_hash_table_foreach_remove (factory->priv->modules, 
+                               hd_plugin_loader_factory_remove_module,
+                               NULL);
+
   path_modules = g_dir_open (HD_PLUGIN_LOADER_MODULES_PATH, 0, &error);
 
+  if (factory->priv->monitor)
+    gnome_vfs_monitor_cancel (factory->priv->monitor);
+  
   if (error != NULL)
   { 
-    g_warning ("I couldn't open %s path for plugin loaders",
-		HD_PLUGIN_LOADER_MODULES_PATH);
-   
     g_error_free (error);
+
+    gnome_vfs_monitor_add (&factory->priv->monitor, 
+                           HD_DESKTOP_MODULE_PATH,
+                           GNOME_VFS_MONITOR_DIRECTORY,
+                           (GnomeVFSMonitorCallback) hd_plugin_loader_factory_dir_changed,
+                           factory);
+
+   callback_pending = 0;
+    
     return;
   }
 
@@ -89,6 +137,8 @@
 			     MODULE_LOAD_SYMBOL,
 			     (gpointer *) &factory->priv->load_module))
 	{
+          g_debug (factory->priv->load_module ());
+                
 	  g_hash_table_insert (factory->priv->modules,
 			       factory->priv->load_module (),
 			       module);
@@ -106,7 +156,15 @@
     } 
   }
    
-  g_dir_close (path_modules); 
+  g_dir_close (path_modules);
+
+  gnome_vfs_monitor_add (&factory->priv->monitor, 
+                         HD_PLUGIN_LOADER_MODULES_PATH,
+                         GNOME_VFS_MONITOR_DIRECTORY,
+                         (GnomeVFSMonitorCallback) hd_plugin_loader_factory_dir_changed,
+                         factory);
+  
+  callback_pending = 0;
 }
 
 static void
@@ -127,6 +185,7 @@
 			   (GDestroyNotify) g_module_close);
 
   hd_plugin_loader_factory_load_modules (factory);
+
 }
 
 static void


More information about the maemo-commits mailing list