Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
serversettings.ServerSettings Class Reference
Inheritance diagram for serversettings.ServerSettings:
Inheritance graph
[legend]
Collaboration diagram for serversettings.ServerSettings:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_dialog
def problems_clicked
def on_server_changed
def on_treeview_selection_changed
def on_add_clicked
def on_browse_poll_edited
def on_browse_poll_edit_cancel
def on_remove_clicked
def on_response
def saveAdvanced
def saveBasic
def getWidgets

Public Attributes

 cupsconn
 handler_ids
 dialog
 browse_treeview
 add
 remove
 browse_poll
 preserve_job_history
 preserve_job_files
 changed
 server_settings
 server_is_publishing

Static Public Attributes

string RESOURCE = "/admin/conf/cupsd.conf"

Private Member Functions

def _fillAdvanced
def _fillBasic
def _connect
def _disconnect
def _reconnect

Private Attributes

 _host
 _parent

Static Private Attributes

dictionary __gsignals__

Detailed Description

Definition at line 58 of file serversettings.py.


Constructor & Destructor Documentation

def serversettings.ServerSettings.__init__ (   self,
  host = None,
  encryption = None,
  parent = None 
)

Definition at line 68 of file serversettings.py.

00068 
00069     def __init__ (self, host=None, encryption=None, parent=None):
00070         gobject.GObject.__init__ (self)
00071         self.cupsconn = authconn.Connection (host=host, encryption=encryption)
00072         self._host = host
00073         self._parent = parent
00074         self.getWidgets({"ServerSettingsDialog":
00075                              ["ServerSettingsDialog",
00076                               "chkServerBrowse",
00077                               "chkServerShare",
00078                               "chkServerShareAny",
00079                               "chkServerRemoteAdmin",
00080                               "chkServerAllowCancelAll",
00081                               "chkServerLogDebug",
00082                               "hboxServerBrowse",
00083                               "rbPreserveJobFiles",
00084                               "rbPreserveJobHistory",
00085                               "rbPreserveJobNone",
00086                               "tvBrowseServers",
00087                               "frameBrowseServers",
00088                               "btAdvServerAdd",
00089                               "btAdvServerRemove"]},
00090 
00091                         domain=config.PACKAGE)
00092 
00093         problems = _UnobtrusiveButton (label=_("Problems?"))
00094         self.hboxServerBrowse.pack_end (problems, False, False, 0)
00095         problems.connect ('clicked', self.problems_clicked)
00096         problems.show ()
00097 
00098         self.ServerSettingsDialog.connect ('response', self.on_response)
00099 
00100         # Signal handler IDs.
00101         self.handler_ids = {}
00102 
00103         self.dialog = self.ServerSettingsDialog
00104         self.browse_treeview = self.tvBrowseServers
00105         self.add = self.btAdvServerAdd
00106         self.remove = self.btAdvServerRemove
00107 
00108         selection = self.browse_treeview.get_selection ()
00109         selection.set_mode (gtk.SELECTION_MULTIPLE)
00110         self._connect (selection, 'changed', self.on_treeview_selection_changed)
00111 
00112         for column in self.browse_treeview.get_columns():
00113             self.browse_treeview.remove_column(column)
00114         col = gtk.TreeViewColumn ('', gtk.CellRendererText (), text=0)
00115         self.browse_treeview.append_column (col)
00116 
00117         self._fillAdvanced ()
00118         self._fillBasic ()
00119 
00120         if parent:
00121             self.dialog.set_transient_for (parent)
00122 
00123         self.dialog.show ()


Member Function Documentation

def serversettings.ServerSettings._connect (   self,
  widget,
  signal,
  handler,
  reason = None 
) [private]

Definition at line 244 of file serversettings.py.

00244 
00245     def _connect (self, widget, signal, handler, reason=None):
00246         id = widget.connect (signal, handler)
00247         if not self.handler_ids.has_key (reason):
00248             self.handler_ids[reason] = []
00249         self.handler_ids[reason].append ((widget, id))

Here is the caller graph for this function:

def serversettings.ServerSettings._disconnect (   self,
  reason = None 
) [private]

Definition at line 250 of file serversettings.py.

