Show
Ignore:
Timestamp:
01/15/07 19:51:27 (19 months ago)
Author:
asterix
Message:

merge usefull diff from trunk

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

Legend:

Unmodified
Added
Removed
  • branches/gajim_0.11/src/advanced.py

    r7095 r7841  
    4747                # value = array(oldval, newval) 
    4848                self.changed_opts = {} 
     49                 
     50                # For i18n 
     51                self.right_true_dict = {True: _('Activated'), False: _('Deactivated')}  
     52                self.types = { 
     53                        'boolean': _('Boolean'), 
     54                        'integer': _('Integer'), 
     55                        'string': _('Text'), 
     56                        'color': _('Color')}  
    4957 
    5058                treeview = self.xml.get_widget('advanced_treeview') 
     
    92100                optname = model[iter][C_PREFNAME] 
    93101                opttype = model[iter][C_TYPE] 
    94                 if opttype == 'boolean' or optname in ('password', 'gpgpassword'): 
     102                if opttype == self.types['boolean'] or optname in ('password',  
     103                        'gpgpassword'): 
    95104                        cell.set_property('editable', False) 
    96105                else: 
     
    138147                modelrow = self.model[modelpath] 
    139148                option = modelrow[0].decode('utf-8') 
    140                 if modelrow[2] == 'boolean': 
    141                         newval = {'False': 'True', 'True': 'False'}[modelrow[1]] 
     149                if modelrow[2] == self.types['boolean']: 
     150                        for key in self.right_true_dict.keys(): 
     151                                if self.right_true_dict[key] == modelrow[1]: 
     152                                        modelrow[1] = key 
     153                        newval = {'False': True, 'True': False}[modelrow[1]] 
    142154                        if len(modelpath) > 1: 
    143155                                optnamerow = self.model[modelpath[0]] 
     
    153165                                gajim.config.set(option, newval) 
    154166                        gajim.interface.save_config() 
    155                         modelrow[1] = newval 
     167                        modelrow[1] = self.right_true_dict[newval] 
    156168                        self.check_for_restart() 
    157169 
     
    222234                if val[OPT_TYPE]: 
    223235                        type = val[OPT_TYPE][0] 
     236                        type = self.types[type] # i18n 
    224237                value = val[OPT_VAL] 
    225238                if name in ('password', 'gpgpassword'): 
    226239                        #we talk about password 
    227240                        value = _('Hidden') # override passwords with this string 
     241                if value in self.right_true_dict: 
     242                        value = self.right_true_dict[value] 
    228243                model.append(iter, [name, value, type]) 
    229244 
  • branches/gajim_0.11/src/common/commands.py

    r7829 r7841  
    2626                ''' This returns True if that command should be visible and invokable 
    2727                for others. 
    28                 samejid - True when command is invoked by an entity with the same bare jid. 
    29                 ''' 
     28                samejid - True when command is invoked by an entity with the same bare  
     29                jid.''' 
    3030                return True 
    3131 
     
    3535                self.sessionid = sessionid 
    3636 
    37         def buildResponse(self, request, status='executing', defaultaction=None, actions=None): 
     37        def buildResponse(self, request, status = 'executing', defaultaction = None, 
     38        actions = None): 
    3839                assert status in ('executing', 'completed', 'canceled') 
    3940 
     
    4647                if defaultaction is not None or actions is not None: 
    4748                        if defaultaction is not None: 
    48                                 assert defaultaction in ('cancel', 'execute', 'prev', 'next', 'complete') 
     49                                assert defaultaction in ('cancel', 'execute', 'prev', 'next', 
     50                                        'complete') 
    4951                                attrs = {'action': defaultaction} 
    5052                        else: 
     
    5557 
    5658        def badRequest(self, stanza): 
    57                 self.connection.connection.send(xmpp.Error(stanza, xmpp.NS_STANZAS+' bad-request')) 
     59                self.connection.connection.send(xmpp.Error(stanza, xmpp.NS_STANZAS + \ 
     60                        ' bad-request')) 
    5861 
    5962        def cancel(self, request): 
    60                 response, cmd = self.buildResponse(request, status='canceled') 
     63                response, cmd = self.buildResponse(request, status = 'canceled') 
    6164                self.connection.connection.send(response) 
    6265                return False    # finish the session 
     
    6467class ChangeStatusCommand(AdHocCommand): 
    6568        commandnode = 'change-status' 
    66         commandname = 'Change status information' 
     69        commandname = _('Change status information') 
    6770 
    6871        @staticmethod 
     
    7376        def execute(self, request): 
    7477                # first query... 
    75                 response, cmd = self.buildResponse(request, defaultaction='execute', actions=['execute']) 
     78                response, cmd = self.buildResponse(request, defaultaction = 'execute', 
     79                        actions = ['execute']) 
    7680                 
    77                 cmd.addChild(node=dataforms.SimpleDataForm( 
    78                         title='Change status', 
    79                         instructions='Set the presence type and description', 
    80                         fields=[ 
     81                cmd.addChild(node = dataforms.SimpleDataForm( 
     82                        title = _('Change status'), 
     83                        instructions = _('Set the presence type and description'), 
     84                        fields = [ 
    8185                                dataforms.Field('list-single', 
    82                                         var='presence-type', 
    83                                         label='Type of presence:', 
    84                                         options=[ 
    85                                                 (u'free-for-chat', u'Free for chat'), 
    86                                                 (u'online', u'Online'), 
    87                                                 (u'away', u'Away'), 
    88                                                 (u'xa', u'Extended away'), 
    89                                                 (u'dnd', u'Do not disturb'), 
    90                                                 (u'offline', u'Offline - disconnect')], 
    91                                         value='online', 
    92                                         required=True), 
     86                                        var = 'presence-type', 
     87                                        label = 'Type of presence:', 
     88                                        options = [ 
     89                                                (u'free-for-chat', _('Free for chat')), 
     90                                                (u'online', _('Online')), 
     91                                                (u'away', _('Away')), 
     92                                                (u'xa', _('Extended away')), 
     93                                                (u'dnd', _('Do not disturb')), 
     94                                                (u'offline', _('Offline - disconnect'))], 
     95                                        value = 'online', 
     96                                        required = True), 
    9397                                dataforms.Field('text-multi', 
    94                                         var='presence-desc', 
    95                                         label='Presence description:')])) 
     98                                        var = 'presence-desc', 
     99                                        label = _('Presence description:'))])) 
    96100 
    97101                self.connection.connection.send(response) 
     
    105109                # check if the data is correct 
    106110                try: 
    107                         form=dataforms.SimpleDataForm(extend=request.getTag('command').getTag('x')) 
     111                        form = dataforms.SimpleDataForm(extend = request.getTag('command').\ 
     112                                getTag('x')) 
    108113                except: 
    109114                        self.badRequest(request) 
    110115                        return False 
    111                  
     116 
    112117                try: 
    113118                        presencetype = form['presence-type'].value 
     
    126131                        presencedesc = u'' 
    127132 
    128                 response, cmd = self.buildResponse(request, status='completed') 
    129                 cmd.addChild('note', {}, 'The status has been changed.') 
     133                response, cmd = self.buildResponse(request, status = 'completed') 
     134                cmd.addChild('note', {}, _('The status has been changed.')) 
    130135 
    131136                # if going offline, we need to push response so it won't go into 
    132137                # queue and disappear 
    133                 self.connection.connection.send(response, presencetype=='offline') 
     138                self.connection.connection.send(response, presencetype == 'offline') 
    134139 
    135140                # send new status 
    136                 gajim.interface.roster.send_status(self.connection.name, presencetype, presencedesc) 
     141                gajim.interface.roster.send_status(self.connection.name, presencetype, 
     142                        presencedesc) 
    137143 
    138144                return False    # finish the session 
     145 
     146def find_current_groupchats(account): 
     147        import message_control 
     148        rooms = [] 
     149        for gc_control in gajim.interface.msg_win_mgr.get_controls( 
     150        message_control.TYPE_GC): 
     151                acct = gc_control.account 
     152                # check if account is the good one 
     153                if acct != account: 
     154                        continue 
     155                room_jid = gc_control.room_jid 
     156                nick = gc_control.nick 
     157                if gajim.gc_connected[acct].has_key(room_jid) and \ 
     158                gajim.gc_connected[acct][room_jid]: 
     159                        rooms.append((room_jid, nick,)) 
     160        return rooms 
     161 
     162 
     163class LeaveGroupchatsCommand(AdHocCommand): 
     164        commandnode = 'leave-groupchats' 
     165        commandname = 'Leave Groupchats' 
     166 
     167        @staticmethod 
     168        def isVisibleFor(samejid): 
     169                ''' Change status is visible only if the entity has the same bare jid. ''' 
     170                return samejid 
     171 
     172        def execute(self, request): 
     173                # first query... 
     174                response, cmd = self.buildResponse(request, defaultaction = 'execute', 
     175                        actions=['execute']) 
     176                options = [] 
     177                account = self.connection.name 
     178                for gc in find_current_groupchats(account): 
     179                        options.append((u'%s' %(gc[0]), _('%(nickname)s on %(room_jid)s') % \ 
     180                                {'nickname': gc[1], 'room_jid': gc[0]})) 
     181                if not len(options): 
     182                        response, cmd = self.buildResponse(request, status = 'completed') 
     183                        cmd.addChild('note', {}, _('You have not joined a groupchat.')) 
     184                 
     185                        self.connection.connection.send(response) 
     186                        return False 
     187 
     188                cmd.addChild(node=dataforms.SimpleDataForm( 
     189                        title = _('Leave Groupchats'), 
     190                        instructions = _('Choose the groupchats you want to leave'), 
     191                        fields=[ 
     192                                dataforms.Field('list-multi', 
     193                                        var = 'groupchats', 
     194                                        label = _('Groupchats'), 
     195                                        options = options, 
     196                                        required = True)])) 
     197 
     198                self.connection.connection.send(response) 
     199 
     200                # for next invocation 
     201                self.execute = self.leavegroupchats 
     202                 
     203                return True     # keep the session 
     204 
     205        def leavegroupchats(self, request): 
     206                # check if the data is correct 
     207                try: 
     208                        form = dataforms.SimpleDataForm(extend = request.getTag('command').\ 
     209                                getTag('x')) 
     210                except: 
     211                        self.badRequest(request) 
     212                        return False 
     213 
     214                try: 
     215                        gc = form['groupchats'].values 
     216                except: # KeyError if there's no presence-type field in form or 
     217                        # AttributeError if that field is of wrong type 
     218                        self.badRequest(request) 
     219                        return False 
     220                account = self.connection.name 
     221                try: 
     222                        for room_jid in gc: 
     223                                gc_control = gajim.interface.msg_win_mgr.get_control(room_jid, 
     224                                        account) 
     225                                gc_control.parent_win.remove_tab(gc_control, None, force = True) 
     226                except: # KeyError if there's no presence-type field in form or 
     227                        self.badRequest(request) 
     228                        return False 
     229                response, cmd = self.buildResponse(request, status = 'completed') 
     230                note = _('You leaved the following groupchats:') 
     231                for room_jid in gc: 
     232                        note += '\n\t' + room_jid 
     233                cmd.addChild('note', {}, note) 
     234 
     235                self.connection.connection.send(response) 
     236                return False 
     237 
    139238 
    140239class ConnectionCommands: 
     
    143242                # a list of all commands exposed: node -> command class 
    144243                self.__commands = {} 
    145                 for cmdobj in (ChangeStatusCommand,): 
     244                for cmdobj in (ChangeStatusCommand, LeaveGroupchatsCommand): 
    146245                        self.__commands[cmdobj.commandnode] = cmdobj 
    147246 
     
    165264                                q.addChild('item', { 
    166265                                        # TODO: find the jid 
    167                                         'jid': self.getOurBareJID()+u'/'+self.server_resource, 
     266                                        'jid': self.getOurBareJID() + u'/' + self.server_resource, 
    168267                                        'node': node, 
    169268                                        'name': cmd.commandname}) 
     
    210309                        if node not in self.__commands.keys(): 
    211310                                self.connection.send( 
    212                                         xmpp.Error(iq_obj, xmpp.NS_STANZAS+' item-not-found')) 
     311                                        xmpp.Error(iq_obj, xmpp.NS_STANZAS + ' item-not-found')) 
    213312                                raise xmpp.NodeProcessed 
    214313 
     
    221320 
    222321                        # create new instance and run it 
    223                         obj = newcmd(conn=self, jid=jid, sessionid=sessionid) 
     322                        obj = newcmd(conn = self, jid = jid, sessionid = sessionid) 
    224323                        rc = obj.execute(iq_obj) 
    225324                        if rc: 
     
    237336 
    238337                        try: 
    239                                 if action == 'cancel':          rc = obj.cancel(iq_obj) 
    240                                 elif action == 'prev':          rc = obj.prev(iq_obj) 
    241                                 elif action == 'next':          rc = obj.next(iq_obj) 
     338                                if action == 'cancel': 
     339                                        rc = obj.cancel(iq_obj) 
     340                                elif action == 'prev': 
     341                                        rc = obj.prev(iq_obj) 
     342                                elif action == 'next': 
     343                                        rc = obj.next(iq_obj) 
    242344                                elif action == 'execute' or action is None: 
    243                                                                 rc = obj.execute(iq_obj) 
    244                                 elif action == 'complete':      rc = obj.complete(iq_obj) 
     345                                        rc = obj.execute(iq_obj) 
     346                                elif action == 'complete': 
     347                                        rc = obj.complete(iq_obj) 
    245348                                else: 
    246349                                        # action is wrong. stop the session, send error 
     
    257360 
    258361                        raise xmpp.NodeProcessed 
    259  
  • branches/gajim_0.11/src/common/config.py

    r7829 r7841  
    131131                'latest_disco_addresses': [ opt_str, '' ], 
    132132                'recently_groupchat': [ opt_str, '' ], 
    133                 'before_nickname': [ opt_str, '' ], 
    134                 'time_stamp': [ opt_str, '[%H:%M] ' ], 
    135                 'after_nickname': [ opt_str, ':' ], 
     133                'time_stamp': [ opt_str, '[%X] ', _('This option let you customize timestamp that is printed in conversation. For exemple "[%H:%M] " will show "[hour:minute] ". See python doc on strftime for full documentation: http://docs.python.org/lib/module-time.html') ], 
     134                'before_nickname': [ opt_str, '', _('Characters that are printed before the nickname in conversations') ], 
     135                'after_nickname': [ opt_str, ':', _('Characters that are printed after the nickname in conversations') ], 
    136136                'send_os_info': [ opt_bool, True ], 
    137137                'set_status_msg_from_current_music_track': [ opt_bool, False ], 
  • branches/gajim_0.11/src/config.py

    r7829 r7841  
    9393                w.hide() 
    9494 
    95                 #trayicon 
     95                # trayicon 
    9696                if gajim.interface.systray_capabilities: 
    9797                        st = gajim.config.get('trayicon') 
     
    100100                        self.trayicon_checkbutton.set_sensitive(False) 
    101101 
    102                 #Save position 
     102                # Save position 
    103103                st = gajim.config.get('saveposition') 
    104104                self.xml.get_widget('save_position_checkbutton').set_active(st) 
     
    241241                        self.xml.get_widget('time_always_radiobutton').set_active(True) 
    242242 
    243                 # TimeStamp 
    244                 st = gajim.config.get('time_stamp') 
    245                 st = helpers.from_one_line(st) 
    246                 self.xml.get_widget('time_stamp_textview').get_buffer().set_text(st) 
    247  
    248                 # before nickname 
    249                 st = gajim.config.get('before_nickname') 
    250                 st = helpers.from_one_line(st) 
    251                 self.xml.get_widget('before_nickname_textview').get_buffer().set_text(st) 
    252  
    253                 # after nickanme 
    254                 st = gajim.config.get('after_nickname') 
    255                 st = helpers.from_one_line(st) 
    256                 self.xml.get_widget('after_nickname_textview').get_buffer().set_text(st) 
    257  
    258243                # Color for incoming messages 
    259244                colSt = gajim.config.get('inmsgcolor') 
     
    732717                        gajim.config.set('print_time', 'always') 
    733718                self._set_sensitivity_for_before_after_time_widgets(True) 
    734                 gajim.interface.save_config() 
    735  
    736         def _get_textview_text(self, tv): 
    737                 buffer = tv.get_buffer() 
    738                 begin, end = buffer.get_bounds() 
    739                 return buffer.get_text(begin, end).decode('utf-8') 
    740  
    741         def on_time_stamp_textview_focus_out_event(self, widget, event): 
    742                 text = self._get_textview_text(widget) 
    743                 text = helpers.to_one_line(text) 
    744                 gajim.config.set('time_stamp', text) 
    745                 gajim.interface.save_config() 
    746  
    747         def on_before_nickname_textview_focus_out_event(self, widget, event): 
    748                 text = self._get_textview_text(widget) 
    749                 text = helpers.to_one_line(text) 
    750                 gajim.config.set('before_nickname', text) 
    751                 gajim.interface.save_config() 
    752  
    753         def on_after_nickname_textview_focus_out_event(self, widget, event): 
    754                 text = self._get_textview_text(widget) 
    755                 text = helpers.to_one_line(text) 
    756                 gajim.config.set('after_nickname', text) 
    757719                gajim.interface.save_config() 
    758720 
     
    26602622                self.option_list = {'': _('Default'), 'all': Q_('?print_status:All'), 
    26612623                        'in_and_out': _('Enter and leave only'), 
    2662                         'none': _('?print_status:None')} 
     2624                        'none': Q_('?print_status:None')} 
    26632625                opts = self.option_list.keys() 
    26642626                opts.sort() 
  • branches/gajim_0.11/src/conversation_textview.py

    r7829 r7841  
    689689                current_print_time = gajim.config.get('print_time') 
    690690                if current_print_time == 'always' and kind != 'info': 
    691                         timestamp_str = gajim.config.get('time_stamp') 
    692                         timestamp_str = helpers.from_one_line(timestamp_str) 
     691                        timestamp_str = self.get_time_to_show(tim) 
    693692                        timestamp = time.strftime(timestamp_str, tim) 
    694693                        buffer.insert_with_tags_by_name(end_iter, timestamp, 
     
    758757                if day_str: 
    759758                        format += day_str + ' ' 
    760                 format += '%X' 
     759                timestamp_str = gajim.config.get('time_stamp') 
     760                timestamp_str = helpers.from_one_line(timestamp_str) 
     761                format += timestamp_str 
    761762                tim_format = time.strftime(format, tim) 
    762763                if locale.getpreferredencoding() != 'KOI8-R': 
  • branches/gajim_0.11/src/dialogs.py

    <
    r7829 r7841  
    215215                column.pack_start(renderer) 
    216216                column.set_attributes(renderer, text = 0) 
    217                  
     217 
    218218                column = gtk.TreeViewColumn(_('In the group')) 
    219219                column.set_expand(False) 
     
    320320                        title_text = _('Status Message') 
    321321                self.window.set_title(title_text) 
    322                  
     322 
    323323                message_textview = self.xml.get_widget('message_textview') 
    324324                self.message_buffer = message_textview.get_buffer() 
     
    332332                msg = helpers.from_one_line(msg) 
    333333                self.message_buffer.set_text(msg) 
    334                  
     334 
    335335                # have an empty string selectable, so user can clear msg 
    336336                self.preset_messages_dict = {'': ''} 
     
    340340                        self.preset_messages_dict[msg_name] = msg_text 
    341341                sorted_keys_list = helpers.get_sorted_keys(self.preset_messages_dict) 
    342                  
     342 
    343343                self.message_liststore = gtk.ListStore(str) # msg_name 
    344344                self.message_combobox = self.xml.get_widget('message_combobox') 
     
    375375                name = model[active][0].decode('utf-8') 
    376376                self.message_buffer.set_text(self.preset_messages_dict[name]) 
    377          
     377 
    378378        def on_change_status_message_dialog_key_press_event(self, widget, event): 
    379379                if event.keyval == gtk.keysyms.Return or \ 
     
    388388                else: 
    389389                        btn.set_sensitive(True) 
    390          
     390 
    391391        def on_save_as_preset_button_clicked(self, widget): 
    392392                start_iter, finish_iter = self.message_buffer.get_bounds() 
     
    404404                        msg_name = msg_name.decode('utf-8') 
    405405                        iter_ = self.message_liststore.append((msg_name,)) 
    406                          
     406 
    407407                        gajim.config.add_per('statusmsg', msg_name) 
    408408                        gajim.config.set_per('statusmsg', msg_name, 'message', msg_text_1l) 
     
    602602                                'utf-8') 
    603603                        jid = jid.replace('@', '%') + '@' + transport 
    604                  
     604 
    605605                # check if jid is conform to RFC and stringprep it 
    606606                try: 
     
    727727                        text = open(copying_file_path).read() 
    728728                        dlg.set_license(text) 
    729                  
     729 
    730730                dlg.set_comments('%s\n%s %s\n%s %s'  
    731731                        % (_('A GTK+ jabber client'), \