[alleyoop] Removed more GNOME dependencies



commit 997cbdbf6827f74a2a7cef904b3810aa4edd0183
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Sat Dec 17 17:31:01 2011 -0500

    Removed more GNOME dependencies
    
    2011-12-17  Jeffrey Stedfast  <fejj gnome org>
    
    	* src/alleyoop.c: Subclass GtkWindow instead of GnomeApp and
    	updated to use GtkUIManager APIs to replace GnomeUIInfo APIs.

 ChangeLog      |    5 +
 src/alleyoop.c |  251 ++++++++++++++++++++++++++++----------------------------
 src/alleyoop.h |   17 +++-
 src/main.c     |   12 +--
 4 files changed, 149 insertions(+), 136 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 44dc2d0..f39233b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-12-17  Jeffrey Stedfast  <fejj gnome org>
 
+	* src/alleyoop.c: Subclass GtkWindow instead of GnomeApp and
+	updated to use GtkUIManager APIs to replace GnomeUIInfo APIs.
+
+2011-12-17  Jeffrey Stedfast  <fejj gnome org>
+
 	* alleyoop.desktop.in: Added.
 
 	* src/alleyoop.c: Replaced the GnomeAbout dialog with a
diff --git a/src/alleyoop.c b/src/alleyoop.c
index 21f2436..3a8efa8 100644
--- a/src/alleyoop.c
+++ b/src/alleyoop.c
@@ -34,7 +34,6 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gconf/gconf-client.h>
-#include <libgnomeui/gnome-app-helper.h>
 
 #include "vgdefaultview.h"
 #include "menu-utils.h"
@@ -43,22 +42,11 @@
 #include "prefs.h"
 
 
-enum {
-	VALGRIND_TOOL_MEMCHECK,
-	VALGRIND_TOOL_ADDRCHECK,
-	VALGRIND_TOOL_CACHEGRIND,
-	VALGRIND_TOOL_HELGRIND,
-};
-
-static struct {
-	const char *name;
-	int tool;
-} valgrind_tools[] = {
-	{ "memcheck",   VALGRIND_TOOL_MEMCHECK   },
-	{ "addrcheck",  VALGRIND_TOOL_ADDRCHECK  },
-	{ "cachegrind", VALGRIND_TOOL_CACHEGRIND },
-	{ "helgrind",   VALGRIND_TOOL_HELGRIND   },
-	{ NULL,         VALGRIND_TOOL_MEMCHECK   },
+static char *tool_names[] = {
+	"memcheck",
+	"addrcheck",
+	"cachegrind",
+	"helgrind",
 };
 
 static void alleyoop_class_init (AlleyoopClass *klass);
@@ -72,7 +60,7 @@ static void alleyoop_finalize (GObject *obj);
 static gboolean io_ready_cb (GIOChannel *gio, GIOCondition condition, gpointer user_data);
 
 
-static GnomeAppClass *parent_class = NULL;
+static GtkWindowClass *parent_class = NULL;
 
 
 GType
@@ -93,7 +81,7 @@ alleyoop_get_type (void)
 			(GInstanceInitFunc) alleyoop_init,
 		};
 		
-		type = g_type_register_static (GNOME_TYPE_APP, "Alleyoop", &info, 0);
+		type = g_type_register_static (GTK_TYPE_WINDOW, "Alleyoop", &info, 0);
 	}
 	
 	return type;
@@ -105,7 +93,7 @@ alleyoop_class_init (AlleyoopClass *klass)
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
 	
-	parent_class = g_type_class_ref (GNOME_TYPE_APP);
+	parent_class = g_type_class_ref (GTK_TYPE_WINDOW);
 	
 	object_class->finalize = alleyoop_finalize;
 	gtk_object_class->destroy = alleyoop_destroy;
@@ -118,6 +106,7 @@ alleyoop_init (Alleyoop *grind)
 	grind->srcdir = NULL;
 	
 	grind->view = NULL;
