[Xfce4-commits] <garcon:jannis/global-monitoring> Monitor .directory files / MenuDirectory elements properly.

Jannis Pohlmann noreply at xfce.org
Wed Mar 10 21:02:07 CET 2010


Updating branch refs/heads/jannis/global-monitoring
         to 66191c5fd08abcfd2e90a064b376f46d87e43943 (commit)
       from 1b5fe5f6bc10e057266e798b086d1611bda093af (commit)

commit 66191c5fd08abcfd2e90a064b376f46d87e43943
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue Mar 9 13:20:49 2010 +0100

    Monitor .directory files / MenuDirectory elements properly.
    
    We need to monitor all potential .directory files just in case the one
    currently being used is deleted and we need to fall back to another one,
    or in case one that comes after the currently used MenuDirectory element
    is created at runtime.

 garcon/garcon-menu.c |  129 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 97 insertions(+), 32 deletions(-)

diff --git a/garcon/garcon-menu.c b/garcon/garcon-menu.c
index 2e71e07..77ac959 100644
--- a/garcon/garcon-menu.c
+++ b/garcon/garcon-menu.c
@@ -1619,7 +1619,11 @@ static void
 garcon_menu_start_monitoring (GarconMenu *menu)
 {
   GFileMonitor *monitor;
+  GFile        *dir;
   GFile        *file;
+  GList        *directory_files;
+  GList        *directory_dirs;
+  GList        *dp;
   GList        *lp;
 
   g_return_if_fail (GARCON_IS_MENU (menu));
@@ -1627,6 +1631,7 @@ garcon_menu_start_monitoring (GarconMenu *menu)
   /* Let only the root menu monitor .menu files and merge directories */
   if (menu->priv->parent == NULL)
     {
+      /* Monitor the root .menu file */
       monitor = g_file_monitor (menu->priv->file, G_FILE_MONITOR_NONE, NULL, NULL);
       if (monitor != NULL)
         {
@@ -1635,6 +1640,7 @@ garcon_menu_start_monitoring (GarconMenu *menu)
                                     G_CALLBACK (garcon_menu_file_changed), menu);
         }
 
+      /* Monitor all .menu files that were merged into the root menu */
       for (lp = menu->priv->merge_files; lp != NULL; lp = lp->next)
         {
           monitor = g_file_monitor (lp->data, G_FILE_MONITOR_NONE, NULL, NULL);
@@ -1646,6 +1652,8 @@ garcon_menu_start_monitoring (GarconMenu *menu)
             }
         }
 
+      /* Monitor all merge directories from which .menu files were merged into
+       * the root menu */
       for (lp = menu->priv->merge_dirs; lp != NULL; lp = lp->next)
         {
           monitor = g_file_monitor (lp->data, G_FILE_MONITOR_NONE, NULL, NULL);
@@ -1658,23 +1666,34 @@ garcon_menu_start_monitoring (GarconMenu *menu)
         }
     }
 
-  /* Monitor the .directory file */
-  if (menu->priv->directory != NULL)
-    {
-      file = garcon_menu_directory_get_file (menu->priv->directory);
+  /* Determine all .directory files we are interested in for this menu */
+  directory_files = garcon_menu_get_directories (menu);
 
-      monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, NULL);
-      if (monitor != NULL)
-        {
-          menu->priv->monitors = g_list_prepend (menu->priv->monitors, monitor);
-          g_signal_connect_swapped (monitor, "changed",
-                                    G_CALLBACK (garcon_menu_directory_file_changed), menu);
-        }
+  /* Determine all .directory lookup dirs for this menu */
+  directory_dirs = garcon_menu_get_directory_dirs (menu);
 
-      g_object_unref (file);
-    }
+  /* Monitor potential .directory files */
+  for (lp = directory_files; lp != NULL; lp = lp->next)
+    for (dp = directory_dirs; dp != NULL; dp = dp->next)
+      {
+        dir = _garcon_file_new_relative_to_file (dp->data, menu->priv->file);
+        file = _garcon_file_new_relative_to_file (lp->data, dir);
+
+        monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, NULL);
+        if (monitor != NULL)
+          {
+            menu->priv->monitors = g_list_prepend (menu->priv->monitors, monitor);
+            g_signal_connect_swapped (monitor, "changed",
+                                      G_CALLBACK (garcon_menu_directory_file_changed), menu);
+          }
 