00250 
00251     def _disconnect (self, reason=None):
00252         if self.handler_ids.has_key (reason):
00253             for (widget, id) in self.handler_ids[reason]:
00254                 widget.disconnect (id)
00255             del self.handler_ids[reason]

Here is the caller graph for this function:

Definition at line 130 of file serversettings.py.

00130 
00131     def _fillAdvanced(self):
00132         # Fetch cupsd.conf
00133         f = tempfile.TemporaryFile ()
00134         try:
00135             self.cupsconn.getFile (self.RESOURCE, file=f)
00136         except cups.HTTPError, (s,):
00137             show_HTTP_Error (s, self._parent)
00138             raise
00139 
00140         def parse_yesno (line):
00141             arg1 = line.split (' ')[1].strip ()
00142             if arg1 in ['true', 'on', 'enabled', 'yes']:
00143                 return True
00144             if arg1 in ['false', 'off', 'disabled', 'no', '0']:
00145                 return False
00146             try:
00147                 if int (arg1) != 0:
00148                     return True
00149             except:
00150                 pass
00151             raise RuntimeError
00152 
00153         preserve_job_history = True
00154         preserve_job_files = False
00155         browsing = True
00156         self.browse_poll = []
00157         f.seek (0)
00158         for line in f.readlines ():
00159             l = line.lower ().strip ()
00160             if l.startswith ("preservejobhistory "):
00161                 try:
00162                     preserve_job_history = parse_yesno (l)
00163                 except:
00164                     pass
00165             elif l.startswith ("preservejobfiles "):
00166                 try:
00167                     preserve_job_files = parse_yesno (l)
00168                 except:
00169                     pass
00170             elif l.startswith ("browsing "):
00171                 try:
00172                     browsing = parse_yesno (l)
00173                 except:
00174                     pass
00175             elif l.startswith ("browsepoll "):
00176                 self.browse_poll.append (line[len ("browsepoll "):].strip ())
00177 
00178         self.frameBrowseServers.set_sensitive (browsing)
00179 
00180         if preserve_job_files:
00181             self.rbPreserveJobFiles.set_active (True)
00182         elif preserve_job_history:
00183             self.rbPreserveJobHistory.set_active (True)
00184         else:
00185             self.rbPreserveJobNone.set_active (True)
00186 
00187         self.preserve_job_history = preserve_job_history
00188         self.preserve_job_files = preserve_job_files
00189 
00190         model = gtk.ListStore (gobject.TYPE_STRING)
00191         self.browse_treeview.set_model (model)
00192         for server in self.browse_poll:
00193             model.append (row=[server])

def serversettings.ServerSettings._fillBasic (   self) [private]

Definition at line 194 of file serversettings.py.

00194 
00195     def _fillBasic(self):
00196         self.changed = set()
00197         self.cupsconn._begin_operation (_("fetching server settings"))
00198         try:
00199             self.server_settings = self.cupsconn.adminGetServerSettings()
00200         except cups.IPPError, (e, m):
00201             show_IPP_Error(e, m, self._parent)
00202             self.cupsconn._end_operation ()
00203             raise
00204 
00205         self.cupsconn._end_operation ()
00206 
00207         for widget, setting in [
00208             (self.chkServerBrowse, cups.CUPS_SERVER_REMOTE_PRINTERS),
00209             (self.chkServerShare, cups.CUPS_SERVER_SHARE_PRINTERS),
00210             (self.chkServerShareAny, try_CUPS_SERVER_REMOTE_ANY),
00211             (self.chkServerRemoteAdmin, cups.CUPS_SERVER_REMOTE_ADMIN),
00212             (self.chkServerAllowCancelAll, cups.CUPS_SERVER_USER_CANCEL_ANY),
00213             (self.chkServerLogDebug, cups.CUPS_SERVER_DEBUG_LOGGING),]:
00214             widget.set_data("setting", setting)
00215             if self.server_settings.has_key(setting):
00216                 widget.set_active(int(self.server_settings[setting]))
00217                 widget.set_sensitive(True)
00218             else:
00219                 widget.set_active(False)
00220                 widget.set_sensitive(False)
00221 
00222         try:
00223             flag = cups.CUPS_SERVER_SHARE_PRINTERS
00224             publishing = int (self.server_settings[flag])
00225             self.server_is_publishing = publishing
00226         except AttributeError:
00227             pass
00228 
00229         # Set sensitivity of 'Allow printing from the Internet'.
00230         self.on_server_changed (self.chkServerShare) # (any will do here)

