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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
/*
WhenWasIt (birthday reminder) plugin for Miranda IM
Copyright © 2006 Cristian Libotean
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 "stdafx.h"
void FillPopupData(POPUPDATAW &ppd, int dtb)
{
int popupTimeout = (dtb == 0) ? g_plugin.popupTimeoutToday : g_plugin.popupTimeout;
ppd.colorBack = g_plugin.background;
ppd.colorText = g_plugin.foreground;
ppd.iSeconds = popupTimeout;
}
void PopupNotifyNoBirthdays()
{
POPUPDATAW ppd;
FillPopupData(ppd, -1);
ppd.lchIcon = GetDTBIcon(-1);
wcsncpy(ppd.lpwzContactName, TranslateT("WhenWasIt"), MAX_CONTACTNAME - 1);
wcsncpy(ppd.lpwzText, TranslateT("No upcoming birthdays."), MAX_SECONDLINE - 1);
PUAddPopupW(&ppd);
}
wchar_t *BuildDTBText(int dtb, wchar_t *name, wchar_t *text, int size)
{
if (dtb > 1)
mir_snwprintf(text, size, TranslateT("%s has birthday in %d days."), name, dtb);
else if (dtb == 1)
mir_snwprintf(text, size, TranslateT("%s has birthday tomorrow."), name);
else
mir_snwprintf(text, size, TranslateT("%s has birthday today."), name);
return text;
}
wchar_t *BuildDABText(int dab, wchar_t *name, wchar_t *text, int size)
{
if (dab > 1)
mir_snwprintf(text, size, TranslateT("%s had birthday %d days ago."), name, dab);
else if (dab == 1)
mir_snwprintf(text, size, TranslateT("%s had birthday yesterday."), name);
else
mir_snwprintf(text, size, TranslateT("%s has birthday today (Should not happen, please report)."), name);
return text;
}
int PopupNotifyBirthday(MCONTACT hContact, int dtb, int age)
{
if (g_plugin.bIgnoreSubcontacts && db_mc_isSub(hContact))
return 0;
wchar_t *name = Clist_GetContactDisplayName(hContact);
wchar_t text[1024];
BuildDTBText(dtb, name, text, _countof(text));
int gender = GetContactGender(hContact);
POPUPDATAW ppd;
FillPopupData(ppd, dtb);
ppd.lchContact = hContact;
ppd.PluginWindowProc = DlgProcPopup;
ppd.lchIcon = GetDTBIcon(dtb);
mir_snwprintf(ppd.lpwzContactName, MAX_CONTACTNAME, TranslateT("Birthday - %s"), name);
wchar_t *sex;
switch (toupper(gender)) {
case 'M':
sex = TranslateT("He");
break;
case 'F':
sex = TranslateT("She");
break;
default:
sex = TranslateT("He/She");
break;
}
if (age > 0) {
if (dtb > 0)
mir_snwprintf(ppd.lpwzText, MAX_SECONDLINE, TranslateT("%s\n%s will be %d years old."), text, sex, age);
else
mir_snwprintf(ppd.lpwzText, MAX_SECONDLINE, TranslateT("%s\n%s just turned %d."), text, sex, age);
}
else
mir_wstrncpy(ppd.lpwzText, text, MAX_SECONDLINE - 1);
PUAddPopupW(&ppd);
return 0;
}
int PopupNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
{
if (g_plugin.bIgnoreSubcontacts && db_mc_isSub(hContact))
return 0;
wchar_t *name = Clist_GetContactDisplayName(hContact);
wchar_t text[1024];
BuildDABText(dab, name, text, _countof(text));
int gender = GetContactGender(hContact);
POPUPDATAW ppd;
FillPopupData(ppd, dab);
ppd.lchContact = hContact;
ppd.PluginWindowProc = DlgProcPopup;
ppd.lchIcon = GetDTBIcon(dab);
mir_snwprintf(ppd.lpwzContactName, MAX_CONTACTNAME, TranslateT("Birthday - %s"), name);
wchar_t *sex;
switch (toupper(gender)) {
case 'M':
sex = TranslateT("He");
break;
case 'F':
sex = TranslateT("She");
break;
default:
sex = TranslateT("He/She");
break;
}
if (age > 0)
mir_snwprintf(ppd.lpwzText, MAX_SECONDLINE, TranslateT("%s\n%s just turned %d."), text, sex, age);
else
mir_wstrncpy(ppd.lpwzText, text, MAX_SECONDLINE - 1);
PUAddPopupW(&ppd);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
static class CUpcomingDlg *g_pUpcomingDlg = nullptr;
class CUpcomingDlg : public CBasicListDlg
{
int timeout;
CTimer m_timer;
public:
CUpcomingDlg() :
CBasicListDlg(IDD_UPCOMING),
m_timer(this, 1002)
{
SetMinSize(400, 160);
m_timer.OnEvent = Callback(this, &CUpcomingDlg::onTimer);
}
bool OnInitDialog() override
{
Window_SetIcon_IcoLib(m_hwnd, hListMenu);
g_pUpcomingDlg = this;
timeout = g_plugin.cDlgTimeout;
m_list.SetExtendedListViewStyleEx(LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
LVCOLUMN col;
col.mask = LVCF_TEXT | LVCF_WIDTH;
col.pszText = TranslateT("Contact");
col.cx = 300;
m_list.InsertColumn(0, &col);
col.pszText = TranslateT("Age");
col.cx = 45;
m_list.InsertColumn(1, &col);
col.pszText = TranslateT("DTB");
col.cx = 45;
m_list.InsertColumn(2, &col);
m_list.SetColumnWidth(0, LVSCW_AUTOSIZE);
if (timeout > 0)
m_timer.Start(1000);
Utils_RestoreWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayListUpcoming");
return true;
}
void OnDestroy() override
{
g_pUpcomingDlg = nullptr;
Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "BirthdayListUpcoming");
Window_FreeIcon_IcoLib(m_hwnd);
m_timer.Stop();
}
void OnResize() override
{
RECT rcWin;
GetWindowRect(m_hwnd, &rcWin);
int cx = rcWin.right - rcWin.left;
int cy = rcWin.bottom - rcWin.top;
SetWindowPos(m_list.GetHwnd(), nullptr, 0, 0, (cx - 30), (cy - 80), (SWP_NOZORDER | SWP_NOMOVE));
m_list.SetColumnWidth(0, (cx - 150));
SetWindowPos(GetDlgItem(m_hwnd, IDOK), nullptr, ((cx / 2) - 95), (cy - 67), 0, 0, SWP_NOSIZE);
RedrawWindow(m_hwnd, nullptr, nullptr, (RDW_FRAME | RDW_INVALIDATE));
}
void onTimer(CTimer *)
{
const int MAX_SIZE = 512;
wchar_t buffer[MAX_SIZE];
timeout--;
mir_snwprintf(buffer, (timeout != 2) ? TranslateT("Closing in %d seconds") : TranslateT("Closing in %d second"), timeout);
SetDlgItemText(m_hwnd, IDOK, buffer);
if (timeout <= 0)
Close();
}
void AddBirthDay(MCONTACT hContact, wchar_t *message, int dtb, int age)
{
LVFINDINFO fi = { 0 };
fi.flags = LVFI_PARAM;
fi.lParam = (LPARAM)hContact;
if (-1 != m_list.FindItem(-1, &fi))
return; /* Allready in list. */
int index = m_list.GetItemCount();
LVITEM item = { 0 };
item.iItem = index;
item.mask = LVIF_PARAM | LVIF_TEXT;
item.lParam = (LPARAM)hContact;
item.pszText = message;
m_list.InsertItem(&item);
wchar_t buffer[512];
mir_snwprintf(buffer, L"%d", age);
m_list.SetItemText(index, 1, buffer);
mir_snwprintf(buffer, L"%d", dtb);
m_list.SetItemText(index, 2, buffer);
Sort(2);
}
};
int DialogNotifyBirthday(MCONTACT hContact, int dtb, int age)
{
wchar_t text[1024];
BuildDABText(dtb, Clist_GetContactDisplayName(hContact), text, _countof(text));
if (!g_pUpcomingDlg) {
g_pUpcomingDlg = new CUpcomingDlg();
g_pUpcomingDlg->Show(g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
g_pUpcomingDlg->AddBirthDay(hContact, text, dtb, age);
return 0;
}
int DialogNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
{
wchar_t text[1024];
BuildDABText(dab, Clist_GetContactDisplayName(hContact), text, _countof(text));
if (!g_pUpcomingDlg) {
g_pUpcomingDlg = new CUpcomingDlg();
g_pUpcomingDlg->Show(g_plugin.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
}
g_pUpcomingDlg->AddBirthDay(hContact, text, -dab, age);
return 0;
}
void CloseUpcoming()
{
if (g_pUpcomingDlg)
g_pUpcomingDlg->Close();
}
int SoundNotifyBirthday(int dtb)
{
if (dtb == 0)
Skin_PlaySound(BIRTHDAY_TODAY_SOUND);
else if (dtb <= g_plugin.cSoundNearDays)
Skin_PlaySound(BIRTHDAY_NEAR_SOUND);
return 0;
}
//if oldClistIcon != -1 it will remove the old location of the clist extra icon
//called with oldClistIcon != -1 from dlg_handlers whtn the extra icon slot changes.
int RefreshAllContactListIcons(int oldClistIcon)
{
for (auto &hContact : Contacts()) {
if (oldClistIcon != -1)
ExtraIcon_Clear(hWWIExtraIcons, hContact);
RefreshContactListIcons(hContact); //will change bBirthdayFound if needed
}
return 0;
}
|