From 4c4735a232c680e60a85d0f85e2cb392e012c6e0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 17 May 2018 17:49:56 +0300 Subject: Toaster, TooltipNotify, TrafficCounter, UInfoEx, UserGuide, Variables -> CMPlugin --- plugins/TrafficCounter/src/TrafficCounter.cpp | 408 +++++++++++++------------- plugins/TrafficCounter/src/TrafficCounter.h | 6 +- plugins/TrafficCounter/src/options.cpp | 2 +- plugins/TrafficCounter/src/stdafx.h | 10 +- plugins/TrafficCounter/src/vars.cpp | 89 +++--- 5 files changed, 256 insertions(+), 259 deletions(-) (limited to 'plugins/TrafficCounter/src') diff --git a/plugins/TrafficCounter/src/TrafficCounter.cpp b/plugins/TrafficCounter/src/TrafficCounter.cpp index 7a43bc55fc..e65fcfdbf5 100644 --- a/plugins/TrafficCounter/src/TrafficCounter.cpp +++ b/plugins/TrafficCounter/src/TrafficCounter.cpp @@ -28,10 +28,10 @@ PROTOLIST OverallInfo; // Суммарные данные по видимым а int NumberOfAccounts; HWND TrafficHwnd; -HINSTANCE hInst; +CMPlugin g_plugin; CLIST_INTERFACE *pcli; - int hLangpack = 0; // Поддержка плагинозависимого перевода. + BOOL bPopupExists = FALSE, bVariablesExists = FALSE, bTooltipExists = FALSE; static wchar_t tszFormat[] = @@ -97,7 +97,7 @@ POINT TooltipPosition; BOOL UseKeyColor; COLORREF KeyColor; -//--------------------------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// PLUGININFOEX pluginInfoEx = { @@ -118,43 +118,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD) return &pluginInfoEx; } -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) -{ - hInst = hinstDLL; - DisableThreadLibraryCalls(hInst); - - return TRUE; -} - -extern "C" int __declspec(dllexport) Load(void) -{ - // Получаем дескриптор языкового пакета. - mir_getLP(&pluginInfoEx); - pcli = Clist_GetInterface(); - - HookEvent(ME_OPT_INITIALISE, TrafficCounterOptInitialise); - HookEvent(ME_SYSTEM_MODULESLOADED, TrafficCounterModulesLoaded); - HookEvent(ME_PROTO_ACK, ProtocolAckHook); - HookEvent(ME_PROTO_ACCLISTCHANGED, OnAccountsListChange); - HookEvent(ME_SYSTEM_PRESHUTDOWN, TrafficCounterShutdown); - HookEvent(ME_SYSTEM_MODULELOAD, ModuleLoad); - HookEvent(ME_SYSTEM_MODULEUNLOAD, ModuleLoad); - - return 0; -} - -extern "C" int __declspec(dllexport) Unload(void) -{ - // Удаляем шрифт. - if (Traffic_h_font) { - DeleteObject(Traffic_h_font); - Traffic_h_font = nullptr; - } - - // Убиваем все рабочие данные. - DestroyProtocolList(); - return 0; -} +///////////////////////////////////////////////////////////////////////////////////////// int TrafficCounterShutdown(WPARAM, LPARAM) { @@ -192,117 +156,6 @@ int ModuleLoad(WPARAM, LPARAM) return 0; } -int TrafficCounterModulesLoaded(WPARAM, LPARAM) -{ - DBVARIANT dbv; - - CreateProtocolList(); - ModuleLoad(0, 0); - - // Читаем флаги - unOptions.Flags = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_WHAT_DRAW, 0x0882); - Stat_SelAcc = db_get_w(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_STAT_ACC_OPT, 0x01); - - // settings for notification - Traffic_PopupBkColor = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_BKCOLOR, RGB(200, 255, 200)); - Traffic_PopupFontColor = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_FONTCOLOR, RGB(0, 0, 0)); - Traffic_Notify_time_value = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_TIME_VALUE, 10); - Traffic_Notify_size_value = db_get_w(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_SIZE_VALUE, 100); - - // popup timeout - Traffic_PopupTimeoutDefault = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_DEFAULT, 1); - Traffic_PopupTimeoutValue = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_VALUE, 5); - - // Формат счётчика для каждого активного протокола - if (db_get_ws(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_COUNTER_FORMAT, &dbv) == 0) { - if (mir_wstrlen(dbv.ptszVal) > 0) - mir_wstrncpy(Traffic_CounterFormat, dbv.ptszVal, _countof(Traffic_CounterFormat)); - // - db_free(&dbv); - } - else //defaults here - { - mir_wstrcpy(Traffic_CounterFormat, tszFormat); - } - - // Формат всплывающих подсказок - if (db_get_ws(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_TOOLTIP_FORMAT, &dbv) == 0) { - if (mir_wstrlen(dbv.ptszVal) > 0) - mir_wstrncpy(Traffic_TooltipFormat, dbv.ptszVal, _countof(Traffic_TooltipFormat)); - // - db_free(&dbv); - } - else //defaults here - { - mir_wstrcpy(Traffic_TooltipFormat, L"Traffic Counter"); - } - - Traffic_AdditionSpace = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_ADDITION_SPACE, 0); - - // Счётчик времени онлайна - OverallInfo.Total.Timer = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_TOTAL_ONLINE_TIME, 0); - - //register traffic font - TrafficFontID.cbSize = sizeof(FontIDW); - mir_wstrcpy(TrafficFontID.group, LPGENW("Traffic counter")); - mir_wstrcpy(TrafficFontID.name, LPGENW("Font")); - mir_strcpy(TrafficFontID.dbSettingsGroup, TRAFFIC_SETTINGS_GROUP); - mir_strcpy(TrafficFontID.prefix, "Font"); - TrafficFontID.flags = FIDF_DEFAULTVALID | FIDF_SAVEPOINTSIZE; - TrafficFontID.deffontsettings.charset = DEFAULT_CHARSET; - TrafficFontID.deffontsettings.colour = GetSysColor(COLOR_BTNTEXT); - TrafficFontID.deffontsettings.size = 12; - TrafficFontID.deffontsettings.style = 0; - mir_wstrcpy(TrafficFontID.deffontsettings.szFace, L"Arial"); - TrafficFontID.order = 0; - Font_RegisterW(&TrafficFontID); - - // Регистрируем цвет фона - TrafficBackgroundColorID.cbSize = sizeof(ColourIDW); - mir_wstrcpy(TrafficBackgroundColorID.group, LPGENW("Traffic counter")); - mir_wstrcpy(TrafficBackgroundColorID.name, LPGENW("Font")); - mir_strcpy(TrafficBackgroundColorID.dbSettingsGroup, TRAFFIC_SETTINGS_GROUP); - mir_strcpy(TrafficBackgroundColorID.setting, "FontBkColor"); - TrafficBackgroundColorID.defcolour = GetSysColor(COLOR_BTNFACE); - Colour_RegisterW(&TrafficBackgroundColorID); - - HookEvent(ME_FONT_RELOAD, UpdateFonts); - - // Добавляем поддержку плагина Variables - RegisterVariablesTokens(); - - CreateServiceFunction("TrafficCounter/ShowHide", MenuCommand_TrafficShowHide); - // Регистрируем горячую клавишу для показа/скрытия фрейма - { - HOTKEYDESC hkd = {}; - hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL | HOTKEYF_SHIFT, 'T'); - hkd.szSection.a = "Traffic Counter"; - hkd.szDescription.a = LPGEN("Show/Hide frame"); - hkd.pszName = "TC_Show_Hide"; - hkd.pszService = "TrafficCounter/ShowHide"; - Hotkey_Register(&hkd); - } - - // Добавляем пункт в главное меню. - if (unOptions.ShowMainMenuItem) - Traffic_AddMainMenuItem(); - - // Создаём контекстное меню. - if (TrafficPopupMenu = CreatePopupMenu()) { - AppendMenu(TrafficPopupMenu, MF_STRING, POPUPMENU_HIDE, TranslateT("Hide traffic window")); - AppendMenu(TrafficPopupMenu, MF_STRING, POPUPMENU_CLEAR_NOW, TranslateT("Clear the current (Now:) value")); - } - - // Регистрируем обработчики событий Netlib - HookEvent(ME_NETLIB_FASTRECV, TrafficRecv); - HookEvent(ME_NETLIB_FASTSEND, TrafficSend); - - CreateTrafficWindow(pcli->hwndContactList); - UpdateFonts(0, 0); //Load and create fonts here - - return 0; -} - void SaveSettings(BYTE OnlyCnt) { unsigned short int i; @@ -423,7 +276,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1; RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32; RGB32BitsBITMAPINFO.bmiHeader.biCompression = BI_RGB; - + HBITMAP hbmp = CreateDIBSection(nullptr, &RGB32BitsBITMAPINFO, DIB_RGB_COLORS, nullptr, nullptr, 0); HBITMAP oldbmp = (HBITMAP)SelectObject(hdc, hbmp); @@ -757,7 +610,7 @@ LRESULT CALLBACK TrafficCounterWndProc_MW(HWND hwnd, UINT msg, WPARAM wParam, LP int i; // switch (msg) { - case (WM_USER + 697) : + case (WM_USER + 697): if (lParam == 666) DestroyWindow(hwnd); break; @@ -987,9 +840,9 @@ void CreateTrafficWindow(HWND hCluiWnd) wcx.lpfnWndProc = TrafficCounterWndProc_MW; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; - wcx.hInstance = hInst; + wcx.hInstance = g_plugin.getInst(); wcx.hIcon = nullptr; - wcx.hCursor = LoadCursor(hInst, IDC_ARROW); + wcx.hCursor = LoadCursor(g_plugin.getInst(), IDC_ARROW); wcx.hbrBackground = nullptr; wcx.lpszMenuName = nullptr; wcx.lpszClassName = TRAFFIC_COUNTER_WINDOW_CLASS; @@ -998,7 +851,7 @@ void CreateTrafficWindow(HWND hCluiWnd) TrafficHwnd = CreateWindowEx(WS_EX_TOOLWINDOW, TRAFFIC_COUNTER_WINDOW_CLASS, TRAFFIC_COUNTER_WINDOW_CLASS, WS_CHILDWINDOW | WS_CLIPCHILDREN, - 0, 0, 0, 0, hCluiWnd, nullptr, hInst, nullptr); + 0, 0, 0, 0, hCluiWnd, nullptr, g_plugin.getInst(), nullptr); if (ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) { // Готовимся создавать фрейм @@ -1089,30 +942,29 @@ void NotifyOnRecv(void) void CreateProtocolList(void) { - int i; - PROTOACCOUNT **acc; - // - Proto_EnumAccounts(&NumberOfAccounts, &acc); - // - ProtoList = (PROTOLIST*)mir_alloc(sizeof(PROTOLIST)*(NumberOfAccounts)); - // - for (i = 0; i < NumberOfAccounts; i++) { - ProtoList[i].name = mir_strdup(acc[i]->szModuleName); - ProtoList[i].tszAccountName = mir_wstrdup(acc[i]->tszAccountName); + auto &accs = Accounts(); + + NumberOfAccounts = accs.getCount(); + ProtoList = (PROTOLIST*)mir_alloc(sizeof(PROTOLIST)*NumberOfAccounts); + + int i = 0; + for (auto &pa : accs) { + auto &p = ProtoList[i++]; + p.name = mir_strdup(pa->szModuleName); + p.tszAccountName = mir_wstrdup(pa->tszAccountName); - ProtoList[i].Flags = db_get_b(NULL, ProtoList[i].name, SETTINGS_PROTO_FLAGS, 3); - ProtoList[i].CurrentRecvTraffic = - ProtoList[i].CurrentSentTraffic = - ProtoList[i].Session.Timer = 0; + p.Flags = db_get_b(NULL, p.name, SETTINGS_PROTO_FLAGS, 3); + p.CurrentRecvTraffic = p.CurrentSentTraffic = p.Session.Timer = 0; - ProtoList[i].Enabled = acc[i]->bIsEnabled; - ProtoList[i].State = 0; + p.Enabled = pa->IsEnabled(); + p.State = 0; Stat_ReadFile(i); - ProtoList[i].StartIndex = ProtoList[i].NumberOfRecords - 1; - ProtoList[i].StartIncoming = ProtoList[i].AllStatistics[ProtoList[i].StartIndex].Incoming; - ProtoList[i].StartOutgoing = ProtoList[i].AllStatistics[ProtoList[i].StartIndex].Outgoing; - } // цикл по аккаунтам + p.StartIndex = p.NumberOfRecords - 1; + p.StartIncoming = p.AllStatistics[p.StartIndex].Incoming; + p.StartOutgoing = p.AllStatistics[p.StartIndex].Outgoing; + } + // Начальные значения для суммарной информации. OverallInfo.Session.Timer = OverallInfo.Total.Timer = 0; } @@ -1130,33 +982,6 @@ void DestroyProtocolList(void) mir_free(ProtoList); } -int ProtocolAckHook(WPARAM, LPARAM lParam) -{ - ACKDATA *pAck = (ACKDATA*)lParam; - - if (ACKTYPE_STATUS == pAck->type) { - if (ID_STATUS_OFFLINE == pAck->lParam) { - for (int i = 0; i < NumberOfAccounts; i++) { - if (!ProtoList[i].name) continue; - if (!mir_strcmp(ProtoList[i].name, pAck->szModule)) { - ProtocolIsOffLine(i); - break; - } - } - } - else { - if ((pAck->lParam >= ID_STATUS_ONLINE) && (pAck->lParam <= ID_STATUS_OUTTOLUNCH)) { - for (int i = 0; i < NumberOfAccounts; i++) - if (!mir_strcmp(ProtoList[i].name, pAck->szModule)) { - ProtocolIsOnLine(i); - break; - } - } - } - } - return 0; -} - int UpdateFonts(WPARAM, LPARAM) { LOGFONT logfont; @@ -1197,8 +1022,39 @@ unsigned short int TrafficWindowHeight(void) return (MaxWndHeight < TrafficFontHeight) ? 0 : MaxWndHeight; } +///////////////////////////////////////////////////////////////////////////////////////// + +static int ProtocolAckHook(WPARAM, LPARAM lParam) +{ + ACKDATA *pAck = (ACKDATA*)lParam; + + if (ACKTYPE_STATUS == pAck->type) { + if (ID_STATUS_OFFLINE == pAck->lParam) { + for (int i = 0; i < NumberOfAccounts; i++) { + if (!ProtoList[i].name) continue; + if (!mir_strcmp(ProtoList[i].name, pAck->szModule)) { + ProtocolIsOffLine(i); + break; + } + } + } + else { + if ((pAck->lParam >= ID_STATUS_ONLINE) && (pAck->lParam <= ID_STATUS_OUTTOLUNCH)) { + for (int i = 0; i < NumberOfAccounts; i++) + if (!mir_strcmp(ProtoList[i].name, pAck->szModule)) { + ProtocolIsOnLine(i); + break; + } + } + } + } + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// // Функция вносит изменения в ProtoList при коммутации аккаунтов -int OnAccountsListChange(WPARAM wParam, LPARAM lParam) + +static int OnAccountsListChange(WPARAM wParam, LPARAM lParam) { PROTOACCOUNT *acc = (PROTOACCOUNT*)lParam; @@ -1219,3 +1075,147 @@ int OnAccountsListChange(WPARAM wParam, LPARAM lParam) UpdateTrafficWindowSize(); return 0; } + +///////////////////////////////////////////////////////////////////////////////////////// + +static int TrafficCounterModulesLoaded(WPARAM, LPARAM) +{ + DBVARIANT dbv; + + CreateProtocolList(); + ModuleLoad(0, 0); + + // Читаем флаги + unOptions.Flags = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_WHAT_DRAW, 0x0882); + Stat_SelAcc = db_get_w(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_STAT_ACC_OPT, 0x01); + + // settings for notification + Traffic_PopupBkColor = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_BKCOLOR, RGB(200, 255, 200)); + Traffic_PopupFontColor = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_FONTCOLOR, RGB(0, 0, 0)); + Traffic_Notify_time_value = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_TIME_VALUE, 10); + Traffic_Notify_size_value = db_get_w(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_SIZE_VALUE, 100); + + // popup timeout + Traffic_PopupTimeoutDefault = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_DEFAULT, 1); + Traffic_PopupTimeoutValue = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_VALUE, 5); + + // Формат счётчика для каждого активного протокола + if (db_get_ws(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_COUNTER_FORMAT, &dbv) == 0) { + if (mir_wstrlen(dbv.ptszVal) > 0) + mir_wstrncpy(Traffic_CounterFormat, dbv.ptszVal, _countof(Traffic_CounterFormat)); + // + db_free(&dbv); + } + else //defaults here + { + mir_wstrcpy(Traffic_CounterFormat, tszFormat); + } + + // Формат всплывающих подсказок + if (db_get_ws(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_TOOLTIP_FORMAT, &dbv) == 0) { + if (mir_wstrlen(dbv.ptszVal) > 0) + mir_wstrncpy(Traffic_TooltipFormat, dbv.ptszVal, _countof(Traffic_TooltipFormat)); + // + db_free(&dbv); + } + else //defaults here + { + mir_wstrcpy(Traffic_TooltipFormat, L"Traffic Counter"); + } + + Traffic_AdditionSpace = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_ADDITION_SPACE, 0); + + // Счётчик времени онлайна + OverallInfo.Total.Timer = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_TOTAL_ONLINE_TIME, 0); + + //register traffic font + TrafficFontID.cbSize = sizeof(FontIDW); + mir_wstrcpy(TrafficFontID.group, LPGENW("Traffic counter")); + mir_wstrcpy(TrafficFontID.name, LPGENW("Font")); + mir_strcpy(TrafficFontID.dbSettingsGroup, TRAFFIC_SETTINGS_GROUP); + mir_strcpy(TrafficFontID.prefix, "Font"); + TrafficFontID.flags = FIDF_DEFAULTVALID | FIDF_SAVEPOINTSIZE; + TrafficFontID.deffontsettings.charset = DEFAULT_CHARSET; + TrafficFontID.deffontsettings.colour = GetSysColor(COLOR_BTNTEXT); + TrafficFontID.deffontsettings.size = 12; + TrafficFontID.deffontsettings.style = 0; + mir_wstrcpy(TrafficFontID.deffontsettings.szFace, L"Arial"); + TrafficFontID.order = 0; + Font_RegisterW(&TrafficFontID); + + // Регистрируем цвет фона + TrafficBackgroundColorID.cbSize = sizeof(ColourIDW); + mir_wstrcpy(TrafficBackgroundColorID.group, LPGENW("Traffic counter")); + mir_wstrcpy(TrafficBackgroundColorID.name, LPGENW("Font")); + mir_strcpy(TrafficBackgroundColorID.dbSettingsGroup, TRAFFIC_SETTINGS_GROUP); + mir_strcpy(TrafficBackgroundColorID.setting, "FontBkColor"); + TrafficBackgroundColorID.defcolour = GetSysColor(COLOR_BTNFACE); + Colour_RegisterW(&TrafficBackgroundColorID); + + HookEvent(ME_FONT_RELOAD, UpdateFonts); + + // Добавляем поддержку плагина Variables + RegisterVariablesTokens(); + + CreateServiceFunction("TrafficCounter/ShowHide", MenuCommand_TrafficShowHide); + // Регистрируем горячую клавишу для показа/скрытия фрейма + { + HOTKEYDESC hkd = {}; + hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL | HOTKEYF_SHIFT, 'T'); + hkd.szSection.a = "Traffic Counter"; + hkd.szDescription.a = LPGEN("Show/Hide frame"); + hkd.pszName = "TC_Show_Hide"; + hkd.pszService = "TrafficCounter/ShowHide"; + Hotkey_Register(&hkd); + } + + // Добавляем пункт в главное меню. + if (unOptions.ShowMainMenuItem) + Traffic_AddMainMenuItem(); + + // Создаём контекстное меню. + if (TrafficPopupMenu = CreatePopupMenu()) { + AppendMenu(TrafficPopupMenu, MF_STRING, POPUPMENU_HIDE, TranslateT("Hide traffic window")); + AppendMenu(TrafficPopupMenu, MF_STRING, POPUPMENU_CLEAR_NOW, TranslateT("Clear the current (Now:) value")); + } + + // Регистрируем обработчики событий Netlib + HookEvent(ME_NETLIB_FASTRECV, TrafficRecv); + HookEvent(ME_NETLIB_FASTSEND, TrafficSend); + + CreateTrafficWindow(pcli->hwndContactList); + UpdateFonts(0, 0); //Load and create fonts here + return 0; +} + +extern "C" int __declspec(dllexport) Load(void) +{ + // Получаем дескриптор языкового пакета. + mir_getLP(&pluginInfoEx); + pcli = Clist_GetInterface(); + + HookEvent(ME_OPT_INITIALISE, TrafficCounterOptInitialise); + HookEvent(ME_SYSTEM_MODULESLOADED, TrafficCounterModulesLoaded); + HookEvent(ME_PROTO_ACK, ProtocolAckHook); + HookEvent(ME_PROTO_ACCLISTCHANGED, OnAccountsListChange); + HookEvent(ME_SYSTEM_PRESHUTDOWN, TrafficCounterShutdown); + HookEvent(ME_SYSTEM_MODULELOAD, ModuleLoad); + HookEvent(ME_SYSTEM_MODULEUNLOAD, ModuleLoad); + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" int __declspec(dllexport) Unload(void) +{ + // Удаляем шрифт. + if (Traffic_h_font) { + DeleteObject(Traffic_h_font); + Traffic_h_font = nullptr; + } + + // Убиваем все рабочие данные. + DestroyProtocolList(); + return 0; +} diff --git a/plugins/TrafficCounter/src/TrafficCounter.h b/plugins/TrafficCounter/src/TrafficCounter.h index a11f4178be..46d24e00d9 100644 --- a/plugins/TrafficCounter/src/TrafficCounter.h +++ b/plugins/TrafficCounter/src/TrafficCounter.h @@ -59,20 +59,20 @@ int TrafficSend(WPARAM wParam,LPARAM lParam); /*====== ФУНКЦИИ МОДУЛЯ =====*/ int TrafficCounterOptInitialise(WPARAM wParam,LPARAM lParam); -int TrafficCounterModulesLoaded(WPARAM wParam,LPARAM lParam); int TrafficCounterShutdown(WPARAM wParam,LPARAM lParam); int ModuleLoad(WPARAM wParam, LPARAM lParam); void SaveSettings(BYTE); void CreateTrafficWindow(HWND); + //popup void UpdateNotifyTimer(void); void NotifyOnSend(void); void NotifyOnRecv(void); + //time counter -int ProtocolAckHook(WPARAM wParam,LPARAM lParam); void CreateProtocolList(void); void DestroyProtocolList(void); -int OnAccountsListChange(WPARAM wParam, LPARAM lParam); + //font service suppot int UpdateFonts(WPARAM wParam, LPARAM lParam); void UpdateTrafficWindowSize(void); diff --git a/plugins/TrafficCounter/src/options.cpp b/plugins/TrafficCounter/src/options.cpp index 16cfb39ab7..1da2a9ee09 100644 --- a/plugins/TrafficCounter/src/options.cpp +++ b/plugins/TrafficCounter/src/options.cpp @@ -344,7 +344,7 @@ int TrafficCounterOptInitialise(WPARAM wParam, LPARAM) // Main options page OPTIONSDIALOGPAGE odp = { 0 }; odp.position = 900000000; - odp.hInstance = hInst; + odp.hInstance = g_plugin.getInst(); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_TRAFFIC); odp.szGroup.a = LPGEN("Services"); odp.szTab.a = LPGEN("Options"); diff --git a/plugins/TrafficCounter/src/stdafx.h b/plugins/TrafficCounter/src/stdafx.h index 728a2a7ecc..fc5fb36f37 100644 --- a/plugins/TrafficCounter/src/stdafx.h +++ b/plugins/TrafficCounter/src/stdafx.h @@ -27,7 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include -#define __NO_CMPLUGIN_NEEDED #include #include #include @@ -53,6 +52,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "statistics.h" #include "TrafficCounter.h" +struct CMPlugin : public PLUGIN +{ + CMPlugin() : + PLUGIN(TRAFFIC_SETTINGS_GROUP) + {} +}; + #pragma pack(push) #pragma pack(1) typedef struct @@ -142,8 +148,6 @@ typedef union }; } uTCFLAGS; -extern HINSTANCE hInst; - extern HWND TrafficHwnd; extern PROTOLIST *ProtoList; extern uTCFLAGS unOptions; diff --git a/plugins/TrafficCounter/src/vars.cpp b/plugins/TrafficCounter/src/vars.cpp index fdbb22892b..54f28fc23f 100644 --- a/plugins/TrafficCounter/src/vars.cpp +++ b/plugins/TrafficCounter/src/vars.cpp @@ -1,5 +1,5 @@ /* -Traffic Counter plugin for Miranda IM +Traffic Counter plugin for Miranda IM Copyright 2007-2011 Mironych. This program is free software; you can redistribute it and/or @@ -30,33 +30,26 @@ static wchar_t* GetTraffic(ARGUMENTSINFO *ai) if (ai->argc != 5) return nullptr; - if (!mir_wstrcmp(ai->targv[1], L"overall")) - { + if (!mir_wstrcmp(ai->targv[1], L"overall")) { tmpsn = OverallInfo.CurrentSentTraffic; tmprn = OverallInfo.CurrentRecvTraffic; tmpst = OverallInfo.TotalSentTraffic; tmprt = OverallInfo.TotalRecvTraffic; } - else - if (!mir_wstrcmp(ai->targv[1], L"summary")) - { + else if (!mir_wstrcmp(ai->targv[1], L"summary")) { for (ed = 0; ed < NumberOfAccounts; ed++) - if (ProtoList[ed].Visible) - { + if (ProtoList[ed].Visible) { tmpsn += ProtoList[ed].CurrentSentTraffic; tmprn += ProtoList[ed].CurrentRecvTraffic; tmpst += ProtoList[ed].TotalSentTraffic; tmprt += ProtoList[ed].TotalRecvTraffic; } } - else - { // Ищем индекс протокола, переданного первым аргументом - for (tmp = ed = 0; ed < NumberOfAccounts; ed++) - { + else { // Ищем индекс протокола, переданного первым аргументом + for (tmp = ed = 0; ed < NumberOfAccounts; ed++) { if (!ProtoList[ed].name) continue; wchar_t *buf = mir_a2u(ProtoList[ed].name); - if (!mir_wstrcmp(buf, ai->targv[1])) - { + if (!mir_wstrcmp(buf, ai->targv[1])) { tmpsn = ProtoList[ed].CurrentSentTraffic; tmprn = ProtoList[ed].CurrentRecvTraffic; tmpst = ProtoList[ed].TotalSentTraffic; @@ -68,35 +61,34 @@ static wchar_t* GetTraffic(ARGUMENTSINFO *ai) if (tmp != 0xAA) return nullptr; } - if (!mir_wstrcmp(ai->targv[2], L"now")) - { + if (!mir_wstrcmp(ai->targv[2], L"now")) { if (!mir_wstrcmp(ai->targv[3], L"sent")) tmp = tmpsn; else - if (!mir_wstrcmp(ai->targv[3], L"received")) tmp = tmprn; - else - if (!mir_wstrcmp(ai->targv[3], L"both")) tmp = tmprn + tmpsn; - else return nullptr; + if (!mir_wstrcmp(ai->targv[3], L"received")) tmp = tmprn; + else + if (!mir_wstrcmp(ai->targv[3], L"both")) tmp = tmprn + tmpsn; + else return nullptr; } - else - if (!mir_wstrcmp(ai->targv[2], L"total")) - { + else if (!mir_wstrcmp(ai->targv[2], L"total")) { if (!mir_wstrcmp(ai->targv[3], L"sent")) tmp = tmpst; else - if (!mir_wstrcmp(ai->targv[3], L"received")) tmp = tmprt; - else - if (!mir_wstrcmp(ai->targv[3], L"both")) tmp = tmprt + tmpst; - else return nullptr; + if (!mir_wstrcmp(ai->targv[3], L"received")) tmp = tmprt; + else + if (!mir_wstrcmp(ai->targv[3], L"both")) tmp = tmprt + tmpst; + else return nullptr; } else return nullptr; - if (!mir_wstrcmp(ai->targv[4], L"b")) ed = 0; + if (!mir_wstrcmp(ai->targv[4], L"b")) + ed = 0; + else if (!mir_wstrcmp(ai->targv[4], L"k")) + ed = 1; + else if (!mir_wstrcmp(ai->targv[4], L"m")) + ed = 2; + else if (!mir_wstrcmp(ai->targv[4], L"d")) + ed = 3; else - if (!mir_wstrcmp(ai->targv[4], L"k")) ed = 1; - else - if (!mir_wstrcmp(ai->targv[4], L"m")) ed = 2; - else - if (!mir_wstrcmp(ai->targv[4], L"d")) ed = 3; - else return nullptr; + return nullptr; // Получаем форматированную строку и возвращаем указатель на неё. // Сначала узнаем размер буфера. @@ -113,30 +105,29 @@ static wchar_t* GetTraffic(ARGUMENTSINFO *ai) static wchar_t* GetTime(ARGUMENTSINFO *ai) { BYTE ed, flag; - DWORD Duration; + DWORD Duration = 0; if (ai->argc != 4) return nullptr; // Ищем индекс протокола, переданного первым аргументом - for (flag = ed = 0; ed < NumberOfAccounts; ed++) - { + for (flag = ed = 0; ed < NumberOfAccounts; ed++) { wchar_t *buf; if (!ProtoList[ed].name) continue; buf = mir_a2u(ProtoList[ed].name); - if (!mir_wstrcmp(buf, ai->targv[1])) - { + if (!mir_wstrcmp(buf, ai->targv[1])) { flag = 0xAA; if (!mir_wstrcmp(ai->targv[2], L"now")) Duration = ProtoList[ed].Session.Timer; else if (!mir_wstrcmp(ai->targv[2], L"total")) Duration = ProtoList[ed].Total.Timer; - else flag = 0; + else + flag = 0; break; } mir_free(buf); } - if ( (flag != 0xAA) && !mir_wstrcmp(ai->targv[1], L"summary") ) - { + + if ((flag != 0xAA) && !mir_wstrcmp(ai->targv[1], L"summary")) { flag = 0xAA; if (!mir_wstrcmp(ai->targv[2], L"now")) Duration = OverallInfo.Session.Timer; @@ -144,25 +135,27 @@ static wchar_t* GetTime(ARGUMENTSINFO *ai) Duration = OverallInfo.Total.Timer; else flag = 0; } - - if (flag != 0xAA) return nullptr; + + if (flag != 0xAA) + return nullptr; // Получаем форматированную строку и возвращаем указатель на неё. // Сначала узнаем размер буфера. size_t l = GetDurationFormatM(Duration, ai->targv[3], nullptr, 0); wchar_t *res = (wchar_t*)mir_alloc(l * sizeof(wchar_t)); - if (!res) return nullptr; + if (!res) + return nullptr; + GetDurationFormatM(Duration, ai->targv[3], res, l); - return res; } void RegisterVariablesTokens(void) { TOKENREGISTER trs; - + if (!bVariablesExists) return; - + memset(&trs, 0, sizeof(trs)); trs.cbSize = sizeof(TOKENREGISTER); -- cgit v1.2.3