summaryrefslogtreecommitdiff
path: root/plugins/WhenWasIt/src/notifiers.cpp
blob: 336970b22433252a726f50a5773d162cfa8a8193 (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
/*
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 "commonheaders.h"

void FillPopupData(POPUPDATAT &pd, int dtb)
{
	int popupTimeout = (dtb == 0) ? commonData.popupTimeoutToday : commonData.popupTimeout;

	pd.colorBack = commonData.background;
	pd.colorText = commonData.foreground;
	pd.iSeconds = popupTimeout;
}

void PopupNotifyNoBirthdays()
{
	POPUPDATAT pd = {0};
	FillPopupData(pd, -1);
	pd.lchIcon = GetDTBIcon(-1);

	_tcscpy(pd.lptzContactName, TranslateT("WhenWasIt"));
	_tcscpy(pd.lptzText, TranslateT("No upcoming birthdays."));
	PUAddPopupT(&pd);
}

TCHAR *BuildDTBText(int dtb, TCHAR *name, TCHAR *text, int size)
{
	if (dtb > 1)
		mir_sntprintf(text, size, TranslateT("%s has birthday in %d days."), name, dtb);
	else if (dtb == 1)
		mir_sntprintf(text, size, TranslateT("%s has birthday tomorrow."), name);
	else
		mir_sntprintf(text, size, TranslateT("%s has birthday today."), name);
		
	return text;
}

TCHAR *BuildDABText(int dab, TCHAR *name, TCHAR *text, int size)
{
	if (dab > 1)
		mir_sntprintf(text, size, TranslateT("%s had birthday %d days ago."), name, dab);
	else if (dab == 1)
		mir_sntprintf(text, size, TranslateT("%s had birthday yesterday."), name);
	else
		mir_sntprintf(text, size, TranslateT("%s has birthday today (Should not happen, please report)."), name);
	
	return text;
}

int PopupNotifyBirthday(MCONTACT hContact, int dtb, int age)
{
	if (commonData.bIgnoreSubcontacts && db_mc_isSub(hContact))
		return 0;

	TCHAR *name = pcli->pfnGetContactDisplayName(hContact, 0);

	TCHAR text[1024];
	BuildDTBText(dtb, name, text, SIZEOF(text));
	int gender = GetContactGender(hContact);
	
	POPUPDATAT pd = {0};
	FillPopupData(pd, dtb);
	pd.lchContact = hContact;
	pd.PluginWindowProc = DlgProcPopup;
	pd.lchIcon = GetDTBIcon(dtb);
	
	mir_sntprintf(pd.lptzContactName, SIZEOF(pd.lptzContactName), TranslateT("Birthday - %s"), name);
	TCHAR *sex;
	switch (toupper(gender)) {
	case _T('M'):
		sex = TranslateT("He");
		break;
	case _T('F'):
		sex = TranslateT("She");
		break;
	default:
		sex = TranslateT("He/She");
		break;
	}
	if (age > 0) {
		if (dtb > 0)
			mir_sntprintf(pd.lptzText, SIZEOF(pd.lptzText), TranslateT("%s\n%s will be %d years old."), text, sex, age);
		else
			mir_sntprintf(pd.lptzText, SIZEOF(pd.lptzText), TranslateT("%s\n%s just turned %d."), text, sex, age);
	}
	else
		mir_tstrncpy(pd.lptzText, text, mir_tstrlen(text));
	
	PUAddPopupT(&pd);

	return 0;
}

int PopupNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
{
	if (commonData.bIgnoreSubcontacts && db_mc_isSub(hContact))
		return 0;

	TCHAR *name = pcli->pfnGetContactDisplayName(hContact, 0);

	TCHAR text[1024];
	BuildDABText(dab, name, text, SIZEOF(text));
	int gender = GetContactGender(hContact);
	
	POPUPDATAT pd = {0};
	FillPopupData(pd, dab);
	pd.lchContact = hContact;
	pd.PluginWindowProc = DlgProcPopup;
	pd.lchIcon = GetDTBIcon(dab);
	
	mir_sntprintf(pd.lptzContactName, SIZEOF(pd.lptzContactName), TranslateT("Birthday - %s"), name);
	TCHAR *sex;
	switch (toupper(gender)) {
	case _T('M'): 
		sex = TranslateT("He");
		break;
	case _T('F'):
		sex = TranslateT("She");
		break;
	default:
		sex = TranslateT("He/She");
		break;
	}
	if (age > 0){
		if (dab > 0)
			mir_sntprintf(pd.lptzText, SIZEOF(pd.lptzText), TranslateT("%s\n%s just turned %d."), text, sex, age);
		else
			mir_sntprintf(pd.lptzText, SIZEOF(pd.lptzText), TranslateT("%s\n%s just turned %d."), text, sex, age);
	}
	else 
		mir_tstrncpy(pd.lptzText, text, mir_tstrlen(text));

	PUAddPopupT(&pd);
	return 0;
}

int DialogNotifyBirthday(MCONTACT hContact, int dtb, int age)
{
	TCHAR *name = pcli->pfnGetContactDisplayName(hContact, 0);

	TCHAR text[1024];
	BuildDTBText(dtb, name, text, SIZEOF(text));
	if (!hUpcomingDlg) {
		hUpcomingDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_UPCOMING), NULL, DlgProcUpcoming);
		ShowWindow(hUpcomingDlg, commonData.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
	}

	TUpcomingBirthday data = {0};
	data.name = name;
	data.message = text;
	data.dtb = dtb;
	data.hContact = hContact;
	data.age = age;
	
	SendMessage(hUpcomingDlg, WWIM_ADD_UPCOMING_BIRTHDAY, (WPARAM) &data, NULL);
	return 0;
}

int DialogNotifyMissedBirthday(MCONTACT hContact, int dab, int age)
{
	TCHAR *name = pcli->pfnGetContactDisplayName(hContact, 0);

	TCHAR text[1024];
	BuildDABText(dab, name, text, SIZEOF(text));
	if ( !hUpcomingDlg) {
		hUpcomingDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_UPCOMING), NULL, DlgProcUpcoming);
		ShowWindow(hUpcomingDlg, commonData.bOpenInBackground ? SW_SHOWNOACTIVATE : SW_SHOW);
	}
	
	TUpcomingBirthday data = {0};
	data.name = name;
	data.message = text;
	data.dtb = -dab;
	data.hContact = hContact;
	data.age = age;
	
	SendMessage(hUpcomingDlg, WWIM_ADD_UPCOMING_BIRTHDAY, (WPARAM) &data, NULL);
	return 0;
}

int SoundNotifyBirthday(int dtb)
{
	if (dtb == 0)
		SkinPlaySound(BIRTHDAY_TODAY_SOUND);
	else if (dtb <= commonData.cSoundNearDays)
		SkinPlaySound(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 (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
		if (oldClistIcon != -1)
			ExtraIcon_Clear(hWWIExtraIcons, hContact);

		RefreshContactListIcons(hContact); //will change bBirthdayFound if needed
	}
	return 0;
}