summaryrefslogtreecommitdiff
path: root/plugins/BuddyPounce/src/options.cpp
blob: 356ed857b96589b0c4057a6b41a258d5fae0582a (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
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
/*
Copyright (C) 2012-21 Miranda NG team (https://miranda-ng.org)

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 version 2
of the License.

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, see <http://www.gnu.org/licenses/>.
*/

#include "stdafx.h"

COptionsDlg::COptionsDlg(int dlgId) :
	CSuper(dlgId),
	m_settings(this, IDC_SETTINGS),
	spin(this, IDC_SPIN, 1024),
	msg1(this, IDC_SETTINGMSG),
	msg2(this, IDC_SETTINGMSG2),
	edtNumber(this, IDC_SETTINGNUMBER),
	chkAdvanced(this, IDC_USEADVANCED),
	chkShowDelivery(this, IDC_SHOWDELIVERYMSGS)
{
	CreateLink(chkAdvanced, g_plugin.bUseAdvanced);
	CreateLink(chkShowDelivery, g_plugin.bShowDelivery);

	m_settings.OnSelChange = Callback(this, &COptionsDlg::onSelChange_Settings);
}

bool COptionsDlg::OnInitDialog()
{
	CSuper::OnInitDialog();

	m_settings.AddString(TranslateT("Send If My Status Is..."));
	m_settings.AddString(TranslateT("Send If They Change Status to..."));
	m_settings.AddString(L"----------------------------");
	m_settings.AddString(TranslateT("Reuse Pounce"));
	m_settings.AddString(TranslateT("Give Up delay"));
	m_settings.AddString(TranslateT("Confirmation Window"));
	m_settings.SetCurSel(g_plugin.getByte(hContact, "LastSetting"));
	onSelChange_Settings(0);
	return true;
}

bool COptionsDlg::OnApply()
{
	CSuper::OnApply();

	saveLastSetting();
	return true;
}

void COptionsDlg::OnDestroy()
{
	if (SendIfMy)
		DestroyWindow(SendIfMy);
	if (SendWhenThey)
		DestroyWindow(SendWhenThey);
}

void COptionsDlg::onSelChange_Settings(CCtrlListBox*)
{
	if (m_bInitialized)
		saveLastSetting();

	int item = m_settings.GetCurSel();
	switch (item) {
	case 0: // Send If My Status Is...
		showAll(false);
		if (m_bInitialized)
			statusModes(true);
		break;

	case 1: // Send If They Change status to
		showAll(false);
		if (m_bInitialized)
			statusModes(false);
		break;

	case 3: // Reuse Pounce
		showAll(true);
		msg1.SetText(TranslateT("Reuse this message? (0 to use it once)"));
		msg2.SetText(TranslateT("Times"));
		edtNumber.SetInt(g_plugin.getByte(hContact, "Reuse"));
		break;

	case 4: // Give Up delay
		showAll(true);
		msg1.SetText(TranslateT("Give up after... (0 to not give up)"));
		msg2.SetText(TranslateT("Days"));
		edtNumber.SetInt(g_plugin.getByte(hContact, "GiveUpDays"));
		break;

	case 5:	// confirm window
		showAll(true);
		msg1.SetText(TranslateT("Show confirmation window? (0 to not Show)"));
		msg2.SetText(TranslateT("Seconds to wait before sending"));
		edtNumber.SetInt(g_plugin.getWord(hContact, "ConfirmTimeout"));
		break;
	}
	g_plugin.setByte(hContact, "LastSetting", (uint8_t)item);
	NotifyChange();
}

void COptionsDlg::saveLastSetting()
{
	switch (g_plugin.getByte(hContact, "LastSetting", 2)) {
	case 3: // Reuse Pounce
		g_plugin.setByte(hContact, "Reuse", (uint8_t)edtNumber.GetInt());
		break;
	case 4: // Give Up delay
		g_plugin.setByte(hContact, "GiveUpDays", (uint8_t)edtNumber.GetInt());
		g_plugin.setDword(hContact, "GiveUpDate", (uint32_t)edtNumber.GetInt() * SECONDSINADAY);
		break;
	case 5:	// confirm window
		g_plugin.setWord(hContact, "ConfirmTimeout", (uint16_t)edtNumber.GetInt());
		break;
	}
}

void COptionsDlg::showAll(bool bShow)
{
	msg1.Show(bShow);
	msg2.Show(bShow);
	spin.Show(bShow);
	edtNumber.Show(bShow);
}

/////////////////////////////////////////////////////////////////////////////////////////
// Status modes dialog wrapper

class CStatusModesDlg : public CDlgBase
{
	COptionsDlg *pDlg;
	bool isMe;

	CCtrlCheck chk1, chk2, chk3, chk4, chk5, chk6, chk7, chk8;

public:
	CStatusModesDlg(COptionsDlg *_1, bool _2) :
		CDlgBase(g_plugin, IDD_STATUSMODES),
		pDlg(_1),
		isMe(_2),
		chk1(this, IDC_CHECK1),
		chk2(this, IDC_CHECK2),
		chk3(this, IDC_CHECK3),
		chk4(this, IDC_CHECK4),
		chk5(this, IDC_CHECK5),
		chk6(this, IDC_CHECK6),
		chk7(this, IDC_CHECK7), 
		chk8(this, IDC_CHECK8)
	{
		SetParent(pDlg->GetHwnd());
	}

	bool OnInitDialog() override
	{
		int statusFlag;

		if (isMe) {
			pDlg->SendIfMy = m_hwnd;
			statusFlag = g_plugin.getWord(pDlg->hContact, "SendIfMyStatusIsFLAG", 0);
			SetCaption(TranslateT("Send If My Status Is"));
			chk1.SetText(TranslateT("Any"));
			chk2.SetText(TranslateT("Online"));
			chk3.SetText(TranslateT("Away"));
			chk4.SetText(TranslateT("Not available"));
			chk5.SetText(TranslateT("Occupied"));
			chk6.SetText(TranslateT("Do not disturb"));
			chk7.SetText(TranslateT("Free for chat"));
			chk8.SetText(TranslateT("Invisible"));
		}
		else {
			pDlg->SendWhenThey = m_hwnd;
			statusFlag = g_plugin.getWord(pDlg->hContact, "SendIfTheirStatusIsFLAG", 0);
			SetCaption(TranslateT("Send If Their Status changes"));
			chk1.SetText(TranslateT("From Offline"));
			chk2.SetText(TranslateT("To Online"));
			chk3.SetText(TranslateT("To Away"));
			chk4.SetText(TranslateT("To Not available"));
			chk5.SetText(TranslateT("To Occupied"));
			chk6.SetText(TranslateT("To Do not disturb"));
			chk7.SetText(TranslateT("To Free for chat"));
			chk8.SetText(TranslateT("To Invisible"));
		}

		chk1.SetState((statusFlag & ANY) != 0);
		chk2.SetState((statusFlag & ONLINE) != 0);
		chk3.SetState((statusFlag & AWAY) != 0);
		chk4.SetState((statusFlag & NA) != 0);
		chk5.SetState((statusFlag & OCCUPIED) != 0);
		chk6.SetState((statusFlag & DND) != 0);
		chk7.SetState((statusFlag & FFC) != 0);
		chk8.SetState((statusFlag & INVISIBLE) != 0);
		return true;
	}

	bool OnApply() override
	{
		int flag = chk1.GetState()
			| (chk2.GetState() << 1)
			| (chk3.GetState() << 2)
			| (chk4.GetState() << 3)
			| (chk5.GetState() << 4)
			| (chk6.GetState() << 5)
			| (chk7.GetState() << 6)
			| (chk8.GetState() << 7);

		if (isMe)
			g_plugin.setWord(pDlg->hContact, "SendIfMyStatusIsFLAG", flag);
		else
			g_plugin.setWord(pDlg->hContact, "SendIfTheirStatusIsFLAG", flag);
		return true;
	}

	void OnDestroy() override
	{
		if (isMe)
			pDlg->SendIfMy = nullptr;
		else
			pDlg->SendWhenThey = nullptr;
	}
};

void COptionsDlg::statusModes(bool isMe)
{
	if (isMe) {
		if (SendIfMy)
			SetForegroundWindow(SendIfMy);
		else
			(new CStatusModesDlg(this, true))->Create();
	}
	else {
		if (SendWhenThey)
			SetForegroundWindow(SendWhenThey);
		else
			(new CStatusModesDlg(this, false))->Create();
	}
}