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 
     44 def idle_func():
     45     while gtk.events_pending():
     46         gtk.main_iteration()
     47 
     48 
     49 class semanagePage:
     50 
     51     def __init__(self, xml, name, description):
     52         self.xml = xml
     53         self.window = self.xml.get_widget("mainWindow").get_root_window()
     54         self.busy_cursor = gtk.gdk.Cursor(gtk.gdk.WATCH)
     55         self.ready_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
     56 
     57         self.local = False
     58         self.view = xml.get_widget("%sView" % name)
     59         self.dialog = xml.get_widget("%sDialog" % name)
     60         self.filter_entry = xml.get_widget("%sFilterEntry" % name)
     61         self.filter_entry.connect("focus_out_event", self.filter_changed)
     62         self.filter_entry.connect("activate", self.filter_changed)
     63 
     64         self.view.connect("row_activated", self.rowActivated)
     65         self.view.get_selection().connect("changed", self.itemSelected)
     66         self.description = description
     67 
     68     def wait(self):
     69         self.window.set_cursor(self.busy_cursor)
     70         idle_func()
     71 
     72     def ready(self):
     73         self.window.set_cursor(self.ready_cursor)
     74         idle_func()
     75 
     76     def get_description(self):
     77         return self.description
     78 
     79     def itemSelected(self, args):
     80         return
     81 
     82     def filter_changed(self, *arg):
     83         filter = arg[0].get_text()
     84         if filter != self.filter:
     85             self.load(filter)
     86 
     87     def search(self, model, col, key, i):
     88         sort_col = self.store.get_sort_column_id()[0]
     89         val = model.get_value(i, sort_col)
     90         if val.lower().startswith(key.lower()):
     91             return False
     92         return True
     93 
     94     def match(self, target, filter):
     95         try:
     96             f = filter.lower()
     97             t = target.lower()
     98             if t.find(f) >= 0:
     99                 return True
    100         except:
    101             pass
    102         return False
    103 
    104     def rowActivated(self, view, row, Column):
    105         self.propertiesDialog()
    106 
    107     def verify(self, message, title=""):
    108         dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO,
    109                                 gtk.BUTTONS_YES_NO,
    110                                 message)
    111         dlg.set_title(title)
    112         dlg.set_position(gtk.WIN_POS_MOUSE)
    113         dlg.show_all()
    114         rc = dlg.run()
    115         dlg.destroy()
    116         return rc
    117 
    118     def error(self, message):
    119         dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
    120                                 gtk.BUTTONS_CLOSE,
    121                                 message)
    122         dlg.set_position(gtk.WIN_POS_MOUSE)
    123         dlg.show_all()
    124         dlg.run()
    125         dlg.destroy()
    126 
    127     def deleteDialog(self):
    128         store, iter = self.view.get_selection().get_selected()
    129         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:
    130             self.delete()
    131 
    132     def use_menus(self):
    133         return True
    134 
    135     def addDialog(self):
    136         self.dialogClear()
    137         self.dialog.set_title(_("Add %s" % self.description))
    138         self.dialog.set_position(gtk.WIN_POS_MOUSE)
    139 
    140         while self.dialog.run() == gtk.RESPONSE_OK:
    141             try:
    142                 if self.add() == False:
    143                     continue
    144                 break
    145             except ValueError, e:
    146                 self.error(e.args[0])
    147         self.dialog.hide()
    148 
    149     def propertiesDialog(self):
    150         self.dialogInit()
    151         self.dialog.set_title(_("Modify %s" % self.description))
    152         self.dialog.set_position(gtk.WIN_POS_MOUSE)
    153         while self.dialog.run() == gtk.RESPONSE_OK:
    154             try:
    155                 if self.modify() == False:
    156                     continue
    157                 break
    158             except ValueError, e:
    159                 self.error(e.args[0])
    160         self.dialog.hide()
    161 
    162     def on_local_clicked(self, button):
    163         self.local = not self.local
    164         if self.local:
    165             button.set_label(_("all"))
    166         else:
    167             button.set_label(_("Customized"))
    168 
    169         self.load(self.filter)
    170         return True
    171