def serversettings.ServerSettings._reconnect (   self) [private]

Definition at line 360 of file serversettings.py.

00360 
00361     def _reconnect (self):
00362         # Now reconnect, in case the server needed to reload.
00363         try:
00364             attempt = 1
00365             while attempt <= 5:
00366                 try:
00367                     self.cupsconn._connect ()
00368                     break
00369                 except RuntimeError:
00370                     # Connection failed.
00371                     time.sleep (1)
00372                     attempt += 1
00373         except AttributeError:
00374             # _connect method is part of the authconn.Connection
00375             # interface, so don't fail if that method doesn't exist.
00376             pass

Here is the caller graph for this function:

Definition at line 124 of file serversettings.py.

00124 
00125     def get_dialog (self):
00126         return self.dialog

def gui.GtkGUI.getWidgets (   self,
  widgets,
  domain = None 
) [inherited]

Definition at line 32 of file gui.py.

00032 
00033     def getWidgets(self, widgets, domain=None):
00034         ui_dir = os.environ.get ("SYSTEM_CONFIG_PRINTER_UI",
00035                                  os.path.join (pkgdata, "ui"))
00036         for xmlfile, names in widgets.iteritems ():
00037             bld = gtk.Builder ()
00038 
00039             if domain:
00040                 bld.set_translation_domain (domain)
00041 
00042             bld.add_from_file (os.path.join (ui_dir, xmlfile + ".ui"))
00043             for name in names:
00044                 widget = bld.get_object(name)
00045                 if widget is None:
00046                     raise ValueError, "Widget '%s' not found" % name
00047                 setattr(self, name, widget)
00048 
00049             try:
00050                 win = widget.get_top_level()
00051             except AttributeError:
00052                 win = None
00053             
00054             if win != None:
00055                 gtk.Window.set_focus_on_map(widget.get_top_level (),
00056                                             self.focus_on_map)
00057                 widget.show()
00058 
00059             bld.connect_signals (self)
def serversettings.ServerSettings.on_add_clicked (   self,
  button 
)

Definition at line 259 of file serversettings.py.

00259 
00260     def on_add_clicked (self, button):
00261         model = self.browse_treeview.get_model ()
00262         iter = model.insert (0, row=[_("Enter hostname")])
00263         button.set_sensitive (False)
00264         col = self.browse_treeview.get_columns ()[0]
00265         cell = col.get_cell_renderers ()[0]
00266         cell.set_property ('editable', True)
00267         self.browse_treeview.set_cursor ((0,), col, start_editing=True)
00268         self._connect (cell, 'edited', self.on_browse_poll_edited, 'edit')
00269         self._connect (cell, 'editing-canceled',
00270                        self.on_browse_poll_edit_cancel, 'edit')

Here is the call graph for this function:

Definition at line 327 of file serversettings.py.

00327 
00328     def on_browse_poll_edit_cancel (self, cell):
00329         cell.stop_editing (canceled=True)
00330         cell.set_property ('editable', False)
00331         model = self.browse_treeview.get_model ()
00332         iter = model.get_iter ((0,))
00333         model.remove (iter)
00334         self.add.set_sensitive (True)
00335         self.remove.set_sensitive (False)
00336         self._disconnect ('edit')

Here is the call graph for this function:

Here is the caller graph for this function:

def serversettings.ServerSettings.on_browse_poll_edited (   self,
  cell,
  path,
  newvalue 
)

Definition at line 271 of file serversettings.py.