+	grind->ui = NULL;
 	
 	grind->gio = NULL;
 	grind->watch_id = 0;
@@ -138,6 +127,9 @@ alleyoop_finalize (GObject *obj)
 	if (grind->gio)
 		g_io_channel_unref (grind->gio);
 	
+	if (grind->ui)
+		g_object_unref (grind->ui);
+	
 	G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
 
@@ -186,7 +178,7 @@ run_prompt_argv (Alleyoop *grind)
 	gtk_widget_show (hbox);
 	gtk_box_pack_start ((GtkBox *) vbox, hbox, FALSE, FALSE, 0);
 	
-	/* FIXME: use a GnomeFileEntry instead? */
+	/* FIXME: use a GtkFileChooserButton instead? */
 	entry = gtk_entry_new ();
 	gtk_widget_show (entry);
 	gtk_box_pack_start ((GtkBox *) vbox, entry, FALSE, FALSE, 0);
@@ -488,37 +480,11 @@ edit_rules_cb (GtkWidget *widget, gpointer user_data)
 }
 
 static void
-tools_default_cb (GtkWidget *widget, gpointer user_data)
-{
-	Alleyoop *grind = (Alleyoop *) user_data;
-	
-	grind->tool = NULL;
-}
-
-static void
-tools_addrcheck_cb (GtkWidget *widget, gpointer user_data)
-{
-	Alleyoop *grind = (Alleyoop *) user_data;
-	
-	grind->tool = "addrcheck";
-}
-
-#if 0
-static void
-tools_cachegrind_cb (GtkWidget *widget, gpointer user_data)
-{
-	Alleyoop *grind = (Alleyoop *) user_data;
-	
-	grind->tool = "cachegrind";
-}
-#endif
-
-static void
-tools_helgrind_cb (GtkWidget *widget, gpointer user_data)
+tool_selected_cb (GtkRadioAction *radio, gpointer user_data)
 {
 	Alleyoop *grind = (Alleyoop *) user_data;
 	
-	grind->tool = "helgrind";
+	grind->tool = gtk_radio_action_get_current_value (radio);
 }
 
 static void
@@ -571,64 +537,83 @@ help_about_cb (GtkWidget *widget, gpointer user_data)
 	gdk_window_raise (grind->about->window);
 }
 
