[Xfce4-commits] <xfdesktop:jannis/port-to-garcon> Rudimentary port to Garcon. No monitoring yet.

Jannis Pohlmann noreply at xfce.org
Thu Jan 7 23:42:03 CET 2010


Updating branch refs/heads/jannis/port-to-garcon
         to 377879f03c4a4526dfe42c5c47e0f2ce321a1980 (commit)
       from cc1c282b6d9789b09a523ebf408da8fcdc52d74d (commit)

commit 377879f03c4a4526dfe42c5c47e0f2ce321a1980
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Thu Jan 7 23:39:11 2010 +0100

    Rudimentary port to Garcon. No monitoring yet.

 configure.ac.in             |   36 +------
 modules/menu/Makefile.am    |    8 +-
 modules/menu/desktop-menu.c |  242 ++++++++-----------------------------------
 3 files changed, 53 insertions(+), 233 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index c6b7a03..24122be 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -18,7 +18,7 @@ m4_define([gtk_minimum_version], [2.14.0])
 m4_define([libxfce4util_minimum_version], [4.6.0])
 m4_define([libxfce4ui_minimum_version], [4.7.0])
 m4_define([xfce_minimum_version], [4.6.0])
-m4_define([xfce4menu_minimum_version], [4.6.0])
+m4_define([garcon_minimum_version], [0.0.1])
 m4_define([exo_minimum_version], [0.3.100])
 m4_define([thunar_minimum_version], [1.0.0])
 m4_define([dbus_minimum_version], [0.34])
@@ -152,12 +152,12 @@ if test "x$ac_cv_enable_desktop_menu" = "xno"; then
     build_desktop_menu="no"
 else
     dnl time for more abuse!
