summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_accounts.cpp
blob: f6e8f4ddd37810e5c4040db21df87eee6dfb6f4f (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
#include "stdafx.h"

LIST<CToxProto> CToxProto::Accounts(1, CToxProto::CompareAccounts);

int CToxProto::CompareAccounts(const CToxProto *p1, const CToxProto *p2)
{
	return mir_wstrcmp(p1->m_tszUserName, p2->m_tszUserName);
}

CToxProto* CToxProto::InitAccount(const char *protoName, const wchar_t *userName)
{
	CToxProto *proto = new CToxProto(protoName, userName);
	Accounts.insert(proto);
	return proto;
}

int CToxProto::UninitAccount(CToxProto *proto)
{
	Accounts.remove(proto);
	delete proto;
	return 0;
}

CToxProto* CToxProto::GetContactAccount(MCONTACT hContact)
{
	for (int i = 0; i < Accounts.getCount(); i++)
		if (mir_strcmpi(GetContactProto(hContact), Accounts[i]->m_szModuleName) == 0)
			return Accounts[i];
	return NULL;
}

int CToxProto::OnAccountLoaded(WPARAM, LPARAM)
{
	HookProtoEvent(ME_OPT_INITIALISE, &CToxProto::OnOptionsInit);
	HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit);
	HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage);

	InitCustomDbEvents();

	return 0;
}

int CToxProto::OnAccountRenamed(WPARAM, LPARAM)
{
	mir_cslock locker(profileLock);

	ptrW newPath(GetToxProfilePath());
	wchar_t oldPath[MAX_PATH];
	mir_snwprintf(oldPath, MAX_PATH, L"%s\\%s.tox", VARSW(L"%miranda_userdata%"), accountName);
	_wrename(oldPath, newPath);
	mir_free(accountName);
	accountName = mir_wstrdup(m_tszUserName);

	return 0;
}

INT_PTR CToxProto::OnAccountManagerInit(WPARAM, LPARAM lParam)
{
	return (INT_PTR)(CToxOptionsMain::CreateAccountManagerPage(this, (HWND)lParam))->GetHwnd();
}