From 831ad8a0121f9f9ee5c4f38d4a0d209b3c2bdb60 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 16 Jan 2014 21:40:14 +0000 Subject: kernel chats, part 3, tabsrmm git-svn-id: http://svn.miranda-ng.org/main/trunk@7684 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TabSRMM/src/chat/tools.cpp | 658 ++++++------------------------------- 1 file changed, 105 insertions(+), 553 deletions(-) (limited to 'plugins/TabSRMM/src/chat/tools.cpp') diff --git a/plugins/TabSRMM/src/chat/tools.cpp b/plugins/TabSRMM/src/chat/tools.cpp index 7230a6298f..ee2b54b374 100644 --- a/plugins/TabSRMM/src/chat/tools.cpp +++ b/plugins/TabSRMM/src/chat/tools.cpp @@ -33,6 +33,8 @@ #include "..\commonheaders.h" +char *szChatIconString = "chaticon"; + int GetRichTextLength(HWND hwnd) { GETTEXTLENGTHEX gtl; @@ -41,97 +43,6 @@ int GetRichTextLength(HWND hwnd) return (int) SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); } -/** - * @param pszWord string to strip of any IRC-style - * formatting - * @param fToLower convert to lowercase - * @param fStripCR strip cr/lf sequences (only for highlighter, defaults to false) - * @param buf caller-provided buffer, use a static one - * when the caller does not provide a - * buffer - * caller provided buffer is NEEDED to make - * this thread-safe. - * - * @return TCHAR* the stripped string - */ -TCHAR* RemoveFormatting(const TCHAR* pszWord, bool fToLower, bool fStripCR, TCHAR* buf, const size_t len) -{ - static TCHAR _szTemp[20000]; - TCHAR* szTemp = 0; - size_t _buflen = 0; - - if (0 == buf) { - szTemp = _szTemp; - _buflen = 20000; - } - else { - szTemp = buf; - _buflen = len; - szTemp[len - 1] = 0; - } - - size_t i = 0; - size_t j = 0; - - if (pszWord == 0) - return NULL; - - size_t wordlen = lstrlen(pszWord); - - while (j < _buflen && i <= wordlen) { - if (pszWord[i] == '%') { - switch (pszWord[i+1]) { - case '%': - szTemp[j] = '%'; - j++; - i++; - i++; - break; - case 'b': - case 'u': - case 'i': - case 'B': - case 'U': - case 'I': - case 'r': - case 'C': - case 'F': - i++; - i++; - break; - - case 'c': - case 'f': - i += 4; - break; - - default: - szTemp[j] = pszWord[i]; - j++; - i++; - break; - } - } - else { - if (fStripCR) { - if (0x0a == pszWord[i] || 0x0c == pszWord[i]) { - szTemp[j++] = ' '; - i++; - continue; - } - } - szTemp[j] = pszWord[i]; - j++; - i++; - } - } - if (fToLower) { - _wsetlocale(LC_ALL, L""); - wcslwr(szTemp); - } - return(szTemp); -} - static void __stdcall ShowRoomFromPopup(void * pi) { SESSION_INFO *si = (SESSION_INFO*) pi; @@ -185,50 +96,6 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA return DefWindowProc(hWnd, message, wParam, lParam); } -static int ShowPopup(HANDLE hContact, SESSION_INFO *si, HICON hIcon, char* pszProtoName, TCHAR* pszRoomName, COLORREF crBkg, const TCHAR* fmt, ...) -{ - POPUPDATAT pd = {0}; - va_list marker; - static TCHAR szBuf[4*1024]; - - if (!fmt || lstrlen(fmt) == 0 || lstrlen(fmt) > 2000) - return 0; - - va_start(marker, fmt); - mir_vsntprintf(szBuf, SIZEOF(szBuf), fmt, marker); - va_end(marker); - - pd.lchContact = hContact; - - if (hIcon) - pd.lchIcon = hIcon ; - else - pd.lchIcon = LoadIconEx(IDI_CHANMGR, "window", 0, 0); - - PROTOACCOUNT *pa = ProtoGetAccount(pszProtoName); - mir_sntprintf(pd.lptzContactName, MAX_CONTACTNAME-1, _T("%s - %s"), - (pa == NULL) ? _A2T(pszProtoName) : pa->tszAccountName, - pcli->pfnGetContactDisplayName(hContact, 0)); - - lstrcpyn(pd.lptzText, TranslateTS(szBuf), MAX_SECONDLINE); - pd.iSeconds = g_Settings.iPopupTimeout; - - if (g_Settings.iPopupStyle == 2) { - pd.colorBack = 0; - pd.colorText = 0; - } else if (g_Settings.iPopupStyle == 3) { - pd.colorBack = g_Settings.crPUBkgColour; - pd.colorText = g_Settings.crPUTextColour; - } else { - pd.colorBack = M.GetDword(FONTMODULE, SRMSGSET_BKGCOLOUR_MUC, SRMSGDEFSET_BKGCOLOUR); - pd.colorText = crBkg; - } - - pd.PluginWindowProc = PopupDlgProc; - pd.PluginData = si; - return PUAddPopupT(&pd); -} - static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) { int iEvent = gce->pDest->iType; @@ -237,55 +104,55 @@ static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) switch (iEvent) { case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT : case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT : - CList_AddEvent(si->hContact, PluginConfig.g_IconMsgEvent, szChatIconString, 0, + pci->AddEvent(si->hContact, PluginConfig.g_IconMsgEvent, szChatIconString, 0, TranslateT("%s wants your attention in %s"), gce->ptszNick, si->ptszName); break; case GC_EVENT_MESSAGE : - CList_AddEvent(si->hContact, hIcons[ICON_MESSAGE], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_MESSAGE], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->ptszNick, si->ptszName); break; case GC_EVENT_ACTION: - CList_AddEvent(si->hContact, hIcons[ICON_ACTION], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_ACTION], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s speaks in %s"), gce->ptszNick, si->ptszName); break; case GC_EVENT_JOIN: - CList_AddEvent(si->hContact, hIcons[ICON_JOIN], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_JOIN], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s has joined %s"), gce->ptszNick, si->ptszName); break; case GC_EVENT_PART: - CList_AddEvent(si->hContact, hIcons[ICON_PART], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_PART], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s has left %s"), gce->ptszNick, si->ptszName); break; case GC_EVENT_QUIT: - CList_AddEvent(si->hContact, hIcons[ICON_QUIT], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_QUIT], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s has disconnected"), gce->ptszNick); break; case GC_EVENT_NICK: - CList_AddEvent(si->hContact, hIcons[ICON_NICK], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_NICK], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText); break; case GC_EVENT_KICK: - CList_AddEvent(si->hContact, hIcons[ICON_KICK], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_KICK], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s kicked %s from %s"), gce->ptszStatus, gce->ptszNick, si->ptszName); break; case GC_EVENT_NOTICE: - CList_AddEvent(si->hContact, hIcons[ICON_NOTICE], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_NOTICE], szChatIconString, CLEF_ONLYAFEW, TranslateT("Notice from %s"), gce->ptszNick); break; case GC_EVENT_TOPIC: - CList_AddEvent(si->hContact, hIcons[ICON_TOPIC], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_TOPIC], szChatIconString, CLEF_ONLYAFEW, TranslateT("Topic change in %s"), si->ptszName); break; case GC_EVENT_INFORMATION: - CList_AddEvent(si->hContact, hIcons[ICON_INFO], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_INFO], szChatIconString, CLEF_ONLYAFEW, TranslateT("Information in %s"), si->ptszName); break; case GC_EVENT_ADDSTATUS: - CList_AddEvent(si->hContact, hIcons[ICON_ADDSTATUS], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_ADDSTATUS], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s enables \'%s\' status for %s in %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick, si->ptszName); break; case GC_EVENT_REMOVESTATUS: - CList_AddEvent(si->hContact, hIcons[ICON_REMSTATUS], szChatIconString, CLEF_ONLYAFEW, + pci->AddEvent(si->hContact, pci->hIcons[ICON_REMSTATUS], szChatIconString, CLEF_ONLYAFEW, TranslateT("%s disables \'%s\' status for %s in %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick, si->ptszName); break; } @@ -296,6 +163,9 @@ static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) static BOOL DoPopup(SESSION_INFO *si, GCEVENT* gce, TWindowData *dat) { int iEvent = gce->pDest->iType; + if (si == NULL || !(iEvent & si->iLogPopupFlags)) + return true; + TContainerData *pContainer = dat ? dat->pContainer : NULL; TCHAR *bbStart, *bbEnd; @@ -305,121 +175,60 @@ static BOOL DoPopup(SESSION_INFO *si, GCEVENT* gce, TWindowData *dat) } else bbStart = bbEnd = _T(""); - if (si && (iEvent & si->iLogPopupFlags)) { - if (nen_options.iMUCDisable) // no popups at all. Period - return 0; - /* - * check the status mode against the status mask - */ - - char *szProto = dat ? dat->szProto : si->pszModule; - if (nen_options.dwStatusMask != -1) { - DWORD dwStatus = 0; - if (szProto != NULL) { - dwStatus = (DWORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0); - if (!(dwStatus == 0 || dwStatus <= ID_STATUS_OFFLINE || ((1 << (dwStatus - ID_STATUS_ONLINE)) & nen_options.dwStatusMask))) // should never happen, but... - return 0; - } + if (nen_options.iMUCDisable) // no popups at all. Period + return 0; + /* + * check the status mode against the status mask + */ + + char *szProto = dat ? dat->szProto : si->pszModule; + if (nen_options.dwStatusMask != -1) { + DWORD dwStatus = 0; + if (szProto != NULL) { + dwStatus = (DWORD)CallProtoService(szProto, PS_GETSTATUS, 0, 0); + if (!(dwStatus == 0 || dwStatus <= ID_STATUS_OFFLINE || ((1 << (dwStatus - ID_STATUS_ONLINE)) & nen_options.dwStatusMask))) // should never happen, but... + return 0; } - if (dat && pContainer != 0) { // message window is open, need to check the container config if we want to see a popup nonetheless - if (nen_options.bWindowCheck) { // no popups at all for open windows... no exceptions - if (!PluginConfig.m_HideOnClose) - return 0; - if (pContainer->fHidden) - goto passed; + } + if (dat && pContainer != 0) { // message window is open, need to check the container config if we want to see a popup nonetheless + if (nen_options.bWindowCheck) { // no popups at all for open windows... no exceptions + if (!PluginConfig.m_HideOnClose) return 0; - } - if (pContainer->dwFlags & CNT_DONTREPORT && IsIconic(pContainer->hwnd)) // in tray counts as "minimised" + if (pContainer->fHidden) + goto passed; + return 0; + } + if (pContainer->dwFlags & CNT_DONTREPORT && IsIconic(pContainer->hwnd)) // in tray counts as "minimised" + goto passed; + if (pContainer->dwFlags & CNT_DONTREPORTUNFOCUSED) { + if (!IsIconic(pContainer->hwnd) && GetForegroundWindow() != pContainer->hwnd && GetActiveWindow() != pContainer->hwnd) + goto passed; + } + if (pContainer->dwFlags & CNT_ALWAYSREPORTINACTIVE) { + if (pContainer->dwFlags & CNT_DONTREPORTFOCUSED) goto passed; - if (pContainer->dwFlags & CNT_DONTREPORTUNFOCUSED) { - if (!IsIconic(pContainer->hwnd) && GetForegroundWindow() != pContainer->hwnd && GetActiveWindow() != pContainer->hwnd) - goto passed; - } - if (pContainer->dwFlags & CNT_ALWAYSREPORTINACTIVE) { - if (pContainer->dwFlags & CNT_DONTREPORTFOCUSED) - goto passed; - if (pContainer->hwndActive == si->hWnd) - return 0; + if (pContainer->hwndActive == si->hWnd) + return 0; - goto passed; - } - return 0; + goto passed; } + return 0; + } passed: - int iNewEvent = iEvent; - COLORREF clr = 0; + int iNewEvent = iEvent; + COLORREF clr = 0; - if ((iNewEvent & GC_EVENT_HIGHLIGHT)) { - clr = aFonts[16].color; - iNewEvent &= ~GC_EVENT_HIGHLIGHT; - } + if ((iNewEvent & GC_EVENT_HIGHLIGHT)) { + clr = pci->aFonts[16].color; + iNewEvent &= ~GC_EVENT_HIGHLIGHT; + } - switch (iNewEvent) { - case GC_EVENT_MESSAGE : - ShowPopup(si->hContact, si, hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, clr ? clr : aFonts[9].color, - TranslateT("%s%s says:%s %s"), bbStart, gce->ptszNick, bbEnd, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_ACTION: - ShowPopup(si->hContact, si, hIcons[ICON_ACTION], si->pszModule, si->ptszName, clr ? clr : aFonts[15].color, _T("%s %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_JOIN: - ShowPopup(si->hContact, si, hIcons[ICON_JOIN], si->pszModule, si->ptszName, clr ? clr : aFonts[3].color, - TranslateT("%s has joined"), gce->ptszNick); - break; - case GC_EVENT_PART: - if (!gce->ptszText) - ShowPopup(si->hContact, si, hIcons[ICON_PART], si->pszModule, si->ptszName, clr ? clr : aFonts[4].color, - TranslateT("%s has left"), gce->ptszNick); - else - ShowPopup(si->hContact, si, hIcons[ICON_PART], si->pszModule, si->ptszName, clr ? clr : aFonts[4].color, - TranslateT("%s has left (%s)"), gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_QUIT: - if (!gce->ptszText) - ShowPopup(si->hContact, si, hIcons[ICON_QUIT], si->pszModule, si->ptszName, clr ? clr : aFonts[5].color, - TranslateT("%s has disconnected"), gce->ptszNick); - else - ShowPopup(si->hContact, si, hIcons[ICON_QUIT], si->pszModule, si->ptszName, clr ? clr : aFonts[5].color, - TranslateT("%s has disconnected (%s)"), gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_NICK: - ShowPopup(si->hContact, si, hIcons[ICON_NICK], si->pszModule, si->ptszName, clr ? clr : aFonts[7].color, - TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText); - break; - case GC_EVENT_KICK: - if (!gce->ptszText) - ShowPopup(si->hContact, si, hIcons[ICON_KICK], si->pszModule, si->ptszName, clr ? clr : aFonts[6].color, - TranslateT("%s kicked %s"), gce->ptszStatus, gce->ptszNick); - else - ShowPopup(si->hContact, si, hIcons[ICON_KICK], si->pszModule, si->ptszName, clr ? clr : aFonts[6].color, - TranslateT("%s kicked %s (%s)"), gce->ptszStatus, gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_NOTICE: - ShowPopup(si->hContact, si, hIcons[ICON_NOTICE], si->pszModule, si->ptszName, clr ? clr : aFonts[8].color, - TranslateT("Notice from %s: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_TOPIC: - if (!gce->ptszNick) - ShowPopup(si->hContact, si, hIcons[ICON_TOPIC], si->pszModule, si->ptszName, clr ? clr : aFonts[11].color, - TranslateT("The topic is \'%s\'"), RemoveFormatting(gce->ptszText)); - else - ShowPopup(si->hContact, si, hIcons[ICON_TOPIC], si->pszModule, si->ptszName, clr ? clr : aFonts[11].color, - TranslateT("The topic is \'%s\' (set by %s)"), RemoveFormatting(gce->ptszText), gce->ptszNick); - break; - case GC_EVENT_INFORMATION: - ShowPopup(si->hContact, si, hIcons[ICON_INFO], si->pszModule, si->ptszName, clr ? clr : aFonts[12].color, _T("%s"), RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_ADDSTATUS: - ShowPopup(si->hContact, si, hIcons[ICON_ADDSTATUS], si->pszModule, si->ptszName, clr ? clr : aFonts[13].color, - TranslateT("%s enables \'%s\' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick); - break; - case GC_EVENT_REMOVESTATUS: - ShowPopup(si->hContact, si, hIcons[ICON_REMSTATUS], si->pszModule, si->ptszName, clr ? clr : aFonts[14].color, - TranslateT("%s disables \'%s\' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick); - break; - } + if (iNewEvent == GC_EVENT_MESSAGE) { + pci->ShowPopup(si->hContact, si, pci->hIcons[ICON_MESSAGE], si->pszModule, si->ptszName, clr ? clr : pci->aFonts[9].color, + TranslateT("%s%s says:%s %s"), bbStart, gce->ptszNick, bbEnd, pci->RemoveFormatting(gce->ptszText)); } + else pci->DoPopup(si, gce); return TRUE; } @@ -445,14 +254,14 @@ void TSAPI DoFlashAndSoundWorker(FLASH_PARAMS* p) if (dat) { HWND hwndTab = GetParent(si->hWnd); - BOOL bForcedIcon = (p->hNotifyIcon == hIcons[ICON_HIGHLIGHT] || p->hNotifyIcon == hIcons[ICON_MESSAGE]); + BOOL bForcedIcon = (p->hNotifyIcon == pci->hIcons[ICON_HIGHLIGHT] || p->hNotifyIcon == pci->hIcons[ICON_MESSAGE]); if ((p->iEvent & si->iLogTrayFlags) || bForcedIcon) { if (!p->bActiveTab) { - if (p->hNotifyIcon == hIcons[ICON_HIGHLIGHT]) + if (p->hNotifyIcon == pci->hIcons[ICON_HIGHLIGHT]) dat->iFlashIcon = p->hNotifyIcon; else { - if (dat->iFlashIcon != hIcons[ICON_HIGHLIGHT] && dat->iFlashIcon != hIcons[ICON_MESSAGE]) + if (dat->iFlashIcon != pci->hIcons[ICON_HIGHLIGHT] && dat->iFlashIcon != pci->hIcons[ICON_MESSAGE]) dat->iFlashIcon = p->hNotifyIcon; } dat->mayFlashTab = TRUE; @@ -498,7 +307,7 @@ void TSAPI DoFlashAndSoundWorker(FLASH_PARAMS* p) } HICON hIcon = (HICON)SendMessage(dat->pContainer->hwnd, WM_GETICON, ICON_BIG, 0); - if (p->hNotifyIcon == hIcons[ICON_HIGHLIGHT] || (hIcon != hIcons[ICON_MESSAGE] && hIcon != hIcons[ICON_HIGHLIGHT])) { + if (p->hNotifyIcon == pci->hIcons[ICON_HIGHLIGHT] || (hIcon != pci->hIcons[ICON_MESSAGE] && hIcon != pci->hIcons[ICON_HIGHLIGHT])) { SendMessage(dat->pContainer->hwnd, DM_SETICON, (WPARAM)dat, (LPARAM)p->hNotifyIcon); dat->pContainer->dwFlags |= CNT_NEED_UPDATETITLE; } @@ -517,7 +326,7 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight return FALSE; TWindowData *dat = NULL; - FLASH_PARAMS *params = (FLASH_PARAMS*)mir_calloc( sizeof(FLASH_PARAMS)); + FLASH_PARAMS *params = (FLASH_PARAMS*)mir_calloc(sizeof(FLASH_PARAMS)); params->hContact = si->hContact; params->bInactive = TRUE; if (si->hWnd && si->dat) { @@ -557,11 +366,11 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight if (g_Settings.bFlashWindowHightlight && params->bInactive) params->bMustFlash = TRUE; params->bMustAutoswitch = TRUE; - params->hNotifyIcon = hIcons[ICON_HIGHLIGHT]; + params->hNotifyIcon = pci->hIcons[ICON_HIGHLIGHT]; } else { // do blinking icons in tray - if (params->bInactive || !g_Settings.bTrayIconInactiveOnly) { + if (params->bInactive || !g_Settings.TrayIconInactiveOnly) { DoTrayIcon(si, gce); if (params->iEvent == GC_EVENT_MESSAGE) bFlagUnread = true; @@ -577,28 +386,28 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight case GC_EVENT_JOIN: params->sound = "ChatJoin"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_JOIN]; + params->hNotifyIcon = pci->hIcons[ICON_JOIN]; break; case GC_EVENT_PART: params->sound = "ChatPart"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_PART]; + params->hNotifyIcon = pci->hIcons[ICON_PART]; break; case GC_EVENT_QUIT: params->sound = "ChatQuit"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_QUIT]; + params->hNotifyIcon = pci->hIcons[ICON_QUIT]; break; case GC_EVENT_ADDSTATUS: case GC_EVENT_REMOVESTATUS: params->sound = "ChatMode"; if (params->bInactive) - params->hNotifyIcon = hIcons[params->iEvent == GC_EVENT_ADDSTATUS ? ICON_ADDSTATUS : ICON_REMSTATUS]; + params->hNotifyIcon = pci->hIcons[params->iEvent == GC_EVENT_ADDSTATUS ? ICON_ADDSTATUS : ICON_REMSTATUS]; break; case GC_EVENT_KICK: params->sound = "ChatKick"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_KICK]; + params->hNotifyIcon = pci->hIcons[ICON_KICK]; break; case GC_EVENT_MESSAGE: params->sound = "ChatMessage"; @@ -610,65 +419,65 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight case GC_EVENT_ACTION: params->sound = "ChatAction"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_ACTION]; + params->hNotifyIcon = pci->hIcons[ICON_ACTION]; break; case GC_EVENT_NICK: params->sound = "ChatNick"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_NICK]; + params->hNotifyIcon = pci->hIcons[ICON_NICK]; break; case GC_EVENT_NOTICE: params->sound = "ChatNotice"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_NOTICE]; + params->hNotifyIcon = pci->hIcons[ICON_NOTICE]; break; case GC_EVENT_TOPIC: params->sound = "ChatTopic"; if (params->bInactive) - params->hNotifyIcon = hIcons[ICON_TOPIC]; + params->hNotifyIcon = pci->hIcons[ICON_TOPIC]; break; } } else { switch (params->iEvent) { case GC_EVENT_JOIN: - params->hNotifyIcon = hIcons[ICON_JOIN]; + params->hNotifyIcon = pci->hIcons[ICON_JOIN]; break; case GC_EVENT_PART: - params->hNotifyIcon = hIcons[ICON_PART]; + params->hNotifyIcon = pci->hIcons[ICON_PART]; break; case GC_EVENT_QUIT: - params->hNotifyIcon = hIcons[ICON_QUIT]; + params->hNotifyIcon = pci->hIcons[ICON_QUIT]; break; case GC_EVENT_KICK: - params->hNotifyIcon = hIcons[ICON_KICK]; + params->hNotifyIcon = pci->hIcons[ICON_KICK]; break; case GC_EVENT_ACTION: - params->hNotifyIcon = hIcons[ICON_ACTION]; + params->hNotifyIcon = pci->hIcons[ICON_ACTION]; break; case GC_EVENT_NICK: - params->hNotifyIcon = hIcons[ICON_NICK]; + params->hNotifyIcon = pci->hIcons[ICON_NICK]; break; case GC_EVENT_NOTICE: - params->hNotifyIcon = hIcons[ICON_NOTICE]; + params->hNotifyIcon = pci->hIcons[ICON_NOTICE]; break; case GC_EVENT_TOPIC: - params->hNotifyIcon = hIcons[ICON_TOPIC]; + params->hNotifyIcon = pci->hIcons[ICON_TOPIC]; break; case GC_EVENT_ADDSTATUS: - params->hNotifyIcon = hIcons[ICON_ADDSTATUS]; + params->hNotifyIcon = pci->hIcons[ICON_ADDSTATUS]; break; case GC_EVENT_REMOVESTATUS: - params->hNotifyIcon = hIcons[ICON_REMSTATUS]; + params->hNotifyIcon = pci->hIcons[ICON_REMSTATUS]; break; } } if (params->iEvent == GC_EVENT_MESSAGE) { params->bMustAutoswitch = TRUE; - if (g_Settings.bFlashWindow) + if (g_Settings.FlashWindow) params->bMustFlash = TRUE; - params->hNotifyIcon = hIcons[ICON_MESSAGE]; + params->hNotifyIcon = pci->hIcons[ICON_MESSAGE]; } } if (dat && bFlagUnread) { @@ -682,7 +491,7 @@ BOOL DoSoundsFlashPopupTrayStuff(SESSION_INFO *si, GCEVENT *gce, BOOL bHighlight int Chat_GetColorIndex(const char* pszModule, COLORREF cr) { - MODULEINFO *pMod = MM_FindModule(pszModule); + MODULEINFO *pMod = pci->MM_FindModule(pszModule); if (!pMod || pMod->nColorCount == 0) return -1; @@ -693,32 +502,6 @@ int Chat_GetColorIndex(const char* pszModule, COLORREF cr) return -1; } -// obscure function that is used to make sure that any of the colors -// passed by the protocol is used as fore- or background color -// in the messagebox. THis is to vvercome limitations in the richedit -// that I do not know currently how to fix - -void CheckColorsInModule(const char* pszModule) -{ - MODULEINFO * pMod = MM_FindModule(pszModule); - COLORREF crFG; - COLORREF crBG = (COLORREF)M.GetDword(FONTMODULE, "inputbg", SRMSGDEFSET_BKGCOLOUR); - - LoadLogfont(MSGFONTID_MESSAGEAREA, NULL, &crFG, FONTMODULE); - - if (!pMod) - return; - - for (int i=0; i < pMod->nColorCount; i++) { - if (pMod->crColors[i] == crFG || pMod->crColors[i] == crBG) { - if (pMod->crColors[i] == RGB(255, 255, 255)) - pMod->crColors[i]--; - else - pMod->crColors[i]++; - } - } -} - TCHAR* my_strstri(const TCHAR* s1, const TCHAR* s2) { int i, j, k; @@ -732,187 +515,9 @@ TCHAR* my_strstri(const TCHAR* s1, const TCHAR* s2) return NULL; } -/* - * log the event to the log file - * allows selective logging of wanted events - */ -BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce) -{ - TCHAR szBuffer[4096]; - TCHAR szLine[4096]; - TCHAR p = '\0'; - - if (!si || !gce) - return FALSE; - - MODULEINFO *mi = MM_FindModule(si->pszModule); - if (!mi) - return FALSE; - - /* - * check whether we have to log this event - */ - if (!(gce->pDest->iType & si->iDiskLogFlags)) - return FALSE; - - szBuffer[0] = '\0'; - - GetChatLogsFilename(si, gce->time); - BOOL bFileJustCreated = !PathFileExists(si->pszLogFileName); - - TCHAR tszFolder[MAX_PATH]; - _tcscpy(tszFolder, si->pszLogFileName); - PathRemoveFileSpec(tszFolder); - if (!PathIsDirectory(tszFolder)) - CreateDirectoryTreeT(tszFolder); - - TCHAR szTime[100]; - lstrcpyn(szTime, MakeTimeStamp(g_Settings.pszTimeStampLog, gce->time), 99); - - FILE *hFile = _tfopen(si->pszLogFileName, _T("ab+")); - if (hFile) { - TCHAR szTemp[512], szTemp2[512]; - TCHAR* pszNick = NULL; - if (bFileJustCreated) - fputws((const wchar_t*)"\377\376", hFile); //UTF-16 LE BOM == FF FE - if (gce->ptszNick) { - if (g_Settings.bLogLimitNames && lstrlen(gce->ptszNick) > 20) { - lstrcpyn(szTemp2, gce->ptszNick, 20); - lstrcpyn(szTemp2 + 20, _T("..."), 4); - } - else lstrcpyn(szTemp2, gce->ptszNick, 511); - - if (gce->ptszUserInfo) - mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%s (%s)"), szTemp2, gce->ptszUserInfo); - else - mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%s"), szTemp2); - pszNick = szTemp; - } - - switch (gce->pDest->iType) { - case GC_EVENT_MESSAGE: - case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT: - p = '*'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_ACTION: - case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT: - p = '*'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_JOIN: - p = '>'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s has joined"), pszNick); - break; - case GC_EVENT_PART: - p = '<'; - if (!gce->ptszText) - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s has left"), pszNick); - else - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s has left (%s)"), pszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_QUIT: - p = '<'; - if (!gce->ptszText) - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s has disconnected"), pszNick); - else - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s has disconnected (%s)"), pszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_NICK: - p = '^'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s is now known as %s"), gce->ptszNick, gce->ptszText); - break; - case GC_EVENT_KICK: - p = '~'; - if (!gce->ptszText) - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s kicked %s"), gce->ptszStatus, gce->ptszNick); - else - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s kicked %s (%s)"), gce->ptszStatus, gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_NOTICE: - p = 'o'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("Notice from %s: %s"), gce->ptszNick, RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_TOPIC: - p = '#'; - if (!gce->ptszNick) - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("The topic is \'%s\'"), RemoveFormatting(gce->ptszText)); - else - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("The topic is \'%s\' (set by %s)"), RemoveFormatting(gce->ptszText), gce->ptszNick); - break; - case GC_EVENT_INFORMATION: - p = '!'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s"), RemoveFormatting(gce->ptszText)); - break; - case GC_EVENT_ADDSTATUS: - p = '+'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s enables \'%s\' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick); - break; - case GC_EVENT_REMOVESTATUS: - p = '-'; - mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s disables \'%s\' status for %s"), gce->ptszText, gce->ptszStatus, gce->ptszNick); - break; - } - - /* - * formatting strings don't need to be translatable - changing them via language pack would - * only screw up the log format. - */ - if (p) - mir_sntprintf(szLine, SIZEOF(szLine), _T("%s %c %s\r\n"), szTime, p, szBuffer); - else - mir_sntprintf(szLine, SIZEOF(szLine), _T("%s %s\r\n"), szTime, szBuffer); - - if (szLine[0]) { - _fputts(szLine, hFile); - - if (g_Settings.LoggingLimit > 0) { - fseek(hFile, 0, SEEK_END); - long dwSize = ftell(hFile); - rewind(hFile); - - long trimlimit = g_Settings.LoggingLimit * 1024; - if (dwSize > trimlimit) { - time_t now = time(0); - - TCHAR tszTimestamp[20]; - _tcsftime(tszTimestamp, 20, _T("%Y%m%d-%H%M%S"), _localtime32((__time32_t *)&now)); - tszTimestamp[19] = 0; - /* - * max size reached, rotate the log - * move old logs to /archived sub folder just inside the log root folder. - * add a time stamp to the file name. - */ - TCHAR tszDrive[_MAX_DRIVE], tszDir[_MAX_DIR], tszName[_MAX_FNAME], tszExt[_MAX_EXT]; - _tsplitpath(si->pszLogFileName, tszDrive, tszDir, tszName, tszExt); - - TCHAR tszNewPath[_MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT + 20]; - mir_sntprintf(tszNewPath, _MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT + 20, _T("%s%sarchived\\"), tszDrive, tszDir); - CreateDirectoryTreeT(tszNewPath); - - TCHAR tszNewName[_MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT + 20]; - mir_sntprintf(tszNewName, _MAX_DRIVE + _MAX_DIR + _MAX_FNAME + _MAX_EXT + 20, _T("%s%s-%s%s"), tszNewPath, tszName, tszTimestamp, tszExt); - fclose(hFile); - hFile = 0; - if (!PathFileExists(tszNewName)) - CopyFile(si->pszLogFileName, tszNewName, TRUE); - DeleteFile(si->pszLogFileName); - } - } - } - - if (hFile) - fclose(hFile); - hFile = NULL; - return TRUE; - } - return FALSE; -} - UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, TCHAR* pszUID, TCHAR* pszWordText) { HMENU hSubMenu = 0; - DWORD codepage = M.GetDword(si->hContact, "ANSIcodepage", 0); *hMenu = GetSubMenu(g_hMenu, iIndex); TranslateMenu(*hMenu); @@ -956,7 +561,7 @@ UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO gcmi.Type = MENU_ON_NICKLIST; } - NotifyEventHooks(hBuildMenuEvent, 0, (WPARAM)&gcmi); + NotifyEventHooks(pci->hBuildMenuEvent, 0, (WPARAM)&gcmi); if (gcmi.nItems > 0) AppendMenu(*hMenu, MF_SEPARATOR, 0, 0); @@ -1012,7 +617,7 @@ void DestroyGCMenu(HMENU *hMenu, int iIndex) BOOL DoEventHookAsync(HWND hwnd, const TCHAR *pszID, const char* pszModule, int iType, TCHAR* pszUID, TCHAR* pszText, DWORD dwItem) { - SESSION_INFO *si = SM_FindSession(pszID, pszModule); + SESSION_INFO *si = pci->SM_FindSession(pszID, pszModule); if (si == NULL) return FALSE; @@ -1029,56 +634,6 @@ BOOL DoEventHookAsync(HWND hwnd, const TCHAR *pszID, const char* pszModule, int return TRUE; } -BOOL DoEventHook(const TCHAR *pszID, const char* pszModule, int iType, const TCHAR* pszUID, const TCHAR* pszText, DWORD dwItem) -{ - SESSION_INFO *si = SM_FindSession(pszID, pszModule); - if (si == NULL) - return FALSE; - - GCDEST gcd = { pszModule, pszID, iType }; - GCHOOK gch = { 0 }; - gch.ptszUID = (LPTSTR)pszUID; - gch.ptszText = (LPTSTR)pszText; - gch.dwData = dwItem; - gch.pDest = &gcd; - NotifyEventHooks(hSendEvent, 0, (WPARAM)&gch); - return TRUE; -} - -BOOL IsEventSupported(int eventType) -{ - // Supported events - switch (eventType) { - case GC_EVENT_JOIN: - case GC_EVENT_PART: - case GC_EVENT_QUIT: - case GC_EVENT_KICK: - case GC_EVENT_NICK: - case GC_EVENT_NOTICE: - case GC_EVENT_MESSAGE: - case GC_EVENT_TOPIC: - case GC_EVENT_INFORMATION: - 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; - } - - // Other events - return FALSE; -} - /* * set all filters and notification config for a session * uses per channel mask + filterbits, default config as backup @@ -1116,14 +671,11 @@ void Chat_SetFilters(SESSION_INFO *si) if (dwMask & (1 << i)) si->iLogTrayFlags = (dwFlags_local & (1 << i) ? si->iLogTrayFlags | (1 << i) : si->iLogTrayFlags & ~(1 << i)); - dwFlags_default = M.GetDword("Chat", "DiskLogFlags", 0xFFFF); - si->iDiskLogFlags = dwFlags_default; - if (si->iLogFilterFlags == 0) si->bFilterEnabled = 0; } -static TCHAR tszOldTimeStamp[30] = _T("\0"); +static TCHAR tszOldTimeStamp[30]; TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) { @@ -1135,7 +687,7 @@ TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) * we have to reparse the filename */ - TCHAR *tszNow = MakeTimeStamp(_T("%a%d%m%Y"), tTime); + TCHAR *tszNow = pci->MakeTimeStamp(_T("%a%d%m%Y"), tTime); bool fReparse = false; if (_tcscmp(tszOldTimeStamp, tszNow)) { @@ -1147,34 +699,34 @@ TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) if (fReparse || 0 == si->pszLogFileName[0]) { REPLACEVARSARRAY rva[11]; rva[0].lptzKey = _T("d"); - rva[0].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%#d"), tTime)); + rva[0].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%#d"), tTime)); // day 01-31 rva[1].lptzKey = _T("dd"); - rva[1].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%d"), tTime)); + rva[1].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%d"), tTime)); // month 1-12 rva[2].lptzKey = _T("m"); - rva[2].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%#m"), tTime)); + rva[2].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%#m"), tTime)); // month 01-12 rva[3].lptzKey = _T("mm"); - rva[3].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%m"), tTime)); + rva[3].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%m"), tTime)); // month text short rva[4].lptzKey = _T("mon"); - rva[4].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%b"), tTime)); + rva[4].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%b"), tTime)); // month text rva[5].lptzKey = _T("month"); - rva[5].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%B"), tTime)); + rva[5].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%B"), tTime)); // year 01-99 rva[6].lptzKey = _T("yy"); - rva[6].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%y"), tTime)); + rva[6].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%y"), tTime)); // year 1901-9999 rva[7].lptzKey = _T("yyyy"); - rva[7].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%Y"), tTime)); + rva[7].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%Y"), tTime)); // weekday short rva[8].lptzKey = _T("wday"); - rva[8].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%a"), tTime)); + rva[8].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%a"), tTime)); // weekday rva[9].lptzKey = _T("weekday"); - rva[9].lptzValue = mir_tstrdup(MakeTimeStamp(_T("%A"), tTime)); + rva[9].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%A"), tTime)); // end of array rva[10].lptzKey = NULL; rva[10].lptzValue = NULL; -- cgit v1.2.3