Author: jannis
Date: 2007-02-14 10:49:23 +0000 (Wed, 14 Feb 2007)
New Revision: 24974
Modified:
libfrap/trunk/libfrap/menu/ChangeLog
libfrap/trunk/libfrap/menu/frap-menu-directory.c
libfrap/trunk/libfrap/menu/frap-menu-directory.h
libfrap/trunk/libfrap/menu/frap-menu-item.c
libfrap/trunk/libfrap/menu/frap-menu-item.h
libfrap/trunk/libfrap/menu/frap-menu.c
libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c
Log:
* frap-menu-item.{c,h}: Don't ignore items which don't match the
current desktop environment. Parse OnlyShowIn/NotShowIn and add
method frap_menu_item_show_in_environment() which returns whether the
item should be displayed in the defined desktop environment or not.
Remove frap_menu_item_matches_environment(). Don't check for != NULL
before free'ing strings (g_free won't complain anyway).
* frap-menu-directory.{c,h}: Don't check for != NULL before calling
g_free(). Add frap_menu_directory_show_in_environment() (see notes on
frap-menu-item.c for how it works).
* tests/test-display-root-menu.c: Update to the new FrapMenu API.
Modified: libfrap/trunk/libfrap/menu/ChangeLog
===================================================================
--- libfrap/trunk/libfrap/menu/ChangeLog 2007-02-13 23:59:11 UTC (rev
24973)
+++ libfrap/trunk/libfrap/menu/ChangeLog 2007-02-14 10:49:23 UTC (rev
24974)
@@ -1,3 +1,16 @@
+2007-02-14 Jannis Pohlmann <[EMAIL PROTECTED]>
+
+ * frap-menu-item.{c,h}: Don't ignore items which don't match the
+ current desktop environment. Parse OnlyShowIn/NotShowIn and add
+ method frap_menu_item_show_in_environment() which returns whether the
+ item should be displayed in the defined desktop environment or not.
+ Remove frap_menu_item_matches_environment(). Don't check for != NULL
+ before free'ing strings (g_free won't complain anyway).
+ * frap-menu-directory.{c,h}: Don't check for != NULL before calling
+ g_free(). Add frap_menu_directory_show_in_environment() (see notes on
+ frap-menu-item.c for how it works).
+ * tests/test-display-root-menu.c: Update to the new FrapMenu API.
+
2007-02-13 Jannis Pohlmann <[EMAIL PROTECTED]>
* frap-menu.c: Add frap_menu_collect_files() and
Modified: libfrap/trunk/libfrap/menu/frap-menu-directory.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-directory.c 2007-02-13 23:59:11 UTC
(rev 24973)
+++ libfrap/trunk/libfrap/menu/frap-menu-directory.c 2007-02-14 10:49:23 UTC
(rev 24974)
@@ -29,6 +29,7 @@
#include <glib.h>
#include <libxfce4util/libxfce4util.h>
+#include <frap-menu-environment.h>
#include <frap-menu-directory.h>
@@ -520,22 +521,17 @@
g_return_if_fail (FRAP_IS_MENU_DIRECTORY (directory));
/* Free name */
- if (G_LIKELY (directory->priv->name != NULL))
- g_free (directory->priv->name);
+ g_free (directory->priv->name);
/* Free comment */
- if (G_LIKELY (directory->priv->comment != NULL))
- g_free (directory->priv->comment);
+ g_free (directory->priv->comment);
/* Free icon */
- if (G_LIKELY (directory->priv->icon != NULL))
- g_free (directory->priv->icon);
+ g_free (directory->priv->icon);
/* Free environment lists */
- if (G_LIKELY (directory->priv->only_show_in != NULL))
- g_strfreev (directory->priv->only_show_in);
- if (G_LIKELY (directory->priv->not_show_in != NULL))
- g_strfreev (directory->priv->not_show_in);
+ g_strfreev (directory->priv->only_show_in);
+ g_strfreev (directory->priv->not_show_in);
}
@@ -591,3 +587,57 @@
g_return_val_if_fail (FRAP_IS_MENU_DIRECTORY (directory), FALSE);
return directory->priv->hidden;
}
+
+
+
+gboolean
+frap_menu_directory_show_in_environment (FrapMenuDirectory *directory)
+{
+ const gchar *env;
+ gboolean show = TRUE;
+ gboolean included;
+ int i;
+
+ g_return_val_if_fail (FRAP_IS_MENU_DIRECTORY (directory), FALSE);
+
+ /* Determine current environment */
+ env = frap_menu_get_environment ();
+
+ /* If no environment has been set, the menu is displayed no matter what
+ * OnlyShowIn or NotShowIn contain */
+ if (G_UNLIKELY (env == NULL))
+ return TRUE;
+
+ /* Check if we have a OnlyShowIn OR a NotShowIn list (only one of them will
be
+ * there, according to the desktop entry specification) */
+ if (G_UNLIKELY (directory->priv->only_show_in != NULL))
+ {
+ /* Determine whether our environment is included in this list */
+ included = FALSE;
+ for (i = 0; i < g_strv_length (directory->priv->only_show_in); ++i)
+ {
+ if (G_UNLIKELY (g_utf8_collate (directory->priv->only_show_in[i],
env) == 0))
+ included = TRUE;
+ }
+
+ /* If it's not, don't show the menu */
+ if (G_LIKELY (!included))
+ show = FALSE;
+ }
+ else if (G_UNLIKELY (directory->priv->not_show_in != NULL))
+ {
+ /* Determine whether our environment is included in this list */
+ included = FALSE;
+ for (i = 0; i < g_strv_length (directory->priv->not_show_in); ++i)
+ {
+ if (G_UNLIKELY (g_utf8_collate (directory->priv->not_show_in[i],
env) == 0))
+ included = TRUE;
+ }
+
+ /* If it is, hide the menu */
+ if (G_UNLIKELY (included))
+ show = FALSE;
+ }
+
+ return show;
+}
Modified: libfrap/trunk/libfrap/menu/frap-menu-directory.h
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-directory.h 2007-02-13 23:59:11 UTC
(rev 24973)
+++ libfrap/trunk/libfrap/menu/frap-menu-directory.h 2007-02-14 10:49:23 UTC
(rev 24974)
@@ -41,24 +41,25 @@
#define FRAP_IS_MENU_DIRECTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
FRAP_TYPE_MENU_DIRECTORY))
#define FRAP_MENU_DIRECTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
FRAP_TYPE_MENU_DIRECTORY, FrapMenuDirectoryClass))
-GType frap_menu_directory_get_type (void)
G_GNUC_CONST;
+GType frap_menu_directory_get_type (void)
G_GNUC_CONST;
-const gchar *frap_menu_directory_get_filename
(FrapMenuDirectory *directory);
-void frap_menu_directory_set_filename
(FrapMenuDirectory *directory,
- const gchar
*name);
-const gchar *frap_menu_directory_get_name
(FrapMenuDirectory *directory);
-void frap_menu_directory_set_name
(FrapMenuDirectory *directory,
- const gchar
*name);
-const gchar *frap_menu_directory_get_comment
(FrapMenuDirectory *directory);
-void frap_menu_directory_set_comment
(FrapMenuDirectory *directory,
- const gchar
*comment);
-const gchar *frap_menu_directory_get_icon
(FrapMenuDirectory *directory);
-void frap_menu_directory_set_icon
(FrapMenuDirectory *directory,
- const gchar
*icon);
-gboolean frap_menu_directory_get_no_display
(FrapMenuDirectory *directory);
-void frap_menu_directory_set_no_display
(FrapMenuDirectory *directory,
- gboolean
no_display);
-gboolean frap_menu_directory_get_hidden
(FrapMenuDirectory *directory);
+const gchar *frap_menu_directory_get_filename
(FrapMenuDirectory *directory);
+void frap_menu_directory_set_filename
(FrapMenuDirectory *directory,
+ const gchar
*name);
+const gchar *frap_menu_directory_get_name
(FrapMenuDirectory *directory);
+void frap_menu_directory_set_name
(FrapMenuDirectory *directory,
+ const gchar
*name);
+const gchar *frap_menu_directory_get_comment
(FrapMenuDirectory *directory);
+void frap_menu_directory_set_comment
(FrapMenuDirectory *directory,
+ const gchar
*comment);
+const gchar *frap_menu_directory_get_icon
(FrapMenuDirectory *directory);
+void frap_menu_directory_set_icon
(FrapMenuDirectory *directory,
+ const gchar
*icon);
+gboolean frap_menu_directory_get_no_display
(FrapMenuDirectory *directory);
+void frap_menu_directory_set_no_display
(FrapMenuDirectory *directory,
+ gboolean
no_display);
+gboolean frap_menu_directory_get_hidden
(FrapMenuDirectory *directory);
+gboolean frap_menu_directory_show_in_environment
(FrapMenuDirectory *directory);
#if defined(LIBFRAPMENU_COMPILATION)
void _frap_menu_directory_init (void) G_GNUC_INTERNAL;
Modified: libfrap/trunk/libfrap/menu/frap-menu-item.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item.c 2007-02-13 23:59:11 UTC (rev
24973)
+++ libfrap/trunk/libfrap/menu/frap-menu-item.c 2007-02-14 10:49:23 UTC (rev
24974)
@@ -63,7 +63,6 @@
const GValue
*value,
GParamSpec
*pspec);
static void frap_menu_item_load (FrapMenuItem
*item);
-static gboolean frap_menu_item_rc_matches_environment (XfceRc *rc);
@@ -102,6 +101,12 @@
/* Menu item icon name */
gchar *icon_name;
+ /* Environments in which the menu item should be displayed only */
+ gchar **only_show_in;
+
+ /* Environments in which the menu item should be hidden */
+ gchar **not_show_in;
+
/* Counter keeping the number of menus which use this item. This works
* like a reference counter and should be increased / decreased by FrapMenu
* items whenever the item is added to or removed from the menu. */
@@ -283,8 +288,10 @@
item->priv->name = NULL;
item->priv->filename = NULL;
item->priv->command = NULL;
- item->priv->icon_name = NULL;
item->priv->categories = NULL;
+ item->priv->icon_name = NULL;
+ item->priv->only_show_in = NULL;
+ item->priv->not_show_in = NULL;
item->priv->num_allocated = 0;
}
@@ -295,21 +302,15 @@
{
FrapMenuItem *item = FRAP_MENU_ITEM (object);
- if (G_LIKELY (item->priv->desktop_id != NULL))
- g_free (item->priv->desktop_id);
+ g_free (item->priv->desktop_id);
+ g_free (item->priv->name);
+ g_free (item->priv->filename);
+ g_free (item->priv->command);
+ g_free (item->priv->icon_name);
- if (G_LIKELY (item->priv->name != NULL))
- g_free (item->priv->name);
+ g_strfreev (item->priv->only_show_in);
+ g_strfreev (item->priv->not_show_in);
- if (G_LIKELY (item->priv->filename != NULL))
- g_free (item->priv->filename);
-
- if (G_LIKELY (item->priv->command != NULL))
- g_free (item->priv->command);
-
- if (G_LIKELY (item->priv->icon_name != NULL))
- g_free (item->priv->icon_name);
-
g_list_foreach (item->priv->categories, (GFunc) g_free, NULL);
g_list_free (item->priv->categories);
@@ -410,13 +411,11 @@
const gchar *name;
const gchar *exec;
const gchar *icon;
- const gchar *tryexec;
const gchar *env;
gchar *command;
gchar **mt;
gchar **str_list;
GList *categories = NULL;
- gboolean present;
gboolean terminal;
gboolean no_display;
gboolean startup_notify;
@@ -430,14 +429,6 @@
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;
- }
-
/* Use the Desktop Entry section of the desktop file */
xfce_rc_set_group (rc, "Desktop Entry");
@@ -453,39 +444,6 @@
exec = xfce_rc_read_entry (rc, "Exec", NULL);
icon = xfce_rc_read_entry (rc, "Icon", NULL);
- /* Check if TryExec exists */
- tryexec = xfce_rc_read_entry_untranslated (rc, "TryExec", NULL);
- tryexec = (tryexec != NULL) ? tryexec : exec;
-
- /* Perform checks in order to ignore non-existend programs */
- if (G_LIKELY (tryexec != NULL && g_shell_parse_argv (tryexec, NULL, &mt,
NULL)))
- {
-#if 0
- /* Check if the path is absolute */
- present = g_file_test (mt[0], G_FILE_TEST_EXISTS);
-
- /* Otherwise, search in $PATH */
- if (G_LIKELY (!present))
- {
- command = g_find_program_in_path (mt[0]);
- present = (command != NULL);
- g_free (command);
- }
-
- /* Free TryExec arguments */
- g_strfreev (mt);
-
- /* If the program is not present, we just ignore it */
- if (G_UNLIKELY (!present))
- {
- xfce_rc_close (rc);
- return NULL;
- }
-#endif
- g_strfreev (mt);
- present = TRUE;
- }
-
/* Validate Name and Exec fields */
if (G_LIKELY (exec != NULL && name != NULL && g_utf8_validate (name, -1,
NULL)))
{
@@ -521,6 +479,10 @@
/* Assign categories list to the menu item */
frap_menu_item_set_categories (item, categories);
}
+
+ /* Set the rest of the private data directly */
+ item->priv->only_show_in = xfce_rc_read_list_entry (rc, "OnlyShowIn",
";");
+ item->priv->not_show_in = xfce_rc_read_list_entry (rc, "NotShowIn", ";");
}
/* Close file handle */
@@ -531,61 +493,6 @@
-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)
{
@@ -879,6 +786,60 @@
+gboolean
+frap_menu_item_show_in_environment (FrapMenuItem *item)
+{
+ const gchar *env;
+ gboolean show = TRUE;
+ gboolean included;
+ int i;
+
+ g_return_val_if_fail (FRAP_IS_MENU_ITEM (item), FALSE);
+
+ /* Determine current environment */
+ env = frap_menu_get_environment ();
+
+ /* If no environment has been set, the menu item is displayed no matter what
+ * OnlyShowIn or NotShowIn contain */
+ if (G_UNLIKELY (env == NULL))
+ return TRUE;
+
+ /* Check if we have a OnlyShowIn OR a NotShowIn list (only one of them will
be
+ * there, according to the desktop entry specification) */
+ if (G_UNLIKELY (item->priv->only_show_in != NULL))
+ {
+ /* Determine whether our environment is included in this list */
+ included = FALSE;
+ for (i = 0; i < g_strv_length (item->priv->only_show_in); ++i)
+ {
+ if (G_UNLIKELY (g_utf8_collate (item->priv->only_show_in[i], env) ==
0))
+ included = TRUE;
+ }
+
+ /* If it's not, don't show the menu item */
+ if (G_LIKELY (!included))
+ show = FALSE;
+ }
+ else if (G_UNLIKELY (item->priv->not_show_in != NULL))
+ {
+ /* Determine whether our environment is included in this list */
+ included = FALSE;
+ for (i = 0; i < g_strv_length (item->priv->not_show_in); ++i)
+ {
+ if (G_UNLIKELY (g_utf8_collate (item->priv->not_show_in[i], env) ==
0))
+ included = TRUE;
+ }
+
+ /* If it is, hide the menu item */
+ if (G_UNLIKELY (included))
+ show = FALSE;
+ }
+
+ return show;
+}
+
+
+
void
frap_menu_item_ref (FrapMenuItem *item)
{
Modified: libfrap/trunk/libfrap/menu/frap-menu-item.h
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu-item.h 2007-02-13 23:59:11 UTC (rev
24973)
+++ libfrap/trunk/libfrap/menu/frap-menu-item.h 2007-02-14 10:49:23 UTC (rev
24974)
@@ -73,6 +73,7 @@
GList *frap_menu_item_get_categories (FrapMenuItem
*item);
void frap_menu_item_set_categories (FrapMenuItem
*item,
GList
*categories);
+gboolean frap_menu_item_show_in_environment (FrapMenuItem
*item);
void frap_menu_item_ref (FrapMenuItem
*item);
void frap_menu_item_unref (FrapMenuItem
*item);
gint frap_menu_item_get_allocated (FrapMenuItem
*item);
Modified: libfrap/trunk/libfrap/menu/frap-menu.c
===================================================================
--- libfrap/trunk/libfrap/menu/frap-menu.c 2007-02-13 23:59:11 UTC (rev
24973)
+++ libfrap/trunk/libfrap/menu/frap-menu.c 2007-02-14 10:49:23 UTC (rev
24974)
@@ -53,7 +53,7 @@
-/* Possible root menu files */
+/* Potential root menu files */
static const gchar FRAP_MENU_ROOT_SPECS[][30] =
{
"menus/applications.menu",
Modified: libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c
===================================================================
--- libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2007-02-13
23:59:11 UTC (rev 24973)
+++ libfrap/trunk/libfrap/menu/tests/test-display-root-menu.c 2007-02-14
10:49:23 UTC (rev 24974)
@@ -173,6 +173,12 @@
GtkWidget *image;
GdkPixbuf *pixbuf;
+ g_return_if_fail (FRAP_IS_MENU_ITEM (item));
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ if (!frap_menu_item_show_in_environment (item))
+ return;
+
/* Try to load the image */
pixbuf = create_icon_for_item (item);
@@ -223,6 +229,11 @@
if (frap_menu_item_pool_get_empty (frap_menu_get_item_pool (iter->data)))
continue;
+ /* Skip if menu is only shown in other environments or is not shown in
+ * this one */
+ if (!frap_menu_directory_show_in_environment (directory))
+ continue;
+
/* Determine icon name */
icon_name = frap_menu_directory_get_icon (directory);
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits