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

« back to all changes in this revision

Viewing changes to Controller.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:
50
50
import SlashCommands
51
51
import Sound
52
52
import PluginManager
53
 
import PluginManagerDialog
54
53
import ConversationManager
55
54
import ConversationLayoutManager
56
55
from Parser import UnifiedParser
93
92
        ()),
94
93
        'usermenu-item-add' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
95
94
        (gobject.TYPE_PYOBJECT,)),
 
95
        
 
96
        'message-read' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
 
97
            ()),
96
98
    }
97
99
 
98
100
    def __init__(self, username, minimized, leakdebug, iconified, badroot):
100
102
        gobject.GObject.__init__(self)
101
103
 
102
104
        self.NAME = 'emesene'
103
 
        self.VERSION = '1.6 "mate"'
104
 
        self.COPYRIGHT = 'Luis Mariano Guerra, dx, C10uD'
 
105
        self.VERSION = '1.6.1 "mate"'
 
106
        self.COPYRIGHT = 'Luis Mariano Guerra, dx, C10uD, arielj'
105
107
        self.COMMENT = _('A client for the WLM%s network') % u'\u2122'
106
108
        self.LICENSE_FALLBACK = 'GNU General Public License'
107
109
        self.WEBSITE = 'http://www.emesene.org'
140
142
            'GrinningArmor (emesene)', \
141
143
            'x-warrior (emesene)', \
142
144
            'Tom \'ukblackknight\' (emesene)', \
 
145
            'Stefano \'Cando\' Candori (emesene)', \
143
146
            'All the fantastic emesene community (all)', \
144
147
            ]
145
148
        
213
216
            gtk.widget_pop_colormap()
214
217
 
215
218
        if TrayIcon.disabled or not (minimized or self.config.glob['startup'] == 'minimize'):
216
 
            if iconified or self.config.glob['startup'] == 'iconify':
 
219
            if iconified or self.config.glob['startup'] == 'iconify' and not self.config.glob['disableTrayIcon']:
217
220
                self.mainWindow.iconify()
218
221
            else:
219
222
                self.mainWindow.show()
290
293
        # messenger.hotmail.com
291
294
        self.msn = core.Msnp(server, 1863, user, password,\
292
295
             self.config.getUserConfigPath(), proxy, \
293
 
             self.config.user['receiveP4context']) # ugly, but i'm lazy
 
296
             self.config.user['receiveP4context'], self.config) # ugly, but i'm lazy
294
297
                    
295
298
        self.msn.setDebug(self.config.glob['debug'],
296
299
            self.config.glob['binary'])
321
324
        if not self.msn:
322
325
            return False
323
326
        if not self.reconnecting:
324
 
            text = _('Error during login, please retry') + \
325
 
             '\n(' + message + ')'
326
 
            self.goToLoginWindow()
327
 
            self.mainWindow.showNiceBar(text,self.niceBarWarningColor, gtk.STOCK_DIALOG_WARNING)
 
327
            if self.config.glob['autoLogin']:
 
328
                self.autoReconnect(self.userEmail, password, self.userStatus)
 
329
            else:    
 
330
                text = _('Error during login, please retry') + \
 
331
                '\n(' + message + ')'
 
332
                self.goToLoginWindow()
 
333
                self.mainWindow.showNiceBar(text,self.niceBarWarningColor, gtk.STOCK_DIALOG_WARNING)
328
334
        else:
329
335
            self.autoReconnect(self.userEmail, password, self.userStatus)
330
336
 
334
340
        except Exception, e:
335
341
            print "Exception at logout", e
336
342
        self.goToLoginWindow()
 
343
        if self.reconnectTimerId is not None:
 
344
            gobject.source_remove(self.reconnectTimerId)
 
345
            self.reconnectTimerId = None
337
346
 
338
347
    def goToLoginWindow(self):
339
348
        self.config.setCurrentUser('')
423
432
            self.trayIcon.menu.prepend(self.trayStatusMenu)
424
433
            self.trayIcon.menu.show_all()
425
434
            self.trayIcon.update(self.msn.status)
426
 
 
 
435
            
427
436
        self.pluginManager = PluginManager.PluginManager(self)
428
437
        gobject.idle_add(self.pluginManager.startActivePlugins)
429
438
 
433
442
        self.msn.connect('new-conversation', self.newConversation)
434
443
        self.msn.connect('user-attr-changed', self.on_user_attr_changed)
435
444
        self.msn.connect('self-status-changed', self.on_self_status_changed)
 
445
        self.msn.connect('self-dp-changed', self.on_change_avatar)
436
446
        self.msn.connect('group-attr-changed', self.on_group_attr_changed)
437
447
        self.msn.connect('add-notification', self.addNotification)
438
448
        self.msn.connect('user-list-change', self.refreshUserList)
507
517
 
508
518
    def removeGroup(self, group):
509
519
        #asks the user before removing the group
510
 
        def remove_cb(response):
 
520
        def remove_cb(response, group):
511
521
            if response == stock.YES:
512
 
                self.groups.remove(group.name)
 
522
                if not isinstance(group, basestring):
 
523
                    group = group.name
 
524
                self.groups.remove(group)
513
525
 
514
526
        message = _('Are you sure you want to remove this group?')
515
 
        dialog.yes_no(message,remove_cb)
 
527
        dialog.yes_no(message,remove_cb, group)
516
528
 
517
529
    def autoReconnect(self, user, password, status):
518
530
        self.mainWindow.buildInterface('reconnect')
613
625
            code.InteractiveConsole(locals()).interact(\
614
626
                "Entering controller.msn leak debug console")
615
627
 
 
628
        hotmail_file = os.path.join(paths.CONFIG_DIR, \
 
629
            self.config.getCurrentUser(), "cache", "login.htm")
 
630
 
 
631
        if os.path.isfile(hotmail_file):
 
632
            try:
 
633
                os.remove(hotmail_file)
 
634
            except:
 
635
                pass
616
636
 
617
637
    def quit(self, status):
618
638
        '''close the window, and do all the things needed...'''
622
642
        #self.mainWindow.connect('unmap-event', self.on_main_hidden, status)
623
643
        self.mainWindow.hide()
624
644
        if not TrayIcon.disabled:
625
 
            self.trayIcon.tray.hide()
 
645
            self.trayIcon.remove()
626
646
 
627
647
        try:
628
648
            self.mainWindow.saveToQuit()
630
650
            pass
631
651
 
632
652
        if self.connected:
633
 
            self.msn.logout()
 
653
            self.logout()
 
654
            #self.msn.logout()
634
655
            self.config.writeUserConfig()
635
656
 
636
657
        self.config.writeGlobalConfig()
676
697
                if avatarPath != self.config.user['avatarPath']:
677
698
                    self.changeAvatar(avatarPath)
678
699
 
679
 
        nick=self.contacts.get_nick()
680
 
        psm=self.contacts.get_message()
 
700
        nick=self.msn.nick.replace('\n', ' ')
 
701
        psm=self.msn.personalMessage.replace('\n', ' ')
681
702
        currentAvatarPath = self.config.user['avatarPath']
682
703
        dialog.show_profile(self, nick, psm, currentAvatarPath, responseProfile)
683
704
 
 
705
    def on_change_avatar(self, msnp, filename):
 
706
        '''control if the avatar already exists or save the new avatar'''
 
707
        if os.path.exists(filename):
 
708
            self.changeAvatar(filename)
 
709
            return
 
710
        else:
 
711
            return
 
712
 
684
713
    def changeAvatar(self, filename):
685
714
        if not self.msn:
686
715
            return
833
862
        return self.conversationManager.newConversation(self.msn, mail, \
834
863
            switchboard, weStarted)
835
864
 
836
 
    def pluginDialog(self):
837
 
        '''Show the pluginManagerDialog'''
838
 
 
839
 
        p = PluginManagerDialog.PluginManagerDialog(self.pluginManager, \
840
 
            self.mainWindow, self.config)
841
 
        p.show()
842
 
 
843
865
    def seeAvatarHistory(self, email):
844
866
       '''opens a dialog with all user's avatars'''
845
867
 
858
880
        '''process the OIM message'''
859
881
        user, date, message = oim
860
882
        window, conv = self.newConversation(msnp, user['addr'], None, False)
 
883
        self.conversationManager.newest_message_conv = conv
861
884
        conv.receiveOIM(user['name'], message, date)
862
885
 
863
886
    def messageError(self, msnp, to, message, error):
945
968
 
946
969
def main():
947
970
    args = parseArgs()
948
 
    if (os.name == 'posix') and (os.getuid() == 0) and (args[5] == False):
 
971
    if (os.name == 'posix') and (os.getuid() == 0) and (args[4] == False):
949
972
        print "I refuse to run as root. " \
950
973
              "If you know the risks and still want to do it," \
951
974
              " just add the --i-know-that-running-emesene-as-root-is-bad option."
972
995
    # this stuff is to interrupt blocking stuff safely.
973
996
    for i in range(5):
974
997
        try:
 
998
            gtk.gdk.threads_init()
 
999
            gtk.gdk.threads_enter()
975
1000
            gtk.main()
 
1001
            gtk.gdk.threads_leave()
 
1002
            
976
1003
        except KeyboardInterrupt:
977
1004
            print 'Interrupt (%s more times to close)' % str(5 - i)
978
1005
        else: