summaryrefslogtreecommitdiff
path: root/protocols/AimOscar/src/popup.cpp
blob: 2c6cf6fabd0fa11e1d1bb19087e709bd10dcf059 (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
/*
Plugin of Miranda IM for communicating with users of the AIM protocol.
Copyright (c) 2008-2009 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr

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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"

struct CAimPopupData
{
	CAimPopupData(CAimProto* _ppro, char* _url) :
		ppro(_ppro),
		url(mir_strdup(_url))
	{}

	~CAimPopupData()
	{ mir_free(url); }

	CAimProto* ppro;
	char* url;
};

LRESULT CALLBACK PopupWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message) 
	{
	case WM_COMMAND:
		if (HIWORD(wParam) == STN_CLICKED)
		{
			CAimPopupData* p = (CAimPopupData*)PUGetPluginData(hWnd);
			if (p->url != nullptr)
				ShellExecuteA(nullptr, "open", p->url, nullptr, nullptr, SW_SHOW);

			PUDeletePopup(hWnd);
			return 0;
		}
		break;

	case WM_CONTEXTMENU:
		PUDeletePopup(hWnd);
		break;

	case UM_FREEPLUGINDATA:
		CAimPopupData* p = (CAimPopupData*)PUGetPluginData(hWnd);
		ReleaseIconEx("aim");
		delete p;
		break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

void CAimProto::ShowPopup(const char* msg, int flags, char* url)
{
	POPUPDATAT ppd = {0};

	mir_snwprintf(ppd.lptzContactName, TranslateT("%s protocol"), m_tszUserName);

	if (flags & ERROR_POPUP) 
	{
		if (flags & TCHAR_POPUP)
		{
			char* errmsg = mir_u2a((wchar_t*)msg);
			debugLogA(errmsg);
			mir_free(errmsg);
		}
		else
			debugLogA(msg);
	}

	wchar_t *msgt = (flags & TCHAR_POPUP) ? mir_wstrdup((wchar_t*)msg) : mir_a2u(msg);
	wcsncpy_s(ppd.lptzText, TranslateW(msgt), _TRUNCATE);
	mir_free(msgt);

	if (!ServiceExists(MS_POPUP_ADDPOPUPT))
	{	
		if (flags & MAIL_POPUP)
		{
			size_t len = mir_wstrlen(ppd.lptzText);
			mir_snwprintf(&ppd.lptzText[len], _countof(ppd.lptzText) - len, L" %s", TranslateT("Open mail account?"));
			if (MessageBox(nullptr, ppd.lptzText, ppd.lptzContactName, MB_YESNO | MB_ICONINFORMATION) == IDYES)
				ShellExecuteA(nullptr, "open", url, nullptr, nullptr, SW_SHOW);
		}
		else
		{
			MessageBox(nullptr, ppd.lptzText, ppd.lptzContactName, MB_OK | MB_ICONINFORMATION);
		}
	}
	else
	{
		ppd.PluginWindowProc = PopupWindowProc;
		ppd.lchIcon = LoadIconEx("aim");
		if (flags & MAIL_POPUP)
		{
			ppd.PluginData = new CAimPopupData(this, url);
			ppd.iSeconds = -1;
		} 
		else 
			ppd.PluginData = new CAimPopupData(this, nullptr);

		CallService(MS_POPUP_ADDPOPUPT, (WPARAM)&ppd, 0);	
	}
}