1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
////////////////////////////////////
/// 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;
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
"Shhh on Idle",
PLUGIN_MAKE_VERSION(0,1,0,0),
"Disable sounds (and optionally PopUps) when Miranda goes idle",
"Scott Ellis",
"mail@scottellis.com.au",
"© 2005-2007 Scott Ellis",
"http://www.scottellis.com.au/",
0, //not transient
0, //doesn't replace anything built-in
{ 0xe36dca71, 0x7b2, 0x4b98, { 0x99, 0xab, 0xa1, 0x89, 0x2d, 0x8e, 0x5c, 0xfc } } // {E36DCA71-07B2-4b98-99AB-A1892D8E5CFC}
};
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
hInst=hinstDLL;
return TRUE;
}
__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
{
pluginInfo.cbSize = sizeof(PLUGININFO);
return (PLUGININFO*)&pluginInfo;
}
__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
return &pluginInfo;
}
static const MUUID interfaces[] = {MIID_SHHHONIDLE, MIID_LAST};
__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
{
return interfaces;
}
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;
}
|