summaryrefslogtreecommitdiff
path: root/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp
blob: 5aa6dac52eca8c249fae3301cab929ada0a71c42 (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
#include "StdAfx.h"

#define LAST_RUN_VERSION "LastRunVersion"

void InitCC();
void InitCbrf();
void InitExchangeRates();

TCurrencyRatesProviders g_apProviders;

CCurrencyRatesProviderBase *g_pCurrentProvider = nullptr;

/////////////////////////////////////////////////////////////////////////////////////////

void InitProviders()
{
	InitCC();
	InitCbrf();
	InitExchangeRates();

	g_pCurrentProvider = FindProvider(g_plugin.getMStringW(DB_STR_PROVIDER));
	if (g_pCurrentProvider == nullptr)
		g_pCurrentProvider = &g_apProviders[0];
}

/////////////////////////////////////////////////////////////////////////////////////////

void ClearProviders()
{
	g_apProviders.destroy();
}

/////////////////////////////////////////////////////////////////////////////////////////

void convert_contact_settings(MCONTACT hContact)
{
	uint16_t dwLogMode = g_plugin.getWord(hContact, DB_STR_CURRENCYRATE_LOG, static_cast<uint16_t>(lmDisabled));
	if ((dwLogMode&lmInternalHistory) || (dwLogMode&lmExternalFile))
		g_plugin.setByte(hContact, DB_STR_CONTACT_SPEC_SETTINGS, 1);
}

void TCurrencyRatesProviders::push(CCurrencyRatesProviderBase *pNew)
{
	if (pNew->Init())
		insert(pNew);
	else
		delete pNew;
}

/////////////////////////////////////////////////////////////////////////////////////////

CCurrencyRatesProviderBase* FindProvider(const CMStringW &rsName)
{
	for (auto &pProvider : g_apProviders) {
		const ICurrencyRatesProvider::CProviderInfo& rInfo = pProvider->GetInfo();
		if (!mir_wstrcmpi(rsName.c_str(), rInfo.m_sName.c_str()))
			return pProvider;
	}

	return nullptr;
}