00271 
00272     def on_browse_poll_edited (self, cell, path, newvalue):
00273         model = self.browse_treeview.get_model ()
00274         iter = model.get_iter (path)
00275         model.set_value (iter, 0, newvalue)
00276         cell.stop_editing (canceled=False)
00277         cell.set_property ('editable', False)
00278         self.add.set_sensitive (True)
00279         self._disconnect ('edit')
00280 
00281         valid = True
00282         # Check that it's a valid IP address or hostname.
00283         # First, is it an IP address?
00284         try:
00285             socket.getaddrinfo (newvalue, '0', socket.AF_UNSPEC, 0, 0,
00286                                 socket.AI_NUMERICHOST)
00287         except socket.gaierror:
00288             # No.  Perhaps it's a hostname.
00289             labels = newvalue.split (".")
00290             seen_alpha = False
00291             for label in labels:
00292                 if (label[0] == '-' or
00293                     label.endswith ('-')):
00294                     valid = False
00295                     break
00296                 for char in label:
00297                     if not seen_alpha:
00298                         if char.isalpha ():
00299                             seen_alpha = True
00300 
00301                     if not (char.isalpha () or
00302                             char.isdigit () or
00303                             char == '-'):
00304                         valid = False
00305                         break
00306 
00307                 if not valid:
00308                     break
00309 
00310             if valid and not seen_alpha:
00311                 valid = False
00312 
00313         if valid:
00314             count = 0
00315             i = model.get_iter_first ()
00316             while i:
00317                 if model.get_value (i, 0) == newvalue:
00318                     count += 1
00319                     if count == 2:
00320                         valid = False
00321                         selection = self.browse_treeview.get_selection ()
00322                         selection.select_iter (i)
00323                         break
00324                 i = model.iter_next (i)
00325         else:
00326             model.remove (iter)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 337 of file serversettings.py.

00337 
00338     def on_remove_clicked (self, button):
00339         model = self.browse_treeview.get_model ()
00340         selection = self.browse_treeview.get_selection ()
00341         rows = selection.get_selected_rows ()
00342         refs = map (lambda path: gtk.TreeRowReference (model, path),
00343                     rows[1])
00344         for ref in refs:
00345             path = ref.get_path ()
00346             iter = model.get_iter (path)
00347             model.remove (iter)

def serversettings.ServerSettings.on_response (   self,
  dialog,
  response 
)

Definition at line 348 of file serversettings.py.

00348 
00349     def on_response (self, dialog, response):
00350         if (response == gtk.RESPONSE_CANCEL or
00351             response != gtk.RESPONSE_OK):
00352             self._disconnect ()
00353             self.dialog.hide ()
00354             self.emit ('dialog-canceled')
00355             del self
00356             return
00357 
00358         self.saveBasic ()
00359         self.saveAdvanced ()

Here is the call graph for this function:

Definition at line 231 of file serversettings.py.

00231 
00232     def on_server_changed(self, widget):
00233         debugprint ("on_server_changed: %s" % widget)
00234         setting = widget.get_data("setting")
00235         if self.server_settings.has_key (setting):
00236             if str(int(widget.get_active())) == self.server_settings[setting]:
00237                 self.changed.discard(widget)
00238             else:
00239                 self.changed.add(widget)
00240 
00241         sharing = self.chkServerShare.get_active ()
00242         self.chkServerShareAny.set_sensitive (
00243             sharing and self.server_settings.has_key(try_CUPS_SERVER_REMOTE_ANY))

Definition at line 256 of file serversettings.py.

00256 
00257     def on_treeview_selection_changed (self, selection):
00258         self.remove.set_sensitive (selection.count_selected_rows () != 0)

def serversettings.ServerSettings.problems_clicked (   self,
  button 
)

Definition at line 127 of file serversettings.py.

00127 
00128     def problems_clicked (self, button):
00129         self.emit ('problems-clicked')

Definition at line 377 of file serversettings.py.

