def on_yes(dummy, fjid, file_props, account): # Delete old file os.remove(file_props.file_name) jid, resource = gajim.get_room_and_nick_from_fjid(fjid) if resource: contact = gajim.contacts.get_contact(account, jid, resource) else: contact = gajim.contacts.get_contact_with_highest_priority( account, jid) fjid = contact.get_full_jid() # Request the file to the sender sid = helpers.get_random_string_16() new_file_props = FilesProp.getNewFileProp(account, sid) new_file_props.file_name = file_props.file_name new_file_props.name = file_props.name new_file_props.desc = file_props.desc new_file_props.size = file_props.size new_file_props.date = file_props.date new_file_props.hash_ = file_props.hash_ new_file_props.type_ = 'r' tsid = gajim.connections[account].start_file_transfer(fjid, new_file_props, True) new_file_props.transport_sid = tsid self.add_transfer(account, contact, new_file_props)
def execute(self, request): account = self.connection.name # Forward messages events = gajim.events.get_events( account, types=['chat', 'normal', 'printed_chat']) j, resource = gajim.get_room_and_nick_from_fjid(self.jid) for jid in events: for event in events[jid]: ev_typ = event.type_ if ev_typ == 'printed_chat': ev_typ = 'chat' gajim.nec.push_outgoing_event( MessageOutgoingEvent(None, account=account, jid=j, message=event.message, type_=ev_typ, subject=event.subject, resource=resource, forward_from=jid, delayed=event.time_)) # Inform other client of completion response, cmd = self.buildResponse(request, status='completed') cmd.addChild('note', {}, _('All unread messages have been forwarded.')) self.connection.connection.send(response) return False # finish the session
def execute(self, request): account = self.connection.name # Forward messages events = gajim.events.get_events(account, types=['chat', 'normal']) j, resource = gajim.get_room_and_nick_from_fjid(self.jid) for jid in events: for event in events[jid]: ev_typ = event.type_ if ev_typ == 'printed_chat': ev_typ = 'chat' gajim.nec.push_outgoing_event( MessageOutgoingEvent(None, account=account, jid=j, message=event.message, type_=ev_typ, subject=event.subject, resource=resource, forward_from=jid, delayed=event.time_, now=True)) response, cmd = self.buildResponse(request, status='completed') cmd.addChild('note', {}, _('The status has been changed.')) # if going offline, we need to push response so it won't go into # queue and disappear self.connection.connection.send(response, now=True) # send new status gajim.interface.roster.send_status(self.connection.name, 'offline', '') # finish the session return False
def _get_contact_or_gc_contact_for_jid(self, jid): contact = gajim.contacts.get_contact_from_full_jid(self._account, jid) if contact is None: room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) contact = gajim.contacts.get_gc_contact(self._account, room_jid, nick) return contact
def delete_pep(jid, name): (user, resource) = gajim.get_room_and_nick_from_fjid(jid) if jid == gajim.get_jid_from_account(name): acc = gajim.connections[name] del acc.activity acc.activity = {} del acc.tune acc.tune = {} del acc.mood acc.mood = {} for contact in gajim.contacts.get_contacts(name, user): del contact.activity contact.activity = {} del contact.tune contact.tune = {} del contact.mood contact.mood = {} if jid == gajim.get_jid_from_account(name): gajim.interface.roster.draw_account(name) gajim.interface.roster.draw_activity(user, name) gajim.interface.roster.draw_tune(user, name) gajim.interface.roster.draw_mood(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_activity() ctrl.update_tune() ctrl.update_mood()
def caps_disco_received(self, iq_obj): if not self.config['show_in_roster']: return roster = gajim.interface.roster contact = gajim.contacts.get_contact_from_full_jid( iq_obj.conn.name, iq_obj.jid) if contact is None: room_jid, nick = gajim.get_room_and_nick_from_fjid(iq_obj.fjid) contact = gajim.contacts.get_gc_contact(iq_obj.conn.name, room_jid, nick) if contact: gc_control = gajim.interface.msg_win_mgr.get_gc_control( iq_obj.jid, iq_obj.conn.name) iter_ = gc_control.get_contact_iter(nick) self.set_icon(gc_control.model, iter_, self.muc_renderer_num, None, contact) return if not contact: return child_iters = roster._get_contact_iter(iq_obj.jid, iq_obj.conn.name, contact, roster.model) if not child_iters: return for iter_ in child_iters: caps = contact.client_caps._node caps_ = self.check_jid(iq_obj.jid) if caps_: caps = caps_ self.set_icon(roster.model, iter_, self.renderer_num, caps, contact)
def caps_disco_received(self, iq_obj): if not self.config['show_in_roster']: return roster = gajim.interface.roster contact = gajim.contacts.get_contact_from_full_jid(iq_obj.conn.name, iq_obj.jid) if contact is None: room_jid, nick = gajim.get_room_and_nick_from_fjid(iq_obj.fjid) contact = gajim.contacts.get_gc_contact(iq_obj.conn.name, room_jid, nick) if contact: gc_control = gajim.interface.msg_win_mgr.get_gc_control( iq_obj.jid, iq_obj.conn.name) iter_ = gc_control.get_contact_iter(nick) self.set_icon(gc_control.model, iter_, self.muc_renderer_num, None, contact) return if not contact: return child_iters = roster._get_contact_iter(iq_obj.jid, iq_obj.conn.name, contact, roster.model) if not child_iters: return for iter_ in child_iters: caps = contact.client_caps._node caps_ = self.check_jid(iq_obj.jid) if caps_: caps = caps_ self.set_icon(roster.model, iter_, self.renderer_num, caps, contact)
def execute(self, request): account = self.connection.name # Forward messages events = gajim.events.get_events(account, types=['chat', 'normal']) j, resource = gajim.get_room_and_nick_from_fjid(self.jid) for jid in events: for event in events[jid]: ev_typ = event.type_ if ev_typ == 'printed_chat': ev_typ = 'chat' gajim.nec.push_outgoing_event(MessageOutgoingEvent(None, account=account, jid=j, message=event.message, type_=ev_typ, subject=event.subject, resource=resource, forward_from=jid, delayed=event.time_, now=True)) response, cmd = self.buildResponse(request, status = 'completed') cmd.addChild('note', {}, _('The status has been changed.')) # if going offline, we need to push response so it won't go into # queue and disappear self.connection.connection.send(response, now = True) # send new status gajim.interface.roster.send_status(self.connection.name, 'offline', '') # finish the session return False
def on_event_added(self, event): account = event.account jid = event.jid when = time.localtime() contact = "" key = (account, jid) if event.type_ == "chat" or \ event.type_ == "printed_chat" or \ event.type_ == "normal" or \ event.type_ == "printed_normal" or \ event.type_ == "file-request" or \ event.type_ == "jingle-incoming": contact = gajim.contacts.get_contact_from_full_jid(account, jid) if contact: contact = contact.get_shown_name() else: contact = jid elif event.type_ == "pm" or event.type_ == "printed_pm": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) + \ "/" + gajim.get_room_and_nick_from_fjid(jid)[1] elif event.type_ == "printed_marked_gc_msg": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) else: return #print account, jid, when, contact event.time = when if key not in self.events: icon = None if gajim.config.get("show_avatars_in_roster"): pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid) if pixbuf not in (None, "ask"): icon = gtk.Image() icon.set_from_pixbuf(pixbuf) else: file_path = gtkgui_helpers.get_path_to_generic_or_avatar(jid) if os.path.isfile(file_path): fd = fopen(file_path, 'rb') data = fd.read() icon = gtk.Image() icon.set_from_pixbuf(gtkgui_helpers.get_pixbuf_from_data(data)) item = gtk.ImageMenuItem(contact + " (1)") if icon: item.set_image(icon) item.set_always_show_image(True) item.connect("activate", self.event_raise, event) item.show() self.menu.insert(item, self.menuEventInsertIndex) self.event_separator.show() self.events[key] = {} self.events[key]['item'] = item self.events[key]['contact'] = contact self.events[key]['events'] = [event] else: self.events[key]['events'].append(event) item = self.events[key]['item'] item.set_label(self.events[key]['contact'] + " (" + str(len(self.events[key]['events'])) + ")") self.indicator.set_status(appindicator.STATUS_ATTENTION)
def on_event_added(self, event): account = event.account jid = event.jid when = time.time() contact = "" key = (account, jid) if event.type_ == "chat" or \ event.type_ == "printed_chat" or \ event.type_ == "normal" or \ event.type_ == "printed_normal" or \ event.type_ == "file-request" or \ event.type_ == "jingle-incoming": contact = gajim.contacts.get_contact_from_full_jid(account, jid) if contact: contact = contact.get_shown_name() else: contact = jid elif event.type_ == "pm" or event.type_ == "printed_pm": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) + \ "/" + gajim.get_room_and_nick_from_fjid(jid)[1] elif event.type_ == "printed_marked_gc_msg": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) else: return #print account, jid, when, contact event.time = when if key not in self.events: icon = None if gajim.config.get("show_avatars_in_roster"): pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid) if pixbuf not in (None, "ask"): icon = gtk.Image() icon.set_from_pixbuf(pixbuf) else: file_path = gtkgui_helpers.get_path_to_generic_or_avatar(jid) if os.path.isfile(file_path): fd = fopen(file_path, 'rb') data = fd.read() icon = gtk.Image() icon.set_from_pixbuf(gtkgui_helpers.get_pixbuf_from_data(data)) item = gtk.ImageMenuItem(contact + " (1)") if icon: item.set_image(icon) item.set_always_show_image(True) item.connect("activate", self.event_raise, event) item.show() self.menu.insert(item, self.menuEventInsertIndex) self.event_separator.show() self.events[key] = {} self.events[key]['item'] = item self.events[key]['contact'] = contact self.events[key]['events'] = [event] else: self.events[key]['events'].append(event) item = self.events[key]['item'] item.set_label(self.events[key]['contact'] + " (" + str(len(self.events[key]['events'])) + ")") self.indicator.set_status(appindicator.STATUS_ATTENTION)
def user_mood(items, name, jid): has_child = False retract = False mood = None text = None for item in items.getTags('item'): child = item.getTag('mood') if child is not None: has_child = True for ch in child.getChildren(): if ch.getName() != 'text': mood = ch.getName() else: text = ch.getData() if items.getTag('retract') is not None: retract = True if jid == gajim.get_jid_from_account(name): acc = gajim.connections[name] if has_child: if 'mood' in acc.mood: del acc.mood['mood'] if 'text' in acc.mood: del acc.mood['text'] if mood is not None: acc.mood['mood'] = mood if text is not None: acc.mood['text'] = text elif retract: if 'mood' in acc.mood: del acc.mood['mood'] if 'text' in acc.mood: del acc.mood['text'] (user, resource) = gajim.get_room_and_nick_from_fjid(jid) for contact in gajim.contacts.get_contacts(name, user): if has_child: if 'mood' in contact.mood: del contact.mood['mood'] if 'text' in contact.mood: del contact.mood['text'] if mood is not None: contact.mood['mood'] = mood if text is not None: contact.mood['text'] = text elif retract: if 'mood' in contact.mood: del contact.mood['mood'] if 'text' in contact.mood: del contact.mood['text'] if jid == gajim.get_jid_from_account(name): gajim.interface.roster.draw_account(name) gajim.interface.roster.draw_mood(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_mood()
def read_queue(self, jid): '''read queue and print messages containted in it''' l = gajim.awaiting_events[self.account][jid] contact = self.contacts[jid] # Is it a pm ? is_pm = False room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) gcs = gajim.interface.instances[self.account]['gc'] if gcs.has_key(room_jid): is_pm = True events_to_keep = [] for event in l: typ = event[0] if typ != 'chat': events_to_keep.append(event) continue data = event[1] kind = data[2] if kind == 'error': kind = 'status' else: kind = 'print_queue' self.print_conversation(data[0], jid, kind, tim = data[3], encrypted = data[4], subject = data[1]) # remove from gc nb_unread if it's pm or from roster if is_pm: gcs[room_jid].nb_unread[room_jid] -= 1 else: gajim.interface.roster.nb_unread -= 1 if is_pm: gcs[room_jid].show_title() else: gajim.interface.roster.show_title() # Keep only non-messages events if len(events_to_keep): gajim.awaiting_events[self.account][jid] = events_to_keep else: del gajim.awaiting_events[self.account][jid] typ = 'chat' # Is it a normal chat or a pm ? # reset to status image in gc if it is a pm gcs = gajim.interface.instances[self.account]['gc'] if gcs.has_key(room_jid): gcs[room_jid].draw_all_roster() typ = 'pm' gajim.interface.roster.draw_contact(jid, self.account) if gajim.interface.systray_enabled: gajim.interface.systray.remove_jid(jid, self.account, typ) if (contact.show == 'offline' or contact.show == 'error'): showOffline = gajim.config.get('showoffline') if not showOffline and typ == 'chat' and \ len(gajim.contacts[self.account][jid]) == 1: gajim.interface.roster.really_remove_contact(contact, self.account) elif typ == 'pm': gcs[room_jid].remove_contact(room_jid, nick)
def presence_received(self, iq_obj): roster = gajim.interface.roster contact = gajim.contacts.get_contact_from_full_jid( iq_obj.conn.name, iq_obj.jid) if contact is None: room_jid, nick = gajim.get_room_and_nick_from_fjid(iq_obj.fjid) contact = gajim.contacts.get_gc_contact(iq_obj.conn.name, room_jid, nick) if contact: self.gc_presence_received(iq_obj, contact) return if not contact: return if not self.config['show_in_roster']: return contact = gajim.contacts.get_contact_with_highest_priority( iq_obj.conn.name, iq_obj.jid) if iq_obj.resource == 'local': # zeroconf return iters = roster._get_contact_iter(iq_obj.jid, iq_obj.conn.name, contact, roster.model) iter_ = iters[0] if contact.show == 'error': self.set_icon(roster.model, iter_, self.renderer_num, None, contact) return if contact.get_full_jid() != iq_obj.fjid: # higest contact changed if roster.model[iter_][self.renderer_num] is not None: caps = contact.client_caps._node if caps: self.set_icon(roster.model, iter_, self.renderer_num, caps, contact) return caps = None tag = iq_obj.stanza.getTags('c') if tag: caps = tag[0].getAttr('node') caps_from_jid = self.check_jid(iq_obj.jid) if caps_from_jid: caps = caps_from_jid for iter_ in iters: self.set_icon(roster.model, iter_, self.renderer_num, caps, contact)
def get_avatar_pixbuf_from_cache(fjid, use_local=True): """ Check if jid has cached avatar and if that avatar is valid image (can be shown) Returns None if there is no image in vcard/ Returns 'ask' if cached vcard should not be used (user changed his vcard, so we have new sha) or if we don't have the vcard """ jid, nick = gajim.get_room_and_nick_from_fjid(fjid) if gajim.config.get('hide_avatar_of_transport') and\ gajim.jid_is_transport(jid): # don't show avatar for the transport itself return None if any(jid in gajim.contacts.get_gc_list(acc) for acc in \ gajim.contacts.get_accounts()): is_groupchat_contact = True else: is_groupchat_contact = False puny_jid = helpers.sanitize_filename(jid) if is_groupchat_contact: puny_nick = helpers.sanitize_filename(nick) path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick) local_avatar_basepath = os.path.join(gajim.AVATAR_PATH, puny_jid, puny_nick) + '_local' else: path = os.path.join(gajim.VCARD_PATH, puny_jid) local_avatar_basepath = os.path.join(gajim.AVATAR_PATH, puny_jid) + \ '_local' if use_local: for extension in ('.png', '.jpeg'): local_avatar_path = local_avatar_basepath + extension if os.path.isfile(local_avatar_path): avatar_file = open(local_avatar_path, 'rb') avatar_data = avatar_file.read() avatar_file.close() return get_pixbuf_from_data(avatar_data) if not os.path.isfile(path): return 'ask' vcard_dict = gajim.connections.values()[0].get_cached_vcard(fjid, is_groupchat_contact) if not vcard_dict: # This can happen if cached vcard is too old return 'ask' if 'PHOTO' not in vcard_dict: return None pixbuf = vcard.get_avatar_pixbuf_encoded_mime(vcard_dict['PHOTO'])[0] return pixbuf
def get_avatar_pixbuf_from_cache(fjid, use_local=True): """ Check if jid has cached avatar and if that avatar is valid image (can be shown) Returns None if there is no image in vcard/ Returns 'ask' if cached vcard should not be used (user changed his vcard, so we have new sha) or if we don't have the vcard """ jid, nick = gajim.get_room_and_nick_from_fjid(fjid) if gajim.config.get('hide_avatar_of_transport') and\ gajim.jid_is_transport(jid): # don't show avatar for the transport itself return None if any(jid in gajim.contacts.get_gc_list(acc) for acc in \ gajim.contacts.get_accounts()): is_groupchat_contact = True else: is_groupchat_contact = False puny_jid = helpers.sanitize_filename(jid) if is_groupchat_contact: puny_nick = helpers.sanitize_filename(nick) path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick) local_avatar_basepath = os.path.join(gajim.AVATAR_PATH, puny_jid, puny_nick) + '_local' else: path = os.path.join(gajim.VCARD_PATH, puny_jid) local_avatar_basepath = os.path.join(gajim.AVATAR_PATH, puny_jid) + \ '_local' if use_local: for extension in ('.png', '.jpeg'): local_avatar_path = local_avatar_basepath + extension if os.path.isfile(local_avatar_path): avatar_file = open(local_avatar_path, 'rb') avatar_data = avatar_file.read() avatar_file.close() return get_pixbuf_from_data(avatar_data) if not os.path.isfile(path): return 'ask' vcard_dict = list(gajim.connections.values())[0].get_cached_vcard( fjid, is_groupchat_contact) if not vcard_dict: # This can happen if cached vcard is too old return 'ask' if 'PHOTO' not in vcard_dict: return None pixbuf = vcard.get_avatar_pixbuf_encoded_mime(vcard_dict['PHOTO'])[0] return pixbuf
def on_event_added(self, event): """ Adds "Nickname Time" to the Messaging menu. """ print "----", event.type_ # Basic variables account = event.account jid = event.jid when = time.time() contact = "" # Check if the event is valid and modify the variables if event.type_ == "chat" or \ event.type_ == "printed_chat" or \ event.type_ == "normal" or \ event.type_ == "printed_normal" or \ event.type_ == "file-request" or \ event.type_ == "jingle-incoming": contact = gajim.contacts.get_contact_from_full_jid(account, jid) if contact: contact = contact.get_shown_name() else: contact = jid elif event.type_ == "pm" or event.type_ == "printed_pm": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) \ + "/" + gajim.get_room_and_nick_from_fjid(jid)[1] elif event.type_ == "printed_marked_gc_msg": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) else: print "ignored" return print account, jid, when, contact # Add a new indicator if necessary key = (account, jid) if not key in self.events: indicator = indicate.Indicator() indicator.set_property("name", contact) indicator.set_property_time("time", when) indicator.set_property_bool("draw-attention", True) indicator.connect("user-display", self.on_indicator_activate) indicator.show() indicator.key = key self.events[key] = (indicator, []) # Prepare the event and save it event.time = when self.events[key][1].append(event)
def presence_received(self, iq_obj): roster = gajim.interface.roster contact = gajim.contacts.get_contact_from_full_jid(iq_obj.conn.name, iq_obj.jid) if contact is None: room_jid, nick = gajim.get_room_and_nick_from_fjid(iq_obj.fjid) contact = gajim.contacts.get_gc_contact(iq_obj.conn.name, room_jid, nick) if contact: self.gc_presence_received(iq_obj, contact) return if not contact: return if not self.config['show_in_roster']: return contact = gajim.contacts.get_contact_with_highest_priority( iq_obj.conn.name, iq_obj.jid) if iq_obj.resource == 'local': # zeroconf return iters = roster._get_contact_iter(iq_obj.jid, iq_obj.conn.name, contact, roster.model) iter_ = iters[0] if contact.show == 'error': self.set_icon(roster.model, iter_, self.renderer_num, None, contact) return if contact.get_full_jid() != iq_obj.fjid: # higest contact changed if roster.model[iter_][self.renderer_num] is not None: caps = contact.client_caps._node if caps: self.set_icon(roster.model, iter_, self.renderer_num, caps, contact) return caps = None tag = iq_obj.stanza.getTags('c') if tag: caps = tag[0].getAttr('node') caps_from_jid = self.check_jid(iq_obj.jid) if caps_from_jid: caps = caps_from_jid for iter_ in iters: self.set_icon(roster.model, iter_, self.renderer_num, caps, contact)
def user_nickname(items, name, jid): has_child = False retract = False nick = None for item in items.getTags('item'): child = item.getTag('nick') if child is not None: has_child = True nick = child.getData() break if items.getTag('retract') is not None: retract = True if jid == gajim.get_jid_from_account(name): if has_child: gajim.nicks[name] = nick if retract: gajim.nicks[name] = gajim.config.get_per('accounts', name, 'name') (user, resource) = gajim.get_room_and_nick_from_fjid(jid) if has_child: if nick is not None: for contact in gajim.contacts.get_contacts(name, user): contact.contact_name = nick gajim.interface.roster.draw_contact(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_ui() win = ctrl.parent_win win.redraw_tab(ctrl) win.show_title() elif retract: contact.contact_name = ''
def execute(self, request): account = self.connection.name # Forward messages events = gajim.events.get_events(account, types=['chat', 'normal', 'printed_chat']) j, resource = gajim.get_room_and_nick_from_fjid(self.jid) for jid in events: for event in events[jid]: ev_typ = event.type_ if ev_typ == 'printed_chat': ev_typ = 'chat' gajim.nec.push_outgoing_event(MessageOutgoingEvent(None, account=account, jid=j, message=event.message, type_=ev_typ, subject=event.subject, resource=resource, forward_from=jid, delayed=event.time_)) # Inform other client of completion response, cmd = self.buildResponse(request, status = 'completed') cmd.addChild('note', {}, _('All unread messages have been forwarded.')) self.connection.connection.send(response) return False # finish the session
def __init__(self, plugin, ctx, fpr=None, parent=None): fjid = ctx.peer gtk.Dialog.__init__(self, title=_('OTR settings for %s') % fjid, parent=parent, flags=gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.ctx = ctx self.fjid = fjid self.jid = gajim.get_room_and_nick_from_fjid(self.fjid)[0] self.account = ctx.user.accountname self.fpr = fpr self.plugin = plugin if self.fpr is None: key = self.ctx.getCurrentKey() if key is not None: self.fpr = key.cfingerprint() self.GTK_BUILDER_FILE_PATH = \ self.plugin.local_file_path('contact_otr_window.ui') self.xml = gtk.Builder() self.xml.set_translation_domain('gajim_plugins') self.xml.add_from_file(self.GTK_BUILDER_FILE_PATH) self.notebook = self.gw('otr_settings_notebook') self.child.pack_start(self.notebook) self.connect('response', self.on_response) self.gw('otr_default_checkbutton').connect('toggled', self._otr_default_checkbutton_toggled) # always set the label containing our fingerprint self.gw('our_fp_label').set_markup(our_fp_text % ctx.user.getPrivkey()) if self.fpr is None: # make the fingerprint widgets insensitive # when not encrypted for widget in self.gw('otr_fp_vbox').get_children(): widget.set_sensitive(False) # show that the fingerprint is unknown self.gw('their_fp_label').set_markup(their_fp_text % { 'jid': self.fjid, 'fp': _('unknown')}) self.gw('verified_combobox').set_active(-1) else: # make the fingerprint widgets sensitive when encrypted for widget in self.gw('otr_fp_vbox').get_children(): widget.set_sensitive(True) # show their fingerprint fp = potr.human_hash(self.fpr) self.gw('their_fp_label').set_markup(their_fp_text % { 'jid': self.fjid, 'fp': fp}) # set the trust combobox if ctx.getCurrentTrust(): self.gw('verified_combobox').set_active(1) else: self.gw('verified_combobox').set_active(0) otr_flags = self.plugin.get_flags(self.account, self.jid, fallback=False) if otr_flags is not None: self.gw('otr_default_checkbutton').set_active(0) for w in self.gw('otr_settings_vbox').get_children(): w.set_sensitive(True) else: # per-user settings not available, # using default settings otr_flags = self.plugin.get_flags(self.account) self.gw('otr_default_checkbutton').set_active(1) for w in self.gw('otr_settings_vbox').get_children(): w.set_sensitive(False) self.gw('otr_policy_allow_v2_checkbutton').set_active( otr_flags['ALLOW_V2']) self.gw('otr_policy_require_checkbutton').set_active( otr_flags['REQUIRE_ENCRYPTION']) self.gw('otr_policy_send_tag_checkbutton').set_active( otr_flags['SEND_TAG']) self.gw('otr_policy_start_on_tag_checkbutton').set_active( otr_flags['WHITESPACE_START_AKE']) self.child.show_all()
def fill_jabber_page(self): self.xml.get_object("nickname_label").set_markup( '<b><span size="x-large">' + self.contact.get_shown_name() + "</span></b>" ) self.xml.get_object("jid_label").set_text(self.contact.jid) subscription_label = self.xml.get_object("subscription_label") ask_label = self.xml.get_object("ask_label") if self.gc_contact: self.xml.get_object("subscription_title_label").set_markup(Q_("?Role in Group Chat:<b>Role:</b>")) uf_role = helpers.get_uf_role(self.gc_contact.role) subscription_label.set_text(uf_role) self.xml.get_object("ask_title_label").set_markup(_("<b>Affiliation:</b>")) uf_affiliation = helpers.get_uf_affiliation(self.gc_contact.affiliation) ask_label.set_text(uf_affiliation) else: uf_sub = helpers.get_uf_sub(self.contact.sub) subscription_label.set_text(uf_sub) eb = self.xml.get_object("subscription_label_eventbox") if self.contact.sub == "from": tt_text = _( "This contact is interested in your presence information, but you are not interested in his/her presence" ) elif self.contact.sub == "to": tt_text = _( "You are interested in the contact's presence information, but he/she is not interested in yours" ) elif self.contact.sub == "both": tt_text = _("You and the contact are interested in each other's presence information") else: # None tt_text = _( "You are not interested in the contact's presence, and neither he/she is interested in yours" ) eb.set_tooltip_text(tt_text) uf_ask = helpers.get_uf_ask(self.contact.ask) ask_label.set_text(uf_ask) eb = self.xml.get_object("ask_label_eventbox") if self.contact.ask == "subscribe": tt_text = _("You are waiting contact's answer about your subscription request") else: tt_text = _("There is no pending subscription request.") eb.set_tooltip_text(tt_text) resources = "%s (%s)" % (self.contact.resource, str(self.contact.priority)) uf_resources = self.contact.resource + _(" resource with priority ") + str(self.contact.priority) if not self.contact.status: self.contact.status = "" # Request list time status only if contact is offline if self.contact.show == "offline": if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) gajim.connections[self.account].request_last_status_time(j, r, self.contact.jid) else: gajim.connections[self.account].request_last_status_time(self.contact.jid, "") # do not wait for os_info if contact is not connected or has error # additional check for observer is needed, as show is offline for him if self.contact.show in ("offline", "error") and not self.contact.is_observer(): self.os_info_arrived = True else: # Request os info if contact is connected if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) GLib.idle_add(gajim.connections[self.account].request_os_info, j, r, self.contact.jid) else: GLib.idle_add(gajim.connections[self.account].request_os_info, self.contact.jid, self.contact.resource) # do not wait for entity_time if contact is not connected or has error # additional check for observer is needed, as show is offline for him if self.contact.show in ("offline", "error") and not self.contact.is_observer(): self.entity_time_arrived = True else: # Request entity time if contact is connected if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) GLib.idle_add(gajim.connections[self.account].request_entity_time, j, r, self.contact.jid) else: GLib.idle_add( gajim.connections[self.account].request_entity_time, self.contact.jid, self.contact.resource ) self.os_info = {0: {"resource": self.real_resource, "client": "", "os": ""}} self.time_info = {0: {"resource": self.real_resource, "time": ""}} i = 1 contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid) if contact_list: for c in contact_list: if c.resource != self.contact.resource: resources += "\n%s (%s)" % (c.resource, str(c.priority)) uf_resources += "\n" + c.resource + _(" resource with priority ") + str(c.priority) if c.show not in ("offline", "error"): GLib.idle_add(gajim.connections[self.account].request_os_info, c.jid, c.resource) GLib.idle_add(gajim.connections[self.account].request_entity_time, c.jid, c.resource) self.os_info[i] = {"resource": c.resource, "client": "", "os": ""} self.time_info[i] = {"resource": c.resource, "time": ""} i += 1 self.xml.get_object("resource_prio_label").set_text(resources) resource_prio_label_eventbox = self.xml.get_object("resource_prio_label_eventbox") resource_prio_label_eventbox.set_tooltip_text(uf_resources) self.fill_status_label() if self.gc_contact: # If we know the real jid, remove the resource from vcard request gajim.connections[self.account].request_vcard(self.real_jid_for_vcard, self.gc_contact.get_full_jid()) else: gajim.connections[self.account].request_vcard(self.contact.jid)
def __init__(self, event_type, jid, account, msg_type = '', file_props = None): self.account = account self.jid = jid self.msg_type = msg_type self.file_props = file_props xml = gtk.glade.XML(GTKGUI_GLADE, 'popup_notification_window', APP) self.window = xml.get_widget('popup_notification_window') close_button = xml.get_widget('close_button') event_type_label = xml.get_widget('event_type_label') event_description_label = xml.get_widget('event_description_label') eventbox = xml.get_widget('eventbox') event_type_label.set_markup('<b>' + event_type + '</b>') if self.jid in gajim.contacts[account]: txt = gajim.contacts[account][self.jid][0].name else: txt = self.jid # set colors [ http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html ] self.window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) if event_type == _('Contact Signed In'): limegreen = gtk.gdk.color_parse('limegreen') close_button.modify_bg(gtk.STATE_NORMAL, limegreen) eventbox.modify_bg(gtk.STATE_NORMAL, limegreen) event_description_label.set_text(txt) elif event_type == _('Contact Signed Out'): red = gtk.gdk.color_parse('red') close_button.modify_bg(gtk.STATE_NORMAL, red) eventbox.modify_bg(gtk.STATE_NORMAL, red) event_description_label.set_text(txt) elif event_type in (_('New Message'), _('New Single Message'), _('New Private Message')): dodgerblue = gtk.gdk.color_parse('dodgerblue') close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue) eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue) if event_type == _('New Private Message'): room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid) txt = _('From %s in room %s') % (nick, room_name) else: txt = _('From %s') % txt event_description_label.set_text(txt) elif event_type == _('File Transfer Request'): bg_color = gtk.gdk.color_parse('khaki') close_button.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) txt = _('From %s') % txt event_description_label.set_text(txt) elif event_type == _('File Transfer Error'): bg_color = gtk.gdk.color_parse('firebrick') close_button.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) event_description_label.set_text(txt) elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): bg_color = gtk.gdk.color_parse('yellowgreen') close_button.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) if file_props is not None: if file_props['type'] == 'r': # get the name of the sender, as it is in the roster sender = unicode(file_props['sender']).split('/')[0] name = gajim.get_first_contact_instance_from_jid( account, sender).name txt = _('From %s') % name else: receiver = file_props['receiver'] if hasattr(receiver, 'jid'): receiver = receiver.jid receiver = receiver.split('/')[0] # get the name of the contact, as it is in the roster name = gajim.get_first_contact_instance_from_jid( account, receiver).name txt = _('To %s') % name else: txt = '' event_description_label.set_text(txt) # position the window to bottom-right of screen window_width, self.window_height = self.window.get_size() gajim.interface.roster.popups_notification_height += self.window_height self.window.move(gtk.gdk.screen_width() - window_width, gtk.gdk.screen_height() - gajim.interface.roster.popups_notification_height) xml.signal_autoconnect(self) self.window.show_all() gobject.timeout_add(5000, self.on_timeout)
def fill_jabber_page(self): self.xml.get_object('nickname_label').set_markup( '<b><span size="x-large">' + self.contact.get_shown_name() + '</span></b>') self.xml.get_object('jid_label').set_text(self.contact.jid) subscription_label = self.xml.get_object('subscription_label') ask_label = self.xml.get_object('ask_label') if self.gc_contact: self.xml.get_object('subscription_title_label').set_markup(Q_("?Role in Group Chat:<b>Role:</b>")) uf_role = helpers.get_uf_role(self.gc_contact.role) subscription_label.set_text(uf_role) self.xml.get_object('ask_title_label').set_markup(_("<b>Affiliation:</b>")) uf_affiliation = helpers.get_uf_affiliation(self.gc_contact.affiliation) ask_label.set_text(uf_affiliation) else: uf_sub = helpers.get_uf_sub(self.contact.sub) subscription_label.set_text(uf_sub) eb = self.xml.get_object('subscription_label_eventbox') if self.contact.sub == 'from': tt_text = _("This contact is interested in your presence information, but you are not interested in his/her presence") elif self.contact.sub == 'to': tt_text = _("You are interested in the contact's presence information, but he/she is not interested in yours") elif self.contact.sub == 'both': tt_text = _("You and the contact are interested in each other's presence information") else: # None tt_text = _("You are not interested in the contact's presence, and neither he/she is interested in yours") eb.set_tooltip_text(tt_text) uf_ask = helpers.get_uf_ask(self.contact.ask) ask_label.set_text(uf_ask) eb = self.xml.get_object('ask_label_eventbox') if self.contact.ask == 'subscribe': tt_text = _("You are waiting contact's answer about your subscription request") else: tt_text = _("There is no pending subscription request.") eb.set_tooltip_text(tt_text) resources = '%s (%s)' % (self.contact.resource, unicode( self.contact.priority)) uf_resources = self.contact.resource + _(' resource with priority ')\ + unicode(self.contact.priority) if not self.contact.status: self.contact.status = '' # Request list time status only if contact is offline if self.contact.show == 'offline': if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) gajim.connections[self.account].request_last_status_time(j, r, self.contact.jid) else: gajim.connections[self.account].request_last_status_time( self.contact.jid, '') # do not wait for os_info if contact is not connected or has error # additional check for observer is needed, as show is offline for him if self.contact.show in ('offline', 'error')\ and not self.contact.is_observer(): self.os_info_arrived = True else: # Request os info if contact is connected if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) gobject.idle_add(gajim.connections[self.account].request_os_info, j, r, self.contact.jid) else: gobject.idle_add(gajim.connections[self.account].request_os_info, self.contact.jid, self.contact.resource) # do not wait for entity_time if contact is not connected or has error # additional check for observer is needed, as show is offline for him if self.contact.show in ('offline', 'error')\ and not self.contact.is_observer(): self.entity_time_arrived = True else: # Request entity time if contact is connected if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) gobject.idle_add(gajim.connections[self.account].\ request_entity_time, j, r, self.contact.jid) else: gobject.idle_add(gajim.connections[self.account].\ request_entity_time, self.contact.jid, self.contact.resource) self.os_info = {0: {'resource': self.real_resource, 'client': '', 'os': ''}} self.time_info = {0: {'resource': self.real_resource, 'time': ''}} i = 1 contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid) if contact_list: for c in contact_list: if c.resource != self.contact.resource: resources += '\n%s (%s)' % (c.resource, unicode(c.priority)) uf_resources += '\n' + c.resource + \ _(' resource with priority ') + unicode(c.priority) if c.show not in ('offline', 'error'): gobject.idle_add( gajim.connections[self.account].request_os_info, c.jid, c.resource) gobject.idle_add(gajim.connections[self.account].\ request_entity_time, c.jid, c.resource) self.os_info[i] = {'resource': c.resource, 'client': '', 'os': ''} self.time_info[i] = {'resource': c.resource, 'time': ''} i += 1 self.xml.get_object('resource_prio_label').set_text(resources) resource_prio_label_eventbox = self.xml.get_object( 'resource_prio_label_eventbox') resource_prio_label_eventbox.set_tooltip_text(uf_resources) self.fill_status_label() if self.gc_contact: # If we know the real jid, remove the resource from vcard request gajim.connections[self.account].request_vcard(self.real_jid_for_vcard, self.gc_contact.get_full_jid()) else: gajim.connections[self.account].request_vcard(self.contact.jid)
return if form.getField('terminate') and\ form.getField('terminate').getValue() in ('1', 'true'): self.acknowledge_termination() self.conn.delete_session(str(self.jid), self.thread_id) return # non-esession negotiation. this isn't very useful, but i'm keeping it # around to test my test suite. if form.getType() == 'form': if not self.control: jid, resource = gajim.get_room_and_nick_from_fjid(self.jid) account = self.conn.name contact = gajim.contacts.get_contact(account, self.jid, resource) if not contact: contact = gajim.contacts.create_contact( jid=jid, resource=resource, show=self.conn.get_status()) gajim.interface.new_chat(contact, account, resource=resource, session=self)
def _fill_completion_dict(self): """ Fill completion_dict for key auto completion. Then load history for current jid (by calling another function) Key will be either jid or full_completion_name (contact name or long description like "pm-contact from groupchat...."). {key : (jid, account, nick_name, full_completion_name} This is a generator and does pseudo-threading via idle_add(). """ liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry) # Add all jids in logs.db: db_jids = gajim.logger.get_jids_in_db() completion_dict = dict.fromkeys(db_jids) self.accounts_seen_online = list(gajim.contacts.get_accounts()) # Enhance contacts of online accounts with contact. Needed for mapping below for account in self.accounts_seen_online: completion_dict.update( helpers.get_contact_dict_for_account(account)) muc_active_img = gtkgui_helpers.load_icon('muc_active') contact_img = gajim.interface.jabber_state_images['16']['online'] muc_active_pix = muc_active_img.get_pixbuf() contact_pix = contact_img.get_pixbuf() keys = list(completion_dict.keys()) # Move the actual jid at first so we load history faster actual_jid = self.jid_entry.get_text() if actual_jid in keys: keys.remove(actual_jid) keys.insert(0, actual_jid) if '' in keys: keys.remove('') if None in keys: keys.remove(None) # Map jid to info tuple # Warning : This for is time critical with big DB for key in keys: completed = key completed2 = None contact = completion_dict[completed] if contact: info_name = contact.get_shown_name() info_completion = info_name info_jid = contact.jid else: # Corrensponding account is offline, we know nothing info_name = completed.split('@')[0] info_completion = completed info_jid = completed info_acc = self._get_account_for_jid(info_jid) if gajim.logger.jid_is_room_jid(completed) or\ gajim.logger.jid_is_from_pm(completed): pix = muc_active_pix if gajim.logger.jid_is_from_pm(completed): # It's PM. Make it easier to find room, nick = gajim.get_room_and_nick_from_fjid(completed) info_completion = '%s from %s' % (nick, room) completed = info_completion info_completion2 = '%s/%s' % (room, nick) completed2 = info_completion2 info_name = nick else: pix = contact_pix if len(completed) > 70: completed = completed[:70] + '[\u2026]' liststore.append((pix, completed)) self.completion_dict[key] = (info_jid, info_acc, info_name, info_completion) self.completion_dict[completed] = (info_jid, info_acc, info_name, info_completion) if completed2: if len(completed2) > 70: completed2 = completed2[:70] + '[\u2026]' liststore.append((pix, completed2)) self.completion_dict[completed2] = (info_jid, info_acc, info_name, info_completion2) if key == actual_jid: self._load_history(info_jid, info_acc) yield True keys.sort() yield False
def user_tune(items, name, jid): has_child = False retract = False artist = None title = None source = None track = None length = None for item in items.getTags('item'): child = item.getTag('tune') if child is not None: has_child = True for ch in child.getChildren(): if ch.getName() == 'artist': artist = ch.getData() elif ch.getName() == 'title': title = ch.getData() elif ch.getName() == 'source': source = ch.getData() elif ch.getName() == 'track': track = ch.getData() elif ch.getName() == 'length': length = ch.getData() if items.getTag('retract') is not None: retract = True if jid == gajim.get_jid_from_account(name): acc = gajim.connections[name] if has_child: if 'artist' in acc.tune: del acc.tune['artist'] if 'title' in acc.tune: del acc.tune['title'] if 'source' in acc.tune: del acc.tune['source'] if 'track' in acc.tune: del acc.tune['track'] if 'length' in acc.tune: del acc.tune['length'] if artist is not None: acc.tune['artist'] = artist if title is not None: acc.tune['title'] = title if source is not None: acc.tune['source'] = source if track is not None: acc.tune['track'] = track if length is not None: acc.tune['length'] = length elif retract: if 'artist' in acc.tune: del acc.tune['artist'] if 'title' in acc.tune: del acc.tune['title'] if 'source' in acc.tune: del acc.tune['source'] if 'track' in acc.tune: del acc.tune['track'] if 'length' in acc.tune: del acc.tune['length'] (user, resource) = gajim.get_room_and_nick_from_fjid(jid) for contact in gajim.contacts.get_contacts(name, user): if has_child: if 'artist' in contact.tune: del contact.tune['artist'] if 'title' in contact.tune: del contact.tune['title'] if 'source' in contact.tune: del contact.tune['source'] if 'track' in contact.tune: del contact.tune['track'] if 'length' in contact.tune: del contact.tune['length'] if artist is not None: contact.tune['artist'] = artist if title is not None: contact.tune['title'] = title if source is not None: contact.tune['source'] = source if track is not None: contact.tune['track'] = track if length is not None: contact.tune['length'] = length elif retract: if 'artist' in contact.tune: del contact.tune['artist'] if 'title' in contact.tune: del contact.tune['title'] if 'source' in contact.tune: del contact.tune['source'] if 'track' in contact.tune: del contact.tune['track'] if 'length' in contact.tune: del contact.tune['length'] if jid == gajim.get_jid_from_account(name): gajim.interface.roster.draw_account(name) gajim.interface.roster.draw_tune(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_tune()
def handle_negotiation(self, form): if form.getField('accept') and not form['accept'] in ('1', 'true'): self.cancelled_negotiation() return # encrypted session states. these are described in stanza_session.py try: if form.getType() == 'form' and 'security' in form.asDict(): security_options = [x[1] for x in form.getField('security').\ getOptions()] if security_options == ['none']: self.respond_archiving(form) else: # bob responds # we don't support 3-message negotiation as the responder if 'dhkeys' in form.asDict(): self.fail_bad_negotiation('3 message negotiation not ' 'supported when responding', ('dhkeys',)) return negotiated, not_acceptable, ask_user = \ self.verify_options_bob(form) if ask_user: def accept_nondefault_options(is_checked): self.dialog.destroy() negotiated.update(ask_user) self.respond_e2e_bob(form, negotiated, not_acceptable) def reject_nondefault_options(): self.dialog.destroy() for key in ask_user.keys(): not_acceptable.append(key) self.respond_e2e_bob(form, negotiated, not_acceptable) self.dialog = dialogs.YesNoDialog(_('Confirm these ' 'session options'), _('The remote client wants to negotiate a session ' 'with these features:\n\n%s\n\nAre these options ' 'acceptable?''') % ( negotiation.describe_features(ask_user)), on_response_yes=accept_nondefault_options, on_response_no=reject_nondefault_options, transient_for=self.control.parent_win.window) else: self.respond_e2e_bob(form, negotiated, not_acceptable) return elif self.status == 'requested-archiving' and form.getType() == \ 'submit': try: self.archiving_accepted(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return # alice accepts elif self.status == 'requested-e2e' and form.getType() == 'submit': negotiated, not_acceptable, ask_user = self.verify_options_alice( form) if ask_user: def accept_nondefault_options(is_checked): if dialog: dialog.destroy() if is_checked: allow_no_log_for = gajim.config.get_per( 'accounts', self.conn.name, 'allow_no_log_for').split() jid = str(self.jid) if jid not in allow_no_log_for: allow_no_log_for.append(jid) gajim.config.set_per('accounts', self.conn.name, 'allow_no_log_for', ' '.join(allow_no_log_for)) negotiated.update(ask_user) try: self.accept_e2e_alice(form, negotiated) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) def reject_nondefault_options(): self.reject_negotiation() dialog.destroy() allow_no_log_for = gajim.config.get_per('accounts', self.conn.name, 'allow_no_log_for').split() if str(self.jid) in allow_no_log_for: dialog = None accept_nondefault_options(False) else: dialog = dialogs.YesNoDialog(_('Confirm these session ' 'options'), _('The remote client selected these options:\n\n%s' '\n\nContinue with the session?') % ( negotiation.describe_features(ask_user)), _('Always accept for this contact'), on_response_yes = accept_nondefault_options, on_response_no = reject_nondefault_options, transient_for=self.control.parent_win.window) else: try: self.accept_e2e_alice(form, negotiated) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return elif self.status == 'responded-archiving' and form.getType() == \ 'result': try: self.we_accept_archiving(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return elif self.status == 'responded-e2e' and form.getType() == 'result': try: self.accept_e2e_bob(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return elif self.status == 'identified-alice' and form.getType() == 'result': try: self.final_steps_alice(form) except exceptions.NegotiationError as details: self.fail_bad_negotiation(details) return except exceptions.Cancelled: # user cancelled the negotiation self.reject_negotiation() return if form.getField('terminate') and\ form.getField('terminate').getValue() in ('1', 'true'): self.acknowledge_termination() self.conn.delete_session(str(self.jid), self.thread_id) return # non-esession negotiation. this isn't very useful, but i'm keeping it # around to test my test suite. if form.getType() == 'form': if not self.control: jid, resource = gajim.get_room_and_nick_from_fjid(str(self.jid)) account = self.conn.name contact = gajim.contacts.get_contact(account, str(self.jid), resource) if not contact: contact = gajim.contacts.create_contact(jid=jid, account=account, resource=resource, show=self.conn.get_status()) gajim.interface.new_chat(contact, account, resource=resource, session=self) negotiation.FeatureNegotiationWindow(account, str(self.jid), self, form)
return if form.getField('terminate') and\ form.getField('terminate').getValue() in ('1', 'true'): self.acknowledge_termination() self.conn.delete_session(str(self.jid), self.thread_id) return # non-esession negotiation. this isn't very useful, but i'm keeping it # around to test my test suite. if form.getType() == 'form': if not self.control: jid, resource = gajim.get_room_and_nick_from_fjid(self.jid) account = self.conn.name contact = gajim.contacts.get_contact(account, self.jid, resource) if not contact: contact = gajim.contacts.create_contact(jid=jid, resource=resource, show=self.conn.get_status()) gajim.interface.new_chat(contact, account, resource=resource, session=self) negotiation.FeatureNegotiationWindow(account, self.jid, self, form) # vim: se ts=3:
def getPolicy(self, key): jid = gajim.get_room_and_nick_from_fjid(self.peer)[0] ret = self.user.plugin.get_flags(self.user.accountname, jid)[key] log.warning('getPolicy(key=%s) = %s', key, ret) return ret
def add_new_line(self, contact_name, tim, kind, show, message): '''add a new line in textbuffer''' if not message: # None or '' return buf = self.history_buffer end_iter = buf.get_end_iter() if gajim.config.get('print_time') == 'always': before_str = gajim.config.get('before_time') after_str = gajim.config.get('after_time') format = before_str + '%X' + after_str + ' ' tim = time.strftime(format, time.localtime(float(tim))) buf.insert(end_iter, tim) # add time elif gajim.config.get('print_time') == 'sometimes': every_foo_seconds = 60 * gajim.config.get( 'print_ichat_every_foo_minutes') seconds_passed = tim - self.last_time_printout if seconds_passed > every_foo_seconds: self.last_time_printout = tim tim = time.strftime('%X ', time.localtime(float(tim))) buf.insert_with_tags_by_name(end_iter, tim + '\n', 'time_sometimes') tag_name = '' tag_msg = '' show = self.get_string_show_from_constant_int(show) if kind == constants.KIND_GC_MSG: tag_name = 'incoming' elif kind in (constants.KIND_SINGLE_MSG_RECV, constants.KIND_CHAT_MSG_RECV): try: # is he in our roster? if yes use the name contact_name = gajim.contacts[self.account][self.jid][0].name except: room_jid, nick = gajim.get_room_and_nick_from_fjid(self.jid) # do we have him as gc_contact? if nick and gajim.gc_contacts[self.account].has_key(room_jid) and\ gajim.gc_contacts[self.account][room_jid].has_key(nick): # so yes, it's pm! contact_name = nick else: contact_name = self.jid.split('@')[0] tag_name = 'incoming' elif kind in (constants.KIND_SINGLE_MSG_SENT, constants.KIND_CHAT_MSG_SENT): contact_name = gajim.nicks[self.account] tag_name = 'outgoing' elif kind == constants.KIND_GCSTATUS: # message here (if not None) is status message if message: message = _('%(nick)s is now %(status)s: %(status_msg)s') %\ {'nick': contact_name, 'status': helpers.get_uf_show(show), 'status_msg': message } else: message = _('%(nick)s is now %(status)s') % {'nick': contact_name, 'status': helpers.get_uf_show(show) } tag_msg = 'status' else: # 'status' # message here (if not None) is status message if message: message = _('Status is now: %(status)s: %(status_msg)s') % \ {'status': helpers.get_uf_show(show), 'status_msg': message} else: message = _('Status is now: %(status)s') % { 'status': helpers.get_uf_show(show) } tag_msg = 'status' # do not do this if gcstats, avoid dupping contact_name # eg. nkour: nkour is now Offline if contact_name and kind != constants.KIND_GCSTATUS: # add stuff before and after contact name before_str = gajim.config.get('before_nickname') after_str = gajim.config.get('after_nickname') format = before_str + contact_name + after_str + ' ' buf.insert_with_tags_by_name(end_iter, format, tag_name) message = message + '\n' if tag_msg: self.history_textview.print_real_text(message, [tag_msg]) else: self.history_textview.print_real_text(message)
def __init__(self, plugin, ctx, fpr=None, parent=None): fjid = ctx.peer gtk.Dialog.__init__(self, title=_('OTR settings for %s') % fjid, parent=parent, flags=gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.ctx = ctx self.fjid = fjid self.jid = gajim.get_room_and_nick_from_fjid(self.fjid)[0] self.account = ctx.user.accountname self.fpr = fpr self.plugin = plugin if self.fpr is None: key = self.ctx.getCurrentKey() if key is not None: self.fpr = key.cfingerprint() self.GTK_BUILDER_FILE_PATH = \ self.plugin.local_file_path('contact_otr_window.ui') self.xml = gtk.Builder() self.xml.set_translation_domain('gajim_plugins') self.xml.add_from_file(self.GTK_BUILDER_FILE_PATH) self.notebook = self.gw('otr_settings_notebook') self.child.pack_start(self.notebook) self.connect('response', self.on_response) self.gw('otr_default_checkbutton').connect( 'toggled', self._otr_default_checkbutton_toggled) # always set the label containing our fingerprint self.gw('our_fp_label').set_markup(our_fp_text % ctx.user.getPrivkey()) if self.fpr is None: # make the fingerprint widgets insensitive # when not encrypted for widget in self.gw('otr_fp_vbox').get_children(): widget.set_sensitive(False) # show that the fingerprint is unknown self.gw('their_fp_label').set_markup(their_fp_text % { 'jid': self.fjid, 'fp': _('unknown') }) self.gw('verified_combobox').set_active(-1) else: # make the fingerprint widgets sensitive when encrypted for widget in self.gw('otr_fp_vbox').get_children(): widget.set_sensitive(True) # show their fingerprint fp = potr.human_hash(self.fpr) self.gw('their_fp_label').set_markup(their_fp_text % { 'jid': self.fjid, 'fp': fp }) # set the trust combobox if ctx.getCurrentTrust(): self.gw('verified_combobox').set_active(1) else: self.gw('verified_combobox').set_active(0) otr_flags = self.plugin.get_flags(self.account, self.jid, fallback=False) if otr_flags is not None: self.gw('otr_default_checkbutton').set_active(0) for w in self.gw('otr_settings_vbox').get_children(): w.set_sensitive(True) else: # per-user settings not available, # using default settings otr_flags = self.plugin.get_flags(self.account) self.gw('otr_default_checkbutton').set_active(1) for w in self.gw('otr_settings_vbox').get_children(): w.set_sensitive(False) self.gw('otr_policy_allow_v2_checkbutton').set_active( otr_flags['ALLOW_V2']) self.gw('otr_policy_require_checkbutton').set_active( otr_flags['REQUIRE_ENCRYPTION']) self.gw('otr_policy_send_tag_checkbutton').set_active( otr_flags['SEND_TAG']) self.gw('otr_policy_start_on_tag_checkbutton').set_active( otr_flags['WHITESPACE_START_AKE']) self.child.show_all()
def get_jid_from_fjid(fjid): return gajim.get_room_and_nick_from_fjid(str(fjid))[0]
def fill_jabber_page(self): self.xml.get_object('nickname_label').set_markup( '<b><span size="x-large">' + self.contact.get_shown_name() + '</span></b>') self.xml.get_object('jid_label').set_text(self.contact.jid) subscription_label = self.xml.get_object('subscription_label') ask_label = self.xml.get_object('ask_label') if self.gc_contact: self.xml.get_object('subscription_title_label').set_markup( Q_("?Role in Group Chat:<b>Role:</b>")) uf_role = helpers.get_uf_role(self.gc_contact.role) subscription_label.set_text(uf_role) self.xml.get_object('ask_title_label').set_markup( _("<b>Affiliation:</b>")) uf_affiliation = helpers.get_uf_affiliation( self.gc_contact.affiliation) ask_label.set_text(uf_affiliation) else: uf_sub = helpers.get_uf_sub(self.contact.sub) subscription_label.set_text(uf_sub) eb = self.xml.get_object('subscription_label_eventbox') if self.contact.sub == 'from': tt_text = _( "This contact is interested in your presence information, but you are not interested in their presence" ) elif self.contact.sub == 'to': tt_text = _( "You are interested in the contact's presence information, but it is not mutual" ) elif self.contact.sub == 'both': tt_text = _( "The contact and you want to exchange presence information" ) else: # None tt_text = _( "You and the contact have a mutual disinterest in each-others presence information" ) eb.set_tooltip_text(tt_text) uf_ask = helpers.get_uf_ask(self.contact.ask) ask_label.set_text(uf_ask) eb = self.xml.get_object('ask_label_eventbox') if self.contact.ask == 'subscribe': tt_text = _( "You are waiting contact's answer about your subscription request" ) else: tt_text = _("There is no pending subscription request.") eb.set_tooltip_text(tt_text) resources = '%s (%s)' % (self.contact.resource, str(self.contact.priority)) uf_resources = self.contact.resource + _(' resource with priority ')\ + str(self.contact.priority) if not self.contact.status: self.contact.status = '' # Request list time status only if contact is offline if self.contact.show == 'offline': if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) gajim.connections[self.account].request_last_status_time( j, r, self.contact.jid) else: gajim.connections[self.account].request_last_status_time( self.contact.jid, '') # do not wait for os_info if contact is not connected or has error # additional check for observer is needed, as show is offline for him if self.contact.show in ('offline', 'error')\ and not self.contact.is_observer(): self.os_info_arrived = True else: # Request os info if contact is connected if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) GLib.idle_add(gajim.connections[self.account].request_os_info, j, r, self.contact.jid) else: GLib.idle_add(gajim.connections[self.account].request_os_info, self.contact.jid, self.contact.resource) # do not wait for entity_time if contact is not connected or has error # additional check for observer is needed, as show is offline for him if self.contact.show in ('offline', 'error')\ and not self.contact.is_observer(): self.entity_time_arrived = True else: # Request entity time if contact is connected if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) GLib.idle_add(gajim.connections[self.account].\ request_entity_time, j, r, self.contact.jid) else: GLib.idle_add(gajim.connections[self.account].\ request_entity_time, self.contact.jid, self.contact.resource) self.os_info = { 0: { 'resource': self.real_resource, 'client': '', 'os': '' } } self.time_info = {0: {'resource': self.real_resource, 'time': ''}} i = 1 contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid) if contact_list: for c in contact_list: if c.resource != self.contact.resource: resources += '\n%s (%s)' % (c.resource, str(c.priority)) uf_resources += '\n' + c.resource + \ _(' resource with priority ') + str(c.priority) if c.show not in ('offline', 'error'): GLib.idle_add(gajim.connections[self.account].\ request_os_info, c.jid, c.resource) GLib.idle_add(gajim.connections[self.account].\ request_entity_time, c.jid, c.resource) self.os_info[i] = { 'resource': c.resource, 'client': '', 'os': '' } self.time_info[i] = {'resource': c.resource, 'time': ''} i += 1 self.xml.get_object('resource_prio_label').set_text(resources) resource_prio_label_eventbox = self.xml.get_object( 'resource_prio_label_eventbox') resource_prio_label_eventbox.set_tooltip_text(uf_resources) self.fill_status_label() if self.gc_contact: # If we know the real jid, remove the resource from vcard request gajim.connections[self.account].request_vcard( self.real_jid_for_vcard, self.gc_contact.get_full_jid()) else: gajim.connections[self.account].request_vcard(self.contact.jid)
def user_activity(items, name, jid): has_child = False retract = False activity = None subactivity = None text = None for item in items.getTags('item'): child = item.getTag('activity') if child is not None: has_child = True for ch in child.getChildren(): if ch.getName() != 'text': activity = ch.getName() for chi in ch.getChildren(): subactivity = chi.getName() else: text = ch.getData() if items.getTag('retract') is not None: retract = True if jid == gajim.get_jid_from_account(name): acc = gajim.connections[name] if has_child: if 'activity' in acc.activity: del acc.activity['activity'] if 'subactivity' in acc.activity: del acc.activity['subactivity'] if 'text' in acc.activity: del acc.activity['text'] if activity is not None: acc.activity['activity'] = activity if subactivity is not None: acc.activity['subactivity'] = subactivity if text is not None: acc.activity['text'] = text elif retract: if 'activity' in acc.activity: del acc.activity['activity'] if 'subactivity' in acc.activity: del acc.activity['subactivity'] if 'text' in acc.activity: del acc.activity['text'] (user, resource) = gajim.get_room_and_nick_from_fjid(jid) for contact in gajim.contacts.get_contacts(name, user): if has_child: if 'activity' in contact.activity: del contact.activity['activity'] if 'subactivity' in contact.activity: del contact.activity['subactivity'] if 'text' in contact.activity: del contact.activity['text'] if activity is not None: contact.activity['activity'] = activity if subactivity is not None: contact.activity['subactivity'] = subactivity if text is not None: contact.activity['text'] = text elif retract: if 'activity' in contact.activity: del contact.activity['activity'] if 'subactivity' in contact.activity: del contact.activity['subactivity'] if 'text' in contact.activity: del contact.activity['text'] if jid == gajim.get_jid_from_account(name): gajim.interface.roster.draw_account(name) gajim.interface.roster.draw_activity(user, name) ctrl = gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_activity()
def _fill_completion_dict(self): """ Fill completion_dict for key auto completion. Then load history for current jid (by calling another function) Key will be either jid or full_completion_name (contact name or long description like "pm-contact from groupchat...."). {key : (jid, account, nick_name, full_completion_name} This is a generator and does pseudo-threading via idle_add(). """ liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry) # Add all jids in logs.db: db_jids = gajim.logger.get_jids_in_db() completion_dict = dict.fromkeys(db_jids) self.accounts_seen_online = list(gajim.contacts.get_accounts()) # Enhance contacts of online accounts with contact. Needed for mapping below for account in self.accounts_seen_online: completion_dict.update(helpers.get_contact_dict_for_account(account)) muc_active_img = gtkgui_helpers.load_icon('muc_active') contact_img = gajim.interface.jabber_state_images['16']['online'] muc_active_pix = muc_active_img.get_pixbuf() contact_pix = contact_img.get_pixbuf() keys = list(completion_dict.keys()) # Move the actual jid at first so we load history faster actual_jid = self.jid_entry.get_text() if actual_jid in keys: keys.remove(actual_jid) keys.insert(0, actual_jid) if '' in keys: keys.remove('') if None in keys: keys.remove(None) # Map jid to info tuple # Warning : This for is time critical with big DB for key in keys: completed = key completed2 = None contact = completion_dict[completed] if contact: info_name = contact.get_shown_name() info_completion = info_name info_jid = contact.jid else: # Corrensponding account is offline, we know nothing info_name = completed.split('@')[0] info_completion = completed info_jid = completed info_acc = self._get_account_for_jid(info_jid) if gajim.logger.jid_is_room_jid(completed) or\ gajim.logger.jid_is_from_pm(completed): pix = muc_active_pix if gajim.logger.jid_is_from_pm(completed): # It's PM. Make it easier to find room, nick = gajim.get_room_and_nick_from_fjid(completed) info_completion = '%s from %s' % (nick, room) completed = info_completion info_completion2 = '%s/%s' % (room, nick) completed2 = info_completion2 info_name = nick else: pix = contact_pix if len(completed) > 70: completed = completed[:70] + '[\u2026]' liststore.append((pix, completed)) self.completion_dict[key] = (info_jid, info_acc, info_name, info_completion) self.completion_dict[completed] = (info_jid, info_acc, info_name, info_completion) if completed2: if len(completed2) > 70: completed2 = completed2[:70] + '[\u2026]' liststore.append((pix, completed2)) self.completion_dict[completed2] = (info_jid, info_acc, info_name, info_completion2) if key == actual_jid: self._load_history(info_jid, info_acc) yield True keys.sort() yield False
def fill_jabber_page(self): tooltips = gtk.Tooltips() self.xml.get_widget('nickname_label').set_markup( '<b><span size="x-large">' + self.contact.get_shown_name() + '</span></b>') self.xml.get_widget('jid_label').set_text(self.contact.jid) subscription_label = self.xml.get_widget('subscription_label') ask_label = self.xml.get_widget('ask_label') if self.gc_contact: self.xml.get_widget('subscription_title_label').set_markup( _("<b>Role:</b>")) uf_role = helpers.get_uf_role(self.gc_contact.role) subscription_label.set_text(uf_role) self.xml.get_widget('ask_title_label').set_markup( _("<b>Affiliation:</b>")) uf_affiliation = helpers.get_uf_affiliation( self.gc_contact.affiliation) ask_label.set_text(uf_affiliation) else: uf_sub = helpers.get_uf_sub(self.contact.sub) subscription_label.set_text(uf_sub) eb = self.xml.get_widget('subscription_label_eventbox') if self.contact.sub == 'from': tt_text = _( "This contact is interested in your presence information, but you are not interested in his/her presence" ) elif self.contact.sub == 'to': tt_text = _( "You are interested in the contact's presence information, but he/she is not interested in yours" ) elif self.contact.sub == 'both': tt_text = _( "You and the contact are interested in each other's presence information" ) else: # None tt_text = _( "You are not interested in the contact's presence, and neither he/she is interested in yours" ) tooltips.set_tip(eb, tt_text) uf_ask = helpers.get_uf_ask(self.contact.ask) ask_label.set_text(uf_ask) eb = self.xml.get_widget('ask_label_eventbox') if self.contact.ask == 'subscribe': tt_text = _( "You are waiting contact's answer about your subscription request" ) else: tt_text = _("There is no pending subscription request.") tooltips.set_tip(eb, tt_text) resources = '%s (%s)' % (self.contact.resource, unicode(self.contact.priority)) uf_resources = self.contact.resource + _(' resource with priority ')\ + unicode(self.contact.priority) if not self.contact.status: self.contact.status = '' # Request list time status if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) gajim.connections[self.account].request_last_status_time( j, r, self.contact.jid) else: gajim.connections[self.account].request_last_status_time( self.contact.jid, self.contact.resource) # do not wait for os_info if contact is not connected or has error # additional check for observer is needed, as show is offline for him if self.contact.show in ('offline', 'error')\ and not self.contact.is_observer(): self.os_info_arrived = True else: # Request os info if contact is connected if self.gc_contact: j, r = gajim.get_room_and_nick_from_fjid(self.real_jid) gobject.idle_add( gajim.connections[self.account].request_os_info, j, r, self.contact.jid) else: gobject.idle_add( gajim.connections[self.account].request_os_info, self.contact.jid, self.contact.resource) self.os_info = { 0: { 'resource': self.contact.resource, 'client': '', 'os': '' } } i = 1 contact_list = gajim.contacts.get_contacts(self.account, self.contact.jid) if contact_list: for c in contact_list: if c.resource != self.contact.resource: resources += '\n%s (%s)' % (c.resource, unicode( c.priority)) uf_resources += '\n' + c.resource + \ _(' resource with priority ') + unicode(c.priority) if c.show not in ('offline', 'error'): gobject.idle_add( gajim.connections[self.account].request_os_info, c.jid, c.resource) gajim.connections[self.account].request_last_status_time( c.jid, c.resource) self.os_info[i] = { 'resource': c.resource, 'client': '', 'os': '' } i += 1 self.xml.get_widget('resource_prio_label').set_text(resources) resource_prio_label_eventbox = self.xml.get_widget( 'resource_prio_label_eventbox') tooltips.set_tip(resource_prio_label_eventbox, uf_resources) self.fill_status_label() if self.gc_contact: # If we know the real jid, remove the resource from vcard request if self.gc_contact.jid: jid = self.gc_contact.jid else: jid = self.real_jid gajim.connections[self.account].request_vcard( jid, self.gc_contact.get_full_jid()) else: gajim.connections[self.account].request_vcard(self.contact.jid)
def send_message(self, message): '''Send the given message to the active tab''' if not message: return jid = self.get_active_jid() contact = gajim.get_first_contact_instance_from_jid(self.account, jid) if contact is None: # contact was from pm in MUC, and left the room, or we left the room room, nick = gajim.get_room_and_nick_from_fjid(jid) dialogs.ErrorDialog(_('Sending private message failed'), #in second %s code replaces with nickname _('You are no longer in room "%s" or "%s" has left.') % \ (room, nick)).get_response() return conv_textview = self.conversation_textviews[jid] message_textview = self.message_textviews[jid] message_buffer = message_textview.get_buffer() if message != '' or message != '\n': self.save_sent_message(jid, message) if message == '/clear': conv_textview.clear() # clear conversation self.clear(message_textview) # clear message textview too return True elif message == '/compact': self.set_compact_view(not self.compact_view_current_state) self.clear(message_textview) return True keyID = '' encrypted = False if self.xmls[jid].get_widget('gpg_togglebutton').get_active(): keyID = self.contacts[jid].keyID encrypted = True chatstates_on = gajim.config.get( 'chat_state_notifications') != 'disabled' chatstate_to_send = None if chatstates_on and contact is not None: if contact.our_chatstate is None: # no info about peer # send active to discover chat state capabilities # this is here (and not in send_chatstate) # because we want it sent with REAL message # (not standlone) eg. one that has body chatstate_to_send = 'active' contact.our_chatstate = 'ask' # pseudo state # if peer supports jep85 and we are not 'ask', send 'active' # NOTE: first active and 'ask' is set in gajim.py elif contact.our_chatstate not in (False, 'ask'): #send active chatstate on every message (as JEP says) chatstate_to_send = 'active' contact.our_chatstate = 'active' # refresh timers # avoid sending composing in less than 5 seconds # if we just send a message gobject.source_remove(self.possible_paused_timeout_id[jid]) gobject.source_remove(self.possible_inactive_timeout_id[jid]) self.possible_paused_timeout_id[jid] =\ gobject.timeout_add(5000, self.check_for_possible_paused_chatstate, jid) self.possible_inactive_timeout_id[jid] =\ gobject.timeout_add(30000, self.check_for_possible_inactive_chatstate, jid) self.reset_kbd_mouse_timeout_vars() gajim.connections[self.account].send_message(jid, message, keyID, chatstate = chatstate_to_send) message_buffer.set_text('') # clear message buffer (and tv of course) self.print_conversation(message, jid, jid, encrypted = encrypted)