Home | History | Annotate | Download | only in gui
      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
     19 import string
     20 import gtk
     21 import gtk.glade
     22 import os
     23 import gobject
     24 import sys
     25 import seobject
     26 
     27 ##
     28 ## I18N
     29 ##
     30 PROGNAME="policycoreutils"
     31 import gettext
     32 gettext.bindtextdomain(PROGNAME, "/usr/share/locale")
     33 gettext.textdomain(PROGNAME)
     34 try:
     35     gettext.install(PROGNAME,
     36                     localedir="/usr/share/locale",
     37                     unicode=False,
     38                     codeset = 'utf-8')
     39 except IOError:
     40     import __builtin__
     41     __builtin__.__dict__['_'] = unicode
     42 
     43 def idle_func():
     44     while gtk.events_pending():
     45         gtk.main_iteration()
     46 
     47 class semanagePage:
     48     def __init__(self, xml, name, description):
     49         self.xml = xml
     50         self.window = self.xml.get_widget("mainWindow").get_root_window()
     51         self.busy_cursor = gtk.gdk.Cursor(gtk.gdk.WATCH)
     52         self.ready_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
     53 
     54         self.local = False
     55         self.view = xml.get_widget("%sView" % name)
     56         self.dialog = xml.get_widget("%sDialog" % name)
     57         self.filter_entry = xml.get_widget("%sFilterEntry" % name )
     58         self.filter_entry.connect("focus_out_event", self.filter_changed)
     59         self.filter_entry.connect("activate", self.filter_changed)
     60 
     61         self.view.connect("row_activated", self.rowActivated)
     62         self.view.get_selection().connect("changed", self.itemSelected)
     63         self.description = description;
     64 
     65     def wait(self):
     66         self.window.set_cursor(self.busy_cursor)
     67         idle_func()
     68 
     69     def ready(self):
     70         self.window.set_cursor(self.ready_cursor)
     71         idle_func()
     72 
     73     def get_description(self):
     74         return self.description
     75 
     76     def itemSelected(self, args):
     77         return
     78 
     79     def filter_changed(self, *arg):
     80         filter =  arg[0].get_text()
     81         if filter != self.filter:
     82             self.load(filter)
     83 
     84     def search(self, model, col, key, i):
     85         sort_col = self.store.get_sort_column_id()[0]
     86         val = model.get_value(i,sort_col)
     87         if val.lower().startswith(key.lower()):
     88             return False
     89         return True
     90 
     91     def match(self, target, filter):
     92         try:
     93             f=filter.lower()
     94             t=target.lower()
     95             if t.find(f) >= 0:
     96                 return True
     97         except:
     98             pass
     99         return False
    100 
    101     def rowActivated(self, view, row, Column):
    102         self.propertiesDialog()
    103 
    104     def verify(self, message, title="" ):
    105         dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO,
    106                                 gtk.BUTTONS_YES_NO,
    107                                 message)
    108         dlg.set_title(title)
    109         dlg.set_position(gtk.WIN_POS_MOUSE)
    110         dlg.show_all()
    111         rc = dlg.run()
    112         dlg.destroy()
    113         return rc
    114 
    115     def error(self, message):
    116         dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
    117                                 gtk.BUTTONS_CLOSE,
    118                                 message)
    119         dlg.set_position(gtk.WIN_POS_MOUSE)
    120         dlg.show_all()
    121         dlg.run()
    122         dlg.destroy()
    123 
    124     def deleteDialog(self):
    125         store, iter = self.view.get_selection().get_selected()
    126         if self.verify(_("Are you sure you want to delete %s '%s'?" % (self.description, store.get_value(iter, 0))), _("Delete %s" % self.description)) == gtk.RESPONSE_YES:
    127             self.delete()
    128 
    129     def use_menus(self):
    130         return True
    131 
    132     def addDialog(self):
    133         self.dialogClear()
    134         self.dialog.set_title(_("Add %s" % self.description))
    135         self.dialog.set_position(gtk.WIN_POS_MOUSE)
    136 
    137         while self.dialog.run() ==  gtk.RESPONSE_OK:
    138             try:
    139                 if self.add() == False:
    140                     continue
    141                 break;
    142             except ValueError, e:
    143                 self.error(e.args[0])
    144         self.dialog.hide()
    145 
    146     def propertiesDialog(self):
    147         self.dialogInit()
    148         self.dialog.set_title(_("Modify %s" % self.description))
    149         self.dialog.set_position(gtk.WIN_POS_MOUSE)
    150         while self.dialog.run() ==  gtk.RESPONSE_OK:
    151             try:
    152                 if self.modify() == False:
    153                     continue
    154                 break;
    155             except ValueError, e:
    156                 self.error(e.args[0])
    157         self.dialog.hide()
    158 
    159     def on_local_clicked(self, button):
    160         self.local = not self.local
    161         if self.local:
    162             button.set_label(_("all"))
    163         else:
    164             button.set_label(_("Customized"))
    165 
    166         self.load(self.filter)
    167         return True
    168