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
|
/*
* Smart Auto Replier (SAR) - auto replier plugin for Miranda IM
*
* Copyright (C) 2004 - 2012 by Volodymyr M. Shcherbyna <volodymyr@shcherbyna.com>
*
* This file is part of SAR.
*
* SAR 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 3 of the License, or
* (at your option) any later version.
*
* SAR 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 SAR. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "../resource.h"
#include "addruledlg.h"
#include "addruledlg.h"
#include "selectuserdlg.h"
extern LPTSTR g_strPluginName;
extern CMessagesHandler *g_pMessHandler;
extern CCrushLog CRUSHLOGOBJ;
CAddRuleDlg::CAddRuleDlg(void) : m_dwCRC32(NULL), m_baur2thisMode(false), m_bEditing(false)
{
BEGIN_PROTECT_AND_LOG_CODE
ZeroMemory(&m_item, sizeof(m_item));
END_PROTECT_AND_LOG_CODE
}
CAddRuleDlg::~CAddRuleDlg(void)
{
BEGIN_PROTECT_AND_LOG_CODE
END_PROTECT_AND_LOG_CODE
}
LRESULT CAddRuleDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
BEGIN_PROTECT_AND_LOG_CODE
TranslateDialogDefault(m_hWnd);
m_editRuleName = GetDlgItem(IDC_ED_RULENAME);
m_editContactName = GetDlgItem(IDC_ED_RULECNAME);
m_editReplyText = GetDlgItem(IDC_ED_RULEREPLY);
//m_editReplyAction = GetDlgItem(IDC_ED_RULEACTION);
m_btnSelUser = GetDlgItem(IDC_BTN_SELUSER);
CenterWindow();
if (m_dwCRC32)
{
SetWindowText(TranslateTS(TEXT("Edit rule")));
m_editRuleName.SetWindowText(m_item.RuleName);
m_editContactName.SetWindowText(m_item.ContactName);
m_editReplyText.SetWindowText(m_item.ReplyText);
//m_editReplyAction.SetWindowText(m_item.ReplyAction);
m_bEditing = true;
}
else if (m_baur2thisMode)
{
m_editRuleName.SetWindowText(m_item.RuleName);
m_editContactName.SetWindowText(m_item.ContactName);
m_editReplyText.SetWindowText(m_item.ReplyText);
//m_editReplyAction.SetWindowText(m_item.ReplyAction);
m_btnSelUser.EnableWindow(FALSE);
m_editContactName.EnableWindow(FALSE);
m_editReplyText.SetSel(0, _tcslen(m_item.ReplyText), FALSE);
m_editReplyText.SetFocus();
}
else
{
m_editRuleName.SetWindowText(SETTINGS_DEF_RULE_NAME);
m_editReplyText.SetWindowText(SETTINGS_DEF_MESSAGE_RULE);
}
END_PROTECT_AND_LOG_CODE
return FALSE;
}
LRESULT CAddRuleDlg::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
BEGIN_PROTECT_AND_LOG_CODE
return FALSE;
END_PROTECT_AND_LOG_CODE
}
BOOL CAddRuleDlg::PreTranslateMessage(MSG* pMsg)
{
BEGIN_PROTECT_AND_LOG_CODE
return FALSE;
END_PROTECT_AND_LOG_CODE
}
LRESULT CAddRuleDlg::OnBtnOKClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BEGIN_PROTECT_AND_LOG_CODE
#define ON_ERROR_1BYTE(x) if (x == 1) { \
MessageBox(TranslateTS(TEXT("Please, specify longer contact name")), g_strPluginName, MB_OK); \
return FALSE; }
#define ON_ERROR(x) MessageBox(TranslateTS(x), g_strPluginName, MB_OK); \
return FALSE;
int nLength = m_editRuleName.GetWindowTextLength();
if (nLength)
{
nLength++;
m_item.RuleName = new TCHAR[nLength];
if (m_item.RuleName != NULL)
{
memset(m_item.RuleName, 0, nLength * sizeof(TCHAR));
m_editRuleName.GetWindowText(m_item.RuleName, nLength);
}
}
else
{
ON_ERROR(TEXT("Please, specify Rule Name"))
}
nLength = m_editContactName.GetWindowTextLength();
if (nLength)
{
ON_ERROR_1BYTE(nLength)
nLength++;
m_item.ContactName = new TCHAR[nLength];
if (m_item.ContactName != NULL)
{
memset(m_item.ContactName, 0, nLength * sizeof(TCHAR));
m_editContactName.GetWindowText(m_item.ContactName, nLength);
}
}
else
{
ON_ERROR(TEXT("Please, specify Contact Name"))
}
nLength = m_editReplyText.GetWindowTextLength();
if (nLength)
{
if (nLength > SETTINGS_MESSAGE_MAXVALENGTH)
{
MessageBox(TranslateTS(TEXT("header is too big")), g_strPluginName, MB_OK);
return FALSE;
}
nLength++;
m_item.ReplyText = new TCHAR[nLength];
if (m_item.ContactName != NULL)
{
memset(m_item.ReplyText, 0, nLength * sizeof(TCHAR));
m_editReplyText.GetWindowText(m_item.ReplyText, nLength);
}
}
else
{
ON_ERROR(TEXT("Please, specify Reply Text"))
}
{
if (m_bEditing)
{/// delete prev item from storage...
g_pMessHandler->getSettings().getStorage().RemReplyAction(m_dwCRC32);
}
bool b;
DWORD dwCrc = g_pMessHandler->getSettings().AddReplyAction(m_item, b);
if (b)
{
MessageBox(TranslateTS(TEXT("Rule with the same contact name already exists")), g_strPluginName, MB_OK);
return FALSE;
}
m_bAddedOk = ((b == false) && dwCrc);
m_dwCRC32 = dwCrc;
}
EndDialog(0);
#undef ON_ERROR
#undef ON_ERROR_1BYTE
END_PROTECT_AND_LOG_CODE
return FALSE;
}
LRESULT CAddRuleDlg::OnBtnCancelClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BEGIN_PROTECT_AND_LOG_CODE
m_bAddedOk = false;
EndDialog(0);
END_PROTECT_AND_LOG_CODE
return FALSE;
}
LRESULT CAddRuleDlg::OnBnClickedBtnSeluser(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BEGIN_PROTECT_AND_LOG_CODE
CSelectUserDlg dlg;
dlg.DoModal(m_hWnd);
if (dlg.m_bAllOk == true)
{
m_editContactName.SetWindowText(dlg.m_szRetVal);
m_editReplyText.SetFocus();
}
else
{
m_editContactName.SetFocus();
}
END_PROTECT_AND_LOG_CODE
return 0;
}
|