~jconti/ubuntu/precise/emesene/fix-956422

« back to all changes in this revision

Viewing changes to plugins_base/NotifyOsdImproved.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-14 01:33:51 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100414013351-r2icbt5gs4ai71j8
Tags: 1.6.1-0ubuntu1
* New upstream release (LP: #562646).
* Fix missing-debian-source-format lintian warning.
* Refresh 20_dont_build_own_libmimic.patch patch.
* Bump Standards-Version to 3.8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
class MainClass(Plugin.Plugin):
38
38
    '''Main plugin class'''
39
39
 
40
 
    description = _('Notify about diferent events using the new notifications of Ubuntu')
 
40
    description = _('Notifies various events using the new system notifications')
41
41
    authors = {'Mariano Guerra': 'luismarianoguerra at gmail dot com',
42
42
        'Nicolas Espina Tacchetti': 'nicolasespina at gmail dot com',
43
43
        'Panagiotis Koutsias': 'pkoutsias at gmail dot com',}
44
44
    website = 'http://emesene-msn.blogspot.com'
45
 
    displayName = _('Notification')
 
45
    displayName = _('NotifyOsdImproved')
46
46
    name = 'NotifyOsdImproved'
47
47
    require = ['pynotify']
48
48
    def __init__(self, controller, msn):
50
50
 
51
51
        Plugin.Plugin.__init__(self, controller, msn)
52
52
 
53
 
        self.description = _('Notify about diferent events using the new notifications of Ubuntu')
 
53
        self.description = _('Notifies various events using the new system notifications')
54
54
        self.authors = {'Mariano Guerra': 'luismarianoguerra at gmail dot com',
55
55
        'Nicolas Espina Tacchetti': 'nicolasespina at gmail dot com',
56
56
        'Panagiotis Koutsias': 'pkoutsias at gmail dot com',}
74
74
        self.showNotification = int(self.config.getPluginValue(self.name, 'showNotification', '0'))
75
75
 
76
76
        #Disable Notification on Systray
77
 
        self.checkBox = gtk.CheckMenuItem(_('Disable Notifications'))
78
 
        self.checkBox.set_active(self.showNotification)
79
 
        self.checkBox.connect('activate', self.on_showNotification_activate)
80
 
 
81
 
        self.tray = self.controller.trayIcon.getNotifyObject()
 
77
        if not TrayIcon.disabled:
 
78
            self.checkBox = gtk.CheckMenuItem(_('Disable Notifications'))
 
79
            self.checkBox.set_active(self.showNotification)
 
80
            self.checkBox.connect('activate', self.on_showNotification_activate)
 
81
            self.tray = self.controller.trayIcon.getNotifyObject()
82
82
        self.pixbuf = self.controller.theme.getImage('userPanel')
83
83
 
84
 
 
85
84
        self.parser = controller.unifiedParser
86
85
        self.contacts = controller.contacts  # ref..
87
86
 
104
103
    def on_showNotification_activate(self, *args):
105
104
        self.showNotification = self.checkBox.get_active()
106
105
        self.config.setPluginValue(self.name, 'showNotification', str(int(self.showNotification)))
 
106
 
 
107
    def connect_onoff(self, *args):
 
108
        self.onlineId = self.connect('user-online', self.online)
 
109
        self.offlineId = self.connect('user-offline', self.offline)
 
110
        if self.notifyId is not None: self.disconnect(self.notifyId)
 
111
        self.notifyId = None
107
112
    
108
113
    def start(self):
109
114
        '''start the plugin'''
112
117
        if not ERROR and not pynotify.init('emesene'):
113
118
            ERROR = _('there was a problem initializing the pynotify module')
114
119
 
115
 
        self.onlineId = self.connect('user-online', self.online)
116
 
        self.offlineId = self.connect('user-offline', self.offline)
 
120
        self.notifyId = None
 
121
        self.onlineId = None
 
122
        self.offlineId = None
 
123
        if self.msn.canNotify:
 
124
            self.connect_onoff()
 
125
        else:
 
126
            self.notifyId = self.connect('enable-notifications', self.connect_onoff)
117
127
        self.newMsgId = self.connect('switchboard::message', self.newMsg)
118
128
        self.offMsgId = self.connect('offline-message-received', self.offMsg)
119
129
        self.typingId = self.connect('switchboard::typing', self.receiveTyping)
120
 
        self.fTInviteId = self.msn.connect('new-file-transfer', self.notifyFileTransferInvite)
121
 
        self.fTFinishedId = self.msn.connect('finished-file-transfer', self.notifyFileTransferFinished)
 
130
        self.fTInviteId = self.connect('new-file-transfer', self.notifyFileTransferInvite)
 
131
        self.fTFinishedId = self.connect('finished-file-transfer', self.notifyFileTransferFinished)
122
132
        self.newMailId = self.connect('new-mail-notification', self.newMail)
123
133
        self.initMailId = self.connect('initial-mail-notification', \
124
134
                self.initMail)
135
145
 
136
146
        self.notifications = []
137
147
 
138
 
        self.disconnect(self.onlineId)
139
 
        self.disconnect(self.offlineId)
 
148
        if self.onlineId is not None: self.disconnect(self.onlineId)
 
149
        if self.offlineId is not None: self.disconnect(self.offlineId)
 
150
        if self.notifyId is not None: self.disconnect(self.notifyId)
140
151
        self.disconnect(self.newMsgId)
141
152
        self.disconnect(self.offMsgId)
142
153
        self.disconnect(self.typingId)
145
156
        self.disconnect(self.newMailId)
146
157
        self.disconnect(self.initMailId)
147
158
        self.enabled = False
148
 
        self.controller.trayIcon.menu.remove(self.checkBox);
149
 
        self.controller.trayIcon.menu.show_all()
150
 
        self.controller.trayIcon.update(self.controller.msn.status)
 
159
        if not TrayIcon.disabled:
 
160
            self.controller.trayIcon.menu.remove(self.checkBox);
 
161
            self.controller.trayIcon.menu.show_all()
 
162
            self.controller.trayIcon.update(self.controller.msn.status)
151
163
 
152
164
    def check(self):
153
165
        '''check if everything is OK to start the plugin
258
270
 
259
271
    def notifyEnabled(self, contact = None):
260
272
        '''checks if notifications are enabled'''
261
 
        if self.config.glob['disableTrayIcon']:
262
 
            return False
263
273
        if not self.enabled:
264
274
            return False
265
275
        if self.notifyBusy and self.msn.status == 'BSY':
273
283
 
274
284
    def notify(self, contact, title, text, execute = '', data = None):
275
285
 
276
 
        notification = pynotify.Notification(title, text, attach = self.tray)
 
286
        notification = pynotify.Notification(title, text)#, attach = self.tray)
277
287
        # both "append" and "x-canonical-append" work fine.
278
288
        notification.set_hint_string ("x-canonical-append", "allowed")
279
289
 
288
298
            self.pixbuf = self.controller.theme.getImage('userPanel')
289
299
 
290
300
 
291
 
        if self.controller.trayIcon and \
 
301
        if not TrayIcon.disabled and \
292
302
           isinstance(self.controller.trayIcon.tray, gtk.StatusIcon):
293
303
            tray = self.controller.trayIcon.tray
294
304
            try: