summaryrefslogtreecommitdiff
path: root/plugins/Quotes/src/QuotesProviderBase.h
blob: 7370318b3d63c217d66893e0206c9b11c7caff35 (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
#ifndef __3e6cb4ec_fc47_468f_a2c8_a77941176bc9_QuotesProviderBase_h__
#define __3e6cb4ec_fc47_468f_a2c8_a77941176bc9_QuotesProviderBase_h__

class CQuotesProviderBase : public IQuotesProvider
{
public:
	class CQuote
	{
	public:
		CQuote(const tstring& rsID = L"", const tstring& rsSymbol = L"", const tstring& rsName = L"")
			: m_sSymbol(rsSymbol), m_sName(rsName), m_sID(rsID){}

		const tstring& GetSymbol()const{ return m_sSymbol; }
		const tstring& GetName()const{ return m_sName; }
		const tstring& GetID()const{ return m_sID; }

	private:
		tstring m_sSymbol;
		tstring m_sName;
		tstring m_sID;
	};

	class CQuoteSection
	{
	public:
		typedef std::vector<CQuoteSection> TSections;
		typedef std::vector<CQuote> TQuotes;

	public:
		CQuoteSection(const tstring& rsName = L"", const TSections& raSections = TSections(), const TQuotes& raQuotes = TQuotes())
			: m_sName(rsName), m_aSections(raSections), m_aQuotes(raQuotes){}

		const tstring& GetName()const
		{
			return m_sName;
		}

		size_t GetSectionCount()const
		{
			return m_aSections.size();
		}
		CQuoteSection GetSection(size_t nIndex)const
		{
			return ((nIndex < m_aSections.size()) ? m_aSections[nIndex] : CQuoteSection());
		}

		size_t GetQuoteCount()const
		{
			return m_aQuotes.size();
		}
		CQuote GetQuote(size_t nIndex)const
		{
			return ((nIndex < m_aQuotes.size()) ? m_aQuotes[nIndex] : CQuote());
		}

	private:
		tstring m_sName;
		TSections m_aSections;
		TQuotes m_aQuotes;
	};

protected:
	typedef std::vector<MCONTACT> TContracts;

public:
	struct CXMLFileInfo;

public:
	CQuotesProviderBase();
	~CQuotesProviderBase();


	const CQuoteSection& GetQuotes()const;
	// 	void SetSettingsEvent();

	virtual bool Init();
	virtual const CProviderInfo& GetInfo()const;
	virtual void AddContact(MCONTACT hContact);
	virtual void DeleteContact(MCONTACT hContact);
	virtual void Run();
	virtual void Accept(CQuotesProviderVisitor& visitor)const;
	virtual void RefreshAllContacts();
	virtual void RefreshSettings();
	virtual void RefreshContact(MCONTACT hContact);
	// 	virtual void SetContactExtraIcon(MCONTACT hContact)const;

protected:
	const tstring& GetURL()const;
	MCONTACT CreateNewContact(const tstring& rsName);
	static bool IsOnline();
	static void SetContactStatus(MCONTACT hContact, int nNewStatus);
	void WriteContactRate(MCONTACT hContact, double dRate, const tstring& rsSymbol = L"");

private:
	virtual void RefreshQuotes(TContracts& anContacts) = 0;

private:
	virtual void OnEndRun();

private:
	CXMLFileInfo* GetXMLFileInfo()const;

protected:
	TContracts m_aContacts;
	mutable mir_cs m_cs;

private:
	typedef boost::scoped_ptr<CXMLFileInfo> TXMLFileInfoPtr;
	mutable TXMLFileInfoPtr m_pXMLInfo;
	HANDLE m_hEventSettingsChanged;
	HANDLE m_hEventRefreshContact;
	tstring m_sContactListFormat;
	tstring m_sStatusMsgFormat;
	tstring m_sTendencyFormat;
	TContracts m_aRefreshingContacts;
	bool m_bRefreshInProgress;
};

#endif //__3e6cb4ec_fc47_468f_a2c8_a77941176bc9_QuotesProviderBase_h__