Show
Ignore:
Timestamp:
02/06/07 20:54:30 (22 months ago)
Author:
asterix
Message:

merge diff from trunk

Location:
branches/gajim_0.11/src/common
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • branches/gajim_0.11/src/common/commands.py

    r7841 r7940  
    118118                        presencetype = form['presence-type'].value 
    119119                        if not presencetype in \ 
    120                             ('free-for-chat', 'online', 'away', 'xa', 'dnd', 'offline'): 
     120                        ('free-for-chat', 'online', 'away', 'xa', 'dnd', 'offline'): 
    121121                                self.badRequest(request) 
    122122                                return False 
     
    283283                        q = iq.getTag('query') 
    284284                        q.addChild('identity', attrs = {'type': 'command-node', 
    285                                                         'category': 'automation', 
    286                                                         'name': cmd.commandname}) 
     285                                'category': 'automation', 
     286                                'name': cmd.commandname}) 
    287287                        q.addChild('feature', attrs = {'var': xmpp.NS_COMMANDS}) 
    288288                        for feature in cmd.commandfeatures: 
  • branches/gajim_0.11/src/common/connection_handlers.py

    r7888 r7940  
    746746                        if node in (None, client_version): 
    747747                                q.addChild('feature', attrs = {'var': common.xmpp.NS_MUC}) 
     748                                q.addChild('feature', attrs = {'var': common.xmpp.NS_CHATSTATES}) 
     749                                q.addChild('feature', attrs = {'var': common.xmpp.NS_COMMANDS}) 
     750                                q.addChild('feature', attrs = {'var': common.xmpp.NS_DISCO_INFO}) 
     751 
    748752                        if q.getChildren(): 
    749753                                self.connection.send(iq) 
     
    839843                                entry = {} 
    840844                                for c in info.getChildren(): 
    841                                          entry[c.getName()] = c.getData() 
     845                                        entry[c.getName()] = c.getData() 
    842846                                dict[name].append(entry) 
    843847                        elif info.getChildren() == []: 
     
    846850                                dict[name] = {} 
    847851                                for c in info.getChildren(): 
    848                                          dict[name][c.getName()] = c.getData() 
     852                                        dict[name][c.getName()] = c.getData() 
    849853                return dict 
    850854 
     
    10501054 
    10511055                del self.awaiting_answers[id] 
    1052          
     1056 
    10531057        def _vCardCB(self, con, vc): 
    10541058                '''Called when we receive a vCard 
    10551059                Parse the vCard and send it to plugins''' 
    10561060                if not vc.getTag('vCard'): 
     1061                        return 
     1062                if not vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD: 
    10571063                        return 
    10581064                frm_iq = vc.getFrom() 
     
    10641070                else: 
    10651071                        who = frm = our_jid 
    1066                 if vc.getTag('vCard').getNamespace() == common.xmpp.NS_VCARD: 
    1067                         card = vc.getChildren()[0] 
    1068                         vcard = self.node_to_dict(card) 
    1069                         photo_decoded = None 
    1070                         if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \ 
    1071                         vcard['PHOTO'].has_key('BINVAL'): 
    1072                                 photo = vcard['PHOTO']['BINVAL'] 
    1073                                 try: 
    1074                                         photo_decoded = base64.decodestring(photo) 
    1075                                         avatar_sha = sha.sha(photo_decoded).hexdigest() 
    1076                                 except: 
    1077                                         avatar_sha = '' 
    1078                         else: 
     1072                card = vc.getChildren()[0] 
     1073                vcard = self.node_to_dict(card) 
     1074                photo_decoded = None 
     1075                if vcard.has_key('PHOTO') and isinstance(vcard['PHOTO'], dict) and \ 
     1076                vcard['PHOTO'].has_key('BINVAL'): 
     1077                        photo = vcard['PHOTO']['BINVAL'] 
     1078                        try: 
     1079                                photo_decoded = base64.decodestring(photo) 
     1080                                avatar_sha = sha.sha(photo_decoded).hexdigest() 
     1081                        except: 
    10791082                                avatar_sha = '' 
    1080  
    1081                         if avatar_sha: 
    1082                                 card.getTag('PHOTO').setTagData('SHA', avatar_sha) 
    1083  
    1084                         # Save it to file 
    1085                         self.save_vcard_to_hd(who, card) 
    1086                         # Save the decoded avatar to a separate file too, and generate files for dbus notifications 
    1087                         puny_jid = helpers.sanitize_filename(frm) 
    1088                         puny_nick = None 
    1089                         begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid) 
    1090                         if frm in self.room_jids: 
    1091                                 puny_nick = helpers.sanitize_filename(resource) 
    1092                                 # create folder if needed 
    1093                                 if not os.path.isdir(begin_path): 
    1094                                         os.mkdir(begin_path, 0700) 
    1095                                 begin_path = os.path.join(begin_path, puny_nick) 
    1096                         if photo_decoded: 
    1097                                 avatar_file = begin_path + '_notif_size_colored.png' 
    1098                                 if frm == our_jid and avatar_sha != self.vcard_sha: 
    1099                                         gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) 
    1100                                 elif frm != our_jid and (not os.path.exists(avatar_file) or \ 
    1101                                         not self.vcard_shas.has_key(frm) or \ 
    1102                                         avatar_sha != self.vcard_shas[frm]): 
    1103                                         gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) 
    1104                         else: 
    1105                                 for ext in ('.jpeg', '.png', '_notif_size_bw.png', 
    1106                                         '_notif_size_colored.png'): 
    1107                                         path = begin_path + ext 
    1108                                         if os.path.isfile(path): 
    1109                                                 os.remove(path) 
    1110  
    1111                         if frm != our_jid: 
     1083                else: 
     1084                        avatar_sha = '' 
     1085 
     1086                if avatar_sha: 
     1087                        card.getTag('PHOTO').setTagData('SHA', avatar_sha) 
     1088 
     1089                # Save it to file 
     1090                self.save_vcard_to_hd(who, card) 
     1091                # Save the decoded avatar to a separate file too, and generate files for dbus notifications 
     1092                puny_jid = helpers.sanitize_filename(frm) 
     1093                puny_nick = None 
     1094                begin_path = os.path.join(gajim.AVATAR_PATH, puny_jid) 
     1095                frm_jid = frm 
     1096                if frm in self.room_jids: 
     1097                        puny_nick = helpers.sanitize_filename(resource) 
     1098                        # create folder if needed 
     1099                        if not os.path.isdir(begin_path): 
     1100                                os.mkdir(begin_path, 0700) 
     1101                        begin_path = os.path.join(begin_path, puny_nick) 
     1102                        frm_jid += '/' + resource 
     1103                if photo_decoded: 
     1104                        avatar_file = begin_path + '_notif_size_colored.png' 
     1105                        if frm_jid == our_jid and avatar_sha != self.vcard_sha: 
     1106                                gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) 
     1107                        elif frm_jid != our_jid and (not os.path.exists(avatar_file) or \ 
     1108                        not self.vcard_shas.has_key(frm_jid) or \ 
     1109                        avatar_sha != self.vcard_shas[frm_jid]): 
     1110                                gajim.interface.save_avatar_files(frm, photo_decoded, puny_nick) 
    11121111                                if avatar_sha: 
    1113                                         self.vcard_shas[frm] = avatar_sha 
    1114                                 elif self.vcard_shas.has_key(frm): 
    1115                                         del self.vcard_shas[frm] 
    1116  
    1117                         vcard['jid'] = frm 
    1118                         vcard['resource'] = resource 
    1119                         if frm == our_jid: 
    1120                                 self.dispatch('MYVCARD', vcard) 
    1121                                 # we re-send our presence with sha if has changed and if we are 
    1122                                 # not invisible 
    1123                                 if self.vcard_sha == avatar_sha: 
    1124                                         return 
    1125                                 self.vcard_sha = avatar_sha 
    1126                                 if STATUS_LIST[self.connected] == 'invisible': 
    1127                                         return 
    1128                                 sshow = helpers.get_xmpp_show(STATUS_LIST[self.connected]) 
    1129                                 p = common.xmpp.Presence(typ = None, priority = self.priority, 
    1130                                         show = sshow, status = self.status) 
    1131                                 p = self.add_sha(p) 
    1132                                 self.connection.send(p) 
    1133                         else: 
    1134                                 self.dispatch('VCARD', vcard) 
     1112                                        self.vcard_shas[frm_jid] = avatar_sha 
     1113                        elif self.vcard_shas.has_key(frm): 
     1114                                del self.vcard_shas[frm] 
     1115                else: 
     1116                        for ext in ('.jpeg', '.png', '_notif_size_bw.png', 
     1117                                '_notif_size_colored.png'): 
     1118                                path = begin_path + ext 
     1119                                if os.path.isfile(path): 
     1120                                        os.remove(path) 
     1121 
     1122                vcard['jid'] = frm 
     1123                vcard['resource'] = resource 
     1124                if frm_jid == our_jid: 
     1125                        self.dispatch('MYVCARD', vcard) 
     1126                        # we re-send our presence with sha if has changed and if we are 
     1127                        # not invisible 
     1128                        if self.vcard_sha == avatar_sha: 
     1129                                return 
     1130                        self.vcard_sha = avatar_sha 
     1131                        if STATUS_LIST[self.connected] == 'invisible': 
     1132                                return 
     1133                        sshow = helpers.get_xmpp_show(STATUS_LIST[self.connected]) 
     1134                        p = common.xmpp.Presence(typ = None, priority = self.priority, 
     1135                                show = sshow, status = self.status) 
     1136                        p = self.add_sha(p) 
     1137                        self.connection.send(p) 
     1138                else: 
     1139                        self.dispatch('VCARD', vcard) 
    11351140 
    11361141class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub): 
     
    14601465                        if msg.timestamp: 
    14611466                                has_timestamp = True 
    1462                         if subject: 
     1467                        if subject != None: 
    14631468                                self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp)) 
    14641469                        else: 
     
    16331638                        if not ptype or ptype == 'unavailable': 
    16341639                                if gajim.config.get('log_contact_status_changes') and self.name\ 
    1635                                         not in no_log_for and jid_stripped not in no_log_for: 
     1640                                not in no_log_for and jid_stripped not in no_log_for: 
    16361641                                        gc_c = gajim.contacts.get_gc_contact(self.name, jid_stripped, resource) 
    16371642                                        st = status or '' 
     
    16491654                                                puny_nick = helpers.sanitize_filename(resource) 
    16501655                                                gajim.interface.remove_avatar_files(jid_stripped, puny_nick) 
    1651                                         if self.vcard_shas.has_key(who): 
     1656                                        if self.vcard_shas.has_key(who): # Verify sha cached in mem 
    16521657                                                if avatar_sha != self.vcard_shas[who]: 
    16531658                                                        # avatar has been updated 
    16541659                                                        self.request_vcard(who, True) 
    1655                                         else: 
    1656                                                 self.vcard_shas[who] = avatar_sha 
     1660                                        else: # Verify sha cached in hdd 
     1661                                                cached_vcard = self.get_cached_vcard(who, True) 
     1662                                                if cached_vcard and cached_vcard.has_key('PHOTO') and \ 
     1663                                                cached_vcard['PHOTO'].has_key('SHA'): 
     1664                                                        cached_sha = cached_vcard['PHOTO']['SHA'] 
     1665                                                else: 
     1666                                                        cached_sha = '' 
     1667                                                if cached_sha != avatar_sha: 
     1668                                                        # avatar has been updated 
     1669                                                        # sha in mem will be updated later 
     1670                                                        self.request_vcard(who, True) 
     1671                                                else: 
     1672                                                        # save sha in mem NOW 
     1673                                                        self.vcard_shas[who] = avatar_sha 
    16571674                                self.dispatch('GC_NOTIFY', (jid_stripped, show, status, resource, 
    16581675                                        prs.getRole(), prs.getAffiliation(), prs.getJid(), 
     
    18471864                self.dispatch('MSGERROR', (jid, errcode, errmsg)) 
    18481865 
     1866        def _IqPingCB(self, con, iq_obj): 
     1867                gajim.log.debug('IqPingCB') 
     1868                iq_obj = iq_obj.buildReply('result') 
     1869                self.connection.send(iq_obj) 
     1870                raise common.xmpp.NodeProcessed 
     1871 
    18491872        def _getRosterCB(self, con, iq_obj): 
    18501873                if not self.connection: 
     
    20112034                con.RegisterHandler('iq', self._DiscoverItemsGetCB, 'get', 
    20122035                        common.xmpp.NS_DISCO_ITEMS) 
     2036                con.RegisterHandler('iq', self._IqPingCB, 'get', 
     2037                        common.xmpp.NS_PING) 
    20132038                con.RegisterHandler('iq', self._PubSubCB, 'result') 
    20142039                con.RegisterHandler('iq', self._ErrorCB, 'error') 
  • branches/gajim_0.11/src/common/connection.py

    r7888 r7940  
    108108                # Do not try to reco while we are already trying 
    109109                self.time_to_reconnect = None 
    110                 if self.connected < 2: #connection failed 
     110                if self.connected < 2: # connection failed 
    111111                        gajim.log.debug('reconnect') 
    112112                        self.retrycount += 1 
     
    146146                                self.connected = 1 
    147147                                self.dispatch('STATUS', 'connecting') 
     148                                if gajim.status_before_autoaway[self.name]: 
     149                                        # We were auto away. So go back online 
     150                                        self.status = gajim.status_before_autoaway[self.name] 
     151                                        gajim.status_before_autoaway[self.name] = '' 
     152                                        self.old_show = 'online' 
    148153                                # this check has moved from _reconnect method 
    149154                                # do exponential backoff until 15 minutes, 
     
    10971102                if show == 'offline': 
    10981103                        ptype = 'unavailable' 
    1099                 show = helpers.get_xmpp_show(show) 
     1104                xmpp_show = helpers.get_xmpp_show(show) 
    11001105                p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype, 
    1101                         show = show, status = status) 
    1102                 if gajim.config.get('send_sha_in_gc_presence'): 
     1106                        show = xmpp_show, status = status) 
     1107                if gajim.config.get('send_sha_in_gc_presence') and show != 'offline': 
    11031108                        p = self.add_sha(p, ptype != 'unavailable') 
    11041109                # send instantly so when we go offline, status is sent to gc before we 
  • branches/gajim_0.11/src/common/contacts.py

    r7787 r7940  
    277277                                        contact_groups = contact.groups 
    278278                                        if not contact_groups: 
    279                                                 # Contact is not in a group, so count it in General group 
    280                                                 contact_groups.append(_('General')) 
     279                                                # Contact is not in a group, so count it in General or 
     280                                                # Transports group 
     281                                                if common.gajim.jid_is_transport(jid): 
     282                                                        contact_groups = [_('Transports')] 
     283                                                else: 
     284                                                        contact_groups = [_('General')] 
    281285                                        for group in groups: 
    282286                                                if group in contact_groups: 
  • branches/gajim_0.11/src/common/fuzzyclock.py

    r7787 r7940  
    3535 
    3636class FuzzyClock: 
    37     def __init__(self): 
    38         self.__hour = 0 
    39         self.__minute = 0 
    40         self.__dayOfWeek = 0 
     37        def __init__(self): 
     38                self.__hour = 0 
     39                self.__minute = 0 
     40                self.__dayOfWeek = 0 
    4141 
    42         self.__hourNames = [ _('one'), _('two'), _('three'), _('four'), _('five'), _('six'), 
    43                              _('seven'), _('eight'), _('nine'), _('ten'), _('eleven'), 
    44                              _('twelve')] 
     42                self.__hourNames = [ _('one'), _('two'), _('three'), _('four'), _('five'), _('six'), 
     43                        _('seven'), _('eight'), _('nine'), _('ten'), _('eleven'), 
     44                        _('twelve')] 
    4545 
    46         #Strings to use for the output. %0 will be replaced with the preceding hour (e.g. "x PAST %0"), %1 with the coming hour (e.g. "x TO %1). ''' 
    47         self.__normalFuzzy = [ _("$0 o'clock"), _('five past $0'), 
    48                                                                                 _('ten past $0'), _('quarter past $0'), 
    49                                                                                 _('twenty past $0'), _('twenty five past $0'), 
    50                                                                                 _('half past $0'), _('twenty five to $1'), 
    51                                                                                 _('twenty to $1'), _('quarter to $1'), 
    52                                                                                 _('ten to $1'), _('five to $1'), _("$1 o'clock") ] 
     46                #Strings to use for the output. %0 will be replaced with the preceding hour (e.g. "x PAST %0"), %1 with the coming hour (e.g. "x TO %1). ''' 
     47                self.__normalFuzzy = [ _("$0 o'clock"), _('five past $0'), 
     48                        _('ten past $0'), _('quarter past $0'), 
     49                        _('twenty past $0'), _('twenty five past $0'), 
     50                        _('half past $0'), _('twenty five to $1'), 
     51                        _('twenty to $1'), _('quarter to $1'), 
     52                        _('ten to $1'), _('five to $1'), _("$1 o'clock") ] 
    5353 
    54         #A "singular-form". It is used when talking about hour 0 
    55         self.__normalFuzzyOne = [ _("$0 o'clock"), _('five past $0'), 
    56                                   _('ten past $0'), _('quarter past $0'), 
    57                                   _('twenty past $0'), _('twenty five past $0'), 
    58                                   _('half past $0'), _('twenty five to $1'), 
    59                                   _('twenty to $1'), _('quarter to $1'), 
    60                                   _('ten to $1'), _('five to $1'), 
    61                                                                                          _("$1 o'clock") ] 
     54                #A "singular-form". It is used when talking about hour 0 
     55                self.__normalFuzzyOne = [ _("$0 o'clock"), _('five past $0'), 
     56                        _('ten past $0'), _('quarter past $0'), 
     57                        _('twenty past $0'), _('twenty five past $0'), 
     58                        _('half past $0'), _('twenty five to $1'), 
     59                        _('twenty to $1'), _('quarter to $1'), 
     60                        _('ten to $1'), _('five to $1'), 
     61                        _("$1 o'clock") ] 
    6262 
    6363 
    64         self.__dayTime = [ _('Night'), _('Early morning'), _('Morning'), _('Almost noon'), 
    65                            _('Noon'), _('Afternoon'), _('Evening'), _('Late evening') ] 
     64                self.__dayTime = [ _('Night'), _('Early morning'), _('Morning'), _('Almost noon'), 
     65                        _('Noon'), _('Afternoon'), _('Evening'), _('Late evening') ] 
    6666 
    67         self.__fuzzyWeek = [ _('Start of week'), _('Middle of week'), _('End of week'), 
    68                              _('Weekend!') ] 
     67                self.__fuzzyWeek = [ _('Start of week'), _('Middle of week'), _('End of week'), 
     68                        _('Weekend!') ] 
    6969 
    70         self.setCurrent() 
     70                self.setCurrent() 
    7171 
    72     def setHour(self,hour): 
    73         self.__hour = int(hour) 
     72        def setHour(self,hour): 
     73                self.__hour = int(hour) 
    7474 
    75     def setMinute(self,minute): 
    76         self.__minute=int(minute) 
     75        def setMinute(self,minute): 
     76                self.__minute=int(minute) 
    7777 
    78     def setDayOfWeek(self,day): 
    79         self.__dayOfWeek=int(day) 
     78        def setDayOfWeek(self,day): 
     79                self.__dayOfWeek=int(day) 
    8080 
    81     def setTime(self,time): 
    82         timeArray = time.split(":") 
    83         self.setHour(timeArray[0]) 
    84         self.setMinute(timeArray[1]) 
     81        def setTime(self,time): 
     82                timeArray = time.split(":") 
     83                self.setHour(timeArray[0]) 
     84                self.setMinute(timeArray[1]) 
    8585 
    86     def setCurrent(self): 
    87         hour=time.strftime("%H") 
    88         minute=time.strftime("%M") 
    89         day=time.strftime("%w") 
     86        def setCurrent(self): 
     87                hour=time.strftime("%H") 
     88                minute=time.strftime("%M") 
     89                day=time.strftime("%w") 
    9090 
    91         self.setTime(hour+":"+minute) 
    92         self.setDayOfWeek(day) 
     91                self.setTime(hour+":"+minute) 
     92                self.setDayOfWeek(day) 
    9393 
    94     def getFuzzyTime(self, fuzzyness = 1): 
    95         sector = 0 
    96         realHour = 0 
     94        def getFuzzyTime(self, fuzzyness = 1): 
     95                sector = 0 
     96                realHour = 0 
    9797 
    98         if fuzzyness == 1 or fuzzyness == 2: 
    99             if fuzzyness == 1: 
    100                 if self.__minute >2: 
    101                     sector = (self.__minute - 3) / 5 +1 
    102             else: 
    103                 if self.__minute > 6: 
    104                     sector = ((self.__minute - 7) / 15 + 1) * 3 
     98                if fuzzyness == 1 or fuzzyness == 2: 
     99                        if fuzzyness == 1: 
     100                                if self.__minute >2: 
     101                                        sector = (self.__minute - 3) / 5 +1 
     102                        else: 
     103                                if self.__minute > 6: 
     104                                        sector = ((self.__minute - 7) / 15 + 1) * 3 
    105105 
    106             newTimeStr = self.__normalFuzzy[sector] 
    107             #$0 or $1? 
    108             deltaHour = int(newTimeStr[newTimeStr.find("$")+1]) 
     106                        newTimeStr = self.__normalFuzzy[sector] 
     107                        #$0 or $1? 
     108                        deltaHour = int(newTimeStr[newTimeStr.find("$")+1]) 
    109109 
    110             if (self.__hour + deltaHour) % 12 > 0: 
    111                 realHour = (self.__hour + deltaHour) % 12 - 1 
    112             else: 
    113                 realHour = 12 - ((self.__hour + deltaHour) % 12 + 1) 
     110                        if (self.__hour + deltaHour) % 12 > 0: 
     111                                realHour = (self.__hour + deltaHour) % 12 - 1 
     112                        else: 
     113                                realHour = 12 - ((self.__hour + deltaHour) % 12 + 1) 
    114114 
    115             if realHour == 0: 
    116                 newTimeStr = self.__normalFuzzyOne[sector] 
     115                        if realHour == 0: 
     116                                newTimeStr = self.__normalFuzzyOne[sector] 
    117117 
    118             newTimeStr = newTimeStr.replace("$"+str(deltaHour), 
    119                                             self.__hourNames[realHour]) 
     118                        newTimeStr = newTimeStr.replace("$"+str(deltaHour), 
     119                                self.__hourNames[realHour]) 
    120120 
    121121 
    122         elif fuzzyness == 3: 
    123             newTimeStr = self.__dayTime[self.__hour / 3] 
     122                elif fuzzyness == 3: 
     123                        newTimeStr = self.__dayTime[self.__hour / 3] 
    124124 
    125         else: 
    126             dayOfWeek = self.__dayOfWeek 
    127             if dayOfWeek == 1: 
    128                 newTimeStr = self.__fuzzyWeek[0] 
    129             elif dayOfWeek >= 2 and dayOfWeek <= 4: 
    130                 newTimeStr = self.__fuzzyWeek[1] 
    131             elif dayOfWeek == 5: 
    132