Author: jannis Date: 2007-01-16 09:52:42 +0000 (Tue, 16 Jan 2007) New Revision: 24501
Added: libfrap/trunk/libfrap/menu/frap-menu-environment.c libfrap/trunk/libfrap/menu/frap-menu-environment.h Modified: libfrap/trunk/libfrap/menu/ChangeLog libfrap/trunk/libfrap/menu/Makefile.am libfrap/trunk/libfrap/menu/frap-menu-item-cache.c libfrap/trunk/libfrap/menu/frap-menu-item.c libfrap/trunk/libfrap/menu/frap-menu.c libfrap/trunk/libfrap/menu/frap-menu.h libfrap/trunk/libfrap/menu/libfrapmenu.h libfrap/trunk/libfrap/menu/tests/test-and-rules.c libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c libfrap/trunk/libfrap/menu/tests/test-menu-item.c libfrap/trunk/libfrap/menu/tests/test-not-rules.c libfrap/trunk/libfrap/menu/tests/test-or-rules.c libfrap/trunk/libfrap/menu/tests/test-root-menu.c Log: * frap-menu-environment.{c,h}, libfrapmenu.h, Makefile.am: Add functions for defining the name of the desktop environment in order to ignore menu items belonging to other environments. * frap-menu.{c,h}: Add desktop environment name parameter to frap_menu_init(). * tests/*.c: Sync with new API. * frap-menu-item.c: Add frap_menu_item_rc_matches_environment() to check whether a desktop file should be displayed in the current environment or not. Call this method in frap_menu_new() before anything else is parsed. Modified: libfrap/trunk/libfrap/menu/ChangeLog =================================================================== --- libfrap/trunk/libfrap/menu/ChangeLog 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/ChangeLog 2007-01-16 09:52:42 UTC (rev 24501) @@ -1,3 +1,16 @@ +2006-01-16 Jannis Pohlmann <[EMAIL PROTECTED]> + + * frap-menu-environment.{c,h}, libfrapmenu.h, Makefile.am: Add + functions for defining the name of the desktop environment in + order to ignore menu items belonging to other environments. + * frap-menu.{c,h}: Add desktop environment name parameter to + frap_menu_init(). + * tests/*.c: Sync with new API. + * frap-menu-item.c: Add frap_menu_item_rc_matches_environment() to check + whether a desktop file should be displayed in the current environment + or not. Call this method in frap_menu_new() before anything else is + parsed. + 2007-01-15 Jannis Pohlmann <[EMAIL PROTECTED]> * frap-menu-item.c: Free TryExec argument list. Remove old code. Don't Modified: libfrap/trunk/libfrap/menu/Makefile.am =================================================================== --- libfrap/trunk/libfrap/menu/Makefile.am 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/Makefile.am 2007-01-16 09:52:42 UTC (rev 24501) @@ -23,6 +23,7 @@ frap-menu-item-pool.c \ frap-menu-item-cache.c \ frap-menu-move.c \ + frap-menu-environment.c \ frap-menu-item.c libfrapmenu_la_DEPENDENCIES = \ @@ -40,6 +41,7 @@ frap-menu-item-pool.h \ frap-menu-item-cache.h \ frap-menu-move.h \ + frap-menu-environment.h \ frap-menu-item.h libfrapmenu_la_CFLAGS = \ Added: libfrap/trunk/libfrap/menu/frap-menu-environment.c =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu-environment.c (rev 0) +++ libfrap/trunk/libfrap/menu/frap-menu-environment.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -0,0 +1,51 @@ +/* $Id$ */ +/* vi:set expandtab sw=2 sts=2: */ +/*- + * Copyright (c) 2007 Jannis Pohlmann <[EMAIL PROTECTED]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + + + +#include <frap-menu-environment.h> + + + +static gchar *environment = NULL; + + + +void +frap_menu_set_environment (const gchar *env) +{ + if (G_LIKELY (environment != NULL)) + g_free (environment); + + environment = g_strdup (env); +} + + + +G_CONST_RETURN gchar* +frap_menu_get_environment (void) +{ + return environment; +} Added: libfrap/trunk/libfrap/menu/frap-menu-environment.h =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu-environment.h (rev 0) +++ libfrap/trunk/libfrap/menu/frap-menu-environment.h 2007-01-16 09:52:42 UTC (rev 24501) @@ -0,0 +1,34 @@ +/* $Id$ */ +/* vi:set expandtab sw=2 sts=2: */ +/*- + * Copyright (c) 2007 Jannis Pohlmann <[EMAIL PROTECTED]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#if !defined(LIBFRAPMENU_INSIDE_LIBFRAPMENU_H) && !defined(LIBFRAPMENU_COMPILATION) +#error "Only <libfrapmenu/libfrapmenu.h> can be included directly. This file may disappear or change contents." +#endif + +#ifndef __FRAP_MENU_ENVIRONMENT_H__ +#define __FRAP_MENU_ENVIRONMENT_H__ + +#include <glib.h> + +void frap_menu_set_environment (const gchar *env); +G_CONST_RETURN gchar *frap_menu_get_environment (void); + +#endif /* !__FRAP_MENU_ENVIRONMENT_H__ */ Modified: libfrap/trunk/libfrap/menu/frap-menu-item-cache.c =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu-item-cache.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/frap-menu-item-cache.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -254,6 +254,8 @@ /* Update desktop id, if necessary */ frap_menu_item_set_desktop_id (item, desktop_id); + /* TODO Check OnlyShowIn / NotShowIn values */ + /* Store updated item in cache */ frap_menu_item_cache_store_item (cache, filename, item); @@ -271,6 +273,8 @@ /* Update desktop id */ frap_menu_item_set_desktop_id (item, desktop_id); + /* TODO Check OnlyShowIn / NotShowIn */ + /* Store updated item in the cache */ frap_menu_item_cache_store_item (cache, filename, item); Modified: libfrap/trunk/libfrap/menu/frap-menu-item.c =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu-item.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/frap-menu-item.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -26,6 +26,7 @@ #include <libxfce4util/libxfce4util.h> +#include <frap-menu-environment.h> #include <frap-menu-item.h> @@ -50,21 +51,23 @@ -static void frap_menu_item_class_init (FrapMenuItemClass *klass); -static void frap_menu_item_init (FrapMenuItem *item); -static void frap_menu_item_finalize (GObject *object); -static void frap_menu_item_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void frap_menu_item_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void frap_menu_item_load (FrapMenuItem *item); +static void frap_menu_item_class_init (FrapMenuItemClass *klass); +static void frap_menu_item_init (FrapMenuItem *item); +static void frap_menu_item_finalize (GObject *object); +static void frap_menu_item_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void frap_menu_item_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void frap_menu_item_load (FrapMenuItem *item); +static gboolean frap_menu_item_rc_matches_environment (XfceRc *rc); + struct _FrapMenuItemClass { GObjectClass __parent__; @@ -408,6 +411,7 @@ const gchar *exec; const gchar *icon; const gchar *tryexec; + const gchar *env; gchar *command; gchar **mt; gchar **str_list; @@ -416,6 +420,7 @@ gboolean terminal; gboolean hidden; gboolean startup_notify; + gboolean show; g_return_val_if_fail (g_path_is_absolute (filename), NULL); g_return_val_if_fail (g_file_test (filename, G_FILE_TEST_EXISTS), NULL); @@ -425,14 +430,20 @@ if (G_UNLIKELY (rc == NULL)) return; + /* Make sure we only parse desktop files which should appear in the current + * desktop environment */ + if (!frap_menu_item_rc_matches_environment (rc)) + { + xfce_rc_close (rc); + return NULL; + } + /* Parse the file */ xfce_rc_set_group (rc, "Desktop Entry"); name = xfce_rc_read_entry (rc, "Name", NULL); exec = xfce_rc_read_entry (rc, "Exec", NULL); icon = xfce_rc_read_entry (rc, "Icon", NULL); - /* TODO Parse OnlyShowIn etc. */ - /* Check if TryExec exists */ tryexec = xfce_rc_read_entry_untranslated (rc, "TryExec", NULL); tryexec = (tryexec != NULL) ? tryexec : exec; @@ -507,6 +518,61 @@ +gboolean +frap_menu_item_rc_matches_environment (XfceRc *rc) +{ + const gchar *env; + gchar **strlist; + gchar **mt; + gboolean show = TRUE; + + g_return_val_if_fail (rc != NULL, FALSE); + + if (G_LIKELY ((env = frap_menu_get_environment ()) != NULL)) + { + /* Try to read the "OnlyShowIn" list */ + strlist = xfce_rc_read_list_entry (rc, "OnlyShowIn", ";"); + + /* Check if this list exists. If so, mark this item for removal if + * the list does not contain the current desktop environment */ + if (G_UNLIKELY (strlist != NULL)) + { + show = FALSE; + for (mt = strlist; *mt != NULL; ++mt) + { + if (g_utf8_collate (*mt, env) == 0) + { + show = TRUE; + break; + } + } + g_strfreev (strlist); + } + else + { + /* If no "OnlyShowIn" list exists, try to read the "NotShowIn" list */ + strlist = xfce_rc_read_list_entry (rc, "NotShowIn", ";"); + + /* Check if this list exists. If so, mark this item for removal if the + * list contains the name of the current desktop environment */ + if (G_UNLIKELY (strlist != NULL)) + { + show = TRUE; + for (mt = strlist; *mt != NULL; ++mt) + { + if (g_utf8_collate (*mt, env) == 0) + show = FALSE; + } + g_strfreev (strlist); + } + } + } + + return show; +} + + + const gchar* frap_menu_item_get_desktop_id (FrapMenuItem *item) { Modified: libfrap/trunk/libfrap/menu/frap-menu.c =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/frap-menu.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -29,6 +29,7 @@ #include <libxfce4util/libxfce4util.h> +#include <frap-menu-environment.h> #include <frap-menu-item.h> #include <frap-menu-rules.h> #include <frap-menu-standard-rules.h> @@ -72,13 +73,16 @@ * Initializes the libfrapmenu library. **/ void -frap_menu_init (void) +frap_menu_init (const gchar *env) { if (g_atomic_int_exchange_and_add (&frap_menu_ref_count, 1) == 0) { /* Initialize the GObject type system */ g_type_init (); + /* Set desktop environment */ + frap_menu_set_environment (env); + /* Initialize the menu item cache */ _frap_menu_item_cache_init (); @@ -99,6 +103,9 @@ { if (g_atomic_int_dec_and_test (&frap_menu_ref_count)) { + /* Unset desktop environment */ + frap_menu_set_environment (NULL); + /* Shutdown the directory module */ _frap_menu_directory_shutdown (); @@ -179,6 +186,7 @@ enum { PROP_0, + PROP_ENVIRONMENT, PROP_FILENAME, PROP_NAME, PROP_DIRECTORY, @@ -627,29 +635,6 @@ if (G_UNLIKELY (root_menu == NULL)) { -#if 0 - /* Generate the location string of the root menu file */ - gchar *filename = g_build_path (G_DIR_SEPARATOR_S, "menus", "applications.menu", NULL); - - /* Search for the root menu file */ - gchar *location = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, filename); - - /* Make sure we found the menu file */ - if (G_LIKELY (location != NULL)) - { - /* Load the root menu */ - root_menu = frap_menu_new (location); - - /* Add weak pointer on the menu */ - g_object_add_weak_pointer (G_OBJECT (root_menu), (gpointer) &root_menu); - - /* Free location string */ - g_free (location); - } - - /* Free filename */ - g_free (filename); -#endif /* Search for a usable root menu file */ for (n = 0; n < G_N_ELEMENTS (FRAP_MENU_ROOT_SPECS) && root_menu == NULL; ++n) { @@ -699,7 +684,8 @@ * Return value: Menu structure found in @filename. **/ FrapMenu* -frap_menu_new (const gchar *filename, GError **error) +frap_menu_new (const gchar *filename, + GError **error) { FrapMenu *menu; @@ -719,6 +705,7 @@ } + const gchar* frap_menu_get_filename (FrapMenu *menu) { Modified: libfrap/trunk/libfrap/menu/frap-menu.h =================================================================== --- libfrap/trunk/libfrap/menu/frap-menu.h 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/frap-menu.h 2007-01-16 09:52:42 UTC (rev 24501) @@ -41,7 +41,7 @@ #define FRAP_IS_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FRAP_TYPE_MENU)) #define FRAP_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FRAP_TYPE_MENU, FrapMenuClass)) -void frap_menu_init (void); +void frap_menu_init (const gchar *env); void frap_menu_shutdown (void); GType frap_menu_get_type (void) G_GNUC_CONST; Modified: libfrap/trunk/libfrap/menu/libfrapmenu.h =================================================================== --- libfrap/trunk/libfrap/menu/libfrapmenu.h 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/libfrapmenu.h 2007-01-16 09:52:42 UTC (rev 24501) @@ -24,6 +24,7 @@ #define LIBFRAPMENU_INSIDE_LIBFRAPMENU_H +#include <frap-menu-environment.h> #include <frap-menu-item.h> #include <frap-menu-item-pool.h> #include <frap-menu-rules.h> Modified: libfrap/trunk/libfrap/menu/tests/test-and-rules.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-and-rules.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/tests/test-and-rules.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -35,7 +35,7 @@ gchar *desktop_file_path; /* Initialize FrapMenu */ - frap_menu_init (); + frap_menu_init (NULL); /* Build desktop file path */ desktop_file_path = g_build_filename (g_getenv ("PWD"), G_DIR_SEPARATOR_S, "data", G_DIR_SEPARATOR_S, "xfmedia.desktop", NULL); Modified: libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -146,6 +146,8 @@ gboolean terminal = frap_menu_item_requires_terminal (item); gboolean startup_notification = frap_menu_item_supports_startup_notification (item); + g_message ("%s activated", frap_menu_item_get_filename (item)); + /* Abort if no command was defined for this item */ if (G_UNLIKELY (command == NULL)) return; @@ -327,7 +329,7 @@ gtk_init (&argc, &argv); /* Initialize the menu library */ - frap_menu_init (); + frap_menu_init ("XFCE"); if (g_strv_length (argv) > 1) { Modified: libfrap/trunk/libfrap/menu/tests/test-menu-item.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-menu-item.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/tests/test-menu-item.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -31,10 +31,10 @@ char **argv) { FrapMenuItem *item; - gchar *desktop_file_path; + gchar *desktop_file_path; /* Initialize FrapMenu */ - frap_menu_init (); + frap_menu_init (NULL); /* Build desktop file path */ desktop_file_path = g_build_filename (g_getenv ("PWD"), G_DIR_SEPARATOR_S, "data", G_DIR_SEPARATOR_S, "xfmedia.desktop", NULL); Modified: libfrap/trunk/libfrap/menu/tests/test-not-rules.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-not-rules.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/tests/test-not-rules.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -35,7 +35,7 @@ gchar *desktop_file_path; /* Initialize FrapMenu */ - frap_menu_init (); + frap_menu_init (NULL); /* Build desktop file path */ desktop_file_path = g_build_filename (g_getenv ("PWD"), G_DIR_SEPARATOR_S, "data", G_DIR_SEPARATOR_S, "xfmedia.desktop", NULL); Modified: libfrap/trunk/libfrap/menu/tests/test-or-rules.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-or-rules.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/tests/test-or-rules.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -35,7 +35,7 @@ gchar *desktop_file_path; /* Initialize FrapMenu */ - frap_menu_init (); + frap_menu_init (NULL); /* Build desktop file path */ desktop_file_path = g_build_filename (g_getenv ("PWD"), G_DIR_SEPARATOR_S, "data", G_DIR_SEPARATOR_S, "xfmedia.desktop", NULL); Modified: libfrap/trunk/libfrap/menu/tests/test-root-menu.c =================================================================== --- libfrap/trunk/libfrap/menu/tests/test-root-menu.c 2007-01-16 08:20:12 UTC (rev 24500) +++ libfrap/trunk/libfrap/menu/tests/test-root-menu.c 2007-01-16 09:52:42 UTC (rev 24501) @@ -36,7 +36,7 @@ FrapMenu *root; /* Initialize FrapMenu */ - frap_menu_init (); + frap_menu_init (NULL); /* Get system root menu */ root = frap_menu_get_root (&error); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits