[Goodies-commits] r1777 - in xfce-menu/trunk: . libxfce4menu tests
Jannis Pohlmann
jannis at xfce.org
Fri Jul 21 13:23:13 CEST 2006
Author: jannis
Date: 2006-07-21 11:23:12 +0000 (Fri, 21 Jul 2006)
New Revision: 1777
Added:
xfce-menu/trunk/tests/display-menu.c
Modified:
xfce-menu/trunk/ChangeLog
xfce-menu/trunk/libxfce4menu/xfce-menu.c
xfce-menu/trunk/tests/CMakeLists.txt
Log:
* libxfce4menu/xfce-menu.c: Destroy the menu parse info in
xfce_menu_finalize, not directly after parsing the menu. Free
old parse info directory name when the menu directory name has
changed and the menu is parsed again.
* tests/CMakeLists.txt, tests/display-menu.c: Added a test program to
display the menu structure. At the moment, it only contains menus
listed in the root menu file, no merged menus or menu items (as
these features have not been implemented yet).
Modified: xfce-menu/trunk/ChangeLog
===================================================================
--- xfce-menu/trunk/ChangeLog 2006-07-20 20:58:25 UTC (rev 1776)
+++ xfce-menu/trunk/ChangeLog 2006-07-21 11:23:12 UTC (rev 1777)
@@ -1,3 +1,14 @@
+2006-07-21 Janins Pohlmann <jannis at xfce.org>
+
+ * libxfce4menu/xfce-menu.c: Destroy the menu parse info in
+ xfce_menu_finalize, not directly after parsing the menu. Free
+ old parse info directory name when the menu directory name has
+ changed and the menu is parsed again.
+ * tests/CMakeLists.txt, tests/display-menu.c: Added a test program to
+ display the menu structure. At the moment, it only contains menus
+ listed in the root menu file, no merged menus or menu items (as
+ these features have not been implemented yet).
+
2006-07-20 Jannis Pohlmann <jannis at xfce.org>
* libxfce4menu/xfce-menu-directory.{c,h}: Remove the
Modified: xfce-menu/trunk/libxfce4menu/xfce-menu.c
===================================================================
--- xfce-menu/trunk/libxfce4menu/xfce-menu.c 2006-07-20 20:58:25 UTC (rev 1776)
+++ xfce-menu/trunk/libxfce4menu/xfce-menu.c 2006-07-21 11:23:12 UTC (rev 1777)
@@ -397,8 +397,7 @@
g_slist_free (menu->priv->app_dirs);
/* Free parse information */
- g_free (menu->priv->parse_info->directory_name);
- g_free (menu->priv->parse_info);
+ xfce_menu_free_parse_info (menu);
(*G_OBJECT_CLASS (xfce_menu_parent_class)->finalize) (object);
}
@@ -785,9 +784,6 @@
/* TODO: Resolve internals, like priv->parse_info->directory_name => priv->directory */
xfce_menu_resolve_directory (menu);
-
- /* Free parse info */
- xfce_menu_free_parse_info (menu);
}
@@ -958,9 +954,13 @@
/* Abort if names are equal */
if (G_UNLIKELY (menu->priv->parse_info->directory_name != NULL))
- if (G_UNLIKELY (g_utf8_collate (name, menu->priv->parse_info->directory_name) == 0))
- return;
+ {
+ if (G_UNLIKELY (g_utf8_collate (name, menu->priv->parse_info->directory_name) == 0))
+ return;
+ g_free (menu->priv->parse_info->directory_name);
+ }
+
/* Set new directory name */
menu->priv->parse_info->directory_name = g_strdup (name);
}
@@ -975,6 +975,9 @@
/* Free directory name */
g_free (menu->priv->parse_info->directory_name);
+
+ /* Free parse info */
+ g_free (menu->priv->parse_info);
}
Modified: xfce-menu/trunk/tests/CMakeLists.txt
===================================================================
--- xfce-menu/trunk/tests/CMakeLists.txt 2006-07-20 20:58:25 UTC (rev 1776)
+++ xfce-menu/trunk/tests/CMakeLists.txt 2006-07-21 11:23:12 UTC (rev 1777)
@@ -9,3 +9,9 @@
${EXECUTABLE_OUTPUT_PATH}/load_root_menu_test
)
TARGET_LINK_LIBRARIES(load_root_menu_test xfce4menu)
+
+# Display menu test
+ADD_EXECUTABLE(display_menu display-menu.c)
+ADD_TEST(display_menu
+ ${EXECUTABLE_OUTPUT_PATH}/display_menu)
+TARGET_LINK_LIBRARIES(display_menu xfce4menu)
Added: xfce-menu/trunk/tests/display-menu.c
===================================================================
--- xfce-menu/trunk/tests/display-menu.c (rev 0)
+++ xfce-menu/trunk/tests/display-menu.c 2006-07-21 11:23:12 UTC (rev 1777)
@@ -0,0 +1,184 @@
+/* $Id$ */
+/* vi:set expandtab sw=2 sts=2: */
+/*-
+ * Copyright (c) 2006 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * 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 <stdlib.h>
+
+#include <libxfce4menu/libxfce4menu.h>
+
+
+
+static XfceMenu *root = NULL;
+static GtkWidget *window = NULL;
+
+
+
+void
+main_window_destroy (GtkWidget *window, gpointer user_data)
+{
+ gtk_main_quit ();
+}
+
+
+
+gint
+compare_menus (XfceMenu *menu1, XfceMenu *menu2)
+{
+ XfceMenuDirectory *dir1 = xfce_menu_get_directory (XFCE_MENU (menu1));
+ XfceMenuDirectory *dir2 = xfce_menu_get_directory (XFCE_MENU (menu2));
+
+ return g_utf8_collate (xfce_menu_directory_get_name (dir1), xfce_menu_directory_get_name (dir2));
+}
+
+
+
+void
+create_widgets_for_menu (GtkWidget *widget, XfceMenu *menu)
+{
+ XfceMenuDirectory *directory;
+ GtkWidget *menu_item;
+ GtkWidget *submenu;
+ GtkWidget *image;
+ GSList *iter;
+ GSList *menus;
+ GtkTooltips *tooltips = gtk_tooltips_new ();
+
+ /* Create sorted copy of the submenu list */
+ menus = g_slist_sort (g_slist_copy (xfce_menu_get_menus (menu)), (GCompareFunc) compare_menus);
+
+ for (iter = menus; iter != NULL; iter = g_slist_next (iter))
+ {
+ /* Get menu directory */
+ directory = xfce_menu_get_directory (XFCE_MENU (iter->data));
+
+ /* Create menu icon */
+ image = gtk_image_new_from_icon_name (xfce_menu_directory_get_icon (directory), GTK_ICON_SIZE_MENU);
+
+ /* Create menu item */
+ menu_item = gtk_image_menu_item_new_with_label (xfce_menu_directory_get_name (directory));
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
+ gtk_menu_shell_append (GTK_MENU_SHELL (widget), menu_item);
+ gtk_widget_show (menu_item);
+
+ /* Create submenu */
+ submenu = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu);
+
+ /* Create widgets for submenu */
+ create_widgets_for_menu (submenu, XFCE_MENU (iter->data));
+ }
+
+ /* Free submenu list */
+ g_slist_free (menus);
+}
+
+
+
+void
+show_menu (GtkButton *button, GtkWidget *menu)
+{
+ /* Create menu widgets if not already done */
+ if (g_list_length (gtk_container_get_children (GTK_CONTAINER (menu))) == 0)
+ {
+ create_widgets_for_menu (menu, root);
+ }
+
+ /* Display the menu */
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time ());
+}
+
+
+
+void
+create_main_window (void)
+{
+ GtkWidget *vbox;
+ GtkWidget *label;
+ GtkWidget *button;
+ GtkWidget *menu;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ /* Basic window setup */
+ gtk_window_set_title (GTK_WINDOW (window), _("XDG Menu"));
+ gtk_container_set_border_width (GTK_CONTAINER (window), 12);
+
+ /* Connect signal handlers */
+ g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (main_window_destroy), NULL);
+
+ /* Display window */
+ gtk_widget_show (window);
+
+ /* Create vbox */
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_widget_show (vbox);
+
+ /* Create label */
+ label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_label_set_markup (GTK_LABEL (label), "<b><big>XDG Menu:</big></b>");
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
+ gtk_widget_show (label);
+
+ /* Create button */
+ button = gtk_button_new_with_mnemonic (_("_Show"));
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, TRUE, 0);
+ gtk_widget_show (button);
+
+ /* Create menu */
+ menu = gtk_menu_new ();
+
+ /* Connect button to the menu */
+ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_menu), menu);
+}
+
+
+
+int main(int argc,
+ char **argv)
+{
+ /* Initialize GTK */
+ gtk_init (&argc, &argv);
+
+ /* Initialize the menu library */
+ xfce_menu_init ();
+
+ /* Get a reference to the root menu */
+ root = xfce_menu_get_root ();
+
+ /* Create the main window */
+ create_main_window ();
+
+ /* Enter main loop */
+ gtk_main ();
+
+ /* Destroy the root menu */
+ g_object_unref (root);
+
+ /* Shut down the menu library */
+ xfce_menu_shutdown ();
+
+ return EXIT_SUCCESS;
+}
More information about the Goodies-commits
mailing list