diff options
author | George Hazan <ghazan@miranda.im> | 2018-06-19 13:04:21 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-06-19 13:04:21 +0300 |
commit | 42425542f1ff6c5e2ece094e004b628e8ed4514d (patch) | |
tree | b1a4cdf06dcfa2fad7e86b445bc82fd26f1adf59 | |
parent | 0fb39531240a0a23e92c0456fe72e26027740696 (diff) |
StatusManager: code cleaning
-rw-r--r-- | plugins/StatusManager/src/aaa_options.cpp | 2 | ||||
-rw-r--r-- | plugins/StatusManager/src/advancedautoaway.cpp | 208 | ||||
-rw-r--r-- | plugins/StatusManager/src/commonstatus.cpp | 8 | ||||
-rw-r--r-- | plugins/StatusManager/src/commonstatus.h | 21 | ||||
-rw-r--r-- | plugins/StatusManager/src/stdafx.h | 24 |
5 files changed, 118 insertions, 145 deletions
diff --git a/plugins/StatusManager/src/aaa_options.cpp b/plugins/StatusManager/src/aaa_options.cpp index a8473936b1..153b1656f7 100644 --- a/plugins/StatusManager/src/aaa_options.cpp +++ b/plugins/StatusManager/src/aaa_options.cpp @@ -30,8 +30,6 @@ struct AAMSGSETTING char* msg; }; -char *StatusModeToDbSetting(int status, const char *suffix); - void DisableDialog(HWND hwndDlg) { EnableWindow(GetDlgItem(hwndDlg, IDC_STATUS), FALSE); diff --git a/plugins/StatusManager/src/advancedautoaway.cpp b/plugins/StatusManager/src/advancedautoaway.cpp index 649f61353f..8f37e7d596 100644 --- a/plugins/StatusManager/src/advancedautoaway.cpp +++ b/plugins/StatusManager/src/advancedautoaway.cpp @@ -54,85 +54,8 @@ DWORD lastMirandaInput = 0; static UINT_PTR hAutoAwayTimer; // prototypes extern DWORD StatusModeToProtoFlag(int status); -static int HookWindowsHooks(int hookMiranda, int hookAll); -static int UnhookWindowsHooks(); -static LRESULT CALLBACK MouseHookFunction(int code, WPARAM wParam, LPARAM lParam); -static LRESULT CALLBACK KeyBoardHookFunction(int code, WPARAM wParam, LPARAM lParam); -static LRESULT CALLBACK MirandaMouseHookFunction(int code, WPARAM wParam, LPARAM lParam); -static LRESULT CALLBACK MirandaKeyBoardHookFunction(int code, WPARAM wParam, LPARAM lParam); -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); - -static VOID CALLBACK AutoAwayTimer(HWND hwnd, UINT message, UINT_PTR idEvent, DWORD dwTime); -extern int AutoAwayOptInitialise(WPARAM wParam, LPARAM lParam); -extern char *StatusModeToDbSetting(int status, const char *suffix); -///////////////////////////////////////////////////////////////////////////////////////// -// Load from DB - -void AAAUnloadOptions() -{ - UnhookWindowsHooks(); - if (hAutoAwayTimer != 0) - KillTimer(nullptr, hAutoAwayTimer); -} - -void AAALoadOptions() -{ - // if bOverride is enabled, samesettings will be ignored (for options loading) - int monitorMiranda = FALSE; // use windows hooks? - int monitorAll = FALSE; // use windows hooks? - - AAAUnloadOptions(); - - ignoreLockKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNLOCK, FALSE); - ignoreSysKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNSYSKEYS, FALSE); - ignoreAltCombo = db_get_b(0, AAAMODULENAME, SETTING_IGNALTCOMBO, FALSE); - monitorMouse = db_get_b(0, AAAMODULENAME, SETTING_MONITORMOUSE, TRUE); - monitorKeyboard = db_get_b(0, AAAMODULENAME, SETTING_MONITORKEYBOARD, TRUE); - lastInput = lastMirandaInput = GetTickCount(); - - for (auto &it : protoList) { - char* protoName; - if (g_bAAASettingSame) - protoName = SETTING_ALL; - else - protoName = it->m_szName; - LoadAutoAwaySetting(*it, protoName); - - if (it->optionFlags & FLAG_MONITORMIRANDA) - monitorMiranda = TRUE; - else if (ignoreLockKeys || ignoreSysKeys || ignoreAltCombo || (monitorMouse != monitorKeyboard)) - monitorAll = TRUE; - } - - HookWindowsHooks(monitorMiranda, monitorAll); - hAutoAwayTimer = SetTimer(nullptr, 0, db_get_w(0, AAAMODULENAME, SETTING_AWAYCHECKTIMEINSECS, 5) * 1000, AutoAwayTimer); -} - -int LoadAutoAwaySetting(SMProto &autoAwaySetting, char* protoName) -{ - char setting[128]; - mir_snprintf(setting, "%s_OptionFlags", protoName); - autoAwaySetting.optionFlags = db_get_w(0, AAAMODULENAME, setting, FLAG_LV2ONINACTIVE | FLAG_RESET | FLAG_ENTERIDLE); - mir_snprintf(setting, "%s_AwayTime", protoName); - autoAwaySetting.awayTime = db_get_w(0, AAAMODULENAME, setting, SETTING_AWAYTIME_DEFAULT); - mir_snprintf(setting, "%s_NATime", protoName); - autoAwaySetting.naTime = db_get_w(0, AAAMODULENAME, setting, SETTING_NATIME_DEFAULT); - mir_snprintf(setting, "%s_StatusFlags", protoName); - autoAwaySetting.statusFlags = db_get_w(0, AAAMODULENAME, setting, StatusModeToProtoFlag(ID_STATUS_ONLINE) | StatusModeToProtoFlag(ID_STATUS_FREECHAT)); - - int flags; - if (g_bAAASettingSame) - flags = 0xFFFFFF; - else - flags = CallProtoService(protoName, PS_GETCAPS, PFLAGNUM_2, 0)&~CallProtoService(protoName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0); - mir_snprintf(setting, "%s_Lv1Status", protoName); - autoAwaySetting.lv1Status = db_get_w(0, AAAMODULENAME, setting, (flags&StatusModeToProtoFlag(ID_STATUS_AWAY)) ? ID_STATUS_AWAY : ID_STATUS_OFFLINE); - mir_snprintf(setting, "%s_Lv2Status", protoName); - autoAwaySetting.lv2Status = db_get_w(0, AAAMODULENAME, setting, (flags&StatusModeToProtoFlag(ID_STATUS_NA)) ? ID_STATUS_NA : ID_STATUS_OFFLINE); - - return 0; -} +int AutoAwayOptInitialise(WPARAM wParam, LPARAM lParam); static int ProcessProtoAck(WPARAM, LPARAM lParam) { @@ -348,35 +271,6 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) ///////////////////////////////////////////////////////////////////////////////////////// // Windows hooks -static int HookWindowsHooks(int hookMiranda, int hookAll) -{ - if (hookMiranda) { - if (monitorKeyboard && hMirandaKeyBoardHook == nullptr) - hMirandaKeyBoardHook = SetWindowsHookEx(WH_KEYBOARD, MirandaKeyBoardHookFunction, nullptr, GetCurrentThreadId()); - if (monitorMouse && hMirandaMouseHook == nullptr) - hMirandaMouseHook = SetWindowsHookEx(WH_MOUSE, MirandaMouseHookFunction, nullptr, GetCurrentThreadId()); - } - if (hookAll) { - if (monitorKeyboard && hKeyBoardHook == nullptr) - hKeyBoardHook = SetWindowsHookEx(WH_KEYBOARD, KeyBoardHookFunction, nullptr, GetCurrentThreadId()); - if (monitorMouse && hMouseHook == nullptr) - hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseHookFunction, nullptr, GetCurrentThreadId()); - } - - return 0; -} - -static int UnhookWindowsHooks() -{ - UnhookWindowsHookEx(hMouseHook); - UnhookWindowsHookEx(hKeyBoardHook); - UnhookWindowsHookEx(hMirandaMouseHook); - UnhookWindowsHookEx(hMirandaKeyBoardHook); - - hMouseHook = hKeyBoardHook = hMirandaMouseHook = hMirandaKeyBoardHook = nullptr; - return 0; -} - static LRESULT CALLBACK MirandaMouseHookFunction(int code, WPARAM wParam, LPARAM lParam) { if (code >= 0) { @@ -503,6 +397,102 @@ static LRESULT CALLBACK KeyBoardHookFunction(int code, WPARAM wParam, LPARAM lPa return CallNextHookEx(hKeyBoardHook, code, wParam, lParam); } +static int HookWindowsHooks(int hookMiranda, int hookAll) +{ + if (hookMiranda) { + if (monitorKeyboard && hMirandaKeyBoardHook == nullptr) + hMirandaKeyBoardHook = SetWindowsHookEx(WH_KEYBOARD, MirandaKeyBoardHookFunction, nullptr, GetCurrentThreadId()); + if (monitorMouse && hMirandaMouseHook == nullptr) + hMirandaMouseHook = SetWindowsHookEx(WH_MOUSE, MirandaMouseHookFunction, nullptr, GetCurrentThreadId()); + } + if (hookAll) { + if (monitorKeyboard && hKeyBoardHook == nullptr) + hKeyBoardHook = SetWindowsHookEx(WH_KEYBOARD, KeyBoardHookFunction, nullptr, GetCurrentThreadId()); + if (monitorMouse && hMouseHook == nullptr) + hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseHookFunction, nullptr, GetCurrentThreadId()); + } + + return 0; +} + +static int UnhookWindowsHooks() +{ + UnhookWindowsHookEx(hMouseHook); + UnhookWindowsHookEx(hKeyBoardHook); + UnhookWindowsHookEx(hMirandaMouseHook); + UnhookWindowsHookEx(hMirandaKeyBoardHook); + + hMouseHook = hKeyBoardHook = hMirandaMouseHook = hMirandaKeyBoardHook = nullptr; + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Load from DB + +int LoadAutoAwaySetting(SMProto &autoAwaySetting, char *protoName) +{ + char setting[128]; + mir_snprintf(setting, "%s_OptionFlags", protoName); + autoAwaySetting.optionFlags = db_get_w(0, AAAMODULENAME, setting, FLAG_LV2ONINACTIVE | FLAG_RESET | FLAG_ENTERIDLE); + mir_snprintf(setting, "%s_AwayTime", protoName); + autoAwaySetting.awayTime = db_get_w(0, AAAMODULENAME, setting, SETTING_AWAYTIME_DEFAULT); + mir_snprintf(setting, "%s_NATime", protoName); + autoAwaySetting.naTime = db_get_w(0, AAAMODULENAME, setting, SETTING_NATIME_DEFAULT); + mir_snprintf(setting, "%s_StatusFlags", protoName); + autoAwaySetting.statusFlags = db_get_w(0, AAAMODULENAME, setting, StatusModeToProtoFlag(ID_STATUS_ONLINE) | StatusModeToProtoFlag(ID_STATUS_FREECHAT)); + + int flags; + if (g_bAAASettingSame) + flags = 0xFFFFFF; + else + flags = CallProtoService(protoName, PS_GETCAPS, PFLAGNUM_2, 0) & ~CallProtoService(protoName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0); + mir_snprintf(setting, "%s_Lv1Status", protoName); + autoAwaySetting.lv1Status = db_get_w(0, AAAMODULENAME, setting, (flags & StatusModeToProtoFlag(ID_STATUS_AWAY)) ? ID_STATUS_AWAY : ID_STATUS_OFFLINE); + mir_snprintf(setting, "%s_Lv2Status", protoName); + autoAwaySetting.lv2Status = db_get_w(0, AAAMODULENAME, setting, (flags & StatusModeToProtoFlag(ID_STATUS_NA)) ? ID_STATUS_NA : ID_STATUS_OFFLINE); + + return 0; +} + +void AAAUnloadOptions() +{ + UnhookWindowsHooks(); + if (hAutoAwayTimer != 0) + KillTimer(nullptr, hAutoAwayTimer); +} + +void AAALoadOptions() +{ + // if bOverride is enabled, samesettings will be ignored (for options loading) + AAAUnloadOptions(); + + bool monitorMiranda = false, monitorAll = false; + + ignoreLockKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNLOCK, FALSE); + ignoreSysKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNSYSKEYS, FALSE); + ignoreAltCombo = db_get_b(0, AAAMODULENAME, SETTING_IGNALTCOMBO, FALSE); + monitorMouse = db_get_b(0, AAAMODULENAME, SETTING_MONITORMOUSE, TRUE) != 0; + monitorKeyboard = db_get_b(0, AAAMODULENAME, SETTING_MONITORKEYBOARD, TRUE) != 0; + lastInput = lastMirandaInput = GetTickCount(); + + for (auto &it : protoList) { + char *protoName; + if (g_bAAASettingSame) + protoName = SETTING_ALL; + else + protoName = it->m_szName; + LoadAutoAwaySetting(*it, protoName); + + if (it->optionFlags & FLAG_MONITORMIRANDA) + monitorMiranda = true; + else if (ignoreLockKeys || ignoreSysKeys || ignoreAltCombo || (monitorMouse != monitorKeyboard)) + monitorAll = true; + } + + HookWindowsHooks(monitorMiranda, monitorAll); + hAutoAwayTimer = SetTimer(nullptr, 0, db_get_w(0, AAAMODULENAME, SETTING_AWAYCHECKTIMEINSECS, 5) * 1000, AutoAwayTimer); +} + ///////////////////////////////////////////////////////////////////////////////////////// // Inits & stuff @@ -512,7 +502,7 @@ static int AutoAwayShutdown(WPARAM, LPARAM) return 0; } -int AAAModuleLoaded(WPARAM, LPARAM) +static int AAAModuleLoaded(WPARAM, LPARAM) { hEvents[0] = HookEvent(ME_OPT_INITIALISE, AutoAwayOptInitialise); hEvents[1] = HookEvent(ME_SYSTEM_PRESHUTDOWN, AutoAwayShutdown); @@ -521,8 +511,6 @@ int AAAModuleLoaded(WPARAM, LPARAM) mouseStationaryTimer = 0; lastInput = lastMirandaInput = GetTickCount(); - //////////////////////////////////////////////////////////////////////////////////////// - AAALoadOptions(); return 0; } diff --git a/plugins/StatusManager/src/commonstatus.cpp b/plugins/StatusManager/src/commonstatus.cpp index f95ec3f89c..ac86edbddf 100644 --- a/plugins/StatusManager/src/commonstatus.cpp +++ b/plugins/StatusManager/src/commonstatus.cpp @@ -78,15 +78,9 @@ TProtoSettings::TProtoSettings(const TProtoSettings &p) insert(new SMProto(*it)); } -///////////////////////////////////////////////////////////////////////////////////////// -// prototypes - -char* StatusModeToDbSetting(int status, const char *suffix); -DWORD StatusModeToProtoFlag(int status); - // some helpers from awaymsg.c ================================================================ -char *StatusModeToDbSetting(int status, const char *suffix) +char* StatusModeToDbSetting(int status, const char *suffix) { char *prefix; static char str[64]; diff --git a/plugins/StatusManager/src/commonstatus.h b/plugins/StatusManager/src/commonstatus.h index 2408323478..5aafe73be4 100644 --- a/plugins/StatusManager/src/commonstatus.h +++ b/plugins/StatusManager/src/commonstatus.h @@ -22,26 +22,7 @@ #ifndef COMMONSTATUSHEADER #define COMMONSTATUSHEADER -#include <windows.h> -#include <shlobj.h> -#include <uxtheme.h> -#include <stdio.h> - -#include <newpluginapi.h> -#include <m_system.h> -#include <m_awaymsg.h> -#include <m_database.h> -#include <m_protosvc.h> -#include <m_clist.h> -#include <m_string.h> -#include <m_langpack.h> -#include <m_popup.h> -#include <m_variables.h> -#include <m_netlib.h> -#include "m_statusplugins.h" -#include <m_utils.h> -#include <m_NewAwaySys.h> -#include <win2k.h> +#define MODULENAME "StatusManager" #if defined( _WIN64 ) #define __PLATFORM_NAME "64" diff --git a/plugins/StatusManager/src/stdafx.h b/plugins/StatusManager/src/stdafx.h index e9343eab16..253429458d 100644 --- a/plugins/StatusManager/src/stdafx.h +++ b/plugins/StatusManager/src/stdafx.h @@ -8,27 +8,36 @@ #include <ipexport.h> #include <icmpapi.h> #include <commctrl.h> +#include <shlobj.h> +#include <uxtheme.h> +#include <stdio.h> #include <newpluginapi.h> -#include <m_core.h> -#include <m_skin.h> +#include <m_awaymsg.h> +#include <m_database.h> #include <m_clistint.h> -#include <m_utils.h> +#include <m_gui.h> #include <m_idle.h> #include <m_icolib.h> +#include <m_langpack.h> +#include <m_netlib.h> +#include <m_NewAwaySys.h> #include <m_options.h> +#include <m_popup.h> #include <m_protosvc.h> #include <m_protocols.h> #include <m_toptoolbar.h> #include <m_statusplugins.h> -#include <m_gui.h> +#include <m_skin.h> +#include <m_string.h> +#include <m_utils.h> +#include <m_variables.h> +#include <win2k.h> #include "version.h" #include "resource.h" -#define MODULENAME "StatusManager" - struct CMPlugin : public PLUGIN<CMPlugin> { CMPlugin(); @@ -49,4 +58,7 @@ extern CMOption<bool> g_AAAEnabled, g_KSEnabled, g_SSEnabled; int OnCommonOptionsInit(WPARAM wParam, LPARAM); void InitCommonOptions(); +char* StatusModeToDbSetting(int status, const char *suffix); +DWORD StatusModeToProtoFlag(int status); + #endif //_COMMON_H_ |