2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 14:25:52 +00:00

* Added context menu to event list

- Provides remove/profile options
* Added initial profiler tool launcher
This commit is contained in:
Matt Barringer
2007-02-07 01:49:43 +00:00
parent ab28d03039
commit fbdd2ade3f
5 changed files with 373 additions and 174 deletions

View File

@@ -242,9 +242,8 @@ void applet_about(BonoboUIComponent * uic)
{
const gchar *license =
_("AppArmorApplet is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
"(at your option) any later version.");
"it under the terms of the GNU General Public License, version 2, as published by\n"
"the Free Software Foundation.");
const gchar *authors[] = {
"Matt Barringer <mbarringer@suse.de>",
@@ -274,7 +273,7 @@ void applet_prefs (BonoboUIComponent *uic)
gboolean on_button_press (GtkWidget *event_box,
GdkEventButton *event,
gpointer data)
{
{
if (event->button != 1)
return FALSE;
@@ -290,19 +289,20 @@ gboolean on_button_press (GtkWidget *event_box,
}
return TRUE;
}
void reject_button_press (GtkDialog * dialog, gint answer, gpointer data)
{
if (answer == GTK_RESPONSE_OK || answer == GTK_RESPONSE_CANCEL)
{
gtk_widget_hide(apparmor_applet->reject_dialog);
}
}
void reject_window_close (GtkDialog * dialog, gpointer data)
/* Decrement the event count and reset the icon/tooltip state if necessary */
void decrement_event_count(gint decrement)
{
gtk_widget_hide(apparmor_applet->reject_dialog);
apparmor_applet->alert_count = apparmor_applet->alert_count - decrement;
if (apparmor_applet->alert_count <= 0)
{
apparmor_applet->alert_count= 0;
apparmor_applet->uncleared_alerts = FALSE;
set_appropriate_icon();
set_tooltip();
}
}
PANEL_APPLET_BONOBO_FACTORY("OAFIID:AppArmorApplet_Factory",

View File

@@ -1,6 +1,12 @@
#ifndef __APPARMOR_APPLET_H
#define __APPARMOR_APPLET_H
#include <panel-applet.h>
#define CONF_PATH "/apps/AppArmor/apparmor-applet"
#define CONF_PROFILE_KEY "/apps/AppArmor/apparmor-applet/profiler"
#define CONF_PATH_KEY "/apps/AppArmor/apparmor-applet/path"
struct _apparmor_applet
{
GtkWidget *applet;
@@ -26,7 +32,6 @@ gboolean on_button_press (GtkWidget *event_box,
GdkEventButton *event,
gpointer data);
void insert_into_list(char *name);
void reject_button_press (GtkDialog * dialog, gint answer, gpointer data);
void reject_window_close (GtkDialog * dialog, gpointer data);
void decrement_event_count(gint decrement);
#endif

View File

@@ -1,5 +1,5 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <sys/types.h>
@@ -10,7 +10,11 @@
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <gconf/gconf-client.h>
#include "preferences_dialog.h"
#include "apparmor-applet.h"
GtkWidget *profile_combobox;
GtkWidget*
create_preferences_dialog (void)
@@ -20,11 +24,15 @@ create_preferences_dialog (void)
GtkWidget *layout_table;
GtkWidget *profile_label;
GtkWidget *path_label;
GtkWidget *path_entry;
GtkWidget *profile_combobox;
GtkWidget *preferences_buttonbox;
GtkWidget *cancel_button;
GtkWidget *ok_button;
GtkWidget *path_entry;
GConfClient *client;
int active_combo;
client = gconf_client_get_default();
active_combo = gconf_client_get_int(client, CONF_PROFILE_KEY, NULL);
preferences_dialog = gtk_dialog_new ();
gtk_widget_set_name (preferences_dialog, "preferences_dialog");
@@ -67,6 +75,7 @@ create_preferences_dialog (void)
(GtkAttachOptions) (0), 0, 0);
gtk_entry_set_invisible_char (GTK_ENTRY (path_entry), 9679);
profile_combobox = gtk_combo_box_new_text ();
gtk_widget_set_name (profile_combobox, "profile_combobox");
gtk_widget_show (profile_combobox);
@@ -75,6 +84,7 @@ create_preferences_dialog (void)
(GtkAttachOptions) (GTK_FILL), 0, 0);
gtk_combo_box_append_text (GTK_COMBO_BOX (profile_combobox), _("YAST"));
gtk_combo_box_append_text (GTK_COMBO_BOX (profile_combobox), _("genprof"));
gtk_combo_box_set_active(GTK_COMBO_BOX(profile_combobox), active_combo);
preferences_buttonbox = GTK_DIALOG (preferences_dialog)->action_area;
gtk_widget_set_name (preferences_buttonbox, "preferences_buttonbox");
@@ -99,10 +109,21 @@ create_preferences_dialog (void)
return preferences_dialog;
}
void button_press (GtkDialog * dialog, gint answer, gpointer data)
void
button_press (GtkDialog * dialog, gint answer, gpointer data)
{
if (answer == GTK_RESPONSE_OK || answer == GTK_RESPONSE_CANCEL)
{
if (answer == GTK_RESPONSE_OK)
{
int active = gtk_combo_box_get_active (GTK_COMBO_BOX(profile_combobox));
if (active <= -1)
active = 0;
GConfClient *client;
client = gconf_client_get_default();
gconf_client_set_int(client, CONF_PROFILE_KEY, active, NULL);
}
gtk_widget_destroy(GTK_WIDGET(dialog));
}
}

View File

@@ -1,13 +1,15 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <gconf/gconf-client.h>
#include <stdio.h>
#include <panel-applet.h>
#include <libgnome/libgnome.h>
#include <glib/gi18n.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
@@ -93,14 +95,178 @@ create_reject_dialog (GtkListStore *store)
gtk_dialog_add_action_widget (GTK_DIALOG (reject_dialog), ok_button, GTK_RESPONSE_OK);
GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
g_signal_connect(reject_dialog, "response",
g_signal_connect(reject_dialog,
"response",
G_CALLBACK(reject_button_press),
NULL);
g_signal_connect(reject_dialog, "delete-event",
g_signal_connect(reject_dialog,
"delete-event",
G_CALLBACK(reject_window_close),
NULL);
g_signal_connect(program_list,
"button-press-event",
G_CALLBACK(popup_button_pressed),
NULL);
g_signal_connect(program_list,
"popup-menu",
G_CALLBACK(view_on_popup_menu),
NULL);
gtk_widget_grab_focus (program_list);
gtk_window_set_default_size(GTK_WINDOW(reject_dialog), 500, 400);
return reject_dialog;
}
void reject_button_press (GtkDialog * dialog, gint answer, gpointer data)
{
if (answer == GTK_RESPONSE_OK || answer == GTK_RESPONSE_CANCEL)
{
gtk_widget_hide(GTK_WIDGET(dialog));
}
}
void reject_window_close (GtkDialog * dialog, gpointer data)
{
gtk_widget_hide(GTK_WIDGET(dialog));
}
void
handle_popup_profile (GtkWidget *menuitem, gpointer userdata)
{
GtkTreeView *treeview = GTK_TREE_VIEW(userdata);
GConfClient *client = gconf_client_get_default();
int profiler_type = gconf_client_get_int(client, CONF_PROFILE_KEY, NULL);
char *cmdline;
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
GtkTreeIter iter;
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
gchar *str_data = NULL;
if (gtk_tree_selection_get_selected(selection, &model, &iter) == TRUE)
{
gint int_data;
GtkListStore *store = GTK_LIST_STORE(model);
gtk_tree_model_get (model, &iter,
0, &str_data,
1, &int_data,
-1);
}
// 0 is YAST, 1 is genprof
if ((profiler_type == 0) && (str_data != NULL))
{
cmdline = "/opt/gnome/bin/gnomesu /sbin/yast2 LogProf";
gnome_execute_terminal_shell(NULL, cmdline);
}
else if ((profiler_type == 1) && (str_data != NULL))
{
/* /usr/sbin/genprof */
cmdline = (char *) malloc(41 + strlen(str_data));
strcpy(cmdline, "/opt/gnome/bin/gnomesu /usr/sbin/genprof ");
strcat(cmdline, str_data);
gnome_execute_terminal_shell(NULL, cmdline);
free(cmdline);
}
if (str_data != NULL)
g_free (str_data);
}
void
handle_popup_remove (GtkWidget *menuitem, gpointer userdata)
{
GtkTreeView *treeview = GTK_TREE_VIEW(userdata);
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
GtkTreeIter iter;
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
if (gtk_tree_selection_get_selected(selection, &model, &iter) == TRUE)
{
gchar *str_data;
gint int_data;
GtkListStore *store = GTK_LIST_STORE(model);
gtk_tree_model_get (model, &iter,
0, &str_data,
1, &int_data,
-1);
g_free (str_data);
decrement_event_count(int_data);
gtk_list_store_remove(store, &iter);
}
}
void
display_popup_menu (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
{
GtkWidget *menu, *remove_item, *profile_item;
menu = gtk_menu_new();
profile_item = gtk_menu_item_new_with_label(_("Profile application"));
remove_item = gtk_menu_item_new_with_label(_("Remove from list"));
g_signal_connect(remove_item,
"activate",
G_CALLBACK(handle_popup_remove),
treeview);
g_signal_connect(profile_item,
"activate",
G_CALLBACK(handle_popup_profile),
treeview);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), profile_item);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), remove_item);
gtk_widget_show_all(menu);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
(event != NULL) ? event->button : 0,
gdk_event_get_time((GdkEvent*)event));
}
gboolean
popup_button_pressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
{
if (event->type == GDK_BUTTON_PRESS && event->button == 3)
{
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
if (gtk_tree_selection_count_selected_rows(selection) <= 1)
{
GtkTreePath *path;
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview),
(gint) event->x,
(gint) event->y,
&path, NULL, NULL, NULL))
{
gtk_tree_selection_unselect_all(selection);
gtk_tree_selection_select_path(selection, path);
gtk_tree_path_free(path);
}
}
display_popup_menu(treeview, event, userdata);
return TRUE;
}
return FALSE;
}
gboolean
view_on_popup_menu (GtkWidget *treeview, gpointer userdata)
{
display_popup_menu(treeview, NULL, userdata);
return TRUE;
}

View File

@@ -2,5 +2,12 @@
#define REJECT_LIST_H
GtkWidget* create_reject_dialog (GtkListStore *store);
void reject_button_press (GtkDialog * dialog, gint answer, gpointer data);
void reject_window_close (GtkDialog * dialog, gpointer data);
void handle_popup_profile (GtkWidget *menuitem, gpointer userdata);
void handle_popup_remove (GtkWidget *menuitem, gpointer userdata);
void display_popup_menu (GtkWidget *treeview, GdkEventButton *event, gpointer userdata);
gboolean popup_button_pressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata);
gboolean view_on_popup_menu (GtkWidget *treeview, gpointer userdata);
#endif