From 0173277372e2962b8f5703a0ebad7892dda15e6c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 9 Mar 2014 21:50:49 +0000 Subject: end of the old MC API git-svn-id: http://svn.miranda-ng.org/main/trunk@8534 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/mc.cpp | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/mir_core/mc.cpp (limited to 'src/mir_core/mc.cpp') diff --git a/src/mir_core/mc.cpp b/src/mir_core/mc.cpp new file mode 100644 index 0000000000..4970b135d8 --- /dev/null +++ b/src/mir_core/mc.cpp @@ -0,0 +1,148 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +static HANDLE hEventDefaultChanged; + +void InitMetaContacts() +{ + hEventDefaultChanged = CreateHookableEvent(ME_MC_DEFAULTTCHANGED); +} + +DBCachedContact* CheckMeta(MCONTACT hMeta) +{ + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hMeta); + return (cc == NULL || cc->nSubs == -1) ? NULL : cc; +} + +int Meta_GetContactNumber(DBCachedContact *cc, MCONTACT hContact) +{ + for (int i = 0; i < cc->nSubs; i++) + if (cc->pSubs[i] == hContact) + return i; + + return -1; +} + +MCONTACT Meta_GetContactHandle(DBCachedContact *cc, int contact_number) +{ + if (contact_number >= cc->nSubs || contact_number < 0) + return 0; + + return cc->pSubs[contact_number]; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// metacontacts + +MIR_CORE_DLL(int) db_mc_isMeta(MCONTACT hContact) +{ + if (currDb == NULL) return false; + + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); + return (cc == NULL) ? false : cc->nSubs != -1; +} + +MIR_CORE_DLL(int) db_mc_isSub(MCONTACT hContact) +{ + if (currDb == NULL) return false; + + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); + return (cc == NULL) ? false : cc->parentID != 0; +} + +//returns a handle to the default contact, or null on failure +MIR_CORE_DLL(MCONTACT) db_mc_getDefault(MCONTACT hMetaContact) +{ + DBCachedContact *cc = CheckMeta(hMetaContact); + if (cc == NULL) + return 0; + + return (cc->nDefault != -1) ? Meta_GetContactHandle(cc, cc->nDefault) : 0; +} + +//returns the default contact number, or -1 on failure +MIR_CORE_DLL(int) db_mc_getDefaultNum(MCONTACT hMetaContact) +{ + DBCachedContact *cc = CheckMeta(hMetaContact); + return (cc == NULL) ? -1 : cc->nDefault; +} + +//returns the number of subcontacts, or -1 on failure +MIR_CORE_DLL(int) db_mc_getSubCount(MCONTACT hMetaContact) +{ + DBCachedContact *cc = CheckMeta(hMetaContact); + return (cc == NULL) ? -1 : cc->nSubs; +} + +// returns parent hContact for a subcontact or INVALID_CONTACT_ID if it's not a sub +MIR_CORE_DLL(MCONTACT) db_mc_getMeta(MCONTACT hSubContact) +{ + if (currDb == NULL) return NULL; + + DBCachedContact *cc = currDb->m_cache->GetCachedContact(hSubContact); + return (cc == NULL) ? NULL : cc->parentID; +} + +// returns a subcontact with the given index +MIR_CORE_DLL(MCONTACT) db_mc_getSub(MCONTACT hMetaContact, int iNum) +{ + DBCachedContact *cc = CheckMeta(hMetaContact); + return (cc == NULL) ? 0 : Meta_GetContactHandle(cc, iNum); +} + +//sets the default contact, using the subcontact's handle +MIR_CORE_DLL(int) db_mc_setDefault(MCONTACT hMetaContact, MCONTACT hSub) +{ + DBCachedContact *cc = CheckMeta(hMetaContact); + if (cc == NULL) + return 1; + + int contact_number = Meta_GetContactNumber(cc, hSub); + if (contact_number == -1) + return 1; + + cc->nDefault = contact_number; + currDb->MetaSetDefault(cc); + + NotifyEventHooks(hEventDefaultChanged, hMetaContact, hSub); + return 0; +} + +//sets the default contact, using the subcontact's number +MIR_CORE_DLL(int) db_mc_setDefaultNum(MCONTACT hMetaContact, int iNum) +{ + DBCachedContact *cc = CheckMeta(hMetaContact); + if (cc == NULL) + return 1; + if (iNum >= cc->nSubs || iNum < 0) + return 1; + + cc->nDefault = iNum; + currDb->MetaSetDefault(cc); + + NotifyEventHooks(hEventDefaultChanged, hMetaContact, Meta_GetContactHandle(cc, iNum)); + return 0; +} -- cgit v1.2.3