def __init__(self, conn_accts): Observable.__init__(self) self.dirty = False self.sorting_paused = True #self._listen_for_pref_load() self.rebuild_timer = wx.PyTimer(self.rebuild_later) self.rebuild_timer.StartRepeating(500) # Holds the final view that goes into the TreeList. self.view = DGroup('__root__', [], []) self.info = {} # Rootgroups are the "protocol" rootgroups with the original, # unmodified versions of the buddy list structure for each account self.rootgroups = [] self.base_attrs = frozenset([None, 'alias', 'status', 'status_message', 'icon', 'icon_hash', 'entering', 'leaving', 'idle', 'away','mobile']) self.attrs = set(self.base_attrs) # conn_accts must be an observable list of connected accounts conn_accts.add_observer(self.on_connections_changed) self.metacontacts = MetaContactManager(self) self._init_order() self.contact_info_changed = Delegate() self.dispatch = ContactDispatcher() self.caches = dict(tofrom = DiskCache('im_history.dat', validator = validate_tofrom)) self.load_local_data() # save local to/from data on exit hooks.register('digsby.app.exit', self.save_local_data) self._search_by = u'' self._search_results = (0, 0) # number of contacts found in last two searches #todo: make then_bys based on a pref self.sort_models = sort_model.build_models( then_bys = 1, obj = self) self.sbw = sort_model.SortByWatcher(self.sort_models)
def update_data(self, data): """ Updates this store's current state with incoming data from the network. data should be a mapping containing 'metacontacts', 'order', and 'info' structures (see comment at top of file) """ rebuild = False # This method needs to substitute some defaultdicts for the normal # dictionaries that come back from the server. # Metacontact information #if data['metacontacts'] mc_dict = data.get('metacontacts', {}) if not isinstance(mc_dict, dict): log.critical('invalid metacontacts dictionary') mc_dict = {} # Contact information like SMS numbers and email addresses. self.info = defaultdict(dict) si = self.info if 'info' in data: for (k, v) in data['info'].iteritems(): if isinstance(k, str): cmpk = k.decode('utf8') else: cmpk = k if not isinstance(cmpk, unicode): continue if cmpk.startswith('Meta') or any((cmpk.endswith('_' + prot) for prot in protocols.iterkeys())): if any(v.values()): si[k] = v for c, v in si.iteritems(): for attr in ('email', 'sms'): if attr in v: self.contact_info_changed(c, attr, v[attr]) self.metacontacts = MetaContactManager(self, mc_dict) if hasattr(self, 'new_sorter'): on_thread('sorter').call(self.new_sorter.removeAllContacts) rebuild = True # Manual ordering of groups try: self.order = deepcopy(data['order']) self.order['groups'] = list(oset(self.order['groups'])) contacts = self._filtered_contacts() self.order['contacts'] = defaultdict(list) self.order['contacts'].update(contacts) except Exception: log.critical('error receiving order') self._init_order() # note: loading tofrom data from the network is deprecated. this data # now goes out to disk. see save/load_local_data if 'tofrom' in data and isinstance(data['tofrom'], dict) and \ 'im' in data['tofrom'] and 'email' in data['tofrom']: self.dispatch.set_tofrom(deepcopy(data['tofrom'])) if rebuild: self.rebuild() self.update_order()