/** * name: toDB * class: CExImContactBase * desc: searches the database for a contact representing the one * identified by this class or creates a new one if it was not found * param: hMetaContact - a meta contact to add this contact to * return: handle of the contact if successful **/ HANDLE CExImContactBase::toDB() { // create new contact if none exists if (_hContact == INVALID_HANDLE_VALUE && _pszProto && _pszUIDKey && _dbvUID.type != DBVT_DELETED) { PROTOACCOUNT* pszAccount = 0; if (NULL == (pszAccount = ProtoGetAccount( _pszProto ))) { //account does not exist _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } if (!IsAccountEnabled(pszAccount)) { ; } // create new contact _hContact = DB::Contact::Add(); if (!_hContact) { _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } // Add the protocol to the new contact if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)_hContact, (LPARAM)_pszProto)) { DB::Contact::Delete(_hContact); _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } // write uid to protocol module if (db_set(_hContact, _pszProto, _pszUIDKey, &_dbvUID)) { DB::Contact::Delete(_hContact); _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } // write nick and display name if (_pszNick) db_set_utf(_hContact, _pszProto, SET_CONTACT_NICK, _pszNick); if (_pszDisp) db_set_utf(_hContact, MOD_CLIST, SET_CONTACT_MYHANDLE, _pszDisp); // add group if (_pszGroup) { ptrT ptszGroup( mir_utf8decodeT(_pszGroup)); db_set_ts(_hContact, MOD_CLIST, "Group", ptszGroup); if ( Clist_GroupExists(ptszGroup) == NULL) { HANDLE hGroup = Clist_CreateGroup(NULL, NULL); if (hGroup) { // renaming twice is stupid but the only way to avoid error dialog telling shit like // a group with that name does exist CallService(MS_CLIST_GROUPRENAME, (WPARAM)hGroup, (LPARAM)ptszGroup); } } } } return _hContact; }
void CSametimeProto::AddGroup(const char* name, bool expanded) { if (name && mir_strcmp(name, "MetaContacts Hidden Group") == 0) return; if (name && mir_strcmp(name, Translate("None")) == 0) return; ptrT ptszGroup(mir_utf8decodeT(name)); HANDLE hGroup = Clist_GroupExists(ptszGroup); if (hGroup == NULL) { hGroup = Clist_CreateGroup(NULL, ptszGroup); if (hGroup) { CallService(MS_CLUI_GROUPADDED, (WPARAM)hGroup, 0); CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)hGroup, expanded ? 1 : 0); } } }
void CSametimeProto::ExportContactsToList(mwSametimeList* user_list) { debugLog(_T("CSametimeProto::ExportContactsToList() start")); mwSametimeGroup* stgroup = 0; char* group_name; char* group_alias; mwSametimeGroupType group_type; bool group_open; mwSametimeUser* stuser; char* user_alias; char* user_shortName; mwSametimeUserType user_type; DBVARIANT dbv, dbv2; char buff[256]; mwAwareIdBlock id_block; mwIdBlock uid; GList* gl = 0; for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) { if (dbv.pszVal) { if (GetAwareIdFromContact(hContact, &id_block)) { if (!db_get_utf(hContact, "CList", "Group", &dbv2)) { group_alias = _strdup(dbv2.pszVal); db_free(&dbv2); } else group_alias = _strdup(Translate("None")); if (group_alias) { mir_snprintf(buff, "GT_%s", group_alias); group_type = (mwSametimeGroupType)db_get_b(0, szProtoGroups, buff, (BYTE)mwSametimeGroup_NORMAL); // apparently we don't want to upload contacts in dynamic groups - see gaim sametime plugin comments if (group_type == mwSametimeGroup_DYNAMIC) { db_free(&dbv); free(id_block.user); free(group_alias); hContact = db_find_next(hContact, m_szModuleName); continue; } mir_snprintf(buff, "GN_%s", group_alias); if (!db_get_utf(0, szProtoGroups, buff, &dbv2)) { group_name = _strdup(dbv2.pszVal); db_free(&dbv2); } else group_name = _strdup(group_alias); //group_open = (db_get_b(0, szProtoGroups, buff, 0) == 1); ptrT ptszGroup(mir_utf8decodeT(group_alias)); HANDLE hGroup = Clist_GroupExists(ptszGroup); if (hGroup) { int expanded; CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, (LPARAM)&expanded); group_open = (expanded != 0); } else { mir_snprintf(buff, "GO_%s", group_alias); group_open = (db_get_b(0, szProtoGroups, buff, 0) == 1); } stgroup = 0; stgroup = mwSametimeList_findGroup(user_list, group_name); if (!stgroup) { if (group_name) stgroup = mwSametimeGroup_new(user_list, group_type, group_name); mwSametimeGroup_setAlias(stgroup, group_alias); mwSametimeGroup_setOpen(stgroup, group_open); } free(group_name); free(group_alias); if (!db_get_utf(hContact, m_szModuleName, "Name", &dbv2)) { user_shortName = _strdup(dbv2.pszVal); db_free(&dbv2); } else user_shortName = 0; if (!db_get_utf(hContact, "CList", "MyHandle", &dbv2)) { user_alias = _strdup(dbv2.pszVal); db_free(&dbv2); } else user_alias = 0; user_type = (mwSametimeUserType)db_get_b(hContact, m_szModuleName, "type", (BYTE)mwSametimeUser_NORMAL); uid.user = id_block.user; uid.community = id_block.community; stuser = mwSametimeUser_new(stgroup, user_type, &uid); if (user_shortName) { mwSametimeUser_setShortName(stuser, user_shortName); free(user_shortName); } if (user_alias) { mwSametimeUser_setAlias(stuser, user_alias); free(user_alias); } } free(id_block.user); } } db_free(&dbv); } } }