From bded3f3d452e097995cbb1e695aaec13a739d1af Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 1 Nov 2006 14:45:50 +0000 Subject: git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@14 4f64403b-2f21-0410-a795-97e2b3489a10 --- shhhonidle/shhhonidle.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 shhhonidle/shhhonidle.c (limited to 'shhhonidle/shhhonidle.c') diff --git a/shhhonidle/shhhonidle.c b/shhhonidle/shhhonidle.c new file mode 100644 index 0000000..b91acfc --- /dev/null +++ b/shhhonidle/shhhonidle.c @@ -0,0 +1,131 @@ +//////////////////////////////////// +/// This Miranda plugin (http://www.miranda-im.org) is released under the General Public Licence, +/// available at http://www.gnu.org/copyleft/gpl.html +/// Copyright Scott Ellis 2005 (mail@scottellis.com.au .. www.scottellis.com.au) +//////////////////////////////////// + +#include "common.h" +#include "options.h" + +HINSTANCE hInst; +PLUGINLINK *pluginLink; + +PLUGININFO pluginInfo={ + sizeof(PLUGININFO), + "Shhh on Idle", + PLUGIN_MAKE_VERSION(0,0,1,3), + "Disable sounds (and optionally PopUps) when Miranda goes idle", + "Scott Ellis", + "mail@scottellis.com.au", + "© 2005 Scott Ellis", + "http://www.scottellis.com.au/", + 0, //not transient + 0 //doesn't replace anything built-in +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + +__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +HANDLE hook_idle = 0; +BOOL is_idle = FALSE; +UINT alarm_timer_id = 0; + +//#define CONTROL_GLOBAL_STATUS +#define CONTROL_SOUND + +#ifdef CONTROL_GLOBAL_STATUS +WORD saved_status; +#endif + +#define ALARM_ON_TIME (1000 * 60 * 10) // alow sound for 10 mins when an alarm with sound notification is triggered + +void EnableSounds(BOOL enable) { + BOOL enabled = (BOOL)DBGetContactSettingByte(0, "Skin", "UseSound", 1); + + DBWriteContactSettingByte(0, "Skin", "UseSound", enable ? 1 : 0); +} + +int OnIdleChanged(WPARAM wParam, LPARAM lParam) { +#ifdef CONTROL_GLOBAL_STATUS + int st; +#endif + + is_idle = (lParam & IDF_ISIDLE); + +#ifdef CONTROL_SOUND + EnableSounds(!is_idle); +#endif + +#ifdef CONTROL_GLOBAL_STATUS + st = CallService(MS_CLIST_GETSTATUSMODE, 0, 0); + if(is_idle && st != ID_STATUS_OFFLINE) { + saved_status = st; + CallService(MS_CLIST_SETSTATUSMODE, (WPARAM)ID_STATUS_AWAY, 0); + } else if(!is_idle && saved_status != ID_STATUS_OFFLINE) { + CallService(MS_CLIST_SETSTATUSMODE, (WPARAM)saved_status, 0); + } +#endif + + if(!is_idle && alarm_timer_id) + KillTimer(0, alarm_timer_id); + + return 0; +} + +VOID CALLBACK AlarmTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { + KillTimer(0, alarm_timer_id); + + if(is_idle) EnableSounds(FALSE); +} + +// do not prevent alarm noise +// (i.e. re-enable sound on any alarm with sound, for a period of time) +int OnAlarm(WPARAM wParam, LPARAM lParam) { + ALARMINFO *al = (ALARMINFO *)lParam; + + if(al && al->sound_num > 0) { + EnableSounds(TRUE); + if(alarm_timer_id) KillTimer(0, alarm_timer_id); + alarm_timer_id = SetTimer(0, 0, ALARM_ON_TIME, AlarmTimerProc); + } + + return 0; +} + +int OnModulesLoaded(WPARAM wParam, LPARAM lParam) { + hook_idle = HookEvent(ME_IDLE_CHANGED, OnIdleChanged); + +#ifdef CONTROL_SOUND + EnableSounds(TRUE); + + // do not prevent alarm noise + HookEvent(ME_ALARMS_TRIGGERED, OnAlarm); +#endif + + return 0; +} + +int __declspec(dllexport) Load(PLUGINLINK *link) +{ + pluginLink = link; + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + + HookEvent(ME_OPT_INITIALISE, OptInit); + LoadOptions(); + + return 0; +} + +int __declspec(dllexport) Unload(void) +{ + UnhookEvent(hook_idle); + return 0; +} \ No newline at end of file -- cgit v1.2.3