void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid) { mir_cslockfull lck(m_csLists); JABBER_LIST_ITEM *LI = ListGetItemPtr(list, jid); if (LI == NULL) return; const TCHAR *p = _tcschr(jid, '@'); const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/'); if (q == NULL) return; pResourceStatus r( LI->findResource(q+1)); if (r == NULL) return; // Found last seen resource ID to be removed if (LI->m_pLastSeenResource == r) LI->m_pLastSeenResource = NULL; // update manually selected resource ID if (LI->resourceMode == RSMODE_MANUAL && LI->m_pManualResource == r) { LI->resourceMode = RSMODE_LASTSEEN; LI->m_pManualResource = NULL; } // Update MirVer due to possible resource changes UpdateMirVer(LI); LI->arResources.remove(r); r->Release(); lck.unlock(); MenuUpdateSrmmIcon(LI); }
INT_PTR __cdecl CJabberProto::OnMenuHandleResource(WPARAM hContact, LPARAM, LPARAM res) { if (!m_bJabberOnline || !hContact) return 0; ptrT tszJid(getTStringA(hContact, "jid")); if (tszJid == NULL) return 0; JABBER_LIST_ITEM *LI = ListGetItemPtr(LIST_ROSTER, tszJid); if (LI == NULL) return 0; if (res == MENUITEM_LASTSEEN) { LI->m_pManualResource = NULL; LI->resourceMode = RSMODE_LASTSEEN; } else if (res == MENUITEM_SERVER) { LI->m_pManualResource = NULL; LI->resourceMode = RSMODE_SERVER; } else if (res >= MENUITEM_RESOURCES) { LI->m_pManualResource = LI->arResources[res - MENUITEM_RESOURCES]; LI->resourceMode = RSMODE_MANUAL; } UpdateMirVer(LI); MenuUpdateSrmmIcon(LI); return 0; }
void CJabberProto::ListRemoveResource( JABBER_LIST list, const TCHAR* jid ) { EnterCriticalSection( &m_csLists ); int i = ListExist( list, jid ); JABBER_LIST_ITEM* LI = m_lstRoster[i-1]; if ( !i || LI == NULL ) { LeaveCriticalSection( &m_csLists ); return; } const TCHAR* p = _tcschr( jid, '@' ); const TCHAR* q = _tcschr(( p == NULL ) ? jid : p, '/' ); if ( q ) { const TCHAR* resource = q+1; if ( resource[0] ) { JABBER_RESOURCE_STATUS* r = LI->resource; int j; for ( j=0; j < LI->resourceCount; j++, r++ ) { if ( !_tcsicmp( r->resourceName, resource )) break; } if ( j < LI->resourceCount ) { // Found last seen resource ID to be removed if ( LI->lastSeenResource == j ) LI->lastSeenResource = -1; else if ( LI->lastSeenResource > j ) LI->lastSeenResource--; // update manually selected resource ID if (LI->resourceMode == RSMODE_MANUAL) { if ( LI->manualResource == j ) { LI->resourceMode = RSMODE_LASTSEEN; LI->manualResource = -1; } else if ( LI->manualResource > j ) LI->manualResource--; } // Update MirVer due to possible resource changes UpdateMirVer(LI); JabberListFreeResourceInternal( r ); if ( LI->resourceCount-- == 1 ) { mir_free( r ); LI->resource = NULL; } else { memmove( r, r+1, ( LI->resourceCount-j )*sizeof( JABBER_RESOURCE_STATUS )); LI->resource = ( JABBER_RESOURCE_STATUS* )mir_realloc( LI->resource, LI->resourceCount*sizeof( JABBER_RESOURCE_STATUS )); } } } } LeaveCriticalSection( &m_csLists ); MenuUpdateSrmmIcon(LI); }
int CJabberProto::ListAddResource( JABBER_LIST list, const TCHAR* jid, int status, const TCHAR* statusMessage, char priority, const TCHAR* nick ) { EnterCriticalSection( &m_csLists ); int i = ListExist( list, jid ); if ( !i ) { LeaveCriticalSection( &m_csLists ); return 0; } JABBER_LIST_ITEM* LI = m_lstRoster[i-1]; int bIsNewResource = false, j; const TCHAR* p = _tcschr( jid, '@' ); const TCHAR* q = _tcschr(( p == NULL ) ? jid : p, '/' ); if ( q ) { const TCHAR* resource = q+1; if ( resource[0] ) { JABBER_RESOURCE_STATUS* r = LI->resource; for ( j=0; j < LI->resourceCount; j++, r++ ) { if ( !_tcscmp( r->resourceName, resource )) { // Already exist, update status and statusMessage r->status = status; replaceStr( r->statusMessage, statusMessage ); r->priority = priority; break; } } if ( j >= LI->resourceCount ) { // Not already exist, add new resource LI->resource = ( JABBER_RESOURCE_STATUS * ) mir_realloc( LI->resource, ( LI->resourceCount+1 )*sizeof( JABBER_RESOURCE_STATUS )); bIsNewResource = true; r = LI->resource + LI->resourceCount++; memset( r, 0, sizeof( JABBER_RESOURCE_STATUS )); r->status = status; r->affiliation = AFFILIATION_NONE; r->role = ROLE_NONE; r->resourceName = mir_tstrdup( resource ); r->nick = mir_tstrdup( nick ); if ( statusMessage ) r->statusMessage = mir_tstrdup( statusMessage ); r->priority = priority; } } } // No resource, update the main statusMessage else { LI->itemResource.status = status; replaceStr( LI->itemResource.statusMessage, statusMessage ); } LeaveCriticalSection( &m_csLists ); MenuUpdateSrmmIcon(LI); return bIsNewResource; }
int CJabberProto::OnProcessSrmmIconClick(WPARAM hContact, LPARAM lParam) { StatusIconClickData *sicd = (StatusIconClickData *)lParam; if (mir_strcmp(sicd->szModule, m_szModuleName)) return 0; if (!hContact) return 0; JABBER_LIST_ITEM *LI = ListGetItemPtr(LIST_ROSTER, ptrT(getTStringA(hContact, "jid"))); if (LI == NULL) return 0; HMENU hMenu = CreatePopupMenu(); TCHAR buf[256]; mir_sntprintf(buf, TranslateT("Last active (%s)"), LI->m_pLastSeenResource ? LI->m_pLastSeenResource->m_tszResourceName : TranslateT("No activity yet, use server's choice")); AppendMenu(hMenu, MF_STRING, MENUITEM_LASTSEEN, buf); AppendMenu(hMenu, MF_STRING, MENUITEM_SERVER, TranslateT("Highest priority (server's choice)")); AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); for (int i = 0; i < LI->arResources.getCount(); i++) AppendMenu(hMenu, MF_STRING, MENUITEM_RESOURCES + i, LI->arResources[i]->m_tszResourceName); if (LI->resourceMode == RSMODE_LASTSEEN) CheckMenuItem(hMenu, MENUITEM_LASTSEEN, MF_BYCOMMAND | MF_CHECKED); else if (LI->resourceMode == RSMODE_SERVER) CheckMenuItem(hMenu, MENUITEM_SERVER, MF_BYCOMMAND | MF_CHECKED); else if (LI->m_pManualResource) CheckMenuItem(hMenu, MENUITEM_RESOURCES + LI->arResources.indexOf(LI->m_pManualResource), MF_BYCOMMAND | MF_CHECKED); int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, sicd->clickLocation.x, sicd->clickLocation.y, 0, WindowList_Find(hDialogsList, hContact), NULL); if (res == MENUITEM_LASTSEEN) { LI->m_pManualResource = NULL; LI->resourceMode = RSMODE_LASTSEEN; } else if (res == MENUITEM_SERVER) { LI->m_pManualResource = NULL; LI->resourceMode = RSMODE_SERVER; } else if (res >= MENUITEM_RESOURCES) { LI->m_pManualResource = LI->arResources[res - MENUITEM_RESOURCES]; LI->resourceMode = RSMODE_MANUAL; } UpdateMirVer(LI); MenuUpdateSrmmIcon(LI); return 0; }
JABBER_LIST_ITEM *CJabberProto::ListAdd( JABBER_LIST list, const TCHAR* jid ) { JABBER_LIST_ITEM* item; BOOL bUseResource=FALSE; EnterCriticalSection( &m_csLists ); if (( item = ListGetItemPtr( list, jid )) != NULL ) { LeaveCriticalSection( &m_csLists ); return item; } TCHAR *s = mir_tstrdup( jid ); TCHAR *q = NULL; // strip resource name if any //fyr if ( !((list== LIST_ROSTER ) && ListExist(LIST_CHATROOM, jid))) { // but only if it is not chat room contact if ( list != LIST_VCARD_TEMP ) { TCHAR *p; if (( p = _tcschr( s, '@' )) != NULL ) if (( q = _tcschr( p, '/' )) != NULL ) *q = '\0'; } } else { bUseResource=TRUE; } if ( !bUseResource && list== LIST_ROSTER ) { //if it is a chat room keep resource and made it resource sensitive if ( ChatRoomHContactFromJID( s ) ) { if (q != NULL) *q='/'; bUseResource=TRUE; } } item = ( JABBER_LIST_ITEM* )mir_alloc( sizeof( JABBER_LIST_ITEM )); ZeroMemory( item, sizeof( JABBER_LIST_ITEM )); item->list = list; item->jid = s; item->itemResource.status = ID_STATUS_OFFLINE; item->resource = NULL; item->resourceMode = RSMODE_LASTSEEN; item->lastSeenResource = -1; item->manualResource = -1; item->bUseResource = bUseResource; m_lstRoster.insert( item ); LeaveCriticalSection( &m_csLists ); MenuUpdateSrmmIcon(item); return item; }
bool CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status, const TCHAR *statusMessage, char priority, const TCHAR *nick) { mir_cslockfull lck(m_csLists); JABBER_LIST_ITEM *LI = ListGetItemPtr(list, jid); if (LI == NULL) return false; bool bIsNewResource = false; const TCHAR *p = _tcschr(jid, '@'); const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/'); if (q) { const TCHAR *resource = q+1; if (*resource == 0) return 0; JABBER_RESOURCE_STATUS *r = LI->findResource(resource); if (r != NULL) { // Already exists, update status and statusMessage r->m_iStatus = status; r->m_tszStatusMessage = mir_tstrdup(statusMessage); r->m_iPriority = priority; } else { // Does not exist, add new resource bIsNewResource = true; r = new JABBER_RESOURCE_STATUS(); r->m_iStatus = status; r->m_affiliation = AFFILIATION_NONE; r->m_role = ROLE_NONE; r->m_tszResourceName = mir_tstrdup(resource); r->m_tszNick = mir_tstrdup(nick); if (statusMessage) r->m_tszStatusMessage = mir_tstrdup(statusMessage); r->m_iPriority = priority; LI->arResources.insert(r); } } // No resource, update the main statusMessage else { JABBER_RESOURCE_STATUS *r = LI->getTemp(); r->m_iStatus = status; r->m_tszStatusMessage = mir_tstrdup(statusMessage); } lck.unlock(); MenuUpdateSrmmIcon(LI); return bIsNewResource; }
JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid) { bool bUseResource = false; mir_cslockfull lck(m_csLists); JABBER_LIST_ITEM *item = ListGetItemPtr(list, jid); if (item != NULL) return item; TCHAR *s = mir_tstrdup(jid); TCHAR *q = NULL; // strip resource name if any //fyr if (!((list== LIST_ROSTER) && ListGetItemPtr(LIST_CHATROOM, jid))) { // but only if it is not chat room contact if (list != LIST_VCARD_TEMP) { TCHAR *p; if ((p = _tcschr(s, '@')) != NULL) if ((q = _tcschr(p, '/')) != NULL) *q = '\0'; } } else bUseResource = true; if (!bUseResource && list == LIST_ROSTER) { //if it is a chat room keep resource and made it resource sensitive if (ChatRoomHContactFromJID(s)) { if (q != NULL) *q='/'; bUseResource = true; } } item = new JABBER_LIST_ITEM(); item->list = list; item->jid = s; item->resourceMode = RSMODE_LASTSEEN; item->bUseResource = bUseResource; m_lstRoster.insert(item); lck.unlock(); MenuUpdateSrmmIcon(item); return item; }