mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-04 00:05:14 +00:00
* Added context menu to event list
- Provides remove/profile options * Added initial profiler tool launcher
This commit is contained in:
@@ -242,9 +242,8 @@ void applet_about(BonoboUIComponent * uic)
|
|||||||
{
|
{
|
||||||
const gchar *license =
|
const gchar *license =
|
||||||
_("AppArmorApplet is free software; you can redistribute it and/or modify\n"
|
_("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"
|
"it under the terms of the GNU General Public License, version 2, as published by\n"
|
||||||
"the Free Software Foundation; either version 2 of the License, or\n"
|
"the Free Software Foundation.");
|
||||||
"(at your option) any later version.");
|
|
||||||
|
|
||||||
const gchar *authors[] = {
|
const gchar *authors[] = {
|
||||||
"Matt Barringer <mbarringer@suse.de>",
|
"Matt Barringer <mbarringer@suse.de>",
|
||||||
@@ -292,17 +291,18 @@ gboolean on_button_press (GtkWidget *event_box,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reject_button_press (GtkDialog * dialog, gint answer, gpointer data)
|
/* Decrement the event count and reset the icon/tooltip state if necessary */
|
||||||
|
void decrement_event_count(gint decrement)
|
||||||
{
|
{
|
||||||
if (answer == GTK_RESPONSE_OK || answer == GTK_RESPONSE_CANCEL)
|
apparmor_applet->alert_count = apparmor_applet->alert_count - decrement;
|
||||||
{
|
|
||||||
gtk_widget_hide(apparmor_applet->reject_dialog);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void reject_window_close (GtkDialog * dialog, gpointer data)
|
if (apparmor_applet->alert_count <= 0)
|
||||||
{
|
{
|
||||||
gtk_widget_hide(apparmor_applet->reject_dialog);
|
apparmor_applet->alert_count= 0;
|
||||||
|
apparmor_applet->uncleared_alerts = FALSE;
|
||||||
|
set_appropriate_icon();
|
||||||
|
set_tooltip();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PANEL_APPLET_BONOBO_FACTORY("OAFIID:AppArmorApplet_Factory",
|
PANEL_APPLET_BONOBO_FACTORY("OAFIID:AppArmorApplet_Factory",
|
||||||
|
@@ -1,6 +1,12 @@
|
|||||||
#ifndef __APPARMOR_APPLET_H
|
#ifndef __APPARMOR_APPLET_H
|
||||||
#define __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
|
struct _apparmor_applet
|
||||||
{
|
{
|
||||||
GtkWidget *applet;
|
GtkWidget *applet;
|
||||||
@@ -26,7 +32,6 @@ gboolean on_button_press (GtkWidget *event_box,
|
|||||||
GdkEventButton *event,
|
GdkEventButton *event,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
void insert_into_list(char *name);
|
void insert_into_list(char *name);
|
||||||
void reject_button_press (GtkDialog * dialog, gint answer, gpointer data);
|
void decrement_event_count(gint decrement);
|
||||||
void reject_window_close (GtkDialog * dialog, gpointer data);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -10,7 +10,11 @@
|
|||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
#include <gconf/gconf-client.h>
|
||||||
#include "preferences_dialog.h"
|
#include "preferences_dialog.h"
|
||||||
|
#include "apparmor-applet.h"
|
||||||
|
|
||||||
|
GtkWidget *profile_combobox;
|
||||||
|
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
create_preferences_dialog (void)
|
create_preferences_dialog (void)
|
||||||
@@ -20,11 +24,15 @@ create_preferences_dialog (void)
|
|||||||
GtkWidget *layout_table;
|
GtkWidget *layout_table;
|
||||||
GtkWidget *profile_label;
|
GtkWidget *profile_label;
|
||||||
GtkWidget *path_label;
|
GtkWidget *path_label;
|
||||||
GtkWidget *path_entry;
|
|
||||||
GtkWidget *profile_combobox;
|
|
||||||
GtkWidget *preferences_buttonbox;
|
GtkWidget *preferences_buttonbox;
|
||||||
GtkWidget *cancel_button;
|
GtkWidget *cancel_button;
|
||||||
GtkWidget *ok_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 ();
|
preferences_dialog = gtk_dialog_new ();
|
||||||
gtk_widget_set_name (preferences_dialog, "preferences_dialog");
|
gtk_widget_set_name (preferences_dialog, "preferences_dialog");
|
||||||
@@ -67,6 +75,7 @@ create_preferences_dialog (void)
|
|||||||
(GtkAttachOptions) (0), 0, 0);
|
(GtkAttachOptions) (0), 0, 0);
|
||||||
gtk_entry_set_invisible_char (GTK_ENTRY (path_entry), 9679);
|
gtk_entry_set_invisible_char (GTK_ENTRY (path_entry), 9679);
|
||||||
|
|
||||||
|
|
||||||
profile_combobox = gtk_combo_box_new_text ();
|
profile_combobox = gtk_combo_box_new_text ();
|
||||||
gtk_widget_set_name (profile_combobox, "profile_combobox");
|
gtk_widget_set_name (profile_combobox, "profile_combobox");
|
||||||
gtk_widget_show (profile_combobox);
|
gtk_widget_show (profile_combobox);
|
||||||
@@ -75,6 +84,7 @@ create_preferences_dialog (void)
|
|||||||
(GtkAttachOptions) (GTK_FILL), 0, 0);
|
(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), _("YAST"));
|
||||||
gtk_combo_box_append_text (GTK_COMBO_BOX (profile_combobox), _("genprof"));
|
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;
|
preferences_buttonbox = GTK_DIALOG (preferences_dialog)->action_area;
|
||||||
gtk_widget_set_name (preferences_buttonbox, "preferences_buttonbox");
|
gtk_widget_set_name (preferences_buttonbox, "preferences_buttonbox");
|
||||||
@@ -99,10 +109,21 @@ create_preferences_dialog (void)
|
|||||||
return preferences_dialog;
|
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 || 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));
|
gtk_widget_destroy(GTK_WIDGET(dialog));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,8 +6,10 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <gconf/gconf-client.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <panel-applet.h>
|
#include <panel-applet.h>
|
||||||
|
#include <libgnome/libgnome.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
#include <gtk/gtk.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_dialog_add_action_widget (GTK_DIALOG (reject_dialog), ok_button, GTK_RESPONSE_OK);
|
||||||
GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
|
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),
|
G_CALLBACK(reject_button_press),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_signal_connect(reject_dialog, "delete-event",
|
g_signal_connect(reject_dialog,
|
||||||
|
"delete-event",
|
||||||
G_CALLBACK(reject_window_close),
|
G_CALLBACK(reject_window_close),
|
||||||
NULL);
|
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_widget_grab_focus (program_list);
|
||||||
|
gtk_window_set_default_size(GTK_WINDOW(reject_dialog), 500, 400);
|
||||||
return reject_dialog;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -2,5 +2,12 @@
|
|||||||
#define REJECT_LIST_H
|
#define REJECT_LIST_H
|
||||||
|
|
||||||
GtkWidget* create_reject_dialog (GtkListStore *store);
|
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
|
#endif
|
||||||
|
Reference in New Issue
Block a user