From 723bc42a5dfe925c655cced2c184ddfdfc144ada Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 13 Jun 2018 18:16:13 +0300 Subject: System idle: - plugin StdIdle that had been acting as an options dialog for StdAutoAway removed; - service MS_IDLE_GETIDLEINFO moved into the core and replaced with Idle_GetInfo(); - new function Idle_Enter() is available to tell the core that Miranda is idle; - StdAutoAway & StatusManager adapted for these changes; --- src/core/stdautoaway/res/resource.rc | 31 ++++++++ src/core/stdautoaway/src/idle.cpp | 87 +++++++++++++++++++++++ src/core/stdautoaway/src/main.cpp | 17 ++++- src/core/stdautoaway/src/options.cpp | 134 +++++++++++++++++++++++++++++++++++ src/core/stdautoaway/src/stdafx.h | 12 ++++ 5 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 src/core/stdautoaway/src/idle.cpp create mode 100644 src/core/stdautoaway/src/options.cpp (limited to 'src/core/stdautoaway') diff --git a/src/core/stdautoaway/res/resource.rc b/src/core/stdautoaway/res/resource.rc index 16038b37b3..ac6ee6fb77 100644 --- a/src/core/stdautoaway/res/resource.rc +++ b/src/core/stdautoaway/res/resource.rc @@ -25,6 +25,37 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Dialog // +IDD_OPT_IDLE DIALOGEX 0, 0, 312, 193 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + CONTROL "Become idle if the following is left unattended:",IDC_IDLESHORT, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,18,259,9 + CONTROL "Windows",IDC_IDLEONWINDOWS,"Button",BS_AUTORADIOBUTTON,45,31,104,9 + CONTROL "Miranda",IDC_IDLEONMIRANDA,"Button",BS_AUTORADIOBUTTON,45,43,103,9 + EDITTEXT IDC_IDLE1STTIME,59,59,27,14,ES_AUTOHSCROLL | ES_NUMBER + CONTROL "Spin2",IDC_IDLESPIN,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS | UDS_HOTTRACK,86,59,11,14 + CONTROL "Become idle if the screen saver is active",IDC_SCREENSAVER, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,83,265,9 + CONTROL "Become idle if the computer is locked",IDC_LOCKED, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,105,265,9 + CONTROL "Become idle if a terminal session is disconnected",IDC_IDLETERMINAL, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,116,265,10 + CONTROL "Do not let protocols report any idle information",IDC_IDLEPRIVATE, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,131,251,9 + LTEXT "minute(s)",IDC_STATIC,99,61,76,9 + RTEXT "for",IDC_STATIC,12,62,41,8 + COMBOBOX IDC_AASTATUS,161,146,64,50,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Change my status mode to:",IDC_AASHORTIDLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,147,132,11 + CONTROL "Do not set status back to online when returning from idle",IDC_IDLESTATUSLOCK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,35,164,254,10 + GROUPBOX "Idle options",IDC_STATIC,3,1,304,192 + CONTROL "Become idle if application full screen",IDC_FULLSCREEN, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,94,265,9 + CONTROL "Disable sounds on idle",IDC_IDLESOUNDSOFF,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,177,265,9 +END + #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// diff --git a/src/core/stdautoaway/src/idle.cpp b/src/core/stdautoaway/src/idle.cpp new file mode 100644 index 0000000000..add27610b8 --- /dev/null +++ b/src/core/stdautoaway/src/idle.cpp @@ -0,0 +1,87 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-18 Miranda NG team (https://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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. +*/ + +#include "stdafx.h" + +static UINT_PTR g_hTimer; + +int IdleOptInit(WPARAM wParam, LPARAM); + +static int IdleObject_IsUserIdle() +{ + if (g_plugin.bIdleMethod) { + DWORD dwTick; + CallService(MS_SYSTEM_GETIDLE, 0, (LPARAM)&dwTick); + return GetTickCount() - dwTick > (g_plugin.iIdleTime1st * 60 * 1000); + } + + LASTINPUTINFO ii = { sizeof(ii) }; + if (GetLastInputInfo(&ii)) + return GetTickCount() - ii.dwTime > (g_plugin.iIdleTime1st * 60 * 1000); + + return FALSE; +} + +static void CALLBACK IdleTimer(HWND, UINT, UINT_PTR idEvent, DWORD) +{ + if (g_hTimer == idEvent) { + if (g_plugin.bIdleCheck && IdleObject_IsUserIdle()) + Idle_Enter(1); + + else if (g_plugin.bIdleOnSaver && IsScreenSaverRunning()) + Idle_Enter(2); + + else if (g_plugin.bIdleOnFullScr && IsFullScreen()) + Idle_Enter(3); + + else if (g_plugin.bIdleOnLock && IsWorkstationLocked()) + Idle_Enter(4); + + else if (g_plugin.bIdleOnTerminal && IsTerminalDisconnected()) + Idle_Enter(5); + } +} + +void IdleObject_Create() +{ + g_hTimer = SetTimer(nullptr, 0, 2000, IdleTimer); +} + +void IdleObject_Destroy() +{ + KillTimer(nullptr, g_hTimer); +} + +int LoadIdleModule(void) +{ + IdleObject_Create(); + + HookEvent(ME_OPT_INITIALISE, IdleOptInit); + return 0; +} + +void UnloadIdleModule() +{ + IdleObject_Destroy(); +} diff --git a/src/core/stdautoaway/src/main.cpp b/src/core/stdautoaway/src/main.cpp index 08cb2a891c..4aed198a66 100644 --- a/src/core/stdautoaway/src/main.cpp +++ b/src/core/stdautoaway/src/main.cpp @@ -41,8 +41,21 @@ PLUGININFOEX pluginInfoEx = { }; CMPlugin::CMPlugin() : - PLUGIN(MODULENAME, pluginInfoEx) -{} + 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), + iIdleTime1st(IDLENAME, "IdleTime1st", 10) +{ +} ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/stdautoaway/src/options.cpp b/src/core/stdautoaway/src/options.cpp new file mode 100644 index 0000000000..e8ee0669da --- /dev/null +++ b/src/core/stdautoaway/src/options.cpp @@ -0,0 +1,134 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-18 Miranda NG team (https://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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. +*/ + +#include "stdafx.h" + +static const WORD aa_Status[] = { ID_STATUS_AWAY, ID_STATUS_NA, ID_STATUS_OCCUPIED, ID_STATUS_DND, ID_STATUS_ONTHEPHONE, ID_STATUS_OUTTOLUNCH }; + +int IdleGetStatusIndex(WORD status) +{ + for (int j = 0; j < _countof(aa_Status); j++) + if (aa_Status[j] == status) + return j; + + return 0; +} + +class COptionsDlg : public CDlgBase +{ + CCtrlEdit edt1sttime; + CCtrlSpin spinIdle; + CCtrlCombo cmbAAStatus; + CCtrlCheck chkShort, chkOnWindows, chkOnMiranda, chkScreenSaver, chkFullScreen, chkLocked; + CCtrlCheck chkPrivate, chkStatusLock, chkTerminal, chkSoundsOff, chkShortIdle; + + void ShowHide() + { + BOOL bChecked = chkShort.GetState(); + chkOnWindows.Enable(bChecked); + chkOnMiranda.Enable(bChecked); + edt1sttime.Enable(bChecked); + + bChecked = chkShortIdle.GetState(); + cmbAAStatus.Enable(bChecked); + chkStatusLock.Enable(bChecked); + } + +public: + COptionsDlg() : + CDlgBase(g_plugin, IDD_OPT_IDLE), + edt1sttime(this, IDC_IDLE1STTIME), + spinIdle(this, IDC_IDLESPIN), + cmbAAStatus(this, IDC_AASTATUS), + chkShort(this, IDC_IDLESHORT), + chkLocked(this, IDC_LOCKED), + chkPrivate(this, IDC_IDLEPRIVATE), + chkTerminal(this, IDC_IDLETERMINAL), + chkOnWindows(this, IDC_IDLEONWINDOWS), + chkSoundsOff(this, IDC_IDLESOUNDSOFF), + chkOnMiranda(this, IDC_IDLEONMIRANDA), + chkShortIdle(this, IDC_AASHORTIDLE), + chkStatusLock(this, IDC_IDLESTATUSLOCK), + chkFullScreen(this, IDC_FULLSCREEN), + chkScreenSaver(this, IDC_SCREENSAVER) + { + CreateLink(chkShort, g_plugin.bIdleCheck); + CreateLink(chkLocked, g_plugin.bIdleOnLock); + CreateLink(chkPrivate, g_plugin.bIdlePrivate); + CreateLink(chkTerminal, g_plugin.bIdleOnTerminal); + CreateLink(chkShortIdle, g_plugin.bAAEnable); + CreateLink(chkOnMiranda, g_plugin.bIdleMethod); + CreateLink(chkSoundsOff, g_plugin.bIdleSoundsOff); + CreateLink(chkStatusLock, g_plugin.bIdleStatusLock); + CreateLink(chkFullScreen, g_plugin.bIdleOnFullScr); + CreateLink(chkScreenSaver, g_plugin.bIdleOnSaver); + + chkShortIdle.OnChange = chkShort.OnChange = Callback(this, &COptionsDlg::onChange); + } + + virtual void OnInitDialog() override + { + chkOnWindows.SetState(!g_plugin.bIdleMethod); + + spinIdle.SetRange(60, 1); + spinIdle.SetPosition(g_plugin.iIdleTime1st); + + for (auto &it : aa_Status) + cmbAAStatus.AddString(Clist_GetStatusModeDescription(it, 0)); + cmbAAStatus.SetCurSel(IdleGetStatusIndex(g_plugin.bAAStatus)); + + ShowHide(); + } + + virtual void OnApply() override + { + g_plugin.iIdleTime1st = spinIdle.GetPosition(); + + int curSel = cmbAAStatus.GetCurSel(); + if (curSel != CB_ERR) + g_plugin.bAAStatus = aa_Status[curSel]; + + // destroy any current idle and reset settings. + IdleObject_Destroy(); + IdleObject_Create(); + } + + void onChange(CCtrlCheck*) + { + ShowHide(); + } +}; + +int IdleOptInit(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + odp.position = 100000000; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_IDLE); + odp.szGroup.a = LPGEN("Status"); + odp.szTitle.a = LPGEN("Idle"); + odp.flags = ODPF_BOLDGROUPS; + odp.pDialog = new COptionsDlg(); + g_plugin.addOptions(wParam, &odp); + return 0; +} diff --git a/src/core/stdautoaway/src/stdafx.h b/src/core/stdautoaway/src/stdafx.h index 6c55b9c1b5..98f1ef29c5 100644 --- a/src/core/stdautoaway/src/stdafx.h +++ b/src/core/stdautoaway/src/stdafx.h @@ -45,6 +45,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include #include @@ -60,16 +61,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include "version.h" #include "../../mir_app/src/resource.h" #define MODULENAME "AutoAway" +#define IDLENAME "Idle" struct CMPlugin : public PLUGIN { CMPlugin(); int Load() override; + + CMOption bIdleCheck, bIdleMethod, bIdleOnSaver, bIdleOnFullScr, bIdleOnLock; + CMOption bIdlePrivate, bIdleSoundsOff, bIdleOnTerminal, bIdleStatusLock; + CMOption bAAEnable; + CMOption bAAStatus; + CMOption iIdleTime1st; }; + +void IdleObject_Destroy(); +void IdleObject_Create(); -- cgit v1.2.3