Example #1
0
    def mainloop(self):
        try:
            messages, events = ipmsg.whatsnew()
            new_incoming = [m for m in messages if m.io == 1 and m not in self.incoming]
            paused = [m for m in messages if m.io == 0 and m.is_send_error()]
            read_notify = [m for m in messages if m.io == 0 and m.is_opened()]
            deleted_notify = [m for m in messages if m.io == 0 and m.is_ignored()]
        except ipmsg.NetworkError:
            ipmsg.put_offline()
            dlg = NetworkErrorDialog(None)
            dlg.show()
            dlg.run()
            return True

        if settings['enable_notify']:
            if settings['notify_online']:
                msg = ''.join([contact.get_desc() + ' signed online.\n' for contact in events if contact.status in (STAT_ON, STAT_AFK)])
                if len(msg) > 0:
                    notify.balloon('notify', msg, notify.EVENT)
            if settings['notify_offline']:
                msg = ''.join([contact.get_desc() + ' signed out.\n' for contact in events if contact.status == STAT_OFF])
                if len(msg) > 0:
                    notify.balloon('notify', msg, notify.EVENT)

            for msg in read_notify:
                notify.balloon('notify', '%s has opened your message.' % msg.contact.name , notify.EVENT)

            for msg in deleted_notify:
                notify.balloon('notify', '%s ignored your message.' % msg.contact.name , notify.EVENT)

        if settings['enable_notify'] and (not ipmsg.get_status().is_afk() or not settings['disable_notify_afk']):
            for msg in new_incoming:
                icon = msg.atts and notify.ATT or notify.MSG
                notify.balloon(msg.contact.get_desc(), msg.options['seal'] and '--Secret Message--' or msg.msg, icon)

        if settings['enable_popup'] and (not ipmsg.get_status().is_afk() or not settings['non_popup_when_afk']):
            for msg in new_incoming:
                recv_dlg = RecvDialog(msg)
                recv_dlg.show()
                ipmsg.read_notice(msg)
            new_incoming = []

        prev_unread = [m for m in self.incoming if not m.is_read()]
        self.incoming = [m for m in messages if m.io == 1]
        self.update_icon()

        for msg in [m for m in paused if m not in self.prev_paused]:
            if settings['notify_error']:
                notify.balloon('Error', 'Message not delivered', notify.EVENT)
            dlg = ResendConfimDialog(None, msg.msg)
            def on_resend_rsps(w, id, msg):
                if id == gtk.RESPONSE_YES:
                    ipmsg.resend(msg)
                w.destroy()
            dlg.connect('response', on_resend_rsps, msg)
            dlg.show()

        self.prev_paused = paused[:]

        for msg in new_incoming:
            label = '    %s ... (%s ago)' % (msg.contact.get_desc(), util.calc_time(msg.packet.age()))
            item = gtk.MenuItem(label, False)
            item.connect('activate', self.on_read_msg, msg)
            item.show()
            self.left_menu.insert(item, 1)
        self.left_menu.get_children()[0].set_sensitive(not ipmsg.get_status().is_off())

        return True
Example #2
0
 def on_read_msg(self, widget, msg):
     ipmsg.read_notice(msg)
     recv_dlg = RecvDialog(msg)
     recv_dlg.show()
     self.update_icon()
     self.left_menu.remove(widget)