summaryrefslogtreecommitdiff
path: root/protocols/CurrencyRates
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-11-07 13:40:55 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-11-07 13:40:55 +0300
commita89cede20d7712dc36cfcaa0a23f8a1b56496e49 (patch)
treebd1920c81660a2c81269dfc2dfd894954c453aa5 /protocols/CurrencyRates
parent3abea4a9b102456ccbb5bc4b6ca1338fd7e83d1d (diff)
fixes #3834 (CurrencyRates: не работает текст всплывающих окон)
Diffstat (limited to 'protocols/CurrencyRates')
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp69
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderBase.h2
-rw-r--r--protocols/CurrencyRates/src/SettingsDlg.cpp17
3 files changed, 50 insertions, 38 deletions
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp
index 373cbc957b..70ecc65a35 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp
@@ -65,7 +65,7 @@ bool parse_section(const TiXmlNode *pTop, CCurrencyRateSection &qs)
return true;
}
-const TiXmlNode* find_provider(const TiXmlNode *pRoot)
+const TiXmlNode *find_provider(const TiXmlNode *pRoot)
{
for (auto *pNode : TiXmlEnum(pRoot)) {
const char *sName = pNode->Value();
@@ -110,7 +110,7 @@ CXMLFileInfo parse_ini_file(const CMStringW &rsXMLFile, bool &rbSucceded)
return res;
}
-CXMLFileInfo init_xml_info(LPCTSTR pszFileName, bool& rbSucceded)
+CXMLFileInfo init_xml_info(LPCTSTR pszFileName, bool &rbSucceded)
{
rbSucceded = false;
CMStringW sIniFile = CreateFilePath(pszFileName);
@@ -121,8 +121,7 @@ CCurrencyRatesProviderBase::CCurrencyRatesProviderBase() :
m_hEventSettingsChanged(::CreateEvent(nullptr, FALSE, FALSE, nullptr)),
m_hEventRefreshContact(::CreateEvent(nullptr, FALSE, FALSE, nullptr)),
m_bRefreshInProgress(false)
-{
-}
+{}
CCurrencyRatesProviderBase::~CCurrencyRatesProviderBase()
{
@@ -144,17 +143,17 @@ bool CCurrencyRatesProviderBase::Init()
return bSucceded;
}
-const CCurrencyRatesProviderBase::CProviderInfo& CCurrencyRatesProviderBase::GetInfo() const
+const CCurrencyRatesProviderBase::CProviderInfo &CCurrencyRatesProviderBase::GetInfo() const
{
return m_pXMLInfo->m_pi;
}
-const CCurrencyRateSection& CCurrencyRatesProviderBase::GetCurrencyRates() const
+const CCurrencyRateSection &CCurrencyRatesProviderBase::GetCurrencyRates() const
{
return m_pXMLInfo->m_qs;
}
-const CMStringW& CCurrencyRatesProviderBase::GetURL() const
+const CMStringW &CCurrencyRatesProviderBase::GetURL() const
{
return m_pXMLInfo->m_sURL;
}
@@ -409,11 +408,11 @@ void log_to_history(const ICurrencyRatesProvider *pProvider, MCONTACT hContact,
dbei.flags = DBEF_READ | DBEF_UTF;
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.cbBlob = (int)::mir_strlen(psz) + 1;
- dbei.pBlob = (uint8_t*)(char*)psz;
+ dbei.pBlob = (uint8_t *)(char *)psz;
db_event_add(hContact, &dbei);
}
-bool do_set_contact_extra_icon(MCONTACT hContact, const CTendency& tendency)
+bool do_set_contact_extra_icon(MCONTACT hContact, const CTendency &tendency)
{
CTendency::EResult nComparison = tendency.Compare();
@@ -429,27 +428,29 @@ bool do_set_contact_extra_icon(MCONTACT hContact, const CTendency& tendency)
return false;
}
-bool show_popup(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, const CTendency &tendency, const CMStringW &rsFormat, const CPopupSettings &ps)
+bool show_popup(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, int nComparison, const CMStringW &rsFormat, const CPopupSettings &ps)
{
POPUPDATAW ppd;
memset(&ppd, 0, sizeof(ppd));
ppd.lchContact = hContact;
- if (tendency.IsValid()) {
- CTendency::EResult nComparison = tendency.Compare();
- 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);
- }
+ 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);
- mir_wstrncpy(ppd.lpwzContactName, pProvider->FormatSymbol(hContact, 's').c_str(), MAX_CONTACTNAME);
- {
- ptrW ss(variables_parsedup((wchar_t*)rsFormat.c_str(), nullptr, hContact));
+ if (pProvider != nullptr) {
+ mir_wstrncpy(ppd.lpwzContactName, pProvider->FormatSymbol(hContact, 's').c_str(), 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);
}
+ else {
+ mir_wstrncpy(ppd.lpwzContactName, TranslateT("Test contact"), MAX_CONTACTNAME);
+ mir_wstrncpy(ppd.lpwzText, L"1 USD = 8.4342 SMC", MAX_SECONDLINE);
+ }
if (CPopupSettings::colourDefault == ps.GetColourMode()) {
ppd.colorText = CPopupSettings::GetDefColourText();
@@ -528,7 +529,7 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat
uint16_t dwMode = (bUseContactSpecific)
? g_plugin.getWord(hContact, DB_STR_CURRENCYRATE_LOG, static_cast<uint16_t>(lmDisabled))
: global_settings.GetLogMode();
- if (dwMode&lmExternalFile) {
+ if (dwMode & lmExternalFile) {
bool bAdd = true;
bool bOnlyIfChanged = (bUseContactSpecific)
? (g_plugin.getWord(hContact, DB_STR_CURRENCYRATE_LOG_FILE_CONDITION, 1) > 0)
@@ -554,7 +555,7 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat
log_to_file(this, hContact, sLogFileName, sFormat);
}
}
- if (dwMode&lmInternalHistory) {
+ if (dwMode & lmInternalHistory) {
bool bAdd = true;
bool bOnlyIfChanged = (bUseContactSpecific)
? (g_plugin.getWord(hContact, DB_STR_CURRENCYRATE_HISTORY_CONDITION, 1) > 0)
@@ -572,7 +573,7 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat
}
}
- if (dwMode&lmPopup) {
+ if (dwMode & lmPopup) {
bool bOnlyIfChanged = (bUseContactSpecific)
? (1 == g_plugin.getByte(hContact, DB_STR_CURRENCYRATE_POPUP_CONDITION, 1) > 0)
: global_settings.GetShowPopupIfValueChangedFlag();
@@ -583,7 +584,11 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat
CPopupSettings ps = *(global_settings.GetPopupSettingsPtr());
ps.InitForContact(hContact);
- show_popup(this, hContact, tendency, sFormat, ps);
+
+ CTendency::EResult nComparison = CTendency::NotChanged;
+ if (tendency.IsValid())
+ nComparison = tendency.Compare();
+ show_popup(this, hContact, nComparison, sFormat, ps);
}
}
@@ -642,7 +647,7 @@ uint32_t get_refresh_timeout_miliseconds()
class CBoolGuard
{
public:
- CBoolGuard(bool& rb) : m_b(rb) { m_b = true; }
+ CBoolGuard(bool &rb) : m_b(rb) { m_b = true; }
~CBoolGuard() { m_b = false; }
private:
@@ -758,7 +763,8 @@ void CCurrencyRatesProviderBase::RefreshSettings()
void CCurrencyRatesProviderBase::RefreshAllContacts()
{
- { mir_cslock lck(m_cs);
+ {
+ mir_cslock lck(m_cs);
m_aRefreshingContacts.clear();
for (auto &hContact : m_aContacts)
m_aRefreshingContacts.push_back(hContact);
@@ -769,7 +775,8 @@ void CCurrencyRatesProviderBase::RefreshAllContacts()
void CCurrencyRatesProviderBase::RefreshContact(MCONTACT hContact)
{
- { mir_cslock lck(m_cs);
+ {
+ mir_cslock lck(m_cs);
m_aRefreshingContacts.push_back(hContact);
}
@@ -796,7 +803,7 @@ bool CCurrencyRatesProviderBase::ParseSymbol(MCONTACT hContact, wchar_t c, doubl
case 'r':
case 'R':
return CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_CURR_VALUE, d);
-
+
case 'p':
case 'P':
return CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_PREV_VALUE, d);
@@ -876,7 +883,7 @@ CMStringW CCurrencyRatesProviderBase::FormatSymbol(MCONTACT hContact, wchar_t c,
ret = format_fetch_time(hContact, sFrmt);
}
break;
-
+
default:
if (ParseSymbol(hContact, c, d))
ret = format_double(d, nWidth);
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
index 4b34ae99bb..47227297d4 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h
@@ -116,4 +116,6 @@ protected:
mutable mir_cs m_cs;
};
+bool show_popup(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, int nComparison, const CMStringW &rsFormat, const CPopupSettings &ps);
+
#endif //__3e6cb4ec_fc47_468f_a2c8_a77941176bc9_CurrencyRatesProviderBase_h__
diff --git a/protocols/CurrencyRates/src/SettingsDlg.cpp b/protocols/CurrencyRates/src/SettingsDlg.cpp
index f3134e29be..e22a12c3a5 100644
--- a/protocols/CurrencyRates/src/SettingsDlg.cpp
+++ b/protocols/CurrencyRates/src/SettingsDlg.cpp
@@ -73,7 +73,7 @@ static LPCTSTR pszFilterParts[] = { LPGENW("Log Files (*.txt,*.log)"), L"*.txt;*
void select_log_file(HWND hDlg)
{
wchar_t pszFile[MAX_PATH];
-
+
CMStringW pszFilter;
for (auto &it : pszFilterParts) {
pszFilter += it;
@@ -120,15 +120,16 @@ void update_popup_controls_settings(HWND hDlg)
bool bIsDelayEnabled = 1 == IsDlgButtonChecked(hDlg, IDC_DELAYCUSTOM);
::EnableWindow(::GetDlgItem(hDlg, IDC_DELAY), bIsDelayEnabled);
-
}
INT_PTR CALLBACK EditPopupSettingsDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
+ auto *pSettings = (CPopupSettings *)(GetWindowLongPtr(hWnd, GWLP_USERDATA));
+
switch (msg) {
case WM_INITDIALOG:
{
- CPopupSettings *pSettings = reinterpret_cast<CPopupSettings *>(lp);
+ pSettings = (CPopupSettings *)lp;
TranslateDialogDefault(hWnd);
::SendDlgItemMessage(hWnd, IDC_BGCOLOR, CPM_SETCOLOUR, 0, pSettings->GetColourBk());
::SendDlgItemMessage(hWnd, IDC_TEXTCOLOR, CPM_SETCOLOUR, 0, pSettings->GetColourText());
@@ -138,8 +139,6 @@ INT_PTR CALLBACK EditPopupSettingsDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM
::CheckRadioButton(hWnd, IDC_RADIO_DEFAULT_COLOURS, IDC_RADIO_USER_DEFINED_COLOURS, (CPopupSettings::colourDefault == pSettings->GetColourMode()) ? IDC_RADIO_DEFAULT_COLOURS : IDC_RADIO_USER_DEFINED_COLOURS);
UINT n;
switch (pSettings->GetDelayMode()) {
- default:
- assert(!"Unknown delay mode. Please, fix it");
case CPopupSettings::delayFromPopup:
n = IDC_DELAYFROMPU;
break;
@@ -149,6 +148,8 @@ INT_PTR CALLBACK EditPopupSettingsDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM
case CPopupSettings::delayPermanent:
n = IDC_DELAYPERMANENT;
break;
+ default:
+ assert(!"Unknown delay mode. Please, fix it");
}
::CheckRadioButton(hWnd, IDC_DELAYFROMPU, IDC_DELAYPERMANENT, n);
@@ -162,6 +163,10 @@ INT_PTR CALLBACK EditPopupSettingsDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM
case WM_COMMAND:
switch (LOWORD(wp)) {
+ case IDC_PREV:
+ show_popup(0, 0, 1, L"", *pSettings);
+ break;
+
case IDC_RADIO_DEFAULT_COLOURS:
case IDC_RADIO_USER_DEFINED_COLOURS:
case IDC_DELAYFROMPU:
@@ -176,8 +181,6 @@ INT_PTR CALLBACK EditPopupSettingsDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM
case IDOK:
{
- CPopupSettings *pSettings = reinterpret_cast<CPopupSettings *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
-
bool bError = false;
BOOL bOk = FALSE;
UINT nDelay = ::GetDlgItemInt(hWnd, IDC_DELAY, &bOk, FALSE);