Changeset 7467

Show
Ignore:
Timestamp:
11/18/06 21:51:50 (2 years ago)
Author:
asterix
Message:

use a dialog to rename a contact or a group. fixes #2200

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/data/glade/input_dialog.glade

    r6265 r7467  
    1818  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> 
    1919  <property name="focus_on_map">True</property> 
     20  <property name="urgency_hint">False</property> 
    2021  <property name="has_separator">False</property> 
     22  <signal name="destroy" handler="on_input_dialog_destroy" last_modification_time="Sat, 18 Nov 2006 20:23:21 GMT"/> 
    2123 
    2224  <child internal-child="vbox"> 
  • trunk/src/dialogs.py

    r7425 r7467  
    10031003        '''Class for Input dialog''' 
    10041004        def __init__(self, title, label_str, input_str = None, is_modal = True, 
    1005 ok_handler = None): 
     1005        ok_handler = None, cancel_handler = None): 
    10061006                # if modal is True you also need to call get_response() 
    10071007                # and ok_handler won't be used 
     
    10121012                self.dialog.set_title(title) 
    10131013                label.set_markup(label_str) 
     1014                self.cancel_handler = cancel_handler 
    10141015                if input_str: 
    10151016                        self.input_entry.set_text(input_str) 
     
    10231024                        cancelbutton = self.xml.get_widget('cancelbutton') 
    10241025                        cancelbutton.connect('clicked', self.on_cancelbutton_clicked) 
     1026                        self.xml.signal_autoconnect(self) 
    10251027                        self.dialog.show_all() 
    10261028 
    1027         def on_okbutton_clicked(self,  widget): 
     1029        def on_input_dialog_destroy(self, widget): 
     1030                if self.cancel_handler: 
     1031                        self.cancel_handler() 
     1032 
     1033        def on_okbutton_clicked(self, widget): 
    10281034                user_input = self.input_entry.get_text().decode('utf-8') 
    10291035                self.dialog.destroy() 
    1030                 self.ok_handler(user_input) 
     1036                if isinstance(self.ok_handler, tuple): 
     1037                        self.ok_handler[0](user_input, *self.ok_handler[1:]) 
     1038                else: 
     1039                        self.ok_handler(user_input) 
    10311040         
    1032         def on_cancelbutton_clicked(self,  widget): 
     1041        def on_cancelbutton_clicked(self, widget): 
    10331042                self.dialog.destroy() 
    10341043 
  • trunk/src/roster_window.py

    r7457 r7467  
    5555C_JID, # the jid of the row 
    5656C_ACCOUNT, # cellrenderer text that holds account name 
    57 C_EDITABLE, # cellrenderer text that holds name editable or not? 
    5857C_SECPIXBUF, # secondary_pixbuf (holds avatar or padlock) 
    59 ) = range(7) 
     58) = range(6) 
    6059 
    6160class RosterWindow: 
     
    166165                        show = helpers.get_global_show() 
    167166                        model.append(None, [self.jabber_state_images['16'][show], 
    168                                 _('Merged accounts'), 'account', '', 'all', False, None]) 
     167                                _('Merged accounts'), 'account', '', 'all', None]) 
    169168                        self.draw_account(account) 
    170169                        return 
     
    181180                model.append(None, [self.jabber_state_images['16'][show], 
    182181                        gtkgui_helpers.escape_for_pango_markup(account), 
    183                         'account', our_jid, account, False, tls_pixbuf]) 
     182                        'account', our_jid, account, tls_pixbuf]) 
    184183 
    185184        def draw_account(self, account): 
     
    314313                                for i in parent_iters: 
    315314                                        # we add some values here. see draw_contact for more 
    316                                         model.append(i, (None, name, 'contact', jid, account, 
    317                                                 False, None)) 
     315                                        model.append(i, (None, name, 'contact', jid, account, None)) 
    318316                                self.draw_contact(jid, account) 
    319317                                self.draw_avatar(jid, account) 
     
    348346                                        self.jabber_state_images['16']['closed'], 
    349347                                        gtkgui_helpers.escape_for_pango_markup(group), 'group', 
    350                                         group, account, False, None]) 
     348                                        group, account, None]) 
    351349                                self.draw_group(group, account) 
    352350                                if model.iter_n_children(IterAcct) == 1: # We added the first one 
     
    367365                        name = contact.get_shown_name() 
    368366                        # we add some values here. see draw_contact for more 
    369                         model.append(iterG, (None, name, typestr, contact.jid, account, 
    370                                 False, None)) 
     367                        model.append(iterG, (None, name, typestr, contact.jid, account, None)) 
    371368 
    372369                        if gajim.groups[account][group]['expand']: 
     
    438435                iterAcct = self.get_account_iter(account) 
    439436                model.append(iterAcct, (None, gajim.nicks[account], 'self_contact', jid, 
    440                         account, False, None)) 
     437                        account, None)) 
    441438                self.draw_contact(jid, account) 
    442439                self.draw_avatar(jid, account) 
     
    13981395        def on_rename(self, widget, iter, path): 
    13991396                # this function is called either by F2 or by Rename menuitem 
    1400                 # to display that menuitem we show a menu, that does focus-out 
    1401                 # we then select Rename and focus-in 
    1402                 # focus-in callback checks on this var and if is NOT None 
    1403                 # it redraws the selected contact resulting in stopping our rename 
    1404                 # procedure. So set this to None to stop that 
    1405                 self._last_selected_contact = [] 
     1397                if gajim.interface.instances.has_key('rename'): 
     1398                        gajim.interface.instances['rename'].dialog.window.present() 
     1399                        return 
    14061400                model = self.tree.get_model() 
    14071401 
     
    14141408                if row_type in ('contact', 'agent'): 
    14151409                        # it's jid 
    1416                         # Remove possible resource indicator (Name (2)) 
    1417                         contact = gajim.contacts.get_first_contact_from_jid(account, jid) 
    1418                         name = contact.name 
    1419                         model[iter][C_NAME] = gtkgui_helpers.escape_for_pango_markup(name) 
     1410                        title = _('Rename Contact') 
     1411                        message = _('Enter a new nickname for contact %s') % jid 
     1412                        old_text = gajim.contacts.get_contact_with_highest_priority(account, 
     1413                                jid).name 
    14201414                elif row_type == 'group': 
    14211415                        if jid in helpers.special_groups + (_('General'),): 
    14221416                                return 
    1423  
    1424                 model[iter][C_EDITABLE] = True # set 'editable' to True 
    1425                 self.tree.set_cursor(path, self.tree.get_column(0), True) 
     1417                        old_text = model[iter][C_JID].decode('utf-8') 
     1418                        title = _('Rename Group') 
     1419                        message = _('Enter a new name for group %s') % old_text 
     1420 
     1421                def on_renamed(new_text, account, row_type, jid, old_text): 
     1422                        if gajim.interface.instances.has_key('rename'): 
     1423                                del gajim.interface.instances['rename'] 
     1424                        if row_type in ('contact', 'agent'): 
     1425                                if old_text == new_text: 
     1426                                        return 
     1427                                for u in gajim.contacts.get_contact(account, jid): 
     1428                                        u.name = new_text 
     1429                                gajim.connections[account].update_contact(jid, new_text, u.groups) 
     1430                                self.draw_contact(jid, account) 
     1431                                # Update opened chat 
     1432                                ctrl = gajim.interface.msg_win_mgr.get_control(jid, account) 
     1433                                if ctrl: 
     1434                                        ctrl.update_ui() 
     1435                                        win = gajim.interface.msg_win_mgr.get_window(jid, account) 
     1436                                        win.redraw_tab(ctrl) 
     1437                                        win.show_title() 
     1438                        elif row_type == 'group': 
     1439                                # in C_JID column, we hold the group name (which is not escaped) 
     1440                                if old_text == new_text: 
     1441                                        return 
     1442                                # Groups may not change name from or to a special groups 
     1443                                for g in helpers.special_groups: 
     1444                                        if g in (new_text, old_text): 
     1445                                                return 
     1446                                # get all contacts in that group 
     1447                                for jid in gajim.contacts.get_jid_list(account): 
     1448                                        contact = gajim.contacts.get_contact_with_highest_priority( 
     1449                                                account, jid) 
     1450                                        if old_text in contact.groups: 
     1451                                                # set them in the new one and remove it from the old 
     1452                                                contact.groups.remove(old_text) 
     1453                                                self.remove_contact(contact, account) 
     1454                                                if new_text not in contact.groups: 
     1455                                                        contact.groups.append(new_text) 
     1456                                                self.add_contact_to_roster(contact.jid, account) 
     1457                                                gajim.connections[account].update_contact(contact.jid, 
     1458                                                        contact.name, contact.groups) 
     1459                                # If last removed iter was not visible, gajim.groups is not cleaned 
     1460                                if gajim.groups[account].has_key(old_text): 
     1461                                        del gajim.groups[account][old_text] 
     1462 
     1463                def on_canceled(): 
     1464                        if gajim.interface.instances.has_key('rename'): 
     1465                                del gajim.interface.instances['rename'] 
     1466                         
     1467                gajim.interface.instances['rename'] = dialogs.InputDialog(title, message, 
     1468                        old_text, False, (on_renamed, account, row_type, jid, old_text), 
     1469                        on_canceled) 
    14261470 
    14271471        def on_remove_group_item_activated(self, widget, group, account): 
     
    23282372                                return 
    23292373                        path = list_of_paths[0] 
    2330                         type = model[path][C_TYPE] 
    2331                         if type in ('contact', 'group', 'agent'): 
    2332                                 if not model[path][C_EDITABLE]: 
    2333                                         # we are NOT already renaming it 
    2334                                         iter = model.get_iter(path) 
    2335                                         self.on_rename(widget, iter, path) 
     2374                        type_ = model[path][C_TYPE] 
     2375                        if type_ in ('contact', 'group', 'agent'): 
     2376                                iter = model.get_iter(path) 
     2377                                self.on_rename(widget, iter, path) 
    23362378 
    23372379                elif event.keyval == gtk.keysyms.Delete: 
     
    33773419                        account = model[iter][C_ACCOUNT].decode('utf-8') 
    33783420                        self.draw_contact(jid, account) 
    3379  
    3380         def on_editing_started(self, cell, event, row): 
    3381                 ''' start editing a cell in the tree''' 
    3382                 path = self.tree.get_cursor()[0] 
    3383                 self.editing_path = path 
    3384  
    3385         def on_editing_canceled(self, cell): 
    3386                 '''editing has been canceled''' 
    3387                 path = self.tree.get_cursor()[0] 
    3388                 # do not set new name if row order has changed 
    3389                 if path != self.editing_path: 
    3390                         self.editing_path = None 
    3391                         return 
    3392                 self.editing_path = None 
    3393                 model = self.tree.get_model() 
    3394                 iter = model.get_iter(path) 
    3395                 account = model[iter][C_ACCOUNT].decode('utf-8') 
    3396                 jid = model[iter][C_JID].decode('utf-8') 
    3397                 type = model[iter][C_TYPE] 
    3398                 # restore the number of resources string at the end of contact name 
    3399                 contacts = gajim.contacts.get_contact(account, jid) 
    3400                 if type in ('contact', 'agent'): 
    3401                         self.draw_contact(jid, account) 
    3402                 # reset editable to False 
    3403                 model[iter][C_EDITABLE] = False 
    3404  
    3405         def on_cell_edited(self, cell, row, new_text): 
    3406                 '''When an iter is edited: 
    3407                 if text has changed, rename the contact''' 
    3408                 model = self.tree.get_model() 
    3409                 # if this is a last item in the group, row is invalid 
    3410                 try: 
    3411                         iter = model.get_iter_from_string(row) 
    3412                 except: 
    3413                         self.editing_path = None 
    3414                         return 
    3415                 path = model.get_path(iter) 
    3416                 # do not set new name if row order has changed 
    3417                 if path != self.editing_path: 
    3418                         self.editing_path = None 
    3419                         return 
    3420                 self.editing_path = None 
    3421                 new_text = new_text.decode('utf-8') 
    3422                 account = model[iter][C_ACCOUNT].decode('utf-8') 
    3423                 jid = model[iter][C_JID].decode('utf-8') 
    3424                 type = model[iter][C_TYPE] 
    3425                 model[iter][C_EDITABLE] = False 
    3426                 if type in ('contact', 'agent'): 
    3427                         old_text = gajim.contacts.get_contact_with_highest_priority(account, 
    3428                                 jid).name 
    3429                         if old_text != new_text: 
    3430                                 for u in gajim.contacts.get_contact(account, jid): 
    3431                                         u.name = new_text 
    3432                                 gajim.connections[account].update_contact(jid, new_text, u.groups) 
    3433                         self.draw_contact(jid, account) 
    3434                         # Update opened chat 
    3435                         ctrl = gajim.interface.msg_win_mgr.get_control(jid, account) 
    3436                         if ctrl: 
    3437                                 ctrl.update_ui() 
    3438                                 win = gajim.interface.msg_win_mgr.get_window(jid, account) 
    3439                                 win.redraw_tab(ctrl) 
    3440                                 win.show_title() 
    3441                 elif type == 'group': 
    3442                         # in C_JID column, we hold the group name (which is not escaped) 
    3443                         old_name = model[iter][C_JID].decode('utf-8') 
    3444                         # Groups may not change name from or to a special groups 
    3445                         for g in helpers.special_groups: 
    3446                                 if g in (new_text, old_name): 
    3447                                         return 
    3448                         # get all contacts in that group 
    3449                         for jid in gajim.contacts.get_jid_list(account): 
    3450                                 contact = gajim.contacts.get_contact_with_highest_priority(account, 
    3451                                         jid) 
    3452                                 if old_name in contact.groups: 
    3453                                         # set them in the new one and remove it from the old 
    3454                                         contact.groups.remove(old_name) 
    3455                                         self.remove_contact(contact, account) 
    3456                                         if not new_text in contact.groups: 
    3457                                                 contact.groups.append(new_text) 
    3458                                         self.add_contact_to_roster(contact.jid, account) 
    3459                                         gajim.connections[account].update_contact(contact.jid, 
    3460                                                 contact.name, contact.groups) 
    3461                         # If last removed iter was not visible, gajim.groups is not cleaned 
    3462                         if gajim.groups[account].has_key(old_name): 
    3463                                 del gajim.groups[account][old_name] 
    34643421 
    34653422        def on_service_disco_menuitem_activate(self, widget, account): 
     
    41294086        def _on_treeview_selection_changed(self, selection): 
    41304087                model, list_of_paths = selection.get_selected_rows() 
    4131                 if len(list_of_paths) == 1 and model[list_of_paths[0]][C_EDITABLE]: 
    4132                         # We are editing this row, do not modify self._last_selected_contact 
    4133                         # Cause that cancel editing 
    4134                         return 
    41354088                if len(self._last_selected_contact): 
    41364089                        # update unselected rows 
     
    42014154 
    42024155                #(icon, name, type, jid, account, editable, secondary_pixbuf) 
    4203                 model = gtk.TreeStore(gtk.Image, str, str, str, str, bool, gtk.gdk.Pixbuf) 
     4156                model = gtk.TreeStore(gtk.Image, str, str, str, str, gtk.gdk.Pixbuf) 
    42044157 
    42054158                model.set_sort_func(1, self.compareIters) 
     
    42984251 
    42994252                render_text = gtk.CellRendererText() # contact or group or account name 
    4300                 render_text.connect('edited', self.on_cell_edited) 
    4301                 render_text.connect('editing-canceled', self.on_editing_canceled) 
    4302                 render_text.connect('editing-started', self.on_editing_started) 
    43034253                col.pack_start(render_text, expand = True) 
    43044254                col.add_attribute(render_text, 'markup', C_NAME) # where we hold the name 
    4305                 col.add_attribute(render_text, 'editable', C_EDITABLE) # where we hold if the row is editable 
    43064255                col.set_cell_data_func(render_text, self.nameCellDataFunc, None) 
    43074256