-    XDT_CHECK_PACKAGE([LIBXFCE4MENU], [libxfce4menu-0.1],
-                      [xfce4menu_minimum_version], [build_desktop_menu="yes"],
+    XDT_CHECK_PACKAGE([GARCON], [garcon-1],
+                      [garcon_minimum_version], [build_desktop_menu="yes"],
                       [
-echo "*** Optional package libxfce4menu-0.1 was either not found on your system"
+echo "*** Optional package garcon-1 was either not found on your system"
 echo "*** or is too old.  Please install or upgrade to at least version"
-echo "*** xfce4menu_minimum_version, or adjust the PKG_CONFIG_PATH environment variable"
+echo "*** garcon_minimum_version, or adjust the PKG_CONFIG_PATH environment variable"
 echo "*** if you installed the new version of the package in a nonstandard"
 echo "*** prefix.  Desktop menu will be disabled."
 build_desktop_menu="no"
@@ -169,32 +169,6 @@ build_desktop_menu="no"
 fi
 AM_CONDITIONAL([BUILD_DESKTOP_MENU], [test "x$build_desktop_menu" = "xyes"])
 
-dnl time for more abuse.  if we don't yet have thunar-vfs, we still might want
-dnl it for desktop menu directory monitoring.
-AC_ARG_ENABLE([desktop-menu-dir-monitor],
-              [AC_HELP_STRING([--disable-desktop-menu-dir-monitor],
-                              [Don't use thunar-vfs to monitor menu files to automatically update the desktop menu when needed. (default=enabled)])],
-              [want_thunar_vfs=$enableval],
-              [want_thunar_vfs=yes])
-if test "x$want_thunar_vfs" = "xyes" -a "x$build_desktop_menu" = "xyes"; then
-    if test "x$already_have_thunar_vfs" != "xyes"; then
-        XDT_CHECK_PACKAGE([THUNAR_VFS], [thunar-vfs-1],
-                          [thunar_minimum_version], [have_thunar_vfs=yes], [
-echo "*** Optional package thunar-vfs-1 was either not found on your system"
-echo "*** or is too old.  Please install or upgrade to at least version"
-echo "*** thunar_minimum_version, or adjust the PKG_CONFIG_PATH environment variable"
-echo "*** if you installed the new version of the package in a nonstandard"
-echo "*** prefix.  Desktop menu directory monitoring will be disabled."
-])
-    fi
-
-    if test "x$have_thunar_vfs" = "xyes" \
-       -o "x$already_have_thunar_vfs" = "xyes"
-    then
-        AC_DEFINE([HAVE_THUNAR_VFS], [1], [Define if thunar-vfs is present.])
-    fi
-fi
-
 AC_ARG_ENABLE([panel-plugin],
         [AC_HELP_STRING([--disable-panel-plugin],
                 [Do not build the panel plugin (default=enabled)])],
diff --git a/modules/menu/Makefile.am b/modules/menu/Makefile.am
index b8db5d5..2610b0a 100644
--- a/modules/menu/Makefile.am
+++ b/modules/menu/Makefile.am
@@ -15,10 +15,9 @@ xfce4_desktop_menu_la_CFLAGS = \
 	-I$(top_srcdir)/common \
 	$(GMODULE_CFLAGS) \
 	$(GTHREAD_CFLAGS) \
-	$(LIBXFCE4MENU_CFLAGS) \
+	$(GARCON_CFLAGS) \
 	$(LIBX11_CFLAGS) \
 	$(LIBXFCE4UI_CFLAGS) \
-	$(THUNAR_VFS_CFLAGS) \
 	-DSYSCONFDIR=\"$(sysconfdir)\" \
 	-DDATADIR=\"$(datadir)\" \
 	-DBINDIR=\"$(bindir)\"
@@ -40,8 +39,7 @@ xfce4_desktop_menu_la_LIBADD = \
 	$(top_builddir)/common/libxfdesktop-menu-utils.la \
 	$(GMODULE_LIBS) \
 	$(GTHREAD_LIBS) \
-	$(LIBXFCE4MENU_LIBS) \
+	$(GARCON_LIBS) \
 	$(LIBX11_LDFLAGS) \
 	$(LIBX11_LIBS) \
-	$(LIBXFCE4UI_LIBS) \
-	$(THUNAR_VFS_LIBS)
+	$(LIBXFCE4UI_LIBS)
diff --git a/modules/menu/desktop-menu.c b/modules/menu/desktop-menu.c
index 6e75648..8c4e017 100644
--- a/modules/menu/desktop-menu.c
+++ b/modules/menu/desktop-menu.c
@@ -4,6 +4,7 @@
  *                     2003 Biju Chacko (botsie at users.sourceforge.net)
  *                     2004 Danny Milosavljevic <danny.milo at gmx.net>
  *                2004-2008 Brian Tarricone <bjt23 at cornell.edu>
+ *                     2009 Jannis Pohlmann <jannis at xfce.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -59,20 +60,17 @@
 #include <gmodule.h>
 #include <glib.h>
 
+#include <garcon/garcon.h>
+
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
-#include <libxfce4menu/libxfce4menu.h>
-
-#ifdef HAVE_THUNAR_VFS
-#include <thunar-vfs/thunar-vfs.h>
-#endif
 
 #include "desktop-menu-utils.h"
 #include "xfdesktop-app-menu-item.h"
 
 typedef struct
 {
-	XfceMenu *xfce_menu;
+    GarconMenu *garcon_menu;
 
     gboolean cache_menu_items;
     GList *menu_item_cache;
@@ -82,10 +80,6 @@ typedef struct
     gboolean use_menu_icons;  /* show menu icons? */
 	
     gint idle_id;  /* source id for idled generation */
-    
-#ifdef HAVE_THUNAR_VFS
-    GList *monitors;
-#endif
 } XfceDesktopMenu;
 
 
@@ -115,7 +109,7 @@ static GtkIconTheme *_deskmenu_icon_theme = NULL;
 static gboolean _generate_menu_idled(gpointer data);
 static gboolean _generate_menu(XfceDesktopMenu *desktop_menu);
 static void desktop_menu_add_items(XfceDesktopMenu *desktop_menu,
-                                   XfceMenu *xfce_menu,
+                                   GarconMenu *garcon_menu,
                                    GtkWidget *menu,
                                    GList **menu_items_return);
 
@@ -135,112 +129,6 @@ itheme_changed_cb(GtkIconTheme *itheme, gpointer user_data)
         desktop_menu->idle_id = g_idle_add(_generate_menu_idled, desktop_menu);
 }
 
-#ifdef HAVE_THUNAR_VFS
-
-static void
-desktop_menu_something_changed(ThunarVfsMonitor *monitor,
-                               ThunarVfsMonitorHandle *handle,
-                               ThunarVfsMonitorEvent event,
-                               ThunarVfsPath *handle_path,
-                               ThunarVfsPath *event_path,
-                               gpointer user_data)
-{
-    XfceDesktopMenu *desktop_menu = user_data;
-    const gchar *filename;
-    XfceMenuItemCache *cache = xfce_menu_item_cache_get_default();
-    
-#ifdef DEBUG
-    {
-        gchar buf[1024];
-        thunar_vfs_path_to_string(event_path, buf, sizeof(buf), NULL);
-        TRACE("entering (%d,%s)", event, buf);
-    }
-#endif
-
-    /* bug #4979: only trigger on files we care about */
-    filename = thunar_vfs_path_get_name(event_path);
-    if(!g_str_has_suffix(filename, ".desktop")
-       && !g_str_has_suffix(filename, ".menu")
-       && !g_str_has_suffix(filename, ".directory"))
-    {
-        DBG("menu: ignoring change on \"%s\"", filename);
-        return;
-    }
-    
-    xfce_menu_item_cache_invalidate(cache);
-    if(!desktop_menu->idle_id)
-        desktop_menu->idle_id = g_idle_add(_generate_menu_idled, desktop_menu);
-}
-
-#if 0
-static gpointer
-desktop_menu_xfce_menu_monitor_file(XfceMenu *menu,
-                                    const gchar *filename,
-                                    gpointer user_data)
-{
-    XfceDesktopMenu *desktop_menu = user_data;
-    ThunarVfsPath *path;
-    ThunarVfsMonitor *monitor = thunar_vfs_monitor_get_default();
-    ThunarVfsMonitorHandle *mhandle = NULL;
-    
-    path = thunar_vfs_path_new(filename, NULL);
-    if(path) {
-        mhandle = thunar_vfs_monitor_add_file(monitor, path,
-                                              desktop_menu_something_changed,
-                                              desktop_menu);
-        thunar_vfs_path_unref(path);
-    }
-    
-    g_object_unref(G_OBJECT(monitor));
-    
-    TRACE("exiting (%s), returning 0x%p\n", filename, mhandle);
-    
-    return mhandle;
-}
-#endif
-
-static gpointer
-desktop_menu_xfce_menu_monitor_directory(XfceMenu *menu,
-                                         const gchar *filename,
-                                         gpointer user_data)
-{
-    XfceDesktopMenu *desktop_menu = user_data;
-    ThunarVfsPath *path;
-    ThunarVfsMonitorHandle *mhandle = NULL;
-    
-    if(!g_file_test(filename, G_FILE_TEST_IS_DIR))
-        return NULL;
-    
-    path = thunar_vfs_path_new(filename, NULL);
-    if(path) {
-        ThunarVfsMonitor *monitor = thunar_vfs_monitor_get_default();
-        mhandle = thunar_vfs_monitor_add_directory(monitor, path,
-                                                   desktop_menu_something_changed,
-                                                   desktop_menu);
-        thunar_vfs_path_unref(path);
-        g_object_unref(G_OBJECT(monitor));
-    }
-    
-    TRACE("exiting (%s), returning 0x%p", filename, mhandle);
-    
-    return mhandle;
-}
-
-static void
-desktop_menu_xfce_menu_remove_monitor(XfceMenu *menu,
-                                      gpointer monitor_handle)
-{
-    ThunarVfsMonitor *monitor = thunar_vfs_monitor_get_default();
-    ThunarVfsMonitorHandle *mhandle = monitor_handle;
-    
-    TRACE("entering (0x%p)", mhandle); 
-    
-    thunar_vfs_monitor_remove(monitor, mhandle);
-    g_object_unref(G_OBJECT(monitor));
-}
-
-#endif
-
 /*
  * this is a bit of a kludge.  in order to support the cache and be a bit
  * faster, we either want to build a GtkMenu, or we want to just build
@@ -249,49 +137,40 @@ desktop_menu_xfce_menu_remove_monitor(XfceMenu *menu,
  */
 static void
 desktop_menu_add_items(XfceDesktopMenu *desktop_menu,
-                       XfceMenu *xfce_menu,
+                       GarconMenu *garcon_menu,
                        GtkWidget *menu,
                        GList **menu_items_return)
 {
-    GSList *items, *l;
+    GList *items, *l;
     GtkWidget *submenu, *mi, *img;
-    XfceMenu *xfce_submenu;
-    XfceMenuDirectory *xfce_directory;
-    XfceMenuItem *xfce_item;
+    GarconMenu *garcon_submenu;
+    GarconMenuDirectory *garcon_directory;
+    GarconMenuItem *garcon_item;
     const gchar *name, *icon_name;
 
     g_return_if_fail((menu && !menu_items_return)
                      || (!menu && menu_items_return));
     
-    if(xfce_menu_has_layout(xfce_menu))
-        items = xfce_menu_get_layout_elements(xfce_menu);
-    else {
-        items = xfce_menu_get_menus(xfce_menu);
-        items = g_slist_concat(items, xfce_menu_get_items(xfce_menu));
-    }
+    items = garcon_menu_get_elements(garcon_menu);
     for(l = items; l; l = l->next) {
-        if(XFCE_IS_MENU(l->data)) {
+        if(!garcon_menu_element_get_visible(l->data))
+            continue;
+
+        if(GARCON_IS_MENU(l->data)) {
             GList *tmpl;
-            xfce_submenu = l->data;
-            xfce_directory = xfce_menu_get_directory(xfce_submenu);
+            garcon_submenu = l->data;
+            garcon_directory = garcon_menu_get_directory(garcon_submenu);
             icon_name = NULL;
             
-            if(xfce_directory
-               && (xfce_menu_directory_get_no_display(xfce_directory)
-               || !xfce_menu_directory_show_in_environment(xfce_directory)))
-            {
-                continue;
-            }
-            
             submenu = gtk_menu_new();
             gtk_widget_show(submenu);
             
-            if(xfce_directory) {
+            if(garcon_directory) {
                 if(desktop_menu->use_menu_icons)
-                    icon_name = xfce_menu_directory_get_icon(xfce_directory);
+                    icon_name = garcon_menu_directory_get_icon(garcon_directory);
             }
             
-            name = xfce_menu_element_get_name(XFCE_MENU_ELEMENT(xfce_submenu));
+            name = garcon_menu_element_get_name(GARCON_MENU_ELEMENT(garcon_submenu));
 
             mi = gtk_image_menu_item_new_with_label(name);
             if(icon_name) {
@@ -308,7 +187,7 @@ desktop_menu_add_items(XfceDesktopMenu *desktop_menu,
             else
                 *menu_items_return = g_list_prepend(*menu_items_return, mi);
             
-            desktop_menu_add_items(desktop_menu, xfce_submenu,
+            desktop_menu_add_items(desktop_menu, garcon_submenu,
                                    submenu, NULL);
             
             /* we have to check emptiness down here instead of at the top of the
@@ -317,7 +196,7 @@ desktop_menu_add_items(XfceDesktopMenu *desktop_menu,
                 gtk_widget_destroy(mi);
             else
                 g_list_free(tmpl);
-        } else if(XFCE_IS_MENU_SEPARATOR(l->data)) {
+        } else if(GARCON_IS_MENU_SEPARATOR(l->data)) {
             mi = gtk_separator_menu_item_new();
             gtk_widget_show(mi);
 
@@ -325,22 +204,16 @@ desktop_menu_add_items(XfceDesktopMenu *desktop_menu,
                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
             else
                 *menu_items_return = g_list_prepend(*menu_items_return, mi);
-        } else if(XFCE_IS_MENU_ITEM(l->data)) {
-            xfce_item = l->data;
+        } else if(GARCON_IS_MENU_ITEM(l->data)) {
+            garcon_item = l->data;
             
-            if(xfce_menu_item_get_no_display(xfce_item)
-               || !xfce_menu_item_show_in_environment(xfce_item))
-            {
-                continue;
-            }
-            
-            mi = xfdesktop_app_menu_item_new_full(xfce_menu_element_get_name(XFCE_MENU_ELEMENT(xfce_item)),
-                                                  xfce_menu_item_get_command(xfce_item),
+            mi = xfdesktop_app_menu_item_new_full(garcon_menu_element_get_name(GARCON_MENU_ELEMENT(garcon_item)),
+                                                  garcon_menu_item_get_command(garcon_item),
                                                   desktop_menu->use_menu_icons
-                                                    ? xfce_menu_item_get_icon_name(xfce_item)
+                                                    ? garcon_menu_item_get_icon_name(garcon_item)
                                                     : NULL,
-                                                  xfce_menu_item_requires_terminal(xfce_item),
-                                                  xfce_menu_item_supports_startup_notification(xfce_item));
+                                                  garcon_menu_item_requires_terminal(garcon_item),
+                                                  garcon_menu_item_supports_startup_notification(garcon_item));
             gtk_widget_show(mi);
 
             if(menu)
@@ -349,7 +222,7 @@ desktop_menu_add_items(XfceDesktopMenu *desktop_menu,
                 *menu_items_return = g_list_prepend(*menu_items_return, mi);
         }
     }
-    g_slist_free(items);
+    g_list_free(items);
 
     if(menu_items_return)
         *menu_items_return = g_list_reverse(*menu_items_return);
@@ -376,22 +249,18 @@ _generate_menu(XfceDesktopMenu *desktop_menu)
     
     DBG("menu file name is %s", desktop_menu->filename);
 
-#if 0
-    /* this is kinda lame, but xfcemenu currently caches too much */
-    xfce_menu_shutdown();
-    xfce_menu_init("XFCE");
-#endif
-    
-    desktop_menu->xfce_menu = xfce_menu_new(desktop_menu->filename, &error);
-    if(!desktop_menu->xfce_menu) {
-        g_critical("Unable to create XfceMenu from file '%s': %s",
+    desktop_menu->garcon_menu = garcon_menu_new_for_path(desktop_menu->filename);
+
+    if(!garcon_menu_load (desktop_menu->garcon_menu, NULL, &error)) {
+        g_critical("Unable to create GarconMenu from file '%s': %s",
                    desktop_menu->filename, error->message);
         g_error_free(error);
+        _xfce_desktop_menu_free_menudata(desktop_menu);
         return FALSE;
     }
 
     if(desktop_menu->cache_menu_items) {
-        desktop_menu_add_items(desktop_menu, desktop_menu->xfce_menu,
+        desktop_menu_add_items(desktop_menu, desktop_menu->garcon_menu,
                                NULL, &desktop_menu->menu_item_cache);
     }
 
@@ -408,12 +277,12 @@ _xfce_desktop_menu_free_menudata(XfceDesktopMenu *desktop_menu)
         desktop_menu->menu_item_cache = NULL;
     }
 
-    if(desktop_menu->xfce_menu) {
-        g_object_unref(G_OBJECT(desktop_menu->xfce_menu));
-        desktop_menu->xfce_menu = NULL;
+    if(desktop_menu->garcon_menu) {
+        g_object_unref(G_OBJECT(desktop_menu->garcon_menu));
+        desktop_menu->garcon_menu = NULL;
     }
     
-    desktop_menu->xfce_menu = NULL;
+    desktop_menu->garcon_menu = NULL;
 }
 
 static gboolean
@@ -435,7 +304,7 @@ desktop_menu_recache(gpointer data,
 {
     XfceDesktopMenu *desktop_menu = data;
     if(!desktop_menu->menu_item_cache) {
-        desktop_menu_add_items(desktop_menu, desktop_menu->xfce_menu,
+        desktop_menu_add_items(desktop_menu, desktop_menu->garcon_menu,
                                NULL, &desktop_menu->menu_item_cache);
     }
 }
@@ -444,13 +313,6 @@ G_MODULE_EXPORT XfceDesktopMenu *
 xfce_desktop_menu_new_impl(const gchar *menu_file,
                            gboolean deferred)
 {
-#ifdef HAVE_THUNAR_VFS
-    static XfceMenuMonitorVTable monitor_vtable = {
-        NULL, /*desktop_menu_xfce_menu_monitor_file,*/
-        desktop_menu_xfce_menu_monitor_directory,
-        desktop_menu_xfce_menu_remove_monitor
-    };
-#endif
     XfceDesktopMenu *desktop_menu = g_new0(XfceDesktopMenu, 1);
     
     desktop_menu->use_menu_icons = TRUE;
@@ -461,18 +323,10 @@ xfce_desktop_menu_new_impl(const gchar *menu_file,
     else
         desktop_menu->filename = xfce_desktop_get_menufile();
     
-#ifdef HAVE_THUNAR_VFS
-    thunar_vfs_init();
-    xfce_menu_monitor_set_vtable(&monitor_vtable, desktop_menu);
-#endif
-    
     if(deferred)
         desktop_menu->idle_id = g_idle_add(_generate_menu_idled, desktop_menu);
     else {
         if(!_generate_menu(desktop_menu)) {
-#ifdef HAVE_THUNAR_VFS
-            xfce_menu_monitor_set_vtable(NULL, NULL);
-#endif
             g_free(desktop_menu);
             desktop_menu = NULL;
         }
@@ -490,13 +344,13 @@ xfce_desktop_menu_populate_menu_impl(XfceDesktopMenu *desktop_menu,
 {
     g_return_if_fail(desktop_menu && menu);
     
-    if(!desktop_menu->xfce_menu) {
+    if(!desktop_menu->garcon_menu) {
         if(desktop_menu->idle_id) {
             g_source_remove(desktop_menu->idle_id);
             desktop_menu->idle_id = 0;
         }
         _generate_menu(desktop_menu);
-        if(!desktop_menu->xfce_menu)
+        if(!desktop_menu->garcon_menu)
             return;
     }
 
@@ -509,7 +363,7 @@ xfce_desktop_menu_populate_menu_impl(XfceDesktopMenu *desktop_menu,
         g_object_weak_ref(G_OBJECT(menu), desktop_menu_recache,
                           desktop_menu);
     } else {
-        desktop_menu_add_items(desktop_menu, desktop_menu->xfce_menu,
+        desktop_menu_add_items(desktop_menu, desktop_menu->garcon_menu,
                                GTK_WIDGET(menu), NULL);
     }
 }
@@ -525,7 +379,7 @@ xfce_desktop_menu_get_widget_impl(XfceDesktopMenu *desktop_menu)
     
     xfce_desktop_menu_populate_menu_impl(desktop_menu, menu);
     
-    if(!desktop_menu->xfce_menu) {
+    if(!desktop_menu->garcon_menu) {
         gtk_widget_destroy(menu);
         return NULL;
     }
@@ -596,10 +450,6 @@ xfce_desktop_menu_destroy_impl(XfceDesktopMenu *desktop_menu)
     g_return_if_fail(desktop_menu != NULL);
     TRACE("dummy");
     
-#ifdef HAVE_THUNAR_VFS
-    xfce_menu_monitor_set_vtable(NULL, NULL);
-#endif
-    
     if(desktop_menu->idle_id) {
         g_source_remove(desktop_menu->idle_id);
         desktop_menu->idle_id = 0;
@@ -622,8 +472,6 @@ g_module_check_init(GModule *module)
 	/* libxfcemenu registers gobject types, so we can't be removed */
 	g_module_make_resident(module);
 	
-	xfce_menu_init("XFCE");
-	
     gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &w, &h);
     _xfce_desktop_menu_icon_size = w;
     



More information about the Xfce4-commits mailing list