Exemple #1
0
    def _consume_message(self, res_obj, sock):
        assert (sock is not None)

        attr = res_obj.headers.get_field_value
        from_uri = attr("F")

        logger.info("Get message from: %s" % from_uri)

        msg = rm_markups(to_unicode_obj(res_obj.body))

        if from_uri != SERVICE_PROVIDER_URI:
            i_send_ack(res_obj, sock)
            contact = self.user.group_agent.get_contact_by_uri(from_uri)
            if not contact:
                """ This message send you before him delete you from his buddy list. """
                name = u"陌生人 (飞信号: %s) " % get_sid_from_uri(from_uri)
            else:
                name = contact.get_display_name()
        else:
            name = to_unicode_obj("系统信息")

        self.goto_or_create_tab_after_received_msg(from_uri)

        chat_history_model = self.chat_history[from_uri]
        self.chat_win.append_to_chat_history(chat_history_model, name, msg,
                                             OTHER_LOG_TPL)
Exemple #2
0
    def _consume_message(self, res_obj, sock):
        assert (sock is not None)

        attr = res_obj.headers.get_field_value
        from_uri = attr("F")

        logger.info("Get message from: %s" % from_uri)

        msg = rm_markups(to_unicode_obj(res_obj.body))

        if from_uri != SERVICE_PROVIDER_URI:
            i_send_ack(res_obj, sock)
            contact = self.user.group_agent.get_contact_by_uri(from_uri)
            if not contact:
                """ This message send you before him delete you from his buddy list. """
                name = u"陌生人 (飞信号: %s) " % get_sid_from_uri(from_uri)
            else:
                name = contact.get_display_name()
        else:
            name = to_unicode_obj("系统信息")

        self.goto_or_create_tab_after_received_msg(from_uri)

        chat_history_model = self.chat_history[from_uri]
        self.chat_win.append_to_chat_history(chat_history_model, name, msg, OTHER_LOG_TPL)
Exemple #3
0
    def create_tab(self, target_uri):
        self.create_chat_history_model_if_not_exists(target_uri)

        if target_uri == SERVICE_PROVIDER_URI:
            label = to_unicode_obj("系统消息")
        else:
            contact = self.user.group_agent.get_contact_by_uri(target_uri)
            assert contact != None
            if contact:
                label = contact.get_display_name()
            else:
                label = u"陌生人 URI: %s " % target_uri

        chat_input = QtGui.QTextEdit(self)
        new_idx = self.convTab.addTab(chat_input, QtCore.QString(label))
        """ Notice:
        It will emit `currentTabChanged()` after addTab called while convTab.count() = 1,
        and we have not set TabData yet at this time, I'm not sure this is a bug,
        do a litter hacking in current_tab_changed() to fix it.
        """
        tabbar = self.convTab.tabBar()
        tabbar.setTabData(new_idx, QtCore.QVariant(QtCore.QString(target_uri)))

        self.convTab.setCurrentIndex(new_idx)
        self.focus_on_current_chat_tab()

        self.contactNameLabel.setText(QtCore.QString(label))

        """ Clean up document model sat by last send or recevie action """
        now_model = self.chat_history_view.document()
        target_model = self.blah.contact_list_win.chat_history[target_uri]
        if now_model is not target_model:
            self.chat_history_view.setDocument(target_model)
Exemple #4
0
 def get_display_name(self):
     if self.nickname and self.nickname.strip():
         return u"%s (%s) " % (to_unicode_obj(self.nickname), self.sid)
     elif self.mobile_no and self.mobile_no.strip():
         return u"%s (%s) " % (self.mobile_no, self.sid)
     else:
         return u"%s" % self.sid
Exemple #5
0
 def get_display_name(self):
     if self.nickname and self.nickname.strip():
         return u"%s (%s) " % (to_unicode_obj(self.nickname), self.sid)
     elif self.mobile_no and self.mobile_no.strip():
         return u"%s (%s) " % (self.mobile_no, self.sid)
     else:
         return u"%s" % self.sid
Exemple #6
0
def _create_contact_from_buddy_xml_node(user, node):
    # Notice: a buddy could belongs to two groups
    attr = node.getAttribute

    contact = Contact(user = user)
    contact.uri = attr("u")
    contact.sid = get_sid_from_uri(contact.uri)
    contact.user_id = attr("i")
    contact.nickname = to_unicode_obj(attr("n"))
    contact.relation_status = int(attr("r"))

    buddy_list_id = attr("l")
    if buddy_list_id:
        gids = [gid for gid in buddy_list_id.split(";") if gid.strip() and int(gid) >= DEFAULT_GID]
        if len(gids) != 1:
            logger.error("!!! User (SID: %s) has multiple GID" % contact.sid)
            print "gids:", gids
        gid = int(gids[0])
    else:
        gid = DEFAULT_GID
    contact.set_gid(gid)

    contact.portrait_crc = 0

    return contact
