Back to index

system-config-printer  1.3.9+20120706
errordialogs.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## system-config-printer
00004 
00005 ## Copyright (C) 2006, 2007, 2008, 2010 Red Hat, Inc.
00006 ## Authors:
00007 ##  Florian Festi <ffesti@redhat.com>
00008 ##  Tim Waugh <twaugh@redhat.com>
00009 
00010 ## This program is free software; you can redistribute it and/or modify
00011 ## it under the terms of the GNU General Public License as published by
00012 ## the Free Software Foundation; either version 2 of the License, or
00013 ## (at your option) any later version.
00014 
00015 ## This program is distributed in the hope that it will be useful,
00016 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 ## GNU General Public License for more details.
00019 
00020 ## You should have received a copy of the GNU General Public License
00021 ## along with this program; if not, write to the Free Software
00022 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 import cups
00025 import gtk
00026 from gettext import gettext as _
00027 
00028 def show_dialog (title, text, type, parent=None):
00029     dialog = gtk.MessageDialog (parent,
00030                                 gtk.DIALOG_MODAL |
00031                                 gtk.DIALOG_DESTROY_WITH_PARENT,
00032                                 type,
00033                                 gtk.BUTTONS_OK,
00034                                 title)
00035     dialog.format_secondary_text (text)
00036     dialog.run ()
00037     dialog.destroy ()
00038 
00039 def show_info_dialog (title, text, parent=None):
00040     return show_dialog (title, text, gtk.MESSAGE_INFO, parent=parent)
00041 
00042 def show_error_dialog (title, text, parent=None):
00043     return show_dialog (title, text, gtk.MESSAGE_ERROR, parent=parent)
00044 
00045 def show_IPP_Error(exception, message, parent=None):
00046     if exception == 0:
00047         # In this case, the user has canceled an authentication dialog.
00048         return
00049     elif exception == cups.IPP_SERVICE_UNAVAILABLE:
00050         # In this case, the user has canceled a retry dialog.
00051         return
00052     else:
00053         title = _("CUPS server error")
00054         text = (_("There was an error during the CUPS "
00055                   "operation: '%s'.")) % message
00056 
00057     show_error_dialog (title, text, parent)
00058 
00059 def show_HTTP_Error(status, parent=None):
00060     if (status == cups.HTTP_UNAUTHORIZED or
00061         status == cups.HTTP_FORBIDDEN):
00062         title = _('Not authorized')
00063         text = (_('The password may be incorrect, or the '
00064                   'server may be configured to deny '
00065                   'remote administration.'))
00066     else:
00067         title = _('CUPS server error')
00068         if status == cups.HTTP_BAD_REQUEST:
00069             msg = _("Bad request")
00070         elif status == cups.HTTP_NOT_FOUND:
00071             msg = _("Not found")
00072         elif status == cups.HTTP_REQUEST_TIMEOUT:
00073             msg = _("Request timeout")
00074         elif status == cups.HTTP_UPGRADE_REQUIRED:
00075             msg = _("Upgrade required")
00076         elif status == cups.HTTP_SERVER_ERROR:
00077             msg = _("Server error")
00078         elif status == -1:
00079             msg = _("Not connected")
00080         else:
00081             msg = _("status %s") % status
00082 
00083         text = _("There was an HTTP error: %s.") % msg
00084 
00085     show_error_dialog (title, text, parent)