summaryrefslogtreecommitdiff
path: root/protocols/CurrencyRates
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-02-09 11:02:54 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-02-09 11:02:54 +0300
commit354f557eb6cfcaf4010161032c6da27d253e71ad (patch)
tree08d2543a81fbb09949e220d2437a470c041b3a4f /protocols/CurrencyRates
parent44293bb1991dfabf262ce2b5006523306b336864 (diff)
fixes #4186 (CurrencyRates: запрос ключа при запуске)
Diffstat (limited to 'protocols/CurrencyRates')
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderBase.h5
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp4
-rw-r--r--protocols/CurrencyRates/src/HTTPSession.cpp12
-rw-r--r--protocols/CurrencyRates/src/Options.cpp18
-rw-r--r--protocols/CurrencyRates/src/version.h2
5 files changed, 28 insertions, 13 deletions
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
index 80111520ef..92a41ad098 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
@@ -80,6 +80,8 @@ public:
void RefreshSettings() override;
void RefreshContact(MCONTACT hContact) override;
+ __forceinline bool HasAuth() const { return m_bRequiresAuth; }
+
MCONTACT ImportContact(const TiXmlNode *) override;
using TRateInfo = std::pair<CCurrencyRate, CCurrencyRate>;
@@ -103,7 +105,8 @@ protected:
virtual void RefreshCurrencyRates(TContacts &anContacts) = 0;
protected:
- mutable mir_cs m_cs;
+ mir_cs m_cs;
+ bool m_bRequiresAuth = true;
};
bool show_popup(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, int nComparison, const CMStringW &rsFormat);
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp
index ed7a94bb3a..8f9fc18c91 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp
@@ -20,7 +20,9 @@ class CCurrencyRatesProviderCbrf : public CCurrencyRatesProviderBase
public:
CCurrencyRatesProviderCbrf()
- {}
+ {
+ m_bRequiresAuth = false;
+ }
void RefreshCurrencyRates(TContacts &anContacts) override
{
diff --git a/protocols/CurrencyRates/src/HTTPSession.cpp b/protocols/CurrencyRates/src/HTTPSession.cpp
index 4bb0374ad1..62fdce7fd4 100644
--- a/protocols/CurrencyRates/src/HTTPSession.cpp
+++ b/protocols/CurrencyRates/src/HTTPSession.cpp
@@ -4,11 +4,6 @@ HNETLIBUSER CHTTPSession::g_hNetLib = nullptr;
#define ERROR_MSG LPGENW("This plugin requires a personal key. Open the Options dialog to obtain it.")
-void CALLBACK waitStub()
-{
- show_popup(g_pCurrentProvider, 0, -1, TranslateW(ERROR_MSG));
-}
-
bool CHTTPSession::OpenURL(const CMStringW &rsURL)
{
m_szUrl = rsURL;
@@ -52,12 +47,17 @@ bool CHTTPSession::ReadResponce(CMStringW &rsResponce)
/////////////////////////////////////////////////////////////////////////////////////////
// module initialization
+static void CALLBACK waitStub()
+{
+ show_popup(g_pCurrentProvider, 0, -1, TranslateW(ERROR_MSG));
+}
+
bool CHTTPSession::Init()
{
assert(nullptr == g_hNetLib);
ptrA szApiKey(g_plugin.getStringA(DB_KEY_ApiKey));
- if (mir_strlen(szApiKey) == 0)
+ if (mir_strlen(szApiKey) == 0 && g_pCurrentProvider->HasAuth())
Miranda_WaitOnHandle(waitStub);
NETLIBUSER nlu = {};
diff --git a/protocols/CurrencyRates/src/Options.cpp b/protocols/CurrencyRates/src/Options.cpp
index 4bf36ddee3..faa433f251 100644
--- a/protocols/CurrencyRates/src/Options.cpp
+++ b/protocols/CurrencyRates/src/Options.cpp
@@ -90,6 +90,7 @@ class COptionsDlg : public CDlgBase
CCurrencyRatesProviderBase *m_pProvider;
+ CCtrlEdit edtKey;
CCtrlCombo cmbProvider, cmbRefresh;
CCtrlButton btnAdd, btnRemove, btnDescr, btnGetKey;
CCtrlListBox m_list;
@@ -101,18 +102,23 @@ public:
m_list(this, IDC_LIST_RATES),
cmbRefresh(this, IDC_COMBO_REFRESH_RATE),
cmbProvider(this, IDC_PROVIDER),
+ edtKey(this, IDC_EDIT_PERSONAL_KEY),
btnAdd(this, IDC_BUTTON_ADD),
btnDescr(this, IDC_BUTTON_DESCRIPTION),
btnGetKey(this, IDC_GET_KEY),
btnRemove(this, IDC_BUTTON_REMOVE)
{
+ CreateLink(edtKey, DB_KEY_ApiKey, L"");
+
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);
m_list.OnSelChange = Callback(this, &COptionsDlg::onSelChange_Rates);
+
cmbRefresh.OnSelChanged = Callback(this, &COptionsDlg::onSelChange_Refresh);
+ cmbProvider.OnSelChanged = Callback(this, &COptionsDlg::onSelChange_Provider);
}
bool OnInitDialog() override
@@ -132,9 +138,6 @@ public:
// set tendency format
::SetDlgItemTextW(m_hwnd, IDC_EDIT_TENDENCY_FORMAT, g_plugin.getMStringW(DB_KEY_TendencyFormat, DB_DEF_TendencyFormat));
- // set api key
- ::SetDlgItemTextW(m_hwnd, IDC_EDIT_PERSONAL_KEY, g_plugin.getMStringW(DB_KEY_ApiKey));
-
// refresh rate
cmbRefresh.AddString(TranslateT("Seconds"));
cmbRefresh.AddString(TranslateT("Minutes"));
@@ -189,7 +192,6 @@ public:
g_plugin.setWString(DB_KEY_DisplayNameFormat, get_window_text(::GetDlgItem(m_hwnd, IDC_EDIT_CONTACT_LIST_FORMAT)));
g_plugin.setWString(DB_KEY_StatusMsgFormat, get_window_text(::GetDlgItem(m_hwnd, IDC_EDIT_STATUS_MESSAGE_FORMAT)));
g_plugin.setWString(DB_KEY_TendencyFormat, get_window_text(::GetDlgItem(m_hwnd, IDC_EDIT_TENDENCY_FORMAT)));
- g_plugin.setWString(DB_KEY_ApiKey, get_window_text(::GetDlgItem(m_hwnd, IDC_EDIT_PERSONAL_KEY)));
TWatchedRates aTemp(g_aWatchedRates);
TWatchedRates aRemove;
@@ -227,6 +229,14 @@ public:
btnRemove.Enable(LB_ERR != m_list.GetCurSel());
}
+ void onSelChange_Provider(CCtrlCombo *)
+ {
+ auto *pProvider = (CCurrencyRatesProviderBase *)cmbProvider.GetCurData();
+ bool bEnabled = pProvider->HasAuth();
+ edtKey.Enable(bEnabled);
+ btnGetKey.Enable(bEnabled);
+ }
+
void onSelChange_Refresh(CCtrlCombo *)
{
switch (cmbRefresh.GetCurSel()) {
diff --git a/protocols/CurrencyRates/src/version.h b/protocols/CurrencyRates/src/version.h
index 8f36de3cb2..1763ca0193 100644
--- a/protocols/CurrencyRates/src/version.h
+++ b/protocols/CurrencyRates/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 1
-#define __BUILD_NUM 2
+#define __BUILD_NUM 3
#include <stdver.h>