Exemple #7
0
 def delete_buddy(self, uri):
     cat = self.user.group_agent.get_contact_by_uri(uri)
     SHOW_MSG = to_unicode_obj("%s (飞信号: %s)")
     show_msg = SHOW_MSG % (cat.nickname, cat.sid)
     sure_btn_clicked, data = DeleteBuddyDialog.get_data(parent = self, show_msg = show_msg)
     if sure_btn_clicked:
         i_delete_buddy(self.user, cat.uri, data["delete_both"], debug = True)
Exemple #8
0
 def delete_buddy(self, uri):
     cat = self.user.group_agent.get_contact_by_uri(uri)
     SHOW_MSG = to_unicode_obj("%s (飞信号: %s)")
     show_msg = SHOW_MSG % (cat.nickname, cat.sid)
     sure_btn_clicked, data = DeleteBuddyDialog.get_data(parent=self,
                                                         show_msg=show_msg)
     if sure_btn_clicked:
         i_delete_buddy(self.user, cat.uri, data["delete_both"], debug=True)
Exemple #9
0
    def __init__(self, parent=None, name=""):
        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)

        self.account_line_edit = self.AccountLineEdit
        self.name_line_edit = self.NameLineEdit
        self.msg_combo_box = self.MsgComboBox

        self.name_line_edit.setText(to_unicode_obj(name))
Exemple #10
0
def map_node_attr_to_obj(node, obj, filters = None):
    """ TODO: add ignore_list paramters """
    attrs = node.attributes.keys()
    for i in attrs:
        key = i
        val = node.getAttribute(key)
        if filters and key in filters:
            key, val = filters[key](key, val)
        if hasattr(obj, key.replace('-', '_')):
            setattr(obj, key.replace('-', '_'), to_unicode_obj(val))
Exemple #11
0
def map_node_attr_to_obj(node, obj, filters=None):
    """ TODO: add ignore_list paramters """
    attrs = node.attributes.keys()
    for i in attrs:
        key = i
        val = node.getAttribute(key)
        if filters and key in filters:
            key, val = filters[key](key, val)
        if hasattr(obj, key.replace('-', '_')):
            setattr(obj, key.replace('-', '_'), to_unicode_obj(val))
Exemple #12
0
def _parse_buddy_lists_node(contact_list_node):
    ga = GroupAgent()

    un_group = Group(gid = DEFAULT_GID, gname = to_unicode_obj("未分组"))
    ga.add_group(un_group)
    buddy_lists = contact_list_node.getElementsByTagName("buddy-lists")[0]
    for i in buddy_lists.childNodes:
        if i.nodeType == minidom.Node.TEXT_NODE:
            continue
        gid, gname = int(i.getAttribute("id")), i.getAttribute("name")
        group = Group(gid, gname)
        ga.add_group(group)

    stranger_group = Group(gid = STRANGER_GROUP_GID, gname = to_unicode_obj("陌生人"))
    ga.add_group(stranger_group)

    blacklist_group = Group(gid = BLACKLIST_GROUP_GID, gname = to_unicode_obj("黑名单"))
    ga.add_group(blacklist_group)

    return ga
Exemple #13
0
def i_parse_add_buddy_application(body_dom):
    app_node = body_dom.getElementsByTagName("application")[0]
    attr = app_node.getAttribute

    data = {
        "uri": attr("uri"),
        "who": to_unicode_obj(attr("desc")),
        "add_buddy_phrase_id": int(attr("addbuddy-phrase-id")),
        "user_id": attr("user-id")
    }
    #type = attr("type")
    return data
Exemple #14
0
def i_parse_add_buddy_application(body_dom):
    app_node = body_dom.getElementsByTagName("application")[0]
    attr = app_node.getAttribute

    data = {
        "uri" : attr("uri"),
        "who" : to_unicode_obj(attr("desc")),
        "add_buddy_phrase_id" : int(attr("addbuddy-phrase-id")),
        "user_id" : attr("user-id")
    }
    #type = attr("type")
    return data
Exemple #15
0
def qstr_to_unicode_obj(qstr):
    return to_unicode_obj(str(qstr.toUtf8()))
Exemple #16
0
def qstr_to_unicode_obj(qstr):
    return to_unicode_obj(str(qstr.toUtf8()))