Debian Codegraph @

errordialogs.py

raw
1 #!/usr/bin/python3
2
3 ## system-config-printer
4
5 ## Copyright (C) 2006, 2007, 2008, 2010, 2013 Red Hat, Inc.
6 ## Authors:
7 ## Florian Festi <[email protected]>
8 ## Tim Waugh <[email protected]>
9
10 ## This program is free software; you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation; either version 2 of the License, or
13 ## (at your option) any later version.
14
15 ## This program is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
19
20 ## You should have received a copy of the GNU General Public License
21 ## along with this program; if not, write to the Free Software
22 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24 import config
25 import cups
26 from gi.repository import Gtk
27 import gettext
28 gettext.install(domain=config.PACKAGE, localedir=config.localedir)
29
30 def show_dialog (title, text, type, parent=None):
31 dialog = Gtk.MessageDialog (parent=parent,
32 modal=True, destroy_with_parent=True,
33 message_type=type,
34 buttons=Gtk.ButtonsType.OK,
35 text=title)
36 dialog.format_secondary_text (text)
37 dialog.run ()
38 dialog.destroy ()
39
40 def show_info_dialog (title, text, parent=None):
41 return show_dialog (title, text, Gtk.MessageType.INFO, parent=parent)
42
43 def show_error_dialog (title, text, parent=None):
44 return show_dialog (title, text, Gtk.MessageType.ERROR, parent=parent)
45
46 def show_IPP_Error(exception, message, parent=None):
47 if exception == 0:
48 # In this case, the user has canceled an authentication dialog.
49 return
50 elif exception == cups.IPP_SERVICE_UNAVAILABLE:
51 # In this case, the user has canceled a retry dialog.
52 return
53 else:
54 title = _("CUPS server error")
55 text = _("There was an error during the CUPS "
56 "operation: '%s'.") % message
57
58 show_error_dialog (title, text, parent)
59
60 def show_HTTP_Error(status, parent=None):
61 if (status == cups.HTTP_UNAUTHORIZED or
62 status == cups.HTTP_FORBIDDEN):
63 title = _('Not authorized')
64 text = (_('The password may be incorrect, or the '
65 'server may be configured to deny '
66 'remote administration.'))
67 else:
68 title = _('CUPS server error')
69 if status == cups.HTTP_BAD_REQUEST:
70 msg = _("Bad request")
71 elif status == cups.HTTP_NOT_FOUND:
72 msg = _("Not found")
73 elif status == cups.HTTP_REQUEST_TIMEOUT:
74 msg = _("Request timeout")
75 elif status == cups.HTTP_UPGRADE_REQUIRED:
76 msg = _("Upgrade required")
77 elif status == cups.HTTP_SERVER_ERROR:
78 msg = _("Server error")
79 elif status == -1:
80 msg = _("Not connected")
81 else:
82 msg = _("status %s") % status
83
84 text = _("There was an HTTP error: %s.") % msg
85
86 show_error_dialog (title, text, parent)