summaryrefslogtreecommitdiff
path: root/plugins/Quotes/src/QuotesProviderFinance.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-02-25 13:36:37 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-02-25 13:36:37 +0000
commit42095fb5cb7228f9dfb94965988029fd7f47b793 (patch)
tree6185ec5d7450fb474ed80b0ce95d0d1c0e0b26a8 /plugins/Quotes/src/QuotesProviderFinance.cpp
parent8e891173c74ceaa0964f32be247f380fd5f8bcd1 (diff)
Quotes: major code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@16335 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Quotes/src/QuotesProviderFinance.cpp')
-rw-r--r--plugins/Quotes/src/QuotesProviderFinance.cpp220
1 files changed, 88 insertions, 132 deletions
diff --git a/plugins/Quotes/src/QuotesProviderFinance.cpp b/plugins/Quotes/src/QuotesProviderFinance.cpp
index a54d597ac1..48502e6c95 100644
--- a/plugins/Quotes/src/QuotesProviderFinance.cpp
+++ b/plugins/Quotes/src/QuotesProviderFinance.cpp
@@ -14,17 +14,14 @@ void CQuotesProviderFinance::GetWatchedQuotes(TQuotes& raQuotes)const
}
}
-namespace
+inline tstring get_quote_id(MCONTACT hContact)
{
- inline tstring get_quote_id(MCONTACT hContact)
- {
- return Quotes_DBGetStringT(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_ID);
- }
+ return Quotes_DBGetStringT(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_ID);
+}
- inline bool is_quote_id_equal(MCONTACT hContact, const tstring& sID)
- {
- return sID == get_quote_id(hContact);
- }
+inline bool is_quote_id_equal(MCONTACT hContact, const tstring& sID)
+{
+ return sID == get_quote_id(hContact);
}
bool CQuotesProviderFinance::WatchForQuote(const CQuote& rQuote, bool bWatch)
@@ -33,10 +30,9 @@ bool CQuotesProviderFinance::WatchForQuote(const CQuote& rQuote, bool bWatch)
TContracts::iterator i = std::find_if(m_aContacts.begin(), m_aContacts.end(),
boost::bind(is_quote_id_equal, _1, sQuoteID));
- if ((false == bWatch) && (i != m_aContacts.end()))
- {
+ if (!bWatch && i != m_aContacts.end()) {
MCONTACT hContact = *i;
- {// for CCritSection
+ {
mir_cslock lck(m_cs);
m_aContacts.erase(i);
}
@@ -44,16 +40,13 @@ bool CQuotesProviderFinance::WatchForQuote(const CQuote& rQuote, bool bWatch)
CallService(MS_DB_CONTACT_DELETE, WPARAM(hContact), 0);
return true;
}
- else if ((true == bWatch) && (i == m_aContacts.end()))
- {
+
+ if (bWatch && i == m_aContacts.end()) {
MCONTACT hContact = CreateNewContact(rQuote.GetSymbol());
- if (hContact)
- {
+ if (hContact) {
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_ID, sQuoteID.c_str());
if (false == rQuote.GetName().empty())
- {
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_DESCRIPTION, rQuote.GetName().c_str());
- }
return true;
}
@@ -69,13 +62,9 @@ MCONTACT CQuotesProviderFinance::GetContactByQuoteID(const tstring& rsQuoteID)co
TContracts::const_iterator i = std::find_if(m_aContacts.begin(), m_aContacts.end(),
boost::bind(std::equal_to<tstring>(), rsQuoteID, boost::bind(get_quote_id, _1)));
if (i != m_aContacts.end())
- {
return *i;
- }
- else
- {
- return NULL;
- }
+
+ return NULL;
}
void CQuotesProviderFinance::Accept(CQuotesProviderVisitor& visitor)const
@@ -88,7 +77,7 @@ namespace
{
inline tstring make_quote_name(const CQuotesProviderBase::CQuote& rQuote)
{
- const tstring& rsDesc = rQuote.GetName();
+ const tstring &rsDesc = rQuote.GetName();
return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
}
@@ -96,25 +85,15 @@ namespace
{
tstring sName = make_quote_name(rQuote);
int nIndex = ::SendMessage(hwnd, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(sName.c_str()));
- if (nIndex >= 0)
- {
+ if (nIndex >= 0) {
CQuotesProviderBase::CQuote* pQuote = new CQuotesProviderBase::CQuote(rQuote);
- if (LB_ERR == ::SendMessage(hwnd, LB_SETITEMDATA, nIndex, reinterpret_cast<LPARAM>(pQuote)))
- {
+ if (LB_ERR == ::SendMessage(hwnd, LB_SETITEMDATA, nIndex, reinterpret_cast<LPARAM>(pQuote))) {
delete pQuote;
}
}
return nIndex;
}
- // typedef CQuotesProviderFinance::TQuotes TQuotes;
- // TQuotes g_aWatchedQuotes;
-
- // inline bool cmp_quotes(const tstring& rsQuoteId,const CQuotesProviderBase::CQuote& quote)
- // {
- // return (0 == quotes_stricmp(rsQuoteId.c_str(),quote.GetID().c_str()));
- // }
-
CQuotesProviderBase::CQuote* get_quote_ptr_from_lb_index(HWND hwndListBox, int nIndex)
{
LRESULT lResult = ::SendMessage(hwndListBox, LB_GETITEMDATA, nIndex, 0);
@@ -124,14 +103,12 @@ namespace
int is_quote_added(HWND hwndList, const tstring& rsQuoteID)
{
int cItems = ::SendMessage(hwndList, LB_GETCOUNT, 0, 0);
- for (int i = 0; i < cItems; ++i)
- {
+ for (int i = 0; i < cItems; ++i) {
const CQuotesProviderBase::CQuote* pQuote = get_quote_ptr_from_lb_index(hwndList, i);
if ((nullptr != pQuote)
&& ((0 == quotes_stricmp(rsQuoteID.c_str(), pQuote->GetID().c_str()))
- || (0 == quotes_stricmp(rsQuoteID.c_str(), pQuote->GetName().c_str()))
- || (0 == quotes_stricmp(rsQuoteID.c_str(), pQuote->GetSymbol().c_str()))))
- {
+ || (0 == quotes_stricmp(rsQuoteID.c_str(), pQuote->GetName().c_str()))
+ || (0 == quotes_stricmp(rsQuoteID.c_str(), pQuote->GetSymbol().c_str())))) {
return i;
}
}
@@ -141,79 +118,65 @@ namespace
INT_PTR CALLBACK GoogleFinanceOptDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
CQuotesProviderFinance* pProvider = nullptr;
- if (WM_INITDIALOG == message)
- {
+ if (WM_INITDIALOG == message) {
pProvider = reinterpret_cast<CQuotesProviderFinance*>(lParam);
SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
}
- else
- {
- pProvider = reinterpret_cast<CQuotesProviderFinance*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
- }
+ else pProvider = reinterpret_cast<CQuotesProviderFinance*>(GetWindowLongPtr(hDlg, GWLP_USERDATA));
CCommonDlgProcData d(pProvider);
CommonOptionDlgProc(hDlg, message, wParam, lParam, d);
- switch (message)
- {
+ switch (message) {
case WM_INITDIALOG:
- {
TranslateDialogDefault(hDlg);
+ {
+ CQuotesProviderFinance::TQuotes aQuotes;
+ pProvider->GetWatchedQuotes(aQuotes);
- CQuotesProviderFinance::TQuotes aQuotes;
- pProvider->GetWatchedQuotes(aQuotes);
+ HWND hwndList = GetDlgItem(hDlg, IDC_LIST_RATES);
+ std::for_each(aQuotes.begin(), aQuotes.end(),
+ boost::bind(add_quote_to_wnd, _1, hwndList));
- HWND hwndList = GetDlgItem(hDlg, IDC_LIST_RATES);
- std::for_each(aQuotes.begin(), aQuotes.end(),
- boost::bind(add_quote_to_wnd, _1, hwndList));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_ADD), FALSE);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_REMOVE), FALSE);
+ }
+ return TRUE;
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_ADD), FALSE);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_REMOVE), FALSE);
- }
- return (TRUE);
case WM_COMMAND:
- switch (LOWORD(wParam))
- {
+ switch (LOWORD(wParam)) {
case IDC_EDIT_QUOTE:
- if (EN_CHANGE == HIWORD(wParam))
- {
+ if (EN_CHANGE == HIWORD(wParam)) {
::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_ADD), GetWindowTextLength(GetDlgItem(hDlg, IDC_EDIT_QUOTE)) > 0);
}
- return (TRUE);
+ return TRUE;
case IDC_BUTTON_ADD:
- if (BN_CLICKED == HIWORD(wParam))
- {
+ if (BN_CLICKED == HIWORD(wParam)) {
HWND hEdit = GetDlgItem(hDlg, IDC_EDIT_QUOTE);
tstring sQuoteSymbol = get_window_text(hEdit);
assert(false == sQuoteSymbol.empty());
HWND hwndList = GetDlgItem(hDlg, IDC_LIST_RATES);
- if (LB_ERR == is_quote_added(hwndList, sQuoteSymbol))
- {
+ if (LB_ERR == is_quote_added(hwndList, sQuoteSymbol)) {
CQuotesProviderBase::CQuote quote(sQuoteSymbol, sQuoteSymbol);
- if (add_quote_to_wnd(quote, hwndList) >= 0)
- {
+ if (add_quote_to_wnd(quote, hwndList) >= 0) {
SetDlgItemText(hDlg, IDC_EDIT_QUOTE, _T(""));
SetFocus(hEdit);
PropSheet_Changed(::GetParent(hDlg), hDlg);
}
- else
- {
+ else {
::MessageBeep(MB_ICONERROR);
}
}
}
- return (TRUE);
+ return TRUE;
case IDC_BUTTON_REMOVE:
- if (BN_CLICKED == HIWORD(wParam))
- {
+ if (BN_CLICKED == HIWORD(wParam)) {
HWND hWnd = ::GetDlgItem(hDlg, IDC_LIST_RATES);
int nSel = ::SendMessage(hWnd, LB_GETCURSEL, 0, 0);
- if (LB_ERR != nSel)
- {
+ if (LB_ERR != nSel) {
CQuotesProviderBase::CQuote* pQuote = get_quote_ptr_from_lb_index(hWnd, nSel);
delete pQuote;
- if (LB_ERR != ::SendMessage(hWnd, LB_DELETESTRING, nSel, 0))
- {
+ if (LB_ERR != ::SendMessage(hWnd, LB_DELETESTRING, nSel, 0)) {
PropSheet_Changed(::GetParent(hDlg), hDlg);
}
}
@@ -221,81 +184,74 @@ namespace
nSel = ::SendMessage(hWnd, LB_GETCURSEL, 0, 0);
::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_REMOVE), (LB_ERR != nSel));
}
- return (TRUE);
+ return TRUE;
case IDC_LIST_RATES:
- if (CBN_SELCHANGE == HIWORD(wParam))
- {
+ if (CBN_SELCHANGE == HIWORD(wParam)) {
int nSel = ::SendDlgItemMessage(hDlg, IDC_LIST_RATES, LB_GETCURSEL, 0, 0);
::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_REMOVE), (LB_ERR != nSel));
}
- return (TRUE);
+ return TRUE;
}
- return (FALSE);
+ return FALSE;
case WM_NOTIFY:
- {
- LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lParam);
- switch (pNMHDR->code)
{
- case PSN_APPLY:
- if (pProvider)
- {
- CQuotesProviderFinance::TQuotes aTemp;
- pProvider->GetWatchedQuotes(aTemp);
-
- typedef std::vector<const CQuotesProviderBase::CQuote*> TQuotesPtr;
- TQuotesPtr apCurrent;
- HWND hwndListBox = GetDlgItem(hDlg, IDC_LIST_RATES);
- int cItems = ::SendMessage(hwndListBox, LB_GETCOUNT, 0, 0);
- for (int i = 0; i < cItems; ++i)
- {
- const CQuotesProviderBase::CQuote* pQuote = get_quote_ptr_from_lb_index(hwndListBox, i);
- if (pQuote)
- {
- apCurrent.push_back(pQuote);
+ LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lParam);
+ switch (pNMHDR->code) {
+ case PSN_APPLY:
+ if (pProvider) {
+ CQuotesProviderFinance::TQuotes aTemp;
+ pProvider->GetWatchedQuotes(aTemp);
+
+ typedef std::vector<const CQuotesProviderBase::CQuote*> TQuotesPtr;
+ TQuotesPtr apCurrent;
+ HWND hwndListBox = GetDlgItem(hDlg, IDC_LIST_RATES);
+ int cItems = ::SendMessage(hwndListBox, LB_GETCOUNT, 0, 0);
+ for (int i = 0; i < cItems; ++i) {
+ const CQuotesProviderBase::CQuote* pQuote = get_quote_ptr_from_lb_index(hwndListBox, i);
+ if (pQuote) {
+ apCurrent.push_back(pQuote);
+ }
}
- }
- std::for_each(aTemp.begin(), aTemp.end(),
- [&apCurrent, pProvider](const CQuotesProviderBase::CQuote& quote)
- {
- if (apCurrent.end() == std::find_if(apCurrent.begin(), apCurrent.end(),
- [&quote](const CQuotesProviderBase::CQuote* pQuote){return 0 == quotes_stricmp(pQuote->GetID().c_str(), quote.GetID().c_str()); }))
+ std::for_each(aTemp.begin(), aTemp.end(),
+ [&apCurrent, pProvider](const CQuotesProviderBase::CQuote& quote)
{
- pProvider->WatchForQuote(quote, false);
- }
- });
-
- std::for_each(apCurrent.begin(), apCurrent.end(),
- [&aTemp, pProvider](const CQuotesProviderBase::CQuote* pQuote)
- {
- if (aTemp.end() ==
- std::find_if(aTemp.begin(), aTemp.end(),
- [pQuote](const CQuotesProviderBase::CQuote& quote){return 0 == quotes_stricmp(pQuote->GetID().c_str(), quote.GetID().c_str()); }))
+ if (apCurrent.end() == std::find_if(apCurrent.begin(), apCurrent.end(),
+ [&quote](const CQuotesProviderBase::CQuote* pQuote) { return 0 == quotes_stricmp(pQuote->GetID().c_str(), quote.GetID().c_str()); })) {
+ pProvider->WatchForQuote(quote, false);
+ }
+ });
+
+ std::for_each(apCurrent.begin(), apCurrent.end(),
+ [&aTemp, pProvider](const CQuotesProviderBase::CQuote* pQuote)
{
- pProvider->WatchForQuote(*pQuote, true);
- }
+ if (aTemp.end() ==
+ std::find_if(aTemp.begin(), aTemp.end(),
+ [pQuote](const CQuotesProviderBase::CQuote& quote) { return 0 == quotes_stricmp(pQuote->GetID().c_str(), quote.GetID().c_str()); })) {
+ pProvider->WatchForQuote(*pQuote, true);
+ }
- });
+ });
- pProvider->RefreshSettings();
- }
+ pProvider->RefreshSettings();
+ }
- return (TRUE);
+ return TRUE;
+ }
}
- }
- return (FALSE);
+ return FALSE;
+
case WM_DESTROY:
HWND hwndListBox = GetDlgItem(hDlg, IDC_LIST_RATES);
int cItems = ::SendMessage(hwndListBox, LB_GETCOUNT, 0, 0);
- for (int i = 0; i < cItems; ++i)
- {
+ for (int i = 0; i < cItems; ++i) {
const CQuotesProviderBase::CQuote* pQuote = get_quote_ptr_from_lb_index(hwndListBox, i);
delete pQuote;
}
- return (FALSE);
+ return FALSE;
}
- return (FALSE);
+ return FALSE;
}
}