diff options
author | George Hazan <george.hazan@gmail.com> | 2016-09-17 16:37:24 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-09-17 16:37:24 +0000 |
commit | e5d58fc3bbbce2773b7c6c3f8b7da6faa66b672e (patch) | |
tree | 6432409a59b53d8098ac38aa1d3072ae2e5f9e4b /src/mir_app | |
parent | 17e345e621254103a98bbc7e662a2829b7aa3ce6 (diff) |
chats: more functions, less structures
git-svn-id: http://svn.miranda-ng.org/main/trunk@17309 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/chat_manager.cpp | 11 | ||||
-rw-r--r-- | src/mir_app/src/chat_svc.cpp | 249 | ||||
-rw-r--r-- | src/mir_app/src/chat_tools.cpp | 9 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 8 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 8 |
5 files changed, 156 insertions, 129 deletions
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index 79659bd7ef..635478ce8f 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -123,11 +123,11 @@ static int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL re while (pTemp != NULL) {
// match
if ((!pszID && pTemp->iType != GCW_SERVER || !mir_wstrcmpi(pTemp->ptszID, pszID)) && !mir_strcmpi(pTemp->pszModule, pszModule)) {
- DWORD dw = pTemp->dwItemData;
+ void *pItemData = pTemp->pItemData;
if (chatApi.OnRemoveSession)
chatApi.OnRemoveSession(pTemp);
- DoEventHook(pTemp->ptszID, pTemp->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (DWORD)pTemp->dwItemData);
+ DoEventHook(pTemp->ptszID, pTemp->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)pTemp->pItemData);
if (pLast == NULL)
chatApi.wndList = pTemp->next;
@@ -142,7 +142,8 @@ static int SM_RemoveSession(const wchar_t *pszID, const char *pszModule, BOOL re SM_FreeSession(pTemp);
if (pszID)
- return (int)dw;
+ return (int)pItemData;
+
if (pLast)
pTemp = pLast->next;
else
@@ -546,8 +547,8 @@ static BOOL SM_RemoveAll(void) SESSION_INFO *pLast = chatApi.wndList->next;
if (chatApi.wndList->hWnd)
- SendMessage(chatApi.wndList->hWnd, GC_EVENT_CONTROL + WM_USER + 500, SESSION_TERMINATE, 0);
- DoEventHook(chatApi.wndList->ptszID, chatApi.wndList->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (DWORD)chatApi.wndList->dwItemData);
+ SendMessage(chatApi.wndList->hWnd, GC_CONTROL_MSG, SESSION_TERMINATE, 0);
+ DoEventHook(chatApi.wndList->ptszID, chatApi.wndList->pszModule, GC_SESSION_TERMINATE, NULL, NULL, (INT_PTR)chatApi.wndList->pItemData);
SM_FreeSession(chatApi.wndList);
chatApi.wndList = pLast;
diff --git a/src/mir_app/src/chat_svc.cpp b/src/mir_app/src/chat_svc.cpp index c5acd9abb6..2320292da5 100644 --- a/src/mir_app/src/chat_svc.cpp +++ b/src/mir_app/src/chat_svc.cpp @@ -137,7 +137,7 @@ EXTERN_C MIR_APP_DLL(int) Chat_GetInfo(GC_INFO *gci) if (si == NULL)
return 1;
- if (gci->Flags & GCF_DATA) gci->dwItemData = si->dwItemData;
+ if (gci->Flags & GCF_DATA) gci->pItemData = si->pItemData;
if (gci->Flags & GCF_HCONTACT) gci->hContact = si->hContact;
if (gci->Flags & GCF_TYPE) gci->iType = si->iType;
if (gci->Flags & GCF_COUNT) gci->iCount = si->nUsersInNicklist;
@@ -155,9 +155,6 @@ MIR_APP_DLL(int) Chat_Register(const GCREGISTER *gcr) if (gcr == NULL)
return GC_REGISTER_ERROR;
- if (gcr->cbSize != sizeof(GCREGISTER))
- return GC_REGISTER_WRONGVER;
-
mir_cslock lck(csChat);
MODULEINFO *mi = chatApi.MM_AddModule(gcr->pszModule);
if (mi == NULL)
@@ -195,9 +192,6 @@ EXTERN_C MIR_APP_DLL(int) Chat_NewSession(const GCSESSION *gcw) if (gcw == NULL)
return GC_NEWSESSION_ERROR;
- if (gcw->cbSize != sizeof(GCSESSION))
- return GC_NEWSESSION_WRONGVER;
-
mir_cslock lck(csChat);
MODULEINFO *mi = chatApi.MM_FindModule(gcw->pszModule);
if (mi == NULL)
@@ -223,7 +217,7 @@ EXTERN_C MIR_APP_DLL(int) Chat_NewSession(const GCSESSION *gcw) if ((si = chatApi.SM_AddSession(gcw->ptszID, gcw->pszModule)) == NULL)
return GC_NEWSESSION_ERROR;
- si->dwItemData = gcw->dwItemData;
+ si->pItemData = gcw->pItemData;
if (gcw->iType != GCW_SERVER)
si->wStatus = ID_STATUS_ONLINE;
si->iType = gcw->iType;
@@ -264,7 +258,7 @@ EXTERN_C MIR_APP_DLL(int) Chat_NewSession(const GCSESSION *gcw) }
/////////////////////////////////////////////////////////////////////////////////////////
-// handles chat event
+// chat control
struct ShowChatParam
{
@@ -294,109 +288,71 @@ static void SetInitDone(SESSION_INFO *si) p->hIcon = HICON(si->iStatusCount - (INT_PTR)p->hIcon - 1);
}
-static int DoControl(GCEVENT *gce, WPARAM wp)
+MIR_APP_DLL(int) Chat_Control(const char *szModule, const wchar_t *wszId, int iCommand)
{
SESSION_INFO *si;
- if (gce->pDest->iType == GC_EVENT_CONTROL) {
- switch (wp) {
- case WINDOW_HIDDEN:
- if (si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) {
- SetInitDone(si);
- chatApi.SetActiveSession(si->ptszID, si->pszModule);
- if (si->hWnd)
- CallFunctionAsync(stubShowRoom, new ShowChatParam(si, wp, FALSE));
- }
- return 0;
-
- case WINDOW_MINIMIZE:
- case WINDOW_MAXIMIZE:
- case WINDOW_VISIBLE:
- case SESSION_INITDONE:
- if (si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) {
- SetInitDone(si);
- if (wp != SESSION_INITDONE || db_get_b(NULL, CHAT_MODULE, "PopupOnJoin", 0) == 0)
- CallFunctionAsync(stubShowRoom, new ShowChatParam(si, wp, TRUE));
- return 0;
- }
- break;
-
- case SESSION_OFFLINE:
- chatApi.SM_SetOffline(gce->pDest->ptszID, gce->pDest->pszModule);
- // fall through
-
- case SESSION_ONLINE:
- chatApi.SM_SetStatus(gce->pDest->ptszID, gce->pDest->pszModule, wp == SESSION_ONLINE ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE);
- break;
-
- case WINDOW_CLEARLOG:
- if (si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) {
- chatApi.LM_RemoveAll(&si->pLog, &si->pLogEnd);
- if (chatApi.OnClearLog)
- chatApi.OnClearLog(si);
- si->iEventCount = 0;
- si->LastTime = 0;
- }
- break;
+ mir_cslock lck(csChat);
+ switch (iCommand) {
+ case WINDOW_HIDDEN:
+ if (si = chatApi.SM_FindSession(wszId, szModule)) {
+ SetInitDone(si);
+ chatApi.SetActiveSession(si->ptszID, si->pszModule);
+ if (si->hWnd)
+ CallFunctionAsync(stubShowRoom, new ShowChatParam(si, iCommand, FALSE));
+ }
+ return 0;
- case SESSION_TERMINATE:
- return chatApi.SM_RemoveSession(gce->pDest->ptszID, gce->pDest->pszModule, (gce->dwFlags & GCEF_REMOVECONTACT) != 0);
+ case WINDOW_MINIMIZE:
+ case WINDOW_MAXIMIZE:
+ case WINDOW_VISIBLE:
+ case SESSION_INITDONE:
+ if (si = chatApi.SM_FindSession(wszId, szModule)) {
+ SetInitDone(si);
+ if (iCommand != SESSION_INITDONE || db_get_b(NULL, CHAT_MODULE, "PopupOnJoin", 0) == 0)
+ CallFunctionAsync(stubShowRoom, new ShowChatParam(si, iCommand, TRUE));
+ return 0;
}
- chatApi.SM_SendMessage(gce->pDest->ptszID, gce->pDest->pszModule, GC_EVENT_CONTROL + WM_USER + 500, wp, 0);
- }
+ break;
- else if (gce->pDest->iType == GC_EVENT_CHUID && gce->ptszText) {
- chatApi.SM_ChangeUID(gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszNick, gce->ptszText);
- }
+ case SESSION_OFFLINE:
+ chatApi.SM_SetOffline(wszId, szModule);
+ // fall through
- else if (gce->pDest->iType == GC_EVENT_CHANGESESSIONAME && gce->ptszText) {
- if (si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) {
- replaceStrW(si->ptszName, gce->ptszText);
- if (si->hWnd)
- SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0);
- if (chatApi.OnRenameSession)
- chatApi.OnRenameSession(si);
- }
- }
+ case SESSION_ONLINE:
+ chatApi.SM_SetStatus(wszId, szModule, iCommand == SESSION_ONLINE ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE);
+ break;
- else if (gce->pDest->iType == GC_EVENT_SETITEMDATA) {
- if (si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule))
- si->dwItemData = gce->dwItemData;
- }
+ case SESSION_TERMINATE:
+ return chatApi.SM_RemoveSession(wszId, szModule, false);
- else if (gce->pDest->iType == GC_EVENT_GETITEMDATA) {
- if (si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) {
- gce->dwItemData = si->dwItemData;
- return si->dwItemData;
+ case WINDOW_CLEARLOG:
+ if (si = chatApi.SM_FindSession(wszId, szModule)) {
+ chatApi.LM_RemoveAll(&si->pLog, &si->pLogEnd);
+ if (chatApi.OnClearLog)
+ chatApi.OnClearLog(si);
+ si->iEventCount = 0;
+ si->LastTime = 0;
}
- return 0;
- }
- else if (gce->pDest->iType == GC_EVENT_SETSBTEXT) {
- if (si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule)) {
- replaceStrW(si->ptszStatusbarText, gce->ptszText);
- if (si->ptszStatusbarText)
- db_set_ws(si->hContact, si->pszModule, "StatusBar", si->ptszStatusbarText);
- else
- db_set_s(si->hContact, si->pszModule, "StatusBar", "");
-
- if (chatApi.OnSetStatusBar)
- chatApi.OnSetStatusBar(si);
- }
- }
- else if (gce->pDest->iType == GC_EVENT_ACK) {
- chatApi.SM_SendMessage(gce->pDest->ptszID, gce->pDest->pszModule, GC_ACKMESSAGE, 0, 0);
- }
- else if (gce->pDest->iType == GC_EVENT_SENDMESSAGE && gce->ptszText) {
- chatApi.SM_SendUserMessage(gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszText);
- }
- else if (gce->pDest->iType == GC_EVENT_SETSTATUSEX) {
- chatApi.SM_SetStatusEx(gce->pDest->ptszID, gce->pDest->pszModule, gce->ptszText, gce->dwItemData);
+ break;
+
+ default:
+ return GC_EVENT_ERROR;
}
- else return 1;
+ chatApi.SM_SendMessage(wszId, szModule, GC_CONTROL_MSG, iCommand, 0);
return 0;
}
+MIR_APP_DLL(int) Chat_Terminate(const char *szModule, const wchar_t *wszId, bool bRemoveContact)
+{
+ mir_cslock lck(csChat);
+ return chatApi.SM_RemoveSession(wszId, szModule, bRemoveContact);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// handles chat event
+
static void AddUser(GCEVENT *gce)
{
SESSION_INFO *si = chatApi.SM_FindSession(gce->pDest->ptszID, gce->pDest->pszModule);
@@ -416,7 +372,7 @@ static void AddUser(GCEVENT *gce) chatApi.OnNewUser(si, ui);
}
-EXTERN_C MIR_APP_DLL(int) Chat_Event(int sessionEvent, GCEVENT *gce)
+EXTERN_C MIR_APP_DLL(int) Chat_Event(GCEVENT *gce)
{
BOOL bIsHighlighted = FALSE;
BOOL bRemoveFlag = FALSE;
@@ -428,9 +384,6 @@ EXTERN_C MIR_APP_DLL(int) Chat_Event(int sessionEvent, GCEVENT *gce) if (gcd == NULL)
return GC_EVENT_ERROR;
- if (gce->cbSize != sizeof(GCEVENT))
- return GC_EVENT_WRONGVER;
-
if (!IsEventSupported(gcd->iType))
return GC_EVENT_ERROR;
@@ -449,17 +402,6 @@ EXTERN_C MIR_APP_DLL(int) Chat_Event(int sessionEvent, GCEVENT *gce) }
return 0;
- case GC_EVENT_CHUID:
- case GC_EVENT_CHANGESESSIONAME:
- case GC_EVENT_SETITEMDATA:
- case GC_EVENT_GETITEMDATA:
- case GC_EVENT_CONTROL:
- case GC_EVENT_SETSBTEXT:
- case GC_EVENT_ACK:
- case GC_EVENT_SENDMESSAGE:
- case GC_EVENT_SETSTATUSEX:
- return DoControl(gce, sessionEvent);
-
case GC_EVENT_SETCONTACTSTATUS:
return chatApi.SM_SetContactStatus(gcd->ptszID, gcd->pszModule, gce->ptszUID, (WORD)gce->dwItemData);
@@ -565,6 +507,86 @@ EXTERN_C MIR_APP_DLL(int) Chat_Event(int sessionEvent, GCEVENT *gce) return GC_EVENT_ERROR;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// chat control functions
+
+MIR_APP_DLL(int) Chat_ChangeSessionName(const char *szModule, const wchar_t *wszId, const wchar_t *wszNewName)
+{
+ if (wszNewName == NULL)
+ return GC_EVENT_ERROR;
+
+ mir_cslock lck(csChat);
+ if (SESSION_INFO *si = chatApi.SM_FindSession(wszId, szModule)) {
+ replaceStrW(si->ptszName, wszNewName);
+ if (si->hWnd)
+ SendMessage(si->hWnd, GC_UPDATETITLE, 0, 0);
+ if (chatApi.OnRenameSession)
+ chatApi.OnRenameSession(si);
+ }
+ return 0;
+}
+
+MIR_APP_DLL(int) Chat_ChangeUserId(const char *szModule, const wchar_t *wszId, const wchar_t *wszOldId, const wchar_t *wszNewId)
+{
+ if (wszNewId == NULL)
+ return GC_EVENT_ERROR;
+
+ mir_cslock lck(csChat);
+ return !chatApi.SM_ChangeUID(wszId, szModule, wszOldId, wszNewId);
+}
+
+MIR_APP_DLL(void*) Chat_GetUserInfo(const char *szModule, const wchar_t *wszId)
+{
+ mir_cslock lck(csChat);
+ if (SESSION_INFO *si = chatApi.SM_FindSession(wszId, szModule))
+ return si->pItemData;
+ return NULL;
+}
+
+MIR_APP_DLL(int) Chat_SendUserMessage(const char *szModule, const wchar_t *wszId, const wchar_t *wszText)
+{
+ if (wszText == NULL)
+ return GC_EVENT_ERROR;
+
+ mir_cslock lck(csChat);
+ return !chatApi.SM_SendUserMessage(wszId, szModule, wszText);
+}
+
+MIR_APP_DLL(int) Chat_SetStatusbarText(const char *szModule, const wchar_t *wszId, const wchar_t *wszText)
+{
+ mir_cslock lck(csChat);
+ if (SESSION_INFO *si = chatApi.SM_FindSession(wszId, szModule)) {
+ replaceStrW(si->ptszStatusbarText, wszText);
+ if (si->ptszStatusbarText)
+ db_set_ws(si->hContact, si->pszModule, "StatusBar", si->ptszStatusbarText);
+ else
+ db_set_s(si->hContact, si->pszModule, "StatusBar", "");
+
+ if (chatApi.OnSetStatusBar)
+ chatApi.OnSetStatusBar(si);
+ }
+ return 0;
+}
+
+MIR_APP_DLL(int) Chat_SetStatusEx(const char *szModule, const wchar_t *wszId, int flags, const wchar_t *wszText)
+{
+ mir_cslock lck(csChat);
+ return !chatApi.SM_SetStatusEx(wszId, szModule, wszText, flags);
+}
+
+MIR_APP_DLL(int) Chat_SetUserInfo(const char *szModule, const wchar_t *wszId, void *pItemData)
+{
+ mir_cslock lck(csChat);
+ if (SESSION_INFO *si = chatApi.SM_FindSession(wszId, szModule)) {
+ si->pItemData = pItemData;
+ return 0;
+ }
+ return GC_EVENT_ERROR;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// module initialization
+
static int ModulesLoaded(WPARAM, LPARAM)
{
LoadChatIcons();
@@ -595,9 +617,6 @@ static int ModulesLoaded(WPARAM, LPARAM) return 0;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-// Service creation
-
static bool bInited = false;
int LoadChatModule(void)
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 0ac5311f81..eb262e1eed 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -658,16 +658,7 @@ BOOL IsEventSupported(int eventType) case GC_EVENT_ACTION:
case GC_EVENT_ADDSTATUS:
case GC_EVENT_REMOVESTATUS:
- case GC_EVENT_CHUID:
- case GC_EVENT_CHANGESESSIONAME:
case GC_EVENT_ADDGROUP:
- case GC_EVENT_SETITEMDATA:
- case GC_EVENT_GETITEMDATA:
- case GC_EVENT_SETSBTEXT:
- case GC_EVENT_ACK:
- case GC_EVENT_SENDMESSAGE:
- case GC_EVENT_SETSTATUSEX:
- case GC_EVENT_CONTROL:
case GC_EVENT_SETCONTACTSTATUS:
return TRUE;
}
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index dd066e34da..a72414500f 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -300,3 +300,11 @@ Chat_Event @300 Chat_GetInfo @301
Chat_NewSession @302
Chat_Register @303
+Chat_GetUserInfo @304
+Chat_SetUserInfo @305
+Chat_ChangeUserId @306
+Chat_ChangeSessionName @307
+Chat_SetStatusbarText @308
+Chat_SendUserMessage @309
+Chat_SetStatusEx @310
+Chat_Terminate @311
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index de2bdb2cbe..e3d58e4aa3 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -300,3 +300,11 @@ Chat_Event @300 Chat_GetInfo @301
Chat_NewSession @302
Chat_Register @303
+Chat_GetUserInfo @304
+Chat_SetUserInfo @305
+Chat_ChangeUserId @306
+Chat_ChangeSessionName @307
+Chat_SetStatusbarText @308
+Chat_SendUserMessage @309
+Chat_SetStatusEx @310
+Chat_Terminate @311
|