00377 
00378     def saveAdvanced (self):
00379         # See if there are changes.
00380         preserve_job_files = self.rbPreserveJobFiles.get_active ()
00381         preserve_job_history = (preserve_job_files or
00382                                 self.rbPreserveJobHistory.get_active ())
00383         model = self.browse_treeview.get_model ()
00384         browse_poll = []
00385         iter = model.get_iter_first ()
00386         while iter:
00387             browse_poll.append (model.get_value (iter, 0))
00388             iter = model.iter_next (iter)
00389 
00390         if (set (browse_poll) == set (self.browse_poll) and
00391             preserve_job_files == self.preserve_job_files and
00392             preserve_job_history == self.preserve_job_history):
00393             self._disconnect ()
00394             self.dialog.hide ()
00395             self.emit ('settings-applied')
00396             del self
00397             return
00398 
00399         # Fetch cupsd.conf afresh
00400         f = tempfile.TemporaryFile ()
00401         try:
00402             self.cupsconn.getFile (self.RESOURCE, file=f)
00403         except cups.HTTPError, (s,):
00404             show_HTTP_Error (s, self.dialog)
00405             return
00406 
00407         job_history_line = job_files_line = browsepoll_lines = ""
00408 
00409         # Default is to preserve job history
00410         if not preserve_job_history:
00411             job_history_line = "PreserveJobHistory No\n"
00412 
00413         # Default is not to preserve job files.
00414         if preserve_job_files:
00415             job_files_line = "PreserveJobFiles Yes\n"
00416 
00417         for server in browse_poll:
00418             browsepoll_lines += "BrowsePoll %s\n" % server
00419 
00420         f.seek (0)
00421         conf = tempfile.TemporaryFile ()
00422         wrote_preserve_history = wrote_preserve_files = False
00423         wrote_browsepoll = False
00424         has_browsepoll = False
00425         lines = f.readlines ()
00426         for line in lines:
00427             l = line.lower ().strip ()
00428             if l.startswith ("browsepoll "):
00429                 has_browsepoll = True
00430                 break
00431 
00432         for line in lines:
00433             l = line.lower ().strip ()
00434             if l.startswith ("preservejobhistory "):
00435                 if wrote_preserve_history:
00436                     # Don't write out another line with this keyword.
00437                     continue
00438                 # Alter this line before writing it out.
00439                 line = job_history_line
00440                 wrote_preserve_history = True
00441             elif l.startswith ("preservejobfiles "):
00442                 if wrote_preserve_files:
00443                     # Don't write out another line with this keyword.
00444                     continue
00445                 # Alter this line before writing it out.
00446                 line = job_files_line
00447                 wrote_preserve_files = True
00448             elif (has_browsepoll and
00449                   l.startswith ("browsepoll ")):
00450                 if wrote_browsepoll:
00451                     # Ignore extra BrowsePoll lines.
00452                     continue
00453                 # Write new BrowsePoll section.
00454                 conf.write (browsepoll_lines)
00455                 wrote_browsepoll = True
00456                 # Don't write out the original BrowsePoll line.
00457                 continue
00458             elif (not has_browsepoll and
00459                   l.startswith ("browsing ")):
00460                 if not wrote_browsepoll:
00461                     # Write original Browsing line.
00462                     conf.write (line)
00463                     # Write new BrowsePoll section.
00464                     conf.write (browsepoll_lines)
00465                     wrote_browsepoll = True
00466                     continue
00467 
00468             conf.write (line)
00469 
00470         if not wrote_preserve_history:
00471             conf.write (job_history_line)
00472         if not wrote_preserve_files:
00473             conf.write (job_files_line)
00474         if not wrote_browsepoll:
00475             conf.write (browsepoll_lines)
00476 
00477         conf.flush ()
00478         fd = conf.fileno ()
00479         os.lseek (fd, 0, os.SEEK_SET)
00480         try:
00481             self.cupsconn.putFile ("/admin/conf/cupsd.conf", fd=fd)
00482         except cups.HTTPError, (s,):
00483             show_HTTP_Error (s, self.dialog)
00484             return
00485 
00486         # Give the server a chance to process our request.
00487         time.sleep (1)
00488 
00489         self._reconnect ()
00490 
00491         self._disconnect ()
00492         self.emit ('settings-applied')
00493         self.dialog.hide ()
00494         del self

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 495 of file serversettings.py.

