diff options
Diffstat (limited to 'src/mir_core')
-rw-r--r-- | src/mir_core/db.cpp | 30 | ||||
-rw-r--r-- | src/mir_core/mc.cpp | 148 | ||||
-rw-r--r-- | src/mir_core/mir_core.def | 6 | ||||
-rw-r--r-- | src/mir_core/mir_core_10.vcxproj | 1 | ||||
-rw-r--r-- | src/mir_core/mir_core_10.vcxproj.filters | 3 | ||||
-rw-r--r-- | src/mir_core/mir_core_12.vcxproj | 1 | ||||
-rw-r--r-- | src/mir_core/mir_core_12.vcxproj.filters | 3 | ||||
-rw-r--r-- | src/mir_core/miranda.cpp | 2 | ||||
-rw-r--r-- | src/mir_core/miranda.h | 1 |
9 files changed, 166 insertions, 29 deletions
diff --git a/src/mir_core/db.cpp b/src/mir_core/db.cpp index 140af537c0..1479748bf2 100644 --- a/src/mir_core/db.cpp +++ b/src/mir_core/db.cpp @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
-static MIDatabase* currDb = NULL;
+MIDatabase *currDb = NULL;
/////////////////////////////////////////////////////////////////////////////////////////
// getting data
@@ -321,34 +321,6 @@ MIR_CORE_DLL(HANDLE) db_event_prev(HANDLE hDbEvent) }
/////////////////////////////////////////////////////////////////////////////////////////
-// 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;
-}
-
-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;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////////////////
// misc functions
MIR_CORE_DLL(INT_PTR) db_free(DBVARIANT *dbv)
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;
+}
diff --git a/src/mir_core/mir_core.def b/src/mir_core/mir_core.def index 0d8eaf3e21..647a78b946 100644 --- a/src/mir_core/mir_core.def +++ b/src/mir_core/mir_core.def @@ -252,3 +252,9 @@ db_mc_isMeta @249 db_mc_isSub @250
db_mc_getMeta @251
db_get_contact @252
+db_mc_getDefault @253
+db_mc_getDefaultNum @254
+db_mc_getSubCount @255
+db_mc_getSub @256
+db_mc_setDefault @257
+db_mc_setDefaultNum @258
diff --git a/src/mir_core/mir_core_10.vcxproj b/src/mir_core/mir_core_10.vcxproj index f6f3f987db..2c3799288b 100644 --- a/src/mir_core/mir_core_10.vcxproj +++ b/src/mir_core/mir_core_10.vcxproj @@ -100,6 +100,7 @@ <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\commonheaders.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="logger.cpp" />
+ <ClCompile Include="mc.cpp" />
<ClCompile Include="mstring.cpp" />
<ClCompile Include="protos.cpp" />
<ClCompile Include="stdafx.cpp">
diff --git a/src/mir_core/mir_core_10.vcxproj.filters b/src/mir_core/mir_core_10.vcxproj.filters index b7a247b20b..1de8cfd829 100644 --- a/src/mir_core/mir_core_10.vcxproj.filters +++ b/src/mir_core/mir_core_10.vcxproj.filters @@ -106,6 +106,9 @@ <ClCompile Include="winver.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="mc.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="commonheaders.h">
diff --git a/src/mir_core/mir_core_12.vcxproj b/src/mir_core/mir_core_12.vcxproj index c9926e96ef..fa8058a1df 100644 --- a/src/mir_core/mir_core_12.vcxproj +++ b/src/mir_core/mir_core_12.vcxproj @@ -96,6 +96,7 @@ <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../commonheaders.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="logger.cpp" />
+ <ClCompile Include="mc.cpp" />
<ClCompile Include="mstring.cpp" />
<ClCompile Include="protos.cpp" />
<ClCompile Include="stdafx.cpp">
diff --git a/src/mir_core/mir_core_12.vcxproj.filters b/src/mir_core/mir_core_12.vcxproj.filters index 3311ae3578..cf84f183a5 100644 --- a/src/mir_core/mir_core_12.vcxproj.filters +++ b/src/mir_core/mir_core_12.vcxproj.filters @@ -103,6 +103,9 @@ <ClCompile Include="winver.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="mc.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="commonheaders.h">
diff --git a/src/mir_core/miranda.cpp b/src/mir_core/miranda.cpp index 639de6b0c1..8779dee996 100644 --- a/src/mir_core/miranda.cpp +++ b/src/mir_core/miranda.cpp @@ -35,6 +35,7 @@ void InitLogs(); void UninitLogs();
void InitWinver();
+void InitMetaContacts();
int hLangpack = 0;
HINSTANCE hInst = 0;
@@ -93,6 +94,7 @@ static void LoadCoreModule(void) InitLogs();
InitialiseModularEngine();
InitProtocols();
+ InitMetaContacts();
}
MIR_CORE_DLL(void) UnloadCoreModule(void)
diff --git a/src/mir_core/miranda.h b/src/mir_core/miranda.h index 122d9fe21d..dc3d055cc0 100644 --- a/src/mir_core/miranda.h +++ b/src/mir_core/miranda.h @@ -42,6 +42,7 @@ extern HINSTANCE hInst; extern HWND hAPCWindow;
extern HANDLE hStackMutex, hThreadQueueEmpty;
extern bool g_bDebugMode;
+extern MIDatabase *currDb;
/**** modules.cpp **********************************************************************/
|