-static GnomeUIInfo file_menu[] = {
-	{ GNOME_APP_UI_ITEM, N_("_Run"), NULL, G_CALLBACK (file_run_cb), NULL, NULL,
-	  GNOME_APP_PIXMAP_STOCK, GTK_STOCK_EXECUTE, 'r', GDK_CONTROL_MASK, NULL },
-	{ GNOME_APP_UI_ITEM, N_("_Kill"), NULL, G_CALLBACK (file_kill_cb), NULL, NULL,
-	  GNOME_APP_PIXMAP_STOCK, GTK_STOCK_CANCEL, 'k', GDK_CONTROL_MASK, NULL },
-	GNOMEUIINFO_MENU_OPEN_ITEM (G_CALLBACK (file_open_cb), NULL),
-	GNOMEUIINFO_MENU_SAVE_ITEM (G_CALLBACK (file_save_cb), NULL),
-	GNOMEUIINFO_MENU_SAVE_AS_ITEM (G_CALLBACK (file_save_as_cb), NULL),
-	GNOMEUIINFO_SEPARATOR,
-	GNOMEUIINFO_MENU_QUIT_ITEM (G_CALLBACK (file_quit_cb), NULL),
-	GNOMEUIINFO_END
+/* Normal menu items */
+static const GtkActionEntry normal_menu_items[] = {
+	{ "FileMenu",          NULL,                         N_("_File")                  },
+	{ "Run",               GTK_STOCK_EXECUTE,            N_("_Run"),
+	  "<control>R",        N_("Run program"),            G_CALLBACK (file_run_cb)     },
+	{ "Kill",              GTK_STOCK_CANCEL,             N_("_Kill"),
+	  "<control>K",        N_("Kill program"),           G_CALLBACK (file_kill_cb)    },
+	{ "Open",              GTK_STOCK_OPEN,               N_("_Open..."),
+	  "<control>O",        N_("Open a log file"),        G_CALLBACK (file_open_cb)    },
+	{ "Save",              GTK_STOCK_SAVE,               N_("_Save"),
+	  "<control>S",        N_("Save the file"),          G_CALLBACK (file_save_cb)    },
+	{ "SaveAs",            GTK_STOCK_SAVE_AS,            N_("Save _As..."),
+	  "<shift><control>S", N_("Save the file as..."),    G_CALLBACK (file_save_as_cb) },
+	{ "Quit",              GTK_STOCK_QUIT,               N_("_Quit"),
+	  "<control>Q",        N_("Exit the program"),       G_CALLBACK (file_quit_cb)    },
+	
+	{ "EditMenu",          NULL,                         N_("_Edit")                  },
+	{ "Cut",               GTK_STOCK_CUT,                N_("Cu_t"),
+	  "<control>X",        N_("Cut to clipboard"),       G_CALLBACK (edit_cut_cb)     },
+	{ "Copy",              GTK_STOCK_COPY,               N_("_Copy"),
+	  "<control>C",        N_("Copy to clipboard"),      G_CALLBACK (edit_copy_cb)    },
+	{ "Paste",             GTK_STOCK_PASTE,              N_("_Paste"),
+	  "<control>V",        N_("Paste from clipboard"),   G_CALLBACK (edit_paste_cb)   },
+	{ "Clear",             GTK_STOCK_CLEAR,              N_("C_lear"),
+	  NULL,                N_("Clear log view"),         G_CALLBACK (edit_clear_cb)   },
+	
+	{ "SettingsMenu",      NULL,                         N_("_Settings")              },
+	{ "Preferences",       GTK_STOCK_PREFERENCES,        N_("Prefere_nces"),
+	  NULL,                N_("Edit preferences..."),    G_CALLBACK (edit_prefs_cb)   },
+	{ "Suppressions",      NULL,                         N_("Suppressions"),
+	  NULL,                N_("View/Edit Suppressions"), G_CALLBACK (edit_rules_cb)   },
+	
+	{ "ToolsMenu",         NULL,                         N_("_Tools")                 },
+	
+	{ "HelpMenu",          NULL,                         N_("_Help")                  },
+	{ "About",             GTK_STOCK_ABOUT,              N_("_About"),
+	  NULL,                N_("About Alleyoop"),         G_CALLBACK (help_about_cb)   },
 };
 
-static GnomeUIInfo edit_menu[] = {
-	GNOMEUIINFO_MENU_CUT_ITEM (G_CALLBACK (edit_cut_cb), NULL),
-	GNOMEUIINFO_MENU_COPY_ITEM (G_CALLBACK (edit_copy_cb), NULL),
-	GNOMEUIINFO_MENU_PASTE_ITEM (G_CALLBACK (edit_paste_cb), NULL),
-	GNOMEUIINFO_MENU_CLEAR_ITEM (G_CALLBACK (edit_clear_cb), NULL),
-	GNOMEUIINFO_END
+static const GtkRadioActionEntry radio_menu_items[] = {
+	{ "AddrCheck",  NULL, "AddrCheck", NULL, N_("Use the AddrCheck Valgrind tool"), VALGRIND_TOOL_ADDRCHECK },
+	{ "MemCheck",   NULL, "MemCheck",  NULL, N_("Use the MemCheck Valgrind tool"),  VALGRIND_TOOL_MEMCHECK  },
+	{ "Helgrind",   NULL, "Helgrind",  NULL, N_("Use the Helgrind tool"),           VALGRIND_TOOL_HELGRIND  },
 };
 
-static GnomeUIInfo settings_menu[] = {
-	GNOMEUIINFO_MENU_PREFERENCES_ITEM (G_CALLBACK (edit_prefs_cb), NULL),
-	{ GNOME_APP_UI_ITEM, N_("Suppressions"), N_("View/Edit Suppressions"), G_CALLBACK (edit_rules_cb),
-	  NULL, NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL },
-	GNOMEUIINFO_END
-};
-
-static GnomeUIInfo tools_menu_items[] = {
-	{ GNOME_APP_UI_ITEM, "Memcheck", NULL, G_CALLBACK (tools_default_cb), NULL,
-	  NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL },
-	{ GNOME_APP_UI_ITEM, "Addrcheck", NULL, G_CALLBACK (tools_addrcheck_cb), NULL,
-	  NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL },
-	/*{ GNOME_APP_UI_ITEM, "Cachegrind", NULL, G_CALLBACK (tools_cachegrind_cb), NULL,
-	  NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL },*/
-	{ GNOME_APP_UI_ITEM, "Helgrind", NULL, G_CALLBACK (tools_helgrind_cb), NULL,
-	  NULL, GNOME_APP_PIXMAP_NONE, NULL, 0, 0, NULL },
-	GNOMEUIINFO_END
-};
-
-static GnomeUIInfo tools_menu[] = {
-	GNOMEUIINFO_RADIOLIST (tools_menu_items),
-	GNOMEUIINFO_END
-};
-
-static GnomeUIInfo help_menu[] = {
-	GNOMEUIINFO_MENU_ABOUT_ITEM (G_CALLBACK (help_about_cb), NULL),
-	GNOMEUIINFO_END
-};
-
-static GnomeUIInfo alleyoop_menu[] = {
-	GNOMEUIINFO_MENU_FILE_TREE (file_menu),
-	GNOMEUIINFO_MENU_EDIT_TREE (edit_menu),
-	GNOMEUIINFO_MENU_SETTINGS_TREE (settings_menu),
-	GNOMEUIINFO_SUBTREE (N_("Tool"), tools_menu),
-	GNOMEUIINFO_MENU_HELP_TREE (help_menu),
-	GNOMEUIINFO_END
-};
+static const char *menu_xml =
+	"<ui>"
+	"  <menubar name='MainMenu'>"
+	"    <menu action='FileMenu'>"
+	"      <menuitem action='Run'/>"
+	"      <menuitem action='Kill'/>"
+	"      <menuitem action='Open'/>"
+	"      <menuitem action='Save'/>"
+	"      <menuitem action='SaveAs'/>"
+	"      <separator/>"
+	"      <menuitem action='Quit'/>"
+	"    </menu>"
+	"    <menu action='EditMenu'>"
+	"      <menuitem action='Cut'/>"
+	"      <menuitem action='Copy'/>"
+	"      <menuitem action='Paste'/>"
+	"      <menuitem action='Clear'/>"
+	"    </menu>"
+	"    <menu action='SettingsMenu'>"
+	"      <menuitem action='Preferences'/>"
+	"      <menuitem action='Suppressions'/>"
+	"    </menu>"
+	"    <menu action='ToolsMenu'>"
+	"      <menuitem action='AddrCheck'/>"
+	"      <menuitem action='MemCheck'/>"
+	"      <menuitem action='Helgrind'/>"
+	"    </menu>"
+	"    <menu action='HelpMenu'>"
+	"      <menuitem action='About'/>"
+	"    </menu>"
+	"  </menubar>"
+	"</ui>";
 
 static GtkWidget *
 alleyoop_toolbar_new (Alleyoop *grind)
@@ -681,9 +666,12 @@ prefs_delete_event (GtkWidget *widget, gpointer user_data)
 }
 
 GtkWidget *
-alleyoop_new (const char *tool, const char **argv, const char **srcdir)
+alleyoop_new (ValgrindTool tool, const char **argv, const char **srcdir)
 {
-	GtkWidget *widget;
+	GtkWidget *menubar, *widget, *vbox;
+	GtkActionGroup *actions;
+	GtkAccelGroup *accels;
+	GError *err = NULL;
 	Alleyoop *grind;
 	char *title;
 	int i;
@@ -695,48 +683,63 @@ alleyoop_new (const char *tool, const char **argv, const char **srcdir)
 	else
 		title = g_strdup ("Alleyoop");
 	
-	gnome_app_construct ((GnomeApp *) grind, "alleyoop", title);
+	//gnome_app_construct ((GnomeApp *) grind, "alleyoop", title);
+	gtk_window_set_title ((GtkWindow *) grind, title);
 	gtk_window_set_default_size ((GtkWindow *) grind, 300, 400);
-	gnome_app_enable_layout_config ((GnomeApp *) grind, TRUE);
 	g_free (title);
 	
 	grind->tool = tool;
 	grind->argv = argv;
 	grind->srcdir = srcdir;
 	
-	/* now construct the UI */
-	gnome_app_create_menus_with_data ((GnomeApp *) grind, alleyoop_menu, grind);
+	vbox = gtk_vbox_new (FALSE, 0);
 	
-	if (tool != NULL) {
-		widget = NULL;
-		
-		for (i = 0; valgrind_tools[i].name != NULL; i++) {
-			if (!strcmp (valgrind_tools[i].name, tool)) {
-				widget = tools_menu_items[i].widget;
-				break;
-			}
-		}
-		
-		if (widget != NULL)
-			gtk_check_menu_item_set_active ((GtkCheckMenuItem *) widget, TRUE);
+	/* construct the menus */
+	grind->ui = gtk_ui_manager_new ();
+	actions = gtk_action_group_new ("MenuActions");
+	gtk_action_group_add_actions (actions, normal_menu_items, G_N_ELEMENTS (normal_menu_items), grind);
+	gtk_action_group_add_radio_actions (actions, radio_menu_items, G_N_ELEMENTS (radio_menu_items), tool,
+					    G_CALLBACK (tool_selected_cb), grind);
+	gtk_ui_manager_insert_action_group (grind->ui, actions, 0);
+	accels = gtk_ui_manager_get_accel_group (grind->ui);
+	gtk_window_add_accel_group ((GtkWindow *) grind, accels);
+	
+	if (!gtk_ui_manager_add_ui_from_string (grind->ui, menu_xml, -1, &err)) {
+		g_message ("Building menus failed: %s", err->message);
+		g_error_free (err);
+		exit (EXIT_FAILURE);
 	}
 	
+	menubar = gtk_ui_manager_get_widget (grind->ui, "/MainMenu");
+	gtk_widget_show (menubar);
+	
+	/* pack in the menubar */
+	gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0);
+	
 	widget = alleyoop_toolbar_new (grind);
-	gnome_app_set_toolbar ((GnomeApp *) grind, (GtkToolbar *) widget);
 	gtk_widget_set_sensitive (grind->toolbar_run, TRUE);
 	gtk_widget_set_sensitive (grind->toolbar_kill, FALSE);
+	gtk_widget_show (widget);
+	
+	/* pack in the toolbar */
+	gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
 	
 	grind->view = widget = vg_default_view_new ();
 	vg_tool_view_set_argv ((VgToolView *) widget, argv);
 	vg_tool_view_set_srcdir ((VgToolView *) widget, srcdir);
 	gtk_widget_show (widget);
-	gnome_app_set_contents ((GnomeApp *) grind, widget);
+	
+	/* pack in the view */
+	gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
 	
 	/* create the prefs dialog (we just don't display it) */
 	grind->prefs = alleyoop_prefs_new ();
 	g_signal_connect (grind->prefs, "response", G_CALLBACK (prefs_response_cb), grind);
 	g_signal_connect (grind->prefs, "delete-event", G_CALLBACK (prefs_delete_event), grind);
 	
+	gtk_widget_show (vbox);
+	gtk_container_add ((GtkContainer *) grind, vbox);
+	
 	return (GtkWidget *) grind;
 }
 
@@ -778,7 +781,7 @@ alleyoop_run (Alleyoop *grind, GError **err)
 	if (pipe (logfd) == -1)
 		return;
 	
-	args = alleyoop_prefs_create_argv ((AlleyoopPrefs *) grind->prefs, grind->tool);
+	args = alleyoop_prefs_create_argv ((AlleyoopPrefs *) grind->prefs, tool_names[grind->tool]);
 	
 	sprintf (logfd_arg, "--log-fd=%d", logfd[1]);
 	g_ptr_array_add (args, logfd_arg);
diff --git a/src/alleyoop.h b/src/alleyoop.h
index 902d0a3..49a0033 100644
--- a/src/alleyoop.h
+++ b/src/alleyoop.h
@@ -22,7 +22,6 @@
 #define __ALLEYOOP_H__
 
 #include <gtk/gtk.h>
-#include <libgnomeui/gnome-app.h>
 
 #include "vgerror.h"
 #include "process.h"
@@ -37,13 +36,21 @@
 typedef struct _Alleyoop Alleyoop;
 typedef struct _AlleyoopClass AlleyoopClass;
 
+typedef enum {
+	VALGRIND_TOOL_MEMCHECK,
+	VALGRIND_TOOL_ADDRCHECK,
+	VALGRIND_TOOL_CACHEGRIND,
+	VALGRIND_TOOL_HELGRIND,
+} ValgrindTool;
+
 struct _Alleyoop {
-	GnomeApp parent_object;
+	GtkWindow parent_object;
 	
-	const char *tool;
 	const char **argv;
 	const char **srcdir;
+	ValgrindTool tool;
 	
+	GtkUIManager *ui;
 	GtkWidget *view;
 	
 	GIOChannel *gio;
@@ -58,14 +65,14 @@ struct _Alleyoop {
 };
 
 struct _AlleyoopClass {
-	GnomeAppClass parent_class;
+	GtkWindowClass parent_class;
 	
 };
 
 
 GType alleyoop_get_type (void);
 
-GtkWidget *alleyoop_new (const char *tool, const char **argv, const char **srcdir);
+GtkWidget *alleyoop_new (ValgrindTool tool, const char **argv, const char **srcdir);
 
 void alleyoop_run (Alleyoop *alleyoop, GError **err);
 void alleyoop_kill (Alleyoop *alleyoop);
diff --git a/src/main.c b/src/main.c
index c21f220..f3ad997 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,7 +84,7 @@ add_subdirs (GPtrArray *srcdir, GPtrArray *gc, const char *topsrcdir)
 }
 
 
-static const char *tool = NULL;
+static ValgrindTool tool = VALGRIND_TOOL_MEMCHECK;
 static GPtrArray *srcdir, *gc;
 
 static void
@@ -141,16 +141,14 @@ static int
 use_tool (GetOptsContext *ctx, GetOptsOption *opt, const char *arg, void *valuep)
 {
 	if (!g_ascii_strcasecmp (arg, "memcheck")) {
-		/* default */
-		tool = NULL;
+		tool = VALGRIND_TOOL_MEMCHECK;
 	} else if (!g_ascii_strcasecmp (arg, "addrcheck")) {
-		tool = "addrcheck";
+		tool = VALGRIND_TOOL_ADDRCHECK;
 	} else if (!g_ascii_strcasecmp (arg, "cachegrind")) {
-		/*tool = "cachegrind";*/
 		fprintf (stderr, "%s is currently an unsupported tool\n", arg);
+		/*tool = VALGRIND_TOOL_CACHEGRIND;*/
 	} else if (!g_ascii_strcasecmp (arg, "helgrind")) {
-		/*tool = "helgrind";*/
-		fprintf (stderr, "%s is currently an unsupported tool\n", arg);
+		tool = VALGRIND_TOOL_HELGRIND;
 	} else {
 		fprintf (stderr, "Unknown tool: %s\n", arg);
 		shutdown ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]