summaryrefslogtreecommitdiff
path: root/protocols/Sametime/src/session_announce_win.cpp
blob: 45c4dffa2d530f4d2d783d597abd760572d12f93 (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
#include "StdAfx.h"
#include "sametime.h"

INT_PTR CALLBACK SessionAnnounceDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	SessionAnnounceDialogProc_arg* arg = (SessionAnnounceDialogProc_arg*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	CSametimeProto *proto;

	switch (uMsg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{

			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
			arg = (SessionAnnounceDialogProc_arg*)lParam;
			proto = arg->proto;
			proto->debugLogW(L"SessionAnnounceDialogProc WM_INITDIALOG");

			SendDlgItemMessage(hwndDlg, IDC_LST_ANTO, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
			{
				LVCOLUMN lvc;
				// Initialize the LVCOLUMN structure.
				// The mask specifies that the format, width, text, and
				// subitem members of the structure are valid. 
				lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
				lvc.fmt = LVCFMT_LEFT;

				lvc.iSubItem = 0;
				lvc.pszText = TranslateT("Recipients");
				lvc.cx = 300;     // width of column in pixels
				ListView_InsertColumn(GetDlgItem(hwndDlg, IDC_LST_ANTO), 0, &lvc);
			}
			//enumerate plugins, fill in list
			{
				ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_LST_ANTO));
				LVITEM lvI;
				// Some code to create the list-view control.
				// Initialize LVITEM members that are common to all items. 
				lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE; 
				lvI.iItem = 0;
				lvI.iSubItem = 0;

				for (MCONTACT hContact = db_find_first(proto->m_szModuleName); hContact; hContact = db_find_next(hContact, proto->m_szModuleName)) {
					if (db_get_b(hContact, proto->m_szModuleName, "ChatRoom", 0) == 0
						&& db_get_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) {
						lvI.lParam = (LPARAM)hContact;
						lvI.pszText = pcli->pfnGetContactDisplayName(hContact, 0);
						ListView_InsertItem(GetDlgItem(hwndDlg, IDC_LST_ANTO), &lvI);
						lvI.iItem++;
					}
				}
			}
		}
		return 0;

	case WM_CLOSE:
		proto = arg->proto;
		proto->debugLogW(L"SessionAnnounceDialogProc WM_CLOSE");
		mir_free(arg);
		DestroyWindow(hwndDlg);
		break;

	case WM_COMMAND:
		proto = arg->proto;
		if (HIWORD(wParam) == BN_CLICKED) {
			int size;
			switch (LOWORD(wParam)) {
			case IDC_BUT_SELALL:
				size = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_LST_ANTO));
				for (int i = 0; i < size; i++)
					ListView_SetCheckState(GetDlgItem(hwndDlg, IDC_LST_ANTO), i, true);
				return 0;

			case IDC_BUT_SELINV:
				size = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_LST_ANTO));
				for (int i = 0; i < size; i++)
					ListView_SetCheckState(GetDlgItem(hwndDlg, IDC_LST_ANTO), i,
					!ListView_GetCheckState(GetDlgItem(hwndDlg, IDC_LST_ANTO), i));
				return 0;

			case IDOK:
				proto->debugLogW(L"SessionAnnounceDialogProc IDOK BN_CLICKED");
				{
					// build SendAnnouncementFunc_arg
					SendAnnouncementFunc_arg* safArg = (SendAnnouncementFunc_arg*)mir_calloc(sizeof(SendAnnouncementFunc_arg));
					DBVARIANT dbv;
					LVITEM lvI = { 0 };

					char id[1024];
					mir_strcpy(id, "@U");		// documentation says prepend '@U' to usernames and '@G' to notes group names - but
					char *p = id + 2;		// it's wrong - it works for a list of user id's with no prefix - so we'll do both

					// build recipient list
					safArg->recipients = nullptr;

					int size = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_LST_ANTO));
					int send_count = 0;
					for (int i = 0; i < size; i++) {
						if (ListView_GetCheckState(GetDlgItem(hwndDlg, IDC_LST_ANTO), i)) {
							lvI.iItem = i;
							lvI.iSubItem = 0;
							lvI.mask = LVIF_PARAM;
							ListView_GetItem(GetDlgItem(hwndDlg, IDC_LST_ANTO), &lvI);

							if (!db_get_utf((MCONTACT)lvI.lParam, proto->m_szModuleName, "stid", &dbv)) {
								safArg->recipients = g_list_prepend(safArg->recipients, _strdup(dbv.pszVal));
								mir_strcpy(p, dbv.pszVal);
								safArg->recipients = g_list_prepend(safArg->recipients, _strdup(id));
								send_count++;
								db_free(&dbv);
							}
						}
					}

					if (send_count > 0) {
						GetDlgItemText(hwndDlg, IDC_ED_ANMSG, safArg->msg, MAX_MESSAGE_SIZE);
						safArg->proto = proto;
						SendAnnouncementFunc sendAnnouncementFunc = arg->sendAnnouncementFunc;
						sendAnnouncementFunc(safArg);
					}

					// clean up recipient list
					if (safArg->recipients) {
						for (GList *rit = safArg->recipients; rit; rit = rit->next) {
							free(rit->data);
						}
						g_list_free(safArg->recipients);
					}
					mir_free(safArg);

					DestroyWindow(hwndDlg);
				}
				return 0;

			case IDCANCEL:
				DestroyWindow(hwndDlg);
				return 0;
			}
		}
		break;
	}

	return 0;
}