void CSametimeProto::UserListCreate() { debugLog(_T("CSametimeProto::UserListCreate() start")); mwServiceAware_unsetAttribute(service_aware, mwAttribute_SPEAKERS); mwServiceAware_unsetAttribute(service_aware, mwAttribute_MICROPHONE); mwServiceAware_unsetAttribute(service_aware, mwAttribute_VIDEO_CAMERA); mwServiceAware_setAttributeBoolean(service_aware, mwAttribute_AV_PREFS_SET, TRUE); mwServiceAware_setAttributeBoolean(service_aware, mwAttribute_FILE_TRANSFER, TRUE); aware_list = mwAwareList_new(service_aware, &mwAwareList_handler); // add all contacts DBVARIANT dbv; mwAwareIdBlock id_block; GList *gl = 0; for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) == 0 /*&& proto && !mir_strcmp( PROTO, proto)*/) { if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) { if (dbv.pszVal) { if (GetAwareIdFromContact(hContact, &id_block)) { // add user to aware list gl = g_list_prepend(0, &id_block); mwAwareList_addAware(aware_list, gl); free(id_block.user); g_list_free(gl); } } db_free(&dbv); } } } // add self - might be necessary for some servers if (!db_get_utf(0, m_szModuleName, "stid", &dbv)) { id_block.type = mwAware_USER; id_block.user = dbv.pszVal; id_block.community = 0; gl = g_list_prepend(0, &id_block); mwAwareList_addAware(aware_list, gl); g_list_free(gl); db_free(&dbv); } }
/* private functions used only by the meanwhile session object */ void MeanwhileSession::addContact(const Kopete::Contact *contact) { HERE; struct mwAwareIdBlock id = { mwAware_USER, strdup(static_cast<const MeanwhileContact *>(contact) ->meanwhileId().toAscii()), 0L }; GList *buddies = g_list_prepend(0L, &id); mwAwareList_addAware(awareList, buddies); g_list_free(buddies); free(id.user); }
void MeanwhileSession::addContacts(const QHash<QString, Kopete::Contact *> &contacts) { HERE; GList *buddies = 0; QHash<QString, Kopete::Contact *>::const_iterator it = contacts.constBegin(); /** Convert our QDict of kopete contact to a GList of meanwhile buddies */ for( ; it != contacts.constEnd(); ++it) { MeanwhileContact *contact = static_cast<MeanwhileContact *>(it.value()); struct mwAwareIdBlock *id = reinterpret_cast<struct mwAwareIdBlock *>(malloc(sizeof(*id))); if (!id) continue; id->user = qstrdup(contact->meanwhileId().toUtf8().constData()); id->community = 0; id->type = mwAware_USER; buddies = g_list_append(buddies, id); } mwAwareList_addAware(awareList, buddies); g_list_foreach(buddies, free_id_block, 0); g_list_free(buddies); }
MCONTACT CSametimeProto::AddContact(mwSametimeUser* user, bool temporary) { debugLog(_T("CSametimeProto::AddContact() start")); const char* id = mwSametimeUser_getUser(user); const char* name = mwSametimeUser_getShortName(user); const char* nick = mwSametimeUser_getAlias(user); //const char* nick = mwSametimeUser_getShortName(user); mwSametimeUserType type = mwSametimeUser_getType(user); MCONTACT hContact = FindContactByUserId(id); bool new_contact = false; if (!hContact) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!hContact) { debugLog(_T("AddContact(): Failed to create Sametime contact")); return NULL; ///TODO error handling } if (Proto_AddToContact(hContact, m_szModuleName) != 0) { CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); debugLog(_T("AddContact(): Failed to register Sametime contact")); return NULL; ///TODO error handling } new_contact = true; } else if (!temporary) { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } // add to miranda if (new_contact) db_set_utf(hContact, m_szModuleName, "stid", id); if (name && mir_strlen(name)) db_set_utf(hContact, m_szModuleName, "Name", name); if (nick && mir_strlen(nick)) { db_set_utf(hContact, m_szModuleName, "Nick", nick); } else if (name && mir_strlen(name)) { db_set_utf(hContact, m_szModuleName, "Nick", name); } else { db_set_utf(hContact, m_szModuleName, "Nick", id); } db_set_b(hContact, m_szModuleName, "type", (BYTE)type); if (new_contact) { //add to our awareness list mwAwareIdBlock id_block; if (GetAwareIdFromContact(hContact, &id_block)) { GList* gl = g_list_prepend(NULL, &id_block); mwAwareList_addAware(aware_list, gl); g_list_free(gl); free(id_block.user); } } if (temporary) { db_set_b(hContact, "CList", "NotOnList", 1); db_set_b(hContact, "CList", "Hidden", 1); } else { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } return hContact; }
void CSametimeProto::ImportContactsFromList(mwSametimeList* user_list, bool temporary) { debugLog(_T("CSametimeProto::ImportContactsFromList() start")); // add contacts mwSametimeGroup* stgroup; mwSametimeUser* stuser; GList *gl, *gtl, *ul, *utl; const char* group_name; const char* group_alias; mwSametimeGroupType group_type; bool group_open; gl = gtl = mwSametimeList_getGroups(user_list); for (; gl; gl = gl->next) { char buff[256]; stgroup = (mwSametimeGroup*)gl->data; group_name = mwSametimeGroup_getName(stgroup); group_alias = mwSametimeGroup_getAlias(stgroup); if (!group_alias) group_alias = group_name; group_type = mwSametimeGroup_getType(stgroup); group_open = (mwSametimeGroup_isOpen(stgroup) != 0); mir_snprintf(buff, "GN_%s", group_alias); db_set_utf(0, szProtoGroups, buff, group_name); mir_snprintf(buff, "GT_%s", group_alias); db_set_b(0, szProtoGroups, buff, (BYTE)group_type); mir_snprintf(buff, "GO_%s", group_alias); db_set_b(0, szProtoGroups, buff, (BYTE)(group_open ? 1 : 0)); // inverse mapping mir_snprintf(buff, "GA_%s", group_name); db_set_utf(0, szProtoGroups, buff, group_alias); AddGroup(group_alias, group_open); if (group_type == mwSametimeGroup_DYNAMIC) { mwAwareIdBlock id_block; id_block.type = mwAware_GROUP; id_block.user = (char*)group_name; id_block.community = 0; GList* gl = g_list_prepend(NULL, &id_block); mwAwareList_addAware(aware_list, gl); g_list_free(gl); } ul = utl = mwSametimeGroup_getUsers(stgroup); for (; ul; ul = ul->next) { stuser = (mwSametimeUser*)ul->data; MCONTACT hContact = AddContact(stuser, temporary); if (hContact && group_alias && mir_strcmp(group_alias, Translate("None")) != 0 && mir_strcmp(group_alias, "MetaContacts Hidden Group") != 0) { SetContactGroup(hContact, group_alias); // mark contact as belonging to dynamic group } } g_list_free(utl); } g_list_free(gtl); }