From 00a9149e272b38b002d2a2711c54fab25bcf733f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 18 Jan 2014 12:41:41 +0000 Subject: - log writing fixed; - DoPopup & DoTrayIcons now use inheritance; - massive cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@7716 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TabSRMM/src/chat/chat.h | 11 +-- plugins/TabSRMM/src/chat/main.cpp | 6 +- plugins/TabSRMM/src/chat/options.cpp | 6 -- plugins/TabSRMM/src/chat/tools.cpp | 185 +++++------------------------------ plugins/TabSRMM/src/chat/window.cpp | 20 ++-- plugins/TabSRMM/src/utils.h | 2 +- 6 files changed, 43 insertions(+), 187 deletions(-) (limited to 'plugins/TabSRMM') diff --git a/plugins/TabSRMM/src/chat/chat.h b/plugins/TabSRMM/src/chat/chat.h index 605e9fefc0..e5d82d1272 100644 --- a/plugins/TabSRMM/src/chat/chat.h +++ b/plugins/TabSRMM/src/chat/chat.h @@ -61,17 +61,14 @@ struct MODULEINFO : public GCModuleInfoBase DWORD idleTimeStamp; DWORD lastIdleCheck; TCHAR tszIdleMsg[60]; - MODULEINFO * next; }; struct SESSION_INFO : public GCSessionInfoBase { TWindowData *dat; TContainerData *pContainer; - int iLogTrayFlags, iLogPopupFlags, iSearchItem; - + int iLogTrayFlags, iLogPopupFlags, iDiskLogFlags, iSearchItem; TCHAR szSearch[255]; - TCHAR pszLogFileName[MAX_PATH + 50]; }; struct LOGSTREAMDATA : public GCLogStreamDataBase @@ -113,6 +110,7 @@ struct FLASH_PARAMS }; extern TMUCSettings g_Settings; +extern CHAT_MANAGER saveCI; struct COLORCHOOSER { @@ -133,7 +131,6 @@ INT_PTR CALLBACK DlgProcColorToolWindow(HWND hwndDlg, UINT msg, WPARAM wParam, L // log.c void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, bool bRedraw, bool bPhaseTwo); char* Log_CreateRtfHeader(MODULEINFO *mi); -TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime); void Log_SetStyles(); // window.c @@ -142,7 +139,6 @@ int GetTextPixelSize(TCHAR* pszText, HFONT hFont, bool bWidth); // options.c enum { FONTSECTION_AUTO, FONTSECTION_IM, FONTSECTION_IP }; -int OptionsInit(void); void LoadMsgDlgFont(int section, int i, LOGFONT * lf, COLORREF * colour, char* szMod); void AddIcons(void); HICON LoadIconEx(int iIndex, char * pszIcoLibName, int iX, int iY); @@ -171,9 +167,10 @@ int GetRichTextLength(HWND hwnd); BOOL IsHighlighted(SESSION_INFO *si, GCEVENT *pszText); UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, TCHAR* pszUID, TCHAR* pszWordText); void DestroyGCMenu(HMENU *hMenu, int iIndex); -BOOL DoEventHookAsync(HWND hwnd, const TCHAR *pszID, const char* pszModule, int iType, TCHAR* pszUID, TCHAR* pszText, DWORD dwItem); void Chat_SetFilters(SESSION_INFO *si); void TSAPI DoFlashAndSoundWorker(FLASH_PARAMS* p); +BOOL LogToFile(SESSION_INFO *si, GCEVENT *gce); + // message.c char* Chat_Message_GetFromStream(HWND hwndDlg, SESSION_INFO *si); TCHAR* Chat_DoRtfToTags(char* pszRtfText, SESSION_INFO *si); diff --git a/plugins/TabSRMM/src/chat/main.cpp b/plugins/TabSRMM/src/chat/main.cpp index c367f9cef0..1e4ab502c9 100644 --- a/plugins/TabSRMM/src/chat/main.cpp +++ b/plugins/TabSRMM/src/chat/main.cpp @@ -49,6 +49,7 @@ static void OnAddLog(SESSION_INFO *si, int isOk) static void OnCreateSession(SESSION_INFO *si, MODULEINFO *mi) { + Chat_SetFilters(si); if (mi) { mi->idleTimeStamp = time(0); pci->SM_BroadcastMessage(mi->pszModule, GC_UPDATESTATUSBAR, 0, 1, TRUE); @@ -207,7 +208,7 @@ void Chat_ModulesLoaded() ///////////////////////////////////////////////////////////////////////////////////////// // load the group chat module -static CHAT_MANAGER saveCI; +CHAT_MANAGER saveCI; static int CopyChatSetting(const char *szSetting, LPARAM param) { @@ -273,12 +274,13 @@ int Chat_Load() // this operation is unsafe, that's why we restore the old pci state on exit pci->DoSoundsFlashPopupTrayStuff = DoSoundsFlashPopupTrayStuff; pci->IsHighlighted = IsHighlighted; + pci->LogToFile = LogToFile; pci->Log_CreateRtfHeader = Log_CreateRtfHeader; pci->ReloadSettings(); g_hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU)); - OptionsInit(); + g_Settings.Highlight = new CMUCHighlight(); return 0; } diff --git a/plugins/TabSRMM/src/chat/options.cpp b/plugins/TabSRMM/src/chat/options.cpp index 0aa3a65092..5b9a0dda05 100644 --- a/plugins/TabSRMM/src/chat/options.cpp +++ b/plugins/TabSRMM/src/chat/options.cpp @@ -1109,9 +1109,3 @@ INT_PTR CALLBACK DlgProcOptions3(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM } return FALSE; } - -int OptionsInit(void) -{ - g_Settings.Highlight = new CMUCHighlight(); - return 0; -} diff --git a/plugins/TabSRMM/src/chat/tools.cpp b/plugins/TabSRMM/src/chat/tools.cpp index 334447193a..e0d2cc7488 100644 --- a/plugins/TabSRMM/src/chat/tools.cpp +++ b/plugins/TabSRMM/src/chat/tools.cpp @@ -96,67 +96,11 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA return DefWindowProc(hWnd, message, wParam, lParam); } -static BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) +BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce) { int iEvent = gce->pDest->iType; - - if (si && (iEvent & si->iLogTrayFlags)) { - switch (iEvent) { - case GC_EVENT_MESSAGE | GC_EVENT_HIGHLIGHT : - case GC_EVENT_ACTION | GC_EVENT_HIGHLIGHT : - 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 : - 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: - 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: - 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: - 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: - pci->AddEvent(si->hContact, pci->hIcons[ICON_QUIT], szChatIconString, CLEF_ONLYAFEW, - TranslateT("%s has disconnected"), gce->ptszNick); - break; - case GC_EVENT_NICK: - 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: - 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: - pci->AddEvent(si->hContact, pci->hIcons[ICON_NOTICE], szChatIconString, CLEF_ONLYAFEW, - TranslateT("Notice from %s"), gce->ptszNick); - break; - case GC_EVENT_TOPIC: - pci->AddEvent(si->hContact, pci->hIcons[ICON_TOPIC], szChatIconString, CLEF_ONLYAFEW, - TranslateT("Topic change in %s"), si->ptszName); - break; - case GC_EVENT_INFORMATION: - pci->AddEvent(si->hContact, pci->hIcons[ICON_INFO], szChatIconString, CLEF_ONLYAFEW, - TranslateT("Information in %s"), si->ptszName); - break; - case GC_EVENT_ADDSTATUS: - 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: - 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; - } - } + if (si && (iEvent & si->iLogTrayFlags)) + return saveCI.DoTrayIcon(si, gce); return TRUE; } @@ -515,6 +459,25 @@ 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) +{ + if (!si || !gce) + return FALSE; + + /* + * check whether we have to log this event + */ + if (!(gce->pDest->iType & si->iDiskLogFlags)) + return FALSE; + + return saveCI.LogToFile(si, gce); // call kernel method +} + UINT CreateGCMenu(HWND hwndDlg, HMENU *hMenu, int iIndex, POINT pt, SESSION_INFO *si, TCHAR* pszUID, TCHAR* pszWordText) { HMENU hSubMenu = 0; @@ -615,25 +578,6 @@ 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 = pci->SM_FindSession(pszID, pszModule); - if (si == NULL) - return FALSE; - - GCHOOK *gch = (GCHOOK*)mir_calloc(sizeof(GCHOOK)); - GCDEST *gcd = (GCDEST*)mir_calloc(sizeof(GCDEST)); - gcd->pszModule = mir_strdup(pszModule); - gcd->ptszID = mir_tstrdup(pszID); - gch->ptszUID = mir_tstrdup(pszUID); - gch->ptszText = mir_tstrdup(pszText); - gcd->iType = iType; - gch->dwData = dwItem; - gch->pDest = gcd; - PostMessage(hwnd, GC_FIREHOOK, 0, (LPARAM)gch); - return TRUE; -} - /* * set all filters and notification config for a session * uses per channel mask + filterbits, default config as backup @@ -666,6 +610,8 @@ void Chat_SetFilters(SESSION_INFO *si) dwFlags_local = db_get_dw(si->hContact, "Chat", "TrayIconFlags", 0x03E0); dwMask = db_get_dw(si->hContact, "Chat", "TrayIconMask", 0); + si->iDiskLogFlags = M.GetDword("Chat", "DiskLogFlags", 0xFFFF); + si->iLogTrayFlags = dwFlags_default; for (int i=0; i < 32; i++) if (dwMask & (1 << i)) @@ -675,89 +621,6 @@ void Chat_SetFilters(SESSION_INFO *si) si->bFilterEnabled = 0; } -static TCHAR tszOldTimeStamp[30]; - -TCHAR* GetChatLogsFilename(SESSION_INFO *si, time_t tTime) -{ - if (!tTime) - time(&tTime); - - /* - * check whether relevant parts of the timestamp have changed and - * we have to reparse the filename - */ - - TCHAR *tszNow = pci->MakeTimeStamp(_T("%a%d%m%Y"), tTime); - - bool fReparse = false; - if (_tcscmp(tszOldTimeStamp, tszNow)) { - _tcsncpy(tszOldTimeStamp, tszNow, 30); - tszOldTimeStamp[29] = 0; - fReparse = true; - } - - if (fReparse || 0 == si->pszLogFileName[0]) { - REPLACEVARSARRAY rva[11]; - rva[0].lptzKey = _T("d"); - rva[0].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%#d"), tTime)); - // day 01-31 - rva[1].lptzKey = _T("dd"); - rva[1].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%d"), tTime)); - // month 1-12 - rva[2].lptzKey = _T("m"); - rva[2].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%#m"), tTime)); - // month 01-12 - rva[3].lptzKey = _T("mm"); - rva[3].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%m"), tTime)); - // month text short - rva[4].lptzKey = _T("mon"); - rva[4].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%b"), tTime)); - // month text - rva[5].lptzKey = _T("month"); - rva[5].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%B"), tTime)); - // year 01-99 - rva[6].lptzKey = _T("yy"); - rva[6].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%y"), tTime)); - // year 1901-9999 - rva[7].lptzKey = _T("yyyy"); - rva[7].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%Y"), tTime)); - // weekday short - rva[8].lptzKey = _T("wday"); - rva[8].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%a"), tTime)); - // weekday - rva[9].lptzKey = _T("weekday"); - rva[9].lptzValue = mir_tstrdup(pci->MakeTimeStamp(_T("%A"), tTime)); - // end of array - rva[10].lptzKey = NULL; - rva[10].lptzValue = NULL; - - if (g_Settings.pszLogDir[lstrlen(g_Settings.pszLogDir)-1] == '\\') - _tcscat(g_Settings.pszLogDir, _T("%userid%.log")); - - REPLACEVARSDATA dat = { sizeof(dat) }; - dat.dwFlags = RVF_TCHAR; - dat.hContact = si->hContact; - dat.variables = rva; - TCHAR *tszParsedName = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)g_Settings.pszLogDir, (LPARAM)&dat); - - if (!M.pathIsAbsolute(tszParsedName)) - mir_sntprintf(si->pszLogFileName, MAX_PATH, _T("%s%s"), M.getChatLogPath(), tszParsedName); - else - mir_sntprintf(si->pszLogFileName, MAX_PATH, _T("%s"), tszParsedName); - - mir_free(tszParsedName); - - for (int i=0; i < SIZEOF(rva);i++) - mir_free(rva[i].lptzValue); - - for (TCHAR *p = si->pszLogFileName + 2; *p; ++p) - if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || *p == '<' || *p == '>' || *p == '|' ) - *p = _T('_'); - } - - return si->pszLogFileName; -} - BOOL IsHighlighted(SESSION_INFO *si, GCEVENT *gce) { if (!g_Settings.HighlightEnabled || !g_Settings.pszHighlightWords || !gce) diff --git a/plugins/TabSRMM/src/chat/window.cpp b/plugins/TabSRMM/src/chat/window.cpp index ea559adc64..4ef037a93c 100644 --- a/plugins/TabSRMM/src/chat/window.cpp +++ b/plugins/TabSRMM/src/chat/window.cpp @@ -1665,7 +1665,7 @@ static LRESULT CALLBACK NicklistSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, break; case ID_MESS: - DoEventHookAsync(GetParent(hwnd), parentdat->ptszID, parentdat->pszModule, GC_USER_PRIVMESS, ui->pszUID, NULL, 0); + pci->DoEventHookAsync(GetParent(hwnd), parentdat->ptszID, parentdat->pszModule, GC_USER_PRIVMESS, ui->pszUID, NULL, 0); break; default: @@ -1679,7 +1679,7 @@ static LRESULT CALLBACK NicklistSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, for (int i=0; i < iSelectedItems; i++) { USERINFO *ui1 = pci->SM_GetUserFromIndex(parentdat->ptszID, parentdat->pszModule, pItems[i]); if (ui1) - DoEventHookAsync(hwndParent, parentdat->ptszID, parentdat->pszModule, GC_USER_NICKLISTMENU, ui1->pszUID, NULL, (LPARAM)uID); + pci->DoEventHookAsync(hwndParent, parentdat->ptszID, parentdat->pszModule, GC_USER_NICKLISTMENU, ui1->pszUID, NULL, (LPARAM)uID); } } mir_free(pItems); @@ -2605,7 +2605,7 @@ LABEL_SHOWWINDOW: return(_dlgReturn(hwndDlg, 1)); case TABSRMM_HK_MUC_SHOWSERVER: if (si->iType != GCW_SERVER) - DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, L"/servershow", 0); + pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, L"/servershow", 0); return(_dlgReturn(hwndDlg, 1)); } } @@ -2705,7 +2705,7 @@ LABEL_SHOWWINDOW: default: PostMessage(hwndDlg, WM_MOUSEACTIVATE, 0, 0); - DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_LOGMENU, NULL, NULL, (LPARAM)uID); + pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_LOGMENU, NULL, NULL, (LPARAM)uID); break; } @@ -2812,11 +2812,11 @@ LABEL_SHOWWINDOW: break; case ID_MESS: - DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_PRIVMESS, ui->pszUID, NULL, 0); + pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_PRIVMESS, ui->pszUID, NULL, 0); break; default: - DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_NICKLISTMENU, ui->pszUID, NULL, (LPARAM)uID); + pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_NICKLISTMENU, ui->pszUID, NULL, (LPARAM)uID); break; } DestroyGCMenu(&hMenu, 1); @@ -2939,7 +2939,7 @@ LABEL_SHOWWINDOW: PostMessage(hwndDlg, WM_MOUSEACTIVATE, 0, 0); SetFocus(GetDlgItem(hwndDlg, IDC_CHAT_MESSAGE)); } - else DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_PRIVMESS, ui->pszUID, NULL, 0); + else pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_PRIVMESS, ui->pszUID, NULL, 0); } return TRUE; } @@ -2979,7 +2979,7 @@ LABEL_SHOWWINDOW: bool fSound = true; if (ptszText[0] == '/' || si->iType == GCW_SERVER) fSound = false; - DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0); + pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_MESSAGE, NULL, ptszText, 0); mi->idleTimeStamp = time(0); mi->lastIdleCheck = 0; pci->SM_BroadcastMessage(si->pszModule, GC_UPDATESTATUSBAR, 0, 1, TRUE); @@ -3050,7 +3050,7 @@ LABEL_SHOWWINDOW: CallService("MSP/HTMLlog/ViewLog", (WPARAM)si->pszModule, (LPARAM)szName); } else if (pInfo) - ShellExecute(hwndDlg, NULL, GetChatLogsFilename(si, 0), NULL, NULL, SW_SHOW); + ShellExecute(hwndDlg, NULL, pci->GetChatLogsFilename(si, 0), NULL, NULL, SW_SHOW); } break; @@ -3061,7 +3061,7 @@ LABEL_SHOWWINDOW: case IDC_CHANMGR: if (!IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHANMGR))) break; - DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_CHANMGR, NULL, NULL, 0); + pci->DoEventHookAsync(hwndDlg, si->ptszID, si->pszModule, GC_USER_CHANMGR, NULL, NULL, 0); break; case IDC_FILTER: diff --git a/plugins/TabSRMM/src/utils.h b/plugins/TabSRMM/src/utils.h index 88c82acd3d..107aca9e16 100644 --- a/plugins/TabSRMM/src/utils.h +++ b/plugins/TabSRMM/src/utils.h @@ -34,7 +34,7 @@ #define RTF_DEFAULT_HEADER _T("{\\rtf1\\ansi\\deff0\\pard\\li%u\\fi-%u\\ri%u\\tx%u") -#define CNT_KEYNAME "CNTW_Def" +#define CNT_KEYNAME "CNTW_Def" #define CNT_BASEKEYNAME "CNTW_" struct TRTFColorTable -- cgit v1.2.3