Changeset 7467
- Timestamp:
- 11/18/06 21:51:50 (2 years ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
data/glade/input_dialog.glade (modified) (1 diff)
-
src/dialogs.py (modified) (3 diffs)
-
src/roster_window.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/glade/input_dialog.glade
r6265 r7467 18 18 <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> 19 19 <property name="focus_on_map">True</property> 20 <property name="urgency_hint">False</property> 20 21 <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"/> 21 23 22 24 <child internal-child="vbox"> -
trunk/src/dialogs.py
r7425 r7467 1003 1003 '''Class for Input dialog''' 1004 1004 def __init__(self, title, label_str, input_str = None, is_modal = True, 1005 ok_handler = None):1005 ok_handler = None, cancel_handler = None): 1006 1006 # if modal is True you also need to call get_response() 1007 1007 # and ok_handler won't be used … … 1012 1012 self.dialog.set_title(title) 1013 1013 label.set_markup(label_str) 1014 self.cancel_handler = cancel_handler 1014 1015 if input_str: 1015 1016 self.input_entry.set_text(input_str) … … 1023 1024 cancelbutton = self.xml.get_widget('cancelbutton') 1024 1025 cancelbutton.connect('clicked', self.on_cancelbutton_clicked) 1026 self.xml.signal_autoconnect(self) 1025 1027 self.dialog.show_all() 1026 1028 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): 1028 1034 user_input = self.input_entry.get_text().decode('utf-8') 1029 1035 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) 1031 1040 1032 def on_cancelbutton_clicked(self, widget):1041 def on_cancelbutton_clicked(self, widget): 1033 1042 self.dialog.destroy() 1034 1043 -
trunk/src/roster_window.py
r7457 r7467 55 55 C_JID, # the jid of the row 56 56 C_ACCOUNT, # cellrenderer text that holds account name 57 C_EDITABLE, # cellrenderer text that holds name editable or not?58 57 C_SECPIXBUF, # secondary_pixbuf (holds avatar or padlock) 59 ) = range( 7)58 ) = range(6) 60 59 61 60 class RosterWindow: … … 166 165 show = helpers.get_global_show() 167 166 model.append(None, [self.jabber_state_images['16'][show], 168 _('Merged accounts'), 'account', '', 'all', False,None])167 _('Merged accounts'), 'account', '', 'all', None]) 169 168 self.draw_account(account) 170 169 return … … 181 180 model.append(None, [self.jabber_state_images['16'][show], 182 181 gtkgui_helpers.escape_for_pango_markup(account), 183 'account', our_jid, account, False,tls_pixbuf])182 'account', our_jid, account, tls_pixbuf]) 184 183 185 184 def draw_account(self, account): … … 314 313 for i in parent_iters: 315 314 # 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)) 318 316 self.draw_contact(jid, account) 319 317 self.draw_avatar(jid, account) … … 348 346 self.jabber_state_images['16']['closed'], 349 347 gtkgui_helpers.escape_for_pango_markup(group), 'group', 350 group, account, False,None])348 group, account, None]) 351 349 self.draw_group(group, account) 352 350 if model.iter_n_children(IterAcct) == 1: # We added the first one … … 367 365 name = contact.get_shown_name() 368 366 # 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)) 371 368 372 369 if gajim.groups[account][group]['expand']: … … 438 435 iterAcct = self.get_account_iter(account) 439 436 model.append(iterAcct, (None, gajim.nicks[account], 'self_contact', jid, 440 account, False,None))437 account, None)) 441 438 self.draw_contact(jid, account) 442 439 self.draw_avatar(jid, account) … … 1398 1395 def on_rename(self, widget, iter, path): 1399 1396 # 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 1406 1400 model = self.tree.get_model() 1407 1401 … … 1414 1408 if row_type in ('contact', 'agent'): 1415 1409 # it's jid 1416 # Remove possible resource indicator (Name (2))1417 contact = gajim.contacts.get_first_contact_from_jid(account, jid)1418 name = contact.name1419 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 1420 1414 elif row_type == 'group': 1421 1415 if jid in helpers.special_groups + (_('General'),): 1422 1416 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) 1426 1470 1427 1471 def on_remove_group_item_activated(self, widget, group, account): … … 2328 2372 return 2329 2373 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) 2336 2378 2337 2379 elif event.keyval == gtk.keysyms.Delete: … … 3377 3419 account = model[iter][C_ACCOUNT].decode('utf-8') 3378 3420 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 = path3384 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 changed3389 if path != self.editing_path:3390 self.editing_path = None3391 return3392 self.editing_path = None3393 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 name3399 contacts = gajim.contacts.get_contact(account, jid)3400 if type in ('contact', 'agent'):3401 self.draw_contact(jid, account)3402 # reset editable to False3403 model[iter][C_EDITABLE] = False3404 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 invalid3410 try:3411 iter = model.get_iter_from_string(row)3412 except:3413 self.editing_path = None3414 return3415 path = model.get_path(iter)3416 # do not set new name if row order has changed3417 if path != self.editing_path:3418 self.editing_path = None3419 return3420 self.editing_path = None3421 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] = False3426 if type in ('contact', 'agent'):3427 old_text = gajim.contacts.get_contact_with_highest_priority(account,3428 jid).name3429 if old_text != new_text:3430 for u in gajim.contacts.get_contact(account, jid):3431 u.name = new_text3432 gajim.connections[account].update_contact(jid, new_text, u.groups)3433 self.draw_contact(jid, account)3434 # Update opened chat3435 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 groups3445 for g in helpers.special_groups:3446 if g in (new_text, old_name):3447 return3448 # get all contacts in that group3449 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 old3454 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 cleaned3462 if gajim.groups[account].has_key(old_name):3463 del gajim.groups[account][old_name]3464 3421 3465 3422 def on_service_disco_menuitem_activate(self, widget, account): … … 4129 4086 def _on_treeview_selection_changed(self, selection): 4130 4087 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_contact4133 # Cause that cancel editing4134 return4135 4088 if len(self._last_selected_contact): 4136 4089 # update unselected rows … … 4201 4154 4202 4155 #(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) 4204 4157 4205 4158 model.set_sort_func(1, self.compareIters) … … 4298 4251 4299 4252 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)4303 4253 col.pack_start(render_text, expand = True) 4304 4254 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 editable4306 4255 col.set_cell_data_func(render_text, self.nameCellDataFunc, None) 4307 4256
