summaryrefslogtreecommitdiff
path: root/src/modules/metacontacts/meta_options.cpp
blob: 2dbcfd32c224ab823c8efd6051e4d77ec83dcfae (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
/*
former MetaContacts Plugin for Miranda IM.

Copyright © 2014 Miranda NG Team
Copyright © 2004-07 Scott Ellis
Copyright © 2004 Universite Louis PASTEUR, STRASBOURG.

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 "..\..\core\commonheaders.h"

#include "metacontacts.h"

MetaOptions options;
MetaOptions options_changes;

INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch ( msg ) {
	case WM_INITDIALOG:
		TranslateDialogDefault( hwndDlg );
		options_changes = options;

		CheckDlgButton(hwndDlg, IDC_CHK_SUPPRESSSTATUS, options_changes.bSuppressStatus);

		CheckDlgButton(hwndDlg, IDC_RAD_UID, options_changes.menu_contact_label == DNT_UID);
		CheckDlgButton(hwndDlg, IDC_RAD_DID, options_changes.menu_contact_label == DNT_DID);

		CheckDlgButton(hwndDlg, IDC_RAD_MSG, options_changes.menu_function == FT_MSG);
		CheckDlgButton(hwndDlg, IDC_RAD_MENU, options_changes.menu_function == FT_MENU);
		CheckDlgButton(hwndDlg, IDC_RAD_INFO, options_changes.menu_function == FT_INFO);

		CheckDlgButton(hwndDlg, IDC_RAD_NICK, options_changes.clist_contact_name == CNNT_NICK);
		CheckDlgButton(hwndDlg, IDC_RAD_NAME, options_changes.clist_contact_name == CNNT_DISPLAYNAME);
		CheckDlgButton(hwndDlg, IDC_CHK_LOCKHANDLE, options_changes.bLockHandle);
		{
			TCHAR buff[40];
			_itot(options_changes.days_history, buff, SIZEOF(buff));
			SetDlgItemText(hwndDlg, IDC_ED_DAYS, buff);
		}
		return TRUE;

	case WM_COMMAND:
		if (HIWORD(wParam) == BN_CLICKED) {
			switch (LOWORD(wParam)) {
			case IDC_CHK_SUPPRESSSTATUS:
				options_changes.bSuppressStatus = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUPPRESSSTATUS) != 0;
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			case IDC_RAD_UID:
				if (IsDlgButtonChecked(hwndDlg, IDC_RAD_UID)) {
					options_changes.menu_contact_label = DNT_UID;
					CheckDlgButton(hwndDlg, IDC_RAD_DID, FALSE);
				}
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			case IDC_RAD_DID:
				if (IsDlgButtonChecked(hwndDlg, IDC_RAD_DID)) {
					options_changes.menu_contact_label = DNT_DID;
					CheckDlgButton(hwndDlg, IDC_RAD_UID, FALSE);
				}
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			case IDC_RAD_MSG:
				if (IsDlgButtonChecked(hwndDlg, IDC_RAD_MSG)) {
					options_changes.menu_function = FT_MSG;
					CheckDlgButton(hwndDlg, IDC_RAD_MENU, FALSE);
					CheckDlgButton(hwndDlg, IDC_RAD_INFO, FALSE);
				}
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			case IDC_RAD_MENU:
				if (IsDlgButtonChecked(hwndDlg, IDC_RAD_MENU)) {
					options_changes.menu_function = FT_MENU;
					CheckDlgButton(hwndDlg, IDC_RAD_MSG, FALSE);
					CheckDlgButton(hwndDlg, IDC_RAD_INFO, FALSE);
				}
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			case IDC_RAD_INFO:
				if (IsDlgButtonChecked(hwndDlg, IDC_RAD_INFO)) {
					options_changes.menu_function = FT_INFO;
					CheckDlgButton(hwndDlg, IDC_RAD_MSG, FALSE);
					CheckDlgButton(hwndDlg, IDC_RAD_MENU, FALSE);
				}
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			case IDC_RAD_NICK:
				if (IsDlgButtonChecked(hwndDlg, IDC_RAD_NICK)) {
					options_changes.clist_contact_name = CNNT_NICK;
					CheckDlgButton(hwndDlg, IDC_RAD_NAME, FALSE);
				}
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			case IDC_RAD_NAME:
				if (IsDlgButtonChecked(hwndDlg, IDC_RAD_NAME)) {
					options_changes.clist_contact_name = CNNT_DISPLAYNAME;
					CheckDlgButton(hwndDlg, IDC_RAD_NICK, FALSE);
				}
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;

			case IDC_CHK_LOCKHANDLE:
				options_changes.bLockHandle = IsDlgButtonChecked(hwndDlg, IDC_CHK_LOCKHANDLE) != 0;
				SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
			}
		}
		else if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) {
			SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0);
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == PSN_APPLY ) {
			TCHAR buff[40];
			GetDlgItemText(hwndDlg, IDC_ED_DAYS, buff, SIZEOF(buff));
			if (buff[0] != 0)
				options_changes.days_history = _ttoi(buff);

			options = options_changes;
			Meta_WriteOptions(&options);

			Meta_SuppressStatus(options.bSuppressStatus);
			Meta_SetAllNicks();
			return TRUE;
		}
		break;
	}

	return FALSE;
}

int Meta_WriteOptions(MetaOptions *opt)
{
	db_set_b(NULL, META_PROTO, "SuppressStatus", opt->bSuppressStatus);
	db_set_w(NULL, META_PROTO, "MenuContactLabel", (WORD)opt->menu_contact_label);
	db_set_w(NULL, META_PROTO, "MenuContactFunction", (WORD)opt->menu_function);
	db_set_w(NULL, META_PROTO, "CListContactName", (WORD)opt->clist_contact_name);
	db_set_dw(NULL, META_PROTO, "DaysHistory", (DWORD)(opt->days_history));
	db_set_dw(NULL, META_PROTO, "SetStatusFromOfflineDelay", (DWORD)(opt->set_status_from_offline_delay));
	db_set_b(NULL, META_PROTO, "LockHandle", opt->bLockHandle);
	return 0;
}

int Meta_ReadOptions(MetaOptions *opt)
{
	db_mc_enable(db_get_b(NULL, META_PROTO, "Enabled", true) != 0);
	opt->bSuppressStatus = db_get_b(NULL, META_PROTO, "SuppressStatus", true) != 0;
	opt->menu_contact_label = (int)db_get_w(NULL, META_PROTO, "MenuContactLabel", DNT_UID);
	opt->menu_function = (int)db_get_w(NULL, META_PROTO, "MenuContactFunction", FT_MENU);
	opt->clist_contact_name = (int)db_get_w(NULL, META_PROTO, "CListContactName", CNNT_DISPLAYNAME);
	opt->days_history = (int)db_get_dw(NULL, META_PROTO, "DaysHistory", 0);
	opt->set_status_from_offline_delay = (int)db_get_dw(NULL, META_PROTO, "SetStatusFromOfflineDelay", DEFAULT_SET_STATUS_SLEEP_TIME);
	opt->bLockHandle = db_get_b(NULL, META_PROTO, "LockHandle", false) != 0;
	return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////

int Meta_OptInit(WPARAM wParam, LPARAM)
{
	OPTIONSDIALOGPAGE odp = { sizeof(odp) };
	odp.position = -790000000;
	odp.hInstance = hInst;
	odp.flags = ODPF_BOLDGROUPS;

	odp.pszTemplate = MAKEINTRESOURCEA(IDD_METAOPTIONS);
	odp.pszTitle = LPGEN("Metacontacts");
	odp.pszGroup = LPGEN("Contacts");
	odp.pfnDlgProc = DlgProcOpts;
	Options_AddPage(wParam, &odp);
	return 0;
}