summaryrefslogtreecommitdiff
path: root/plugins/Quotes/src
diff options
context:
space:
mode:
authorDioksin <dioksin@ua.fm>2018-06-27 18:03:32 +0300
committerDioksin <dioksin@ua.fm>2018-06-27 18:03:32 +0300
commitc27c86cb021b6bf789ee674fab29164448e0c251 (patch)
tree389d4fe0a7ed2d7d8da360e8a3a46f969e17b981 /plugins/Quotes/src
parentf53ec5ce1181d1595178a8096c4798a7258774e1 (diff)
Quotes plugin
Quotes plugin: as google is not supported currency conversion now it was removed and code to work with https://free.currencyconverterapi.com/ was implemented. So Gooogle goodbye!
Diffstat (limited to 'plugins/Quotes/src')
-rw-r--r--plugins/Quotes/src/CurrencyConverter.cpp39
-rw-r--r--plugins/Quotes/src/ImportExport.cpp8
-rw-r--r--plugins/Quotes/src/QuotesProviderCurrencyConverter.cpp425
-rw-r--r--plugins/Quotes/src/QuotesProviderCurrencyConverter.h29
-rw-r--r--plugins/Quotes/src/QuotesProviderGoogle.cpp431
-rw-r--r--plugins/Quotes/src/QuotesProviderGoogle.h40
-rw-r--r--plugins/Quotes/src/QuotesProviderVisitor.h4
-rw-r--r--plugins/Quotes/src/QuotesProviderVisitorDbSettings.cpp56
-rw-r--r--plugins/Quotes/src/QuotesProviderVisitorDbSettings.h10
-rw-r--r--plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.cpp18
-rw-r--r--plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.h11
-rw-r--r--plugins/Quotes/src/QuotesProviderVisitorFormater.cpp37
-rw-r--r--plugins/Quotes/src/QuotesProviderVisitorFormater.h10
-rw-r--r--plugins/Quotes/src/QuotesProviders.cpp3
-rw-r--r--plugins/Quotes/src/resource.h4
-rw-r--r--plugins/Quotes/src/stdafx.h1
16 files changed, 555 insertions, 571 deletions
diff --git a/plugins/Quotes/src/CurrencyConverter.cpp b/plugins/Quotes/src/CurrencyConverter.cpp
index 39de2a3805..e66511ce91 100644
--- a/plugins/Quotes/src/CurrencyConverter.cpp
+++ b/plugins/Quotes/src/CurrencyConverter.cpp
@@ -1,4 +1,5 @@
#include "StdAfx.h"
+#include "QuotesProviderCurrencyConverter.h"
#define WINDOW_PREFIX "CurrenyConverter_"
@@ -6,36 +7,37 @@
#define DB_STR_CC_QUOTE_TO_ID "CurrencyConverter_ToID"
#define DB_STR_CC_AMOUNT "CurrencyConverter_Amount"
-static CQuotesProviderGoogle* get_google_provider()
+static CQuotesProviderCurrencyConverter* get_currency_converter_provider()
{
CModuleInfo::TQuotesProvidersPtr pProviders = CModuleInfo::GetQuoteProvidersPtr();
const CQuotesProviders::TQuotesProviders& rapQuotesProviders = pProviders->GetProviders();
for (CQuotesProviders::TQuotesProviders::const_iterator i = rapQuotesProviders.begin(); i != rapQuotesProviders.end(); ++i) {
const CQuotesProviders::TQuotesProviderPtr& pProvider = *i;
- CQuotesProviderGoogle* pGoogle = dynamic_cast<CQuotesProviderGoogle*>(pProvider.get());
- if (pGoogle)
- return pGoogle;
+ if (auto p = dynamic_cast<CQuotesProviderCurrencyConverter*>(pProvider.get()))
+ {
+ return p;
+ }
}
assert(!"We should never get here!");
return nullptr;
}
-CQuotesProviderGoogle::CQuoteSection get_quotes(const CQuotesProviderGoogle* pProvider = nullptr)
+CQuotesProviderBase::CQuoteSection get_quotes(const CQuotesProviderCurrencyConverter* pProvider = nullptr)
{
if (nullptr == pProvider)
- pProvider = get_google_provider();
+ pProvider = get_currency_converter_provider();
if (pProvider) {
- const CQuotesProviderGoogle::CQuoteSection& rQuotes = pProvider->GetQuotes();
+ const auto& rQuotes = pProvider->GetQuotes();
if (rQuotes.GetSectionCount() > 0)
return rQuotes.GetSection(0);
}
- return CQuotesProviderGoogle::CQuoteSection();
+ return CQuotesProviderBase::CQuoteSection();
}
-inline tstring make_quote_name(const CQuotesProviderGoogle::CQuote& rQuote)
+inline tstring make_quote_name(const CQuotesProviderBase::CQuote& rQuote)
{
const tstring& rsDesc = rQuote.GetName();
return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
@@ -97,11 +99,11 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM
tstring sFromQuoteID = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, DB_STR_CC_QUOTE_FROM_ID);
tstring sToQuoteID = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, DB_STR_CC_QUOTE_TO_ID);
- const CQuotesProviderGoogle* pProvider = get_google_provider();
- const CQuotesProviderGoogle::CQuoteSection& rSection = get_quotes(pProvider);
- size_t cQuotes = rSection.GetQuoteCount();
- for (size_t i = 0; i < cQuotes; ++i) {
- const CQuotesProviderGoogle::CQuote& rQuote = rSection.GetQuote(i);
+ const auto pProvider = get_currency_converter_provider();
+ const auto& rSection = get_quotes(pProvider);
+ auto cQuotes = rSection.GetQuoteCount();
+ for (auto i = 0u; i < cQuotes; ++i) {
+ const auto& rQuote = rSection.GetQuote(i);
tstring sName = make_quote_name(rQuote);
LPCTSTR pszName = sName.c_str();
LRESULT nFrom = ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName));
@@ -193,17 +195,16 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM
size_t nFrom = static_cast<size_t>(::SendDlgItemMessage(hDlg, IDC_COMBO_CONVERT_FROM, CB_GETCURSEL, 0, 0));
size_t nTo = static_cast<size_t>(::SendDlgItemMessage(hDlg, IDC_COMBO_CONVERT_INTO, CB_GETCURSEL, 0, 0));
if ((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo)) {
- const CQuotesProviderGoogle::CQuoteSection& rSection = get_quotes();
+ const auto& rSection = get_quotes();
size_t cQuotes = rSection.GetQuoteCount();
if ((nFrom < cQuotes) && (nTo < cQuotes)) {
- CQuotesProviderGoogle::CRateInfo ri;
- CQuotesProviderGoogle::CQuote from = rSection.GetQuote(nFrom);
- CQuotesProviderGoogle::CQuote to = rSection.GetQuote(nTo);
+ auto from = rSection.GetQuote(nFrom);
+ auto to = rSection.GetQuote(nTo);
db_set_ws(NULL, QUOTES_MODULE_NAME, DB_STR_CC_QUOTE_FROM_ID, from.GetID().c_str());
db_set_ws(NULL, QUOTES_MODULE_NAME, DB_STR_CC_QUOTE_TO_ID, to.GetID().c_str());
- const CQuotesProviderGoogle* pProvider = get_google_provider();
+ const auto pProvider = get_currency_converter_provider();
assert(pProvider);
if (pProvider) {
tstring sResult;
diff --git a/plugins/Quotes/src/ImportExport.cpp b/plugins/Quotes/src/ImportExport.cpp
index b68cc67103..564fb7b960 100644
--- a/plugins/Quotes/src/ImportExport.cpp
+++ b/plugins/Quotes/src/ImportExport.cpp
@@ -1,4 +1,5 @@
#include "StdAfx.h"
+#include "QuotesProviderCurrencyConverter.h"
LPCTSTR g_pszXmlValue = L"Value";
LPCTSTR g_pszXmlName = L"Name";
@@ -462,7 +463,7 @@ bool get_contact_state(const IXMLNode::TXMLNodePtr& pXmlContact, CContactState&
MCONTACT GetContact()const { return m_hContact; }
private:
- virtual void Visit(const CQuotesProviderDukasCopy& rProvider)
+ virtual void Visit(const CQuotesProviderDukasCopy& rProvider)override
{
tstring sQuoteID = GetXMLNodeValue(DB_STR_QUOTE_ID);
if (false == sQuoteID.empty()) {
@@ -470,9 +471,8 @@ bool get_contact_state(const IXMLNode::TXMLNodePtr& pXmlContact, CContactState&
}
}
- virtual void Visit(const CQuotesProviderGoogle& rProvider)
+ virtual void Visit(const CQuotesProviderCurrencyConverter& rProvider)override
{
- // USES_CONVERSION;
static const tstring g_sFromID = quotes_a2t(DB_STR_FROM_ID);//A2CT(DB_STR_FROM_ID);
static const tstring g_sToID = quotes_a2t(DB_STR_TO_ID);//A2CT(DB_STR_TO_ID);
@@ -497,7 +497,7 @@ bool get_contact_state(const IXMLNode::TXMLNodePtr& pXmlContact, CContactState&
}
}
- virtual void Visit(const CQuotesProviderFinance& rProvider)
+ virtual void Visit(const CQuotesProviderFinance& rProvider)override
{
tstring sQuoteID = GetXMLNodeValue(DB_STR_QUOTE_ID);
if (false == sQuoteID.empty()) {
diff --git a/plugins/Quotes/src/QuotesProviderCurrencyConverter.cpp b/plugins/Quotes/src/QuotesProviderCurrencyConverter.cpp
new file mode 100644
index 0000000000..f51a662721
--- /dev/null
+++ b/plugins/Quotes/src/QuotesProviderCurrencyConverter.cpp
@@ -0,0 +1,425 @@
+#include "stdafx.h"
+#include "QuotesProviderCurrencyConverter.h"
+#include <boost\property_tree\ptree.hpp>
+#include <boost\property_tree\json_parser.hpp>
+
+namespace
+{
+ tstring build_url(const tstring& rsURL, const tstring& from, const tstring& to)
+ {
+ tostringstream o;
+ o << rsURL << L"?q=" << from << L"_" << to << "&compact=ultra";
+ return o.str();
+ }
+
+ tstring build_url(MCONTACT hContact, const tstring& rsURL)
+ {
+ tstring sFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
+ tstring sTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
+ return build_url(rsURL, sFrom, sTo);
+ }
+
+ bool parse_responce(const tstring& rsJSON, double& dRate)
+ {
+ try
+ {
+ boost::property_tree::ptree pt;
+ std::istringstream i_stream(quotes_t2a(rsJSON.c_str()));
+
+ boost::property_tree::read_json(i_stream, pt);
+ if (!pt.empty())
+ {
+ auto pt_nested = pt.begin()->second;
+ dRate = pt_nested.get_value<double>();
+ }
+ else
+ {
+ dRate = pt.get_value<double>();
+ }
+
+ return true;
+ }
+ catch (boost::property_tree::ptree_error& )
+ {
+ }
+ return false;
+ }
+
+ using TWatchedRates = std::vector<CQuotesProviderCurrencyConverter::TRateInfo>;
+ TWatchedRates g_aWatchedRates;
+
+ INT_PTR CALLBACK OptDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+ {
+ auto get_provider = []()->CQuotesProviderCurrencyConverter*
+ {
+ auto pProviders = CModuleInfo::GetQuoteProvidersPtr();
+ const auto& rapQuotesProviders = pProviders->GetProviders();
+ for (auto i = rapQuotesProviders.begin(); i != rapQuotesProviders.end(); ++i) {
+ const auto& pProvider = *i;
+ if (auto p = dynamic_cast<CQuotesProviderCurrencyConverter*>(pProvider.get()))
+ {
+ return p;
+ }
+ }
+
+ assert(!"We should never get here!");
+ return nullptr;
+ };
+
+ auto make_quote_name = [](const CQuotesProviderBase::CQuote& rQuote)->tstring
+ {
+ const tstring& rsDesc = rQuote.GetName();
+ return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
+ };
+
+ auto make_contact_name = [](const tstring& rsSymbolFrom, const tstring& rsSymbolTo)->tstring
+ {
+ tostringstream o;
+ o << rsSymbolFrom << L"/" << rsSymbolTo;
+ return o.str();
+ };
+
+
+ auto make_rate_name = [make_contact_name](const CQuotesProviderCurrencyConverter::TRateInfo& ri)->tstring
+ {
+ if ((false == ri.first.GetName().empty()) && (false == ri.second.GetName().empty()))
+ return make_contact_name(ri.first.GetName(), ri.second.GetName());
+
+ return make_contact_name(ri.first.GetSymbol(), ri.second.GetSymbol());
+ };
+
+
+ auto pProvider = get_provider();
+
+ CCommonDlgProcData d(pProvider);
+ CommonOptionDlgProc(hdlg, message, wParam, lParam, d);
+
+ switch (message) {
+ case WM_NOTIFY:
+ {
+ LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lParam);
+ switch (pNMHDR->code) {
+ case PSN_APPLY:
+ {
+ if (pProvider) {
+ TWatchedRates aTemp(g_aWatchedRates);
+ TWatchedRates aRemove;
+ size_t cWatchedRates = pProvider->GetWatchedRateCount();
+ for (size_t i = 0; i < cWatchedRates; ++i) {
+ CQuotesProviderCurrencyConverter::TRateInfo ri;
+ if (true == pProvider->GetWatchedRateInfo(i, ri)) {
+ auto it = std::find_if(aTemp.begin(), aTemp.end(), [&ri](const auto& other)->bool
+ {
+ return ((0 == mir_wstrcmpi(ri.first.GetID().c_str(), other.first.GetID().c_str()))
+ && ((0 == mir_wstrcmpi(ri.second.GetID().c_str(), other.second.GetID().c_str()))));
+ });
+ if (it == aTemp.end()) {
+ aRemove.push_back(ri);
+ }
+ else {
+ aTemp.erase(it);
+ }
+ }
+ }
+
+ std::for_each(aRemove.begin(), aRemove.end(), [pProvider](const auto& ri) {pProvider->WatchForRate(ri, false); });
+ std::for_each(aTemp.begin(), aTemp.end(), [pProvider](const auto& ri) {pProvider->WatchForRate(ri, true); });
+ pProvider->RefreshSettings();
+ }
+ }
+ break;
+ }
+ }
+ break;
+
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+ {
+ g_aWatchedRates.clear();
+
+ HWND hcbxFrom = ::GetDlgItem(hdlg, IDC_COMBO_CONVERT_FROM);
+ HWND hcbxTo = ::GetDlgItem(hdlg, IDC_COMBO_CONVERT_INTO);
+
+ CQuotesProviderBase::CQuoteSection rSection;
+ const auto& rQuotes = pProvider->GetQuotes();
+ if (rQuotes.GetSectionCount() > 0)
+ {
+ rSection = rQuotes.GetSection(0);
+ }
+
+ auto cQuotes = rSection.GetQuoteCount();
+ for (auto i = 0u; i < cQuotes; ++i)
+ {
+ const auto& rQuote = rSection.GetQuote(i);
+ tstring sName = make_quote_name(rQuote);
+ LPCTSTR pszName = sName.c_str();
+ ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName));
+ ::SendMessage(hcbxTo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName));
+ }
+
+ auto cWatchedRates = pProvider->GetWatchedRateCount();
+ for (auto i = 0u; i < cWatchedRates; ++i)
+ {
+ CQuotesProviderCurrencyConverter::TRateInfo ri;
+ if (true == pProvider->GetWatchedRateInfo(i, ri))
+ {
+ g_aWatchedRates.push_back(ri);
+ tstring sRate = make_rate_name(ri);
+ LPCTSTR pszRateName = sRate.c_str();
+ ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRateName));
+ }
+ }
+
+ ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_ADD), FALSE);
+ ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_REMOVE), FALSE);
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (HIWORD(wParam)) {
+ case CBN_SELCHANGE:
+ switch (LOWORD(wParam)) {
+ case IDC_COMBO_REFRESH_RATE:
+ break;
+ case IDC_COMBO_CONVERT_FROM:
+ case IDC_COMBO_CONVERT_INTO:
+ {
+ int nFrom = static_cast<int>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_FROM, CB_GETCURSEL, 0, 0));
+ int nTo = static_cast<int>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_INTO, CB_GETCURSEL, 0, 0));
+ bool bEnableAddButton = ((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo));
+ EnableWindow(GetDlgItem(hdlg, IDC_BUTTON_ADD), bEnableAddButton);
+ }
+ break;
+ case IDC_LIST_RATES:
+ {
+ int nSel = ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_GETCURSEL, 0, 0);
+ ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_REMOVE), (LB_ERR != nSel));
+ }
+ break;
+ }
+ break;
+
+ case BN_CLICKED:
+ switch (LOWORD(wParam)) {
+ case IDC_BUTTON_ADD:
+ {
+ size_t nFrom = static_cast<size_t>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_FROM, CB_GETCURSEL, 0, 0));
+ size_t nTo = static_cast<size_t>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_INTO, CB_GETCURSEL, 0, 0));
+ if ((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo))
+ {
+ CQuotesProviderBase::CQuoteSection rSection;
+ const auto& rQuotes = pProvider->GetQuotes();
+ if (rQuotes.GetSectionCount() > 0)
+ {
+ rSection = rQuotes.GetSection(0);
+ }
+
+ auto cQuotes = rSection.GetQuoteCount();
+ if ((nFrom < cQuotes) && (nTo < cQuotes))
+ {
+ CQuotesProviderCurrencyConverter::TRateInfo ri;
+ ri.first = rSection.GetQuote(nFrom);
+ ri.second = rSection.GetQuote(nTo);
+
+ g_aWatchedRates.push_back(ri);
+
+ tstring sRate = make_rate_name(ri);
+ LPCTSTR pszRateName = sRate.c_str();
+ ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRateName));
+ PropSheet_Changed(::GetParent(hdlg), hdlg);
+ }
+ }
+ }
+ break;
+
+ case IDC_BUTTON_REMOVE:
+ HWND hWnd = ::GetDlgItem(hdlg, IDC_LIST_RATES);
+ int nSel = ::SendMessage(hWnd, LB_GETCURSEL, 0, 0);
+ if (LB_ERR != nSel) {
+ if ((LB_ERR != ::SendMessage(hWnd, LB_DELETESTRING, nSel, 0))
+ && (nSel < static_cast<int>(g_aWatchedRates.size()))) {
+
+ TWatchedRates::iterator i = g_aWatchedRates.begin();
+ std::advance(i, nSel);
+ g_aWatchedRates.erase(i);
+ PropSheet_Changed(::GetParent(hdlg), hdlg);
+ }
+ }
+
+ nSel = ::SendMessage(hWnd, LB_GETCURSEL, 0, 0);
+ ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_REMOVE), (LB_ERR != nSel));
+ break;
+ }
+ break;
+ }
+ break;
+ }
+
+ return FALSE;
+ }
+
+}
+
+
+CQuotesProviderCurrencyConverter::CQuotesProviderCurrencyConverter()
+{
+}
+
+
+CQuotesProviderCurrencyConverter::~CQuotesProviderCurrencyConverter()
+{
+}
+
+void CQuotesProviderCurrencyConverter::Accept(CQuotesProviderVisitor& visitor)const
+{
+ CQuotesProviderBase::Accept(visitor);
+ visitor.Visit(*this);
+}
+
+void CQuotesProviderCurrencyConverter::ShowPropertyPage(WPARAM wp, OPTIONSDIALOGPAGE& odp)
+{
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_DIALOG_OPT_GOOGLE);
+ odp.pfnDlgProc = OptDlgProc;
+ odp.szTab.w = const_cast<LPTSTR>(GetInfo().m_sName.c_str());
+ g_plugin.addOptions(wp, &odp);
+}
+
+void CQuotesProviderCurrencyConverter::RefreshQuotes(TContracts& anContacts)
+{
+ CHTTPSession http;
+ tstring sURL = GetURL();
+
+ for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i) {
+ MCONTACT hContact = *i;
+
+ tstring sFullURL = build_url(hContact, sURL);
+ if ((true == http.OpenURL(sFullURL)) && (true == IsOnline())) {
+ tstring sHTML;
+ if ((true == http.ReadResponce(sHTML)) && (true == IsOnline())) {
+ double dRate = 0.0;
+ if ((true == parse_responce(sHTML, dRate)) && (true == IsOnline())) {
+ WriteContactRate(hContact, dRate);
+ continue;
+ }
+ }
+ }
+
+ SetContactStatus(hContact, ID_STATUS_NA);
+ }
+}
+
+double CQuotesProviderCurrencyConverter::Convert(double dAmount, const CQuote& from, const CQuote& to)const
+{
+ tstring sFullURL = build_url(GetURL(), from.GetID(), to.GetID());
+
+ CHTTPSession http;
+ if ((true == http.OpenURL(sFullURL))) {
+ tstring sHTML;
+ if ((true == http.ReadResponce(sHTML))) {
+ double dResult = 0.0;
+ if ((true == parse_responce(sHTML, dResult)))
+ {
+ return dResult*dAmount;
+ }
+
+ throw std::runtime_error(Translate("Error occurred during HTML parsing."));
+ }
+ else throw std::runtime_error(Translate("Error occurred during site access."));
+ }
+ else throw std::runtime_error(Translate("Error occurred during site access."));
+
+ return 0.0;
+}
+
+size_t CQuotesProviderCurrencyConverter::GetWatchedRateCount()const
+{
+ return m_aContacts.size();
+}
+
+bool CQuotesProviderCurrencyConverter::GetWatchedRateInfo(size_t nIndex, TRateInfo& rRateInfo)
+{
+ if(nIndex < m_aContacts.size()) {
+ MCONTACT hContact = m_aContacts[nIndex];
+ tstring sSymbolFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
+ tstring sSymbolTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
+ tstring sDescFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_DESCRIPTION);
+ tstring sDescTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_DESCRIPTION);
+
+ rRateInfo.first = CQuote(sSymbolFrom, sSymbolFrom, sDescFrom);
+ rRateInfo.second = CQuote(sSymbolTo, sSymbolTo, sDescTo);
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+bool CQuotesProviderCurrencyConverter::WatchForRate(const TRateInfo& ri, bool bWatch)
+{
+ auto i = std::find_if(m_aContacts.begin(), m_aContacts.end(), [&ri](auto hContact)->bool
+ {
+ tstring sFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
+ tstring sTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
+ return ((0 == mir_wstrcmpi(ri.first.GetID().c_str(), sFrom.c_str()))
+ && (0 == mir_wstrcmpi(ri.second.GetID().c_str(), sTo.c_str())));
+ });
+
+ auto make_contact_name = [](const tstring& rsSymbolFrom, const tstring& rsSymbolTo)->tstring
+ {
+ tostringstream o;
+ o << rsSymbolFrom << L"/" << rsSymbolTo;
+ return o.str();
+ };
+
+
+ if ((true == bWatch) && (i == m_aContacts.end()))
+ {
+ tstring sName = make_contact_name(ri.first.GetSymbol(), ri.second.GetSymbol());
+ MCONTACT hContact = CreateNewContact(sName);
+ if (hContact)
+ {
+ db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID, ri.first.GetID().c_str());
+ db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID, ri.second.GetID().c_str());
+ if (false == ri.first.GetName().empty())
+ {
+ db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_DESCRIPTION, ri.first.GetName().c_str());
+ }
+ if (false == ri.second.GetName().empty())
+ {
+ db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_DESCRIPTION, ri.second.GetName().c_str());
+ }
+
+ return true;
+ }
+ }
+ else if ((false == bWatch) && (i != m_aContacts.end()))
+ {
+ MCONTACT hContact = *i;
+ {// for CCritSection
+ mir_cslock lck(m_cs);
+ m_aContacts.erase(i);
+ }
+
+ db_delete_contact(hContact);
+ return true;
+ }
+
+ return false;
+}
+
+MCONTACT CQuotesProviderCurrencyConverter::GetContactByID(const tstring& rsFromID, const tstring& rsToID)const
+{
+ mir_cslock lck(m_cs);
+
+ auto i = std::find_if(m_aContacts.begin(), m_aContacts.end(), [rsFromID, rsToID](MCONTACT hContact)->bool
+ {
+ tstring sFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
+ tstring sTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
+ return ((0 == mir_wstrcmpi(rsFromID.c_str(), sFrom.c_str())) && (0 == mir_wstrcmpi(rsToID.c_str(), sTo.c_str())));
+
+ });
+ if (i != m_aContacts.end())
+ return *i;
+
+ return NULL;
+}
diff --git a/plugins/Quotes/src/QuotesProviderCurrencyConverter.h b/plugins/Quotes/src/QuotesProviderCurrencyConverter.h
new file mode 100644
index 0000000000..c6138756b3
--- /dev/null
+++ b/plugins/Quotes/src/QuotesProviderCurrencyConverter.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#define DB_STR_FROM_ID "FromID"
+#define DB_STR_TO_ID "ToID"
+#define DB_STR_FROM_DESCRIPTION "FromDesc"
+#define DB_STR_TO_DESCRIPTION "ToDesc"
+
+
+class CQuotesProviderCurrencyConverter : public CQuotesProviderBase
+{
+public:
+ using TRateInfo = std::pair<CQuote, CQuote>;
+
+public:
+ CQuotesProviderCurrencyConverter();
+ ~CQuotesProviderCurrencyConverter();
+
+ double Convert(double dAmount, const CQuote& from, const CQuote& to)const;
+ size_t GetWatchedRateCount()const;
+ bool GetWatchedRateInfo(size_t nIndex, TRateInfo& rRateInfo);
+ bool WatchForRate(const TRateInfo& ri, bool bWatch);
+ MCONTACT GetContactByID(const tstring& rsFromID, const tstring& rsToID)const;
+
+private:
+ virtual void Accept(CQuotesProviderVisitor& visitor)const override;
+ virtual void ShowPropertyPage(WPARAM wp, OPTIONSDIALOGPAGE& odp)override;
+ virtual void RefreshQuotes(TContracts& anContacts)override;
+};
+
diff --git a/plugins/Quotes/src/QuotesProviderGoogle.cpp b/plugins/Quotes/src/QuotesProviderGoogle.cpp
deleted file mode 100644
index e791b8cc4f..0000000000
--- a/plugins/Quotes/src/QuotesProviderGoogle.cpp
+++ /dev/null
@@ -1,431 +0,0 @@
-#include "StdAfx.h"
-
-CQuotesProviderGoogle::CQuotesProviderGoogle()
-{
-}
-
-CQuotesProviderGoogle::~CQuotesProviderGoogle()
-{
-}
-
-inline tstring make_contact_name(const tstring& rsSymbolFrom, const tstring& rsSymbolTo)
-{
- tostringstream o;
- o << rsSymbolFrom << L"/" << rsSymbolTo;
- return o.str();
-}
-
-inline bool is_rate_watched(MCONTACT hContact,
- const CQuotesProviderBase::CQuote& from,
- const CQuotesProviderBase::CQuote& to)
-{
- tstring sFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
- tstring sTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
- return ((0 == mir_wstrcmpi(from.GetID().c_str(), sFrom.c_str()))
- && (0 == mir_wstrcmpi(to.GetID().c_str(), sTo.c_str())));
-}
-
-bool CQuotesProviderGoogle::WatchForRate(const CRateInfo& ri,
- bool bWatch)
-{
- TContracts::const_iterator i = std::find_if(m_aContacts.begin(), m_aContacts.end(),
- boost::bind(is_rate_watched, _1, ri.m_from, ri.m_to));
- if ((true == bWatch) && (i == m_aContacts.end())) {
- tstring sName = make_contact_name(ri.m_from.GetSymbol(), ri.m_to.GetSymbol());
- MCONTACT hContact = CreateNewContact(sName);
- if (hContact) {
- db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID, ri.m_from.GetID().c_str());
- db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID, ri.m_to.GetID().c_str());
- if (false == ri.m_from.GetName().empty()) {
- db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_DESCRIPTION, ri.m_from.GetName().c_str());
- }
- if (false == ri.m_to.GetName().empty()) {
- db_set_ws(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_DESCRIPTION, ri.m_to.GetName().c_str());
- }
-
- return true;
- }
- }
- else if ((false == bWatch) && (i != m_aContacts.end())) {
- MCONTACT hContact = *i;
- {// for CCritSection
- mir_cslock lck(m_cs);
- m_aContacts.erase(i);
- }
-
- db_delete_contact(hContact);
- return true;
- }
-
- return false;
-}
-
-size_t CQuotesProviderGoogle::GetWatchedRateCount()const
-{
- return m_aContacts.size();
-}
-
-bool CQuotesProviderGoogle::GetWatchedRateInfo(size_t nIndex, CRateInfo& rRateInfo)
-{
- if (nIndex < m_aContacts.size()) {
- MCONTACT hContact = m_aContacts[nIndex];
- tstring sSymbolFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
- tstring sSymbolTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
- tstring sDescFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_DESCRIPTION);
- tstring sDescTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_DESCRIPTION);
-
- rRateInfo.m_from = CQuote(sSymbolFrom, sSymbolFrom, sDescFrom);
- rRateInfo.m_to = CQuote(sSymbolTo, sSymbolTo, sDescTo);
- return true;
- }
- else {
- return false;
- }
-}
-
-static tstring build_url(const tstring& rsURL, const tstring& from, const tstring& to, double dAmount)
-{
- tostringstream o;
- o << rsURL << L"?a=" << std::fixed << dAmount << L"&from=" << from << L"&to=" << to;
- return o.str();
-}
-
-static tstring build_url(MCONTACT hContact, const tstring& rsURL, double dAmount = 1.0)
-{
- tstring sFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
- tstring sTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
- return build_url(rsURL, sFrom, sTo, dAmount);
-}
-
-typedef IHTMLNode::THTMLNodePtr THTMLNodePtr;
-
-bool parse_html_node(const THTMLNodePtr& pNode, double& rdRate)
-{
- tstring sID = pNode->GetAttribute(L"id");
- if ((false == sID.empty()) && (0 == mir_wstrcmpi(sID.c_str(), L"currency_converter_result"))) {
- size_t cChild = pNode->GetChildCount();
- // assert(1 == cChild);
- if (cChild > 0) {
- THTMLNodePtr pChild = pNode->GetChildPtr(0);
- tstring sRate = pChild->GetText();
-
- tistringstream input(sRate);
- input >> rdRate;
-
- return ((false == input.bad()) && (false == input.fail()));
- }
- }
- else {
- size_t cChild = pNode->GetChildCount();
- for (size_t i = 0; i < cChild; ++i) {
- THTMLNodePtr pChild = pNode->GetChildPtr(i);
- if (pChild && (true == parse_html_node(pChild, rdRate))) {
- return true;
- }
- }
- }
-
- return false;
-}
-
-bool parse_responce(const tstring& rsHTML, double& rdRate)
-{
- IHTMLEngine::THTMLParserPtr pHTMLParser = CModuleInfo::GetHTMLEngine()->GetParserPtr();
- THTMLNodePtr pRoot = pHTMLParser->ParseString(rsHTML);
- if (pRoot) {
- return parse_html_node(pRoot, rdRate);
- }
- else {
- return false;
- }
-}
-
-void CQuotesProviderGoogle::RefreshQuotes(TContracts& anContacts)
-{
- CHTTPSession http;
- tstring sURL = GetURL();
-
- for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i) {
- MCONTACT hContact = *i;
-
- tstring sFullURL = build_url(hContact, sURL);
- // LogIt(Info,sFullURL);
- if ((true == http.OpenURL(sFullURL)) && (true == IsOnline())) {
- tstring sHTML;
- if ((true == http.ReadResponce(sHTML)) && (true == IsOnline())) {
- double dRate = 0.0;
- if ((true == parse_responce(sHTML, dRate)) && (true == IsOnline())) {
- WriteContactRate(hContact, dRate);
- continue;
- }
- }
- }
-
- SetContactStatus(hContact, ID_STATUS_NA);
- }
-}
-
-inline tstring make_quote_name(const CQuotesProviderGoogle::CQuote& rQuote)
-{
- const tstring& rsDesc = rQuote.GetName();
- return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
-}
-
-static CQuotesProviderGoogle* get_google_provider()
-{
- CModuleInfo::TQuotesProvidersPtr pProviders = CModuleInfo::GetQuoteProvidersPtr();
- const CQuotesProviders::TQuotesProviders& rapQuotesProviders = pProviders->GetProviders();
- for (CQuotesProviders::TQuotesProviders::const_iterator i = rapQuotesProviders.begin(); i != rapQuotesProviders.end(); ++i) {
- const CQuotesProviders::TQuotesProviderPtr& pProvider = *i;
- CQuotesProviderGoogle* pGoogle = dynamic_cast<CQuotesProviderGoogle*>(pProvider.get());
- if (pGoogle)
- return pGoogle;
- }
-
- assert(!"We should never get here!");
- return nullptr;
-}
-
-CQuotesProviderGoogle::CQuoteSection get_quotes()
-{
- const CQuotesProviderGoogle* pProvider = get_google_provider();
- if (pProvider) {
- const CQuotesProviderGoogle::CQuoteSection& rQuotes = pProvider->GetQuotes();
- if (rQuotes.GetSectionCount() > 0)
- return rQuotes.GetSection(0);
- }
-
- return CQuotesProviderGoogle::CQuoteSection();
-}
-
-tstring make_rate_name(const CQuotesProviderGoogle::CQuote& rFrom,
- const CQuotesProviderGoogle::CQuote& rTo)
-{
- if ((false == rFrom.GetName().empty()) && (false == rTo.GetName().empty()))
- return make_contact_name(rFrom.GetName(), rTo.GetName());
-
- return make_contact_name(rFrom.GetSymbol(), rTo.GetSymbol());
-}
-
-typedef std::vector<CQuotesProviderGoogle::CRateInfo> TWatchedRates;
-TWatchedRates g_aWatchedRates;
-
-bool is_equal_rate(const CQuotesProviderGoogle::CRateInfo& riL, const CQuotesProviderGoogle::CRateInfo& riR)
-{
- return ((0 == mir_wstrcmpi(riL.m_from.GetID().c_str(), riR.m_from.GetID().c_str()))
- && ((0 == mir_wstrcmpi(riL.m_to.GetID().c_str(), riR.m_to.GetID().c_str()))));
-}
-
-INT_PTR CALLBACK GoogleOptDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
-{
- CQuotesProviderGoogle* pProvider = get_google_provider();
-
- CCommonDlgProcData d(pProvider);
- CommonOptionDlgProc(hdlg, message, wParam, lParam, d);
-
- switch (message) {
- case WM_NOTIFY:
- {
- LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lParam);
- switch (pNMHDR->code) {
- case PSN_APPLY:
- {
- if (pProvider) {
- TWatchedRates aTemp(g_aWatchedRates);
- TWatchedRates aRemove;
- size_t cWatchedRates = pProvider->GetWatchedRateCount();
- for (size_t i = 0; i < cWatchedRates; ++i) {
- CQuotesProviderGoogle::CRateInfo ri;
- if (true == pProvider->GetWatchedRateInfo(i, ri)) {
- TWatchedRates::iterator it =
- std::find_if(aTemp.begin(), aTemp.end(),
- boost::bind(is_equal_rate, _1, boost::cref(ri)));
- if (it == aTemp.end()) {
- aRemove.push_back(ri);
- }
- else {
- aTemp.erase(it);
- }
- }
- }
-
- std::for_each(aRemove.begin(), aRemove.end(), boost::bind(&CQuotesProviderGoogle::WatchForRate, pProvider, _1, false));
- std::for_each(aTemp.begin(), aTemp.end(), boost::bind(&CQuotesProviderGoogle::WatchForRate, pProvider, _1, true));
-
- pProvider->RefreshSettings();
- }
- }
- break;
- }
- }
- break;
-
- case WM_INITDIALOG:
- TranslateDialogDefault(hdlg);
- {
- g_aWatchedRates.clear();
-
- HWND hcbxFrom = ::GetDlgItem(hdlg, IDC_COMBO_CONVERT_FROM);
- HWND hcbxTo = ::GetDlgItem(hdlg, IDC_COMBO_CONVERT_INTO);
-
- const CQuotesProviderGoogle::CQuoteSection& rSection = get_quotes();
- size_t cQuotes = rSection.GetQuoteCount();
- for (size_t i = 0; i < cQuotes; ++i) {
- const CQuotesProviderGoogle::CQuote& rQuote = rSection.GetQuote(i);
- tstring sName = make_quote_name(rQuote);
- LPCTSTR pszName = sName.c_str();
- ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName));
- ::SendMessage(hcbxTo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName));
- }
-
- pProvider = get_google_provider();
- if (pProvider) {
- size_t cWatchedRates = pProvider->GetWatchedRateCount();
- for (size_t i = 0; i < cWatchedRates; ++i) {
- CQuotesProviderGoogle::CRateInfo ri;
- if (true == pProvider->GetWatchedRateInfo(i, ri)) {
- g_aWatchedRates.push_back(ri);
- tstring sRate = make_rate_name(ri.m_from, ri.m_to);
- LPCTSTR pszRateName = sRate.c_str();
- ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRateName));
- }
- }
- }
-
- ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_ADD), FALSE);
- ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_REMOVE), FALSE);
- }
- return TRUE;
-
- case WM_COMMAND:
- switch (HIWORD(wParam)) {
- case CBN_SELCHANGE:
- switch (LOWORD(wParam)) {
- case IDC_COMBO_REFRESH_RATE:
- break;
- case IDC_COMBO_CONVERT_FROM:
- case IDC_COMBO_CONVERT_INTO:
- {
- int nFrom = static_cast<int>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_FROM, CB_GETCURSEL, 0, 0));
- int nTo = static_cast<int>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_INTO, CB_GETCURSEL, 0, 0));
- bool bEnableAddButton = ((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo));
- EnableWindow(GetDlgItem(hdlg, IDC_BUTTON_ADD), bEnableAddButton);
- }
- break;
- case IDC_LIST_RATES:
- {
- int nSel = ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_GETCURSEL, 0, 0);
- ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_REMOVE), (LB_ERR != nSel));
- }
- break;
- }
- break;
-
- case BN_CLICKED:
- switch (LOWORD(wParam)) {
- case IDC_BUTTON_ADD:
- {
- size_t nFrom = static_cast<size_t>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_FROM, CB_GETCURSEL, 0, 0));
- size_t nTo = static_cast<size_t>(::SendDlgItemMessage(hdlg, IDC_COMBO_CONVERT_INTO, CB_GETCURSEL, 0, 0));
- if ((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo)) {
- const CQuotesProviderGoogle::CQuoteSection& rSection = get_quotes();
- size_t cQuotes = rSection.GetQuoteCount();
- if ((nFrom < cQuotes) && (nTo < cQuotes)) {
- CQuotesProviderGoogle::CRateInfo ri;
- ri.m_from = rSection.GetQuote(nFrom);
- ri.m_to = rSection.GetQuote(nTo);
-
- g_aWatchedRates.push_back(ri);
-
- tstring sRate = make_rate_name(ri.m_from, ri.m_to);
- LPCTSTR pszRateName = sRate.c_str();
- ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRateName));
- PropSheet_Changed(::GetParent(hdlg), hdlg);
- }
- }
- }
- break;
-
- case IDC_BUTTON_REMOVE:
- HWND hWnd = ::GetDlgItem(hdlg, IDC_LIST_RATES);
- int nSel = ::SendMessage(hWnd, LB_GETCURSEL, 0, 0);
- if (LB_ERR != nSel) {
- if ((LB_ERR != ::SendMessage(hWnd, LB_DELETESTRING, nSel, 0))
- && (nSel < static_cast<int>(g_aWatchedRates.size()))) {
-
- TWatchedRates::iterator i = g_aWatchedRates.begin();
- std::advance(i, nSel);
- g_aWatchedRates.erase(i);
- PropSheet_Changed(::GetParent(hdlg), hdlg);
- }
- }
-
- nSel = ::SendMessage(hWnd, LB_GETCURSEL, 0, 0);
- ::EnableWindow(::GetDlgItem(hdlg, IDC_BUTTON_REMOVE), (LB_ERR != nSel));
- break;
- }
- break;
- }
- break;
- }
-
- return FALSE;
-}
-
-void CQuotesProviderGoogle::ShowPropertyPage(WPARAM wp, OPTIONSDIALOGPAGE &odp)
-{
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_DIALOG_OPT_GOOGLE);
- odp.pfnDlgProc = GoogleOptDlgProc;
- odp.szTab.w = const_cast<LPTSTR>(GetInfo().m_sName.c_str());
- g_plugin.addOptions(wp, &odp);
-}
-
-void CQuotesProviderGoogle::Accept(CQuotesProviderVisitor& visitor)const
-{
- CQuotesProviderBase::Accept(visitor);
- visitor.Visit(*this);
-}
-
-double CQuotesProviderGoogle::Convert(double dAmount, const CQuote& from, const CQuote& to)const
-{
- tstring sFullURL = build_url(GetURL(), from.GetID(), to.GetID(), dAmount);
-
- CHTTPSession http;
- if ((true == http.OpenURL(sFullURL))) {
- tstring sHTML;
- if ((true == http.ReadResponce(sHTML))) {
- double dResult = 0.0;
- if ((true == parse_responce(sHTML, dResult)))
- return dResult;
-
- throw std::runtime_error(Translate("Error occurred during HTML parsing."));
- }
- else throw std::runtime_error(Translate("Error occurred during site access."));
- }
- else throw std::runtime_error(Translate("Error occurred during site access."));
-
- return 0.0;
-}
-
-namespace
-{
- bool is_equal_ids(MCONTACT hContact, const tstring& rsFromID, const tstring& rsToID)
- {
- tstring sFrom = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID);
- tstring sTo = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID);
- return ((0 == mir_wstrcmpi(rsFromID.c_str(), sFrom.c_str()))
- && (0 == mir_wstrcmpi(rsToID.c_str(), sTo.c_str())));
- }
-}
-
-MCONTACT CQuotesProviderGoogle::GetContactByID(const tstring& rsFromID, const tstring& rsToID)const
-{
- mir_cslock lck(m_cs);
-
- TContracts::const_iterator i = std::find_if(m_aContacts.begin(), m_aContacts.end(),
- boost::bind(is_equal_ids, _1, boost::cref(rsFromID), boost::cref(rsToID)));
- if (i != m_aContacts.end())
- return *i;
-
- return NULL;
-}
diff --git a/plugins/Quotes/src/QuotesProviderGoogle.h b/plugins/Quotes/src/QuotesProviderGoogle.h
deleted file mode 100644
index 083a2945d8..0000000000
--- a/plugins/Quotes/src/QuotesProviderGoogle.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#ifndef __c0e48a95_b3f0_4227_8adc_455e265f3c14_QuotesProviderGoogle_h__
-#define __c0e48a95_b3f0_4227_8adc_455e265f3c14_QuotesProviderGoogle_h__
-
-#define DB_STR_FROM_ID "FromID"
-#define DB_STR_TO_ID "ToID"
-#define DB_STR_FROM_DESCRIPTION "FromDesc"
-#define DB_STR_TO_DESCRIPTION "ToDesc"
-#define DB_STR_GOOGLE_REFRESH_RATE_TYPE "Google_RefreshRateType"
-#define DB_STR_GOOGLE_REFRESH_RATE_VALUE "Google_RefreshRateValue"
-#define DB_STR_GOOGLE_DISPLAY_NAME_FORMAT "Google_DspNameFrmt"
-// #define DB_STR_GOOGLE_LOG_FILE_FORMAT "Google_LogFileFormat"
-// #define DB_STR_GOOGLE_HISTORY_FORMAT "Google_HistoryFormat"
-
-class CQuotesProviderGoogle : public CQuotesProviderBase
-{
-public:
- struct CRateInfo
- {
- CQuotesProviderBase::CQuote m_from;
- CQuotesProviderBase::CQuote m_to;
- };
-public:
- CQuotesProviderGoogle();
- ~CQuotesProviderGoogle();
-
- bool WatchForRate(const CRateInfo& ri, bool bWatch);
- size_t GetWatchedRateCount()const;
- bool GetWatchedRateInfo(size_t nIndex, CRateInfo& rRateInfo);
-
- MCONTACT GetContactByID(const tstring& rsFromID, const tstring& rsToID)const;
-
- double Convert(double dAmount, const CQuote& from, const CQuote& to)const;
-
-private:
- virtual void RefreshQuotes(TContracts& anContacts);
- virtual void ShowPropertyPage(WPARAM wp, OPTIONSDIALOGPAGE& odp);
- virtual void Accept(CQuotesProviderVisitor& visitor)const;
-};
-
-#endif //__c0e48a95_b3f0_4227_8adc_455e265f3c14_QuotesProviderGoogle_h__
diff --git a/plugins/Quotes/src/QuotesProviderVisitor.h b/plugins/Quotes/src/QuotesProviderVisitor.h
index f074884030..f262763871 100644
--- a/plugins/Quotes/src/QuotesProviderVisitor.h
+++ b/plugins/Quotes/src/QuotesProviderVisitor.h
@@ -4,9 +4,9 @@
class CQuotesProviderBase;
class CQuotesProviderFinance;
class CQuotesProviderDukasCopy;
-class CQuotesProviderGoogle;
class CQuotesProviderGoogleFinance;
class CQuotesProviderYahoo;
+class CQuotesProviderCurrencyConverter;
class CQuotesProviderVisitor
{
@@ -17,9 +17,9 @@ public:
virtual void Visit(const CQuotesProviderBase&){}
virtual void Visit(const CQuotesProviderFinance&){}
virtual void Visit(const CQuotesProviderDukasCopy&){}
- virtual void Visit(const CQuotesProviderGoogle&){}
virtual void Visit(const CQuotesProviderGoogleFinance&){}
virtual void Visit(const CQuotesProviderYahoo&){}
+ virtual void Visit(const CQuotesProviderCurrencyConverter&) {}
};
#endif //__7fca59e7_17b2_4849_bd7a_02c7675f2d76_QuotesProviderVisitor_h__
diff --git a/plugins/Quotes/src/QuotesProviderVisitorDbSettings.cpp b/plugins/Quotes/src/QuotesProviderVisitorDbSettings.cpp
index 51f4fab953..2208d7561f 100644
--- a/plugins/Quotes/src/QuotesProviderVisitorDbSettings.cpp
+++ b/plugins/Quotes/src/QuotesProviderVisitorDbSettings.cpp
@@ -68,34 +68,6 @@ void CQuotesProviderVisitorDbSettings::Visit(const CQuotesProviderDukasCopy&/* r
m_pszDbTendencyFormat = "DC_TendencyFormat";
}
-void CQuotesProviderVisitorDbSettings::Visit(const CQuotesProviderGoogle&/* rProvider*/)
-{
- m_pszDbRefreshRateType = DB_STR_GOOGLE_REFRESH_RATE_TYPE;
- m_pszDbRefreshRateValue = DB_STR_GOOGLE_REFRESH_RATE_VALUE;
- m_pszDbDisplayNameFormat = DB_STR_GOOGLE_DISPLAY_NAME_FORMAT;
- m_pszDefDisplayFormat = L"1 %f = %r %i";
- m_pszXMLIniFileName = L"Google.xml";
- m_pszDbStatusMsgFormat = "Google_StatusMessageFormat";
-
- m_pszDbLogMode = "Google_LogMode";
- m_pszDbHistoryFormat = "Google_HistoryFormat";
- m_pszDbHistoryCondition = "Google_AddToHistoryOnlyIfValueIsChanged";
- m_pszDbLogFile = "Google_LogFile";
- m_pszDbLogFormat = "Google_LogFileFormat";
- m_pszDbLogCondition = "Google_AddToLogOnlyIfValueIsChanged";
- m_pszDbPopupFormat = "Google_PopupFormat";
- m_pszDbPopupCondition = "Google_ShowPopupOnlyIfValueChanged";
-
- m_pszDbPopupColourMode = "Google_PopupColourMode";
- m_pszDbPopupBkColour = "Google_PopupColourBk";
- m_pszDbPopupTextColour = "Google_PopupColourText";
- m_pszDbPopupDelayMode = "Google_PopupDelayMode";
- m_pszDbPopupDelayTimeout = "Google_PopupDelayTimeout";
- m_pszDbPopupHistoryFlag = "Google_PopupHistoryFlag";
-
- m_pszDbTendencyFormat = "Google_TendencyFormat";
-}
-
void CQuotesProviderVisitorDbSettings::Visit(const CQuotesProviderGoogleFinance&/* rProvider*/)
{
m_pszDbRefreshRateType = "GoogleFinance_RefreshRateType";
@@ -151,3 +123,31 @@ void CQuotesProviderVisitorDbSettings::Visit(const CQuotesProviderYahoo&)
m_pszDbTendencyFormat = "Yahoo_TendencyFormat";
}
+
+void CQuotesProviderVisitorDbSettings::Visit(const CQuotesProviderCurrencyConverter&)
+{
+ m_pszDbRefreshRateType = "CC_RefreshRateType";
+ m_pszDbRefreshRateValue = "CC_RefreshRateValue";
+ m_pszDbDisplayNameFormat = "CC_DspNameFrmt";
+ m_pszDefDisplayFormat = L"1 %f = %r %i";
+ m_pszXMLIniFileName = L"CC.xml";
+ m_pszDbStatusMsgFormat = "CC_StatusMessageFormat";
+
+ m_pszDbLogMode = "CC_LogMode";
+ m_pszDbHistoryFormat = "CC_HistoryFormat";
+ m_pszDbHistoryCondition = "CC_AddToHistoryOnlyIfValueIsChanged";
+ m_pszDbLogFile = "CC_LogFile";
+ m_pszDbLogFormat = "CC_LogFileFormat";
+ m_pszDbLogCondition = "CC_AddToLogOnlyIfValueIsChanged";
+ m_pszDbPopupFormat = "CC_PopupFormat";
+ m_pszDbPopupCondition = "CC_ShowPopupOnlyIfValueChanged";
+
+ m_pszDbPopupColourMode = "CC_PopupColourMode";
+ m_pszDbPopupBkColour = "CC_PopupColourBk";
+ m_pszDbPopupTextColour = "CC_PopupColourText";
+ m_pszDbPopupDelayMode = "CC_PopupDelayMode";
+ m_pszDbPopupDelayTimeout = "CC_PopupDelayTimeout";
+ m_pszDbPopupHistoryFlag = "CC_PopupHistoryFlag";
+
+ m_pszDbTendencyFormat = "CC_TendencyFormat";
+}
diff --git a/plugins/Quotes/src/QuotesProviderVisitorDbSettings.h b/plugins/Quotes/src/QuotesProviderVisitorDbSettings.h
index 95805cc110..12ce87ee14 100644
--- a/plugins/Quotes/src/QuotesProviderVisitorDbSettings.h
+++ b/plugins/Quotes/src/QuotesProviderVisitorDbSettings.h
@@ -8,11 +8,11 @@ public:
~CQuotesProviderVisitorDbSettings();
private:
- virtual void Visit(const CQuotesProviderBase& rProvider);
- virtual void Visit(const CQuotesProviderDukasCopy& rProvider);
- virtual void Visit(const CQuotesProviderGoogle& rProvider);
- virtual void Visit(const CQuotesProviderGoogleFinance& rProvider);
- virtual void Visit(const CQuotesProviderYahoo& rProvider);
+ virtual void Visit(const CQuotesProviderBase& rProvider)override;
+ virtual void Visit(const CQuotesProviderDukasCopy& rProvider)override;
+ virtual void Visit(const CQuotesProviderGoogleFinance& rProvider)override;
+ virtual void Visit(const CQuotesProviderYahoo& rProvider)override;
+ virtual void Visit(const CQuotesProviderCurrencyConverter& rProvider)override;
public:
LPCSTR m_pszDbRefreshRateType;
LPCSTR m_pszDbRefreshRateValue;
diff --git a/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.cpp b/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.cpp
index 5dc1bd1848..09a62442ab 100644
--- a/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.cpp
+++ b/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.cpp
@@ -14,15 +14,6 @@ void CQuotesProviderVisitorFormatSpecificator::Visit(const CQuotesProviderDukasC
m_aSpecificators.push_back(CFormatSpecificator(L"%d", TranslateT("Quote Name")));
}
-void CQuotesProviderVisitorFormatSpecificator::Visit(const CQuotesProviderGoogle&/* rProvider*/)
-{
- m_aSpecificators.push_back(CFormatSpecificator(L"%F", TranslateT("From Currency Full Name")));
- m_aSpecificators.push_back(CFormatSpecificator(L"%f", TranslateT("From Currency Short Name")));
- m_aSpecificators.push_back(CFormatSpecificator(L"%I", TranslateT("Into Currency Full Name")));
- m_aSpecificators.push_back(CFormatSpecificator(L"%i", TranslateT("Into Currency Short Name")));
- m_aSpecificators.push_back(CFormatSpecificator(L"%s", TranslateT("Short notation for \"%f/%i\"")));
-}
-
void CQuotesProviderVisitorFormatSpecificator::Visit(const CQuotesProviderBase&/* rProvider*/)
{
m_aSpecificators.push_back(CFormatSpecificator(L"%S", TranslateT("Source of Information")));
@@ -60,3 +51,12 @@ void CQuotesProviderVisitorFormatSpecificator::Visit(const CQuotesProviderYahoo&
m_aSpecificators.push_back(CFormatSpecificator(L"%P", TranslateT("Previous Close")));
m_aSpecificators.push_back(CFormatSpecificator(L"%c", TranslateT("Change")));
}
+
+void CQuotesProviderVisitorFormatSpecificator::Visit(const CQuotesProviderCurrencyConverter&)
+{
+ m_aSpecificators.push_back(CFormatSpecificator(L"%F", TranslateT("From Currency Full Name")));
+ m_aSpecificators.push_back(CFormatSpecificator(L"%f", TranslateT("From Currency Short Name")));
+ m_aSpecificators.push_back(CFormatSpecificator(L"%I", TranslateT("Into Currency Full Name")));
+ m_aSpecificators.push_back(CFormatSpecificator(L"%i", TranslateT("Into Currency Short Name")));
+ m_aSpecificators.push_back(CFormatSpecificator(L"%s", TranslateT("Short notation for \"%f/%i\"")));
+} \ No newline at end of file
diff --git a/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.h b/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.h
index 25bb88b15e..156b82b9aa 100644
--- a/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.h
+++ b/plugins/Quotes/src/QuotesProviderVisitorFormatSpecificator.h
@@ -21,12 +21,11 @@ public:
const TFormatSpecificators& GetSpecificators()const;
private:
- virtual void Visit(const CQuotesProviderDukasCopy& rProvider);
- virtual void Visit(const CQuotesProviderGoogle& rProvider);
- virtual void Visit(const CQuotesProviderBase& rProvider);
- virtual void Visit(const CQuotesProviderGoogleFinance& rProvider);
- virtual void Visit(const CQuotesProviderYahoo& rProvider);
-
+ virtual void Visit(const CQuotesProviderDukasCopy& rProvider)override;
+ virtual void Visit(const CQuotesProviderBase& rProvider)override;
+ virtual void Visit(const CQuotesProviderGoogleFinance& rProvider)override;
+ virtual void Visit(const CQuotesProviderYahoo& rProvider)override;
+ virtual void Visit(const CQuotesProviderCurrencyConverter& rProvider)override;
private:
TFormatSpecificators m_aSpecificators;
};
diff --git a/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp b/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp
index f421813bf7..f6af082980 100644
--- a/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp
+++ b/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp
@@ -1,4 +1,5 @@
#include "StdAfx.h"
+#include "QuotesProviderCurrencyConverter.h"
CQuotesProviderVisitorFormater::CQuotesProviderVisitorFormater(MCONTACT hContact, wchar_t chr, int nWidth)
: m_hContact(hContact),
@@ -22,24 +23,6 @@ void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderDukasCopy&)
m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_DESCRIPTION);
}
-void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderGoogle&)
-{
- switch (m_chr) {
- case 'F':
- m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_FROM_DESCRIPTION);
- break;
- case 'f':
- m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_FROM_ID);
- break;
- case 'I':
- m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_TO_DESCRIPTION);
- break;
- case 'i':
- m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_TO_ID);
- break;
- }
-}
-
static bool get_fetch_time(MCONTACT hContact, time_t& rTime)
{
DBVARIANT dbv;
@@ -166,3 +149,21 @@ void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderYahoo&)
break;
}
}
+
+void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderCurrencyConverter&)
+{
+ switch (m_chr) {
+ case 'F':
+ m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_FROM_DESCRIPTION);
+ break;
+ case 'f':
+ m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_FROM_ID);
+ break;
+ case 'I':
+ m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_TO_DESCRIPTION);
+ break;
+ case 'i':
+ m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_TO_ID);
+ break;
+ }
+} \ No newline at end of file
diff --git a/plugins/Quotes/src/QuotesProviderVisitorFormater.h b/plugins/Quotes/src/QuotesProviderVisitorFormater.h
index 0b03842a35..5017edd33b 100644
--- a/plugins/Quotes/src/QuotesProviderVisitorFormater.h
+++ b/plugins/Quotes/src/QuotesProviderVisitorFormater.h
@@ -10,11 +10,11 @@ public:
const tstring& GetResult()const;
private:
- virtual void Visit(const CQuotesProviderDukasCopy& rProvider);
- virtual void Visit(const CQuotesProviderGoogle& rProvider);
- virtual void Visit(const CQuotesProviderBase& rProvider);
- virtual void Visit(const CQuotesProviderGoogleFinance& rProvider);
- virtual void Visit(const CQuotesProviderYahoo& rProvider);
+ virtual void Visit(const CQuotesProviderDukasCopy& rProvider)override;
+ virtual void Visit(const CQuotesProviderBase& rProvider)override;
+ virtual void Visit(const CQuotesProviderGoogleFinance& rProvider)override;
+ virtual void Visit(const CQuotesProviderYahoo& rProvider)override;
+ virtual void Visit(const CQuotesProviderCurrencyConverter& rProvider)override;
private:
void FormatDoubleHelper(LPCSTR pszDbSet, const tstring sInvalid = L"-");
diff --git a/plugins/Quotes/src/QuotesProviders.cpp b/plugins/Quotes/src/QuotesProviders.cpp
index f12c0f39df..c9bb5fc045 100644
--- a/plugins/Quotes/src/QuotesProviders.cpp
+++ b/plugins/Quotes/src/QuotesProviders.cpp
@@ -1,4 +1,5 @@
#include "StdAfx.h"
+#include "QuotesProviderCurrencyConverter.h"
#define LAST_RUN_VERSION "LastRunVersion"
@@ -27,9 +28,9 @@ template<class T>void create_provider(CQuotesProviders::TQuotesProviders& apProv
void CQuotesProviders::CreateProviders()
{
create_provider<CQuotesProviderDukasCopy>(m_apProviders);
- create_provider<CQuotesProviderGoogle>(m_apProviders);
create_provider<CQuotesProviderGoogleFinance>(m_apProviders);
create_provider<CQuotesProviderYahoo>(m_apProviders);
+ create_provider<CQuotesProviderCurrencyConverter>(m_apProviders);
}
void CQuotesProviders::ClearProviders()
diff --git a/plugins/Quotes/src/resource.h b/plugins/Quotes/src/resource.h
index d1c78c3a60..c0154194f1 100644
--- a/plugins/Quotes/src/resource.h
+++ b/plugins/Quotes/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by C:\Code\My code\MirandaNG\plugins\Quotes\res\Forex.rc
+// Used by C:\Code\miranda-ng-from-github\plugins\Quotes\res\Forex.rc
//
#define IDD_DIALOG_ECONOMIC_RATES 101
#define IDI_ICON_MAIN 102
@@ -96,7 +96,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 124
+#define _APS_NEXT_RESOURCE_VALUE 125
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1073
#define _APS_NEXT_SYMED_VALUE 101
diff --git a/plugins/Quotes/src/stdafx.h b/plugins/Quotes/src/stdafx.h
index ad3d73a0cd..4c2eb96152 100644
--- a/plugins/Quotes/src/stdafx.h
+++ b/plugins/Quotes/src/stdafx.h
@@ -96,7 +96,6 @@ inline tstring quotes_a2t(const char* s)
#include "QuotesProviders.h"
#include "QuotesProviderBase.h"
#include "QuotesProviderFinance.h"
-#include "QuotesProviderGoogle.h"
#include "QuotesProviderYahoo.h"
#include "QuotesProviderDukasCopy.h"
#include "QuotesProviderGoogleFinance.h"