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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
/*
Miranda NG: the free IM client for Microsoft* Windows*
Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org)
Copyright (c) 2000-06 Miranda ICQ/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 "globals.h"
//#include "../../miranda-IM/core/commonheaders.h"
//int idleCheckPerm = 0;
//int idleMethodPerm = 0;
//int idleTimeFirstPerm = 5; // this is in mins
//int idleTimeSecondPerm = 10; //
//int idleTimeFirstOnPerm = 0;
//int idleTimeSecondOnPerm = 0;
//int idleOnSaverPerm = 0;
//int idleOnLockPerm = 0;
//int idleGLIPerm = 1;
//int idlePrivatePerm = 0;
BOOL (WINAPI * MyGetLastInputInfo)(PLASTINPUTINFO);
unsigned long idleOptsPerm; // C G L S M P L S --LONG-- --SHORT-
unsigned long idleOpts; // C G L S M P L S --LONG-- --SHORT-
static BOOL idleDialogInInit = FALSE;
BOOL InitDialogIdlePart(HWND hwndDlg)
{
// TranslateDialogDefault(hwndDlg);
CheckDlgButton(hwndDlg, IDC_IDLECHECK, (idleOpts&IdleBitsCheck) ? BST_CHECKED : BST_UNCHECKED);
// check/uncheck options
CheckDlgButton(hwndDlg, IDC_IDLEONWINDOWS, (idleOpts&IdleBitsMethod) ? BST_UNCHECKED : BST_CHECKED);
CheckDlgButton(hwndDlg, IDC_IDLEONMIRANDA, (idleOpts&IdleBitsMethod) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_IDLEUSEGLI, (idleOpts&IdleBitsGLI) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_SCREENSAVER, (idleOpts&IdleBitsOnSaver) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_LOCKED, (idleOpts&IdleBitsOnLock) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_IDLESHORT, (idleOpts&IdleBitsFirstOn) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_IDLELONG, (idleOpts&IdleBitsSecondOn) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_IDLEPRIVATE, (idleOpts&IdleBitsPrivate) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_DISBABLEAUTOHERE, (idleOpts&IdleSuppressAutoHere) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_DISABLEIDLEMENU, (idleOpts&IdleSuppressIdleMenu) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_HEREONSTATUSCHANGE, (idleOpts&IdleHereOnStatusChange)? BST_CHECKED : BST_UNCHECKED);
// set times
idleDialogInInit = TRUE;
SetDlgItemInt(hwndDlg, IDC_IDLE1STTIME, GetBits(idleOpts,IdleBitsTimeFirst), FALSE);
SetDlgItemInt(hwndDlg, IDC_IDLE2NDTIME, GetBits(idleOpts,IdleBitsTimeSecond), FALSE);
idleDialogInInit = FALSE;
// enable options
SendMessage(hwndDlg, WM_USER+4, (WPARAM)((idleOpts&IdleBitsCheck)!=0), 0);
return TRUE;
}
// delphi code here http://www.swissdelphicenter.ch/torry/printcode.php?id=2048
/**BOOL IsWorkstationLocked(void)
{
BOOL rc=0;
HDESK hDesk = OpenDesktopA("default", 0, FALSE, DESKTOP_SWITCHDESKTOP);
if ( hDesk != 0 ) {
rc = SwitchDesktop(hDesk) == FALSE;
CloseDesktop(hDesk);
}
return rc;
}**/
// ticks every 2 seconds
int FirstTick;
unsigned long secondsAfterLastActivity;
unsigned long lastIdleEventTime = 0;
int isCurrentlyIdle=0; //0 notidle //1 short //2long
VOID CALLBACK IdleTimer(HWND hwnd, UINT message, UINT_PTR idEvent, DWORD dwTime)
{
DWORD dwTick = GetTickCount();
int isIdle[3] = {0};
static int isEventFired[3] = {0};
int j;
if (FirstTick) {
FirstTick--;
if (FirstTick==0){
int flags = 0;
starting = 1;
switch (isCurrentlyIdle)
{
default : {flags = 0;/*MessageBox(theDialog,"BeHere","Button Pressed",0);*/ break;}
case 1: {flags = IDF_SHORT|IDF_ISIDLE; /*MessageBox(theDialog,"BeAway","Button Pressed",0);*/ break;}
case 2: {flags = IDF_LONG|IDF_ISIDLE; /*MessageBox(theDialog,"BeNA","Button Pressed",0);*/ break;}
}
if (isCurrentlyIdle) {
lastIdleEventTime = db_get_dw(NULL,AA_MODULE,AA_LASTIDLETIME,(DWORD)time(NULL));
secondsAfterLastActivity = time(NULL) - lastIdleEventTime;
} else secondsAfterLastActivity = 0;
flags |= idleOpts&IdleBitsPrivate?IDF_PRIVACY:0;
NotifyEventHooks( hIdleEvent, 0, flags ); //Tell everyone we are here
return;
}
}
for (j = 0 ; j < protoCount ; j++) {
if ( !isInterestingProto(j) ) continue;
if (isWaitingForRestoreStatusMessage[j]) {
isWaitingForRestoreStatusMessage[j]--;
if (!(isWaitingForRestoreStatusMessage[j])) {
#ifdef UNICODE
TCHAR *awayMsg=0;
if (HasAwayMessageW){
awayMsg = (TCHAR *) CallService(MS_AWAYMSG_GETSTATUSMSGW, (WPARAM) courAwayStatus[j], 0);
} else {
char *temp=(char *)CallService(MS_AWAYMSG_GETSTATUSMSG, (WPARAM) courAwayStatus[j], 0);
if ((int)temp == CALLSERVICE_NOTFOUND) awayMsg = 0;
else{
awayMsg = (TCHAR *)mir_alloc((maxMessageLength+1)*sizeof(TCHAR));
my_a2u(temp,awayMsg,maxMessageLength);
mir_free(temp);
}
}
#else
char * awayMsg = (char *) CallService(MS_AWAYMSG_GETSTATUSMSG, (WPARAM) courAwayStatus[j], 0);
if ((int)awayMsg==CALLSERVICE_NOTFOUND) awayMsg = NULL;
#endif
#ifdef AALOG
{
char str[1000];
sprintf(str,"%s: Restoring the default \"StatusMessage\": %s",accounts[j]->szModuleName,awayMsg ? awayMsg : "none");
CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)str);
}
#endif
#ifdef UNICODE
if (protoHasAwayMessageW[j]) CallProtoService(accounts[j]->szModuleName, PS_SETAWAYMSGW, courAwayStatus[j], (LPARAM) awayMsg);
else {
char temp[maxMessageLength+1];
my_u2a(awayMsg,temp,maxMessageLength);
CallProtoService(accounts[j]->szModuleName, PS_SETAWAYMSG, courAwayStatus[j], (LPARAM) temp);
}
#else
CallProtoService(accounts[j]->szModuleName, PS_SETAWAYMSG, courAwayStatus[j], (LPARAM) awayMsg);
#endif
if (awayMsg) {
#ifdef AALOG
char str[1000];
sprintf(str,"%s: Cleaning after MS_AWAYMSG_GETSTATUSMSG: %s",accounts[j]->szModuleName,awayMsg);
CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)str);
#endif
mir_free(awayMsg);
}
}
}
}
TimerProc(); //for the reconnect
secondsAfterLastActivity = 0;
isCurrentlyIdle = 0;
if ( (idleOptsPerm&IdleBitsCheck) == 0 ) return;
if ( (idleOptsPerm&IdleBitsMethod) == 0 ) {
// use windows idle time
if ( GetBits(idleOptsPerm,IdleBitsGLI) && (MyGetLastInputInfo != 0) ) {
LASTINPUTINFO ii;
memset(&ii,0,sizeof(ii));
ii.cbSize=sizeof(ii);
if ( MyGetLastInputInfo(&ii) ) dwTick = ii.dwTime;
} else {
// mouse check
static int mouseIdle = 0;
static POINT lastMousePos = {0};
POINT pt;
GetCursorPos(&pt);
if ( pt.x != lastMousePos.x || pt.y != lastMousePos.y )
{
mouseIdle=0;
lastMousePos=pt;
}
else mouseIdle += 2; // interval of timer
if ( mouseIdle ) dwTick = GetTickCount() - (mouseIdle * 1000);
}
} else {
// use miranda idle time
CallService(MS_SYSTEM_GETIDLE, 0, (LPARAM)&dwTick);
}
secondsAfterLastActivity = (GetTickCount() - dwTick)/1000;
#ifdef AALOG
{ char log[1024];
sprintf(log,"%d seconds after last activity",secondsAfterLastActivity);
CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log);}
#endif
// has the first idle elapsed? If not permited FirstIdle time:ignore
isIdle[0] = (idleOptsPerm&IdleBitsFirstOn)? (secondsAfterLastActivity >= (DWORD)( GetBits(idleOptsPerm,IdleBitsTimeFirst) * 60 )):0;
// and the second? if not permited the SecondIdleTime: idnore
isIdle[1] = (idleOptsPerm&IdleBitsSecondOn)?(secondsAfterLastActivity >= (DWORD)( GetBits(idleOptsPerm,IdleBitsTimeSecond) * 60 )):0;
isIdle[2] = FALSE;
if ( idleOptsPerm&IdleBitsOnSaver ) { // check saver
BOOL isScreenSaverRunning = FALSE;
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &isScreenSaverRunning, FALSE);
isIdle[2] |= isScreenSaverRunning;
}
// check workstation?
if ( idleOptsPerm&IdleBitsOnLock ) { // check station locked?
isIdle[2] |= IsWorkstationLocked();
}
{ //check if the new idle is more idle than the previous idle is idle ;)
int temp = isIdle[1]?2:((isIdle[0] || isIdle[2])?1:0);
if (temp>=isCurrentlyIdle) isCurrentlyIdle = temp;
else return; //if we are alredy idle then exit
}
for ( j = 0; j<3; j++ )
{
int flags = ( idleOptsPerm&IdleBitsPrivate ? IDF_PRIVACY:0 );
switch (j) {
case 0: flags |= IDF_SHORT; break;
case 1: flags |= IDF_LONG; break;
case 2: flags |= IDF_ONFORCE; break;
}
if ( isIdle[j]==1 && isEventFired[j] == 0 ) { // idle and no one knows
isEventFired[j]=1;
NotifyEventHooks( hIdleEvent, 0, IDF_ISIDLE | flags );
}
if ( isIdle[j]==0 && isEventFired[j] == 1 ) { // not idle, no one knows
isEventFired[j]=0;
if ( !(idleOptsPerm&IdleSuppressAutoHere) ) NotifyEventHooks( hIdleEvent, 0, flags );
}
}//for
// {
// int flags = ( idleOptsPerm&IdleBitsPrivate ? IDF_PRIVACY:0 );
// if (isIdle[0]||isIdle[1]||isIdle[2]) flags |= IDF_ISIDLE;
// if (isIdle[0]) flags |= IDF_SHORT;
// if (isIdle[1]) flags |= IDF_LONG;
// if (isIdle[2]) flags |= IDF_ONFORCE;
// NotifyEventHooks( hIdleEvent, 0, flags );
// }
}
INT_PTR IdleGetInfo(WPARAM wParam, LPARAM lParam)
{
MIRANDA_IDLE_INFO * mii = (MIRANDA_IDLE_INFO *) lParam;
if (mii) {
int minutesAfterLastActivity = (time(NULL)-lastIdleEventTime)/60;
#ifdef AALOG
char log[1024];
sprintf(log,"\"%s\": %d came.",
MS_IDLE_GETIDLEINFO,
mii->cbSize/sizeof(mii->cbSize));
CallService("Netlib/Log" ,(WPARAM)hNetlib ,(LPARAM)log);
#endif
if (minutesAfterLastActivity<=0) minutesAfterLastActivity = 1;
//this is the only field with similar meaning in "old" and "new miranda";
if (mii->cbSize/sizeof(mii->cbSize)>=2) mii->idleTime = isCurrentlyIdle?minutesAfterLastActivity:0;
if (mii->cbSize/sizeof(mii->cbSize)>=3) mii->privacy = (idleOptsPerm&IdleBitsPrivate) !=0;
if (mii->cbSize/sizeof(mii->cbSize)>=4) mii->aaStatus = isCurrentlyIdle==1?ID_STATUS_AWAY:(isCurrentlyIdle>1?ID_STATUS_NA:ID_STATUS_ONLINE); //dont know what to with that
if (mii->cbSize/sizeof(mii->cbSize)>=5) mii->aaLock = (idleOptsPerm&IdleSuppressAutoHere) !=0;
if (mii->cbSize/sizeof(mii->cbSize)>=6) mii->idleType = isCurrentlyIdle?1:0;
return 0;
} else return 1;
}
INT_PTR CALLBACK DlgProcOptsIdle(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
InitDialogIdlePart(hwndDlg);
return TRUE;
case WM_USER+4:
{
DWORD nID[] = { IDC_IDLEONWINDOWS,
IDC_IDLEUSEGLI,
IDC_IDLEONMIRANDA,
IDC_SCREENSAVER,
IDC_LOCKED,
IDC_IDLESHORT,
IDC_IDLE1STTIME,
IDC_IDLELONG,
IDC_IDLE2NDTIME//,IDC_IDLEPRIVATE
};
int j;
// enable/disable all sub controls,
for (j = 0; j < sizeof(nID) / sizeof(nID[0]); j++) {
int nEnable = wParam;
switch ( nID[j] ) {
case IDC_IDLEUSEGLI: nEnable &= IsDlgButtonChecked(hwndDlg, IDC_IDLEONWINDOWS) == BST_CHECKED ? 1 : 0; break;
case IDC_IDLE1STTIME: nEnable &= IsDlgButtonChecked(hwndDlg, IDC_IDLESHORT) == BST_CHECKED ? 1 : 0; break;
case IDC_IDLE2NDTIME: nEnable &= IsDlgButtonChecked(hwndDlg, IDC_IDLELONG) == BST_CHECKED ? 1 : 0; break;
}
EnableWindow(GetDlgItem(hwndDlg, nID[j]), nEnable);
}
idleOpts=SetBits(idleOpts,IdleBitsCheck, IsDlgButtonChecked(hwndDlg, IDC_IDLECHECK) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleBitsMethod, IsDlgButtonChecked(hwndDlg, IDC_IDLEONMIRANDA) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleBitsFirstOn, IsDlgButtonChecked(hwndDlg, IDC_IDLESHORT) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleBitsSecondOn, IsDlgButtonChecked(hwndDlg, IDC_IDLELONG) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleBitsGLI, IsDlgButtonChecked(hwndDlg, IDC_IDLEUSEGLI) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleBitsOnSaver, IsDlgButtonChecked(hwndDlg, IDC_SCREENSAVER) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleBitsOnLock, IsDlgButtonChecked(hwndDlg, IDC_LOCKED) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleBitsPrivate, IsDlgButtonChecked(hwndDlg, IDC_IDLEPRIVATE) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleSuppressAutoHere, IsDlgButtonChecked(hwndDlg, IDC_DISBABLEAUTOHERE) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleSuppressIdleMenu, IsDlgButtonChecked(hwndDlg, IDC_DISABLEIDLEMENU) == BST_CHECKED);
idleOpts=SetBits(idleOpts,IdleHereOnStatusChange, IsDlgButtonChecked(hwndDlg, IDC_HEREONSTATUSCHANGE) == BST_CHECKED);
break;
}
case WM_USER+8:
{
if (wParam == IDC_IDLE1STTIME) idleOpts = SetBits(idleOpts,IdleBitsTimeFirst,GetDlgItemInt(hwndDlg, wParam, NULL, FALSE));
if (wParam == IDC_IDLE2NDTIME) idleOpts = SetBits(idleOpts,IdleBitsTimeSecond,GetDlgItemInt(hwndDlg, wParam, NULL, FALSE));
break;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_IDLEBUTTON:
case IDC_IDLEBUTTON+1:
case IDC_IDLEBUTTON+2:SimulateIdle(LOWORD(wParam)-IDC_IDLEBUTTON); break;
case IDC_IDLECHECK:
case IDC_IDLEONWINDOWS:
case IDC_IDLEONMIRANDA:
case IDC_IDLESHORT:
case IDC_IDLELONG:
case IDC_IDLEUSEGLI:
case IDC_SCREENSAVER:
case IDC_LOCKED:
case IDC_IDLEPRIVATE:
case IDC_DISBABLEAUTOHERE:
case IDC_HEREONSTATUSCHANGE:
case IDC_DISABLEIDLEMENU:
{
SendMessage(hwndDlg, WM_USER+4, (WPARAM)IsDlgButtonChecked(hwndDlg, IDC_IDLECHECK) == BST_CHECKED, 0);
break;
}
case IDC_IDLE1STTIME:
case IDC_IDLE2NDTIME:
{
if ( HIWORD(wParam) != EN_CHANGE ) return TRUE;
SendMessage(hwndDlg, WM_USER+8, LOWORD(wParam), 0);
break;
}
}
if (!idleDialogInInit) if ((HIWORD(wParam)==BN_CLICKED)||(HIWORD(wParam)==EN_CHANGE))
{
if ((LOWORD(wParam)!=IDC_IDLEBUTTON)&&(LOWORD(wParam)!=IDC_IDLEBUTTON+1)&&(LOWORD(wParam)!=IDC_IDLEBUTTON+2))
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
break;
case WM_NOTIFY:
switch (((LPNMHDR) lParam)->idFrom) {
case 0:
switch (((LPNMHDR) lParam)->code) {
case PSN_APPLY: {
return TRUE;
}
}
break;
}
break;
case WM_DESTROY:
break;
}
return FALSE;
}
|