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
|
/*
KeepStatus Plugin for Miranda-IM (www.miranda-im.org)
Copyright 2003-2006 P. Boon
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 "../commonstatus.h"
#include "keepstatus.h"
#include "../resource.h"
#include <m_trigger.h>
extern HINSTANCE hInst;
static HANDLE hKeepStatusHook;
static INT_PTR CALLBACK DlgProcOptsTriggerKeepStatus(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
/* lParam = (LPARAM)(DWORD)triggerID, or 0 if this is a new trigger */
DWORD triggerID = (DWORD)lParam;
CheckDlgButton(hwndDlg, IDC_CONNLOST, (DBGetTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, 0)&TRIGGER_CONNLOST)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_LOGINERROR, (DBGetTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, 0)&TRIGGER_LOGINERROR)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_OTHERLOC, (DBGetTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, 0)&TRIGGER_OTHERLOC)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CONNRETRY, (DBGetTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, 0)&TRIGGER_CONNRETRY)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CONNSUCCESS, (DBGetTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, 0)&TRIGGER_CONNSUCCESS)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CONNGIVEUP, (DBGetTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, 0)&TRIGGER_CONNGIVEUP)?BST_CHECKED:BST_UNCHECKED);
break;
}
case WM_COMMAND:
break;
case TM_ADDTRIGGER:
{
// wParam = (WPARAM)(DWORD)triggerID
DWORD triggerID;
int flags;
triggerID = (DWORD)wParam;
flags = 0;
flags |= IsDlgButtonChecked(hwndDlg, IDC_CONNLOST)?TRIGGER_CONNLOST:0;
flags |= IsDlgButtonChecked(hwndDlg, IDC_LOGINERROR)?TRIGGER_LOGINERROR:0;
flags |= IsDlgButtonChecked(hwndDlg, IDC_OTHERLOC)?TRIGGER_OTHERLOC:0;
flags |= IsDlgButtonChecked(hwndDlg, IDC_CONNRETRY)?TRIGGER_CONNRETRY:0;
flags |= IsDlgButtonChecked(hwndDlg, IDC_CONNSUCCESS)?TRIGGER_CONNSUCCESS:0;
flags |= IsDlgButtonChecked(hwndDlg, IDC_CONNGIVEUP)?TRIGGER_CONNGIVEUP:0;
DBWriteTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, (WORD)flags);
break;
}
case TM_DELTRIGGER:
{
/* wParam = (WPARAM)(DWORD)triggerID */
// wParam = triggerID
DWORD triggerID;
REMOVETRIGGERSETTINGS rts;
triggerID = (DWORD)wParam;
rts.cbSize = sizeof(REMOVETRIGGERSETTINGS);
rts.prefix = PREFIX_TRIGGERID;
rts.id = triggerID;
rts.hContact = NULL;
rts.szModule = MODULENAME;
CallService(MS_TRIGGER_REMOVESETTINGS, 0, (LPARAM)&rts);
break;
}
case WM_DESTROY:
break;
}
return FALSE;
}
static int KeepStatusEvent(WPARAM wParam, LPARAM lParam) {
DWORD triggerID;
TRIGGERDATA td;
int flags;
triggerID = 0;
do {
triggerID = (DWORD)CallService(MS_TRIGGER_FINDNEXTTRIGGERID, triggerID, (LPARAM)TRIGGERNAME);
if (triggerID == 0)
continue;
ZeroMemory(&td, sizeof(TRIGGERDATA));
td.cbSize = sizeof(TRIGGERDATA);
flags = DBGetTriggerSettingWord(triggerID, NULL, MODULENAME, SETTING_TRIGGERON, 0);
switch (wParam) {
case KS_CONN_STATE_LOST:
if (!(flags&TRIGGER_CONNLOST))
continue;
td.dFlags |= DF_PROTO;
td.szProto = (char *)lParam;
break;
case KS_CONN_STATE_LOGINERROR:
if (!(flags&TRIGGER_LOGINERROR))
continue;
td.dFlags |= DF_PROTO;
td.szProto = (char *)lParam;
break;
case KS_CONN_STATE_OTHERLOCATION:
if (!(flags&TRIGGER_OTHERLOC))
continue;
td.dFlags |= DF_PROTO;
td.szProto = (char *)lParam;
break;
case KS_CONN_STATE_RETRY:
if (!(flags&TRIGGER_CONNRETRY))
continue;
break;
case KS_CONN_STATE_STOPPEDCHECKING:
if ( (lParam) && (!(flags&TRIGGER_CONNSUCCESS)) )
continue;
if ( (!lParam) && (!(flags&TRIGGER_CONNGIVEUP)) )
continue;
break;
default:
continue;
}
REPORTINFO ri = { 0 };
ri.cbSize = sizeof(REPORTINFO);
ri.flags = TRG_PERFORM;
ri.triggerID = triggerID;
ri.td = &td;
CallService(MS_TRIGGER_REPORTEVENT, 0, (LPARAM)&ri);
}
while (triggerID != 0);
return 0;
}
int RegisterTrigger()
{
if (!ServiceExists(MS_TRIGGER_REGISTERTRIGGER))
return -1;
hKeepStatusHook = HookEvent(ME_KS_CONNECTIONEVENT, KeepStatusEvent);
TRIGGERREGISTER tr = { 0 };
tr.cbSize = sizeof(TRIGGERREGISTER);
tr.pszName = TRIGGERNAME;
tr.hInstance = hInst;
tr.pfnDlgProc = DlgProcOptsTriggerKeepStatus;
tr.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_KS_TRIGGER);
tr.dFlags = DF_PROTO;
/* register the trigger at the TriggerPlugin */
CallService(MS_TRIGGER_REGISTERTRIGGER, 0, (LPARAM)&tr);
return 0;
}
int DeInitTrigger()
{
UnhookEvent(hKeepStatusHook);
return 0;
}
|