summaryrefslogtreecommitdiff
path: root/plugins/GmailNotifier/src/utility.cpp
blob: 31410fbfbdd4ab688000e5c2ef930e68974ec436 (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
#include "stdafx.h"

void BuildList(void)
{
	g_accs.destroy();

	for (MCONTACT hContact = db_find_first(MODULE_NAME); hContact; hContact = db_find_next(hContact, MODULE_NAME)) {
		ptrA szName(db_get_sa(hContact, MODULE_NAME, "name"));
		if (szName != nullptr) {
			Account *p = new Account;
			p->hContact = hContact;
			mir_strcpy(p->name, szName);
			CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE);

			ptrA szPassword(db_get_sa(hContact, MODULE_NAME, "Password"));
			if (szPassword != nullptr)
				mir_strcpy(p->pass, szPassword);
			g_accs.insert(p);
		}
	}

	for (int i = 0; i < g_accs.getCount(); i++) {
		Account &acc = g_accs[i];
		char *tail = strchr(acc.name, '@');
		if (tail && mir_strcmp(tail + 1, "gmail.com") != 0)
			mir_strcpy(acc.hosted, tail + 1);
		acc.IsChecking = false;
	}
}

BOOL GetBrowser(char *str)
{
	HKEY hKey = nullptr;
	char *strKey;
	char strIE[] = "Applications\\iexplore.exe\\shell\\open\\command";
	char strDefault[] = "https\\shell\\open\\command";
	DBVARIANT dbv;

	if (opt.OpenUsePrg == 1)
		strKey = strIE;
	else if (opt.OpenUsePrg == 0)
		strKey = strDefault;
	else {
		if (!db_get_s(NULL, MODULE_NAME, "OpenUsePrgPath", &dbv)) {
			mir_strcpy(str, dbv.pszVal);
			db_free(&dbv);
		}
		else *str = 0;
		return FALSE;
	}

	// Open the registry
	if (RegOpenKeyExA(HKEY_CLASSES_ROOT, strKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
		// Data size
		DWORD cbData = 0;
		// Get the default value
		if (RegQueryValueExA(hKey, nullptr, nullptr, nullptr, nullptr, &cbData) == ERROR_SUCCESS && cbData > 0) {
			if (RegQueryValueExA(hKey, nullptr, nullptr, nullptr, (LPBYTE)str, &cbData) == ERROR_SUCCESS) {
				if ((strKey = strstr(str, "%1")) != nullptr)
					*(strKey--) = '\0';
				if ((strKey = strstr(str, "-")) != nullptr)
					*(strKey--) = '\0';
				RegCloseKey(hKey);
				return TRUE;
			}
		}
	}
	return FALSE;
}

Account* GetAccountByContact(MCONTACT hContact)
{
	for (int i = 0; i < g_accs.getCount(); i++)
		if (g_accs[i].hContact == hContact)
			return &g_accs[i];

	return nullptr;
}