summaryrefslogtreecommitdiff
path: root/plugins/ClientChangeNotify/src/OptDlg.cpp
blob: 996c5eab39297a6d5ac2b8bb976c229510adb349 (plain)
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
/*
	ClientChangeNotify - Plugin for Miranda IM
	Copyright (c) 2006-2008 Chervov Dmitry

    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 "Common.h"

// ================================================ Popup options ================================================

COptPage g_PopupOptPage(MOD_NAME, NULL);


void EnablePopupOptDlgControls()
{
	int I;
	g_PopupOptPage.PageToMem();
	int UsePopups = g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_POPUPNOTIFY);
	for (I = 0; I < g_PopupOptPage.Items.GetSize(); I++)
	{
		switch (g_PopupOptPage.Items[I]->GetParam())
		{
			case IDC_POPUPOPTDLG_POPUPNOTIFY:
			{
				g_PopupOptPage.Items[I]->Enable(UsePopups);
			} break;
			case IDC_POPUPOPTDLG_DEFBGCOLOUR:
			{
				g_PopupOptPage.Items[I]->Enable(UsePopups && !g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_DEFBGCOLOUR));
			} break;
			case IDC_POPUPOPTDLG_DEFTEXTCOLOUR:
			{
				g_PopupOptPage.Items[I]->Enable(UsePopups && !g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_DEFTEXTCOLOUR));
			} break;
		}
	}
	if (g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_VERCHGNOTIFY))
	{
		COptItem *ShowVer = g_PopupOptPage.Find(IDC_POPUPOPTDLG_SHOWVER);
		ShowVer->SetValue(1);
		ShowVer->Enable(false);
		ShowVer->MemToWnd(g_PopupOptPage.hWnd);
	}
	if (!bFingerprintExists)
	{ // disable these checkboxes if Fingerprint wasn't found
		g_PopupOptPage.Find(IDC_POPUPOPTDLG_VERCHGNOTIFY)->Enable(false);
		g_PopupOptPage.Find(IDC_POPUPOPTDLG_SHOWVER)->Enable(false);
	}
	SetDlgItemText(g_PopupOptPage.GetWnd(), IDC_POPUPOPTDLG_STATIC_REGEXP, TranslateT("(you can use regular expressions here)"));
	g_PopupOptPage.MemToPage(true);
	InvalidateRect(GetDlgItem(g_PopupOptPage.GetWnd(), IDC_POPUPOPTDLG_POPUPDELAY_SPIN), NULL, false); // update spin control
}

static struct {
	TCHAR *Text;
	int Action;
}
PopupActions[] = 
{
	LPGENT("Open message window"), PCA_OPENMESSAGEWND,
	LPGENT("Close popup"), PCA_CLOSEPOPUP,
	LPGENT("Open contact details window"), PCA_OPENDETAILS,
	LPGENT("Open contact menu"), PCA_OPENMENU,
	LPGENT("Open contact history"), PCA_OPENHISTORY,
	LPGENT("Do nothing"), PCA_DONOTHING
};

INT_PTR CALLBACK PopupOptDlg(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static int ChangeLock = 0;
	switch (msg) {
	case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			ChangeLock++;
			g_PopupOptPage.SetWnd(hwndDlg);
			SendDlgItemMessage(hwndDlg, IDC_POPUPOPTDLG_POPUPDELAY, EM_LIMITTEXT, 4, 0);
			SendDlgItemMessage(hwndDlg, IDC_POPUPOPTDLG_IGNORESTRINGS, EM_LIMITTEXT, IGNORESTRINGS_MAX_LEN, 0);
			SendDlgItemMessage(hwndDlg, IDC_POPUPOPTDLG_POPUPDELAY_SPIN, UDM_SETRANGE32, -1, 9999);

			HWND hLCombo = GetDlgItem(hwndDlg, IDC_POPUPOPTDLG_LCLICK_ACTION);
			HWND hRCombo = GetDlgItem(hwndDlg, IDC_POPUPOPTDLG_RCLICK_ACTION);
			int I;
			for (I = 0; I < lengthof(PopupActions); I++) {
				SendMessage(hLCombo, CB_SETITEMDATA, SendMessage(hLCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(PopupActions[I].Text)), PopupActions[I].Action);
				SendMessage(hRCombo, CB_SETITEMDATA, SendMessage(hRCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(PopupActions[I].Text)), PopupActions[I].Action);
			}
			g_PopupOptPage.DBToMemToPage();
			EnablePopupOptDlgControls();
			ChangeLock--;
		}
		return true;

	case WM_NOTIFY:
		switch (((NMHDR*)lParam)->code) {
		case PSN_APPLY: 
			g_PopupOptPage.PageToMemToDB();
			RecompileRegexps(*(TCString*)g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_IGNORESTRINGS));
			return true;
		}
		break;

	case WM_COMMAND:
		switch (HIWORD(wParam)) {
		case BN_CLICKED:
			switch (LOWORD(wParam)) {
			case IDC_POPUPOPTDLG_POPUPNOTIFY:
			case IDC_POPUPOPTDLG_DEFBGCOLOUR:
			case IDC_POPUPOPTDLG_DEFTEXTCOLOUR:
			case IDC_POPUPOPTDLG_VERCHGNOTIFY:
				EnablePopupOptDlgControls();
				// go through

			case IDC_POPUPOPTDLG_SHOWPREVCLIENT:
			case IDC_POPUPOPTDLG_SHOWVER:
			case IDC_POPUPOPTDLG_USESTATUSNOTIFYFLAG:
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
				return 0;
				
			case IDC_POPUPOPTDLG_POPUPPREVIEW:
				g_PreviewOptPage = new COptPage(g_PopupOptPage);
				g_PreviewOptPage->PageToMem();
				DBCONTACTWRITESETTING cws = {0};
				cws.szModule = "ICQ";
				cws.szSetting = DB_MIRVER;
				db_set_s(NULL, MOD_NAME, DB_OLDMIRVER, "ICQ Lite v5");
				ContactSettingChanged(NULL, (LPARAM)&cws); // simulate a version change
				delete g_PreviewOptPage;
				g_PreviewOptPage = NULL;
				break;
			}
			break;
		
		case EN_CHANGE:
			if (LOWORD(wParam) == IDC_POPUPOPTDLG_POPUPDELAY || LOWORD(wParam) == IDC_POPUPOPTDLG_IGNORESTRINGS)
				if (!ChangeLock && g_PopupOptPage.GetWnd())
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);

			break;

		case CBN_SELCHANGE:
			if ((LOWORD(wParam) == IDC_POPUPOPTDLG_LCLICK_ACTION) || (LOWORD(wParam) == IDC_POPUPOPTDLG_RCLICK_ACTION) || (LOWORD(wParam) == IDC_POPUPOPTDLG_BGCOLOUR) || (LOWORD(wParam) == IDC_POPUPOPTDLG_TEXTCOLOUR))
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);

			break;
		}
		break;
		
	case WM_DESTROY:
		g_PopupOptPage.SetWnd(NULL);
		return 0;
	}
	return 0;
}

int OptionsDlgInit(WPARAM wParam, LPARAM lParam)
{
	if (bPopupExists) {
		OPTIONSDIALOGPAGE optDi = { sizeof(optDi) };
		optDi.position = 920000000;
		optDi.ptszTitle = LPGENT("ClientChangeNotify");
		optDi.pfnDlgProc = PopupOptDlg;
		optDi.pszTemplate = MAKEINTRESOURCEA(IDD_POPUPOPTDLG);
		optDi.hInstance = g_hInstance;
		optDi.ptszGroup = LPGENT("Popups");
		optDi.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
		Options_AddPage(wParam, &optDi);
	}
	return 0;
}

void InitOptions()
{
	g_PopupOptPage.Items.AddElem(new COptItem_Checkbox(IDC_POPUPOPTDLG_POPUPNOTIFY, "PopupNotify", DBVT_BYTE, 1));
	g_PopupOptPage.Items.AddElem(new COptItem_Checkbox(IDC_POPUPOPTDLG_SHOWPREVCLIENT, "ShowPrevClient", DBVT_BYTE, 0, 0, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Checkbox(IDC_POPUPOPTDLG_VERCHGNOTIFY, "VerChgNotify", DBVT_BYTE, 0, 0, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Checkbox(IDC_POPUPOPTDLG_SHOWVER, "ShowVer", DBVT_BYTE, 1, 0, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Checkbox(IDC_POPUPOPTDLG_USESTATUSNOTIFYFLAG, "UseStatusNotifyFlag", DBVT_BYTE, 1, 0, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_POPUPPREVIEW, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Combobox(IDC_POPUPOPTDLG_LCLICK_ACTION, "PopupLClickAction", DBVT_BYTE, POPUP_DEF_LCLICKACTION, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Combobox(IDC_POPUPOPTDLG_RCLICK_ACTION, "PopupRClickAction", DBVT_BYTE, POPUP_DEF_RCLICKACTION, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_LCLICK, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_RCLICK, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Colourpicker(IDC_POPUPOPTDLG_BGCOLOUR, "PopupBGColour", POPUP_DEF_POPUP_BGCOLOUR, IDC_POPUPOPTDLG_DEFBGCOLOUR));
	g_PopupOptPage.Items.AddElem(new COptItem_Colourpicker(IDC_POPUPOPTDLG_TEXTCOLOUR, "PopupTextColour", POPUP_DEF_POPUP_TEXTCOLOUR, IDC_POPUPOPTDLG_DEFTEXTCOLOUR));
	g_PopupOptPage.Items.AddElem(new COptItem_Checkbox(IDC_POPUPOPTDLG_DEFBGCOLOUR, "UseDefBGColour", DBVT_BYTE, POPUP_DEF_USEDEFBGCOLOUR, 0, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Checkbox(IDC_POPUPOPTDLG_DEFTEXTCOLOUR, "UseDefTextColour", DBVT_BYTE, POPUP_DEF_USEDEFTEXTCOLOUR, 0, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_BGCOLOUR, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_TEXTCOLOUR, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_IntEdit(IDC_POPUPOPTDLG_POPUPDELAY, "PopupDelay", DBVT_WORD, true, POPUP_DEF_POPUPDELAY, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_SEC, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_DEFAULT, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_INFINITE, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_IGNORESTRINGS, IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Edit(IDC_POPUPOPTDLG_IGNORESTRINGS, DB_IGNORESUBSTRINGS, IGNORESTRINGS_MAX_LEN, _T("gmail;skype;/Miranda[0-9A-F]{8}/"), IDC_POPUPOPTDLG_POPUPNOTIFY));
	g_PopupOptPage.Items.AddElem(new COptItem_Generic(IDC_POPUPOPTDLG_STATIC_REGEXP, IDC_POPUPOPTDLG_POPUPNOTIFY));
}