00495 
00496     def saveBasic (self):
00497         setting_dict = dict()
00498         for widget, setting in [
00499             (self.chkServerBrowse, cups.CUPS_SERVER_REMOTE_PRINTERS),
00500             (self.chkServerShare, cups.CUPS_SERVER_SHARE_PRINTERS),
00501             (self.chkServerShareAny, try_CUPS_SERVER_REMOTE_ANY),
00502             (self.chkServerRemoteAdmin, cups.CUPS_SERVER_REMOTE_ADMIN),
00503             (self.chkServerAllowCancelAll, cups.CUPS_SERVER_USER_CANCEL_ANY),
00504             (self.chkServerLogDebug, cups.CUPS_SERVER_DEBUG_LOGGING),]:
00505             if not self.server_settings.has_key(setting): continue
00506             setting_dict[setting] = str(int(widget.get_active()))
00507         self.cupsconn._begin_operation (_("modifying server settings"))
00508         try:
00509             self.cupsconn.adminSetServerSettings(setting_dict)
00510         except cups.IPPError, (e, m):
00511             show_IPP_Error(e, m, self.dialog)
00512             self.cupsconn._end_operation ()
00513             return True
00514         except RuntimeError, s:
00515             show_IPP_Error(None, s, self.dialog)
00516             self.cupsconn._end_operation ()
00517             return True
00518         self.cupsconn._end_operation ()
00519         self.changed = set()
00520 
00521         old_setting = self.server_settings.get (cups.CUPS_SERVER_SHARE_PRINTERS,
00522                                                 '0')
00523         new_setting = setting_dict.get (cups.CUPS_SERVER_SHARE_PRINTERS, '0')
00524         if (old_setting == '0' and new_setting != '0'):
00525             # We have just enabled print queue sharing.
00526             # Let's see if the firewall will allow IPP TCP packets in.
00527             try:
00528                 if (self._host == 'localhost' or
00529                     self._host[0] == '/'):
00530                     f = firewall.Firewall ()
00531                     allowed = f.check_ipp_server_allowed ()
00532                 else:
00533                     # This is a remote server.  Nothing we can do
00534                     # about the firewall there.
00535                     allowed = True
00536 
00537                 if not allowed:
00538                     dialog = gtk.MessageDialog (self.ServerSettingsDialog,
00539                                                 gtk.DIALOG_MODAL |
00540                                                 gtk.DIALOG_DESTROY_WITH_PARENT,
00541                                                 gtk.MESSAGE_QUESTION,
00542                                                 gtk.BUTTONS_NONE,
00543                                                 _("Adjust Firewall"))
00544                     dialog.format_secondary_text (_("Adjust the firewall now "
00545                                                     "to allow all incoming IPP "
00546                                                     "connections?"))
00547                     dialog.add_buttons (gtk.STOCK_CANCEL, gtk.RESPONSE_NO,
00548                                         _("Adjust Firewall"), gtk.RESPONSE_YES)
00549                     response = dialog.run ()
00550                     dialog.destroy ()
00551 
00552                     if response == gtk.RESPONSE_YES:
00553                         f.add_rule (f.ALLOW_IPP_SERVER)
00554                         f.write ()
00555             except (dbus.DBusException, Exception):
00556                 nonfatalException ()
00557 
00558         time.sleep(1) # give the server a chance to process our request
00559 
00560         # Now reconnect, in case the server needed to reload.
00561         self._reconnect ()
00562 
00563 gobject.type_register (ServerSettings)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

dictionary serversettings.ServerSettings.__gsignals__ [static, private]
Initial value:
{
        'settings-applied': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
        'dialog-canceled': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
        'problems-clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [])
        }

Definition at line 60 of file serversettings.py.

Definition at line 71 of file serversettings.py.

Definition at line 72 of file serversettings.py.

Definition at line 104 of file serversettings.py.

Definition at line 155 of file serversettings.py.

Definition at line 103 of file serversettings.py.

Definition at line 195 of file serversettings.py.

Definition at line 70 of file serversettings.py.

Definition at line 102 of file serversettings.py.

Definition at line 100 of file serversettings.py.

Definition at line 187 of file serversettings.py.

Definition at line 186 of file serversettings.py.

Definition at line 105 of file serversettings.py.

string serversettings.ServerSettings.RESOURCE = "/admin/conf/cupsd.conf" [static]

Definition at line 66 of file serversettings.py.

Definition at line 224 of file serversettings.py.

Definition at line 198 of file serversettings.py.


The documentation for this class was generated from the following file: