From 785527c5313f64f763f5e572e86dd2d0bb6ff5a0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 1 Nov 2023 19:29:11 +0300 Subject: code cleaning --- plugins/StatusManager/src/aaa_main.cpp | 50 +++++++++++++++---------------- plugins/StatusManager/src/aaa_options.cpp | 14 ++++----- src/core/stdautoaway/src/main.cpp | 22 +++++++------- src/core/stdautoaway/src/options.cpp | 4 +-- src/core/stdautoaway/src/stdafx.h | 8 ++--- 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/plugins/StatusManager/src/aaa_main.cpp b/plugins/StatusManager/src/aaa_main.cpp index 5cfa722dc9..f69cd394bb 100644 --- a/plugins/StatusManager/src/aaa_main.cpp +++ b/plugins/StatusManager/src/aaa_main.cpp @@ -34,12 +34,11 @@ CFakePlugin AAAPlugin(AAAMODULENAME); static HANDLE hEvents[3]; -static BOOL ignoreLockKeys = FALSE; -static BOOL ignoreSysKeys = FALSE; -static BOOL ignoreAltCombo = FALSE; -static BOOL monitorMouse = TRUE; -static BOOL monitorKeyboard = TRUE; -static HWND confirmDialog; +static bool ignoreLockKeys = false; +static bool ignoreSysKeys = false; +static bool ignoreAltCombo = false; +static bool monitorMouse = true; +static bool monitorKeyboard = true; static int mouseStationaryTimer; HHOOK hMirandaMouseHook = nullptr; HHOOK hMirandaKeyBoardHook = nullptr; @@ -51,6 +50,7 @@ HHOOK hKeyBoardHook = nullptr; #pragma data_seg() #pragma comment(linker, "/section:Shared,rws") uint32_t lastMirandaInput = 0; +static HWND confirmDialog; static UINT_PTR hAutoAwayTimer; // prototypes extern uint32_t StatusModeToProtoFlag(int status); @@ -147,8 +147,7 @@ static int getIdleMode(int options) static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) { - int statusChanged = FALSE; - int confirm = FALSE; + bool bStatusChanged = false, bConfirm = false; for (auto &it : protoList) { it->aaaStatus = ID_STATUS_DISABLED; @@ -165,7 +164,6 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) int sts2Time = it->naTime * SECS_PER_MINUTE; int sts1setTime = it->sts1setTimer == 0 ? 0 : (GetTickCount() - it->sts1setTimer) / 1000; int currentMode = Proto_GetStatus(it->m_szName); - int mode = getIdleMode(it->optionFlags); /* check states */ @@ -179,14 +177,14 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) it->aaaStatus = it->lv1Status; it->sts1setTimer = GetTickCount(); sts1setTime = 0; - it->bStatusChanged = statusChanged = true; + it->bStatusChanged = bStatusChanged = true; changeState(*it, mode, STATUS1_SET); } else if (mouseStationaryTimer >= sts2Time && currentMode == it->lv1Status && currentMode != it->lv2Status && (it->optionFlags & FLAG_SETNA) && (it->statusFlags & StatusModeToProtoFlag(currentMode))) { /* from ACTIVE to STATUS2_SET */ it->m_lastStatus = it->originalStatusMode = Proto_GetStatus(it->m_szName); it->aaaStatus = it->lv2Status; - it->bStatusChanged = statusChanged = true; + it->bStatusChanged = bStatusChanged = true; changeState(*it, mode, STATUS2_SET); } } @@ -208,7 +206,7 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) /* from STATUS1_SET to STATUS2_SET */ it->m_lastStatus = Proto_GetStatus(it->m_szName); it->aaaStatus = it->lv2Status; - it->bStatusChanged = statusChanged = true; + it->bStatusChanged = bStatusChanged = true; changeState(*it, mode, STATUS2_SET); } } @@ -240,30 +238,31 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD) /* HIDDEN_ACTIVE to STATUS2_SET */ it->m_lastStatus = it->originalStatusMode = Proto_GetStatus(it->m_szName); it->aaaStatus = it->lv2Status; - it->bStatusChanged = statusChanged = true; + it->bStatusChanged = bStatusChanged = true; changeState(*it, mode, STATUS2_SET); } } + if (it->curState == SET_ORGSTATUS) { /* SET_ORGSTATUS to ACTIVE */ it->m_lastStatus = Proto_GetStatus(it->m_szName); it->aaaStatus = it->originalStatusMode; - confirm = (it->optionFlags & FLAG_CONFIRM) ? TRUE : confirm; - it->bStatusChanged = statusChanged = true; + bConfirm = (it->optionFlags & FLAG_CONFIRM) ? true : bConfirm; + it->bStatusChanged = bStatusChanged = true; changeState(*it, mode, ACTIVE); it->sts1setTimer = 0; } it->bManualStatus = false; } - if (confirm || statusChanged) { + if (bConfirm || bStatusChanged) { TProtoSettings ps(protoList); // make a copy of data not to pollute main array for (auto &it : ps) it->m_status = it->aaaStatus; - if (confirm) + if (bConfirm) confirmDialog = ShowConfirmDialogEx(&ps, AAAPlugin.getWord(SETTING_CONFIRMDELAY, 5)); - else if (statusChanged) + else if (bStatusChanged) SetStatusEx(ps); } } @@ -446,11 +445,12 @@ int LoadAutoAwaySetting(SMProto &autoAwaySetting, char *protoName) 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 = AAAPlugin.getWord(setting, (flags & StatusModeToProtoFlag(ID_STATUS_AWAY)) ? ID_STATUS_AWAY : ID_STATUS_OFFLINE); + mir_snprintf(setting, "%s_Lv2Status", protoName); autoAwaySetting.lv2Status = AAAPlugin.getWord(setting, (flags & StatusModeToProtoFlag(ID_STATUS_NA)) ? ID_STATUS_NA : ID_STATUS_OFFLINE); - return 0; } @@ -468,11 +468,11 @@ void AAALoadOptions() bool monitorMiranda = false, monitorAll = false; - ignoreLockKeys = AAAPlugin.getByte(SETTING_IGNLOCK, FALSE); - ignoreSysKeys = AAAPlugin.getByte(SETTING_IGNSYSKEYS, FALSE); - ignoreAltCombo = AAAPlugin.getByte(SETTING_IGNALTCOMBO, FALSE); - monitorMouse = AAAPlugin.getByte(SETTING_MONITORMOUSE, TRUE) != 0; - monitorKeyboard = AAAPlugin.getByte(SETTING_MONITORKEYBOARD, TRUE) != 0; + ignoreLockKeys = AAAPlugin.getBool(SETTING_IGNLOCK, false); + ignoreSysKeys = AAAPlugin.getBool(SETTING_IGNSYSKEYS, false); + ignoreAltCombo = AAAPlugin.getBool(SETTING_IGNALTCOMBO, false); + monitorMouse = AAAPlugin.getBool(SETTING_MONITORMOUSE, true); + monitorKeyboard = AAAPlugin.getBool(SETTING_MONITORKEYBOARD, true); lastInput = lastMirandaInput = GetTickCount(); for (auto &it : protoList) { @@ -507,7 +507,7 @@ static int AAAModuleLoaded(WPARAM, LPARAM) hEvents[0] = HookEvent(ME_OPT_INITIALISE, AutoAwayOptInitialise); hEvents[1] = HookEvent(ME_SYSTEM_PRESHUTDOWN, AutoAwayShutdown); hEvents[2] = HookEvent(ME_PROTO_ACK, ProcessProtoAck); - + mouseStationaryTimer = 0; lastInput = lastMirandaInput = GetTickCount(); diff --git a/plugins/StatusManager/src/aaa_options.cpp b/plugins/StatusManager/src/aaa_options.cpp index 296b54c7d6..6e976fe277 100644 --- a/plugins/StatusManager/src/aaa_options.cpp +++ b/plugins/StatusManager/src/aaa_options.cpp @@ -41,7 +41,7 @@ void DisableDialog(HWND hwndDlg) INT_PTR CALLBACK DlgProcAutoAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static AAMSGSETTING** settings; + static AAMSGSETTING **settings; static int last, count; switch (msg) { @@ -52,7 +52,7 @@ INT_PTR CALLBACK DlgProcAutoAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L count = 0; last = -1; - PROTOACCOUNT** proto; + PROTOACCOUNT **proto; int protoCount = 0; Proto_EnumAccounts(&protoCount, &proto); if (protoCount <= 0) { @@ -220,7 +220,7 @@ static void SetDialogItems(HWND hwndDlg, SMProto *setting) bool bFullScr = (setting->optionFlags & FLAG_FULLSCREEN) != 0; bool bOnLock = (setting->optionFlags & FLAG_ONLOCK) != 0; bool bOnTS = (setting->optionFlags & FLAG_ONTS) != 0; - bool bAnyOption = bIsTimed | bSaver | bFullScr | bOnLock | bOnTS; + bool bAnyOption = bIsTimed || bSaver || bFullScr || bOnLock || bOnTS; CheckDlgButton(hwndDlg, IDC_FULLSCREEN, bFullScr ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_SCREENSAVE, bSaver ? BST_CHECKED : BST_UNCHECKED); @@ -252,7 +252,7 @@ static void SetDialogItems(HWND hwndDlg, SMProto *setting) EnableWindow(GetDlgItem(hwndDlg, IDC_SETNASTR), bSetNA && bIsTimed); EnableWindow(GetDlgItem(hwndDlg, IDC_SETNASTR), bSetNA && bIsTimed); EnableWindow(GetDlgItem(hwndDlg, IDC_LV2STATUS), bSetNA && bIsTimed); - + EnableWindow(GetDlgItem(hwndDlg, IDC_PROTOCOL), !g_bAAASettingSame); } @@ -296,7 +296,7 @@ static TProtoSettings optionSettings; static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - static SMProto* sameSetting; + static SMProto *sameSetting; SMProto *setting; static int init; @@ -346,7 +346,7 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM int flags = 0; if (!g_bAAASettingSame) - flags = CallProtoService(setting->m_szName, PS_GETCAPS, PFLAGNUM_2, 0)&~CallProtoService(setting->m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0); + flags = CallProtoService(setting->m_szName, PS_GETCAPS, PFLAGNUM_2, 0) & ~CallProtoService(setting->m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0); LVITEM lvItem = { 0 }; lvItem.mask = LVIF_TEXT | LVIF_PARAM; @@ -367,7 +367,7 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM { int flags = 0; if (!g_bAAASettingSame) - flags = CallProtoService(setting->m_szName, PS_GETCAPS, PFLAGNUM_2, 0)&~CallProtoService(setting->m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0); + flags = CallProtoService(setting->m_szName, PS_GETCAPS, PFLAGNUM_2, 0) & ~CallProtoService(setting->m_szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0); // clear box and add new status, loop status and check if compatible with proto SendDlgItemMessage(hwndDlg, IDC_LV1STATUS, CB_RESETCONTENT, 0, 0); diff --git a/src/core/stdautoaway/src/main.cpp b/src/core/stdautoaway/src/main.cpp index 1022f2a4d5..2d3278b47f 100644 --- a/src/core/stdautoaway/src/main.cpp +++ b/src/core/stdautoaway/src/main.cpp @@ -42,17 +42,17 @@ PLUGININFOEX pluginInfoEx = { CMPlugin::CMPlugin() : PLUGIN(MODULENAME, pluginInfoEx), - bIdleCheck(IDLENAME, "UserIdleCheck", 0), - bIdleMethod(IDLENAME, "IdleMethod", 0), - bIdleOnSaver(IDLENAME, "IdleOnSaver", 0), - bIdleOnFullScr(IDLENAME, "IdleOnFullScr", 0), - bIdleOnLock(IDLENAME, "IdleOnLock", 0), - bIdlePrivate(IDLENAME, "IdlePrivate", 0), - bIdleSoundsOff(IDLENAME, "IdleSoundsOff", 1), - bIdleOnTerminal(IDLENAME, "IdleOnTerminalDisconnect", 0), - bIdleStatusLock(IDLENAME, "IdleStatusLock", 0), - bAAEnable(IDLENAME, "AAEnable", 0), - bAAStatus(IDLENAME, "AAStatus", 0), + bIdleCheck(IDLENAME, "UserIdleCheck", false), + bIdleMethod(IDLENAME, "IdleMethod", false), + bIdleOnSaver(IDLENAME, "IdleOnSaver", false), + bIdleOnFullScr(IDLENAME, "IdleOnFullScr", false), + bIdleOnLock(IDLENAME, "IdleOnLock", false), + bIdlePrivate(IDLENAME, "IdlePrivate", false), + bIdleSoundsOff(IDLENAME, "IdleSoundsOff", true), + bIdleOnTerminal(IDLENAME, "IdleOnTerminalDisconnect", false), + bIdleStatusLock(IDLENAME, "IdleStatusLock", false), + bAAEnable(IDLENAME, "AAEnable", false), + iAAStatus(IDLENAME, "AAStatus", 0), iIdleTime1st(IDLENAME, "IdleTime1st", 10) { } diff --git a/src/core/stdautoaway/src/options.cpp b/src/core/stdautoaway/src/options.cpp index fed12a11f8..76d2d98605 100644 --- a/src/core/stdautoaway/src/options.cpp +++ b/src/core/stdautoaway/src/options.cpp @@ -95,7 +95,7 @@ public: for (auto &it : aa_Status) cmbAAStatus.AddString(Clist_GetStatusModeDescription(it, 0)); - cmbAAStatus.SetCurSel(IdleGetStatusIndex(g_plugin.bAAStatus)); + cmbAAStatus.SetCurSel(IdleGetStatusIndex(g_plugin.iAAStatus)); ShowHide(); return true; @@ -107,7 +107,7 @@ public: int curSel = cmbAAStatus.GetCurSel(); if (curSel != CB_ERR) - g_plugin.bAAStatus = aa_Status[curSel]; + g_plugin.iAAStatus = aa_Status[curSel]; // destroy any current idle and reset settings. IdleObject_Destroy(); diff --git a/src/core/stdautoaway/src/stdafx.h b/src/core/stdautoaway/src/stdafx.h index aed3748da5..04aa4cad33 100644 --- a/src/core/stdautoaway/src/stdafx.h +++ b/src/core/stdautoaway/src/stdafx.h @@ -76,10 +76,10 @@ struct CMPlugin : public PLUGIN int Load() override; int Unload() override; - CMOption bIdleCheck, bIdleMethod, bIdleOnSaver, bIdleOnFullScr, bIdleOnLock; - CMOption bIdlePrivate, bIdleSoundsOff, bIdleOnTerminal, bIdleStatusLock; - CMOption bAAEnable; - CMOption bAAStatus; + CMOption bIdleCheck, bIdleMethod, bIdleOnSaver, bIdleOnFullScr, bIdleOnLock; + CMOption bIdlePrivate, bIdleSoundsOff, bIdleOnTerminal, bIdleStatusLock; + CMOption bAAEnable; + CMOption iAAStatus; CMOption iIdleTime1st; }; -- cgit v1.2.3