From e305b0a6143716dba6c11fd1a4c6d60e6ed27fd6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 4 Mar 2013 11:36:46 +0000 Subject: - fix for the crash on exit; - options moved to the separate file git-svn-id: http://svn.miranda-ng.org/main/trunk@3881 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TrafficCounter/TrafficCounter_10.vcxproj | 1 + .../TrafficCounter_10.vcxproj.filters | 3 + plugins/TrafficCounter/TrafficCounter_11.vcxproj | 1 + .../TrafficCounter_11.vcxproj.filters | 3 + plugins/TrafficCounter/src/TrafficCounter.cpp | 431 +-------------------- plugins/TrafficCounter/src/TrafficCounter.h | 25 ++ plugins/TrafficCounter/src/options.cpp | 406 +++++++++++++++++++ plugins/TrafficCounter/src/statistics.cpp | 3 - plugins/TrafficCounter/src/vars.h | 1 - 9 files changed, 457 insertions(+), 417 deletions(-) create mode 100644 plugins/TrafficCounter/src/options.cpp (limited to 'plugins/TrafficCounter') diff --git a/plugins/TrafficCounter/TrafficCounter_10.vcxproj b/plugins/TrafficCounter/TrafficCounter_10.vcxproj index a7ad35cb85..479cbce7bf 100644 --- a/plugins/TrafficCounter/TrafficCounter_10.vcxproj +++ b/plugins/TrafficCounter/TrafficCounter_10.vcxproj @@ -522,6 +522,7 @@ + diff --git a/plugins/TrafficCounter/TrafficCounter_10.vcxproj.filters b/plugins/TrafficCounter/TrafficCounter_10.vcxproj.filters index c5186361dc..a184e52246 100644 --- a/plugins/TrafficCounter/TrafficCounter_10.vcxproj.filters +++ b/plugins/TrafficCounter/TrafficCounter_10.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + diff --git a/plugins/TrafficCounter/TrafficCounter_11.vcxproj b/plugins/TrafficCounter/TrafficCounter_11.vcxproj index 976f9378ed..110b4fd61e 100644 --- a/plugins/TrafficCounter/TrafficCounter_11.vcxproj +++ b/plugins/TrafficCounter/TrafficCounter_11.vcxproj @@ -526,6 +526,7 @@ + diff --git a/plugins/TrafficCounter/TrafficCounter_11.vcxproj.filters b/plugins/TrafficCounter/TrafficCounter_11.vcxproj.filters index c5186361dc..a184e52246 100644 --- a/plugins/TrafficCounter/TrafficCounter_11.vcxproj.filters +++ b/plugins/TrafficCounter/TrafficCounter_11.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + diff --git a/plugins/TrafficCounter/src/TrafficCounter.cpp b/plugins/TrafficCounter/src/TrafficCounter.cpp index 76a235fd10..b2c6bce1c7 100644 --- a/plugins/TrafficCounter/src/TrafficCounter.cpp +++ b/plugins/TrafficCounter/src/TrafficCounter.cpp @@ -42,7 +42,7 @@ TCHAR* TRAFFIC_COUNTER_WINDOW_CLASS = _T("TrafficCounterWnd"); /*-------------------------------------------------------------------------------------------------------------------*/ //TRAFFIC COUNTER /*-------------------------------------------------------------------------------------------------------------------*/ -OPTTREE_OPTION *pOptions; // Через этот указатель модуль opttree.c может добраться до списка опций. + WORD notify_send_size = 0; WORD notify_recv_size = 0; // @@ -50,10 +50,10 @@ WORD notify_recv_size = 0; COLORREF Traffic_BkColor,Traffic_FontColor; //notify -int Traffic_PopupBkColor; -int Traffic_PopupFontColor; +int Traffic_PopupBkColor; +int Traffic_PopupFontColor; char Traffic_Notify_time_value; -short int Traffic_Notify_size_value; +int Traffic_Notify_size_value; char Traffic_PopupTimeoutDefault; char Traffic_PopupTimeoutValue; @@ -66,9 +66,6 @@ HANDLE Traffic_FrameID = NULL; char Traffic_AdditionSpace; -HANDLE h_OnRecv, h_OnSend; -HANDLE h_FontReload; - HFONT Traffic_h_font = NULL; HMENU TrafficPopupMenu = NULL; HGENMENU hTrafficMainMenuItem = NULL; @@ -95,9 +92,7 @@ POINT TooltipPosition; BOOL UseKeyColor; COLORREF KeyColor; -// Внутренние функции модуля. -void Traffic_AddMainMenuItem(void); - +//--------------------------------------------------------------------------------------------- PLUGININFOEX pluginInfoEx = { @@ -145,6 +140,14 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void) { + // Удаляем шрифт. + if (Traffic_h_font) { + DeleteObject(Traffic_h_font); + Traffic_h_font = NULL; + } + + // Убиваем все рабочие данные. + DestroyProtocolList(); return 0; } @@ -153,11 +156,6 @@ int TrafficCounterShutdown(WPARAM wParam, LPARAM lParam) KillTimer(TrafficHwnd, TIMER_REDRAW); KillTimer(TrafficHwnd, TIMER_NOTIFY_TICK); - // Отказываемся от обработки событий. - UnhookEvent(h_FontReload); - UnhookEvent(h_OnRecv); - UnhookEvent(h_OnSend); - SaveSettings(0); // Удаляем пункт главного меню. @@ -174,26 +172,13 @@ int TrafficCounterShutdown(WPARAM wParam, LPARAM lParam) } // Разрегистрируем процедуру отрисовки фрейма. CallService(MS_SKINENG_REGISTERPAINTSUB, (WPARAM)TrafficHwnd, (LPARAM)NULL); + // Удаляем фрейм. if( (ServiceExists(MS_CLIST_FRAMES_REMOVEFRAME)) && Traffic_FrameID ) { CallService(MS_CLIST_FRAMES_REMOVEFRAME, (WPARAM)Traffic_FrameID, 0); Traffic_FrameID = NULL; } - // Разрегистрируем горячую клавишу. - CallService(MS_HOTKEY_UNREGISTER, 0, (LPARAM)"TC_Show_Hide"); - // Разрегистрируем функцию переключения видимости окна. - DestroyServiceFunction(MenuCommand_TrafficShowHide); - // Удаляем шрифт. - if (Traffic_h_font) - { - DeleteObject(Traffic_h_font); - Traffic_h_font = NULL; - } - - // Убиваем все рабочие данные. - DestroyProtocolList(); - return 0; } @@ -288,7 +273,7 @@ int TrafficCounterModulesLoaded(WPARAM wParam, LPARAM lParam) TrafficBackgroundColorID.defcolour = GetSysColor(COLOR_BTNFACE); ColourRegisterT(&TrafficBackgroundColorID); - h_FontReload = HookEvent(ME_FONT_RELOAD, UpdateFonts); + HookEvent(ME_FONT_RELOAD, UpdateFonts); // Добавляем поддержку плагина Variables RegisterVariablesTokens(); @@ -318,8 +303,8 @@ int TrafficCounterModulesLoaded(WPARAM wParam, LPARAM lParam) } // Регистрируем обработчики событий Netlib - h_OnRecv = HookEvent(ME_NETLIB_FASTRECV, TrafficRecv); - h_OnSend = HookEvent(ME_NETLIB_FASTSEND, TrafficSend); + HookEvent(ME_NETLIB_FASTRECV, TrafficRecv); + HookEvent(ME_NETLIB_FASTSEND, TrafficSend); CreateTrafficWindow((HWND)CallService(MS_CLUI_GETHWND, 0, 0)); UpdateFonts(0, 0); //Load and create fonts here @@ -327,384 +312,6 @@ int TrafficCounterModulesLoaded(WPARAM wParam, LPARAM lParam) return 0; } -static INT_PTR CALLBACK DlgProcPopupsTraffic(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) - { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - // - CheckDlgButton(hwndDlg,IDC_NOTIFYSIZE,(unOptions.NotifyBySize) ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hwndDlg,IDC_ENOTIFYSIZE,Traffic_Notify_size_value,0); - SendDlgItemMessage(hwndDlg,IDC_ENOTIFYSIZE,EM_LIMITTEXT,4,0); - if (!unOptions.NotifyBySize) EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYSIZE),0); - CheckDlgButton(hwndDlg,IDC_NOTIFYTIME,(unOptions.NotifyByTime) ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(hwndDlg,IDC_ENOTIFYTIME,Traffic_Notify_time_value,0); - SendDlgItemMessage(hwndDlg,IDC_ENOTIFYTIME,EM_LIMITTEXT,2,0); - if (!unOptions.NotifyByTime) EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYTIME),0); - //colors - SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETDEFAULTCOLOUR,0,RGB(200,255,200)); - SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETCOLOUR,0,Traffic_PopupBkColor); - SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETDEFAULTCOLOUR,0,RGB(0,0,0)); - SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETCOLOUR,0,Traffic_PopupFontColor); - //timeout - CheckDlgButton(hwndDlg,IDC_RADIO_FROMPOPUP,(Traffic_PopupTimeoutDefault != 0) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg,IDC_RADIO_CUSTOM,(Traffic_PopupTimeoutDefault == 0) ? BST_CHECKED : BST_UNCHECKED); - EnableWindow(GetDlgItem(hwndDlg,IDC_POPUP_TIMEOUT),Traffic_PopupTimeoutDefault == 0); - SetDlgItemInt(hwndDlg,IDC_POPUP_TIMEOUT,Traffic_PopupTimeoutValue,0); - SendDlgItemMessage(hwndDlg,IDC_POPUP_TIMEOUT,EM_LIMITTEXT,2,0); - - return 0; - - case WM_COMMAND: - switch(LOWORD(wParam)) - { - case IDC_NOTIFYSIZE: - EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYSIZE),IsDlgButtonChecked(hwndDlg,IDC_NOTIFYSIZE)); - break; - - case IDC_ENOTIFYSIZE: - if (HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus()) return 0; - break; - - case IDC_NOTIFYTIME: - EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYTIME),IsDlgButtonChecked(hwndDlg,IDC_NOTIFYTIME)); - break; - - case IDC_ENOTIFYTIME: - if (HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus()) return 0; - break; - - case IDC_RESETCOLORS: - SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETDEFAULTCOLOUR,0,RGB(200,255,200)); - SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETCOLOUR,0,RGB(200,255,200)); - SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETDEFAULTCOLOUR,0,RGB(0,0,0)); - SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETCOLOUR,0,RGB(0,0,0)); - break; - - case IDC_RADIO_FROMPOPUP: - case IDC_RADIO_CUSTOM: - EnableWindow(GetDlgItem(hwndDlg,IDC_POPUP_TIMEOUT),IsDlgButtonChecked(hwndDlg,IDC_RADIO_CUSTOM)); - break; - - case IDC_TEST: - NotifyOnRecv(); - NotifyOnSend(); - return 0; - - } - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - return 0; - - case WM_NOTIFY: - switch(((LPNMHDR)lParam)->idFrom) - { - case 0: - if (((LPNMHDR)lParam)->code == PSN_APPLY ) { - unOptions.NotifyBySize = IsDlgButtonChecked(hwndDlg,IDC_NOTIFYSIZE); - Traffic_Notify_size_value = GetDlgItemInt(hwndDlg,IDC_ENOTIFYSIZE,NULL,0); - unOptions.NotifyByTime = IsDlgButtonChecked(hwndDlg,IDC_NOTIFYTIME); - Traffic_Notify_time_value = GetDlgItemInt(hwndDlg,IDC_ENOTIFYTIME,NULL,0); - // - Traffic_PopupBkColor = SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_GETCOLOUR,0,0); - Traffic_PopupFontColor = SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_GETCOLOUR,0,0); - // - Traffic_PopupTimeoutDefault = IsDlgButtonChecked(hwndDlg,IDC_RADIO_FROMPOPUP); - if (Traffic_PopupTimeoutDefault == 0) Traffic_PopupTimeoutValue = GetDlgItemInt(hwndDlg,IDC_POPUP_TIMEOUT,NULL,0); - // - UpdateNotifyTimer(); - return TRUE; - } - break; - } - break; - } - return 0; -} - -static INT_PTR CALLBACK DlgProcTCOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - WORD i, j, l; - BOOL result; - static BYTE Initialized = 0; - static WORD optionCount = 0; - static OPTTREE_OPTION options[] = - { - {0, LPGENT("Display/") LPGENT("Icon"), - OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawProtoIcon"}, - {0, LPGENT("Display/") LPGENT("Account name"), - OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawProtoName"}, - {0, LPGENT("Display/") LPGENT("Current traffic"), - OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawCurrentTraffic"}, - {0, LPGENT("Display/") LPGENT("Total traffic"), - OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawTotalTraffic"}, - {0, LPGENT("Display/") LPGENT("Current online"), - OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawCurrentTime"}, - {0, LPGENT("Display/") LPGENT("Total online"), - OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawTotalTime"}, - {0, LPGENT("General/") LPGENT("Draw frame as skin element"), - OPTTREE_CHECK, 1, NULL, "DrawFrmAsSkin"}, - {0, LPGENT("General/") LPGENT("Show tooltip in traffic window"), - OPTTREE_CHECK, 1, NULL, "ShowTooltip"}, - {0, LPGENT("General/") LPGENT("\"Toggle traffic counter\" in main menu"), - OPTTREE_CHECK, 1, NULL, "ShowMainMenuItem"}, - // Резервируем место под активные и видимые протоколы - // Максимум 16 позиций видимых и 16 активных - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, - {0, LPGENT("Visible accounts/") LPGENT("Summary traffic for visible accounts"), - OPTTREE_CHECK, 1, NULL, "ShowSummary"}, - {0, LPGENT("Visible accounts/") LPGENT("Overall traffic"), - OPTTREE_CHECK, 1, NULL, "ShowOverall"}, - }; - - if (!Initialized) - { - pOptions = options; - optionCount = SIZEOF(options); - // Если нет Variables, активируем галочки для старого метода рисования - if (!bVariablesExists) - { - for (i = 0; i < 8; i++) options[i].dwFlag = 1; - } - - // Флажки для видимости аккаунтов создаются в любом случае. - for (i = j = 0; (j < NumberOfAccounts) && (i < optionCount) ; i++) - if ((options[i].dwFlag & OPTTREE_INVISIBLE) && !options[i].szSettingName) - { - options[i].szSettingName = (char*)mir_alloc(1 + strlen(ProtoList[j].name)); - strcpy(options[i].szSettingName, ProtoList[j].name); - l = 20 + _tcslen(ProtoList[j].tszAccountName); - options[i].szOptionName = (TCHAR*)mir_alloc(sizeof(TCHAR) * l); - mir_sntprintf(options[i].szOptionName, - l, - _T("Visible accounts/%s"), - ProtoList[j].tszAccountName); - options[i].dwFlag = (ProtoList[j++].Enabled ? 1 : OPTTREE_INVISIBLE) - | OPTTREE_NOTRANSLATE; - } - Initialized = 1; - } - - if (OptTree_ProcessMessage(hwndDlg, msg, wParam, lParam, &result, IDC_APPEARANCEOPTIONS, options, optionCount)) - return result; - - switch (msg) - { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - - SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(15, 0)); - SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETPOS, 0, GetDlgItemInt(hwndDlg, IDC_EDIT_SPACE, NULL, FALSE)); - - //show/hide button - SetDlgItemText(hwndDlg,IDC_BSHOWHIDE,(IsWindowVisible(TrafficHwnd) != 0)? TranslateT("Hide now") : TranslateT("Show now")); - - // Строки формата для счётчиков - EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_COUNTER_FORMAT), bVariablesExists); - SetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_COUNTER_FORMAT), Traffic_CounterFormat); - - // Формат всплывающей подсказки - EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_TOOLTIP_FORMAT), - bTooltipExists); - SetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_TOOLTIP_FORMAT), Traffic_TooltipFormat); - - // Display traffic for current... - SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Day")); - SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Week")); - SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Month")); - SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Year")); - SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_SETCURSEL, unOptions.PeriodForShow, 0); - - // Интервал между строками - SetDlgItemInt(hwndDlg, IDC_EDIT_SPACE, Traffic_AdditionSpace, 0); - SendDlgItemMessage(hwndDlg, IDC_EDIT_SPACE, EM_LIMITTEXT, 2, 0); - - // Appearance - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawProtoIcon, "DrawProtoIcon"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawProtoName, "DrawProtoName"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawCurrentTraffic, "DrawCurrentTraffic"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawTotalTraffic, "DrawTotalTraffic"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawCurrentTimeCounter, "DrawCurrentTime"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawTotalTimeCounter, "DrawTotalTime"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawFrmAsSkin, "DrawFrmAsSkin"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowSummary , "ShowSummary"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowTooltip, "ShowTooltip"); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowMainMenuItem, "ShowMainMenuItem"); - - // Настройки видимости протоколов - for (i = 0; i < NumberOfAccounts; i++) - { - char buffer[32]; - strcpy(buffer, ProtoList[i].name); - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, ProtoList[i].Visible, buffer); - } - OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowOverall, "ShowOverall"); - - EnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_APPLY),FALSE); - return 0; - - case WM_COMMAND: - { - switch(LOWORD(wParam)) - { - case IDC_BSHOWHIDE: - MenuCommand_TrafficShowHide(0, 0); - SetDlgItemText(hwndDlg,IDC_BSHOWHIDE,IsWindowVisible(TrafficHwnd)? TranslateT("Hide now") : TranslateT("Show now")); - return 0; - - case IDC_EDIT_SPACE: - case IDC_EDIT_COUNTER_FORMAT: - case IDC_EDIT_OVERALL_COUNTER_FORMAT: - case IDC_EDIT_TOOLTIP_FORMAT: - if (HIWORD(wParam) == EN_CHANGE) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case IDC_COMBO_AUTO_CLEAR: - if (HIWORD(wParam) == CBN_SELCHANGE) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - break; - } - - case WM_NOTIFY: - { - LPNMHDR lpnmhdr = (LPNMHDR)lParam; - - switch (lpnmhdr->code) - { - case PSN_APPLY: - { - unOptions.PeriodForShow = (char)SendDlgItemMessage(hwndDlg,IDC_COMBO_AUTO_CLEAR,CB_GETCURSEL,0,0); - - // Интервал между строками - Traffic_AdditionSpace = GetDlgItemInt(hwndDlg, IDC_EDIT_SPACE, NULL, 0); - // Настройки Appearance - unOptions.DrawProtoIcon = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawProtoIcon"); - unOptions.DrawProtoName = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawProtoName"); - unOptions.DrawCurrentTraffic = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawCurrentTraffic"); - unOptions.DrawTotalTraffic = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawTotalTraffic"); - unOptions.DrawTotalTimeCounter = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawTotalTime"); - unOptions.DrawCurrentTimeCounter = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawCurrentTime"); - unOptions.DrawTotalTimeCounter = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawTotalTime"); - unOptions.DrawFrmAsSkin = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawFrmAsSkin"); - unOptions.ShowSummary = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowSummary"); - unOptions.ShowTooltip = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowTooltip"); - unOptions.ShowMainMenuItem = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowMainMenuItem"); - - // Настройки видимости протоколов - for (i = 0; i < NumberOfAccounts; i++) - { - char buffer[32]; - strcpy(buffer, ProtoList[i].name); - ProtoList[i].Visible = (BYTE)OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, buffer); - } - unOptions.ShowOverall = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowOverall"); - - // Формат счётчиков - GetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_COUNTER_FORMAT), Traffic_CounterFormat, 512); - // Формат всплывающей подсказки - GetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_TOOLTIP_FORMAT), Traffic_TooltipFormat, 512); - - // Ключевой цвет - UseKeyColor = db_get_b(NULL, "ModernSettings", "UseKeyColor", 1); - KeyColor = db_get_dw(NULL, "ModernSettings", "KeyColor", 0); - - // Перерисовываем фрейм - UpdateTrafficWindowSize(); - - // Если отключается показ пункта главного меню, то удаляем его. - if (!unOptions.ShowMainMenuItem && hTrafficMainMenuItem) - { - CallService(MS_CLIST_REMOVEMAINMENUITEM, (WPARAM)hTrafficMainMenuItem, 0); - hTrafficMainMenuItem = NULL; - } - // Если включается, то создаём. - if (unOptions.ShowMainMenuItem && !hTrafficMainMenuItem) - Traffic_AddMainMenuItem(); - - SaveSettings(0); - // - return TRUE; - } // case PSN_APPLY - } // switch - } - - case WM_DESTROY: - return FALSE; - } - return 0; -} - -int TrafficCounterOptInitialise(WPARAM wParam,LPARAM lParam) -{ - OPTIONSDIALOGPAGE odp={0}; - // Main options page - odp.cbSize=sizeof(odp); - odp.position=900000000; - odp.groupPosition = 1; - odp.hInstance=hInst; - odp.pszTemplate=MAKEINTRESOURCEA(IDD_OPT_TRAFFIC); - odp.pszGroup = LPGEN("Services"); - odp.pszTab = LPGEN("Options"); - odp.pszTitle = LPGEN("Traffic counter"); - odp.pfnDlgProc=DlgProcTCOptions; - odp.flags=ODPF_BOLDGROUPS; - Options_AddPage(wParam, &odp); - - // Statistics options page - odp.pszTemplate=MAKEINTRESOURCEA(IDD_OPT_STATS); - odp.pszTab = LPGEN("Statistics"); - odp.pfnDlgProc = DlgProcOptStatistics; - Options_AddPage(wParam, &odp); - - // Popups option page - if (bPopupExists) - { - odp.groupPosition = 100; - odp.pszTemplate=MAKEINTRESOURCEA(IDD_OPT_TRAFFIC_POPUPS); - odp.pszGroup=LPGEN("PopUps"); - odp.pszTitle=LPGEN("Traffic counter"); - odp.pfnDlgProc=DlgProcPopupsTraffic; - odp.flags=ODPF_BOLDGROUPS; - Options_AddPage(wParam, &odp); - } - - return 0; -} - void SaveSettings(BYTE OnlyCnt) { unsigned short int i; @@ -1602,9 +1209,7 @@ void CreateProtocolList(void) void DestroyProtocolList(void) { - int i; - // - for (i = 0; i < NumberOfAccounts; i++) + for (int i = 0; i < NumberOfAccounts; i++) { Stat_CheckStatistics(i); CloseHandle(ProtoList[i].hFile); diff --git a/plugins/TrafficCounter/src/TrafficCounter.h b/plugins/TrafficCounter/src/TrafficCounter.h index 99666984e4..ba474cf3e0 100644 --- a/plugins/TrafficCounter/src/TrafficCounter.h +++ b/plugins/TrafficCounter/src/TrafficCounter.h @@ -82,5 +82,30 @@ int TrafficCounter_Draw(HWND, HDC); int PaintTrafficCounterWindow(HWND, HDC); // Вспомогательные функции INT_PTR MenuCommand_TrafficShowHide(WPARAM, LPARAM); +void Traffic_AddMainMenuItem(void); + +extern HINSTANCE hInst; + +extern HWND TrafficHwnd; +extern PROTOLIST *ProtoList; +extern uTCFLAGS unOptions; + +extern int Traffic_PopupBkColor; +extern int Traffic_PopupFontColor; +extern char Traffic_Notify_time_value; +extern int Traffic_Notify_size_value; +extern char Traffic_PopupTimeoutDefault; +extern char Traffic_PopupTimeoutValue; +extern char Traffic_AdditionSpace; + +extern TCHAR Traffic_CounterFormat[512]; +extern TCHAR Traffic_TooltipFormat[512]; + +extern BOOL bPopupExists, bVariablesExists, bTooltipExists; + +extern BOOL UseKeyColor; +extern COLORREF KeyColor; + +extern HGENMENU hTrafficMainMenuItem; #endif; diff --git a/plugins/TrafficCounter/src/options.cpp b/plugins/TrafficCounter/src/options.cpp new file mode 100644 index 0000000000..f46d545482 --- /dev/null +++ b/plugins/TrafficCounter/src/options.cpp @@ -0,0 +1,406 @@ +/* +Traffic Counter plugin for Miranda IM +Copyright 2007-2011 Mironych. + +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. +*/ +/* ====================================================================================== +Здесь содержатся переменные и функции для работы со статистикой +Автор: Mironych +=======================================================================================*/ + +#include "commonheaders.h" + +OPTTREE_OPTION *pOptions; // Через этот указатель модуль opttree.c может добраться до списка опций. + +///////////////////////////////////////////////////////////////////////////////////////// + +static INT_PTR CALLBACK DlgProcPopupsTraffic(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + // + CheckDlgButton(hwndDlg,IDC_NOTIFYSIZE,(unOptions.NotifyBySize) ? BST_CHECKED : BST_UNCHECKED); + SetDlgItemInt(hwndDlg,IDC_ENOTIFYSIZE,Traffic_Notify_size_value,0); + SendDlgItemMessage(hwndDlg,IDC_ENOTIFYSIZE,EM_LIMITTEXT,4,0); + if (!unOptions.NotifyBySize) EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYSIZE),0); + CheckDlgButton(hwndDlg,IDC_NOTIFYTIME,(unOptions.NotifyByTime) ? BST_CHECKED : BST_UNCHECKED); + SetDlgItemInt(hwndDlg,IDC_ENOTIFYTIME,Traffic_Notify_time_value,0); + SendDlgItemMessage(hwndDlg,IDC_ENOTIFYTIME,EM_LIMITTEXT,2,0); + if (!unOptions.NotifyByTime) EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYTIME),0); + //colors + SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETDEFAULTCOLOUR,0,RGB(200,255,200)); + SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETCOLOUR,0,Traffic_PopupBkColor); + SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETDEFAULTCOLOUR,0,RGB(0,0,0)); + SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETCOLOUR,0,Traffic_PopupFontColor); + //timeout + CheckDlgButton(hwndDlg,IDC_RADIO_FROMPOPUP,(Traffic_PopupTimeoutDefault != 0) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg,IDC_RADIO_CUSTOM,(Traffic_PopupTimeoutDefault == 0) ? BST_CHECKED : BST_UNCHECKED); + EnableWindow(GetDlgItem(hwndDlg,IDC_POPUP_TIMEOUT),Traffic_PopupTimeoutDefault == 0); + SetDlgItemInt(hwndDlg,IDC_POPUP_TIMEOUT,Traffic_PopupTimeoutValue,0); + SendDlgItemMessage(hwndDlg,IDC_POPUP_TIMEOUT,EM_LIMITTEXT,2,0); + + return 0; + + case WM_COMMAND: + switch(LOWORD(wParam)) + { + case IDC_NOTIFYSIZE: + EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYSIZE),IsDlgButtonChecked(hwndDlg,IDC_NOTIFYSIZE)); + break; + + case IDC_ENOTIFYSIZE: + if (HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus()) return 0; + break; + + case IDC_NOTIFYTIME: + EnableWindow(GetDlgItem(hwndDlg,IDC_ENOTIFYTIME),IsDlgButtonChecked(hwndDlg,IDC_NOTIFYTIME)); + break; + + case IDC_ENOTIFYTIME: + if (HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus()) return 0; + break; + + case IDC_RESETCOLORS: + SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETDEFAULTCOLOUR,0,RGB(200,255,200)); + SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_SETCOLOUR,0,RGB(200,255,200)); + SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETDEFAULTCOLOUR,0,RGB(0,0,0)); + SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_SETCOLOUR,0,RGB(0,0,0)); + break; + + case IDC_RADIO_FROMPOPUP: + case IDC_RADIO_CUSTOM: + EnableWindow(GetDlgItem(hwndDlg,IDC_POPUP_TIMEOUT),IsDlgButtonChecked(hwndDlg,IDC_RADIO_CUSTOM)); + break; + + case IDC_TEST: + NotifyOnRecv(); + NotifyOnSend(); + return 0; + + } + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + return 0; + + case WM_NOTIFY: + switch(((LPNMHDR)lParam)->idFrom) + { + case 0: + if (((LPNMHDR)lParam)->code == PSN_APPLY ) { + unOptions.NotifyBySize = IsDlgButtonChecked(hwndDlg,IDC_NOTIFYSIZE); + Traffic_Notify_size_value = GetDlgItemInt(hwndDlg,IDC_ENOTIFYSIZE,NULL,0); + unOptions.NotifyByTime = IsDlgButtonChecked(hwndDlg,IDC_NOTIFYTIME); + Traffic_Notify_time_value = GetDlgItemInt(hwndDlg,IDC_ENOTIFYTIME,NULL,0); + // + Traffic_PopupBkColor = SendDlgItemMessage(hwndDlg,IDC_COLOR1,CPM_GETCOLOUR,0,0); + Traffic_PopupFontColor = SendDlgItemMessage(hwndDlg,IDC_COLOR2,CPM_GETCOLOUR,0,0); + // + Traffic_PopupTimeoutDefault = IsDlgButtonChecked(hwndDlg,IDC_RADIO_FROMPOPUP); + if (Traffic_PopupTimeoutDefault == 0) Traffic_PopupTimeoutValue = GetDlgItemInt(hwndDlg,IDC_POPUP_TIMEOUT,NULL,0); + // + UpdateNotifyTimer(); + return TRUE; + } + break; + } + break; + } + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static OPTTREE_OPTION options[] = +{ + {0, LPGENT("Display/") LPGENT("Icon"), + OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawProtoIcon"}, + {0, LPGENT("Display/") LPGENT("Account name"), + OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawProtoName"}, + {0, LPGENT("Display/") LPGENT("Current traffic"), + OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawCurrentTraffic"}, + {0, LPGENT("Display/") LPGENT("Total traffic"), + OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawTotalTraffic"}, + {0, LPGENT("Display/") LPGENT("Current online"), + OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawCurrentTime"}, + {0, LPGENT("Display/") LPGENT("Total online"), + OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, "DrawTotalTime"}, + {0, LPGENT("General/") LPGENT("Draw frame as skin element"), + OPTTREE_CHECK, 1, NULL, "DrawFrmAsSkin"}, + {0, LPGENT("General/") LPGENT("Show tooltip in traffic window"), + OPTTREE_CHECK, 1, NULL, "ShowTooltip"}, + {0, LPGENT("General/") LPGENT("\"Toggle traffic counter\" in main menu"), + OPTTREE_CHECK, 1, NULL, "ShowMainMenuItem"}, + // Резервируем место под активные и видимые протоколы + // Максимум 16 позиций видимых и 16 активных + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, NULL, OPTTREE_CHECK, OPTTREE_INVISIBLE, NULL, NULL}, + {0, LPGENT("Visible accounts/") LPGENT("Summary traffic for visible accounts"), + OPTTREE_CHECK, 1, NULL, "ShowSummary"}, + {0, LPGENT("Visible accounts/") LPGENT("Overall traffic"), + OPTTREE_CHECK, 1, NULL, "ShowOverall"}, +}; + +static INT_PTR CALLBACK DlgProcTCOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + WORD i, j, l; + BOOL result; + static BYTE Initialized = 0; + static WORD optionCount = 0; + + if (!Initialized) + { + pOptions = options; + optionCount = SIZEOF(options); + // Если нет Variables, активируем галочки для старого метода рисования + if (!bVariablesExists) + { + for (i = 0; i < 8; i++) options[i].dwFlag = 1; + } + + // Флажки для видимости аккаунтов создаются в любом случае. + for (i = j = 0; (j < NumberOfAccounts) && (i < optionCount) ; i++) + if ((options[i].dwFlag & OPTTREE_INVISIBLE) && !options[i].szSettingName) + { + options[i].szSettingName = (char*)mir_alloc(1 + strlen(ProtoList[j].name)); + strcpy(options[i].szSettingName, ProtoList[j].name); + l = 20 + _tcslen(ProtoList[j].tszAccountName); + options[i].szOptionName = (TCHAR*)mir_alloc(sizeof(TCHAR) * l); + mir_sntprintf(options[i].szOptionName, + l, + _T("Visible accounts/%s"), + ProtoList[j].tszAccountName); + options[i].dwFlag = (ProtoList[j++].Enabled ? 1 : OPTTREE_INVISIBLE) + | OPTTREE_NOTRANSLATE; + } + Initialized = 1; + } + + if (OptTree_ProcessMessage(hwndDlg, msg, wParam, lParam, &result, IDC_APPEARANCEOPTIONS, options, optionCount)) + return result; + + switch (msg) + { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + + SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(15, 0)); + SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETPOS, 0, GetDlgItemInt(hwndDlg, IDC_EDIT_SPACE, NULL, FALSE)); + + //show/hide button + SetDlgItemText(hwndDlg,IDC_BSHOWHIDE,(IsWindowVisible(TrafficHwnd) != 0)? TranslateT("Hide now") : TranslateT("Show now")); + + // Строки формата для счётчиков + EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_COUNTER_FORMAT), bVariablesExists); + SetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_COUNTER_FORMAT), Traffic_CounterFormat); + + // Формат всплывающей подсказки + EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_TOOLTIP_FORMAT), bTooltipExists); + SetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_TOOLTIP_FORMAT), Traffic_TooltipFormat); + + // Display traffic for current... + SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Day")); + SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Week")); + SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Month")); + SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Year")); + SendDlgItemMessage(hwndDlg, IDC_COMBO_AUTO_CLEAR, CB_SETCURSEL, unOptions.PeriodForShow, 0); + + // Интервал между строками + SetDlgItemInt(hwndDlg, IDC_EDIT_SPACE, Traffic_AdditionSpace, 0); + SendDlgItemMessage(hwndDlg, IDC_EDIT_SPACE, EM_LIMITTEXT, 2, 0); + + // Appearance + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawProtoIcon, "DrawProtoIcon"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawProtoName, "DrawProtoName"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawCurrentTraffic, "DrawCurrentTraffic"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawTotalTraffic, "DrawTotalTraffic"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawCurrentTimeCounter, "DrawCurrentTime"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawTotalTimeCounter, "DrawTotalTime"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.DrawFrmAsSkin, "DrawFrmAsSkin"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowSummary , "ShowSummary"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowTooltip, "ShowTooltip"); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowMainMenuItem, "ShowMainMenuItem"); + + // Настройки видимости протоколов + for (i = 0; i < NumberOfAccounts; i++) + { + char buffer[32]; + strcpy(buffer, ProtoList[i].name); + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, ProtoList[i].Visible, buffer); + } + OptTree_SetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, unOptions.ShowOverall, "ShowOverall"); + + EnableWindow(GetDlgItem(GetParent(hwndDlg),IDC_APPLY),FALSE); + return 0; + + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case IDC_BSHOWHIDE: + MenuCommand_TrafficShowHide(0, 0); + SetDlgItemText(hwndDlg,IDC_BSHOWHIDE,IsWindowVisible(TrafficHwnd)? TranslateT("Hide now") : TranslateT("Show now")); + return 0; + + case IDC_EDIT_SPACE: + case IDC_EDIT_COUNTER_FORMAT: + case IDC_EDIT_OVERALL_COUNTER_FORMAT: + case IDC_EDIT_TOOLTIP_FORMAT: + if (HIWORD(wParam) == EN_CHANGE) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case IDC_COMBO_AUTO_CLEAR: + if (HIWORD(wParam) == CBN_SELCHANGE) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + break; + } + + case WM_NOTIFY: + { + LPNMHDR lpnmhdr = (LPNMHDR)lParam; + + switch (lpnmhdr->code) + { + case PSN_APPLY: + { + unOptions.PeriodForShow = (char)SendDlgItemMessage(hwndDlg,IDC_COMBO_AUTO_CLEAR,CB_GETCURSEL,0,0); + + // Интервал между строками + Traffic_AdditionSpace = GetDlgItemInt(hwndDlg, IDC_EDIT_SPACE, NULL, 0); + // Настройки Appearance + unOptions.DrawProtoIcon = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawProtoIcon"); + unOptions.DrawProtoName = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawProtoName"); + unOptions.DrawCurrentTraffic = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawCurrentTraffic"); + unOptions.DrawTotalTraffic = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawTotalTraffic"); + unOptions.DrawTotalTimeCounter = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawTotalTime"); + unOptions.DrawCurrentTimeCounter = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawCurrentTime"); + unOptions.DrawTotalTimeCounter = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawTotalTime"); + unOptions.DrawFrmAsSkin = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "DrawFrmAsSkin"); + unOptions.ShowSummary = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowSummary"); + unOptions.ShowTooltip = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowTooltip"); + unOptions.ShowMainMenuItem = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowMainMenuItem"); + + // Настройки видимости протоколов + for (i = 0; i < NumberOfAccounts; i++) + { + char buffer[32]; + strcpy(buffer, ProtoList[i].name); + ProtoList[i].Visible = (BYTE)OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, buffer); + } + unOptions.ShowOverall = OptTree_GetOptions(hwndDlg, IDC_APPEARANCEOPTIONS, options, optionCount, "ShowOverall"); + + // Формат счётчиков + GetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_COUNTER_FORMAT), Traffic_CounterFormat, 512); + // Формат всплывающей подсказки + GetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_TOOLTIP_FORMAT), Traffic_TooltipFormat, 512); + + // Ключевой цвет + UseKeyColor = db_get_b(NULL, "ModernSettings", "UseKeyColor", 1); + KeyColor = db_get_dw(NULL, "ModernSettings", "KeyColor", 0); + + // Перерисовываем фрейм + UpdateTrafficWindowSize(); + + // Если отключается показ пункта главного меню, то удаляем его. + if (!unOptions.ShowMainMenuItem && hTrafficMainMenuItem) + { + CallService(MS_CLIST_REMOVEMAINMENUITEM, (WPARAM)hTrafficMainMenuItem, 0); + hTrafficMainMenuItem = NULL; + } + // Если включается, то создаём. + if (unOptions.ShowMainMenuItem && !hTrafficMainMenuItem) + Traffic_AddMainMenuItem(); + + SaveSettings(0); + // + return TRUE; + } // case PSN_APPLY + } // switch + } + + case WM_DESTROY: + return FALSE; + } + return 0; +} + +int TrafficCounterOptInitialise(WPARAM wParam,LPARAM lParam) +{ + // Main options page + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.position = 900000000; + odp.groupPosition = 1; + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_TRAFFIC); + odp.pszGroup = LPGEN("Services"); + odp.pszTab = LPGEN("Options"); + odp.pszTitle = LPGEN("Traffic counter"); + odp.pfnDlgProc = DlgProcTCOptions; + odp.flags = ODPF_BOLDGROUPS; + Options_AddPage(wParam, &odp); + + // Statistics options page + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_STATS); + odp.pszTab = LPGEN("Statistics"); + odp.pfnDlgProc = DlgProcOptStatistics; + Options_AddPage(wParam, &odp); + + // Popups option page + if (bPopupExists) { + odp.groupPosition = 100; + odp.pszTemplate=MAKEINTRESOURCEA(IDD_OPT_TRAFFIC_POPUPS); + odp.pszGroup=LPGEN("PopUps"); + odp.pszTitle=LPGEN("Traffic counter"); + odp.pfnDlgProc=DlgProcPopupsTraffic; + odp.flags=ODPF_BOLDGROUPS; + Options_AddPage(wParam, &odp); + } + + return 0; +} diff --git a/plugins/TrafficCounter/src/statistics.cpp b/plugins/TrafficCounter/src/statistics.cpp index e8a975fdf1..a0c46ea118 100644 --- a/plugins/TrafficCounter/src/statistics.cpp +++ b/plugins/TrafficCounter/src/statistics.cpp @@ -24,9 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" #include -extern HWND TrafficHwnd; -extern PROTOLIST *ProtoList; -extern uTCFLAGS unOptions; WORD Stat_SelAcc; // Выбранные аккаунты в окне статистики HWND hListAccs; diff --git a/plugins/TrafficCounter/src/vars.h b/plugins/TrafficCounter/src/vars.h index f0284a0ca1..0b35ec2670 100644 --- a/plugins/TrafficCounter/src/vars.h +++ b/plugins/TrafficCounter/src/vars.h @@ -3,7 +3,6 @@ //extern BYTE numProto; extern int NumberOfAccounts; -extern BOOL bVariablesExists; //extern PROTOLIST *ProtoList; void RegisterVariablesTokens(void); -- cgit v1.2.3