1## semanagePage.py - show selinux mappings 2## Copyright (C) 2006 Red Hat, Inc. 3 4## This program is free software; you can redistribute it and/or modify 5## it under the terms of the GNU General Public License as published by 6## the Free Software Foundation; either version 2 of the License, or 7## (at your option) any later version. 8 9## This program is distributed in the hope that it will be useful, 10## but WITHOUT ANY WARRANTY; without even the implied warranty of 11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12## GNU General Public License for more details. 13 14## You should have received a copy of the GNU General Public License 15## along with this program; if not, write to the Free Software 16## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 18## Author: Dan Walsh 19import string 20import gtk 21import gtk.glade 22import os 23import gobject 24import sys 25import seobject 26 27## 28## I18N 29## 30PROGNAME = "policycoreutils" 31try: 32 import gettext 33 kwargs = {} 34 if sys.version_info < (3,): 35 kwargs['unicode'] = True 36 gettext.install(PROGNAME, 37 localedir="/usr/share/locale", 38 codeset='utf-8', 39 **kwargs) 40except: 41 try: 42 import builtins 43 builtins.__dict__['_'] = str 44 except ImportError: 45 import __builtin__ 46 __builtin__.__dict__['_'] = unicode 47 48 49def idle_func(): 50 while gtk.events_pending(): 51 gtk.main_iteration() 52 53 54class semanagePage: 55 56 def __init__(self, xml, name, description): 57 self.xml = xml 58 self.window = self.xml.get_widget("mainWindow").get_root_window() 59 self.busy_cursor = gtk.gdk.Cursor(gtk.gdk.WATCH) 60 self.ready_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR) 61 62 self.local = False 63 self.view = xml.get_widget("%sView" % name) 64 self.dialog = xml.get_widget("%sDialog" % name) 65 self.filter_entry = xml.get_widget("%sFilterEntry" % name) 66 self.filter_entry.connect("focus_out_event", self.filter_changed) 67 self.filter_entry.connect("activate", self.filter_changed) 68 69 self.view.connect("row_activated", self.rowActivated) 70 self.view.get_selection().connect("changed", self.itemSelected) 71 self.description = description 72 73 def wait(self): 74 self.window.set_cursor(self.busy_cursor) 75 idle_func() 76 77 def ready(self): 78 self.window.set_cursor(self.ready_cursor) 79 idle_func() 80 81 def get_description(self): 82 return self.description 83 84 def itemSelected(self, args): 85 return 86 87 def filter_changed(self, *arg): 88 filter = arg[0].get_text() 89 if filter != self.filter: 90 self.load(filter) 91 92 def search(self, model, col, key, i): 93 sort_col = self.store.get_sort_column_id()[0] 94 val = model.get_value(i, sort_col) 95 if val.lower().startswith(key.lower()): 96 return False 97 return True 98 99 def match(self, target, filter): 100 try: 101 f = filter.lower() 102 t = target.lower() 103 if t.find(f) >= 0: 104 return True 105 except: 106 pass 107 return False 108 109 def rowActivated(self, view, row, Column): 110 self.propertiesDialog() 111 112 def verify(self, message, title=""): 113 dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, 114 gtk.BUTTONS_YES_NO, 115 message) 116 dlg.set_title(title) 117 dlg.set_position(gtk.WIN_POS_MOUSE) 118 dlg.show_all() 119 rc = dlg.run() 120 dlg.destroy() 121 return rc 122 123 def error(self, message): 124 dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, 125 gtk.BUTTONS_CLOSE, 126 message) 127 dlg.set_position(gtk.WIN_POS_MOUSE) 128 dlg.show_all() 129 dlg.run() 130 dlg.destroy() 131 132 def deleteDialog(self): 133 store, it = self.view.get_selection().get_selected() 134 if (it is not None) and (self.verify(_("Are you sure you want to delete %s '%s'?" % (self.description, store.get_value(it, 0))), _("Delete %s" % self.description)) == gtk.RESPONSE_YES): 135 self.delete() 136 137 def use_menus(self): 138 return True 139 140 def addDialog(self): 141 self.dialogClear() 142 self.dialog.set_title(_("Add %s" % self.description)) 143 self.dialog.set_position(gtk.WIN_POS_MOUSE) 144 145 while self.dialog.run() == gtk.RESPONSE_OK: 146 try: 147 if self.add() == False: 148 continue 149 break 150 except ValueError as e: 151 self.error(e.args[0]) 152 self.dialog.hide() 153 154 def propertiesDialog(self): 155 self.dialogInit() 156 self.dialog.set_title(_("Modify %s" % self.description)) 157 self.dialog.set_position(gtk.WIN_POS_MOUSE) 158 while self.dialog.run() == gtk.RESPONSE_OK: 159 try: 160 if self.modify() == False: 161 continue 162 break 163 except ValueError as e: 164 self.error(e.args[0]) 165 self.dialog.hide() 166 167 def on_local_clicked(self, button): 168 self.local = not self.local 169 if self.local: 170 button.set_label(_("all")) 171 else: 172 button.set_label(_("Customized")) 173 174 self.load(self.filter) 175 return True 176