-  /* TODO monitor desktop directories */
+        g_object_unref (file);
+        g_object_unref (dir);
+      }
+
+  /* Free lists */
+  g_list_free (directory_dirs);
+  g_list_free (directory_files);
 
   /* Recurse into child menus */
   for (lp = menu->priv->submenus; lp != NULL; lp = lp->next)
@@ -1735,30 +1754,76 @@ garcon_menu_directory_file_changed (GarconMenu       *menu,
                                     GFileMonitorEvent event_type,
                                     GFileMonitor     *monitor)
 {
-  g_return_if_fail (GARCON_IS_MENU (menu));
-  g_return_if_fail (menu->priv->parent == NULL);
+  GFile *directory_file;
 
-  g_debug ("directory file %s changed", g_file_get_path (file));
+  g_return_if_fail (GARCON_IS_MENU (menu));
 
-  if (event_type == G_FILE_MONITOR_EVENT_CHANGED)
+  if (event_type == G_FILE_MONITOR_EVENT_CHANGED 
+      || event_type == G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED)
     {
-      /* TODO reload the menu directory (we need a new method
-       * garcon_menu_directory_load() for this) and emit a 
-       * GarconMenu::directory-changed signal */
+      g_debug ("directory file %s changed", g_file_get_path (file));
+
+      if (menu->priv->directory != NULL)
+        {
+          directory_file = garcon_menu_directory_get_file (menu->priv->directory);
+
+          if (g_file_equal (directory_file, file))
+            {
+              g_debug ("  reload the directory file");
+
+#if 0
+              if (garcon_menu_directory_load (menu->priv->directory, NULL, &error))
+                {
+                  /* TODO reload the menu directory (we need a new method
+                   * garcon_menu_directory_load() for this) and emit a 
+                   * GarconMenu::directory-changed signal */
+                }
+              else
+                {
+                  g_signal_emit (menu, menu_signals[DIRECTORY_CHANGED], 0, 
+                                 menu->priv->directory, NULL);
+
+                  g_object_unref (menu->priv->directory);
+                  menu->priv->directory = NULL;
+                }
+#endif
+            }
+
+          g_object_unref (directory_file);
+        }
     }
   else if (event_type == G_FILE_MONITOR_EVENT_DELETED)
     {
-      /* TODO destroy the menu directory and emit a 
-       * GarconMenu::directory-changed signal with the
-       * GarconMenuDirectory set to NULL */
-
-      /* TODO check if there is another MenuDirectory
-       * element that we can use and load instead. If this is
-       * the case, change the file of the current menu directory,
-       * reload it and emit a directory-changed signal.
-       * otherwise destroy the menu directory and emit
-       * a directory-changed signal with the GarconMenuDirectory
-       * parameter set to NULL */
+      g_debug ("directory file %s deleted", g_file_get_path (file));
+
+      if (menu->priv->directory != NULL)
+        {
+          directory_file = garcon_menu_directory_get_file (menu->priv->directory);
+
+          if (g_file_equal (directory_file, file))
+            {
+              g_debug ("  current .directory file deleted");
+
+              /* TODO check if there is another MenuDirectory
+               * element that we can use and load instead. If this is
+               * the case, change the file of the current menu directory,
+               * reload it and emit a directory-changed signal.
+               * otherwise destroy the menu directory and emit
+               * a directory-changed signal with the GarconMenuDirectory
+               * parameter set to NULL */
+            }
+
+          g_object_unref (directory_file);
+        }
+    }
+  else if (event_type == G_FILE_MONITOR_EVENT_CREATED)
+    {
+      g_debug ("directory file %s created", g_file_get_path (file));
+
+      /* TODO check if the file corresponds a MenuDirectory element that comes
+       * after the one currently used by the Menu. If this is the case,
+       * change the file of the GarconMenuElement, reload it
+       * and emit a 'directory-changed' signal */
     }
 }
 



More information about the Xfce4-commits mailing list