bool lmcMessaging::addUser(QString szUserId, QString szVersion, QString szAddress, QString szName, QString szStatus, QString szAvatar, QString szNote, QString szCaps) { for(int index = 0; index < userList.count(); index++) if(userList[index].id.compare(szUserId) == 0) return false; lmcTrace::write("Adding new user: "******", " + szVersion + ", " + szAddress); if(!userGroupMap.contains(szUserId) || !groupList.contains(Group(userGroupMap.value(szUserId)))) userGroupMap.insert(szUserId, GRP_DEFAULT_ID); int nAvatar = szAvatar.isNull() ? -1 : szAvatar.toInt(); userList.append(User(szUserId, szVersion, szAddress, szName, szStatus, userGroupMap[szUserId], nAvatar, szNote, QString::null, szCaps)); if(!szStatus.isNull()) { XmlMessage xmlMessage; xmlMessage.addHeader(XN_FROM, szUserId); xmlMessage.addData(XN_STATUS, szStatus); // send a status message to app layer, this is different from announce message emit messageReceived(MT_Status, &szUserId, &xmlMessage); int statusIndex = Helper::statusIndexFromCode(szStatus); if(statusType[statusIndex] == StatusTypeOffline) // offline status return false; // no need to send a new user message to app layer } emit messageReceived(MT_Announce, &szUserId, NULL); return true; }
void lmcWebNetwork::raiseError(ErrorType type) { XmlMessage xmlMessage; xmlMessage.addHeader(XN_TYPE, MessageTypeNames[MT_WebFailed]); xmlMessage.addData(XN_ERROR, ErrorTypeNames[type]); QString szMessage = xmlMessage.toString(); emit messageReceived(&szMessage); }
void lmcChatRoomWindow::sendMessage(void) { if(ui.txtMessage->document()->isEmpty()) return; if(bConnected) { QString szHtmlMessage(ui.txtMessage->toHtml()); encodeMessage(&szHtmlMessage); QTextDocument docMessage; docMessage.setHtml(szHtmlMessage); QString szMessage = docMessage.toPlainText(); QFont font = ui.txtMessage->font(); font.setPointSize(ui.txtMessage->fontPointSize()); MessageType type = groupMode ? MT_GroupMessage : MT_PublicMessage; XmlMessage xmlMessage; xmlMessage.addHeader(XN_TIME, QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch())); xmlMessage.addData(XN_FONT, font.toString()); xmlMessage.addData(XN_COLOR, messageColor.name()); xmlMessage.addData(XN_MESSAGE, szMessage); if(groupMode) { xmlMessage.addData(XN_THREAD, threadId); xmlMessage.addData(XN_GROUPMSGOP, GroupMsgOpNames[GMO_Message]); } appendMessageLog(type, &localId, &localName, &xmlMessage); if(groupMode) { QHash<QString, QString>::const_iterator index = peerIds.constBegin(); while (index != peerIds.constEnd()) { QString userId = index.value(); emit messageSent(type, &userId, &xmlMessage); index++; } } else emit messageSent(type, NULL, &xmlMessage); } else appendMessageLog(MT_Error, NULL, NULL, NULL); ui.txtMessage->clear(); ui.txtMessage->setFocus(); }