Changeset 10022 for trunk/src/roster_window.py
- Timestamp:
- 07/25/08 01:53:56 (4 months ago)
- Files:
-
- 1 modified
-
trunk/src/roster_window.py (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/roster_window.py
r9985 r10022 63 63 64 64 from common.xmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC 65 from common.pep import MOODS 65 66 66 67 try: … … 76 77 C_JID, # the jid of the row 77 78 C_ACCOUNT, # cellrenderer text that holds account name 79 C_MOOD, 78 80 C_AVATAR_PIXBUF, # avatar_pixbuf 79 81 C_PADLOCK_PIXBUF, # use for account row only 80 ) = range( 7)82 ) = range(8) 81 83 82 84 class RosterWindow: … … 84 86 85 87 def _get_account_iter(self, name, model = None): 86 ''' Return the gtk.TreeIter of the given account or None if not found. 88 ''' 89 Return the gtk.TreeIter of the given account or None 90 if not found. 87 91 88 92 Keyword arguments: 89 93 name -- the account name 90 94 model -- the data model (default TreeFilterModel) 91 92 95 ''' 93 96 if not model: … … 106 109 107 110 108 def _get_group_iter(self, name, account, account_iter = None, model = None): 109 ''' Return the gtk.TreeIter of the given group or None if not found. 111 def _get_group_iter(self, name, account, account_iter = None, 112 model = None): 113 ''' 114 Return the gtk.TreeIter of the given group or None if not found. 110 115 111 116 Keyword arguments: … … 168 173 if not model: 169 174 model = self.modelfilter 170 if model is None: # when closing Gajim model can be none (async pbs?) 175 # when closing Gajim model can be none (async pbs?) 176 if model is None: 171 177 return [] 172 178 173 179 if jid == gajim.get_jid_from_account(account): 174 contact_iter = self._get_self_contact_iter(jid, account, model) 180 contact_iter = self._get_self_contact_iter(jid, 181 account, model) 175 182 if contact_iter: 176 183 return [contact_iter] … … 179 186 180 187 if not contact: 181 contact = gajim.contacts.get_first_contact_from_jid(account, jid) 188 contact = gajim.contacts.get_first_contact_from_jid( 189 account, jid) 182 190 if not contact: 183 191 # We don't know this contact … … 187 195 found = [] # the contact iters. One per group 188 196 for group in contact.get_shown_groups(): 189 group_iter = self._get_group_iter(group, account, acct, model) 197 group_iter = self._get_group_iter(group, account, 198 acct, model) 190 199 contact_iter = model.iter_children(group_iter) 191 200 … … 193 202 # Loop over all contacts in this group 194 203 iter_jid = model[contact_iter][C_JID] 195 if iter_jid and jid == iter_jid.decode('utf-8') and \ 196 account == model[contact_iter][C_ACCOUNT].decode('utf-8'): 204 if iter_jid and \ 205 jid == iter_jid.decode('utf-8') and account == \ 206 model[contact_iter][C_ACCOUNT].decode('utf-8'): 197 207 # only one iter per group 198 208 found.append(contact_iter) … … 200 210 elif model.iter_has_child(contact_iter): 201 211 # it's a big brother and has children 202 contact_iter = model.iter_children(contact_iter) 212 contact_iter = model.iter_children( 213 contact_iter) 203 214 else: 204 215 # try to find next contact: 205 # other contact in this group or brother contact 206 next_contact_iter = model.iter_next(contact_iter) 216 # other contact in this group or 217 # brother contact 218 next_contact_iter = model.iter_next( 219 contact_iter) 207 220 if next_contact_iter: 208 221 contact_iter = next_contact_iter 209 222 else: 210 # It's the last one. Go up if we are big brother 211 parent_iter = model.iter_parent(contact_iter) 212 if parent_iter and model[parent_iter][C_TYPE] == 'contact': 213 contact_iter = model.iter_next(parent_iter) 223 # It's the last one. 224 # Go up if we are big brother 225 parent_iter = model.iter_parent( 226 contact_iter) 227 if parent_iter and \ 228 model[parent_iter][C_TYPE] == \ 229 'contact': 230 contact_iter = \ 231 model.iter_next( 232 parent_iter) 214 233 else: 215 # we tested all contacts in this group 234 # we tested all 235 # contacts in this group 216 236 contact_iter = None 217 237 return found … … 245 265 while contact_iter: 246 266 yield model[contact_iter] 247 contact_iter = model.iter_next(contact_iter) 267 contact_iter = model.iter_next( 268 contact_iter) 248 269 group_iter = model.iter_next(group_iter) 249 270 account_iter = model.iter_next(account_iter) … … 255 276 256 277 def add_account(self, account): 257 '''Add account to roster and draw it. Do nothing if it is already in.''' 278 ''' 279 Add account to roster and draw it. Do nothing if it is 280 already in. 281 ''' 258 282 if self._get_account_iter(account): 259 283 # Will happen on reconnect or for merged accounts … … 263 287 # Merged accounts view 264 288 show = helpers.get_global_show() 265 self.model.append(None, [gajim.interface.jabber_state_images['16'][ 266 show], _('Merged accounts'), 'account', '', 'all', None, None]) 267 else: 268 show = gajim.SHOW_LIST[gajim.connections[account].connected] 289 self.model.append(None, [ 290 gajim.interface.jabber_state_images['16'][show], 291 _('Merged accounts'), 'account', '', 'all', 292 None, None, None]) 293 else: 294 show = gajim.SHOW_LIST[gajim.connections[account]. \ 295 connected] 269 296 our_jid = gajim.get_jid_from_account(account) 270 297 … … 273 300 # the only way to create a pixbuf from stock 274 301 tls_pixbuf = self.window.render_icon( 275 gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_MENU) 276 277 self.model.append(None, [gajim.interface.jabber_state_images['16'][ 278 show], gobject.markup_escape_text(account), 'account', our_jid, 279 account, None, tls_pixbuf]) 302 gtk.STOCK_DIALOG_AUTHENTICATION, 303 gtk.ICON_SIZE_MENU) 304 305 self.model.append(None, [ 306 gajim.interface.jabber_state_images['16'][show], 307 gobject.markup_escape_text(account), 'account', 308 our_jid, account, None, None, tls_pixbuf]) 280 309 281 310 self.draw_account(account) … … 316 345 contact -- the contact to add 317 346 account -- the contacts account 318 groups -- list of groups to add the contact to. (default groups in319 contact.get_shown_groups()).347 groups -- list of groups to add the contact to. 348 (default groups in contact.get_shown_groups()). 320 349 Parameter ignored when big_brother_contact is specified. 321 big_brother_contact -- if specified contact is added as child 322 big_brother_contact. (default None)350 big_brother_contact -- if specified contact is added as child 351 big_brother_contact. (default None) 323 352 ''' 324 353 added_iters = [] … … 326 355 # Add contact under big brother 327 356 328 parent_iters = self._get_contact_iter(big_brother_contact.jid, 329 big_brother_account, big_brother_contact, self.model) 357 parent_iters = self._get_contact_iter( 358 big_brother_contact.jid, big_brother_account, 359 big_brother_contact, self.model) 330 360 assert len(parent_iters) > 0,\ 331 361 'Big brother is not yet in roster!' … … 333 363 # Do not confuse get_contact_iter 334 364 # Sync groups of family members 335 contact.groups = big_brother_contact.get_shown_groups()[:] 365 contact.groups = \ 366 big_brother_contact.get_shown_groups()[:] 336 367 337 368 for child_iter in parent_iters: 338 it = self.model.append(child_iter, (None, contact.get_shown_name(), 339 'contact', contact.jid, account, None, None)) 369 it = self.model.append(child_iter, (None, 370 contact.get_shown_name(), 'contact', 371 contact.jid, account, None, None, None)) 340 372 added_iters.append(it) 341 373 else: … … 344 376 groups = contact.get_shown_groups() 345 377 for group in groups: 346 child_iterG = self._get_group_iter(group, account, model=self.model) 378 child_iterG = self._get_group_iter(group, 379 account, model = self.model) 347 380 if not child_iterG: 348 381 # Group is not yet in roster, add it! 349 child_iterA = self._get_account_iter(account, self.model) 350 child_iterG = self.model.append(child_iterA, [ 351 gajim.interface.jabber_state_images['16']['closed'], 352 gobject.markup_escape_text(group), 'group', 353 group, account, None, None]) 382 child_iterA = self._get_account_iter( 383 account, self.model) 384 child_iterG = self.model.append( 385 child_iterA, [gajim.interface. \ 386 jabber_state_images['16'] \ 387 ['closed'], gobject. \ 388 markup_escape_text(group), 389 'group', group, account, None, 390 None, None]) 354 391 self.draw_group(group, account) 355 392 … … 361 398 typestr = 'contact' 362 399 363 # we add some values here. see draw_contact for more 364 i_ = self.model.append(child_iterG, (None, contact.get_shown_name(), 365 typestr, contact.jid, account, None, None)) 400 # we add some values here. see draw_contact 401 # for more 402 i_ = self.model.append(child_iterG, (None, 403 contact.get_shown_name(), typestr, 404 contact.jid, account, None, None, None)) 366 405 added_iters.append(i_) 367 406 … … 372 411 is_expanded = True 373 412 if group not in gajim.groups[account]: 374 gajim.groups[account][group] = {'expand': is_expanded} 375 376 assert len(added_iters), '%s has not been added to roster!' % contact.jid 413 gajim.groups[account][group] = \ 414 {'expand': is_expanded} 415 416 assert len(added_iters), '%s has not been added to roster!' % \ 417 contact.jid 377 418 for titer in added_iters: 378 419 assert self.model[titer][C_JID] == contact.jid and \ … … 385 426 386 427 Empty groups after contact removal are removed too. 387 Return False if contact still has children and deletion was not performed. 428 Return False if contact still has children and deletion was 429 not performed. 388 430 Return True on success. 389 431 … … 393 435 groups -- list of groups to remove the contact from. 394 436 ''' 395 iters = self._get_contact_iter(contact.jid, account, contact, self.model) 396 assert iters, '%s shall be removed but is not in roster' % contact.jid 437 iters = self._get_contact_iter(contact.jid, account, contact, 438 self.model) 439 assert iters, '%s shall be removed but is not in roster' % \ 440 contact.jid 397 441 398 442 parent_iter = self.model.iter_parent(iters[0]) … … 402 446 # Only remove from specified groups 403 447 all_iters = iters[:] 404 group_iters = [self._get_group_iter(group, account) for group in\405 groups]448 group_iters = [self._get_group_iter(group, account) \ 449 for group in groups] 406 450 iters = [titer for titer in all_iters 407 451 if self.model.iter_parent(titer) in group_iters] … … 421 465 if parent_type == 'group' and \ 422 466 self.model.iter_n_children(parent_i) == 1: 423 group = self.model[parent_i][C_JID].decode('utf-8') 467 group = self.model[parent_i][C_JID]. \ 468 decode('utf-8') 424 469 if gajim.groups[account].has_key(group): 425 470 del gajim.groups[account][group] … … 430 475 431 476 def _add_metacontact_family(self, family, account): 432 '''Add the give Metacontact family to roster data model. 477 ''' 478 Add the give Metacontact family to roster data model. 433 479 434 480 Add Big Brother to his groups and all others under him. 435 Return list of all added (contact, account) tuples with Big Brother436 as first element.481 Return list of all added (contact, account) tuples with 482 Big Brother as first element. 437 483 438 484 Keyword arguments: … … 445 491 big_brother_account, big_brother_jid) 446 492 447 assert len(self._get_contact_iter(big_brother_jid, big_brother_account,448 big_brother_ contact, self.model)) == 0,\449 'Big brother %s already in roster \n Family: %s' % (big_brother_jid,450 family)493 assert len(self._get_contact_iter(big_brother_jid, 494 big_brother_account, big_brother_contact, self.model)) \ 495 == 0, 'Big brother %s already in roster\n Family: %s' \ 496 % (big_brother_jid, family) 451 497 self._add_entity(big_brother_contact, big_brother_account) 452 498 … … 456 502 _account = data['account'] 457 503 _jid = data['jid'] 458 _contact = gajim.contacts.get_first_contact_from_jid(_account, _jid) 504 _contact = gajim.contacts.get_first_contact_from_jid( 505 _account, _jid) 459 506 460 507 if not _contact or _contact == big_brother_contact: … … 463 510 continue 464 511 465 assert len(self._get_contact_iter(_jid, _account, _contact, self.model) 466 ) == 0, "%s already in roster. \n Family: %s" % (_jid, nearby_family) 467 self._add_entity(_contact, _account, big_brother_contact = \ 468 big_brother_contact, big_brother_account=big_brother_account) 512 assert len(self._get_contact_iter(_jid, _account, 513 _contact, self.model)) == 0, "%s already in " \ 514 "roster.\n Family: %s" % (_jid, nearby_family) 515 self._add_entity(_contact, _account, 516 big_brother_contact = big_brother_contact, 517 big_brother_account = big_brother_account) 469 518 brothers.append((_contact, _account)) 470 519 … … 473 522 474 523 def _remove_metacontact_family(self, family, account): 475 '''Remove the given Metacontact family from roster data model. 476 477 See Contacts.get_metacontacts_family() and RosterWindow._remove_entity() 524 ''' 525 Remove the given Metacontact family from roster data model. 526 527 See Contacts.get_metacontacts_family() and 528 RosterWindow._remove_entity() 478 529 ''' 479 530 nearby_family = self._get_nearby_family_and_big_brother( … … 599 650 child_iterA = self._get_account_iter(account, self.model) 600 651 self.model.append(child_iterA, (None, gajim.nicks[account], 601 'self_contact', jid, account, None, None ))652 'self_contact', jid, account, None, None, None)) 602 653 603 654 self.draw_contact(jid, account) … … 964 1015 contact_instances) 965 1016 966 child_iters = self._get_contact_iter(jid, account, contact, self.model) 1017 child_iters = self._get_contact_iter(jid, account, 1018 contact, self.model) 967 1019 if not child_iters: 968 1020 return False … … 975 1027 nb_unread = len(gajim.events.get_events(account, jid, 976 1028 ['printed_marked_gc_msg'])) 977 nb_unread += \978 gajim.interface.minimized_controls[account][jid].get_nb_unread_pm()1029 nb_unread += gajim.interface.minimized_controls \ 1030 [account][jid].get_nb_unread_pm() 979 1031 980 1032 if nb_unread == 1: … … 989 1041 else: 990 1042 for group in contact.get_shown_groups(): 991 if group in gajim.connections[account].blocked_groups: 1043 if group in \ 1044 gajim.connections[account].blocked_groups: 992 1045 strike = True 993 1046 break … … 1003 1056 name += ' (' + unicode(nb_connected_contact) + ')' 1004 1057 1005 # show (account_name) if there are 2 contact with same jid in merged mode 1058 # show (account_name) if there are 2 contact with same jid 1059 # in merged mode 1006 1060 if self.regroup: 1007 1061 add_acct = False 1008 1062 # look through all contacts of all accounts 1009 1063 for account_ in gajim.connections: 1010 if account_ == account: # useless to add accout name 1064 # useless to add account name 1065 if account_ == account: 1011 1066 continue 1012 for jid_ in gajim.contacts.get_jid_list(account_): 1013 contact_ = gajim.contacts.get_first_contact_from_jid(account_, 1014 jid_) 1015 if contact_.get_shown_name() == contact.get_shown_name() and \ 1067 for jid_ in \ 1068 gajim.contacts.get_jid_list(account_): 1069 contact_ = gajim.contacts. \ 1070 get_first_contact_from_jid( 1071 account_, jid_) 1072 if contact_.get_shown_name() == \ 1073 contact.get_shown_name() and \ 1016 1074 (jid_, account_) != (jid, account): 1017 1075 add_acct = True 1018 1076 break 1019 1077 if add_acct: 1020 # No need to continue in other account if we already found one 1078 # No need to continue in other account 1079 # if we already found one 1021 1080 break 1022 1081 if add_acct: 1023 1082 name += ' (' + account + ')' 1024 1083 1025 # add status msg, if not empty, under contact name in the treeview 1026 if contact.status and gajim.config.get('show_status_msgs_in_roster'): 1084 # add status msg, if not empty, under contact name in 1085 # the treeview 1086 if contact.status \ 1087 and gajim.config.get('show_status_msgs_in_roster'): 1027 1088 status = contact.status.strip() 1028 1089 if status != '': 1029 status = helpers.reduce_chars_newlines(status, max_lines = 1) 1030 # escape markup entities and make them small italic and fg color 1031 # color is calcuted to be always readable 1032 color = gtkgui_helpers._get_fade_color(self.tree, selected, focus) 1033 colorstring = '#%04x%04x%04x' % (color.red, color.green, color.blue) 1034 name += \ 1035 '\n<span size="small" style="italic" foreground="%s">%s</span>' \ 1036 % (colorstring, gobject.markup_escape_text(status)) 1090 status = helpers.reduce_chars_newlines(status, 1091 max_lines = 1) 1092 # escape markup entities and make them small 1093 # italic and fg color color is calcuted to be 1094 # always readable 1095 color = gtkgui_helpers._get_fade_color( 1096 self.tree, selected, focus) 1097 colorstring = '#%04x%04x%04x' % (color.red, 1098 color.green, color.blue) 1099 name += '\n<span size="small" style="italic" ' \ 1100 'foreground="%s">%s</span>' % ( 1101 colorstring, 1102 gobject.markup_escape_text(status)) 1037 1103 1038 1104 icon_name = helpers.get_icon_name_to_show(contact, account) … … 1040 1106 for c in contact_instances: 1041 1107 c_icon_name = helpers.get_icon_name_to_show(c, account) 1042 if c_icon_name in ('event', 'muc_active', 'muc_inactive'): 1108 if c_icon_name \ 1109 in ('event', 'muc_active', 'muc_inactive'): 1043 1110 icon_name = c_icon_name 1044 1111
