summaryrefslogtreecommitdiff
path: root/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:44 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:55 +0300
commit931a7dc1ac0dbc7e6c1083583ced915e572f5b47 (patch)
tree9fe9a6448d44030e26aa7107ce16044ed413e0d0 /protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
parentdd7d9954042254e66e3bbbec7195c6be8b1a0663 (diff)
all protocols (even virtual ones) moved to the Protocols folder
Diffstat (limited to 'protocols/CurrencyRates/src/CurrencyRatesProviderBase.h')
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderBase.h122
1 files changed, 122 insertions, 0 deletions
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
new file mode 100644
index 0000000000..d407a9a709
--- /dev/null
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
@@ -0,0 +1,122 @@
+#ifndef __3e6cb4ec_fc47_468f_a2c8_a77941176bc9_CurrencyRatesProviderBase_h__
+#define __3e6cb4ec_fc47_468f_a2c8_a77941176bc9_CurrencyRatesProviderBase_h__
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// CCurrencyRate - one currency
+
+class CCurrencyRate
+{
+public:
+ CCurrencyRate(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;
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// CCurrencyRateSection - block of currency settings
+
+class CCurrencyRateSection
+{
+public:
+ typedef std::vector<CCurrencyRateSection> TSections;
+ typedef std::vector<CCurrencyRate> TCurrencyRates;
+
+public:
+ CCurrencyRateSection(const tstring& rsName = L"", const TSections& raSections = TSections(), const TCurrencyRates& raCurrencyRates = TCurrencyRates())
+ : m_sName(rsName), m_aSections(raSections), m_aCurrencyRates(raCurrencyRates){}
+
+ const tstring& GetName() const
+ {
+ return m_sName;
+ }
+
+ size_t GetSectionCount() const
+ {
+ return m_aSections.size();
+ }
+
+ CCurrencyRateSection GetSection(size_t nIndex) const
+ {
+ return ((nIndex < m_aSections.size()) ? m_aSections[nIndex] : CCurrencyRateSection());
+ }
+
+ size_t GetCurrencyRateCount() const
+ {
+ return m_aCurrencyRates.size();
+ }
+
+ CCurrencyRate GetCurrencyRate(size_t nIndex) const
+ {
+ return ((nIndex < m_aCurrencyRates.size()) ? m_aCurrencyRates[nIndex] : CCurrencyRate());
+ }
+
+private:
+ tstring m_sName;
+ TSections m_aSections;
+ TCurrencyRates m_aCurrencyRates;
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// CCurrencyRatesProviderBase - basic set of methods for retrieving currencies
+
+typedef std::vector<MCONTACT> TContacts;
+
+class CCurrencyRatesProviderBase : public ICurrencyRatesProvider
+{
+ void OnEndRun();
+
+ struct CXMLFileInfo *m_pXMLInfo = nullptr;
+
+ HANDLE m_hEventSettingsChanged;
+ HANDLE m_hEventRefreshContact;
+ tstring m_sContactListFormat;
+ tstring m_sStatusMsgFormat;
+ tstring m_sTendencyFormat;
+ TContacts m_aRefreshingContacts;
+ bool m_bRefreshInProgress;
+
+public:
+ CCurrencyRatesProviderBase();
+ ~CCurrencyRatesProviderBase();
+
+ const CCurrencyRateSection& GetCurrencyRates() const;
+
+ bool Init() override;
+ const CProviderInfo& GetInfo() const override;
+
+ void AddContact(MCONTACT hContact) override;
+ void DeleteContact(MCONTACT hContact) override;
+
+ void Run() override;
+
+ void RefreshAllContacts() override;
+ void RefreshSettings() override;
+ void RefreshContact(MCONTACT hContact) override;
+
+ void FillFormat(TFormatSpecificators&) const override;
+ bool ParseSymbol(MCONTACT hContact, wchar_t c, double &d) override;
+ tstring FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth = 0) const override;
+
+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"");
+
+ virtual void RefreshCurrencyRates(TContacts &anContacts) = 0;
+
+protected:
+ TContacts m_aContacts;
+ mutable mir_cs m_cs;
+};
+
+#endif //__3e6cb4ec_fc47_468f_a2c8_a77941176bc9_CurrencyRatesProviderBase_h__