summaryrefslogtreecommitdiff
path: root/Plugins/smcnotify/menu.c
blob: ae74ea8a01116609d42b9d00f149822d3ae75769 (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
/*
Status Message Change Notify plugin for Miranda IM.

Copyright © 2004-2005 NoName
Copyright © 2005-2006 Daniel Vijge, Tomasz S³otwiñski, Ricardo Pescuma Domenecci

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"


int hmPopups;
int hmShowList;
int hmGoToURL;

char *pszStatusMsgURL;

char *pszIconId[ICONCOUNT] = {"smcnotify_pope", "smcnotify_popd", "smcnotify_list", "smcnotify_url", "smcnotify_history", "smcnotify_log"};

extern void LoadIcons(void) {
	SKINICONDESC sid;

	TCHAR *ptszIconName[ICONCOUNT] = {
		TranslateT("PopUps Enabled"),
		TranslateT("PopUps Disabled"),
		TranslateT("List Contacts"),
		TranslateT("Go To URL"),
		TranslateT("Status Message History"),
		TranslateT("Log To File")
	};
	int iIconId[ICONCOUNT] = {IDI_POPUP, IDI_NOPOPUP, IDI_LIST, IDI_URL, IDI_HISTORY, IDI_LOG};
	int i;
	ZeroMemory(&sid, sizeof(sid));
	sid.cbSize = sizeof(sid);
	sid.flags = SIDF_TCHAR;
	sid.ptszSection = TranslateT(PLUGIN_NAME);
	for (i = 0; i < ICONCOUNT; i++)
	{
		sid.pszName = pszIconId[i];
		sid.ptszDescription = ptszIconName[i];
		sid.hDefaultIcon = LoadIcon(hInst, MAKEINTRESOURCE(iIconId[i]));
		hLibIcons[i] = (HANDLE)CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
	}

	return;
}

static void UpdateMenuItems(BOOL set) {
	CLISTMENUITEM mi;

	ZeroMemory(&mi, sizeof(mi));
	mi.cbSize = sizeof(mi);
	if (set)
	{
		mi.pszName = Translate("Disable status message change notification");
		mi.hIcon = ICO_POPUP_E;
	}
	else
	{
		mi.pszName = Translate("Enable status message change notification");
		mi.hIcon = ICO_POPUP_D;
	}
	puopts.bEnable = set;
	mi.flags = CMIM_NAME | CMIM_ICON;
	CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hmPopups, (LPARAM)&mi);

	return;
}

extern void InitMenuItems(void) {
	CLISTMENUITEM mi;

	ZeroMemory(&mi, sizeof(mi));
	mi.cbSize = sizeof(mi);
//	mi.flags = CMIF_ICONFROMICOLIB;

	if (PopupActive)
	{
		//Disable/Enable status message change notification
		mi.position = 0;
//		mi.icolibItem = ICO_POPUP_E;
		mi.pszPopupName = Translate("PopUps");
		mi.pszService = MS_SMCNOTIFY_POPUPS;
		hmPopups = CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM)&mi);

		mi.ptszPopupName = NULL;
	}

	mi.flags = CMIF_TCHAR | CMIF_ICONFROMICOLIB;

	//List Contacts with Status Message - main menu
	mi.position = 500021000;
	mi.icolibItem = ICO_LIST;
	mi.ptszName = TranslateT("List Contacts with Status Message");
	mi.pszService = MS_SMCNOTIFY_LIST;
	hmShowList = CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM)&mi);

	mi.pszContactOwner = NULL;

	//Go To URL in Status Message - contact menu
	mi.position = -2000004000;
	mi.icolibItem = ICO_URL;
	mi.ptszName = TranslateT("Go To URL in Status Message");
	mi.pszService = MS_SMCNOTIFY_GOTOURL;
	hmGoToURL = CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM)&mi);

	UpdateMenuItems(puopts.bEnable);
	return;
}

int MenuItemCmd_PopUps(WPARAM wParam, LPARAM lParam) {
	UpdateMenuItems(wParam ? lParam : !puopts.bEnable);
	return 0;
}

int MenuItemCmd_ShowList(WPARAM wParam, LPARAM lParam) {
	ShowList();
	return 0;
}

int MenuItemCmd_GoToURL(WPARAM wParam, LPARAM lParam) {
	CallService(MS_UTILS_OPENURL, 1, (LPARAM)pszStatusMsgURL);
	MIR_FREE(pszStatusMsgURL);

	return 0;
}

extern int PreBuildCMenu(WPARAM wParam, LPARAM lParam) {
	DBVARIANT dbv;
	CLISTMENUITEM clmi;
	char *str, *p;
	int c;
	str = NULL;

	ZeroMemory(&clmi, sizeof(clmi));
	clmi.cbSize = sizeof(clmi);
	clmi.flags = CMIM_FLAGS | CMIF_HIDDEN;
	if (!DBGetContactSettingTString((HANDLE)wParam, "CList", "StatusMsg", &dbv))
	{
#ifdef UNICODE
		if ((dbv.type == DBVT_ASCIIZ) || (dbv.type == DBVT_UTF8))
		{
			str = dbv.pszVal;
		}
		else if (dbv.type == DBVT_WCHAR)
		{
		str = mir_dupToAscii(dbv.pwszVal);
		}
#else
		if (dbv.type == DBVT_ASCIIZ)
		{
			str = dbv.pszVal;
		}
#endif

		if (lstrcmpA(str, ""))
		{
			p = strstr(str, "www.");
			if (p == NULL) p = strstr(str, "http://");
			if (p != NULL)
			{
				for (c = 0; p[c] != '\n' && p[c] != '\r' && p[c] != '\t' && p[c] != ' ' && p[c] != '\0'; c++);

				lstrcpynA(str, p, c + 1);
				mir_free(pszStatusMsgURL);
				pszStatusMsgURL = mir_strdup(str);

				clmi.flags = CMIM_FLAGS;
			}
		}
		DBFreeVariant(&dbv);
	}
	CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hmGoToURL, (LPARAM)&clmi);

	mir_free(str);
	mir_free(p);

	return 0;
}