~khurshid-alam/gwibber/gwibber-hack

« back to all changes in this revision

Viewing changes to gwibber/error.py

  • Committer: Khurshid Alam
  • Date: 2012-04-06 14:38:38 UTC
  • Revision ID: khurshid.alam@linuxmail.org-20120406143838-nz7hjg8vtzi2wl7i
initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2010 Canonical Ltd
 
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 version 2 as
 
6
# published by the Free Software Foundation.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
#
 
16
# Copyright (C) 2010 Ken VanDine <ken.vandine@canonical.com>
 
17
#
 
18
# Error dialog for Gwibber
 
19
#
 
20
 
 
21
import subprocess, os
 
22
 
 
23
import gettext
 
24
from gettext import lgettext as _
 
25
if hasattr(gettext, 'bind_textdomain_codeset'):
 
26
    gettext.bind_textdomain_codeset('gwibber','UTF-8')
 
27
gettext.textdomain('gwibber')
 
28
 
 
29
import gtk
 
30
 
 
31
class GwibberErrorService:
 
32
 
 
33
    def __init__(self):
 
34
        self.notified = {}
 
35
 
 
36
    def ShowDialog(self, message=None, title=None, condition="error", service=None, username=None, type=None):
 
37
        """show_dialog raises a gtk.MessageDialog to the user
 
38
           displaying errors or information.
 
39
 
 
40
           arguments are:
 
41
             message - a string to present to the user
 
42
             title - OPTIONAL: a string which will set the title of the window
 
43
             condition - a string, must be either "error" or "info"
 
44
             service
 
45
             username
 
46
             type - auth, network, keyring
 
47
        """
 
48
 
 
49
        if type == "keyring": service = "any"
 
50
        # Don't notify for the same error again
 
51
        if self.notified.has_key(service):
 
52
            if self.notified[service] == type:
 
53
                return
 
54
 
 
55
        if type == "keyring":
 
56
            if os.path.exists(os.path.join("bin", "gwibber-accounts")):
 
57
                cmd = os.path.join("bin", "gwibber-accounts")
 
58
            else:
 
59
                cmd = "gwibber-accounts"
 
60
            ret = subprocess.call([cmd])
 
61
            self.notified[service] = type
 
62
            return ret
 
63
 
 
64
        self.notified[service] = type
 
65
        if condition == "info":
 
66
            condition = gtk.MESSAGE_INFO
 
67
        else:
 
68
            condition = gtk.MESSAGE_ERROR
 
69
 
 
70
        if title is None:
 
71
            title = _("Gwibber Error")
 
72
        dialog = gtk.MessageDialog(
 
73
            parent = None,
 
74
            type = condition,
 
75
            buttons = gtk.BUTTONS_CLOSE,
 
76
            message_format = message)
 
77
        dialog.set_title(title)
 
78
        dialog.set_position(gtk.WIN_POS_CENTER_ALWAYS)
 
79
        dialog.run()
 
80
        dialog.destroy()