summaryrefslogtreecommitdiff
path: root/protocols/CurrencyRates
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-11-17 18:07:10 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-11-17 18:07:10 +0300
commitf47c3437da642cc85e6e1fed470a2964e914f208 (patch)
tree73f01228df45c6ac6ea0f669c40966c5b1a193fb /protocols/CurrencyRates
parent0353de737783a61cc1381d26dcdeda3111b61cb8 (diff)
CurrencyRates: adaptation for two or more data providers
Diffstat (limited to 'protocols/CurrencyRates')
-rw-r--r--protocols/CurrencyRates/Forex.vcxproj1
-rw-r--r--protocols/CurrencyRates/Forex.vcxproj.filters3
-rw-r--r--protocols/CurrencyRates/res/Forex.rc73
-rw-r--r--protocols/CurrencyRates/src/CurrencyConverter.cpp62
-rw-r--r--protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp34
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp39
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderBase.h29
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp6
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h2
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderExchangeRates.cpp86
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviders.cpp44
-rw-r--r--protocols/CurrencyRates/src/EconomicRateInfo.h1
-rw-r--r--protocols/CurrencyRates/src/Forex.cpp14
-rw-r--r--protocols/CurrencyRates/src/HTTPSession.cpp8
-rw-r--r--protocols/CurrencyRates/src/ICurrencyRatesProvider.h19
-rw-r--r--protocols/CurrencyRates/src/ImportExport.cpp6
-rw-r--r--protocols/CurrencyRates/src/Options.cpp148
-rw-r--r--protocols/CurrencyRates/src/SettingsDlg.cpp10
-rw-r--r--protocols/CurrencyRates/src/resource.h13
19 files changed, 340 insertions, 258 deletions
diff --git a/protocols/CurrencyRates/Forex.vcxproj b/protocols/CurrencyRates/Forex.vcxproj
index e2a771d55e..f65c410009 100644
--- a/protocols/CurrencyRates/Forex.vcxproj
+++ b/protocols/CurrencyRates/Forex.vcxproj
@@ -32,6 +32,7 @@
<ClCompile Include="src\CurrencyRateInfoDlg.cpp" />
<ClCompile Include="src\CurrencyRatesProviderBase.cpp" />
<ClCompile Include="src\CurrencyRatesProviderCurrencyConverter.cpp" />
+ <ClCompile Include="src\CurrencyRatesProviderExchangeRates.cpp" />
<ClCompile Include="src\CurrencyRatesProviders.cpp" />
<ClCompile Include="src\DBUtils.cpp" />
<ClCompile Include="src\ExtraImages.cpp" />
diff --git a/protocols/CurrencyRates/Forex.vcxproj.filters b/protocols/CurrencyRates/Forex.vcxproj.filters
index 247512c02b..f01423621c 100644
--- a/protocols/CurrencyRates/Forex.vcxproj.filters
+++ b/protocols/CurrencyRates/Forex.vcxproj.filters
@@ -56,6 +56,9 @@
<ClCompile Include="src\Options.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\CurrencyRatesProviderExchangeRates.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Chart.h">
diff --git a/protocols/CurrencyRates/res/Forex.rc b/protocols/CurrencyRates/res/Forex.rc
index e62a62d4e6..531692f1b4 100644
--- a/protocols/CurrencyRates/res/Forex.rc
+++ b/protocols/CurrencyRates/res/Forex.rc
@@ -222,15 +222,13 @@ BEGIN
EDITTEXT IDC_EDIT_PREVIOUS_RATE,97,75,61,12,ES_AUTOHSCROLL | ES_READONLY
END
-IDD_DIALOG_OPT_GOOGLE DIALOGEX 0, 0, 310, 242
+IDD_OPTIONS_GENERAL DIALOGEX 0, 0, 310, 242
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- LTEXT "&Convert:",IDC_STATIC,7,9,56,8
- COMBOBOX IDC_COMBO_CONVERT_FROM,64,7,105,44,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
- LTEXT "&to:",IDC_STATIC,175,9,21,8
- COMBOBOX IDC_COMBO_CONVERT_INTO,200,7,105,44,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+ LTEXT "Provider:",IDC_STATIC,7,9,78,8
+ COMBOBOX IDC_PROVIDER,79,7,226,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Add",IDC_BUTTON_ADD,255,35,50,14
LTEXT "&Watched currency rates:",IDC_STATIC,7,23,110,8
LISTBOX IDC_LIST_RATES,19,35,231,111,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
@@ -248,6 +246,7 @@ BEGIN
EDITTEXT IDC_EDIT_TENDENCY_FORMAT,117,193,120,12,ES_AUTOHSCROLL
LTEXT "&Personal key:",IDC_STATIC,7,210,107,8
EDITTEXT IDC_EDIT_PERSONAL_KEY,117,208,120,12,ES_AUTOHSCROLL
+ PUSHBUTTON "Get key",IDC_GET_KEY,245,208,50,12
PUSHBUTTON "&Advanced Settings...",IDC_BUTTON_ADVANCED_SETTINGS,105,223,110,14
END
@@ -324,11 +323,10 @@ BEGIN
BOTTOMMARGIN, 124
END
- IDD_DIALOG_OPT_GOOGLE, DIALOG
+ IDD_OPTIONS_GENERAL, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 305
- VERTGUIDE, 249
TOPMARGIN, 7
BOTTOMMARGIN, 237
END
@@ -354,7 +352,7 @@ BEGIN
0
END
-IDD_DIALOG_OPT_GOOGLE AFX_DIALOG_LAYOUT
+IDD_OPTIONS_GENERAL AFX_DIALOG_LAYOUT
BEGIN
0
END
@@ -363,6 +361,65 @@ END
/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// English (United States) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_ADD_PAIR DIALOGEX 0, 0, 314, 63
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Add currency pair"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,205,42,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,257,42,50,14
+ LTEXT "From:",IDC_STATIC,7,8,73,8
+ COMBOBOX IDC_COMBO_CONVERT_FROM,82,7,225,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ LTEXT "To:",IDC_STATIC,7,27,72,8
+ COMBOBOX IDC_COMBO_CONVERT_INTO,82,24,225,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_ADD_PAIR, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 307
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 56
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// AFX_DIALOG_LAYOUT
+//
+
+IDD_ADD_PAIR AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
+#endif // English (United States) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/CurrencyRates/src/CurrencyConverter.cpp b/protocols/CurrencyRates/src/CurrencyConverter.cpp
index 16b6cd6618..a5add5ecef 100644
--- a/protocols/CurrencyRates/src/CurrencyConverter.cpp
+++ b/protocols/CurrencyRates/src/CurrencyConverter.cpp
@@ -6,36 +6,6 @@
#define DB_STR_CC_CURRENCYRATE_TO_ID "CurrencyConverter_ToID"
#define DB_STR_CC_AMOUNT "CurrencyConverter_Amount"
-static CCurrencyRatesProviderBase *get_currency_converter_provider()
-{
- for (auto &it : g_apProviders)
- if (auto p = dynamic_cast<CCurrencyRatesProviderBase *>(it))
- return p;
-
- assert(!"We should never get here!");
- return nullptr;
-}
-
-CCurrencyRateSection get_currencyrates(const CCurrencyRatesProviderBase *pProvider = nullptr)
-{
- if (nullptr == pProvider)
- pProvider = get_currency_converter_provider();
-
- if (pProvider) {
- const auto &rCurrencyRates = pProvider->GetCurrencyRates();
- if (rCurrencyRates.GetSectionCount() > 0)
- return rCurrencyRates.GetSection(0);
- }
-
- return CCurrencyRateSection();
-}
-
-inline CMStringW make_currencyrate_name(const CCurrencyRate &rCurrencyRate)
-{
- const CMStringW &rsDesc = rCurrencyRate.GetName();
- return((false == rsDesc.IsEmpty()) ? rsDesc : rCurrencyRate.GetSymbol());
-}
-
inline void update_convert_button(HWND hDlg)
{
int nFrom = static_cast<int>(::SendDlgItemMessage(hDlg, IDC_COMBO_CONVERT_FROM, CB_GETCURSEL, 0, 0));
@@ -75,20 +45,17 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM
CMStringW sFromCurrencyRateID = g_plugin.getMStringW(DB_STR_CC_CURRENCYRATE_FROM_ID);
CMStringW sToCurrencyRateID = g_plugin.getMStringW(DB_STR_CC_CURRENCYRATE_TO_ID);
- const auto pProvider = get_currency_converter_provider();
- const auto &rSection = get_currencyrates(pProvider);
- auto cCurrencyRates = rSection.GetCurrencyRateCount();
- for (auto i = 0u; i < cCurrencyRates; ++i) {
- const auto &rCurrencyRate = rSection.GetCurrencyRate(i);
- CMStringW sName = make_currencyrate_name(rCurrencyRate);
+ auto &rSection = g_pCurrentProvider->GetSection();
+ for (auto &it : rSection.GetCurrencyRates()) {
+ CMStringW sName = it.MakeName();
LRESULT nFrom = ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, LPARAM(sName.c_str()));
LRESULT nTo = ::SendMessage(hcbxTo, CB_ADDSTRING, 0, LPARAM(sName.c_str()));
- if (0 == mir_wstrcmpi(rCurrencyRate.GetID().c_str(), sFromCurrencyRateID.c_str())) {
+ if (0 == mir_wstrcmpi(it.GetID().c_str(), sFromCurrencyRateID.c_str())) {
::SendMessage(hcbxFrom, CB_SETCURSEL, nFrom, 0);
}
- if (0 == mir_wstrcmpi(rCurrencyRate.GetID().c_str(), sToCurrencyRateID.c_str())) {
+ if (0 == mir_wstrcmpi(it.GetID().c_str(), sToCurrencyRateID.c_str())) {
::SendMessage(hcbxTo, CB_SETCURSEL, nTo, 0);
}
}
@@ -99,7 +66,7 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM
swprintf_s(str, L"%.2lf", dAmount);
::SetDlgItemText(hDlg, IDC_EDIT_VALUE, str);
- auto &pi = pProvider->GetInfo();
+ auto &pi = g_pCurrentProvider->GetInfo();
CMStringW provInfo(FORMAT, L"%s <a href=\"%s\">%s</a>", TranslateT("Info provided by"), pi.m_sURL.c_str(), pi.m_sName.c_str());
::SetDlgItemText(hDlg, IDC_SYSLINK_PROVIDER, provInfo);
@@ -168,22 +135,21 @@ 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 auto &rSection = get_currencyrates();
- size_t cCurrencyRates = rSection.GetCurrencyRateCount();
- if ((nFrom < cCurrencyRates) && (nTo < cCurrencyRates)) {
- auto from = rSection.GetCurrencyRate(nFrom);
- auto to = rSection.GetCurrencyRate(nTo);
+ const auto &rSection = g_pCurrentProvider->GetSection();
+ auto &cCurrencyRates = rSection.GetCurrencyRates();
+ if ((nFrom < cCurrencyRates.size()) && (nTo < cCurrencyRates.size())) {
+ auto &from = cCurrencyRates[nFrom];
+ auto &to = cCurrencyRates[nTo];
g_plugin.setWString(DB_STR_CC_CURRENCYRATE_FROM_ID, from.GetID().c_str());
g_plugin.setWString(DB_STR_CC_CURRENCYRATE_TO_ID, to.GetID().c_str());
- const auto pProvider = get_currency_converter_provider();
- assert(pProvider);
- if (pProvider) {
+ assert(g_pCurrentProvider);
+ if (g_pCurrentProvider) {
CMStringW sResult;
try {
- double dResult = pProvider->Convert(dAmount, from, to);
+ double dResult = g_pCurrentProvider->Convert(dAmount, from, to);
sResult.Format(L"%.2lf %s = %.2lf %s", dAmount, from.GetName().c_str(), dResult, to.GetName().c_str());
}
catch (std::exception &e) {
diff --git a/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp b/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp
index bb59292a77..33428830fe 100644
--- a/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp
+++ b/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp
@@ -14,7 +14,7 @@ MCONTACT g_hContact;
inline bool IsMyContact(MCONTACT hContact)
{
- return nullptr != GetContactProviderPtr(hContact);
+ return Proto_IsProtoOnContact(hContact, MODULENAME);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -57,7 +57,7 @@ public:
}
}
- auto &pi = GetContactProviderPtr(m_hContact)->GetInfo();
+ auto &pi = g_pCurrentProvider->GetInfo();
CMStringW provInfo(FORMAT, L"%s <a href=\"%s\">%s</a>", TranslateT("Info provided by"), pi.m_sURL.c_str(), pi.m_sName.c_str());
::SetDlgItemTextW(m_hwnd, IDC_SYSLINK_PROVIDER, provInfo);
return false;
@@ -119,22 +119,21 @@ struct CurrencyRateInfoDlg2 : public CurrencyRateInfoDlg
int CurrencyRates_OnContactDoubleClick(WPARAM wp, LPARAM/* lp*/)
{
- MCONTACT hContact = MCONTACT(wp);
- if (GetContactProviderPtr(hContact)) {
- MWindowList hWL = CModuleInfo::GetWindowList(WINDOW_PREFIX_INFO, true);
- assert(hWL);
- HWND hWnd = WindowList_Find(hWL, hContact);
- if (nullptr != hWnd) {
- SetForegroundWindow(hWnd);
- SetFocus(hWnd);
- }
- else if (true == IsMyContact(hContact))
- (new CurrencyRateInfoDlg2(hContact))->Show();
+ if (!g_pCurrentProvider)
+ return 0;
- return 1;
+ MCONTACT hContact = MCONTACT(wp);
+ MWindowList hWL = CModuleInfo::GetWindowList(WINDOW_PREFIX_INFO, true);
+ assert(hWL);
+ HWND hWnd = WindowList_Find(hWL, hContact);
+ if (nullptr != hWnd) {
+ SetForegroundWindow(hWnd);
+ SetFocus(hWnd);
}
+ else if (true == IsMyContact(hContact))
+ (new CurrencyRateInfoDlg2(hContact))->Show();
- return 0;
+ return 1;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -175,9 +174,8 @@ INT_PTR CurrencyRatesMenu_RefreshContact(WPARAM wp, LPARAM)
if (NULL == hContact)
return 0;
- ICurrencyRatesProvider *pProvider = GetContactProviderPtr(hContact);
- if (pProvider)
- pProvider->RefreshContact(hContact);
+ if (g_pCurrentProvider)
+ g_pCurrentProvider->RefreshContact(hContact);
return 0;
}
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp
index adf19de68a..5084304bd3 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp
@@ -38,18 +38,12 @@ bool parse_currencyrate(const TiXmlNode *pTop, CCurrencyRate &q)
bool parse_section(const TiXmlNode *pTop, CCurrencyRateSection &qs)
{
- CCurrencyRateSection::TSections aSections;
CCurrencyRateSection::TCurrencyRates aCurrencyRates;
CMStringW sSectionName;
for (auto *pNode : TiXmlEnum(pTop)) {
const char *sName = pNode->Value();
- if (!mir_strcmpi(sName, "section")) {
- CCurrencyRateSection qs1;
- if (true == parse_section(pNode, qs1))
- aSections.push_back(qs1);
- }
- else if (!mir_strcmpi(sName, "currencyrate")) {
+ if (!mir_strcmpi(sName, "currencyrate")) {
CCurrencyRate q;
if (true == parse_currencyrate(pNode, q))
aCurrencyRates.push_back(q);
@@ -61,7 +55,7 @@ bool parse_section(const TiXmlNode *pTop, CCurrencyRateSection &qs)
}
}
- qs = CCurrencyRateSection(TranslateW(sSectionName.c_str()), aSections, aCurrencyRates);
+ qs = CCurrencyRateSection(TranslateW(sSectionName.c_str()), aCurrencyRates);
return true;
}
@@ -82,8 +76,7 @@ const TiXmlNode *find_provider(const TiXmlNode *pRoot)
CXMLFileInfo parse_ini_file(const CMStringW &rsXMLFile, bool &rbSucceded)
{
CXMLFileInfo res;
- CCurrencyRateSection::TSections aSections;
-
+
TiXmlDocument doc;
if (doc.LoadFile(_T2A(rsXMLFile.c_str())) == tinyxml2::XML_SUCCESS) {
const TiXmlNode *pProvider = find_provider(&doc);
@@ -94,7 +87,7 @@ CXMLFileInfo parse_ini_file(const CMStringW &rsXMLFile, bool &rbSucceded)
if (!mir_strcmpi(sName, "section")) {
CCurrencyRateSection qs;
if (parse_section(pNode, qs))
- aSections.push_back(qs);
+ res.m_qs = qs;
}
else if (!mir_strcmpi(sName, "Name"))
res.m_pi.m_sName = GetNodeText(pNode);
@@ -106,7 +99,6 @@ CXMLFileInfo parse_ini_file(const CMStringW &rsXMLFile, bool &rbSucceded)
}
}
- res.m_qs = CCurrencyRateSection(res.m_pi.m_sName, aSections);
return res;
}
@@ -148,7 +140,7 @@ const CCurrencyRatesProviderBase::CProviderInfo &CCurrencyRatesProviderBase::Get
return m_pXMLInfo->m_pi;
}
-const CCurrencyRateSection &CCurrencyRatesProviderBase::GetCurrencyRates() const
+const CCurrencyRateSection &CCurrencyRatesProviderBase::GetSection() const
{
return m_pXMLInfo->m_qs;
}
@@ -193,7 +185,8 @@ public:
{
NotChanged,
Up,
- Down
+ Down,
+ Unknown = -1
};
public:
@@ -412,15 +405,19 @@ bool show_popup(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, int
memset(&ppd, 0, sizeof(ppd));
ppd.lchContact = hContact;
- if (CTendency::NotChanged == nComparison)
- ppd.lchIcon = g_plugin.getIcon(IDI_ICON_NOTCHANGED);
- else if (CTendency::Up == nComparison)
- ppd.lchIcon = g_plugin.getIcon(IDI_ICON_UP);
- else if (CTendency::Down == nComparison)
- ppd.lchIcon = g_plugin.getIcon(IDI_ICON_DOWN);
+ switch (nComparison) {
+ case CTendency::Up: ppd.lchIcon = g_plugin.getIcon(IDI_ICON_UP); break;
+ case CTendency::Down: ppd.lchIcon = g_plugin.getIcon(IDI_ICON_DOWN); break;
+ case CTendency::NotChanged: ppd.lchIcon = g_plugin.getIcon(IDI_ICON_NOTCHANGED); break;
+ default:
+ ppd.lchIcon = g_plugin.getIcon(IDI_ICON_CURRENCYRATE);
+ }
if (pProvider != nullptr) {
- mir_wstrncpy(ppd.lpwzContactName, pProvider->FormatSymbol(hContact, 's').c_str(), MAX_CONTACTNAME);
+ if (hContact)
+ mir_wstrncpy(ppd.lpwzContactName, pProvider->FormatSymbol(hContact, 's').c_str(), MAX_CONTACTNAME);
+ else
+ mir_wstrncpy(ppd.lpwzContactName, TranslateT("Currency Rates"), MAX_CONTACTNAME);
ptrW ss(variables_parsedup((wchar_t *)rsFormat.c_str(), nullptr, hContact));
mir_wstrncpy(ppd.lpwzText, format_rate(pProvider, hContact, ss.get()), MAX_SECONDLINE);
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
index d17795afed..79b3c3b26a 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
@@ -16,6 +16,8 @@ public:
const CMStringW& GetSymbol() const{ return m_sSymbol; }
const CMStringW& GetName() const{ return m_sName; }
const CMStringW& GetID() const{ return m_sID; }
+
+ const CMStringW& MakeName() const { return m_sName.IsEmpty() ? m_sID : m_sName; }
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -24,17 +26,15 @@ public:
class CCurrencyRateSection
{
public:
- typedef std::vector<CCurrencyRateSection> TSections;
typedef std::vector<CCurrencyRate> TCurrencyRates;
private:
CMStringW m_sName;
- TSections m_aSections;
TCurrencyRates m_aCurrencyRates;
public:
- CCurrencyRateSection(const CMStringW &rsName = L"", const TSections &raSections = TSections(), const TCurrencyRates &raCurrencyRates = TCurrencyRates()) :
- m_sName(rsName), m_aSections(raSections), m_aCurrencyRates(raCurrencyRates)
+ CCurrencyRateSection(const CMStringW &rsName = L"", const TCurrencyRates &raCurrencyRates = TCurrencyRates()) :
+ m_sName(rsName), m_aCurrencyRates(raCurrencyRates)
{}
const CMStringW& GetName() const
@@ -42,24 +42,9 @@ public:
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
+ const TCurrencyRates& GetCurrencyRates() const
{
- return ((nIndex < m_aCurrencyRates.size()) ? m_aCurrencyRates[nIndex] : CCurrencyRate());
+ return m_aCurrencyRates;
}
};
@@ -84,7 +69,7 @@ public:
CCurrencyRatesProviderBase();
~CCurrencyRatesProviderBase();
- const CCurrencyRateSection& GetCurrencyRates() const;
+ const CCurrencyRateSection& GetSection() const;
bool Init() override;
const CProviderInfo& GetInfo() const override;
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp
index a34d272052..3e8195fa4b 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp
@@ -29,12 +29,8 @@ static bool parse_response(const CMStringW &rsJSON, double &dRate)
/////////////////////////////////////////////////////////////////////////////////////////
// CCurrencyRatesProviderCurrencyConverter implementation
-class CCurrencyRatesProviderCurrencyConverter : public CCurrencyRatesProviderBase
+struct CCurrencyRatesProviderCurrencyConverter : public CCurrencyRatesProviderBase
{
-public:
- typedef CCurrencyRatesProviderBase CSuper;
-
-public:
CCurrencyRatesProviderCurrencyConverter()
{}
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h b/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h
deleted file mode 100644
index 3f59c932d3..0000000000
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#pragma once
-
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderExchangeRates.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderExchangeRates.cpp
new file mode 100644
index 0000000000..7b90322a8f
--- /dev/null
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderExchangeRates.cpp
@@ -0,0 +1,86 @@
+#include "stdafx.h"
+
+static CMStringW build_url(const CMStringW &rsURL)
+{
+ CMStringW res = rsURL + L"?";
+ ptrA szApiKey(g_plugin.getStringA(DB_KEY_ApiKey));
+ if (szApiKey != nullptr)
+ res.AppendFormat(L"&access_key=%S", szApiKey.get());
+ return res;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// CCurrencyRatesProviderExchangeRates implementation
+
+class CCurrencyRatesProviderExchangeRates : public CCurrencyRatesProviderBase
+{
+ std::map<CMStringA, double> m_lastRates;
+
+ double GetRate(const CMStringA &id1, const CMStringA &id2) const
+ {
+ if (!id1.IsEmpty() && !id2.IsEmpty()) {
+ auto r1 = m_lastRates.find(id1), r2 = m_lastRates.find(id2);
+ if (r1 != m_lastRates.end() && r2 != m_lastRates.end())
+ return r2->second / r1->second;
+ }
+
+ return 0.0;
+ }
+
+public:
+ CCurrencyRatesProviderExchangeRates()
+ {}
+
+ void RefreshCurrencyRates(TContacts &anContacts) override
+ {
+ CHTTPSession http;
+ if (true == http.OpenURL(build_url(GetURL()))) {
+ CMStringW sHTML;
+ if (true == http.ReadResponce(sHTML)) {
+ JSONNode root = JSONNode::parse(_T2A(sHTML));
+ if (!root)
+ return;
+
+ auto rates = root["rates"];
+ if (!root["success"].as_bool() || !rates)
+ return;
+
+ auto &qs = GetSection();
+
+ m_lastRates.clear();
+ for (auto &it : qs.GetCurrencyRates()) {
+ CMStringA id = it.GetID();
+ m_lastRates[id] = rates[id].as_float();
+ }
+ }
+ }
+
+ for (auto &hContact : anContacts) {
+ double rate = GetRate(g_plugin.getMStringA(hContact, DB_STR_FROM_ID), g_plugin.getMStringA(hContact, DB_STR_TO_ID));
+ if (rate != 0.0) {
+ WriteContactRate(hContact, rate);
+ continue;
+ }
+ SetContactStatus(hContact, ID_STATUS_NA);
+ }
+ }
+
+ double Convert(double dAmount, const CCurrencyRate &from, const CCurrencyRate &to) const override
+ {
+ CMStringA id1 = from.GetID(), id2 = to.GetID();
+ return dAmount * GetRate(id1, id2);
+ }
+
+ wchar_t* GetXmlFilename() const override
+ {
+ return L"ExchangeRates.xml";
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Module entry point
+
+void InitExchangeRates()
+{
+ g_apProviders.push(new CCurrencyRatesProviderExchangeRates());
+}
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp
index 14604d63f7..70d9979b06 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp
@@ -7,11 +7,18 @@ void InitExchangeRates();
TCurrencyRatesProviders g_apProviders;
+CCurrencyRatesProviderBase *g_pCurrentProvider = nullptr;
+
/////////////////////////////////////////////////////////////////////////////////////////
-void CreateProviders()
+void InitProviders()
{
InitCC();
+ InitExchangeRates();
+
+ g_pCurrentProvider = FindProvider(g_plugin.getMStringW(DB_STR_PROVIDER));
+ if (g_pCurrentProvider == nullptr)
+ g_pCurrentProvider = &g_apProviders[0];
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -30,40 +37,17 @@ void convert_contact_settings(MCONTACT hContact)
g_plugin.setByte(hContact, DB_STR_CONTACT_SPEC_SETTINGS, 1);
}
-void InitProviders()
+void TCurrencyRatesProviders::push(CCurrencyRatesProviderBase *pNew)
{
- CreateProviders();
-
- const uint16_t nCurrentVersion = 17;
- uint16_t nVersion = g_plugin.getWord(LAST_RUN_VERSION, 1);
-
- for (auto &hContact : Contacts(MODULENAME)) {
- ICurrencyRatesProvider *pProvider = GetContactProviderPtr(hContact);
- if (pProvider && nVersion < nCurrentVersion)
- convert_contact_settings(hContact);
- }
-
- g_plugin.setWord(LAST_RUN_VERSION, nCurrentVersion);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-ICurrencyRatesProvider* GetContactProviderPtr(MCONTACT hContact)
-{
- char* szProto = Proto_GetBaseAccountName(hContact);
- if (nullptr == szProto || 0 != ::_stricmp(szProto, MODULENAME))
- return nullptr;
-
- CMStringW sProvider = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_PROVIDER);
- if (sProvider.IsEmpty())
- return nullptr;
-
- return FindProvider(sProvider);
+ if (pNew->Init())
+ insert(pNew);
+ else
+ delete pNew;
}
/////////////////////////////////////////////////////////////////////////////////////////
-ICurrencyRatesProvider* FindProvider(const CMStringW &rsName)
+CCurrencyRatesProviderBase* FindProvider(const CMStringW &rsName)
{
for (auto &pProvider : g_apProviders) {
const ICurrencyRatesProvider::CProviderInfo& rInfo = pProvider->GetInfo();
diff --git a/protocols/CurrencyRates/src/EconomicRateInfo.h b/protocols/CurrencyRates/src/EconomicRateInfo.h
index 3eaccc45e3..d1bd87f49e 100644
--- a/protocols/CurrencyRates/src/EconomicRateInfo.h
+++ b/protocols/CurrencyRates/src/EconomicRateInfo.h
@@ -13,6 +13,7 @@ enum ERefreshRateType
#define DB_STR_FROM_ID "FromID"
#define DB_STR_TO_ID "ToID"
+#define DB_STR_PROVIDER "Provider"
#define DB_STR_FROM_DESCRIPTION "FromDesc"
#define DB_STR_TO_DESCRIPTION "ToDesc"
#define DB_STR_ENABLE_LOG "EnableLog"
diff --git a/protocols/CurrencyRates/src/Forex.cpp b/protocols/CurrencyRates/src/Forex.cpp
index 64588d865e..f2e1b9ce89 100644
--- a/protocols/CurrencyRates/src/Forex.cpp
+++ b/protocols/CurrencyRates/src/Forex.cpp
@@ -40,8 +40,7 @@ static void UpdateMenu()
static INT_PTR CurrencyRatesMenu_RefreshAll(WPARAM, LPARAM)
{
- for (auto &pProvider : g_apProviders)
- pProvider->RefreshAllContacts();
+ g_pCurrentProvider->RefreshAllContacts();
return 0;
}
@@ -50,11 +49,9 @@ static INT_PTR CurrencyRatesMenu_EnableDisable(WPARAM, LPARAM)
g_bAutoUpdate = !g_bAutoUpdate;
g_plugin.setByte(DB_STR_AUTO_UPDATE, g_bAutoUpdate);
- for (auto &pProvider : g_apProviders) {
- pProvider->RefreshSettings();
- if (g_bAutoUpdate)
- pProvider->RefreshAllContacts();
- }
+ g_pCurrentProvider->RefreshSettings();
+ if (g_bAutoUpdate)
+ g_pCurrentProvider->RefreshAllContacts();
UpdateMenu();
return 0;
@@ -199,8 +196,7 @@ int CurrencyRatesEventFunc_OnModulesLoaded(WPARAM, LPARAM)
::ResetEvent(g_hEventWorkThreadStop);
- for (auto &pProvider : g_apProviders)
- g_ahThreads.push_back(mir_forkthread(WorkingThread, pProvider));
+ g_ahThreads.push_back(mir_forkthread(WorkingThread, g_pCurrentProvider));
return 0;
}
diff --git a/protocols/CurrencyRates/src/HTTPSession.cpp b/protocols/CurrencyRates/src/HTTPSession.cpp
index eb7ffd26ab..242a2b08ac 100644
--- a/protocols/CurrencyRates/src/HTTPSession.cpp
+++ b/protocols/CurrencyRates/src/HTTPSession.cpp
@@ -2,12 +2,12 @@
HNETLIBUSER CHTTPSession::g_hNetLib = nullptr;
-#define ERROR_MSG LPGENW("This plugin requires a personal key. Press Yes to obtain it at the site and then enter the result in the Options dialog, otherwise this plugin will fail.")
+#define ERROR_MSG LPGENW("This plugin requires a personal key. Open the Options dialog to obtain it.")
void CALLBACK waitStub()
{
- if (IDYES == MessageBox(0, TranslateW(ERROR_MSG), _A2W(MODULENAME), MB_YESNOCANCEL))
- Utils_OpenUrl("https://free.currencyconverterapi.com/free-api-key");
+ CAdvProviderSettings global_settings(g_pCurrentProvider);
+ show_popup(g_pCurrentProvider, 0, -1, TranslateW(ERROR_MSG), *global_settings.GetPopupSettingsPtr());
}
static int find_header(const NETLIBHTTPREQUEST* pRequest, const char* hdr)
@@ -76,7 +76,7 @@ bool CHTTPSession::Init()
assert(nullptr == g_hNetLib);
ptrA szApiKey(g_plugin.getStringA(DB_KEY_ApiKey));
- if (szApiKey == nullptr)
+ if (mir_strlen(szApiKey) == 0)
Miranda_WaitOnHandle(waitStub);
NETLIBUSER nlu = {};
diff --git a/protocols/CurrencyRates/src/ICurrencyRatesProvider.h b/protocols/CurrencyRates/src/ICurrencyRatesProvider.h
index 7ceec2aa8c..bc850aa676 100644
--- a/protocols/CurrencyRates/src/ICurrencyRatesProvider.h
+++ b/protocols/CurrencyRates/src/ICurrencyRatesProvider.h
@@ -45,28 +45,23 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
-struct TCurrencyRatesProviders : public OBJLIST<ICurrencyRatesProvider>
+class CCurrencyRatesProviderBase;
+
+struct TCurrencyRatesProviders : public OBJLIST<CCurrencyRatesProviderBase>
{
TCurrencyRatesProviders() :
- OBJLIST<ICurrencyRatesProvider>(1)
+ OBJLIST<CCurrencyRatesProviderBase>(1)
{}
- void push(ICurrencyRatesProvider *pNew)
- {
- if (pNew->Init())
- insert(pNew);
- else
- delete pNew;
- }
+ void push(CCurrencyRatesProviderBase *pNew);
};
extern TCurrencyRatesProviders g_apProviders;
+extern CCurrencyRatesProviderBase *g_pCurrentProvider;
-ICurrencyRatesProvider* FindProvider(const CMStringW &rsName);
-ICurrencyRatesProvider* GetContactProviderPtr(MCONTACT hContact);
+CCurrencyRatesProviderBase* FindProvider(const CMStringW &rsName);
void InitProviders();
-void CreateProviders();
void ClearProviders();
#endif //__ac71e133_786c_41a7_ab07_625b76ff2a8c_CurrencyRatesProvider_h__
diff --git a/protocols/CurrencyRates/src/ImportExport.cpp b/protocols/CurrencyRates/src/ImportExport.cpp
index 8d6804713a..e91dbe5993 100644
--- a/protocols/CurrencyRates/src/ImportExport.cpp
+++ b/protocols/CurrencyRates/src/ImportExport.cpp
@@ -211,8 +211,7 @@ INT_PTR CurrencyRates_Export(WPARAM wp, LPARAM lp)
MCONTACT hContact = MCONTACT(wp);
if (hContact) {
- auto pProvider = GetContactProviderPtr(hContact);
- if (pProvider) {
+ if (g_pCurrentProvider) {
auto *pNode = export_contact(hContact, doc);
if (pNode)
pRoot->InsertEndChild(pNode);
@@ -220,8 +219,7 @@ INT_PTR CurrencyRates_Export(WPARAM wp, LPARAM lp)
}
else {
for (auto &cc : Contacts(MODULENAME)) {
- auto pProvider = GetContactProviderPtr(cc);
- if (pProvider) {
+ if (g_pCurrentProvider) {
auto *pNode = export_contact(cc, doc);
if (pNode)
pRoot->InsertEndChild(pNode);
diff --git a/protocols/CurrencyRates/src/Options.cpp b/protocols/CurrencyRates/src/Options.cpp
index ee4db5a1b9..21fa0afd41 100644
--- a/protocols/CurrencyRates/src/Options.cpp
+++ b/protocols/CurrencyRates/src/Options.cpp
@@ -17,6 +17,59 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+/////////////////////////////////////////////////////////////////////////////////////////
+// Pair adding dialog
+
+class CPairAddDialog : public CDlgBase
+{
+ CCtrlCombo cmbFrom, cmbTo;
+ CCtrlButton btnOk;
+
+public:
+ CCurrencyRatesProviderBase::TRateInfo ri;
+
+ CPairAddDialog() :
+ CDlgBase(g_plugin, IDD_ADD_PAIR),
+ btnOk(this, IDOK),
+ cmbTo(this, IDC_COMBO_CONVERT_INTO),
+ cmbFrom(this, IDC_COMBO_CONVERT_FROM)
+ {
+ cmbTo.OnSelChanged = cmbFrom.OnSelChanged = Callback(this, &CPairAddDialog::onSelChange_From);
+ }
+
+ bool OnInitDialog() override
+ {
+ auto &rSection = g_pCurrentProvider->GetSection();
+ for (auto &it : rSection.GetCurrencyRates()) {
+ CMStringW sName = it.MakeName();
+ cmbFrom.AddString(TranslateW(sName), LPARAM(&it));
+ cmbTo.AddString(TranslateW(sName), LPARAM(&it));
+ }
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ auto *c1 = (CCurrencyRate*)cmbFrom.GetCurData();
+ auto *c2 = (CCurrencyRate *)cmbTo.GetCurData();
+ if (c1 && c2) {
+ ri.first = *c1;
+ ri.second = *c2;
+ }
+ return true;
+ }
+
+ void onSelChange_From(CCtrlCombo *)
+ {
+ int nFrom = cmbFrom.GetCurSel();
+ int nTo = cmbTo.GetCurSel();
+ btnOk.Enable((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo));
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// General options dialog
+
typedef boost::shared_ptr<CAdvProviderSettings> TAdvSettingsPtr;
typedef std::map<const ICurrencyRatesProvider *, TAdvSettingsPtr> TAdvSettings;
@@ -46,22 +99,6 @@ void remove_adv_settings(const ICurrencyRatesProvider *m_pProvider)
class COptionsDlg : public CDlgBase
{
- CCurrencyRatesProviderBase* get_provider()
- {
- for (auto &it : g_apProviders)
- if (auto p = dynamic_cast<CCurrencyRatesProviderBase *>(it))
- return p;
-
- assert(!"We should never get here!");
- return nullptr;
- };
-
- CMStringW make_currencyrate_name(const CCurrencyRate &rCurrencyRate)
- {
- auto &rsDesc = rCurrencyRate.GetName();
- return((false == rsDesc.IsEmpty()) ? rsDesc : rCurrencyRate.GetSymbol());
- };
-
CMStringW make_contact_name(const CMStringW &rsSymbolFrom, const CMStringW &rsSymbolTo)
{
return rsSymbolFrom + L"/" + rsSymbolTo;
@@ -80,33 +117,39 @@ class COptionsDlg : public CDlgBase
CCurrencyRatesProviderBase *m_pProvider;
- CCtrlCombo cmbFrom, cmbTo;
- CCtrlButton btnAdd, btnRemove, btnDescr, btnAdvanced;
+ CCtrlCombo cmbProvider;
+ CCtrlButton btnAdd, btnRemove, btnDescr, btnAdvanced, btnGetKey;
CCtrlListBox m_list;
public:
COptionsDlg() :
- CDlgBase(g_plugin, IDD_DIALOG_OPT_GOOGLE),
- m_pProvider(get_provider()),
+ CDlgBase(g_plugin, IDD_OPTIONS_GENERAL),
+ m_pProvider(g_pCurrentProvider),
m_list(this, IDC_LIST_RATES),
+ cmbProvider(this, IDC_PROVIDER),
btnAdd(this, IDC_BUTTON_ADD),
btnDescr(this, IDC_BUTTON_DESCRIPTION),
+ btnGetKey(this, IDC_GET_KEY),
btnRemove(this, IDC_BUTTON_REMOVE),
- btnAdvanced(this, IDC_BUTTON_ADVANCED_SETTINGS),
- cmbTo(this, IDC_COMBO_CONVERT_INTO),
- cmbFrom(this, IDC_COMBO_CONVERT_FROM)
+ btnAdvanced(this, IDC_BUTTON_ADVANCED_SETTINGS)
{
btnAdd.OnClick = Callback(this, &COptionsDlg::onClick_Add);
btnDescr.OnClick = Callback(this, &COptionsDlg::onClick_Descr);
+ btnGetKey.OnClick = Callback(this, &COptionsDlg::onClick_GetKey);
btnRemove.OnClick = Callback(this, &COptionsDlg::onClick_Remove);
btnAdvanced.OnClick = Callback(this, &COptionsDlg::onClick_Advanced);
- cmbTo.OnSelChanged = cmbFrom.OnSelChanged = Callback(this, &COptionsDlg::onSelChange_From);
m_list.OnSelChange = Callback(this, &COptionsDlg::onSelChange_Rates);
}
bool OnInitDialog() override
{
+ for (auto &it : g_apProviders) {
+ int idx = cmbProvider.AddString(it->GetInfo().m_sName, (LPARAM)it);
+ if (it == g_pCurrentProvider)
+ cmbProvider.SetCurSel(idx);
+ }
+
// set contact list display format
::SetDlgItemTextW(m_hwnd, IDC_EDIT_CONTACT_LIST_FORMAT, g_plugin.getMStringW(DB_KEY_DisplayNameFormat, DB_DEF_DisplayNameFormat));
@@ -151,20 +194,6 @@ public:
g_aWatchedRates.clear();
- CCurrencyRateSection rSection;
- const auto &rCurrencyRates = m_pProvider->GetCurrencyRates();
- if (rCurrencyRates.GetSectionCount() > 0) {
- rSection = rCurrencyRates.GetSection(0);
- }
-
- auto cCurrencyRates = rSection.GetCurrencyRateCount();
- for (auto i = 0u; i < cCurrencyRates; ++i) {
- const auto &rCurrencyRate = rSection.GetCurrencyRate(i);
- CMStringW sName = make_currencyrate_name(rCurrencyRate);
- cmbFrom.AddString(sName);
- cmbTo.AddString(sName);
- }
-
for (auto &cc : Contacts(MODULENAME)) {
CCurrencyRatesProviderBase::TRateInfo ri;
if (true == m_pProvider->GetWatchedRateInfo(cc, ri)) {
@@ -174,7 +203,6 @@ public:
}
}
- btnAdd.Disable();
btnRemove.Disable();
return true;
}
@@ -222,6 +250,9 @@ public:
for (auto &it : aTemp)
m_pProvider->WatchForRate(it, true);
m_pProvider->RefreshSettings();
+
+ g_pCurrentProvider = (CCurrencyRatesProviderBase *)cmbProvider.GetCurData();
+ g_plugin.setWString(DB_STR_PROVIDER, g_pCurrentProvider->GetInfo().m_sName);
return true;
}
@@ -277,13 +308,6 @@ public:
return CDlgBase::DlgProc(msg, wParam, lParam);
}
- void onSelChange_From(CCtrlCombo *)
- {
- int nFrom = cmbFrom.GetCurSel();
- int nTo = cmbTo.GetCurSel();
- btnAdd.Enable((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo));
- }
-
void onSelChange_Rates(CCtrlCombo *)
{
int nType = m_list.GetCurSel();
@@ -306,26 +330,14 @@ public:
void onClick_Add(CCtrlButton *)
{
- size_t nFrom = cmbFrom.GetCurSel();
- size_t nTo = cmbTo.GetCurSel();
- if ((CB_ERR != nFrom) && (CB_ERR != nTo) && (nFrom != nTo)) {
- CCurrencyRateSection rSection;
- const auto &rCurrencyRates = m_pProvider->GetCurrencyRates();
- if (rCurrencyRates.GetSectionCount() > 0)
- rSection = rCurrencyRates.GetSection(0);
-
- auto cCurrencyRates = rSection.GetCurrencyRateCount();
- if ((nFrom < cCurrencyRates) && (nTo < cCurrencyRates)) {
- CCurrencyRatesProviderBase::TRateInfo ri;
- ri.first = rSection.GetCurrencyRate(nFrom);
- ri.second = rSection.GetCurrencyRate(nTo);
-
- g_aWatchedRates.push_back(ri);
+ CPairAddDialog dlg;
+ dlg.SetParent(m_hwnd);
+ if (dlg.DoModal() == IDOK) {
+ g_aWatchedRates.push_back(dlg.ri);
- CMStringW sRate = make_rate_name(ri);
- m_list.AddString(sRate);
- NotifyChange();
- }
+ CMStringW sRate = make_rate_name(dlg.ri);
+ m_list.AddString(sRate);
+ NotifyChange();
}
}
@@ -342,6 +354,12 @@ public:
show_variable_list(m_hwnd, m_pProvider);
}
+ void onClick_GetKey(CCtrlButton *)
+ {
+ if (auto *pProvider = (CCurrencyRatesProviderBase *)cmbProvider.GetCurData())
+ Utils_OpenUrlW(pProvider->GetInfo().m_sURL);
+ }
+
void onClick_Remove(CCtrlButton *)
{
int nSel = m_list.GetCurSel();
diff --git a/protocols/CurrencyRates/src/SettingsDlg.cpp b/protocols/CurrencyRates/src/SettingsDlg.cpp
index 134d504553..042012ce19 100644
--- a/protocols/CurrencyRates/src/SettingsDlg.cpp
+++ b/protocols/CurrencyRates/src/SettingsDlg.cpp
@@ -241,8 +241,7 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L
uint8_t bUseContactSpecific = g_plugin.getByte(hContact, DB_STR_CONTACT_SPEC_SETTINGS, 0);
::CheckDlgButton(hWnd, IDC_CHECK_CONTACT_SPECIFIC, bUseContactSpecific ? BST_CHECKED : BST_UNCHECKED);
- auto pProvider = GetContactProviderPtr(hContact);
- CAdvProviderSettings setGlobal(pProvider);
+ CAdvProviderSettings setGlobal(g_pCurrentProvider);
// log to history
uint16_t dwLogMode = g_plugin.getWord(hContact, DB_STR_CURRENCYRATE_LOG, setGlobal.GetLogMode());
UINT nCheck = (dwLogMode & lmInternalHistory) ? 1 : 0;
@@ -291,7 +290,7 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L
case IDC_BUTTON_LOG_FILE_DESCRIPTION:
case IDC_BUTTON_POPUP_FORMAT_DESCRIPTION:
if (BN_CLICKED == HIWORD(wp))
- show_variable_list(hWnd, GetContactProviderPtr(get_param(hWnd)->m_hContact));
+ show_variable_list(hWnd, g_pCurrentProvider);
break;
case IDC_CHECK_CONTACT_SPECIFIC:
@@ -837,14 +836,13 @@ CMStringW GetContactLogFileName(MCONTACT hContact)
{
CMStringW result;
- auto pProvider = GetContactProviderPtr(hContact);
- if (pProvider) {
+ if (g_pCurrentProvider) {
CMStringW sPattern;
bool bUseContactSpecific = (g_plugin.getByte(hContact, DB_STR_CONTACT_SPEC_SETTINGS, 0) > 0);
if (bUseContactSpecific)
sPattern = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_LOG_FILE);
else {
- CAdvProviderSettings global_settings(pProvider);
+ CAdvProviderSettings global_settings(g_pCurrentProvider);
sPattern = global_settings.GetLogFileName();
}
diff --git a/protocols/CurrencyRates/src/resource.h b/protocols/CurrencyRates/src/resource.h
index e1216a897c..eac6b6af70 100644
--- a/protocols/CurrencyRates/src/resource.h
+++ b/protocols/CurrencyRates/src/resource.h
@@ -1,10 +1,10 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by w:\miranda-ng\plugins\CurrencyRates\res\Forex.rc
+// Used by W:\miranda-ng\protocols\CurrencyRates\res\Forex.rc
//
#define IDI_ICON_MAIN 102
#define IDD_DIALOG_CURRENCYRATE_INFO 102
-#define IDD_DIALOG_OPT_GOOGLE 103
+#define IDD_OPTIONS_GENERAL 103
#define IDI_ICON_SECTION 110
#define IDI_ICON_CURRENCYRATE 111
#define IDI_ICON_UP 113
@@ -23,6 +23,7 @@
#define IDI_ICON_MAIN1 122
#define IDI_ICON_DISABLED 122
#define IDD_DIALOG_VARIABLE_LIST 123
+#define IDD_ADD_PAIR 126
#define IDC_EDIT_REFRESH_RATE 1002
#define IDC_SPIN_REFRESH_RATE 1003
#define IDC_COMBO_REFRESH_RATE 1004
@@ -32,6 +33,7 @@
#define IDC_STATIC_CURRENCYRATE_CHART 1010
#define IDC_COMBO_CONVERT_FROM 1011
#define IDC_COMBO_CONVERT_INTO 1012
+#define IDC_COMBO_CONVERT_ 1012
#define IDC_BUTTON_ADD 1013
#define IDC_LIST_RATES 1014
#define IDC_BUTTON_REMOVE 1015
@@ -83,8 +85,11 @@
#define IDC_DELAY 1072
#define IDC_EDIT1 1072
#define IDC_EDIT_VARIABLE 1072
+#define IDC_PROVIDER 1073
#define IDC_BGCOLOR 1074
#define IDC_TEXTCOLOR 1075
+#define IDC_BUTTON1 1075
+#define IDC_GET_KEY 1075
#define IDC_PREV 1076
#define IDC_DELAYFROMPU 1093
#define IDC_DELAYCUSTOM 1094
@@ -94,9 +99,9 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 126
+#define _APS_NEXT_RESOURCE_VALUE 128
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1073
+#define _APS_NEXT_CONTROL_VALUE 1076
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif