[maemo-commits] [maemo-commits] r8537 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Fri Dec 1 16:36:55 EET 2006
- Previous message: [maemo-commits] r8536 - projects/haf/tags/osso-af-startup
- Next message: [maemo-commits] r8538 - in projects/haf: tags trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: lucasr Date: 2006-12-01 16:36:53 +0200 (Fri, 01 Dec 2006) New Revision: 8537 Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-desktop.c projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-manager.c Log: 2006-12-01 Lucas Rocha <lucas.rocha at nokia.com> * hd-desktop.c: keep track of container plugin directory changes and unload plugins and save new configuration if needed. Fix some memory leaks. Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog =================================================================== --- projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog 2006-12-01 14:04:53 UTC (rev 8536) +++ projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog 2006-12-01 14:36:53 UTC (rev 8537) @@ -1,3 +1,9 @@ +2006-12-01 Lucas Rocha <lucas.rocha at nokia.com> + + * hd-desktop.c: keep track of container plugin directory changes and + unload plugins and save new configuration if needed. Fix some memory + leaks. + 2006-11-30 Lucas Rocha <lucas.rocha at nokia.com> * src/hd-select-plugins-dialog.[ch], src/hd-desktop.c: don't clear Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-desktop.c =================================================================== --- projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-desktop.c 2006-12-01 14:04:53 UTC (rev 8536) +++ projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-desktop.c 2006-12-01 14:36:53 UTC (rev 8537) @@ -28,6 +28,8 @@ #include <stdlib.h> +#include <hildon-base-lib/hildon-base-dnotify.h> + #include <glib.h> #include <glib-object.h> #include <gtk/gtk.h> @@ -59,6 +61,24 @@ static void hd_desktop_load_containers (HDDesktop *desktop); +static gint +hd_desktop_find_by_id (gconstpointer a, gconstpointer b) +{ + gint result = -1; + gchar *id = NULL; + + g_object_get (G_OBJECT (a), + "id", &id, + NULL); + + if (!g_ascii_strcasecmp (id, b)) + result = 0; + + g_free (id); + + return result; +} + static GList * hd_desktop_plugin_list_from_container (GtkContainer *container) { @@ -66,7 +86,7 @@ children = gtk_container_get_children (container); - for (iter = g_list_first (children); iter; iter = g_list_next (iter)) + for (iter = children; iter; iter = g_list_next (iter)) { gchar *id; @@ -93,7 +113,7 @@ keyfile = g_key_file_new (); - for (iter = g_list_first (plugin_list); iter; iter = g_list_next (iter)) + for (iter = plugin_list; iter; iter = g_list_next (iter)) { g_key_file_set_string (keyfile, (gchar *) iter->data, @@ -182,16 +202,14 @@ { HDDesktopPrivate *priv; GList *plugin_list; - gchar *config_file; + const gchar *config_file; g_return_if_fail (user_data != NULL); g_return_if_fail (HD_IS_DESKTOP (user_data)); priv = HD_DESKTOP_GET_PRIVATE (user_data); - config_file = g_build_filename (priv->config_path, - hildon_desktop_window_get_config_file (window), - NULL); + config_file = hildon_desktop_window_get_config_file (window); plugin_list = hd_desktop_plugin_list_from_conf (config_file); @@ -199,8 +217,8 @@ plugin_list, window->container); + g_list_foreach (plugin_list, (GFunc) g_free , NULL); g_list_free (plugin_list); - g_free (config_file); } static void @@ -208,33 +226,31 @@ { HDDesktopPrivate *priv; GList *plugin_list; - gchar *config_file; + const gchar *config_file; g_return_if_fail (user_data != NULL); g_return_if_fail (HD_IS_DESKTOP (user_data)); priv = HD_DESKTOP_GET_PRIVATE (user_data); - config_file = g_build_filename (priv->config_path, - hildon_desktop_window_get_config_file (window), - NULL); + config_file = hildon_desktop_window_get_config_file (window); plugin_list = hd_desktop_plugin_list_from_container (window->container); hd_desktop_plugin_list_to_conf (plugin_list, config_file); + g_list_foreach (plugin_list, (GFunc) g_free , NULL); g_list_free (plugin_list); - g_free (config_file); } static void hd_desktop_select_plugins (HildonDesktopWindow *window, gpointer user_data) { - const gchar *plugin_dir; - gchar *config_file; + HDDesktopPrivate *priv; GList *loaded_plugins = NULL; GList *selected_plugins = NULL; - HDDesktopPrivate *priv; + const gchar *plugin_dir; + const gchar *config_file; gint response; g_return_if_fail (user_data != NULL); @@ -244,9 +260,7 @@ loaded_plugins = gtk_container_get_children (window->container); - config_file = g_build_filename (priv->config_path, - hildon_desktop_window_get_config_file (window), - NULL); + config_file = hildon_desktop_window_get_config_file (window); plugin_dir = hildon_desktop_window_get_plugin_dir (window); @@ -261,9 +275,9 @@ window->container); } + g_list_foreach (selected_plugins, (GFunc) g_free , NULL); g_list_free (selected_plugins); g_list_free (loaded_plugins); - g_free (config_file); } static gboolean @@ -302,9 +316,75 @@ plugin_list, HILDON_DESKTOP_WINDOW (container)->container); + g_list_foreach (plugin_list, (GFunc) g_free , NULL); g_list_free (plugin_list); } +static void +hd_desktop_plugin_dir_changed (gchar *plugin_dir, HildonDesktopWindow *window) +{ + GDir *dir; + const gchar *filename; + GError *error = NULL; + GList *plugin_list = NULL, *remove_list, *iter; + + remove_list = gtk_container_get_children (window->container); + + dir = g_dir_open (plugin_dir, 0, &error); + + if (!dir) + { + g_warning ("Error reading plugin directory: %s", error->message); + g_error_free (error); + + return; + } + + /* Iterate through available plugins and check if the loaded plugins + are still there. */ + while ((filename = g_dir_read_name (dir))) + { + GList *found = NULL; + gchar *desktop_path = NULL; + + desktop_path = g_build_filename (plugin_dir, filename, NULL); + + found = g_list_find_custom (remove_list, + desktop_path, + hd_desktop_find_by_id); + + if (found) + { + plugin_list = g_list_append (plugin_list, desktop_path); + remove_list = g_list_remove (remove_list, found->data); + + g_debug ("Removing: %s", desktop_path); + } + } + + /* Destroy all loaded plugins which are not available anymore */ + for (iter = remove_list; iter; iter = g_list_next (iter)) + { + gtk_widget_destroy (iter->data); + } + + /* Save the current plugin list if needed */ + if (remove_list) + { + const gchar *config_file; + + g_debug ("Save needed"); + + config_file = hildon_desktop_window_get_config_file (window); + + hd_desktop_plugin_list_to_conf (plugin_list, config_file); + } + + g_list_foreach (plugin_list, (GFunc) g_free , NULL); + g_list_free (plugin_list); + g_list_free (remove_list); +} + static void hd_desktop_watch_file (gchar *config_file, gpointer callback, @@ -315,6 +395,38 @@ } static void +hd_desktop_watch_dir (gchar *plugin_dir, + gpointer callback, + gpointer user_data) +{ + hildon_return_t ret; + + g_return_if_fail (plugin_dir); + + ret = hildon_dnotify_set_cb ((hildon_dnotify_cb_f *) hd_desktop_plugin_dir_changed, + (gchar *) plugin_dir, + user_data); + + if (ret != HILDON_OK) + { + g_warning ("Error trying to watch plugin directory: %s", plugin_dir); + } +} + +static void +hd_desktop_dnotify_init () +{ + hildon_return_t ret; + + ret = hildon_dnotify_handler_init (); + + if (ret != HILDON_OK) + { + g_warning ("Error on dnotify init"); + } +} + +static void hd_desktop_load_containers (HDDesktop *desktop) { HDDesktopPrivate *priv; @@ -546,7 +658,7 @@ } hildon_desktop_window_set_config_file (HILDON_DESKTOP_WINDOW (container), - container_config_file); + container_config); hildon_desktop_window_set_plugin_dir (HILDON_DESKTOP_WINDOW (container), plugin_dir); @@ -570,6 +682,10 @@ hd_desktop_container_config_changed, container); + hd_desktop_watch_dir (plugin_dir, + hd_desktop_plugin_dir_changed, + HILDON_DESKTOP_WINDOW (container)); + g_hash_table_insert (priv->containers, container_config, container); plugin_list = hd_desktop_plugin_list_from_conf (container_config); @@ -583,6 +699,7 @@ g_free (type); g_free (container_config); g_free (container_config_file); + g_list_foreach (plugin_list, (GFunc) g_free , NULL); g_list_free (plugin_list); } @@ -639,6 +756,8 @@ desktop->priv->config_file = g_strdup (env_config_file); } + hd_desktop_dnotify_init (); + hd_desktop_watch_file (desktop->priv->config_file, hd_desktop_config_changed, desktop); Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-manager.c =================================================================== --- projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-manager.c 2006-12-01 14:04:53 UTC (rev 8536) +++ projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-manager.c 2006-12-01 14:36:53 UTC (rev 8537) @@ -93,7 +93,7 @@ } static gint -hd_plugin_manager_find_by_file (gconstpointer a, gconstpointer b) +hd_plugin_manager_find_by_id (gconstpointer a, gconstpointer b) { gint result = -1; gchar *id = NULL; @@ -204,7 +204,7 @@ { GList *found = g_list_find_custom (children, iter->data, - hd_plugin_manager_find_by_file); + hd_plugin_manager_find_by_id); if (!found) {
- Previous message: [maemo-commits] r8536 - projects/haf/tags/osso-af-startup
- Next message: [maemo-commits] r8538 - in projects/haf: tags trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]