diff options
Diffstat (limited to 'plugins')
34 files changed, 3033 insertions, 4273 deletions
diff --git a/plugins/Quotes/src/ComHelper.cpp b/plugins/Quotes/src/ComHelper.cpp index 36241a423e..83a07c58e8 100644 --- a/plugins/Quotes/src/ComHelper.cpp +++ b/plugins/Quotes/src/ComHelper.cpp @@ -5,23 +5,17 @@ tstring ComException2Msg(_com_error& e, const tstring& rsAdditionalInfo) HRESULT hError = e.Error();
tostringstream o;
if (false == rsAdditionalInfo.empty())
- {
o << rsAdditionalInfo << "\n";
- }
o << e.ErrorMessage() << _T(" (") << std::hex << hError << _T(")");
IErrorInfo* p = e.ErrorInfo();
CComPtr<IErrorInfo> pErrorInfo(p);
if (NULL != p)
- {
p->Release();
- }
if (pErrorInfo)
- {
o << _T("\n") << e.Description();
- }
return o.str();
}
diff --git a/plugins/Quotes/src/CommonOptionDlg.cpp b/plugins/Quotes/src/CommonOptionDlg.cpp index be7ea014ce..e192f2f16a 100644 --- a/plugins/Quotes/src/CommonOptionDlg.cpp +++ b/plugins/Quotes/src/CommonOptionDlg.cpp @@ -1,264 +1,228 @@ #include "StdAfx.h"
-namespace
-{
- typedef boost::shared_ptr<CAdvProviderSettings> TAdvSettingsPtr;
- typedef std::map<const IQuotesProvider*, TAdvSettingsPtr> TAdvSettings;
+typedef boost::shared_ptr<CAdvProviderSettings> TAdvSettingsPtr;
+typedef std::map<const IQuotesProvider*, TAdvSettingsPtr> TAdvSettings;
- TAdvSettings g_aAdvSettings;
+TAdvSettings g_aAdvSettings;
- CAdvProviderSettings* get_adv_settings(const IQuotesProvider* pProvider, bool bCreateIfNonExist)
- {
- TAdvSettings::iterator i = g_aAdvSettings.find(pProvider);
- if (i != g_aAdvSettings.end())
- {
- return i->second.get();
- }
- else if (true == bCreateIfNonExist)
- {
- TAdvSettingsPtr pAdvSet(new CAdvProviderSettings(pProvider));
- g_aAdvSettings.insert(std::make_pair(pProvider, pAdvSet));
- return pAdvSet.get();
- }
- else
- {
- return NULL;
- }
+CAdvProviderSettings* get_adv_settings(const IQuotesProvider* pProvider, bool bCreateIfNonExist)
+{
+ TAdvSettings::iterator i = g_aAdvSettings.find(pProvider);
+ if (i != g_aAdvSettings.end())
+ return i->second.get();
+
+ if (true == bCreateIfNonExist) {
+ TAdvSettingsPtr pAdvSet(new CAdvProviderSettings(pProvider));
+ g_aAdvSettings.insert(std::make_pair(pProvider, pAdvSet));
+ return pAdvSet.get();
}
- void remove_adv_settings(const IQuotesProvider* pProvider)
- {
- TAdvSettings::iterator i = g_aAdvSettings.find(pProvider);
- if (i != g_aAdvSettings.end())
- {
- g_aAdvSettings.erase(i);
- }
- }
+ return NULL;
+}
+
+void remove_adv_settings(const IQuotesProvider *pProvider)
+{
+ TAdvSettings::iterator i = g_aAdvSettings.find(pProvider);
+ if (i != g_aAdvSettings.end())
+ g_aAdvSettings.erase(i);
}
void CommonOptionDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp, CCommonDlgProcData& rData)
{
- switch (msg)
- {
+ switch (msg) {
case WM_INITDIALOG:
- {
- assert(rData.m_pQuotesProvider);
-
- CQuotesProviderVisitorDbSettings visitor;
- rData.m_pQuotesProvider->Accept(visitor);
- assert(visitor.m_pszDbRefreshRateType);
- assert(visitor.m_pszDbRefreshRateValue);
- assert(visitor.m_pszDbDisplayNameFormat);
- assert(visitor.m_pszDbStatusMsgFormat);
- assert(visitor.m_pszDbTendencyFormat);
-
- // set contact list display format
- tstring sDspNameFrmt = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbDisplayNameFormat, visitor.m_pszDefDisplayFormat);
- ::SetDlgItemText(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT, sDspNameFrmt.c_str());
-
- // set status message display format
- tstring sStatusMsgFrmt = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbStatusMsgFormat, visitor.m_pszDefStatusMsgFormat);
- ::SetDlgItemText(hWnd, IDC_EDIT_STATUS_MESSAGE_FORMAT, sStatusMsgFrmt.c_str());
-
- // set tendency format
- tstring sTendencyFrmt = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbTendencyFormat, visitor.m_pszDefTendencyFormat);
- ::SetDlgItemText(hWnd, IDC_EDIT_TENDENCY_FORMAT, sTendencyFrmt.c_str());
-
- // refresh rate
- HWND hwndCombo = ::GetDlgItem(hWnd, IDC_COMBO_REFRESH_RATE);
- LPCTSTR pszRefreshRateTypes[] = { TranslateT("Seconds"), TranslateT("Minutes"), TranslateT("Hours") };
- for (int i = 0; i < _countof(pszRefreshRateTypes); ++i)
{
- ::SendMessage(hwndCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRefreshRateTypes[i]));
- }
+ assert(rData.m_pQuotesProvider);
- int nRefreshRateType = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateType, RRT_MINUTES);
- if (nRefreshRateType < RRT_SECONDS || nRefreshRateType > RRT_HOURS)
- {
- nRefreshRateType = RRT_MINUTES;
- }
+ CQuotesProviderVisitorDbSettings visitor;
+ rData.m_pQuotesProvider->Accept(visitor);
+ assert(visitor.m_pszDbRefreshRateType);
+ assert(visitor.m_pszDbRefreshRateValue);
+ assert(visitor.m_pszDbDisplayNameFormat);
+ assert(visitor.m_pszDbStatusMsgFormat);
+ assert(visitor.m_pszDbTendencyFormat);
- UINT nRate = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateValue, 1);
- switch (nRefreshRateType)
- {
- default:
- case RRT_SECONDS:
- case RRT_MINUTES:
- if (nRate < 1 || nRate > 60)
- {
- nRate = 1;
- }
- spin_set_range(::GetDlgItem(hWnd, IDC_SPIN_REFRESH_RATE), 1, 60);
- break;
- case RRT_HOURS:
- if (nRate < 1 || nRate > 24)
- {
- nRate = 1;
+ // set contact list display format
+ tstring sDspNameFrmt = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbDisplayNameFormat, visitor.m_pszDefDisplayFormat);
+ ::SetDlgItemText(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT, sDspNameFrmt.c_str());
+
+ // set status message display format
+ tstring sStatusMsgFrmt = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbStatusMsgFormat, visitor.m_pszDefStatusMsgFormat);
+ ::SetDlgItemText(hWnd, IDC_EDIT_STATUS_MESSAGE_FORMAT, sStatusMsgFrmt.c_str());
+
+ // set tendency format
+ tstring sTendencyFrmt = Quotes_DBGetStringT(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbTendencyFormat, visitor.m_pszDefTendencyFormat);
+ ::SetDlgItemText(hWnd, IDC_EDIT_TENDENCY_FORMAT, sTendencyFrmt.c_str());
+
+ // refresh rate
+ HWND hwndCombo = ::GetDlgItem(hWnd, IDC_COMBO_REFRESH_RATE);
+ LPCTSTR pszRefreshRateTypes[] = { TranslateT("Seconds"), TranslateT("Minutes"), TranslateT("Hours") };
+ for (int i = 0; i < _countof(pszRefreshRateTypes); ++i)
+ ::SendMessage(hwndCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRefreshRateTypes[i]));
+
+ int nRefreshRateType = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateType, RRT_MINUTES);
+ if (nRefreshRateType < RRT_SECONDS || nRefreshRateType > RRT_HOURS)
+ nRefreshRateType = RRT_MINUTES;
+
+ UINT nRate = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateValue, 1);
+ switch (nRefreshRateType) {
+ default:
+ case RRT_SECONDS:
+ case RRT_MINUTES:
+ if (nRate < 1 || nRate > 60)
+ nRate = 1;
+
+ spin_set_range(::GetDlgItem(hWnd, IDC_SPIN_REFRESH_RATE), 1, 60);
+ break;
+ case RRT_HOURS:
+ if (nRate < 1 || nRate > 24)
+ nRate = 1;
+
+ spin_set_range(::GetDlgItem(hWnd, IDC_SPIN_REFRESH_RATE), 1, 24);
+ break;
}
- spin_set_range(::GetDlgItem(hWnd, IDC_SPIN_REFRESH_RATE), 1, 24);
- break;
- }
- ::SendMessage(hwndCombo, CB_SETCURSEL, nRefreshRateType, 0);
- ::SetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, nRate, FALSE);
+ ::SendMessage(hwndCombo, CB_SETCURSEL, nRefreshRateType, 0);
+ ::SetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, nRate, FALSE);
+
+ PropSheet_UnChanged(::GetParent(hWnd), hWnd);
+ }
+ break;
- PropSheet_UnChanged(::GetParent(hWnd), hWnd);
- }
- break;
case WM_COMMAND:
- switch (HIWORD(wp))
- {
+ switch (HIWORD(wp)) {
case CBN_SELCHANGE:
- if (IDC_COMBO_REFRESH_RATE == LOWORD(wp))
- {
+ if (IDC_COMBO_REFRESH_RATE == LOWORD(wp)) {
ERefreshRateType nType = static_cast<ERefreshRateType>(::SendMessage(reinterpret_cast<HWND>(lp), CB_GETCURSEL, 0, 0));
- switch (nType)
- {
+ switch (nType) {
default:
case RRT_SECONDS:
case RRT_MINUTES:
spin_set_range(::GetDlgItem(hWnd, IDC_SPIN_REFRESH_RATE), 1, 60);
break;
case RRT_HOURS:
- {
spin_set_range(::GetDlgItem(hWnd, IDC_SPIN_REFRESH_RATE), 1, 24);
BOOL bOk = FALSE;
UINT nRefreshRate = ::GetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, &bOk, FALSE);
if (TRUE == bOk && nRefreshRate > 24)
- {
::SetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, 24, FALSE);
- }
- }
- break;
+ break;
}
PropSheet_Changed(::GetParent(hWnd), hWnd);
}
break;
+
case EN_CHANGE:
- switch (LOWORD(wp))
- {
+ switch (LOWORD(wp)) {
case IDC_EDIT_REFRESH_RATE:
case IDC_EDIT_CONTACT_LIST_FORMAT:
case IDC_EDIT_STATUS_MESSAGE_FORMAT:
case IDC_EDIT_TENDENCY_FORMAT:
if (reinterpret_cast<HWND>(lp) == ::GetFocus())
- {
PropSheet_Changed(::GetParent(hWnd), hWnd);
- }
break;
}
break;
+
case BN_CLICKED:
- switch (LOWORD(wp))
- {
+ switch (LOWORD(wp)) {
case IDC_BUTTON_DESCRIPTION:
show_variable_list(hWnd, rData.m_pQuotesProvider);
break;
case IDC_BUTTON_ADVANCED_SETTINGS:
- {
CAdvProviderSettings* pAdvSet = get_adv_settings(rData.m_pQuotesProvider, true);
assert(pAdvSet);
if (true == ShowSettingsDlg(hWnd, pAdvSet))
- {
PropSheet_Changed(::GetParent(hWnd), hWnd);
- }
- }
- break;
+ break;
}
break;
}
break;
+
case WM_NOTIFY:
- {
- LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lp);
- switch (pNMHDR->code)
- {
- case PSN_KILLACTIVE:
{
- BOOL bOk = FALSE;
- UINT nRefreshRate = ::GetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, &bOk, FALSE);
- ERefreshRateType nType = static_cast<ERefreshRateType>(::SendDlgItemMessage(hWnd, IDC_COMBO_REFRESH_RATE, CB_GETCURSEL, 0, 0));
- switch (nType)
- {
- default:
- case RRT_MINUTES:
- case RRT_SECONDS:
- if (FALSE == bOk || nRefreshRate < 1 || nRefreshRate > 60)
+ LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lp);
+ switch (pNMHDR->code) {
+ case PSN_KILLACTIVE:
{
- prepare_edit_ctrl_for_error(::GetDlgItem(hWnd, IDC_EDIT_REFRESH_RATE));
- Quotes_MessageBox(hWnd, TranslateT("Enter integer value between 1 and 60."), MB_OK | MB_ICONERROR);
- bOk = FALSE;
- }
- break;
- case RRT_HOURS:
- if (FALSE == bOk || nRefreshRate < 1 || nRefreshRate > 24)
- {
- prepare_edit_ctrl_for_error(::GetDlgItem(hWnd, IDC_EDIT_REFRESH_RATE));
- Quotes_MessageBox(hWnd, TranslateT("Enter integer value between 1 and 24."), MB_OK | MB_ICONERROR);
- bOk = FALSE;
- }
- break;
- }
+ BOOL bOk = FALSE;
+ UINT nRefreshRate = ::GetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, &bOk, FALSE);
+ ERefreshRateType nType = static_cast<ERefreshRateType>(::SendDlgItemMessage(hWnd, IDC_COMBO_REFRESH_RATE, CB_GETCURSEL, 0, 0));
+ switch (nType) {
+ default:
+ case RRT_MINUTES:
+ case RRT_SECONDS:
+ if (FALSE == bOk || nRefreshRate < 1 || nRefreshRate > 60) {
+ prepare_edit_ctrl_for_error(::GetDlgItem(hWnd, IDC_EDIT_REFRESH_RATE));
+ Quotes_MessageBox(hWnd, TranslateT("Enter integer value between 1 and 60."), MB_OK | MB_ICONERROR);
+ bOk = FALSE;
+ }
+ break;
+ case RRT_HOURS:
+ if (FALSE == bOk || nRefreshRate < 1 || nRefreshRate > 24) {
+ prepare_edit_ctrl_for_error(::GetDlgItem(hWnd, IDC_EDIT_REFRESH_RATE));
+ Quotes_MessageBox(hWnd, TranslateT("Enter integer value between 1 and 24."), MB_OK | MB_ICONERROR);
+ bOk = FALSE;
+ }
+ break;
+ }
- if (TRUE == bOk)
- {
- HWND hEdit = ::GetDlgItem(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT);
- assert(IsWindow(hEdit));
+ if (TRUE == bOk) {
+ HWND hEdit = ::GetDlgItem(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT);
+ assert(IsWindow(hEdit));
- tstring s = get_window_text(hEdit);
- if (true == s.empty())
- {
- prepare_edit_ctrl_for_error(hEdit);
- Quotes_MessageBox(hWnd, TranslateT("Enter text to display in contact list."), MB_OK | MB_ICONERROR);
- bOk = FALSE;
+ tstring s = get_window_text(hEdit);
+ if (true == s.empty()) {
+ prepare_edit_ctrl_for_error(hEdit);
+ Quotes_MessageBox(hWnd, TranslateT("Enter text to display in contact list."), MB_OK | MB_ICONERROR);
+ bOk = FALSE;
+ }
+ }
+
+ ::SetWindowLongPtr(hWnd, DWLP_MSGRESULT, (TRUE == bOk) ? FALSE : TRUE);
}
- }
+ break;
- ::SetWindowLongPtr(hWnd, DWLP_MSGRESULT, (TRUE == bOk) ? FALSE : TRUE);
- }
- break;
- case PSN_APPLY:
- {
- BOOL bOk = FALSE;
- UINT nRefreshRate = ::GetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, &bOk, FALSE);
- assert(TRUE == bOk);
- ERefreshRateType nType = static_cast<ERefreshRateType>(::SendDlgItemMessage(hWnd, IDC_COMBO_REFRESH_RATE, CB_GETCURSEL, 0, 0));
+ case PSN_APPLY:
+ BOOL bOk = FALSE;
+ UINT nRefreshRate = ::GetDlgItemInt(hWnd, IDC_EDIT_REFRESH_RATE, &bOk, FALSE);
+ assert(TRUE == bOk);
+ ERefreshRateType nType = static_cast<ERefreshRateType>(::SendDlgItemMessage(hWnd, IDC_COMBO_REFRESH_RATE, CB_GETCURSEL, 0, 0));
- assert(rData.m_pQuotesProvider);
+ assert(rData.m_pQuotesProvider);
- CQuotesProviderVisitorDbSettings visitor;
- rData.m_pQuotesProvider->Accept(visitor);
- assert(visitor.m_pszDbRefreshRateType);
- assert(visitor.m_pszDbRefreshRateValue);
- assert(visitor.m_pszDbDisplayNameFormat);
- assert(visitor.m_pszDbStatusMsgFormat);
+ CQuotesProviderVisitorDbSettings visitor;
+ rData.m_pQuotesProvider->Accept(visitor);
+ assert(visitor.m_pszDbRefreshRateType);
+ assert(visitor.m_pszDbRefreshRateValue);
+ assert(visitor.m_pszDbDisplayNameFormat);
+ assert(visitor.m_pszDbStatusMsgFormat);
- rData.m_bFireSetingsChangedEvent = true;
- db_set_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateType, nType);
- db_set_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateValue, nRefreshRate);
+ rData.m_bFireSetingsChangedEvent = true;
+ db_set_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateType, nType);
+ db_set_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateValue, nRefreshRate);
- tstring s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT));
- db_set_ts(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbDisplayNameFormat, s.c_str());
+ tstring s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT));
+ db_set_ts(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbDisplayNameFormat, s.c_str());
- s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_STATUS_MESSAGE_FORMAT));
- db_set_ts(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbStatusMsgFormat, s.c_str());
+ s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_STATUS_MESSAGE_FORMAT));
+ db_set_ts(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbStatusMsgFormat, s.c_str());
- s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_TENDENCY_FORMAT));
- db_set_ts(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbTendencyFormat, s.c_str());
+ s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_TENDENCY_FORMAT));
+ db_set_ts(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbTendencyFormat, s.c_str());
- CAdvProviderSettings* pAdvSet = get_adv_settings(rData.m_pQuotesProvider, false);
- if (pAdvSet)
- {
- pAdvSet->SaveToDb();
+ CAdvProviderSettings* pAdvSet = get_adv_settings(rData.m_pQuotesProvider, false);
+ if (pAdvSet)
+ pAdvSet->SaveToDb();
+ break;
}
}
break;
- }
- }
- break;
+
case WM_DESTROY:
remove_adv_settings(rData.m_pQuotesProvider);
break;
}
-}
\ No newline at end of file +}
diff --git a/plugins/Quotes/src/CreateFilePath.cpp b/plugins/Quotes/src/CreateFilePath.cpp index 5f1ea74ef7..e02cb91cd3 100644 --- a/plugins/Quotes/src/CreateFilePath.cpp +++ b/plugins/Quotes/src/CreateFilePath.cpp @@ -1,25 +1,19 @@ #include "StdAfx.h"
-namespace
+static TCHAR InvalidSymbols[] = { _T('\\'), _T('/'), _T(':'), _T('*'), _T('?'), _T('"'), _T('<'), _T('>'), _T('|') };
+
+TCHAR replace_invalid_symbol(TCHAR chr)
{
- TCHAR replace_invalid_symbol(TCHAR chr)
- {
- TCHAR InvaliSymbols[] = { _T('\\'), _T('/'), _T(':'), _T('*'), _T('?'), _T('"'), _T('<'), _T('>'), _T('|') };
- for (int i = 0; i < sizeof(InvaliSymbols) / sizeof(InvaliSymbols[0]); ++i)
- {
- if (chr == InvaliSymbols[i])
- {
- return _T('_');
- }
- }
+ for (int i = 0; i < _countof(InvalidSymbols); ++i)
+ if (chr == InvalidSymbols[i])
+ return _T('_');
- return chr;
- }
+ return chr;
+}
- void prepare_name(tstring& rsName)
- {
- std::transform(rsName.begin(), rsName.end(), rsName.begin(), boost::bind(replace_invalid_symbol, _1));
- }
+void prepare_name(tstring& rsName)
+{
+ std::transform(rsName.begin(), rsName.end(), rsName.begin(), boost::bind(replace_invalid_symbol, _1));
}
tstring CreateFilePath(const tstring& rsName)
@@ -29,9 +23,7 @@ tstring CreateFilePath(const tstring& rsName) TCHAR* p = _tcsrchr(szPath, _T('\\'));
if (p)
- {
*p = 0;
- }
tstring s(rsName);
prepare_name(s);
diff --git a/plugins/Quotes/src/CurrencyConverter.cpp b/plugins/Quotes/src/CurrencyConverter.cpp index 6858aa9a28..8c46d37fc3 100644 --- a/plugins/Quotes/src/CurrencyConverter.cpp +++ b/plugins/Quotes/src/CurrencyConverter.cpp @@ -6,104 +6,92 @@ #define DB_STR_CC_QUOTE_TO_ID "CurrencyConverter_ToID"
#define DB_STR_CC_AMOUNT "CurrencyConverter_Amount"
-namespace
+static CQuotesProviderGoogle* get_google_provider()
{
- 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 NULL;
+ 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 NULL;
+}
- CQuotesProviderGoogle::CQuoteSection get_quotes(const CQuotesProviderGoogle* pProvider = NULL)
- {
- if (NULL == pProvider)
- {
- pProvider = get_google_provider();
- }
- if (pProvider)
- {
- const CQuotesProviderGoogle::CQuoteSection& rQuotes = pProvider->GetQuotes();
- if (rQuotes.GetSectionCount() > 0)
- {
- return rQuotes.GetSection(0);
- }
- }
+CQuotesProviderGoogle::CQuoteSection get_quotes(const CQuotesProviderGoogle* pProvider = NULL)
+{
+ if (NULL == pProvider)
+ pProvider = get_google_provider();
- return CQuotesProviderGoogle::CQuoteSection();
+ if (pProvider) {
+ const CQuotesProviderGoogle::CQuoteSection& rQuotes = pProvider->GetQuotes();
+ if (rQuotes.GetSectionCount() > 0)
+ return rQuotes.GetSection(0);
}
- inline tstring make_quote_name(const CQuotesProviderGoogle::CQuote& rQuote)
- {
- const tstring& rsDesc = rQuote.GetName();
- return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
- }
+ return CQuotesProviderGoogle::CQuoteSection();
+}
- inline void update_convert_button(HWND hDlg)
- {
- 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 bEnableButton = ((CB_ERR != nFrom)
- && (CB_ERR != nTo)
- && (nFrom != nTo)
- && (GetWindowTextLength(GetDlgItem(hDlg, IDC_EDIT_VALUE)) > 0));
- EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_CONVERT), bEnableButton);
- }
+inline tstring make_quote_name(const CQuotesProviderGoogle::CQuote& rQuote)
+{
+ const tstring& rsDesc = rQuote.GetName();
+ return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
+}
- inline void update_swap_button(HWND hDlg)
- {
- 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 bEnableButton = ((CB_ERR != nFrom)
- && (CB_ERR != nTo)
- && (nFrom != nTo));
- EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SWAP), bEnableButton);
- }
+inline void update_convert_button(HWND hDlg)
+{
+ 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 bEnableButton = ((CB_ERR != nFrom)
+ && (CB_ERR != nTo)
+ && (nFrom != nTo)
+ && (GetWindowTextLength(GetDlgItem(hDlg, IDC_EDIT_VALUE)) > 0));
+ EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_CONVERT), bEnableButton);
+}
- inline tstring double2str(double dValue)
- {
- tostringstream output;
- output.imbue(GetSystemLocale());
- output << std::fixed << std::setprecision(2) << dValue;
- return output.str();
- }
+inline void update_swap_button(HWND hDlg)
+{
+ 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 bEnableButton = ((CB_ERR != nFrom)
+ && (CB_ERR != nTo)
+ && (nFrom != nTo));
+ EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SWAP), bEnableButton);
+}
- inline bool str2double(const tstring& s, double& d)
- {
- tistringstream input(s);
- input.imbue(GetSystemLocale());
- input >> d;
- return ((false == input.bad()) && (false == input.fail()));
- }
+inline tstring double2str(double dValue)
+{
+ tostringstream output;
+ output.imbue(GetSystemLocale());
+ output << std::fixed << std::setprecision(2) << dValue;
+ return output.str();
+}
+inline bool str2double(const tstring& s, double& d)
+{
+ tistringstream input(s);
+ input.imbue(GetSystemLocale());
+ input >> d;
+ return ((false == input.bad()) && (false == input.fail()));
+}
- INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
- {
- switch (msg)
- {
- case WM_INITDIALOG:
+
+INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hDlg);
{
MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, false);
assert(hWL);
WindowList_Add(hWL, hDlg, NULL);
- TranslateDialogDefault(hDlg);
-
- ::SendMessage(hDlg, WM_SETICON, FALSE, reinterpret_cast<LPARAM>(Quotes_LoadIconEx(ICON_STR_CURRENCY_CONVERTER)));
- ::SendMessage(hDlg, WM_SETICON, TRUE, reinterpret_cast<LPARAM>(Quotes_LoadIconEx(ICON_STR_CURRENCY_CONVERTER, true)));
+ ::SendMessage(hDlg, WM_SETICON, FALSE, LPARAM(Quotes_LoadIconEx(IDI_ICON_CURRENCY_CONVERTER)));
+ ::SendMessage(hDlg, WM_SETICON, TRUE, LPARAM(Quotes_LoadIconEx(IDI_ICON_CURRENCY_CONVERTER, true)));
HWND hcbxFrom = ::GetDlgItem(hDlg, IDC_COMBO_CONVERT_FROM);
HWND hcbxTo = ::GetDlgItem(hDlg, IDC_COMBO_CONVERT_INTO);
@@ -114,21 +102,18 @@ namespace 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)
- {
+ 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();
LRESULT nFrom = ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName));
LRESULT nTo = ::SendMessage(hcbxTo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName));
- if (0 == quotes_stricmp(rQuote.GetID().c_str(), sFromQuoteID.c_str()))
- {
+ if (0 == quotes_stricmp(rQuote.GetID().c_str(), sFromQuoteID.c_str())) {
::SendMessage(hcbxFrom, CB_SETCURSEL, nFrom, 0);
}
- if (0 == quotes_stricmp(rQuote.GetID().c_str(), sToQuoteID.c_str()))
- {
+ if (0 == quotes_stricmp(rQuote.GetID().c_str(), sToQuoteID.c_str())) {
::SendMessage(hcbxTo, CB_SETCURSEL, nTo, 0);
}
}
@@ -143,8 +128,7 @@ namespace ::SetDlgItemText(hDlg, IDC_SYSLINK_PROVIDER, o.str().c_str());
- ::SendDlgItemMessage(hDlg, IDC_BUTTON_SWAP, BM_SETIMAGE, IMAGE_ICON,
- reinterpret_cast<LPARAM>(Quotes_LoadIconEx(ICON_STR_SWAP)));
+ ::SendDlgItemMessage(hDlg, IDC_BUTTON_SWAP, BM_SETIMAGE, IMAGE_ICON, LPARAM(Quotes_LoadIconEx(IDI_ICON_SWAP)));
update_convert_button(hDlg);
update_swap_button(hDlg);
@@ -152,8 +136,9 @@ namespace Utils_RestoreWindowPositionNoSize(hDlg, NULL, QUOTES_PROTOCOL_NAME, WINDOW_PREFIX);
::ShowWindow(hDlg, SW_SHOW);
}
- return (TRUE);
- case WM_CLOSE:
+ return TRUE;
+
+ case WM_CLOSE:
{
MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, false);
assert(hWL);
@@ -161,30 +146,28 @@ namespace Utils_SaveWindowPosition(hDlg, NULL, QUOTES_PROTOCOL_NAME, WINDOW_PREFIX);
EndDialog(hDlg, 0);
}
- return (TRUE);
- case WM_COMMAND:
- switch (LOWORD(wp))
- {
- case IDC_COMBO_CONVERT_FROM:
- case IDC_COMBO_CONVERT_INTO:
- if (CBN_SELCHANGE == HIWORD(wp))
- {
- update_convert_button(hDlg);
- update_swap_button(hDlg);
- }
- return TRUE;
- case IDC_EDIT_VALUE:
- if (EN_CHANGE == HIWORD(wp))
- {
- update_convert_button(hDlg);
- }
- return TRUE;
- case IDCANCEL:
- {
- SendMessage(hDlg, WM_CLOSE, 0, 0);
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wp)) {
+ case IDC_COMBO_CONVERT_FROM:
+ case IDC_COMBO_CONVERT_INTO:
+ if (CBN_SELCHANGE == HIWORD(wp)) {
+ update_convert_button(hDlg);
+ update_swap_button(hDlg);
}
- return (TRUE);
- case IDC_BUTTON_SWAP:
+ return TRUE;
+
+ case IDC_EDIT_VALUE:
+ if (EN_CHANGE == HIWORD(wp))
+ update_convert_button(hDlg);
+ return TRUE;
+
+ case IDCANCEL:
+ SendMessage(hDlg, WM_CLOSE, 0, 0);
+ return TRUE;
+
+ case IDC_BUTTON_SWAP:
{
HWND wndFrom = ::GetDlgItem(hDlg, IDC_COMBO_CONVERT_FROM);
HWND wndTo = ::GetDlgItem(hDlg, IDC_COMBO_CONVERT_INTO);
@@ -194,25 +177,23 @@ namespace ::SendMessage(wndFrom, CB_SETCURSEL, nTo, 0);
::SendMessage(wndTo, CB_SETCURSEL, nFrom, 0);
}
- return (TRUE);
- case IDC_BUTTON_CONVERT:
+ return TRUE;
+
+ case IDC_BUTTON_CONVERT:
{
HWND hwndAmount = GetDlgItem(hDlg, IDC_EDIT_VALUE);
tstring sText = get_window_text(hwndAmount);
double dAmount = 1.0;
- if ((true == str2double(sText, dAmount)) && (dAmount > 0.0))
- {
+ if ((true == str2double(sText, dAmount)) && (dAmount > 0.0)) {
Quotes_DBWriteDouble(NULL, QUOTES_MODULE_NAME, DB_STR_CC_AMOUNT, dAmount);
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))
- {
+ 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))
- {
+ if ((nFrom < cQuotes) && (nTo < cQuotes)) {
CQuotesProviderGoogle::CRateInfo ri;
CQuotesProviderGoogle::CQuote from = rSection.GetQuote(nFrom);
CQuotesProviderGoogle::CQuote to = rSection.GetQuote(nTo);
@@ -222,77 +203,61 @@ namespace const CQuotesProviderGoogle* pProvider = get_google_provider();
assert(pProvider);
- if (pProvider)
- {
+ if (pProvider) {
tstring sResult;
std::string sError;
- try
- {
+ try {
double dResult = pProvider->Convert(dAmount, from, to);
tostringstream ss;
ss.imbue(GetSystemLocale());
ss << std::fixed << std::setprecision(2) << dAmount << " " << from.GetName() << " = " << dResult << " " << to.GetName();
sResult = ss.str();
}
- catch (std::exception& e)
- {
+ catch (std::exception& e) {
sError = e.what();
- //Quotes_MessageBox(hDlg,sResult.c_str());
}
if (false == sError.empty())
- {
- //USES_CONVERSION;
sResult = quotes_a2t(sError.c_str());//A2T(sError.c_str());
- }
SetDlgItemText(hDlg, IDC_EDIT_RESULT, sResult.c_str());
}
}
}
}
- else
- {
+ else {
Quotes_MessageBox(hDlg, TranslateT("Enter positive number."), MB_OK | MB_ICONERROR);
prepare_edit_ctrl_for_error(GetDlgItem(hDlg, IDC_EDIT_VALUE));
}
}
- return (TRUE);
- }
- return (FALSE);
- case WM_NOTIFY:
- {
- LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lp);
- switch (pNMHDR->code)
- {
- case NM_CLICK:
- if (IDC_SYSLINK_PROVIDER == wp)
- {
- PNMLINK pNMLink = reinterpret_cast<PNMLINK>(pNMHDR);
- ::ShellExecute(hDlg, _T("open"), pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);
- }
- break;
- }
+ return TRUE;
}
break;
+
+ case WM_NOTIFY:
+ LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lp);
+ switch (pNMHDR->code) {
+ case NM_CLICK:
+ if (IDC_SYSLINK_PROVIDER == wp) {
+ PNMLINK pNMLink = reinterpret_cast<PNMLINK>(pNMHDR);
+ ::ShellExecute(hDlg, _T("open"), pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);
+ }
+ break;
}
- return (FALSE);
+ break;
}
+ return (FALSE);
}
INT_PTR QuotesMenu_CurrencyConverter(WPARAM, LPARAM)
{
MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, true);
HWND hWnd = WindowList_Find(hWL, NULL);
- if (NULL != hWnd)
- {
+ if (NULL != hWnd) {
SetForegroundWindow(hWnd);
SetFocus(hWnd);
}
- else
- {
- CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_CURRENCY_CONVERTER), NULL, CurrencyConverterDlgProc, 0);
- }
+ else CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_CURRENCY_CONVERTER), NULL, CurrencyConverterDlgProc, 0);
return 0;
}
diff --git a/plugins/Quotes/src/DBUtils.cpp b/plugins/Quotes/src/DBUtils.cpp index e2d9f5f15e..57fac8aa53 100644 --- a/plugins/Quotes/src/DBUtils.cpp +++ b/plugins/Quotes/src/DBUtils.cpp @@ -4,15 +4,12 @@ std::string Quotes_DBGetStringA(MCONTACT hContact, const char* szModule, const c {
std::string sResult;
char* pszSymbol = db_get_sa(hContact, szModule, szSetting);
- if (NULL != pszSymbol)
- {
+ if (NULL != pszSymbol) {
sResult = pszSymbol;
mir_free(pszSymbol);
}
else if (NULL != pszDefValue)
- {
sResult = pszDefValue;
- }
return sResult;
}
@@ -21,15 +18,12 @@ std::wstring Quotes_DBGetStringW(MCONTACT hContact, const char* szModule, const {
std::wstring sResult;
wchar_t* pszSymbol = db_get_wsa(hContact, szModule, szSetting);
- if (NULL != pszSymbol)
- {
+ if (NULL != pszSymbol) {
sResult = pszSymbol;
mir_free(pszSymbol);
}
else if (NULL != pszDefValue)
- {
sResult = pszDefValue;
- }
return sResult;
}
diff --git a/plugins/Quotes/src/ExtraImages.cpp b/plugins/Quotes/src/ExtraImages.cpp index dd823bfcc2..ce5b7ded1c 100644 --- a/plugins/Quotes/src/ExtraImages.cpp +++ b/plugins/Quotes/src/ExtraImages.cpp @@ -4,7 +4,7 @@ static HANDLE hExtraIcon; void Quotes_InitExtraIcons()
{
- hExtraIcon = ExtraIcon_RegisterIcolib(ICON_STR_QUOTE, QUOTES_PROTOCOL_NAME, Quotes_MakeIconName(ICON_STR_MAIN).c_str());
+ hExtraIcon = ExtraIcon_RegisterIcolib(ICON_STR_QUOTE, QUOTES_PROTOCOL_NAME, QUOTES_PROTOCOL_NAME "_" ICON_STR_MAIN);
}
bool SetContactExtraImage(MCONTACT hContact, EImageIndex nIndex)
diff --git a/plugins/Quotes/src/Forex.cpp b/plugins/Quotes/src/Forex.cpp index 2ce2a1d7db..b92535800b 100644 --- a/plugins/Quotes/src/Forex.cpp +++ b/plugins/Quotes/src/Forex.cpp @@ -66,9 +66,8 @@ INT_PTR QuotesMenu_EnableDisable(WPARAM, LPARAM) const CQuotesProviders::TQuotesProviders& rapProviders = pProviders->GetProviders();
std::for_each(std::begin(rapProviders), std::end(rapProviders), [](const CQuotesProviders::TQuotesProviderPtr& pProvider) {
pProvider->RefreshSettings();
- if (g_bAutoUpdate) {
+ if (g_bAutoUpdate)
pProvider->RefreshAllContacts();
- }
});
UpdateMenu(g_bAutoUpdate);
@@ -191,12 +190,19 @@ int Quotes_OnToolbarLoaded(WPARAM, LPARAM) return 0;
}
+static void WorkingThread(void *pParam)
+{
+ IQuotesProvider *pProvider = reinterpret_cast<IQuotesProvider*>(pParam);
+ assert(pProvider);
+
+ if (pProvider)
+ pProvider->Run();
+}
+
int QuotesEventFunc_OnModulesLoaded(WPARAM, LPARAM)
{
CHTTPSession::Init();
- // HookEvent(ME_CLIST_EXTRA_IMAGE_APPLY,QuotesEventFunc_onExtraImageApply);
-
g_hEventWorkThreadStop = ::CreateEvent(NULL, TRUE, FALSE, NULL);
HookEvent(ME_USERINFO_INITIALISE, QuotesEventFunc_OnUserInfoInit);
@@ -227,10 +233,8 @@ int QuotesEventFunc_OnContactDeleted(WPARAM wParam, LPARAM) const CModuleInfo::TQuotesProvidersPtr& pProviders = CModuleInfo::GetQuoteProvidersPtr();
CQuotesProviders::TQuotesProviderPtr pProvider = pProviders->GetContactProviderPtr(hContact);
- if (pProvider) {
+ if (pProvider)
pProvider->DeleteContact(hContact);
- }
-
return 0;
}
@@ -267,7 +271,7 @@ int QuotesEventFunc_OptInitialise(WPARAM wp, LPARAM/* lp*/) odp.hInstance = g_hInstance;
odp.ptszTitle = _T(QUOTES_PROTOCOL_NAME);
odp.ptszGroup = LPGENT("Network");
- odp.hIcon = Quotes_LoadIconEx(ICON_STR_MAIN);
+ odp.hIcon = Quotes_LoadIconEx(IDI_ICON_MAIN);
odp.flags = ODPF_USERINFOTAB | ODPF_TCHAR;
std::for_each(rapProviders.begin(), rapProviders.end(), boost::bind(&IQuotesProvider::ShowPropertyPage, _1, wp, boost::ref(odp)));
diff --git a/plugins/Quotes/src/HTMLParserMS.cpp b/plugins/Quotes/src/HTMLParserMS.cpp index 92c394f332..c79c32ed5d 100644 --- a/plugins/Quotes/src/HTMLParserMS.cpp +++ b/plugins/Quotes/src/HTMLParserMS.cpp @@ -2,195 +2,167 @@ using _com_util::CheckError;
-namespace
+class CHTMLNode : public IHTMLNode
{
- class CHTMLNode : public IHTMLNode
- {
- public:
- typedef CComPtr<IDispatch> TComPtr;
- typedef CComPtr<IHTMLDocument3> TDocumentPtr;
+public:
+ typedef CComPtr<IDispatch> TComPtr;
+ typedef CComPtr<IHTMLDocument3> TDocumentPtr;
- protected:
- typedef CComPtr<IHTMLElementCollection> TElementCollectionPtr;
+protected:
+ typedef CComPtr<IHTMLElementCollection> TElementCollectionPtr;
- public:
- CHTMLNode(const TComPtr& pElement, const TDocumentPtr& pDocument)
- : m_pElement(pElement), m_pDocument(pDocument){}
+public:
+ CHTMLNode(const TComPtr& pElement, const TDocumentPtr& pDocument)
+ : m_pElement(pElement), m_pDocument(pDocument)
+ {
+ }
- virtual THTMLNodePtr GetElementByID(const tstring& rsID)const
- {
- if (m_pDocument)
- {
- CComPtr<IHTMLElement> pElement;
- if (SUCCEEDED(m_pDocument->getElementById(bstr_t(rsID.c_str()), &pElement))
- && pElement)
- {
- TComPtr p(pElement);
- return THTMLNodePtr(new CHTMLNode(p, m_pDocument));
- }
+ virtual THTMLNodePtr GetElementByID(const tstring& rsID)const
+ {
+ if (m_pDocument) {
+ CComPtr<IHTMLElement> pElement;
+ if (SUCCEEDED(m_pDocument->getElementById(bstr_t(rsID.c_str()), &pElement))
+ && pElement) {
+ TComPtr p(pElement);
+ return THTMLNodePtr(new CHTMLNode(p, m_pDocument));
}
-
- return THTMLNodePtr();
}
- virtual size_t GetChildCount()const
- {
- TElementCollectionPtr pColl = GetElementCollectionPtr();
- if (pColl)
- {
- LONG celem = 0;
- HRESULT hr = pColl->get_length(&celem);
- if (S_OK == hr)
- {
- return celem;
- }
- }
+ return THTMLNodePtr();
+ }
- return 0;
+ virtual size_t GetChildCount()const
+ {
+ TElementCollectionPtr pColl = GetElementCollectionPtr();
+ if (pColl) {
+ LONG celem = 0;
+ HRESULT hr = pColl->get_length(&celem);
+ if (S_OK == hr)
+ return celem;
}
- virtual THTMLNodePtr GetChildPtr(size_t nIndex)
- {
- TElementCollectionPtr pColl = GetElementCollectionPtr();
- if (pColl)
- {
- VARIANT varIndex;
- varIndex.vt = VT_UINT;
- varIndex.lVal = (LONG)nIndex;
- VARIANT var2;
- VariantInit(&var2);
- TComPtr pDisp;
- HRESULT hr = pColl->item(varIndex, var2, &pDisp);
- if (S_OK == hr && pDisp)
- {
- return THTMLNodePtr(new CHTMLNode(pDisp, m_pDocument));
- }
- }
+ return 0;
+ }
- return THTMLNodePtr();
+ virtual THTMLNodePtr GetChildPtr(size_t nIndex)
+ {
+ TElementCollectionPtr pColl = GetElementCollectionPtr();
+ if (pColl) {
+ VARIANT varIndex;
+ varIndex.vt = VT_UINT;
+ varIndex.lVal = (LONG)nIndex;
+ VARIANT var2;
+ VariantInit(&var2);
+ TComPtr pDisp;
+ HRESULT hr = pColl->item(varIndex, var2, &pDisp);
+ if (S_OK == hr && pDisp)
+ return THTMLNodePtr(new CHTMLNode(pDisp, m_pDocument));
}
- virtual bool Is(EType nType)const
- {
- switch (nType)
- {
- case Table:
+ return THTMLNodePtr();
+ }
+
+ virtual bool Is(EType nType)const
+ {
+ switch (nType) {
+ case Table:
{
CComPtr<IHTMLTable> pTable;
return (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLTable, reinterpret_cast<void**>(&pTable))) && (pTable));
}
- case TableRow:
+ case TableRow:
{
CComPtr<IHTMLTableRow> pRow;
return (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLTableRow, reinterpret_cast<void**>(&pRow))) && (pRow));
}
- case TableColumn:
+ case TableColumn:
{
CComPtr<IHTMLTableCol> pCol;
return (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLTableCol, reinterpret_cast<void**>(&pCol))) && (pCol));
}
- }
-
- return false;
}
- virtual tstring GetAttribute(const tstring& rsAttrName)const
- {
- tstring sAttr;
- CComPtr<IHTMLElement> pElement;
- if (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&pElement))) && pElement)
- {
- _variant_t vAttribute;
- BSTR pbstrAttrName = ::SysAllocString(rsAttrName.c_str());
- if (SUCCEEDED(pElement->getAttribute(pbstrAttrName, 1, &vAttribute))
- && VT_NULL != vAttribute.vt && VT_EMPTY != vAttribute.vt)
- {
- try
- {
- _bstr_t b(vAttribute);
- LPCTSTR psz = b;
- if (psz)
- {
- sAttr = psz;
- }
- }
- catch (_com_error&)
- {
- }
+ return false;
+ }
+
+ virtual tstring GetAttribute(const tstring& rsAttrName)const
+ {
+ tstring sAttr;
+ CComPtr<IHTMLElement> pElement;
+ if (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&pElement))) && pElement) {
+ _variant_t vAttribute;
+ BSTR pbstrAttrName = ::SysAllocString(rsAttrName.c_str());
+ if (SUCCEEDED(pElement->getAttribute(pbstrAttrName, 1, &vAttribute)) && VT_NULL != vAttribute.vt && VT_EMPTY != vAttribute.vt) {
+ try {
+ _bstr_t b(vAttribute);
+ LPCTSTR psz = b;
+ if (psz)
+ sAttr = psz;
+ }
+ catch (_com_error&) {
}
- ::SysFreeString(pbstrAttrName);
}
-
- return sAttr;
+ ::SysFreeString(pbstrAttrName);
}
- virtual tstring GetText()const
- {
- // USES_CONVERSION;
+ return sAttr;
+ }
- tstring sText;
- CComPtr<IHTMLElement> pElement;
- if (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&pElement))) && pElement)
- {
- BSTR bstrText;
- if (SUCCEEDED(pElement->get_innerText(&bstrText)) && bstrText)
- {
- try
- {
- sText = _bstr_t(bstrText);
- }
- catch (_com_error&)
- {
- }
-
- ::SysFreeString(bstrText);
+ virtual tstring GetText()const
+ {
+ tstring sText;
+ CComPtr<IHTMLElement> pElement;
+ if (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&pElement))) && pElement) {
+ BSTR bstrText;
+ if (SUCCEEDED(pElement->get_innerText(&bstrText)) && bstrText) {
+ try {
+ sText = _bstr_t(bstrText);
+ }
+ catch (_com_error&) {
}
- }
- return sText;
+ ::SysFreeString(bstrText);
+ }
}
- protected:
- virtual TElementCollectionPtr GetElementCollectionPtr()const
- {
- TElementCollectionPtr pColl;
- HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElementCollection, reinterpret_cast<void**>(&pColl));
- if (FAILED(hr))
- {
- CComPtr<IHTMLElement> pElement;
- if (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&pElement))) && pElement)
- {
- CComPtr<IDispatch> pDisp;
- if (SUCCEEDED(pElement->get_children(&pDisp)) && pDisp)
- {
- hr = pDisp->QueryInterface(IID_IHTMLElementCollection, reinterpret_cast<void**>(&pColl));
- }
- }
- }
+ return sText;
+ }
- return pColl;
+protected:
+ virtual TElementCollectionPtr GetElementCollectionPtr()const
+ {
+ TElementCollectionPtr pColl;
+ HRESULT hr = m_pElement->QueryInterface(IID_IHTMLElementCollection, reinterpret_cast<void**>(&pColl));
+ if (FAILED(hr)) {
+ CComPtr<IHTMLElement> pElement;
+ if (SUCCEEDED(m_pElement->QueryInterface(IID_IHTMLElement, reinterpret_cast<void**>(&pElement))) && pElement) {
+ CComPtr<IDispatch> pDisp;
+ if (SUCCEEDED(pElement->get_children(&pDisp)) && pDisp)
+ pDisp->QueryInterface(IID_IHTMLElementCollection, reinterpret_cast<void**>(&pColl));
+ }
}
- private:
- TComPtr m_pElement;
- TDocumentPtr m_pDocument;
- };
-}
+ return pColl;
+ }
+
+private:
+ TComPtr m_pElement;
+ TDocumentPtr m_pDocument;
+};
CHTMLParserMS::CHTMLParserMS() : m_bCallUninit(false)
{
- try
- {
+ try {
CheckError(::CoInitialize(NULL));
m_bCallUninit = true;
_com_util::CheckError(
::CoCreateInstance(CLSID_HTMLDocument,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_IHTMLDocument2,
- (LPVOID*)&m_pDoc)
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_IHTMLDocument2,
+ (LPVOID*)&m_pDoc)
);
CComPtr<IPersistStreamInit> pPersist;
@@ -202,17 +174,14 @@ CHTMLParserMS::CHTMLParserMS() : m_bCallUninit(false) _com_util::CheckError(m_pDoc->QueryInterface(IID_IMarkupServices,
(LPVOID*)&m_pMS));
- if (m_pMS)
- {
+ if (m_pMS) {
_com_util::CheckError(m_pMS->CreateMarkupPointer(&m_pMkStart));
_com_util::CheckError(m_pMS->CreateMarkupPointer(&m_pMkFinish));
}
}
- catch (_com_error&/* e*/)
- {
+ catch (_com_error&/* e*/) {
// show_com_error_msg(e);
}
-
}
CHTMLParserMS::~CHTMLParserMS()
@@ -227,12 +196,10 @@ CHTMLParserMS::THTMLNodePtr CHTMLParserMS::ParseString(const tstring& rsHTML) CComPtr<IMarkupContainer> pMC;
HRESULT hr = m_pMS->ParseString((OLECHAR*)rsHTML.c_str(), 0, &pMC, m_pMkStart, m_pMkFinish);
- if (SUCCEEDED(hr) && pMC)
- {
+ if (SUCCEEDED(hr) && pMC) {
CComPtr<IHTMLDocument2> pNewDoc;
hr = pMC->QueryInterface(IID_IHTMLDocument, (LPVOID*)&pNewDoc);
- if (SUCCEEDED(hr) && pNewDoc)
- {
+ if (SUCCEEDED(hr) && pNewDoc) {
CComPtr<IHTMLElementCollection> pColl;
pNewDoc->get_all(&pColl);
@@ -249,8 +216,7 @@ bool CHTMLParserMS::IsInstalled() {
bool bResult = true;
bool bCallUninit = false;
- try
- {
+ try {
CheckError(::CoInitialize(NULL));
bCallUninit = true;
@@ -258,14 +224,13 @@ bool CHTMLParserMS::IsInstalled() CComPtr<IHTMLDocument2> pDoc;
_com_util::CheckError(
::CoCreateInstance(CLSID_HTMLDocument,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_IHTMLDocument2,
- reinterpret_cast<LPVOID*>(&pDoc))
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_IHTMLDocument2,
+ reinterpret_cast<LPVOID*>(&pDoc))
);
}
- catch (_com_error&/* e*/)
- {
+ catch (_com_error&/* e*/) {
bResult = false;
}
@@ -277,12 +242,10 @@ bool CHTMLParserMS::IsInstalled() CHTMLEngineMS::CHTMLEngineMS()
{
-
}
CHTMLEngineMS::~CHTMLEngineMS()
{
-
}
CHTMLEngineMS::THTMLParserPtr CHTMLEngineMS::GetParserPtr()const
diff --git a/plugins/Quotes/src/HTTPSession.cpp b/plugins/Quotes/src/HTTPSession.cpp index 7390b2817f..ebe919e9f9 100644 --- a/plugins/Quotes/src/HTTPSession.cpp +++ b/plugins/Quotes/src/HTTPSession.cpp @@ -10,224 +10,122 @@ public: virtual bool ReadResponce(tstring& rsResponce)const = 0;
};
-namespace
+int find_header(const NETLIBHTTPREQUEST* pRequest, const char* hdr)
{
- // class CImplMS : public CHTTPSession::CImpl
- // {
- // public:
- // CImplMS()
- // : m_hSession(::InternetOpen(_T("Dioksin"),PRE_CONFIG_INTERNET_ACCESS,NULL,INTERNET_INVALID_PORT_NUMBER,0)),
- // m_hRequest(NULL)
- // {
- //
- // }
- //
- // ~CImplMS()
- // {
- // if(m_hRequest)
- // {
- // ::InternetCloseHandle(m_hRequest);
- // }
- //
- // if(m_hSession)
- // {
- // ::InternetCloseHandle(m_hSession);
- // }
- // }
- //
- // virtual bool OpenURL(const tstring& rsURL)
- // {
- // if(NULL == m_hSession)
- // {
- // return false;
- // }
- //
- // if(NULL != m_hRequest)
- // {
- // ::InternetCloseHandle(m_hRequest);
- // m_hRequest = NULL;
- // }
- //
- // m_hRequest = ::InternetOpenUrl(m_hSession,rsURL.c_str(),NULL,0,INTERNET_FLAG_RELOAD,0);
- // return NULL != m_hRequest;
- // }
- //
- // virtual bool ReadResponce(tstring& rsResponce)const
- // {
- // if(NULL == m_hRequest)
- // {
- // return false;
- // }
- //
- // std::string sBuffer;
- // bool bResult = true;
- // DWORD cbRead = 0;
- // char szBuffer[1024];
- // do{
- // if(FALSE == ::InternetReadFile(m_hRequest,szBuffer,1024,&cbRead))
- // {
- // bResult = false;
- // break;
- // }
- // if (0 == cbRead)
- // {
- // break; // Stop.
- // }
- // else
- // {
- // sBuffer.insert(sBuffer.size(),szBuffer,cbRead);
- // }
- // }while(true);
- //
- // if(true == bResult)
- // {
- // USES_CONVERSION;
- // rsResponce = A2CT(sBuffer.c_str());
- // }
- //
- // return bResult;
- // }
- // private:
- // HINTERNET m_hSession;
- // HINTERNET m_hRequest;
- // };
- //
- int find_header(const NETLIBHTTPREQUEST* pRequest, const char* hdr)
+ for (int i = 0; i < pRequest->headersCount; ++i)
{
- for (int i = 0; i < pRequest->headersCount; ++i)
+ if (0 == _stricmp(pRequest->headers[i].szName, hdr))
{
- if (0 == _stricmp(pRequest->headers[i].szName, hdr))
- {
- return i;
- }
+ return i;
}
-
- return -1;
}
+ return -1;
+}
+
+class CImplMI : public CHTTPSession::CImpl
+{
+public:
+ CImplMI() {}
- class CImplMI : public CHTTPSession::CImpl
+ static bool Init()
{
- public:
- CImplMI() {}
-
- static bool Init()
- {
- assert(NULL == g_hNetLib);
-
- NETLIBUSER nlu = { 0 };
- nlu.cbSize = sizeof(nlu);
- nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_NOHTTPSOPTION | NUF_TCHAR;
- nlu.szSettingsModule = QUOTES_PROTOCOL_NAME;
- nlu.ptszDescriptiveName = TranslateT("Quotes HTTP connections");
- g_hNetLib = reinterpret_cast<HANDLE>(CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu));
- return (NULL != g_hNetLib);
- }
+ assert(NULL == g_hNetLib);
+
+ NETLIBUSER nlu = { 0 };
+ nlu.cbSize = sizeof(nlu);
+ nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_NOHTTPSOPTION | NUF_TCHAR;
+ nlu.szSettingsModule = QUOTES_PROTOCOL_NAME;
+ nlu.ptszDescriptiveName = TranslateT("Quotes HTTP connections");
+ g_hNetLib = reinterpret_cast<HANDLE>(CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu));
+ return (NULL != g_hNetLib);
+ }
- static bool IsValid(){ return NULL != g_hNetLib; }
+ static bool IsValid() { return NULL != g_hNetLib; }
- virtual bool OpenURL(const tstring& rsURL)
- {
- m_aURL.swap(TBuffer());
+ virtual bool OpenURL(const tstring& rsURL)
+ {
+ m_aURL.clear();
- std::string s = quotes_t2a(rsURL.c_str());
- const char* psz = s.c_str();
- m_aURL.insert(m_aURL.begin(), psz, psz + mir_strlen(psz) + 1);
- return true;
- }
+ std::string s = quotes_t2a(rsURL.c_str());
+ const char* psz = s.c_str();
+ m_aURL.insert(m_aURL.begin(), psz, psz + mir_strlen(psz) + 1);
+ return true;
+ }
- virtual bool ReadResponce(tstring& rsResponce)const
+ virtual bool ReadResponce(tstring& rsResponce)const
+ {
+ if (true == m_aURL.empty())
+ return false;
+
+ NETLIBHTTPREQUEST nlhr = { 0 };
+ nlhr.cbSize = sizeof(nlhr);
+ nlhr.requestType = REQUEST_GET;
+ nlhr.flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT;
+ char* pURL = &*(m_aURL.begin());
+ nlhr.szUrl = pURL;
+
+ nlhr.headersCount = 4;
+ nlhr.headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount);
+ nlhr.headers[0].szName = "User-Agent";
+ nlhr.headers[0].szValue = NETLIB_USER_AGENT;
+ nlhr.headers[1].szName = "Connection";
+ nlhr.headers[1].szValue = "close";
+ nlhr.headers[2].szName = "Cache-Control";
+ nlhr.headers[2].szValue = "no-cache";
+ nlhr.headers[3].szName = "Pragma";
+ nlhr.headers[3].szValue = "no-cache";
+ // nlhr.headers[4].szName = "Accept-Encoding";
+ // nlhr.headers[4].szValue = "deflate, gzip";
+ // nlhr.headers[5].szName = "Cookie";
+ // nlhr.headers[5].szValue = cookie;
+
+ bool bResult = false;
+ NETLIBHTTPREQUEST* pReply = NULL;
{
- if (true == m_aURL.empty())
- return false;
-
- NETLIBHTTPREQUEST nlhr = { 0 };
- nlhr.cbSize = sizeof(nlhr);
- nlhr.requestType = REQUEST_GET;
- nlhr.flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT;
- char* pURL = &*(m_aURL.begin());
- nlhr.szUrl = pURL;
-
- nlhr.headersCount = 4;
- nlhr.headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount);
- nlhr.headers[0].szName = "User-Agent";
- nlhr.headers[0].szValue = NETLIB_USER_AGENT;
- nlhr.headers[1].szName = "Connection";
- nlhr.headers[1].szValue = "close";
- nlhr.headers[2].szName = "Cache-Control";
- nlhr.headers[2].szValue = "no-cache";
- nlhr.headers[3].szName = "Pragma";
- nlhr.headers[3].szValue = "no-cache";
- // nlhr.headers[4].szName = "Accept-Encoding";
- // nlhr.headers[4].szValue = "deflate, gzip";
- // nlhr.headers[5].szName = "Cookie";
- // nlhr.headers[5].szValue = cookie;
-
- bool bResult = false;
- NETLIBHTTPREQUEST* pReply = NULL;
-
- {
- mir_cslock lck(m_mx);
- pReply = reinterpret_cast<NETLIBHTTPREQUEST*>(CallService(MS_NETLIB_HTTPTRANSACTION,
- reinterpret_cast<WPARAM>(g_hNetLib), reinterpret_cast<LPARAM>(&nlhr)));
- }
+ mir_cslock lck(m_mx);
+ pReply = reinterpret_cast<NETLIBHTTPREQUEST*>(CallService(MS_NETLIB_HTTPTRANSACTION,
+ reinterpret_cast<WPARAM>(g_hNetLib), reinterpret_cast<LPARAM>(&nlhr)));
+ }
- if (pReply)
- {
- if ((200 == pReply->resultCode) && (pReply->dataLength > 0))
- {
- TBuffer apBuffer;
- apBuffer.insert(apBuffer.begin(), pReply->pData, pReply->pData + pReply->dataLength);
- apBuffer.push_back('\0');
-
- char* pResult = &*(apBuffer.begin());
- int nIndex = find_header(pReply, "Content-Type");
- if ((-1 != nIndex) && (NULL != strstr(_strlwr(pReply->headers[nIndex].szValue), "utf-8")))
- {
- TCHAR* p = mir_utf8decodeT(pResult);
- rsResponce = p;
- mir_free(p);
- }
- else
- {
- // USES_CONVERSION;
- // LPCTSTR p = A2CT(pResult);
- rsResponce = quotes_a2t(pResult);//p;
- }
-
- bResult = true;
+ if (pReply) {
+ if ((200 == pReply->resultCode) && (pReply->dataLength > 0)) {
+ TBuffer apBuffer;
+ apBuffer.insert(apBuffer.begin(), pReply->pData, pReply->pData + pReply->dataLength);
+ apBuffer.push_back('\0');
+
+ char* pResult = &*(apBuffer.begin());
+ int nIndex = find_header(pReply, "Content-Type");
+ if ((-1 != nIndex) && (NULL != strstr(_strlwr(pReply->headers[nIndex].szValue), "utf-8"))) {
+ TCHAR* p = mir_utf8decodeT(pResult);
+ rsResponce = p;
+ mir_free(p);
+ }
+ else {
+ // USES_CONVERSION;
+ // LPCTSTR p = A2CT(pResult);
+ rsResponce = quotes_a2t(pResult);//p;
}
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, reinterpret_cast<LPARAM>(pReply));
+ bResult = true;
}
- mir_free(nlhr.headers);
-
- return bResult;
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, reinterpret_cast<LPARAM>(pReply));
}
- private:
- static HANDLE g_hNetLib;
- typedef std::vector<char> TBuffer;
- mutable TBuffer m_aURL;
- mutable mir_cs m_mx;
- };
-
- HANDLE CImplMI::g_hNetLib = NULL;
-
- // CHTTPSession::CImpl* create_impl()
- // {
- // if(true == CImplMI::IsValid())
- // {
- // return new CImplMI;
- // }
- // else
- // {
- // return new CImplMS;
- // }
- // }
-}
+ mir_free(nlhr.headers);
+
+ return bResult;
+ }
+
+private:
+ static HANDLE g_hNetLib;
+ typedef std::vector<char> TBuffer;
+ mutable TBuffer m_aURL;
+ mutable mir_cs m_mx;
+};
+HANDLE CImplMI::g_hNetLib = NULL;
CHTTPSession::CHTTPSession()
: m_pImpl(new CImplMI)
diff --git a/plugins/Quotes/src/IconLib.cpp b/plugins/Quotes/src/IconLib.cpp index 70f88882cb..d2ea08eee0 100644 --- a/plugins/Quotes/src/IconLib.cpp +++ b/plugins/Quotes/src/IconLib.cpp @@ -2,18 +2,18 @@ static IconItem iconList[] =
{
- { LPGEN("Protocol icon"), ICON_STR_MAIN, IDI_ICON_MAIN },
- { LPGEN("Auto Update Disabled"), ICON_STR_AUTO_UPDATE_DISABLED, IDI_ICON_DISABLED },
- { LPGEN("Quote/Rate up"), ICON_STR_QUOTE_UP, IDI_ICON_UP },
- { LPGEN("Quote/Rate down"), ICON_STR_QUOTE_DOWN, IDI_ICON_DOWN },
- { LPGEN("Quote/Rate not changed"), ICON_STR_QUOTE_NOT_CHANGED, IDI_ICON_NOTCHANGED },
- { LPGEN("Quote Section"), ICON_STR_SECTION, IDI_ICON_SECTION },
- { LPGEN("Quote"), ICON_STR_QUOTE, IDI_ICON_QUOTE },
- { LPGEN("Currency Converter"), ICON_STR_CURRENCY_CONVERTER, IDI_ICON_CURRENCY_CONVERTER },
- { LPGEN("Refresh"), ICON_STR_REFRESH, IDI_ICON_REFRESH },
- { LPGEN("Export"), ICON_STR_EXPORT, IDI_ICON_EXPORT },
- { LPGEN("Swap button"), ICON_STR_SWAP, IDI_ICON_SWAP },
- { LPGEN("Import"), ICON_STR_IMPORT, IDI_ICON_IMPORT }
+ { LPGEN("Protocol icon"), ICON_STR_MAIN, IDI_ICON_MAIN },
+ { LPGEN("Auto Update Disabled"), "auto_update_disabled", IDI_ICON_DISABLED },
+ { LPGEN("Quote/Rate up"), "quote_up", IDI_ICON_UP },
+ { LPGEN("Quote/Rate down"), "quote_down", IDI_ICON_DOWN },
+ { LPGEN("Quote/Rate not changed"), "quote_not_changed", IDI_ICON_NOTCHANGED },
+ { LPGEN("Quote Section"), "quote_section", IDI_ICON_SECTION },
+ { LPGEN("Quote"), ICON_STR_QUOTE, IDI_ICON_QUOTE },
+ { LPGEN("Currency Converter"), "currency_converter", IDI_ICON_CURRENCY_CONVERTER },
+ { LPGEN("Refresh"), "refresh", IDI_ICON_REFRESH },
+ { LPGEN("Export"), "export", IDI_ICON_EXPORT },
+ { LPGEN("Swap button"), "swap", IDI_ICON_SWAP },
+ { LPGEN("Import"), "import", IDI_ICON_IMPORT }
};
void Quotes_IconsInit()
@@ -21,19 +21,13 @@ void Quotes_IconsInit() ::Icon_Register(g_hInstance, QUOTES_PROTOCOL_NAME, iconList, _countof(iconList), QUOTES_PROTOCOL_NAME);
}
-std::string Quotes_MakeIconName(const char* name)
+HICON Quotes_LoadIconEx(int iconId, bool bBig /*= false*/)
{
- assert(name);
- std::string sName(QUOTES_PROTOCOL_NAME);
- sName += "_";
- sName += name;
- return sName;
-}
+ for (int i = 0; i < _countof(iconList); i++)
+ if (iconList[i].defIconID == iconId)
+ return IcoLib_GetIconByHandle(iconList[i].hIcolib, bBig);
-HICON Quotes_LoadIconEx(const char* name, bool bBig /*= false*/)
-{
- std::string sIconName = Quotes_MakeIconName(name);
- return IcoLib_GetIcon(sIconName.c_str(), bBig);
+ return NULL;
}
HANDLE Quotes_GetIconHandle(int iconId)
diff --git a/plugins/Quotes/src/IconLib.h b/plugins/Quotes/src/IconLib.h index b7e1fda175..9979c8a56d 100644 --- a/plugins/Quotes/src/IconLib.h +++ b/plugins/Quotes/src/IconLib.h @@ -1,22 +1,11 @@ #ifndef __8821d334_afac_439e_9a81_76318e1ac4ef_IconLib_h__
#define __8821d334_afac_439e_9a81_76318e1ac4ef_IconLib_h__
-#define ICON_STR_MAIN "main"
-#define ICON_STR_AUTO_UPDATE_DISABLED "auto_update_disabled"
-#define ICON_STR_QUOTE_UP "quote_up"
-#define ICON_STR_QUOTE_DOWN "quote_down"
-#define ICON_STR_QUOTE_NOT_CHANGED "quote_not_changed"
-#define ICON_STR_SECTION "quote_section"
+#define ICON_STR_MAIN "main"
#define ICON_STR_QUOTE "quote"
-#define ICON_STR_CURRENCY_CONVERTER "currency_converter"
-#define ICON_STR_REFRESH "refresh"
-#define ICON_STR_IMPORT "import"
-#define ICON_STR_EXPORT "export"
-#define ICON_STR_SWAP "swap"
void Quotes_IconsInit();
-HICON Quotes_LoadIconEx(const char* name, bool bBig = false);
+HICON Quotes_LoadIconEx(int iconId, bool bBig = false);
HANDLE Quotes_GetIconHandle(int iconId);
-std::string Quotes_MakeIconName(const char* name);
#endif //__8821d334_afac_439e_9a81_76318e1ac4ef_IconLib_h__
diff --git a/plugins/Quotes/src/ImportExport.cpp b/plugins/Quotes/src/ImportExport.cpp index 06d9942d43..34f65b35d9 100644 --- a/plugins/Quotes/src/ImportExport.cpp +++ b/plugins/Quotes/src/ImportExport.cpp @@ -1,301 +1,238 @@ #include "StdAfx.h"
-namespace
+LPCTSTR g_pszXmlValue = _T("Value");
+LPCTSTR g_pszXmlName = _T("Name");
+LPCTSTR g_pszXmlSetting = _T("Setting");
+LPCTSTR g_pszXmlModule = _T("Module");
+LPCTSTR g_pszXmlContact = _T("Contact");
+LPCTSTR g_pszXmlContacts = _T("Contacts");
+LPCTSTR g_pszXmlType = _T("type");
+LPCTSTR g_pszXmlTypeByte = _T("byte");
+LPCTSTR g_pszXmlTypeWord = _T("word");
+LPCTSTR g_pszXmlTypeDword = _T("dword");
+LPCTSTR g_pszXmlTypeAsciiz = _T("asciiz");
+LPCTSTR g_pszXmlTypeWchar = _T("wchar");
+LPCTSTR g_pszXmlTypeUtf8 = _T("utf8");
+LPCTSTR g_pszXmlTypeBlob = _T("blob");
+
+struct CEnumContext
{
- LPCTSTR g_pszXmlValue = _T("Value");
- LPCTSTR g_pszXmlName = _T("Name");
- LPCTSTR g_pszXmlSetting = _T("Setting");
- LPCTSTR g_pszXmlModule = _T("Module");
- LPCTSTR g_pszXmlContact = _T("Contact");
- LPCTSTR g_pszXmlContacts = _T("Contacts");
- LPCTSTR g_pszXmlType = _T("type");
- LPCTSTR g_pszXmlTypeByte = _T("byte");
- LPCTSTR g_pszXmlTypeWord = _T("word");
- LPCTSTR g_pszXmlTypeDword = _T("dword");
- LPCTSTR g_pszXmlTypeAsciiz = _T("asciiz");
- LPCTSTR g_pszXmlTypeWchar = _T("wchar");
- LPCTSTR g_pszXmlTypeUtf8 = _T("utf8");
- LPCTSTR g_pszXmlTypeBlob = _T("blob");
-
- struct CEnumContext
- {
- CModuleInfo::TXMLEnginePtr m_pXmlEngine;
- IXMLNode::TXMLNodePtr m_pNode;
- MCONTACT m_hContact;
- LPCSTR m_pszModule;
- };
-
- struct mir_safety_dbvar
- {
- mir_safety_dbvar(DBVARIANT* p) : m_p(p){}
- ~mir_safety_dbvar(){ db_free(m_p); }
- DBVARIANT* m_p;
- };
-
- static int enum_contact_settings(const char* szSetting, LPARAM lp)
- {
- CEnumContext* ctx = reinterpret_cast<CEnumContext*>(lp);
+ CModuleInfo::TXMLEnginePtr m_pXmlEngine;
+ IXMLNode::TXMLNodePtr m_pNode;
+ MCONTACT m_hContact;
+ LPCSTR m_pszModule;
+};
- DBVARIANT dbv;
- if (0 == db_get(ctx->m_hContact, ctx->m_pszModule, szSetting, &dbv))
- {
- mir_safety_dbvar sdbvar(&dbv);
-
- tstring sType;
- tostringstream sValue;
- sValue.imbue(GetSystemLocale());
-
- switch (dbv.type)
- {
- case DBVT_BYTE:
- sValue << dbv.bVal;
- sType = g_pszXmlTypeByte;
- break;
- case DBVT_WORD:
- sValue << dbv.wVal;
- sType = g_pszXmlTypeWord;
- break;
- case DBVT_DWORD:
- sValue << dbv.dVal;
- sType = g_pszXmlTypeDword;
- break;
- case DBVT_ASCIIZ:
- sType = g_pszXmlTypeAsciiz;
- if (dbv.pszVal)
- {
- sValue << dbv.pszVal;
- // mir_safe_string<char> mss(mir_utf8encode(dbv.pszVal));
- // if(mss.m_p)
- // {
- // sValue << mss.m_p;
- // }
- }
- break;
- case DBVT_WCHAR:
- sType = g_pszXmlTypeWchar;
- if (dbv.pwszVal)
- {
- sValue << dbv.pwszVal;
- // mir_safe_string<char> mss(mir_utf8encodeW(dbv.pwszVal));
- // if(mss.m_p)
- // {
- // sValue << mss.m_p;
- // }
- }
- break;
- case DBVT_UTF8:
- sType = g_pszXmlTypeUtf8;
- if (dbv.pszVal)
- {
- sValue << dbv.pszVal;
- }
- break;
- case DBVT_BLOB:
- sType = g_pszXmlTypeBlob;
- if (dbv.pbVal)
- {
- ptrA buf(mir_base64_encode(dbv.pbVal, dbv.cpbVal));
- if (buf) {
- sValue << buf;
- }
- }
- break;
- }
+struct mir_safety_dbvar
+{
+ mir_safety_dbvar(DBVARIANT* p) : m_p(p) {}
+ ~mir_safety_dbvar() { db_free(m_p); }
+ DBVARIANT* m_p;
+};
- // mir_safe_string<char> mssSetting(mir_utf8encode(szSetting));
- // if(mssSetting.m_p)
- {
- IXMLNode::TXMLNodePtr pXmlSet = ctx->m_pXmlEngine->CreateNode(g_pszXmlSetting, tstring());
- if (pXmlSet)
- {
- IXMLNode::TXMLNodePtr pXmlName = ctx->m_pXmlEngine->CreateNode(g_pszXmlName, quotes_a2t(szSetting));
-
- IXMLNode::TXMLNodePtr pXmlValue = ctx->m_pXmlEngine->CreateNode(g_pszXmlValue, sValue.str());
- if (pXmlName && pXmlValue)
- {
- pXmlValue->AddAttribute(g_pszXmlType, sType);
-
- pXmlSet->AddChild(pXmlName);
- pXmlSet->AddChild(pXmlValue);
- ctx->m_pNode->AddChild(pXmlSet);
- }
- }
+static int enum_contact_settings(const char* szSetting, LPARAM lp)
+{
+ CEnumContext* ctx = reinterpret_cast<CEnumContext*>(lp);
+
+ DBVARIANT dbv;
+ if (0 == db_get(ctx->m_hContact, ctx->m_pszModule, szSetting, &dbv)) {
+ mir_safety_dbvar sdbvar(&dbv);
+
+ tstring sType;
+ tostringstream sValue;
+ sValue.imbue(GetSystemLocale());
+
+ switch (dbv.type) {
+ case DBVT_BYTE:
+ sValue << dbv.bVal;
+ sType = g_pszXmlTypeByte;
+ break;
+ case DBVT_WORD:
+ sValue << dbv.wVal;
+ sType = g_pszXmlTypeWord;
+ break;
+ case DBVT_DWORD:
+ sValue << dbv.dVal;
+ sType = g_pszXmlTypeDword;
+ break;
+ case DBVT_ASCIIZ:
+ sType = g_pszXmlTypeAsciiz;
+ if (dbv.pszVal)
+ sValue << dbv.pszVal;
+ break;
+ case DBVT_WCHAR:
+ sType = g_pszXmlTypeWchar;
+ if (dbv.pwszVal)
+ sValue << dbv.pwszVal;
+ break;
+ case DBVT_UTF8:
+ sType = g_pszXmlTypeUtf8;
+ if (dbv.pszVal)
+ sValue << dbv.pszVal;
+ break;
+ case DBVT_BLOB:
+ sType = g_pszXmlTypeBlob;
+ if (dbv.pbVal) {
+ ptrA buf(mir_base64_encode(dbv.pbVal, dbv.cpbVal));
+ if (buf)
+ sValue << buf;
}
+ break;
}
- return 0;
- }
-
- int EnumDbModules(const char *szModuleName, DWORD, LPARAM lp)
- {
- CEnumContext *ctx = (CEnumContext*)lp;
- IXMLNode::TXMLNodePtr pXml = ctx->m_pNode;
- IXMLNode::TXMLNodePtr pModule = ctx->m_pXmlEngine->CreateNode(g_pszXmlModule, quotes_a2t(szModuleName)/*A2CT(szModuleName)*/);
- if (pModule)
- {
- ctx->m_pszModule = szModuleName;
- ctx->m_pNode = pModule;
+ IXMLNode::TXMLNodePtr pXmlSet = ctx->m_pXmlEngine->CreateNode(g_pszXmlSetting, tstring());
+ if (pXmlSet) {
+ IXMLNode::TXMLNodePtr pXmlName = ctx->m_pXmlEngine->CreateNode(g_pszXmlName, quotes_a2t(szSetting));
- DBCONTACTENUMSETTINGS dbces;
- dbces.pfnEnumProc = &enum_contact_settings;
- dbces.szModule = szModuleName;
- dbces.lParam = reinterpret_cast<LPARAM>(ctx);
+ IXMLNode::TXMLNodePtr pXmlValue = ctx->m_pXmlEngine->CreateNode(g_pszXmlValue, sValue.str());
+ if (pXmlName && pXmlValue) {
+ pXmlValue->AddAttribute(g_pszXmlType, sType);
- CallService(MS_DB_CONTACT_ENUMSETTINGS, WPARAM(ctx->m_hContact), reinterpret_cast<LPARAM>(&dbces));
- if (pModule->GetChildCount() > 0)
- pXml->AddChild(pModule);
-
- ctx->m_pNode = pXml;
+ pXmlSet->AddChild(pXmlName);
+ pXmlSet->AddChild(pXmlValue);
+ ctx->m_pNode->AddChild(pXmlSet);
+ }
}
-
- return 0;
}
- IXMLNode::TXMLNodePtr export_contact(MCONTACT hContact, const CModuleInfo::TXMLEnginePtr& pXmlEngine)
- {
- IXMLNode::TXMLNodePtr pNode = pXmlEngine->CreateNode(g_pszXmlContact, tstring());
- if (pNode)
- {
- CEnumContext ctx;
- ctx.m_pXmlEngine = pXmlEngine;
- ctx.m_pNode = pNode;
- ctx.m_hContact = hContact;
+ return 0;
+}
- CallService(MS_DB_MODULES_ENUM, (WPARAM)&ctx, (LPARAM)EnumDbModules);
- }
- return pNode;
+int EnumDbModules(const char *szModuleName, DWORD, LPARAM lp)
+{
+ CEnumContext *ctx = (CEnumContext*)lp;
+ IXMLNode::TXMLNodePtr pXml = ctx->m_pNode;
+ IXMLNode::TXMLNodePtr pModule = ctx->m_pXmlEngine->CreateNode(g_pszXmlModule, quotes_a2t(szModuleName)/*A2CT(szModuleName)*/);
+ if (pModule) {
+ ctx->m_pszModule = szModuleName;
+ ctx->m_pNode = pModule;
+
+ DBCONTACTENUMSETTINGS dbces;
+ dbces.pfnEnumProc = &enum_contact_settings;
+ dbces.szModule = szModuleName;
+ dbces.lParam = reinterpret_cast<LPARAM>(ctx);
+
+ CallService(MS_DB_CONTACT_ENUMSETTINGS, WPARAM(ctx->m_hContact), reinterpret_cast<LPARAM>(&dbces));
+ if (pModule->GetChildCount() > 0)
+ pXml->AddChild(pModule);
+
+ ctx->m_pNode = pXml;
}
- LPCTSTR prepare_filter(LPTSTR pszBuffer, size_t cBuffer)
- {
- LPTSTR p = pszBuffer;
- LPCTSTR pszXml = TranslateT("XML File (*.xml)");
- mir_tstrncpy(p, pszXml, (int)cBuffer);
- size_t nLen = mir_tstrlen(pszXml) + 1;
- p += nLen;
- if (nLen < cBuffer)
- {
- mir_tstrncpy(p, _T("*.xml"), (int)(cBuffer - nLen));
- p += 6;
- nLen += 6;
- }
+ return 0;
+}
- if (nLen < cBuffer)
- {
- LPCTSTR pszAll = TranslateT("All files (*.*)");
- mir_tstrncpy(p, pszAll, (int)(cBuffer - nLen));
- size_t n = mir_tstrlen(pszAll) + 1;
- nLen += n;
- p += n;
- }
+IXMLNode::TXMLNodePtr export_contact(MCONTACT hContact, const CModuleInfo::TXMLEnginePtr& pXmlEngine)
+{
+ IXMLNode::TXMLNodePtr pNode = pXmlEngine->CreateNode(g_pszXmlContact, tstring());
+ if (pNode) {
+ CEnumContext ctx;
+ ctx.m_pXmlEngine = pXmlEngine;
+ ctx.m_pNode = pNode;
+ ctx.m_hContact = hContact;
+
+ CallService(MS_DB_MODULES_ENUM, (WPARAM)&ctx, (LPARAM)EnumDbModules);
+ }
+ return pNode;
+}
- if (nLen < cBuffer)
- {
- mir_tstrncpy(p, _T("*.*"), (int)(cBuffer - nLen));
- p += 4;
- nLen += 4;
- }
+LPCTSTR prepare_filter(LPTSTR pszBuffer, size_t cBuffer)
+{
+ LPTSTR p = pszBuffer;
+ LPCTSTR pszXml = TranslateT("XML File (*.xml)");
+ mir_tstrncpy(p, pszXml, (int)cBuffer);
+ size_t nLen = mir_tstrlen(pszXml) + 1;
+ p += nLen;
+ if (nLen < cBuffer) {
+ mir_tstrncpy(p, _T("*.xml"), (int)(cBuffer - nLen));
+ p += 6;
+ nLen += 6;
+ }
- if (nLen < cBuffer)
- {
- *p = _T('\0');
- }
+ if (nLen < cBuffer) {
+ LPCTSTR pszAll = TranslateT("All files (*.*)");
+ mir_tstrncpy(p, pszAll, (int)(cBuffer - nLen));
+ size_t n = mir_tstrlen(pszAll) + 1;
+ nLen += n;
+ p += n;
+ }
- return pszBuffer;
+ if (nLen < cBuffer) {
+ mir_tstrncpy(p, _T("*.*"), (int)(cBuffer - nLen));
+ p += 4;
+ nLen += 4;
}
- bool show_open_file_dialog(bool bOpen, tstring& rsFile)
- {
- TCHAR szBuffer[MAX_PATH];
- TCHAR szFilter[MAX_PATH];
- OPENFILENAME ofn;
- memset(&ofn, 0, sizeof(ofn));
-
- ofn.lStructSize = sizeof(OPENFILENAME);
-
- ofn.hwndOwner = NULL;
- ofn.lpstrFilter = prepare_filter(szFilter, MAX_PATH);
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
- ofn.lpstrDefExt = _T("xml");
- if (true == bOpen)
- {
- ofn.Flags |= OFN_FILEMUSTEXIST;
- }
- else
- {
- ofn.Flags |= OFN_OVERWRITEPROMPT;
- }
- ofn.nMaxFile = MAX_PATH;
- ofn.lpstrFile = szBuffer;
- ofn.lpstrFile[0] = _T('\0');
+ if (nLen < cBuffer)
+ *p = _T('\0');
- if (bOpen)
- {
- if (FALSE == GetOpenFileName(&ofn))
- {
- return false;
- }
- }
- else
- {
- if (FALSE == GetSaveFileName(&ofn))
- {
- return false;
- }
- }
+ return pszBuffer;
+}
+
+bool show_open_file_dialog(bool bOpen, tstring& rsFile)
+{
+ TCHAR szBuffer[MAX_PATH];
+ TCHAR szFilter[MAX_PATH];
+ OPENFILENAME ofn;
+ memset(&ofn, 0, sizeof(ofn));
+
+ ofn.lStructSize = sizeof(OPENFILENAME);
+
+ ofn.hwndOwner = NULL;
+ ofn.lpstrFilter = prepare_filter(szFilter, MAX_PATH);
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
+ ofn.lpstrDefExt = _T("xml");
+ if (bOpen)
+ ofn.Flags |= OFN_FILEMUSTEXIST;
+ else
+ ofn.Flags |= OFN_OVERWRITEPROMPT;
- rsFile = szBuffer;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.lpstrFile = szBuffer;
+ ofn.lpstrFile[0] = _T('\0');
- return true;
+ if (bOpen) {
+ if (FALSE == GetOpenFileName(&ofn))
+ return false;
+ }
+ else {
+ if (FALSE == GetSaveFileName(&ofn))
+ return false;
}
+
+ rsFile = szBuffer;
+ return true;
}
INT_PTR Quotes_Export(WPARAM wp, LPARAM lp)
{
- // USES_CONVERSION;
-
tstring sFileName;
const char* pszFile = reinterpret_cast<const char*>(lp);
- if (NULL == pszFile)
- {
+ if (NULL == pszFile) {
if (false == show_open_file_dialog(false, sFileName))
- {
return -1;
- }
- }
- else
- {
- sFileName = quotes_a2t(pszFile);//A2CT(pszFile);
}
+ else sFileName = quotes_a2t(pszFile);//A2CT(pszFile);
CModuleInfo::TXMLEnginePtr pXmlEngine = CModuleInfo::GetInstance().GetXMLEnginePtr();
CModuleInfo::TQuotesProvidersPtr pProviders = CModuleInfo::GetInstance().GetQuoteProvidersPtr();
IXMLNode::TXMLNodePtr pRoot = pXmlEngine->CreateNode(g_pszXmlContacts, tstring());
MCONTACT hContact = MCONTACT(wp);
- if (hContact)
- {
+ if (hContact) {
CQuotesProviders::TQuotesProviderPtr pProvider = pProviders->GetContactProviderPtr(hContact);
- if (pProvider)
- {
+ if (pProvider) {
IXMLNode::TXMLNodePtr pNode = export_contact(hContact, pXmlEngine);
if (pNode)
- {
pRoot->AddChild(pNode);
- }
}
}
- else
- {
- for (hContact = db_find_first(QUOTES_MODULE_NAME); hContact; hContact = db_find_next(hContact, QUOTES_MODULE_NAME))
- {
+ else {
+ for (hContact = db_find_first(QUOTES_MODULE_NAME); hContact; hContact = db_find_next(hContact, QUOTES_MODULE_NAME)) {
CQuotesProviders::TQuotesProviderPtr pProvider = pProviders->GetContactProviderPtr(hContact);
- if (pProvider)
- {
+ if (pProvider) {
IXMLNode::TXMLNodePtr pNode = export_contact(hContact, pXmlEngine);
if (pNode)
- {
pRoot->AddChild(pNode);
- }
}
}
}
@@ -303,464 +240,389 @@ INT_PTR Quotes_Export(WPARAM wp, LPARAM lp) return ((true == pXmlEngine->SaveFile(sFileName, pRoot)) ? 0 : 1);
}
-namespace
+bool set_contact_settings(MCONTACT hContact, DBCONTACTWRITESETTING& dbs)
{
- bool set_contact_settings(MCONTACT hContact, DBCONTACTWRITESETTING& dbs)
- {
- assert(DBVT_DELETED != dbs.value.type);
- return (0 == db_set(hContact, dbs.szModule, dbs.szSetting, &dbs.value));
- }
+ assert(DBVT_DELETED != dbs.value.type);
+ return (0 == db_set(hContact, dbs.szModule, dbs.szSetting, &dbs.value));
+}
- bool handle_module(MCONTACT hContact, const IXMLNode::TXMLNodePtr& pXmlModule)
- {
- size_t cCreatedRecords = 0;
- tstring sModuleName = pXmlModule->GetText();
- if (false == sModuleName.empty())
- {
- DBCONTACTWRITESETTING dbs;
- std::string s = quotes_t2a(sModuleName.c_str());
- dbs.szModule = s.c_str();//T2CA(sModuleName.c_str());
-
- bool bCListModule = 0 == quotes_stricmp(sModuleName.c_str(), _T("CList"));
-
- size_t cChild = pXmlModule->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pSetting = pXmlModule->GetChildNode(i);
- tstring sSetting = pSetting->GetName();
- if (0 == quotes_stricmp(g_pszXmlSetting, sSetting.c_str()))
- {
- size_t cSetChild = pSetting->GetChildCount();
- if (cSetChild >= 2)
- {
- tstring sName;
- tstring sValue;
- tstring sType;
- for (size_t j = 0; j < cSetChild; ++j)
- {
- IXMLNode::TXMLNodePtr pNode = pSetting->GetChildNode(j);
- tstring sNode = pNode->GetName();
- if (0 == quotes_stricmp(g_pszXmlName, sNode.c_str()))
- {
- sName = pNode->GetText();
- }
- else if (0 == quotes_stricmp(g_pszXmlValue, sNode.c_str()))
- {
- sValue = pNode->GetText();
- sType = pNode->GetAttributeValue(g_pszXmlType);
- }
+bool handle_module(MCONTACT hContact, const IXMLNode::TXMLNodePtr& pXmlModule)
+{
+ size_t cCreatedRecords = 0;
+ tstring sModuleName = pXmlModule->GetText();
+ if (false == sModuleName.empty()) {
+ DBCONTACTWRITESETTING dbs;
+ std::string s = quotes_t2a(sModuleName.c_str());
+ dbs.szModule = s.c_str();//T2CA(sModuleName.c_str());
+
+ bool bCListModule = 0 == quotes_stricmp(sModuleName.c_str(), _T("CList"));
+
+ size_t cChild = pXmlModule->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pSetting = pXmlModule->GetChildNode(i);
+ tstring sSetting = pSetting->GetName();
+ if (0 == quotes_stricmp(g_pszXmlSetting, sSetting.c_str())) {
+ size_t cSetChild = pSetting->GetChildCount();
+ if (cSetChild >= 2) {
+ tstring sName;
+ tstring sValue;
+ tstring sType;
+ for (size_t j = 0; j < cSetChild; ++j) {
+ IXMLNode::TXMLNodePtr pNode = pSetting->GetChildNode(j);
+ tstring sNode = pNode->GetName();
+ if (0 == quotes_stricmp(g_pszXmlName, sNode.c_str())) {
+ sName = pNode->GetText();
+ }
+ else if (0 == quotes_stricmp(g_pszXmlValue, sNode.c_str())) {
+ sValue = pNode->GetText();
+ sType = pNode->GetAttributeValue(g_pszXmlType);
}
+ }
- if ((false == sName.empty()) && (false == sType.empty()))
- {
- std::string s1 = quotes_t2a(sName.c_str());
- dbs.szSetting = s1.c_str();
- if (0 == quotes_stricmp(g_pszXmlTypeByte, sType.c_str()))
- {
- tistringstream in(sValue.c_str());
- in.imbue(GetSystemLocale());
- dbs.value.cVal = in.get();
- if (in.good() && in.eof())
- {
- dbs.value.type = DBVT_BYTE;
- if (set_contact_settings(hContact, dbs))
- ++cCreatedRecords;
- }
- }
- else if (0 == quotes_stricmp(g_pszXmlTypeWord, sType.c_str()))
- {
- tistringstream in(sValue.c_str());
- in.imbue(GetSystemLocale());
- in >> dbs.value.wVal;
- if (in.good() || in.eof())
- {
- dbs.value.type = DBVT_WORD;
- if (set_contact_settings(hContact, dbs))
- ++cCreatedRecords;
- }
- }
- else if (0 == quotes_stricmp(g_pszXmlTypeDword, sType.c_str()))
- {
- tistringstream in(sValue.c_str());
- in.imbue(GetSystemLocale());
- in >> dbs.value.dVal;
- if (in.good() || in.eof())
- {
- dbs.value.type = DBVT_DWORD;
- if (set_contact_settings(hContact, dbs))
- ++cCreatedRecords;
- }
- }
- else if (0 == quotes_stricmp(g_pszXmlTypeAsciiz, sType.c_str()))
- {
- ptrA v(mir_t2a(sValue.c_str()));
- dbs.value.pszVal = v;
- dbs.value.type = DBVT_ASCIIZ;
+ if ((false == sName.empty()) && (false == sType.empty())) {
+ std::string s1 = quotes_t2a(sName.c_str());
+ dbs.szSetting = s1.c_str();
+ if (0 == quotes_stricmp(g_pszXmlTypeByte, sType.c_str())) {
+ tistringstream in(sValue.c_str());
+ in.imbue(GetSystemLocale());
+ dbs.value.cVal = in.get();
+ if (in.good() && in.eof()) {
+ dbs.value.type = DBVT_BYTE;
if (set_contact_settings(hContact, dbs))
++cCreatedRecords;
}
- else if (0 == quotes_stricmp(g_pszXmlTypeUtf8, sType.c_str()))
- {
- T2Utf szValue(sValue.c_str());
- dbs.value.pszVal = szValue;
- dbs.value.type = DBVT_UTF8;
+ }
+ else if (0 == quotes_stricmp(g_pszXmlTypeWord, sType.c_str())) {
+ tistringstream in(sValue.c_str());
+ in.imbue(GetSystemLocale());
+ in >> dbs.value.wVal;
+ if (in.good() || in.eof()) {
+ dbs.value.type = DBVT_WORD;
if (set_contact_settings(hContact, dbs))
++cCreatedRecords;
}
- else if (0 == quotes_stricmp(g_pszXmlTypeWchar, sType.c_str()))
- {
- ptrW val(mir_t2u(sValue.c_str()));
- dbs.value.pwszVal = val;
- dbs.value.type = DBVT_WCHAR;
+ }
+ else if (0 == quotes_stricmp(g_pszXmlTypeDword, sType.c_str())) {
+ tistringstream in(sValue.c_str());
+ in.imbue(GetSystemLocale());
+ in >> dbs.value.dVal;
+ if (in.good() || in.eof()) {
+ dbs.value.type = DBVT_DWORD;
if (set_contact_settings(hContact, dbs))
++cCreatedRecords;
-
- mir_free(dbs.value.pwszVal);
- }
- else if (0 == quotes_stricmp(g_pszXmlTypeBlob, sType.c_str()))
- {
- unsigned bufLen;
- mir_ptr<BYTE> buf((PBYTE)mir_base64_decode(_T2A(sValue.c_str()), &bufLen));
- if (buf) {
- dbs.value.pbVal = buf;
- dbs.value.cpbVal = (WORD)bufLen;
- dbs.value.type = DBVT_BLOB;
-
- if (set_contact_settings(hContact, dbs))
- ++cCreatedRecords;
- }
}
+ }
+ else if (0 == quotes_stricmp(g_pszXmlTypeAsciiz, sType.c_str())) {
+ ptrA v(mir_t2a(sValue.c_str()));
+ dbs.value.pszVal = v;
+ dbs.value.type = DBVT_ASCIIZ;
+ if (set_contact_settings(hContact, dbs))
+ ++cCreatedRecords;
+ }
+ else if (0 == quotes_stricmp(g_pszXmlTypeUtf8, sType.c_str())) {
+ T2Utf szValue(sValue.c_str());
+ dbs.value.pszVal = szValue;
+ dbs.value.type = DBVT_UTF8;
+ if (set_contact_settings(hContact, dbs))
+ ++cCreatedRecords;
+ }
+ else if (0 == quotes_stricmp(g_pszXmlTypeWchar, sType.c_str())) {
+ ptrW val(mir_t2u(sValue.c_str()));
+ dbs.value.pwszVal = val;
+ dbs.value.type = DBVT_WCHAR;
+ if (set_contact_settings(hContact, dbs))
+ ++cCreatedRecords;
+
+ mir_free(dbs.value.pwszVal);
+ }
+ else if (0 == quotes_stricmp(g_pszXmlTypeBlob, sType.c_str())) {
+ unsigned bufLen;
+ mir_ptr<BYTE> buf((PBYTE)mir_base64_decode(_T2A(sValue.c_str()), &bufLen));
+ if (buf) {
+ dbs.value.pbVal = buf;
+ dbs.value.cpbVal = (WORD)bufLen;
+ dbs.value.type = DBVT_BLOB;
- if ((true == bCListModule) && (0 == quotes_stricmp(sName.c_str(), _T("Group"))))
- CallService(MS_CLIST_GROUPCREATE, NULL, reinterpret_cast<LPARAM>(sValue.c_str()));
+ if (set_contact_settings(hContact, dbs))
+ ++cCreatedRecords;
+ }
}
+
+ if ((true == bCListModule) && (0 == quotes_stricmp(sName.c_str(), _T("Group"))))
+ CallService(MS_CLIST_GROUPCREATE, NULL, reinterpret_cast<LPARAM>(sValue.c_str()));
}
}
}
}
-
- return true;
}
- size_t count_contacts(const IXMLNode::TXMLNodePtr& pXmlRoot, bool bInContactsGroup)
- {
- size_t cContacts = 0;
- size_t cChild = pXmlRoot->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pXmlRoot->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (false == bInContactsGroup)
- {
- if (0 == quotes_stricmp(g_pszXmlContacts, sName.c_str()))
- {
- cContacts += count_contacts(pNode, true);
- }
- else
- {
- cContacts += count_contacts(pNode, false);
- }
- }
+ return true;
+}
+
+size_t count_contacts(const IXMLNode::TXMLNodePtr& pXmlRoot, bool bInContactsGroup)
+{
+ size_t cContacts = 0;
+ size_t cChild = pXmlRoot->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pXmlRoot->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (false == bInContactsGroup) {
+ if (0 == quotes_stricmp(g_pszXmlContacts, sName.c_str()))
+ cContacts += count_contacts(pNode, true);
else
- {
- if (0 == quotes_stricmp(g_pszXmlContact, sName.c_str()))
- {
- ++cContacts;
- }
- }
+ cContacts += count_contacts(pNode, false);
+ }
+ else {
+ if (0 == quotes_stricmp(g_pszXmlContact, sName.c_str()))
+ ++cContacts;
}
-
- return cContacts;
}
- struct CImportContext
- {
- CImportContext(size_t cTotalContacts) : m_cTotalContacts(cTotalContacts), m_cHandledContacts(0), m_nFlags(0){}
+ return cContacts;
+}
- size_t m_cTotalContacts;
- size_t m_cHandledContacts;
- UINT m_nFlags;
- };
+struct CImportContext
+{
+ CImportContext(size_t cTotalContacts) : m_cTotalContacts(cTotalContacts), m_cHandledContacts(0), m_nFlags(0) {}
- struct CContactState
- {
- CContactState() : m_hContact(NULL), m_bNewContact(false){}
- MCONTACT m_hContact;
- CQuotesProviders::TQuotesProviderPtr m_pProvider;
- bool m_bNewContact;
- };
+ size_t m_cTotalContacts;
+ size_t m_cHandledContacts;
+ UINT m_nFlags;
+};
- IXMLNode::TXMLNodePtr find_quotes_module(const IXMLNode::TXMLNodePtr& pXmlContact)
- {
- // USES_CONVERSION;
- // LPCTSTR pszQuotes = A2T(QUOTES_MODULE_NAME);
- static const tstring g_sQuotes = quotes_a2t(QUOTES_MODULE_NAME);
- size_t cChild = pXmlContact->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pXmlContact->GetChildNode(i);
- tstring sName = pNode->GetName();
- if ((0 == quotes_stricmp(g_pszXmlModule, sName.c_str()))
- && (0 == quotes_stricmp(g_sQuotes.c_str(), pNode->GetText().c_str())))
- {
- return pNode;
- }
- }
+struct CContactState
+{
+ CContactState() : m_hContact(NULL), m_bNewContact(false) {}
+ MCONTACT m_hContact;
+ CQuotesProviders::TQuotesProviderPtr m_pProvider;
+ bool m_bNewContact;
+};
- return IXMLNode::TXMLNodePtr();
+IXMLNode::TXMLNodePtr find_quotes_module(const IXMLNode::TXMLNodePtr& pXmlContact)
+{
+ static const tstring g_sQuotes = quotes_a2t(QUOTES_MODULE_NAME);
+ size_t cChild = pXmlContact->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pXmlContact->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if ((0 == quotes_stricmp(g_pszXmlModule, sName.c_str()))
+ && (0 == quotes_stricmp(g_sQuotes.c_str(), pNode->GetText().c_str()))) {
+ return pNode;
+ }
}
- typedef std::pair<tstring, tstring> TNameValue;//first is name,second is value
- TNameValue parse_setting_node(const IXMLNode::TXMLNodePtr& pXmlSetting)
- {
- assert(pXmlSetting);
+ return IXMLNode::TXMLNodePtr();
+}
- tstring sName, sValue;
- size_t cSettingChildItems = pXmlSetting->GetChildCount();
- for (size_t j = 0; j < cSettingChildItems; ++j)
- {
- IXMLNode::TXMLNodePtr pXMLSetChild = pXmlSetting->GetChildNode(j);
- if (pXMLSetChild)
- {
- if (0 == quotes_stricmp(g_pszXmlName, pXMLSetChild->GetName().c_str()))
- {
- sName = pXMLSetChild->GetText();
- }
- else if (0 == quotes_stricmp(g_pszXmlValue, pXMLSetChild->GetName().c_str()))
- {
- sValue = pXMLSetChild->GetText();
- }
+typedef std::pair<tstring, tstring> TNameValue;//first is name,second is value
+TNameValue parse_setting_node(const IXMLNode::TXMLNodePtr& pXmlSetting)
+{
+ assert(pXmlSetting);
+
+ tstring sName, sValue;
+ size_t cSettingChildItems = pXmlSetting->GetChildCount();
+ for (size_t j = 0; j < cSettingChildItems; ++j) {
+ IXMLNode::TXMLNodePtr pXMLSetChild = pXmlSetting->GetChildNode(j);
+ if (pXMLSetChild) {
+ if (0 == quotes_stricmp(g_pszXmlName, pXMLSetChild->GetName().c_str())) {
+ sName = pXMLSetChild->GetText();
+ }
+ else if (0 == quotes_stricmp(g_pszXmlValue, pXMLSetChild->GetName().c_str())) {
+ sValue = pXMLSetChild->GetText();
}
}
+ }
- return std::make_pair(sName, sValue);
+ return std::make_pair(sName, sValue);
+}
+
+CQuotesProviders::TQuotesProviderPtr find_provider(const IXMLNode::TXMLNodePtr& pXmlQuotesModule)
+{
+ // USES_CONVERSION;
+ static const tstring g_sQuotesProvider = quotes_a2t(DB_STR_QUOTE_PROVIDER);//A2CT(DB_STR_QUOTE_PROVIDER);
+ size_t cChild = pXmlQuotesModule->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pXMLSetting = pXmlQuotesModule->GetChildNode(i);
+ if (pXMLSetting && (0 == quotes_stricmp(g_pszXmlSetting, pXMLSetting->GetName().c_str()))) {
+ TNameValue Item = parse_setting_node(pXMLSetting);
+ if ((0 == quotes_stricmp(g_sQuotesProvider.c_str(), Item.first.c_str())) && (false == Item.second.empty())) {
+ return CModuleInfo::GetInstance().GetQuoteProvidersPtr()->FindProvider(Item.second);
+ }
+ }
}
- CQuotesProviders::TQuotesProviderPtr find_provider(const IXMLNode::TXMLNodePtr& pXmlQuotesModule)
+ return CQuotesProviders::TQuotesProviderPtr();
+}
+
+bool get_contact_state(const IXMLNode::TXMLNodePtr& pXmlContact, CContactState& cst)
+{
+ class visitor : public CQuotesProviderVisitor
{
- // USES_CONVERSION;
- static const tstring g_sQuotesProvider = quotes_a2t(DB_STR_QUOTE_PROVIDER);//A2CT(DB_STR_QUOTE_PROVIDER);
- size_t cChild = pXmlQuotesModule->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
+ public:
+ visitor(const IXMLNode::TXMLNodePtr& pXmlQuotes)
+ : m_hContact(NULL), m_pXmlQuotes(pXmlQuotes)
{
- IXMLNode::TXMLNodePtr pXMLSetting = pXmlQuotesModule->GetChildNode(i);
- if (pXMLSetting && (0 == quotes_stricmp(g_pszXmlSetting, pXMLSetting->GetName().c_str())))
- {
- TNameValue Item = parse_setting_node(pXMLSetting);
- if ((0 == quotes_stricmp(g_sQuotesProvider.c_str(), Item.first.c_str())) && (false == Item.second.empty()))
- {
- return CModuleInfo::GetInstance().GetQuoteProvidersPtr()->FindProvider(Item.second);
- }
- }
}
- return CQuotesProviders::TQuotesProviderPtr();
- }
+ MCONTACT GetContact()const { return m_hContact; }
- bool get_contact_state(const IXMLNode::TXMLNodePtr& pXmlContact, CContactState& cst)
- {
- class visitor : public CQuotesProviderVisitor
+ private:
+ virtual void Visit(const CQuotesProviderDukasCopy& rProvider)
{
- public:
- visitor(const IXMLNode::TXMLNodePtr& pXmlQuotes)
- : m_hContact(NULL), m_pXmlQuotes(pXmlQuotes){}
-
- MCONTACT GetContact()const{ return m_hContact; }
-
- private:
- virtual void Visit(const CQuotesProviderDukasCopy& rProvider)
- {
- tstring sQuoteID = GetXMLNodeValue(DB_STR_QUOTE_ID);
- if (false == sQuoteID.empty())
- {
- m_hContact = rProvider.GetContactByQuoteID(sQuoteID);
- }
+ tstring sQuoteID = GetXMLNodeValue(DB_STR_QUOTE_ID);
+ if (false == sQuoteID.empty()) {
+ m_hContact = rProvider.GetContactByQuoteID(sQuoteID);
}
+ }
- virtual void Visit(const CQuotesProviderGoogle& rProvider)
- {
- // 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);
-
- tstring sFromID;
- tstring sToID;
- size_t cChild = m_pXmlQuotes->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = m_pXmlQuotes->GetChildNode(i);
- if (pNode && (0 == quotes_stricmp(g_pszXmlSetting, pNode->GetName().c_str())))
- {
- TNameValue Item = parse_setting_node(pNode);
- if (0 == quotes_stricmp(g_sFromID.c_str(), Item.first.c_str()))
- {
- sFromID = Item.second;
- }
- else if (0 == quotes_stricmp(g_sToID.c_str(), Item.first.c_str()))
- {
- sToID = Item.second;
- }
+ virtual void Visit(const CQuotesProviderGoogle& rProvider)
+ {
+ // 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);
+
+ tstring sFromID;
+ tstring sToID;
+ size_t cChild = m_pXmlQuotes->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = m_pXmlQuotes->GetChildNode(i);
+ if (pNode && (0 == quotes_stricmp(g_pszXmlSetting, pNode->GetName().c_str()))) {
+ TNameValue Item = parse_setting_node(pNode);
+ if (0 == quotes_stricmp(g_sFromID.c_str(), Item.first.c_str())) {
+ sFromID = Item.second;
+ }
+ else if (0 == quotes_stricmp(g_sToID.c_str(), Item.first.c_str())) {
+ sToID = Item.second;
}
}
+ }
- if ((false == sFromID.empty()) && (false == sToID.empty()))
- {
- m_hContact = rProvider.GetContactByID(sFromID, sToID);
- }
+ if ((false == sFromID.empty()) && (false == sToID.empty())) {
+ m_hContact = rProvider.GetContactByID(sFromID, sToID);
}
+ }
- virtual void Visit(const CQuotesProviderFinance& rProvider)
- {
- tstring sQuoteID = GetXMLNodeValue(DB_STR_QUOTE_ID);
- if (false == sQuoteID.empty())
- {
- m_hContact = rProvider.GetContactByQuoteID(sQuoteID);
- }
+ virtual void Visit(const CQuotesProviderFinance& rProvider)
+ {
+ tstring sQuoteID = GetXMLNodeValue(DB_STR_QUOTE_ID);
+ if (false == sQuoteID.empty()) {
+ m_hContact = rProvider.GetContactByQuoteID(sQuoteID);
}
+ }
- tstring GetXMLNodeValue(const char* pszXMLNodeName)const
- {
- // USES_CONVERSION;
- tstring sXMLNodeName = quotes_a2t(pszXMLNodeName);//A2CT(pszXMLNodeName);
-
- tstring sValue;
- size_t cChild = m_pXmlQuotes->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = m_pXmlQuotes->GetChildNode(i);
- if (pNode && (0 == quotes_stricmp(g_pszXmlSetting, pNode->GetName().c_str())))
- {
- TNameValue Item = parse_setting_node(pNode);
- if (0 == quotes_stricmp(Item.first.c_str(), sXMLNodeName.c_str()))
- {
- sValue = Item.second;
- break;
- }
+ tstring GetXMLNodeValue(const char* pszXMLNodeName)const
+ {
+ tstring sXMLNodeName = quotes_a2t(pszXMLNodeName);
+
+ tstring sValue;
+ size_t cChild = m_pXmlQuotes->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = m_pXmlQuotes->GetChildNode(i);
+ if (pNode && (0 == quotes_stricmp(g_pszXmlSetting, pNode->GetName().c_str()))) {
+ TNameValue Item = parse_setting_node(pNode);
+ if (0 == quotes_stricmp(Item.first.c_str(), sXMLNodeName.c_str())) {
+ sValue = Item.second;
+ break;
}
}
-
- return sValue;
}
- private:
- MCONTACT m_hContact;
- IXMLNode::TXMLNodePtr m_pXmlQuotes;
- };
-
- IXMLNode::TXMLNodePtr pXmlQuotes = find_quotes_module(pXmlContact);
- if (pXmlQuotes)
- {
- cst.m_pProvider = find_provider(pXmlQuotes);
- if (cst.m_pProvider)
- {
- visitor vs(pXmlQuotes);
- cst.m_pProvider->Accept(vs);
- cst.m_hContact = vs.GetContact();
- return true;
- }
+ return sValue;
}
- return false;
+ private:
+ MCONTACT m_hContact;
+ IXMLNode::TXMLNodePtr m_pXmlQuotes;
+ };
+
+ IXMLNode::TXMLNodePtr pXmlQuotes = find_quotes_module(pXmlContact);
+ if (pXmlQuotes) {
+ cst.m_pProvider = find_provider(pXmlQuotes);
+ if (cst.m_pProvider) {
+ visitor vs(pXmlQuotes);
+ cst.m_pProvider->Accept(vs);
+ cst.m_hContact = vs.GetContact();
+ return true;
+ }
}
- bool import_contact(const IXMLNode::TXMLNodePtr& pXmlContact, CImportContext& impctx)
- {
- ++impctx.m_cHandledContacts;
+ return false;
+}
- CContactState cst;
- bool bResult = get_contact_state(pXmlContact, cst);
- if (bResult)
- {
- if (NULL == cst.m_hContact)
- {
- cst.m_hContact = MCONTACT(CallService(MS_DB_CONTACT_ADD, 0, 0));
- cst.m_bNewContact = true;
- }
- else if (impctx.m_nFlags"ES_IMPORT_SKIP_EXISTING_CONTACTS)
- {
- return true;
+bool import_contact(const IXMLNode::TXMLNodePtr& pXmlContact, CImportContext& impctx)
+{
+ ++impctx.m_cHandledContacts;
+
+ CContactState cst;
+ bool bResult = get_contact_state(pXmlContact, cst);
+ if (bResult) {
+ if (NULL == cst.m_hContact) {
+ cst.m_hContact = MCONTACT(CallService(MS_DB_CONTACT_ADD, 0, 0));
+ cst.m_bNewContact = true;
+ }
+ else if (impctx.m_nFlags & QUOTES_IMPORT_SKIP_EXISTING_CONTACTS)
+ return true;
+
+ if (cst.m_hContact) {
+ size_t cChild = pXmlContact->GetChildCount();
+ for (size_t i = 0; i < cChild && bResult; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pXmlContact->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (0 == quotes_stricmp(g_pszXmlModule, sName.c_str()))
+ bResult &= handle_module(cst.m_hContact, pNode);
}
- if (cst.m_hContact)
- {
- size_t cChild = pXmlContact->GetChildCount();
- for (size_t i = 0; i < cChild && bResult; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pXmlContact->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (0 == quotes_stricmp(g_pszXmlModule, sName.c_str()))
- {
- bResult &= handle_module(cst.m_hContact, pNode);
- }
- }
-
- if (cst.m_bNewContact && bResult)
- {
- cst.m_pProvider->AddContact(cst.m_hContact);
- cst.m_pProvider->RefreshContact(cst.m_hContact);
- }
- }
- else
- {
- bResult = false;
+ if (cst.m_bNewContact && bResult) {
+ cst.m_pProvider->AddContact(cst.m_hContact);
+ cst.m_pProvider->RefreshContact(cst.m_hContact);
}
}
+ else bResult = false;
+ }
- return bResult;
+ return bResult;
+}
+size_t import_contacts(const IXMLNode::TXMLNodePtr& pXmlContacts, CImportContext& impctx)
+{
+ size_t cContacts = 0;
+ size_t cChild = pXmlContacts->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pXmlContacts->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (0 == quotes_stricmp(g_pszXmlContact, sName.c_str()))
+ if (true == import_contact(pNode, impctx))
+ ++cContacts;
}
- size_t import_contacts(const IXMLNode::TXMLNodePtr& pXmlContacts, CImportContext& impctx)
- {
- size_t cContacts = 0;
- size_t cChild = pXmlContacts->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pXmlContacts->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (0 == quotes_stricmp(g_pszXmlContact, sName.c_str()))
- {
- if (true == import_contact(pNode, impctx))
- {
- ++cContacts;
- }
- }
- }
+ return cContacts;
- return cContacts;
+}
+size_t handle_contacts_node(const IXMLNode::TXMLNodePtr& pXmlRoot, CImportContext& impctx)
+{
+ size_t cContacts = 0;
+ size_t cChild = pXmlRoot->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pXmlRoot->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (0 == quotes_stricmp(g_pszXmlContacts, sName.c_str()))
+ cContacts += import_contacts(pNode, impctx);
+ else
+ cContacts += handle_contacts_node(pNode, impctx);
}
- size_t handle_contacts_node(const IXMLNode::TXMLNodePtr& pXmlRoot, CImportContext& impctx)
- {
- size_t cContacts = 0;
- size_t cChild = pXmlRoot->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pXmlRoot->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (0 == quotes_stricmp(g_pszXmlContacts, sName.c_str()))
- {
- cContacts += import_contacts(pNode, impctx);
- }
- else
- {
- cContacts += handle_contacts_node(pNode, impctx);
- }
- }
-
- return cContacts;
+ return cContacts;
- }
+}
- bool do_import(const IXMLNode::TXMLNodePtr& pXmlRoot, UINT nFlags)
- {
- CImportContext imctx(count_contacts(pXmlRoot, false));
- imctx.m_cHandledContacts = 0;
- imctx.m_nFlags = nFlags;
+bool do_import(const IXMLNode::TXMLNodePtr& pXmlRoot, UINT nFlags)
+{
+ CImportContext imctx(count_contacts(pXmlRoot, false));
+ imctx.m_cHandledContacts = 0;
+ imctx.m_nFlags = nFlags;
- return (handle_contacts_node(pXmlRoot, imctx) > 0);
- }
+ return (handle_contacts_node(pXmlRoot, imctx) > 0);
}
INT_PTR Quotes_Import(WPARAM wp, LPARAM lp)
@@ -769,23 +631,16 @@ INT_PTR Quotes_Import(WPARAM wp, LPARAM lp) tstring sFileName;
const char* pszFile = reinterpret_cast<const char*>(lp);
- if (NULL == pszFile)
- {
+ if (NULL == pszFile) {
if (false == show_open_file_dialog(true, sFileName))
- {
return -1;
- }
- }
- else
- {
- sFileName = quotes_a2t(pszFile);//A2CT(pszFile);
}
+ else sFileName = quotes_a2t(pszFile);//A2CT(pszFile);
+
CModuleInfo::TXMLEnginePtr pXmlEngine = CModuleInfo::GetInstance().GetXMLEnginePtr();
IXMLNode::TXMLNodePtr pXmlRoot = pXmlEngine->LoadFile(sFileName);
if (pXmlRoot)
- {
return ((true == do_import(pXmlRoot, wp)) ? 0 : 1);
- }
return 1;
}
diff --git a/plugins/Quotes/src/Locale.cpp b/plugins/Quotes/src/Locale.cpp index fe1427dac7..4e72558cff 100644 --- a/plugins/Quotes/src/Locale.cpp +++ b/plugins/Quotes/src/Locale.cpp @@ -5,70 +5,55 @@ const std::locale GetSystemLocale() return std::locale("");
}
-namespace
+tstring get_int_registry_value(LPCTSTR pszValueName)
{
- tstring get_int_registry_value(LPCTSTR pszValueName)
- {
- tstring sResult;
- HKEY hKey = NULL;
- LONG lResult = ::RegOpenKeyEx(HKEY_CURRENT_USER,
- _T("Control Panel\\International"), 0, KEY_QUERY_VALUE, &hKey);
- if ((ERROR_SUCCESS == lResult) && (NULL != hKey))
- {
- DWORD dwType = 0;
- DWORD dwSize = 0;
- lResult = ::RegQueryValueEx(hKey, pszValueName, nullptr, &dwType, nullptr, &dwSize);
- if ((ERROR_SUCCESS == lResult) && ((REG_SZ == dwType) || (REG_EXPAND_SZ == dwType)))
- {
- std::vector<TCHAR> aBuffer(dwSize);
- lResult = ::RegQueryValueEx(hKey, pszValueName, nullptr, nullptr, reinterpret_cast<LPBYTE>(&*aBuffer.begin()), &dwSize);
- if (ERROR_SUCCESS == lResult)
- {
- std::copy(aBuffer.begin(), aBuffer.end(), std::back_inserter(sResult));
- }
- }
+ tstring sResult;
+ HKEY hKey = NULL;
+ LONG lResult = ::RegOpenKeyEx(HKEY_CURRENT_USER,
+ _T("Control Panel\\International"), 0, KEY_QUERY_VALUE, &hKey);
+ if ((ERROR_SUCCESS == lResult) && (NULL != hKey)) {
+ DWORD dwType = 0;
+ DWORD dwSize = 0;
+ lResult = ::RegQueryValueEx(hKey, pszValueName, nullptr, &dwType, nullptr, &dwSize);
+ if ((ERROR_SUCCESS == lResult) && ((REG_SZ == dwType) || (REG_EXPAND_SZ == dwType))) {
+ std::vector<TCHAR> aBuffer(dwSize);
+ lResult = ::RegQueryValueEx(hKey, pszValueName, nullptr, nullptr, reinterpret_cast<LPBYTE>(&*aBuffer.begin()), &dwSize);
+ if (ERROR_SUCCESS == lResult)
+ std::copy(aBuffer.begin(), aBuffer.end(), std::back_inserter(sResult));
}
-
- if (NULL != hKey)
- {
- lResult = ::RegCloseKey(hKey);
- assert(ERROR_SUCCESS == lResult);
- }
-
- return sResult;
}
- tstring date_win_2_boost(const tstring& sFrmt)
- {
- tstring sResult(_T("%d.%m.%y"));
- if (sFrmt == _T("dd/MM/yy"))
- {
- sResult = _T("%d/%m/%y");
- }
- else if (sFrmt == _T("yyyy-MM-dd"))
- {
- sResult = _T("%y-%m-%d");
- }
- return sResult;
+ if (NULL != hKey) {
+ lResult = ::RegCloseKey(hKey);
+ assert(ERROR_SUCCESS == lResult);
}
- tstring time_win_2_boost(const tstring& sFrmt)
- {
- tstring sResult = _T("%H:%M:%S");
- if (sFrmt == _T("H:mm") || sFrmt == _T("HH:mm"))
- {
- sResult = _T("%H:%M");
- }
- return sResult;
- }
+ return sResult;
}
-tstring Quotes_GetDateFormat(bool bShort)
+LPCTSTR date_win_2_boost(const tstring& sFrmt)
+{
+ if (sFrmt == _T("dd/MM/yy"))
+ return _T("%d/%m/%y");
+ if (sFrmt == _T("yyyy-MM-dd"))
+ return _T("%y-%m-%d");
+ return _T("%d.%m.%y");
+}
+
+LPCTSTR time_win_2_boost(const tstring& sFrmt)
+{
+ if (sFrmt == _T("H:mm") || sFrmt == _T("HH:mm"))
+ return _T("%H:%M");
+
+ return _T("%H:%M:%S");
+}
+
+LPCTSTR Quotes_GetDateFormat(bool bShort)
{
return date_win_2_boost(get_int_registry_value(bShort ? _T("sShortDate") : _T("sLongDate")));
}
-tstring Quotes_GetTimeFormat(bool bShort)
+LPCTSTR Quotes_GetTimeFormat(bool bShort)
{
return time_win_2_boost(get_int_registry_value(bShort ? _T("sShortTime") : _T("sTimeFormat")));
-}
\ No newline at end of file +}
diff --git a/plugins/Quotes/src/Locale.h b/plugins/Quotes/src/Locale.h index 92d3a56ed4..05288c146f 100644 --- a/plugins/Quotes/src/Locale.h +++ b/plugins/Quotes/src/Locale.h @@ -3,7 +3,7 @@ // std::string GetLocaleInfoString(LCTYPE LCType,LCID Locale = LOCALE_USER_DEFAULT);
const std::locale GetSystemLocale();
-tstring Quotes_GetDateFormat(bool bShort);
-tstring Quotes_GetTimeFormat(bool bShort);
+LPCTSTR Quotes_GetDateFormat(bool bShort);
+LPCTSTR Quotes_GetTimeFormat(bool bShort);
#endif //__11f7afd0_5a66_4029_8bf3_e3c66346b349_Locale_h_
diff --git a/plugins/Quotes/src/Log.cpp b/plugins/Quotes/src/Log.cpp index a9ffb93389..fea13ef91b 100644 --- a/plugins/Quotes/src/Log.cpp +++ b/plugins/Quotes/src/Log.cpp @@ -25,19 +25,8 @@ namespace if (file.good())
{
TCHAR szTime[20];
- // TCHAR sz[10000+1];
_tstrtime_s(szTime);
file << szTime << _T(" ================================>\n") << rsMsg << _T("\n\n");
-
- // size_t cBytes = rsMsg.size();
- // const TCHAR* p = rsMsg.c_str();
- // for(size_t c = 0;c < cBytes;c += 10000,p+=10000)
- // {
- // _tcsncpy_s(sz,p,10000);
- // file << sz;
- // }
- //
- // file << "\n\n";
}
}
}
diff --git a/plugins/Quotes/src/ModuleInfo.cpp b/plugins/Quotes/src/ModuleInfo.cpp index 2b137a6258..ffdc8542a7 100644 --- a/plugins/Quotes/src/ModuleInfo.cpp +++ b/plugins/Quotes/src/ModuleInfo.cpp @@ -1,11 +1,8 @@ #include "StdAfx.h"
-namespace
-{
- CModuleInfo::TXMLEnginePtr g_pXMLEngine;
- CModuleInfo::THTMLEnginePtr g_pHTMLEngine;
- mir_cs g_lmParsers;
-}
+static CModuleInfo::TXMLEnginePtr g_pXMLEngine;
+static CModuleInfo::THTMLEnginePtr g_pHTMLEngine;
+static mir_cs g_lmParsers;
CModuleInfo::CModuleInfo()
: m_bExtendedStatusInfo(1 == db_get_b(NULL, QUOTES_MODULE_NAME, "ExtendedStatus", false))
@@ -26,12 +23,10 @@ MWindowList CModuleInfo::GetWindowList(const std::string& rsKey, bool bAllocateI {
MWindowList hResult = NULL;
THandles::const_iterator i = m_ahWindowLists.find(rsKey);
- if (i != m_ahWindowLists.end())
- {
+ if (i != m_ahWindowLists.end()) {
hResult = i->second;
}
- else if (bAllocateIfNonExist)
- {
+ else if (bAllocateIfNonExist) {
hResult = WindowList_Create();
if (hResult)
m_ahWindowLists.insert(std::make_pair(rsKey, hResult));
@@ -56,8 +51,7 @@ CModuleInfo::TQuotesProvidersPtr CModuleInfo::GetQuoteProvidersPtr() CModuleInfo::TXMLEnginePtr CModuleInfo::GetXMLEnginePtr()
{
- if (!g_pXMLEngine)
- {
+ if (!g_pXMLEngine) {
mir_cslock lck(g_lmParsers);
if (!g_pXMLEngine)
g_pXMLEngine = TXMLEnginePtr(new CXMLEngineMI);
@@ -66,20 +60,12 @@ CModuleInfo::TXMLEnginePtr CModuleInfo::GetXMLEnginePtr() return g_pXMLEngine;
}
-// void CModuleInfo::SetXMLEnginePtr(TXMLEnginePtr pEngine)
-// {
-// g_pXMLEngine = pEngine;
-// }
-
CModuleInfo::THTMLEnginePtr CModuleInfo::GetHTMLEngine()
{
- if (!g_pHTMLEngine)
- {
+ if (!g_pHTMLEngine) {
mir_cslock lck(g_lmParsers);
if (!g_pHTMLEngine)
- {
g_pHTMLEngine = THTMLEnginePtr(new CHTMLEngineMS);
- }
}
return g_pHTMLEngine;
@@ -96,18 +82,14 @@ bool CModuleInfo::Verify() icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES | ICC_LINK_CLASS;
if (FALSE == ::InitCommonControlsEx(&icc))
- {
return false;
- }
- if (!GetXMLEnginePtr())
- {
+ if (!GetXMLEnginePtr()) {
Quotes_MessageBox(NULL, TranslateT("Miranda could not load Quotes plugin. XML parser is missing."), MB_OK | MB_ICONERROR);
return false;
}
- if (!g_pHTMLEngine && (false == CHTMLParserMS::IsInstalled()))
- {
+ if (!g_pHTMLEngine && (false == CHTMLParserMS::IsInstalled())) {
Quotes_MessageBox(NULL,
TranslateT("Miranda could not load Quotes plugin. Microsoft HTML parser is missing."),
MB_YESNO | MB_ICONQUESTION);
diff --git a/plugins/Quotes/src/OptionDukasCopy.cpp b/plugins/Quotes/src/OptionDukasCopy.cpp index 6ded86da76..f5506cada2 100644 --- a/plugins/Quotes/src/OptionDukasCopy.cpp +++ b/plugins/Quotes/src/OptionDukasCopy.cpp @@ -1,326 +1,266 @@ #include "StdAfx.h"
-namespace
+enum ETreeCheckBoxState
{
- enum ETreeCheckBoxState
- {
- // tree check box state
- TCBS_NOSTATEBOX = 0,
- TCBS_UNCHECKED = 1,
- TCBS_CHECKED = 2,
- };
-
- enum
- {
- TREE_VIEW_CHECK_STATE_CHANGE = WM_USER + 100,
- IMAGE_INDEX_SECTION = 0,
- IMAGE_INDEX_QUOTE = 1
- };
-
- // typedef CQuotesProviders::TQuotesProviders TQuotesProviders;
- // typedef CQuotesProviders::TQuotesProviderPtr TQuotesProviderPtr;
-
- HTREEITEM tree_insert_item(HWND hwndTree,
- const tstring& rsName,
- HTREEITEM htiParent,
- int nImage,
- LPARAM lp = 0)
- {
- // USES_CONVERSION;
- TVINSERTSTRUCT tvi;
- memset(&tvi, 0, sizeof(tvi));
-
- tvi.hParent = htiParent;
- tvi.hInsertAfter = TVI_LAST;
- tvi.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
+ // tree check box state
+ TCBS_NOSTATEBOX = 0,
+ TCBS_UNCHECKED = 1,
+ TCBS_CHECKED = 2,
+};
- // CA2T name(rsName.c_str());
-
- tvi.item.pszText = const_cast<LPTSTR>(rsName.c_str());//name;
- tvi.item.lParam = lp;
- tvi.item.iImage = nImage;
- tvi.item.iSelectedImage = nImage;
- return TreeView_InsertItem(hwndTree, &tvi);
- }
-
- bool add_quote_to_tree(const CQuotesProviderDukasCopy::CQuote& q, HWND hwndTree, HTREEITEM htiParent, const CQuotesProviderDukasCopy* pQuotesProvier)
- {
- bool bChecked = pQuotesProvier->IsQuoteWatched(q);
- HTREEITEM hti = tree_insert_item(hwndTree, ((false == q.GetName().empty()) ? q.GetName() : q.GetSymbol()), htiParent, IMAGE_INDEX_QUOTE);
- if (hti && bChecked)
- {
- HWND hDlg = ::GetParent(hwndTree);
- assert(::IsWindow(hDlg));
- ::PostMessage(hDlg, TREE_VIEW_CHECK_STATE_CHANGE, MAKEWPARAM(0, TCBS_CHECKED), reinterpret_cast<LPARAM>(hti));
- }
+enum
+{
+ TREE_VIEW_CHECK_STATE_CHANGE = WM_USER + 100,
+ IMAGE_INDEX_SECTION = 0,
+ IMAGE_INDEX_QUOTE = 1
+};
+
+HTREEITEM tree_insert_item(HWND hwndTree,
+ const tstring& rsName,
+ HTREEITEM htiParent,
+ int nImage,
+ LPARAM lp = 0)
+{
+ TVINSERTSTRUCT tvi = {};
+ tvi.hParent = htiParent;
+ tvi.hInsertAfter = TVI_LAST;
+ tvi.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
+ tvi.item.pszText = const_cast<LPTSTR>(rsName.c_str());//name;
+ tvi.item.lParam = lp;
+ tvi.item.iImage = nImage;
+ tvi.item.iSelectedImage = nImage;
+ return TreeView_InsertItem(hwndTree, &tvi);
+}
- return (NULL != hti && bChecked);
+bool add_quote_to_tree(const CQuotesProviderDukasCopy::CQuote& q, HWND hwndTree, HTREEITEM htiParent, const CQuotesProviderDukasCopy* pQuotesProvier)
+{
+ bool bChecked = pQuotesProvier->IsQuoteWatched(q);
+ HTREEITEM hti = tree_insert_item(hwndTree, ((false == q.GetName().empty()) ? q.GetName() : q.GetSymbol()), htiParent, IMAGE_INDEX_QUOTE);
+ if (hti && bChecked) {
+ HWND hDlg = ::GetParent(hwndTree);
+ assert(::IsWindow(hDlg));
+ ::PostMessage(hDlg, TREE_VIEW_CHECK_STATE_CHANGE, MAKEWPARAM(0, TCBS_CHECKED), reinterpret_cast<LPARAM>(hti));
}
- void add_section_to_tree(const CQuotesProviderDukasCopy::CQuoteSection& qs,
- HWND hwndTree,
- HTREEITEM htiParent,
- const CQuotesProviderDukasCopy* pQuotesProvier,
- bool& rbIsChecked,
- bool& rbIsExpended,
- bool bExpand = false)
- {
- rbIsChecked = false;
- rbIsExpended = false;
- HTREEITEM hti = tree_insert_item(hwndTree, qs.GetName(), htiParent, IMAGE_INDEX_SECTION);
-
- size_t cCheckedItems = 0;
- size_t cSection = qs.GetSectionCount();
- for (size_t i = 0; i < cSection; ++i)
- {
- bool bIsChecked = false;
- bool bIsExpanded = false;
- CQuotesProviderDukasCopy::CQuoteSection other = qs.GetSection(i);
- add_section_to_tree(other, hwndTree, hti, pQuotesProvier, bIsChecked, bIsExpanded);
-
- if (bIsChecked)
- {
- ++cCheckedItems;
- }
-
- if (bIsExpanded)
- {
- bExpand = true;
- }
- }
-
- size_t cQuotes = qs.GetQuoteCount();
- for (size_t i = 0; i < cQuotes; ++i)
- {
- CQuotesProviderDukasCopy::CQuote q = qs.GetQuote(i);
- if (true == add_quote_to_tree(q, hwndTree, hti, pQuotesProvier))
- {
- ++cCheckedItems;
- }
- }
-
- if (bExpand || cCheckedItems > 0)
- {
- rbIsExpended = true;
- TreeView_Expand(hwndTree, hti, TVE_EXPAND);
- }
+ return (NULL != hti && bChecked);
+}
- if (cCheckedItems == (cSection + cQuotes))
- {
- rbIsChecked = true;
- HWND hDlg = ::GetParent(hwndTree);
- assert(::IsWindow(hDlg));
- ::PostMessage(hDlg, TREE_VIEW_CHECK_STATE_CHANGE, MAKEWPARAM(0, TCBS_CHECKED), reinterpret_cast<LPARAM>(hti));
- }
- }
+void add_section_to_tree(const CQuotesProviderDukasCopy::CQuoteSection& qs,
+ HWND hwndTree,
+ HTREEITEM htiParent,
+ const CQuotesProviderDukasCopy* pQuotesProvier,
+ bool& rbIsChecked,
+ bool& rbIsExpended,
+ bool bExpand = false)
+{
+ rbIsChecked = false;
+ rbIsExpended = false;
+ HTREEITEM hti = tree_insert_item(hwndTree, qs.GetName(), htiParent, IMAGE_INDEX_SECTION);
- void add_provider_to_tree(const CQuotesProviderDukasCopy* pQuotesProvier, HWND hwndTree)
- {
- CQuotesProviderDukasCopy::CQuoteSection qs = pQuotesProvier->GetQuotes();
+ size_t cCheckedItems = 0;
+ size_t cSection = qs.GetSectionCount();
+ for (size_t i = 0; i < cSection; ++i) {
bool bIsChecked = false;
bool bIsExpanded = false;
- add_section_to_tree(qs, hwndTree, TVI_ROOT, pQuotesProvier, bIsChecked, bIsExpanded, true);
+ CQuotesProviderDukasCopy::CQuoteSection other = qs.GetSection(i);
+ add_section_to_tree(other, hwndTree, hti, pQuotesProvier, bIsChecked, bIsExpanded);
+
+ if (bIsChecked)
+ ++cCheckedItems;
+
+ if (bIsExpanded)
+ bExpand = true;
}
- inline HTREEITEM tree_get_child_item(HWND hwndTree, HTREEITEM hti)
- {
- return reinterpret_cast<HTREEITEM>(::SendMessage(hwndTree, TVM_GETNEXTITEM, TVGN_CHILD, reinterpret_cast<LPARAM>(hti)));
+ size_t cQuotes = qs.GetQuoteCount();
+ for (size_t i = 0; i < cQuotes; ++i) {
+ CQuotesProviderDukasCopy::CQuote q = qs.GetQuote(i);
+ if (true == add_quote_to_tree(q, hwndTree, hti, pQuotesProvier))
+ ++cCheckedItems;
}
- inline HTREEITEM tree_get_next_sibling_item(HWND hwndTree, HTREEITEM hti)
- {
- return reinterpret_cast<HTREEITEM>(::SendMessage(hwndTree, TVM_GETNEXTITEM, TVGN_NEXT, reinterpret_cast<LPARAM>(hti)));
+ if (bExpand || cCheckedItems > 0) {
+ rbIsExpended = true;
+ TreeView_Expand(hwndTree, hti, TVE_EXPAND);
}
- inline ETreeCheckBoxState tree_get_state_image(HWND hwndTree, HTREEITEM hti)
- {
- TVITEM tvi;
- tvi.hItem = hti;
- tvi.mask = TVIF_STATE | TVIF_HANDLE;
- tvi.stateMask = TVIS_STATEIMAGEMASK;
- if (TRUE == ::SendMessage(hwndTree, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvi)))
- {
- UINT nState = (tvi.state >> 12);
- return static_cast<ETreeCheckBoxState>(nState);
- }
- else
- {
- return TCBS_UNCHECKED;
- }
+ if (cCheckedItems == (cSection + cQuotes)) {
+ rbIsChecked = true;
+ HWND hDlg = ::GetParent(hwndTree);
+ assert(::IsWindow(hDlg));
+ ::PostMessage(hDlg, TREE_VIEW_CHECK_STATE_CHANGE, MAKEWPARAM(0, TCBS_CHECKED), reinterpret_cast<LPARAM>(hti));
}
+}
- void tree_do_set_item_state(HWND hwndTree, HTREEITEM hti, ETreeCheckBoxState nState)
- {
- TVITEM tvi;
- memset(&tvi, 0, sizeof(tvi));
+void add_provider_to_tree(const CQuotesProviderDukasCopy* pQuotesProvier, HWND hwndTree)
+{
+ CQuotesProviderDukasCopy::CQuoteSection qs = pQuotesProvier->GetQuotes();
+ bool bIsChecked = false;
+ bool bIsExpanded = false;
+ add_section_to_tree(qs, hwndTree, TVI_ROOT, pQuotesProvier, bIsChecked, bIsExpanded, true);
+}
- tvi.mask = TVIF_STATE | TVIF_HANDLE;
- tvi.hItem = hti;
+inline HTREEITEM tree_get_child_item(HWND hwndTree, HTREEITEM hti)
+{
+ return reinterpret_cast<HTREEITEM>(::SendMessage(hwndTree, TVM_GETNEXTITEM, TVGN_CHILD, reinterpret_cast<LPARAM>(hti)));
+}
- tvi.stateMask = TVIS_STATEIMAGEMASK;
- tvi.state = INDEXTOSTATEIMAGEMASK(nState);
+inline HTREEITEM tree_get_next_sibling_item(HWND hwndTree, HTREEITEM hti)
+{
+ return reinterpret_cast<HTREEITEM>(::SendMessage(hwndTree, TVM_GETNEXTITEM, TVGN_NEXT, reinterpret_cast<LPARAM>(hti)));
+}
- ::SendMessage(hwndTree, TVM_SETITEM, 0, reinterpret_cast<LPARAM>(&tvi));
+inline ETreeCheckBoxState tree_get_state_image(HWND hwndTree, HTREEITEM hti)
+{
+ TVITEM tvi;
+ tvi.hItem = hti;
+ tvi.mask = TVIF_STATE | TVIF_HANDLE;
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+ if (TRUE == ::SendMessage(hwndTree, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvi))) {
+ UINT nState = (tvi.state >> 12);
+ return static_cast<ETreeCheckBoxState>(nState);
}
- void tree_set_item_state(HWND hwndTree, HTREEITEM hti, ETreeCheckBoxState nState, bool bRecursively)
- {
- if (true == bRecursively)
- {
- for (hti = tree_get_child_item(hwndTree, hti); hti; hti = tree_get_next_sibling_item(hwndTree, hti))
- {
- tree_do_set_item_state(hwndTree, hti, nState);
- tree_set_item_state(hwndTree, hti, nState, bRecursively);
- }
- }
- else
- {
+ return TCBS_UNCHECKED;
+}
+
+void tree_do_set_item_state(HWND hwndTree, HTREEITEM hti, ETreeCheckBoxState nState)
+{
+ TVITEM tvi = {};
+ tvi.mask = TVIF_STATE | TVIF_HANDLE;
+ tvi.hItem = hti;
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+ tvi.state = INDEXTOSTATEIMAGEMASK(nState);
+ ::SendMessage(hwndTree, TVM_SETITEM, 0, reinterpret_cast<LPARAM>(&tvi));
+}
+
+void tree_set_item_state(HWND hwndTree, HTREEITEM hti, ETreeCheckBoxState nState, bool bRecursively)
+{
+ if (true == bRecursively) {
+ for (hti = tree_get_child_item(hwndTree, hti); hti; hti = tree_get_next_sibling_item(hwndTree, hti)) {
tree_do_set_item_state(hwndTree, hti, nState);
+ tree_set_item_state(hwndTree, hti, nState, bRecursively);
}
}
+ else tree_do_set_item_state(hwndTree, hti, nState);
+}
- void save_quote_selection(HWND hwndTree, HTREEITEM h, const CQuotesProviderDukasCopy::CQuote& q, CQuotesProviderDukasCopy* pQuotesProvier)
- {
- ETreeCheckBoxState nState = tree_get_state_image(hwndTree, h);
- pQuotesProvier->WatchForQuote(q, (TCBS_CHECKED == nState));
- }
-
- void recursive_save_quote_section_selection(HWND hwndTree, HTREEITEM h, const CQuotesProviderDukasCopy::CQuoteSection& qs, CQuotesProviderDukasCopy* pQuotesProvier)
- {
- size_t cSection = qs.GetSectionCount();
- h = tree_get_child_item(hwndTree, h);
- for (size_t i = 0; h && (i < cSection); ++i, h = tree_get_next_sibling_item(hwndTree, h))
- {
- CQuotesProviderDukasCopy::CQuoteSection other = qs.GetSection(i);
- recursive_save_quote_section_selection(hwndTree, h, other, pQuotesProvier);
- }
+void save_quote_selection(HWND hwndTree, HTREEITEM h, const CQuotesProviderDukasCopy::CQuote& q, CQuotesProviderDukasCopy* pQuotesProvier)
+{
+ ETreeCheckBoxState nState = tree_get_state_image(hwndTree, h);
+ pQuotesProvier->WatchForQuote(q, (TCBS_CHECKED == nState));
+}
- size_t cQuotes = qs.GetQuoteCount();
- for (size_t i = 0; h && (i < cQuotes); ++i, h = tree_get_next_sibling_item(hwndTree, h))
- {
- CQuotesProviderDukasCopy::CQuote q = qs.GetQuote(i);
- save_quote_selection(hwndTree, h, q, pQuotesProvier);
- }
+void recursive_save_quote_section_selection(HWND hwndTree, HTREEITEM h, const CQuotesProviderDukasCopy::CQuoteSection& qs, CQuotesProviderDukasCopy* pQuotesProvier)
+{
+ size_t cSection = qs.GetSectionCount();
+ h = tree_get_child_item(hwndTree, h);
+ for (size_t i = 0; h && (i < cSection); ++i, h = tree_get_next_sibling_item(hwndTree, h)) {
+ CQuotesProviderDukasCopy::CQuoteSection other = qs.GetSection(i);
+ recursive_save_quote_section_selection(hwndTree, h, other, pQuotesProvier);
}
- void recursive_save_selection(HWND hwndTree, CQuotesProviderDukasCopy* pQuotesProvider)
- {
- // CModuleInfo::TQuotesProvidersPtr& pProviders = CModuleInfo::GetQuoteProvidersPtr();
- // const TQuotesProviders& rapQuotesProviders = pProviders->GetProviders();
- //
- // TQuotesProviders::const_iterator i = rapQuotesProviders.begin();
- // TQuotesProviders::const_iterator iE = rapQuotesProviders.end();
- // for(HTREEITEM h = tree_get_child_item(hwndTree,TVI_ROOT);h && (i!=iE);++i,h = tree_get_next_sibling_item(hwndTree,h))
- // {
- // const TQuotesProviderPtr& pQuotesProvier = *i;
- CQuotesProviderDukasCopy::CQuoteSection qs = pQuotesProvider->GetQuotes();
- recursive_save_quote_section_selection(hwndTree, tree_get_child_item(hwndTree, TVI_ROOT), qs, pQuotesProvider);
- // }
+ size_t cQuotes = qs.GetQuoteCount();
+ for (size_t i = 0; h && (i < cQuotes); ++i, h = tree_get_next_sibling_item(hwndTree, h)) {
+ CQuotesProviderDukasCopy::CQuote q = qs.GetQuote(i);
+ save_quote_selection(hwndTree, h, q, pQuotesProvier);
}
+}
- class CImageListWrapper
- {
- public:
- CImageListWrapper()
- : m_hImageList(ImageList_Create(::GetSystemMetrics(SM_CXSMICON),
+void recursive_save_selection(HWND hwndTree, CQuotesProviderDukasCopy* pQuotesProvider)
+{
+ CQuotesProviderDukasCopy::CQuoteSection qs = pQuotesProvider->GetQuotes();
+ recursive_save_quote_section_selection(hwndTree, tree_get_child_item(hwndTree, TVI_ROOT), qs, pQuotesProvider);
+}
+
+class CImageListWrapper
+{
+public:
+ CImageListWrapper()
+ : m_hImageList(ImageList_Create(::GetSystemMetrics(SM_CXSMICON),
::GetSystemMetrics(SM_CYSMICON),
ILC_COLOR24 | ILC_MASK, 2, 0))
- {
- if (m_hImageList)
- {
- ImageList_AddIcon(m_hImageList, Quotes_LoadIconEx(ICON_STR_SECTION));
- ImageList_AddIcon(m_hImageList, Quotes_LoadIconEx(ICON_STR_QUOTE));
- }
- }
-
- ~CImageListWrapper()
- {
- if (m_hImageList)
- {
- ImageList_Destroy(m_hImageList);
- }
- }
-
- operator HIMAGELIST()const
- {
- return m_hImageList;
+ {
+ if (m_hImageList) {
+ ImageList_AddIcon(m_hImageList, Quotes_LoadIconEx(IDI_ICON_SECTION));
+ ImageList_AddIcon(m_hImageList, Quotes_LoadIconEx(IDI_ICON_QUOTE));
}
+ }
- private:
- HIMAGELIST m_hImageList;
- };
-
- HIMAGELIST get_image_list()
+ ~CImageListWrapper()
{
- static CImageListWrapper wrapper;
- return wrapper;
+ if (m_hImageList)
+ ImageList_Destroy(m_hImageList);
}
- CQuotesProviderDukasCopy* get_dukas_copy_provider()
+ operator HIMAGELIST()const
{
- 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;
- CQuotesProviderDukasCopy* pDukas = dynamic_cast<CQuotesProviderDukasCopy*>(pProvider.get());
- if (pDukas)
- {
- return pDukas;
- }
- }
+ return m_hImageList;
+ }
+
+private:
+ HIMAGELIST m_hImageList;
+};
+
+HIMAGELIST get_image_list()
+{
+ static CImageListWrapper wrapper;
+ return wrapper;
+}
- assert(!"We should never get here!");
- return NULL;
+CQuotesProviderDukasCopy* get_dukas_copy_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;
+ CQuotesProviderDukasCopy* pDukas = dynamic_cast<CQuotesProviderDukasCopy*>(pProvider.get());
+ if (pDukas)
+ return pDukas;
}
- INT_PTR CALLBACK EconomicRatesDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- CCommonDlgProcData d(get_dukas_copy_provider());
- CommonOptionDlgProc(hdlg, message, wParam, lParam, d);
+ assert(!"We should never get here!");
+ return NULL;
+}
- switch (message)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hdlg);
+INT_PTR CALLBACK EconomicRatesDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ CCommonDlgProcData d(get_dukas_copy_provider());
+ CommonOptionDlgProc(hdlg, message, wParam, lParam, d);
+ switch (message) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+ {
HWND hwndTree = ::GetDlgItem(hdlg, IDC_TREE_ECONOMIC_RATES);
HIMAGELIST hImage = get_image_list();
- if (hImage)
- {
+ if (hImage) {
TreeView_SetImageList(hwndTree, hImage, TVSIL_NORMAL);
}
const CQuotesProviderDukasCopy* pDukasProvider = get_dukas_copy_provider();
if (pDukasProvider)
- {
add_provider_to_tree(pDukasProvider, hwndTree);
- }
- // Window_SetIcon_IcoLib(hdlg, SKINICON_OTHER_MIRANDA);
}
return TRUE;
- case WM_NOTIFY:
+ case WM_NOTIFY:
{
LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lParam);
- switch (pNMHDR->code)
- {
+ switch (pNMHDR->code) {
case TVN_KEYDOWN:
- if (IDC_TREE_ECONOMIC_RATES == wParam)
- {
+ if (IDC_TREE_ECONOMIC_RATES == wParam) {
LPNMTVKEYDOWN pKeyDown = reinterpret_cast<LPNMTVKEYDOWN>(lParam);
- if (VK_SPACE == pKeyDown->wVKey)
- {
+ if (VK_SPACE == pKeyDown->wVKey) {
HTREEITEM hti = TreeView_GetSelection(::GetDlgItem(hdlg, IDC_TREE_ECONOMIC_RATES));
::PostMessage(hdlg, TREE_VIEW_CHECK_STATE_CHANGE, MAKEWPARAM(1, 0), reinterpret_cast<LPARAM>(hti));
PropSheet_Changed(::GetParent(hdlg), hdlg);
}
}
break;
+
case NM_CLICK:
- if (IDC_TREE_ECONOMIC_RATES == wParam)
- {
+ if (IDC_TREE_ECONOMIC_RATES == wParam) {
DWORD pos = ::GetMessagePos();
HWND hwndTree = ::GetDlgItem(hdlg, IDC_TREE_ECONOMIC_RATES);
@@ -331,57 +271,41 @@ namespace ::ScreenToClient(hwndTree, &(tvhti.pt));
HTREEITEM hti = reinterpret_cast<HTREEITEM>(::SendMessage(hwndTree, TVM_HITTEST, 0, reinterpret_cast<LPARAM>(&tvhti)));
- if (hti && (tvhti.flags&TVHT_ONITEMSTATEICON))
- {
+ if (hti && (tvhti.flags&TVHT_ONITEMSTATEICON)) {
::PostMessage(hdlg, TREE_VIEW_CHECK_STATE_CHANGE, MAKEWPARAM(1, 0), reinterpret_cast<LPARAM>(hti));
PropSheet_Changed(::GetParent(hdlg), hdlg);
}
}
break;
+
case PSN_APPLY:
- {
CQuotesProviderDukasCopy* pDukasProvider = get_dukas_copy_provider();
- if (pDukasProvider)
- {
+ if (pDukasProvider) {
recursive_save_selection(::GetDlgItem(hdlg, IDC_TREE_ECONOMIC_RATES), pDukasProvider);
pDukasProvider->RefreshSettings();
}
- }
- break;
+ break;
}
}
return TRUE;
- case TREE_VIEW_CHECK_STATE_CHANGE:
- {
- HWND hwndTree = ::GetDlgItem(hdlg, IDC_TREE_ECONOMIC_RATES);
- HTREEITEM hti = reinterpret_cast<HTREEITEM>(lParam);
+ case TREE_VIEW_CHECK_STATE_CHANGE:
+ HWND hwndTree = ::GetDlgItem(hdlg, IDC_TREE_ECONOMIC_RATES);
+ HTREEITEM hti = reinterpret_cast<HTREEITEM>(lParam);
- ETreeCheckBoxState nState;
+ ETreeCheckBoxState nState;
- bool bRecursively = 1 == LOWORD(wParam);
- if (bRecursively)
- {
- nState = tree_get_state_image(hwndTree, hti);
- }
- else
- {
- nState = static_cast<ETreeCheckBoxState>(HIWORD(wParam));
- }
+ bool bRecursively = 1 == LOWORD(wParam);
+ if (bRecursively)
+ nState = tree_get_state_image(hwndTree, hti);
+ else
+ nState = static_cast<ETreeCheckBoxState>(HIWORD(wParam));
- tree_set_item_state(hwndTree, hti, nState, bRecursively);
- }
+ tree_set_item_state(hwndTree, hti, nState, bRecursively);
break;
- // case WM_CLOSE:
- // DestroyWindow(hdlg);
- // break;
- // case WM_DESTROY:
- // g_hwndEconomicRates = NULL;
- // break;
- }
-
- return FALSE;
}
+
+ return FALSE;
}
void ShowDukasCopyPropPage(CQuotesProviderDukasCopy* pProvider, WPARAM wp, OPTIONSDIALOGPAGE& odp)
@@ -390,15 +314,6 @@ void ShowDukasCopyPropPage(CQuotesProviderDukasCopy* pProvider, WPARAM wp, OPTIO odp.pszTemplate = MAKEINTRESOURCEA(IDD_DIALOG_ECONOMIC_RATES);
odp.pfnDlgProc = EconomicRatesDlgProc;
- // #if MIRANDA_VER >= 0x0600
- //odp.ptszTab = TranslateTS(const_cast<LPTSTR>(pi.m_sName.c_str()));
odp.ptszTab = const_cast<LPTSTR>(pi.m_sName.c_str());
- // #else
- // tostringstream o;
- // o << TranslateTS(QUOTES_PROTOCOL_NAME) << _T(" - ") << TranslateTS(pi.m_sName.c_str());
- // tstring sTitle = o.str();
- // odp.ptszTitle = TranslateTS(const_cast<LPTSTR>(sTitle.c_str()));
- // #endif
-
Options_AddPage(wp, &odp);
}
diff --git a/plugins/Quotes/src/QuoteChart.cpp b/plugins/Quotes/src/QuoteChart.cpp index c0fec78d59..48938faef2 100644 --- a/plugins/Quotes/src/QuoteChart.cpp +++ b/plugins/Quotes/src/QuoteChart.cpp @@ -5,389 +5,356 @@ #define WINDOW_PREFIX "Quotes Chart_"
#define CHART_CTRL_CLASS _T("DioksinChart")
-namespace
+struct CTimeConvert
{
- struct CTimeConvert
+ static double Convert(const boost::posix_time::time_duration& v)
{
- static double Convert(const boost::posix_time::time_duration& v)
- {
- return boost::numeric_cast<double>(v.ticks());
- }
-
- static tstring ToString(const boost::posix_time::ptime& v)
- {
- tostringstream k;
- k.imbue(std::locale(GetSystemLocale(),new ttime_facet(_T("%d/%m/%y %H:%M:%S"))));
- k << v;
- return k.str();
- }
- };
-
- typedef CChart<boost::posix_time::ptime,double,CTimeConvert> TChart;
+ return boost::numeric_cast<double>(v.ticks());
+ }
- inline TChart* get_chart_ptr(HWND hWnd)
+ static tstring ToString(const boost::posix_time::ptime& v)
{
- TChart* pChart = reinterpret_cast<TChart*>(GetWindowLongPtr(hWnd,GWLP_USERDATA));
- return pChart;
+ tostringstream k;
+ k.imbue(std::locale(GetSystemLocale(), new ttime_facet(_T("%d/%m/%y %H:%M:%S"))));
+ k << v;
+ return k.str();
}
+};
- bool read_log_file(MCONTACT hContact,TChart& rChart)
- {
- tstring sLogFileName = GetContactLogFileName(hContact);
- if(false == sLogFileName.empty())
- {
- std::locale loc(GetSystemLocale(),new ttime_input_facet(_T("%d.%m.%y %H:%M:%S")));
- boost::posix_time::ptime oDateTime;
- double dRate;
-
- tifstream file(sLogFileName.c_str());
- file.imbue(loc);
- while((false == file.fail()) && (false == file.eof()))
- {
- tstring sLine;
- std::getline(file,sLine);
-
- tistringstream line(sLine);
- line.imbue(loc);
-
- tstring sName;
- std::getline(line,sName,_T('\t'));
- line >> oDateTime >> dRate;
- if ((false == line.fail()) && (true == line.eof()))
- {
- rChart.AddValue(oDateTime,dRate);
- }
- }
+typedef CChart<boost::posix_time::ptime, double, CTimeConvert> TChart;
- return true;
+inline TChart* get_chart_ptr(HWND hWnd)
+{
+ TChart* pChart = reinterpret_cast<TChart*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
+ return pChart;
+}
+
+bool read_log_file(MCONTACT hContact, TChart& rChart)
+{
+ tstring sLogFileName = GetContactLogFileName(hContact);
+ if (false == sLogFileName.empty()) {
+ std::locale loc(GetSystemLocale(), new ttime_input_facet(_T("%d.%m.%y %H:%M:%S")));
+ boost::posix_time::ptime oDateTime;
+ double dRate;
+
+ tifstream file(sLogFileName.c_str());
+ file.imbue(loc);
+ while ((false == file.fail()) && (false == file.eof())) {
+ tstring sLine;
+ std::getline(file, sLine);
+
+ tistringstream line(sLine);
+ line.imbue(loc);
+
+ tstring sName;
+ std::getline(line, sName, _T('\t'));
+ line >> oDateTime >> dRate;
+ if ((false == line.fail()) && (true == line.eof())) {
+ rChart.AddValue(oDateTime, dRate);
+ }
}
- return false;
+
+ return true;
}
+ return false;
+}
- enum
- {
- ID_CHART = 0x1969,
+enum
+{
+ ID_CHART = 0x1969,
- srcLogFile = 0,
- srcHistory = 1,
+ srcLogFile = 0,
+ srcHistory = 1,
- filterAll = 0,
- filterLastDay = 1,
- filterLastWeek = 2,
- filterLastMonth = 3,
- filterLastYear = 4,
- filterUserDefined = 5,
+ filterAll = 0,
+ filterLastDay = 1,
+ filterLastWeek = 2,
+ filterLastMonth = 3,
+ filterLastYear = 4,
+ filterUserDefined = 5,
- CHART_SET_SOURCE = WM_USER + 1,
- CHART_SET_FILTER = WM_USER + 2,
- };
+ CHART_SET_SOURCE = WM_USER + 1,
+ CHART_SET_FILTER = WM_USER + 2,
+};
- LRESULT CALLBACK ChartWndProc(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp)
- {
- switch(msg)
- {
- case WM_CREATE:
+LRESULT CALLBACK ChartWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+ switch (msg) {
+ case WM_CREATE:
{
CREATESTRUCT* pCS = reinterpret_cast<CREATESTRUCT*>(lp);
MCONTACT hContact = reinterpret_cast<HANDLE>(pCS->lpCreateParams);
TChart* pChart = new TChart;
- read_log_file(hContact,*pChart);
+ read_log_file(hContact, *pChart);
- ::SetWindowLongPtr(hWnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pChart));
- }
+ ::SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pChart));
+ }
return 0;
- case CHART_SET_SOURCE:
- break;
+ case CHART_SET_SOURCE:
+ break;
- case CHART_SET_FILTER:
- break;
+ case CHART_SET_FILTER:
+ break;
- case WM_SIZE:
+ case WM_SIZE:
{
TChart* pChart = get_chart_ptr(hWnd);
- pChart->SetRect(0,0,LOWORD(lp),HIWORD(lp));
+ pChart->SetRect(0, 0, LOWORD(lp), HIWORD(lp));
}
return 0;
- case WM_PAINT:
- if(TRUE == ::GetUpdateRect(hWnd,NULL,FALSE))
- {
- PAINTSTRUCT ps;
- HDC hdc = ::BeginPaint(hWnd,&ps);
- if(NULL != hdc)
- {
- TChart* pChart = get_chart_ptr(hWnd);
- pChart->Draw(hdc);
- ::EndPaint(hWnd,&ps);
- }
+ case WM_PAINT:
+ if (TRUE == ::GetUpdateRect(hWnd, NULL, FALSE)) {
+ PAINTSTRUCT ps;
+ HDC hdc = ::BeginPaint(hWnd, &ps);
+ if (NULL != hdc) {
+ TChart* pChart = get_chart_ptr(hWnd);
+ pChart->Draw(hdc);
+ ::EndPaint(hWnd, &ps);
}
+ }
- return 0;
- case WM_DESTROY:
+ return 0;
+ case WM_DESTROY:
{
TChart* pChart = get_chart_ptr(hWnd);
- ::SetWindowLongPtr(hWnd,GWLP_USERDATA,0);
+ ::SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
delete pChart;
}
break;
- }
-
- return ::DefWindowProc(hWnd,msg,wp,lp);
}
- void register_chart_control()
- {
- static bool g_bRegister = false;
- if(g_bRegister)
- {
- return;
- }
-
- WNDCLASS wc;
+ return ::DefWindowProc(hWnd, msg, wp, lp);
+}
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = ChartWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = CModuleInfo::GetInstance().GetModuleHandle();
- wc.hIcon = NULL;
- wc.hCursor = LoadCursor(NULL,IDC_ARROW);
- wc.hbrBackground = static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
- wc.lpszMenuName = NULL;
- wc.lpszClassName = CHART_CTRL_CLASS;
+void register_chart_control()
+{
+ static bool g_bRegister = false;
+ if (g_bRegister) {
+ return;
+ }
- if(RegisterClass(&wc))
- {
- g_bRegister = true;
- }
+ WNDCLASS wc;
+
+ wc.style = CS_HREDRAW | CS_VREDRAW;
+ wc.lpfnWndProc = ChartWndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = CModuleInfo::GetInstance().GetModuleHandle();
+ wc.hIcon = NULL;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = CHART_CTRL_CLASS;
+
+ if (RegisterClass(&wc)) {
+ g_bRegister = true;
}
+}
- bool screen_2_client(HWND hWnd,LPRECT pRect)
- {
- POINT pt;
- pt.x = pRect->left;
- pt.y = pRect->top;
- bool bResult = TRUE == ::ScreenToClient(hWnd,&pt);
- pRect->left = pt.x;
- pRect->top = pt.y;
- pt.x = pRect->right;
- pt.y = pRect->bottom;
- bResult |= TRUE == ::ScreenToClient(hWnd,&pt);
- pRect->right = pt.x;
- pRect->bottom = pt.y;
- return bResult;
- }
-
- inline HANDLE get_contact(HWND hWnd)
- {
- MCONTACT hContact = reinterpret_cast<HANDLE>(GetWindowLongPtr(hWnd,GWLP_USERDATA));
- return hContact;
- }
+bool screen_2_client(HWND hWnd, LPRECT pRect)
+{
+ POINT pt;
+ pt.x = pRect->left;
+ pt.y = pRect->top;
+ bool bResult = TRUE == ::ScreenToClient(hWnd, &pt);
+ pRect->left = pt.x;
+ pRect->top = pt.y;
+ pt.x = pRect->right;
+ pt.y = pRect->bottom;
+ bResult |= TRUE == ::ScreenToClient(hWnd, &pt);
+ pRect->right = pt.x;
+ pRect->bottom = pt.y;
+ return bResult;
+}
- void update_filter_controls(HWND hDlg)
- {
- int nSel = ::SendDlgItemMessage(hDlg,IDC_COMBO_FILTER,CB_GETCURSEL,0,0);
+inline HANDLE get_contact(HWND hWnd)
+{
+ MCONTACT hContact = reinterpret_cast<HANDLE>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
+ return hContact;
+}
- ::ShowWindow(::GetDlgItem(hDlg,IDC_EDIT_FROM),(filterUserDefined == nSel) ? SW_SHOW : SW_HIDE);
- ::ShowWindow(::GetDlgItem(hDlg,IDC_EDIT_TO),(filterUserDefined == nSel) ? SW_SHOW : SW_HIDE);
- }
+void update_filter_controls(HWND hDlg)
+{
+ int nSel = ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_GETCURSEL, 0, 0);
- INT_PTR CALLBACK ChartDlgProc(HWND hDlg,UINT msg,WPARAM wp,LPARAM lp)
- {
- switch(msg)
- {
- case WM_INITDIALOG:
+ ::ShowWindow(::GetDlgItem(hDlg, IDC_EDIT_FROM), (filterUserDefined == nSel) ? SW_SHOW : SW_HIDE);
+ ::ShowWindow(::GetDlgItem(hDlg, IDC_EDIT_TO), (filterUserDefined == nSel) ? SW_SHOW : SW_HIDE);
+}
+
+INT_PTR CALLBACK ChartDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hDlg);
{
MCONTACT hContact = reinterpret_cast<HANDLE>(lp);
- TranslateDialogDefault(hDlg);
-
tstring sName = get_window_text(hDlg);
sName += _T(" - ");
sName += GetContactName(hContact);
- ::SetWindowText(hDlg,sName.c_str());
+ ::SetWindowText(hDlg, sName.c_str());
- HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX,false);
+ HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, false);
assert(hWL);
- WindowList_Add(hWL,hDlg,hContact);
+ WindowList_Add(hWL, hDlg, hContact);
- ::SetWindowLongPtr(hDlg,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(hContact));
+ ::SetWindowLongPtr(hDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(hContact));
- static LPCTSTR szSources[] = {LPGENT("Log File"), LPGENT("Miranda's History")};
- static LPCTSTR szFilters[] = {LPGENT("All"), LPGENT("Last Day"), LPGENT("Last Week"), LPGENT("Last Month"), LPGENT("Last Year"), LPGENT("User-Defined")};
+ static LPCTSTR szSources[] = { LPGENT("Log File"), LPGENT("Miranda's History") };
+ static LPCTSTR szFilters[] = { LPGENT("All"), LPGENT("Last Day"), LPGENT("Last Week"), LPGENT("Last Month"), LPGENT("Last Year"), LPGENT("User-Defined") };
- for(int i = 0;i < sizeof(szSources)/sizeof(szSources[0]);++i)
- {
+ for (int i = 0; i < sizeof(szSources) / sizeof(szSources[0]); ++i) {
LPCTSTR p = TranslateTS(szSources[i]);
- ::SendDlgItemMessage(hDlg,IDC_COMBO_DATA_SOURCE,CB_INSERTSTRING,-1,reinterpret_cast<LPARAM>(p));
+ ::SendDlgItemMessage(hDlg, IDC_COMBO_DATA_SOURCE, CB_INSERTSTRING, -1, reinterpret_cast<LPARAM>(p));
}
- int nSel = db_get_b(hContact,QUOTES_PROTOCOL_NAME,"Chart_Source",srcLogFile);
- ::SendDlgItemMessage(hDlg,IDC_COMBO_DATA_SOURCE,CB_SETCURSEL,nSel,0);
+ int nSel = db_get_b(hContact, QUOTES_PROTOCOL_NAME, "Chart_Source", srcLogFile);
+ ::SendDlgItemMessage(hDlg, IDC_COMBO_DATA_SOURCE, CB_SETCURSEL, nSel, 0);
- for(int i = 0;i < sizeof(szFilters)/sizeof(szFilters[0]);++i)
- {
+ for (int i = 0; i < sizeof(szFilters) / sizeof(szFilters[0]); ++i) {
LPCTSTR p = TranslateTS(szSources[i]);
- ::SendDlgItemMessage(hDlg,IDC_COMBO_FILTER,CB_INSERTSTRING,-1,reinterpret_cast<LPARAM>(szFilters[i]));
+ ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_INSERTSTRING, -1, reinterpret_cast<LPARAM>(szFilters[i]));
}
- nSel = db_get_b(hContact,QUOTES_PROTOCOL_NAME,"Chart_Filter",filterAll);
- ::SendDlgItemMessage(hDlg,IDC_COMBO_FILTER,CB_SETCURSEL,nSel,0);
+ nSel = db_get_b(hContact, QUOTES_PROTOCOL_NAME, "Chart_Filter", filterAll);
+ ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_SETCURSEL, nSel, 0);
update_filter_controls(hDlg);
register_chart_control();
- HWND hwndImage = ::GetDlgItem(hDlg,IDC_STATIC_IMAGE);
+ HWND hwndImage = ::GetDlgItem(hDlg, IDC_STATIC_IMAGE);
RECT rcImage;
- ::GetWindowRect(hwndImage,&rcImage);
- screen_2_client(hDlg,&rcImage);
+ ::GetWindowRect(hwndImage, &rcImage);
+ screen_2_client(hDlg, &rcImage);
//BOOL bResult = ShowWindow(hwndImage,SW_HIDE);
//assert(bResult);
- HWND hChart = ::CreateWindowEx(0L,CHART_CTRL_CLASS,NULL,WS_CHILDWINDOW|WS_VISIBLE,
- rcImage.left,rcImage.top,rcImage.right-rcImage.left,rcImage.bottom-rcImage.top,
- hDlg,reinterpret_cast<HMENU>(ID_CHART),CModuleInfo::GetInstance().GetModuleHandle(),hContact);
+ HWND hChart = ::CreateWindowEx(0L, CHART_CTRL_CLASS, NULL, WS_CHILDWINDOW | WS_VISIBLE,
+ rcImage.left, rcImage.top, rcImage.right - rcImage.left, rcImage.bottom - rcImage.top,
+ hDlg, reinterpret_cast<HMENU>(ID_CHART), CModuleInfo::GetInstance().GetModuleHandle(), hContact);
assert(NULL != hChart);
- Utils_RestoreWindowPosition(hDlg,hContact,QUOTES_MODULE_NAME,WINDOW_PREFIX);
- BOOL bResult = ::ShowWindow(hDlg,SW_SHOW);
+ Utils_RestoreWindowPosition(hDlg, hContact, QUOTES_MODULE_NAME, WINDOW_PREFIX);
+ BOOL bResult = ::ShowWindow(hDlg, SW_SHOW);
assert(bResult);
}
return (TRUE);
- case WM_CLOSE:
+ case WM_CLOSE:
{
MCONTACT hContact = get_contact(hDlg);
- SetWindowLongPtr(hDlg,GWLP_USERDATA,0);
+ SetWindowLongPtr(hDlg, GWLP_USERDATA, 0);
// save_options(hDlg,hContact);
- HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX,false);
+ HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, false);
assert(hWL);
- WindowList_Remove(hWL,hDlg);
- Utils_SaveWindowPosition(hDlg,hContact,QUOTES_MODULE_NAME,WINDOW_PREFIX);
+ WindowList_Remove(hWL, hDlg);
+ Utils_SaveWindowPosition(hDlg, hContact, QUOTES_MODULE_NAME, WINDOW_PREFIX);
- HWND hwndChart = ::GetDlgItem(hDlg,ID_CHART);
+ HWND hwndChart = ::GetDlgItem(hDlg, ID_CHART);
BOOL bResult = ::DestroyWindow(hwndChart);
assert(bResult);
- ::EndDialog(hDlg,0);
+ ::EndDialog(hDlg, 0);
}
return (TRUE);
- case WM_COMMAND:
- switch(LOWORD(wp))
- {
- case IDCANCEL:
- {
- SendMessage(hDlg, WM_CLOSE, 0, 0);
- }
+
+ case WM_COMMAND:
+ switch (LOWORD(wp)) {
+ case IDCANCEL:
+ SendMessage(hDlg, WM_CLOSE, 0, 0);
return (TRUE);
- case IDC_COMBO_FILTER:
- if(CBN_SELCHANGE == HIWORD(wp))
- {
- ::SendDlgItemMessage(hDlg,ID_CHART,CHART_SET_FILTER,::SendDlgItemMessage(hDlg,IDC_COMBO_FILTER,CB_GETCURSEL,0,0),0);
- update_filter_controls(hDlg);
- }
- break;
- case IDC_COMBO_DATA_SOURCE:
- if(CBN_SELCHANGE == HIWORD(wp))
- {
- ::SendDlgItemMessage(hDlg,ID_CHART,CHART_SET_SOURCE,::SendDlgItemMessage(hDlg,IDC_COMBO_DATA_SOURCE,CB_GETCURSEL,0,0),0);
- }
- break;
+
+ case IDC_COMBO_FILTER:
+ if (CBN_SELCHANGE == HIWORD(wp)) {
+ ::SendDlgItemMessage(hDlg, ID_CHART, CHART_SET_FILTER, ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_GETCURSEL, 0, 0), 0);
+ update_filter_controls(hDlg);
}
- return (FALSE);
- case WM_NOTIFY:
+ break;
+ case IDC_COMBO_DATA_SOURCE:
+ if (CBN_SELCHANGE == HIWORD(wp))
+ ::SendDlgItemMessage(hDlg, ID_CHART, CHART_SET_SOURCE, ::SendDlgItemMessage(hDlg, IDC_COMBO_DATA_SOURCE, CB_GETCURSEL, 0, 0), 0);
+ break;
+ }
+ return (FALSE);
+
+ case WM_NOTIFY:
{
LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lp);
- switch(pNMHDR->code)
- {
+ switch (pNMHDR->code) {
case NM_CLICK:
- if(IDC_SYSLINK_PROVIDER == wp)
- {
+ if (IDC_SYSLINK_PROVIDER == wp) {
PNMLINK pNMLink = reinterpret_cast<PNMLINK>(pNMHDR);
- ::ShellExecute(hDlg,_T("open"),pNMLink->item.szUrl,NULL,NULL,SW_SHOWNORMAL);
+ ::ShellExecute(hDlg, _T("open"), pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);
}
break;
}
}
break;
- // case WM_ERASEBKGND:
- // {
- // HDC hdc = reinterpret_cast<HDC>(wp);
- // TChart* pChart = get_chart_ptr(hDlg);
- // pChart->DrawBackground(hdc);
- // return TRUE;
- // }
- // break;
- case WM_SIZE:
+
+ case WM_SIZE:
{
- enum{ INDENT = 7};
+ enum { INDENT = 7 };
int nWidth = LOWORD(lp);
int nHeight = HIWORD(lp);
- HWND hwndChart = GetDlgItem(hDlg,ID_CHART);
- HWND hwndLink = GetDlgItem(hDlg,IDC_SYSLINK_PROVIDER);
- HWND hwndClose = GetDlgItem(hDlg,IDCANCEL);
+ HWND hwndChart = GetDlgItem(hDlg, ID_CHART);
+ HWND hwndLink = GetDlgItem(hDlg, IDC_SYSLINK_PROVIDER);
+ HWND hwndClose = GetDlgItem(hDlg, IDCANCEL);
RECT rcDlg;
- GetClientRect(hDlg,&rcDlg);
+ GetClientRect(hDlg, &rcDlg);
RECT rcChart;
- GetWindowRect(hwndChart,&rcChart);
- screen_2_client(hDlg,&rcChart);
+ GetWindowRect(hwndChart, &rcChart);
+ screen_2_client(hDlg, &rcChart);
RECT rcLink;
- GetWindowRect(hwndLink,&rcLink);
- screen_2_client(hDlg,&rcLink);
- SetWindowPos(hwndLink,NULL,rcDlg.left + INDENT,
- rcDlg.bottom-INDENT-(rcLink.bottom-rcLink.top),
- 0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
+ GetWindowRect(hwndLink, &rcLink);
+ screen_2_client(hDlg, &rcLink);
+ SetWindowPos(hwndLink, NULL, rcDlg.left + INDENT,
+ rcDlg.bottom - INDENT - (rcLink.bottom - rcLink.top),
+ 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
RECT rcClose;
- GetWindowRect(hwndClose,&rcClose);
- screen_2_client(hDlg,&rcClose);
- SetWindowPos(hwndClose,NULL,rcDlg.right - INDENT - (rcClose.right-rcClose.left),
- rcDlg.bottom-INDENT-(rcClose.bottom-rcClose.top),
- 0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
+ GetWindowRect(hwndClose, &rcClose);
+ screen_2_client(hDlg, &rcClose);
+ SetWindowPos(hwndClose, NULL, rcDlg.right - INDENT - (rcClose.right - rcClose.left),
+ rcDlg.bottom - INDENT - (rcClose.bottom - rcClose.top),
+ 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
- SetWindowPos(hwndChart,NULL,rcDlg.left + INDENT,
+ SetWindowPos(hwndChart, NULL, rcDlg.left + INDENT,
rcChart.top,
- (nWidth-INDENT*2),
- nHeight-(rcClose.bottom-rcClose.top)-INDENT*2-rcChart.top,
- SWP_NOZORDER|SWP_NOACTIVATE);
+ (nWidth - INDENT * 2),
+ nHeight - (rcClose.bottom - rcClose.top) - INDENT * 2 - rcChart.top,
+ SWP_NOZORDER | SWP_NOACTIVATE);
}
break;
- }
- return (FALSE);
}
+ return (FALSE);
}
-INT_PTR QuotesMenu_Chart(WPARAM wp,LPARAM lp)
+INT_PTR QuotesMenu_Chart(WPARAM wp, LPARAM lp)
{
MCONTACT hContact = reinterpret_cast<HANDLE>(wp);
- if(NULL == hContact)
- {
+ if (NULL == hContact)
return 0;
- }
- HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX,true);
+ HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, true);
assert(hWL);
- HWND hWnd = WindowList_Find(hWL,hContact);
- if(NULL != hWnd)
- {
+ HWND hWnd = WindowList_Find(hWL, hContact);
+ if (NULL != hWnd) {
SetForegroundWindow(hWnd);
SetFocus(hWnd);
}
- else
- {
- CreateDialogParam(CModuleInfo::GetModuleHandle(), MAKEINTRESOURCE(IDD_DUKASCOPY_CHART), NULL, ChartDlgProc, reinterpret_cast<LPARAM>(hContact));
- }
+ else CreateDialogParam(CModuleInfo::GetModuleHandle(), MAKEINTRESOURCE(IDD_DUKASCOPY_CHART), NULL, ChartDlgProc, reinterpret_cast<LPARAM>(hContact));
return 0;
}
diff --git a/plugins/Quotes/src/QuoteInfoDlg.cpp b/plugins/Quotes/src/QuoteInfoDlg.cpp index 51970a044f..fdb60d15ab 100644 --- a/plugins/Quotes/src/QuoteInfoDlg.cpp +++ b/plugins/Quotes/src/QuoteInfoDlg.cpp @@ -8,7 +8,6 @@ extern HGENMENU g_hMenuChart; #endif
extern HGENMENU g_hMenuRefresh, g_hMenuRoot;
-
#define WINDOW_PREFIX_INFO "Quote Info"
MCONTACT g_hContact;
@@ -24,7 +23,7 @@ inline MCONTACT get_contact(HWND hWnd) return MCONTACT(GetWindowLongPtr(hWnd, GWLP_USERDATA));
}
-bool get_fetch_time(time_t& rTime, MCONTACT hContact)
+static bool get_fetch_time(time_t& rTime, MCONTACT hContact)
{
rTime = db_get_dw(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FETCH_TIME, -1);
return (rTime != -1);
@@ -42,8 +41,7 @@ INT_PTR CALLBACK QuoteInfoDlgProcImpl(MCONTACT hContact, HWND hdlg, UINT msg, WP ::SetDlgItemText(hdlg, IDC_STATIC_QUOTE_NAME, sDescription.c_str());
double dRate = 0.0;
- if (true == Quotes_DBReadDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_PREV_VALUE, dRate))
- {
+ if (true == Quotes_DBReadDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_PREV_VALUE, dRate)) {
tostringstream o;
o.imbue(GetSystemLocale());
o << dRate;
@@ -52,8 +50,7 @@ INT_PTR CALLBACK QuoteInfoDlgProcImpl(MCONTACT hContact, HWND hdlg, UINT msg, WP }
dRate = 0.0;
- if (true == Quotes_DBReadDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_CURR_VALUE, dRate))
- {
+ if (true == Quotes_DBReadDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_CURR_VALUE, dRate)) {
tostringstream o;
o.imbue(GetSystemLocale());
o << dRate;
@@ -62,11 +59,9 @@ INT_PTR CALLBACK QuoteInfoDlgProcImpl(MCONTACT hContact, HWND hdlg, UINT msg, WP }
time_t nFetchTime;
- if (true == get_fetch_time(nFetchTime, hContact))
- {
+ if (true == get_fetch_time(nFetchTime, hContact)) {
TCHAR szTime[50] = { 0 };
- if (0 == _tctime_s(szTime, 50, &nFetchTime))
- {
+ if (0 == _tctime_s(szTime, 50, &nFetchTime)) {
::SetDlgItemText(hdlg, IDC_EDIT_RATE_FETCH_TIME, szTime);
}
}
@@ -114,7 +109,7 @@ int QuotesEventFunc_OnUserInfoInit(WPARAM wp, LPARAM lp) OPTIONSDIALOGPAGE odp = { 0 };
odp.hInstance = g_hInstance;
- odp.hIcon = Quotes_LoadIconEx(ICON_STR_MAIN);
+ odp.hIcon = Quotes_LoadIconEx(IDI_ICON_MAIN);
odp.pfnDlgProc = QuoteInfoDlgProc;
odp.position = -2000000000;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_DIALOG_QUOTE_INFO);
@@ -218,8 +213,7 @@ static INT_PTR CALLBACK QuoteInfoDlgProc1(HWND hdlg, UINT msg, WPARAM wParam, LP int Quotes_OnContactDoubleClick(WPARAM wp, LPARAM/* lp*/)
{
MCONTACT hContact = MCONTACT(wp);
- if (CModuleInfo::GetQuoteProvidersPtr()->GetContactProviderPtr(hContact))
- {
+ if (CModuleInfo::GetQuoteProvidersPtr()->GetContactProviderPtr(hContact)) {
MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX_INFO, true);
assert(hWL);
HWND hWnd = WindowList_Find(hWL, hContact);
@@ -240,9 +234,9 @@ int Quotes_PrebuildContactMenu(WPARAM wp, LPARAM) {
Menu_EnableItem(g_hMenuEditSettings, false);
Menu_EnableItem(g_hMenuOpenLogFile, false);
-#ifdef CHART_IMPLEMENT
- Menu_EnableItem(g_hMenuChart,false);
-#endif
+ #ifdef CHART_IMPLEMENT
+ Menu_EnableItem(g_hMenuChart, false);
+ #endif
Menu_EnableItem(g_hMenuRefresh, false);
MCONTACT hContact = MCONTACT(wp);
@@ -260,11 +254,10 @@ int Quotes_PrebuildContactMenu(WPARAM wp, LPARAM) tstring sLogFileName;
bool bThereIsLogFile = (true == get_log_file(hContact, sLogFileName))
&& (false == sLogFileName.empty()) && (0 == _taccess(sLogFileName.c_str(), 04));
- if (true == bThereIsLogFile)
- {
-#ifdef CHART_IMPLEMENT
- Menu_EnableItem(g_hMenuChart,true);
-#endif
+ if (true == bThereIsLogFile) {
+ #ifdef CHART_IMPLEMENT
+ Menu_EnableItem(g_hMenuChart, true);
+ #endif
Menu_EnableItem(g_hMenuOpenLogFile, true);
}
diff --git a/plugins/Quotes/src/QuotesProviderBase.cpp b/plugins/Quotes/src/QuotesProviderBase.cpp index f66d976722..c97126e9fe 100644 --- a/plugins/Quotes/src/QuotesProviderBase.cpp +++ b/plugins/Quotes/src/QuotesProviderBase.cpp @@ -3,172 +3,138 @@ extern bool g_bAutoUpdate;
extern HANDLE g_hEventWorkThreadStop;
-
struct CQuotesProviderBase::CXMLFileInfo
{
- CXMLFileInfo() : m_qs(_T("Unknown")){}
+ CXMLFileInfo() : m_qs(_T("Unknown")) {}
IQuotesProvider::CProviderInfo m_pi;
CQuotesProviderBase::CQuoteSection m_qs;
tstring m_sURL;
};
-namespace
+inline tstring get_ini_file_name(LPCTSTR pszFileName)
{
- inline tstring get_ini_file_name(LPCTSTR pszFileName)
- {
- return CreateFilePath(pszFileName);
- }
+ return CreateFilePath(pszFileName);
+}
- bool parse_quote(const IXMLNode::TXMLNodePtr& pTop, CQuotesProviderBase::CQuote& q)
- {
- tstring sSymbol;
- tstring sDescription;
- tstring sID;
-
- size_t cChild = pTop->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pTop->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (0 == quotes_stricmp(_T("symbol"), sName.c_str()))
- {
- sSymbol = pNode->GetText();
- if (true == sSymbol.empty())
- {
- return false;
- }
- }
- else if (0 == quotes_stricmp(_T("description"), sName.c_str()))
- {
- sDescription = pNode->GetText();
- }
- else if (0 == quotes_stricmp(_T("id"), sName.c_str()))
- {
- sID = pNode->GetText();
- if (true == sID.empty())
- {
- return false;
- }
- }
+bool parse_quote(const IXMLNode::TXMLNodePtr& pTop, CQuotesProviderBase::CQuote& q)
+{
+ tstring sSymbol;
+ tstring sDescription;
+ tstring sID;
+
+ size_t cChild = pTop->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pTop->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (0 == quotes_stricmp(_T("symbol"), sName.c_str())) {
+ sSymbol = pNode->GetText();
+ if (true == sSymbol.empty())
+ return false;
+ }
+ else if (0 == quotes_stricmp(_T("description"), sName.c_str())) {
+ sDescription = pNode->GetText();
+ }
+ else if (0 == quotes_stricmp(_T("id"), sName.c_str())) {
+ sID = pNode->GetText();
+ if (true == sID.empty())
+ return false;
}
-
- q = CQuotesProviderBase::CQuote(sID, TranslateTS(sSymbol.c_str()), TranslateTS(sDescription.c_str()));
- return true;
}
- bool parse_section(const IXMLNode::TXMLNodePtr& pTop, CQuotesProviderBase::CQuoteSection& qs)
- {
- CQuotesProviderBase::CQuoteSection::TSections aSections;
- CQuotesProviderBase::CQuoteSection::TQuotes aQuotes;
- tstring sSectionName;
-
- size_t cChild = pTop->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pTop->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (0 == quotes_stricmp(_T("section"), sName.c_str()))
- {
- CQuotesProviderBase::CQuoteSection qs1;
- if (true == parse_section(pNode, qs1))
- aSections.push_back(qs1);
- }
- else if (0 == quotes_stricmp(_T("quote"), sName.c_str()))
- {
- CQuotesProviderBase::CQuote q;
- if (true == parse_quote(pNode, q))
- aQuotes.push_back(q);
- }
- else if (0 == quotes_stricmp(_T("name"), sName.c_str()))
- {
- sSectionName = pNode->GetText();
- if (true == sSectionName.empty())
- return false;
- }
- }
+ q = CQuotesProviderBase::CQuote(sID, TranslateTS(sSymbol.c_str()), TranslateTS(sDescription.c_str()));
+ return true;
+}
- qs = CQuotesProviderBase::CQuoteSection(TranslateTS(sSectionName.c_str()), aSections, aQuotes);
- return true;
+bool parse_section(const IXMLNode::TXMLNodePtr& pTop, CQuotesProviderBase::CQuoteSection& qs)
+{
+ CQuotesProviderBase::CQuoteSection::TSections aSections;
+ CQuotesProviderBase::CQuoteSection::TQuotes aQuotes;
+ tstring sSectionName;
+
+ size_t cChild = pTop->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pTop->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (0 == quotes_stricmp(_T("section"), sName.c_str())) {
+ CQuotesProviderBase::CQuoteSection qs1;
+ if (true == parse_section(pNode, qs1))
+ aSections.push_back(qs1);
+ }
+ else if (0 == quotes_stricmp(_T("quote"), sName.c_str())) {
+ CQuotesProviderBase::CQuote q;
+ if (true == parse_quote(pNode, q))
+ aQuotes.push_back(q);
+ }
+ else if (0 == quotes_stricmp(_T("name"), sName.c_str())) {
+ sSectionName = pNode->GetText();
+ if (true == sSectionName.empty())
+ return false;
+ }
}
- IXMLNode::TXMLNodePtr find_provider(const IXMLNode::TXMLNodePtr& pRoot)
- {
- IXMLNode::TXMLNodePtr pProvider;
- size_t cChild = pRoot->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pRoot->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (0 == quotes_stricmp(_T("Provider"), sName.c_str()))
- {
- pProvider = pNode;
- break;
- }
- else
- {
- pProvider = find_provider(pNode);
- if (pProvider)
- {
- break;
- }
- }
+ qs = CQuotesProviderBase::CQuoteSection(TranslateTS(sSectionName.c_str()), aSections, aQuotes);
+ return true;
+}
+
+IXMLNode::TXMLNodePtr find_provider(const IXMLNode::TXMLNodePtr& pRoot)
+{
+ IXMLNode::TXMLNodePtr pProvider;
+ size_t cChild = pRoot->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pRoot->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (0 == quotes_stricmp(_T("Provider"), sName.c_str())) {
+ pProvider = pNode;
+ break;
}
- return pProvider;
+ pProvider = find_provider(pNode);
+ if (pProvider)
+ break;
}
- CQuotesProviderBase::CXMLFileInfo parse_ini_file(const tstring& rsXMLFile, bool& rbSucceded)
- {
- CQuotesProviderBase::CXMLFileInfo res;
- CQuotesProviderBase::CQuoteSection::TSections aSections;
-
- const CModuleInfo::TXMLEnginePtr& pXMLEngine = CModuleInfo::GetXMLEnginePtr();
- IXMLNode::TXMLNodePtr pRoot = pXMLEngine->LoadFile(rsXMLFile);
- if (pRoot)
- {
- IXMLNode::TXMLNodePtr pProvider = find_provider(pRoot);
- if (pProvider)
- {
- rbSucceded = true;
- size_t cChild = pProvider->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IXMLNode::TXMLNodePtr pNode = pProvider->GetChildNode(i);
- tstring sName = pNode->GetName();
- if (0 == quotes_stricmp(_T("section"), sName.c_str()))
- {
- CQuotesProviderBase::CQuoteSection qs;
- if (true == parse_section(pNode, qs))
- {
- aSections.push_back(qs);
- }
- }
- else if (0 == quotes_stricmp(_T("Name"), sName.c_str()))
- {
- res.m_pi.m_sName = pNode->GetText();
- }
- else if (0 == quotes_stricmp(_T("ref"), sName.c_str()))
- {
- res.m_pi.m_sURL = pNode->GetText();
- }
- else if (0 == quotes_stricmp(_T("url"), sName.c_str()))
- {
- res.m_sURL = pNode->GetText();
- }
+ return pProvider;
+}
+
+CQuotesProviderBase::CXMLFileInfo parse_ini_file(const tstring& rsXMLFile, bool& rbSucceded)
+{
+ CQuotesProviderBase::CXMLFileInfo res;
+ CQuotesProviderBase::CQuoteSection::TSections aSections;
+
+ const CModuleInfo::TXMLEnginePtr& pXMLEngine = CModuleInfo::GetXMLEnginePtr();
+ IXMLNode::TXMLNodePtr pRoot = pXMLEngine->LoadFile(rsXMLFile);
+ if (pRoot) {
+ IXMLNode::TXMLNodePtr pProvider = find_provider(pRoot);
+ if (pProvider) {
+ rbSucceded = true;
+ size_t cChild = pProvider->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IXMLNode::TXMLNodePtr pNode = pProvider->GetChildNode(i);
+ tstring sName = pNode->GetName();
+ if (0 == quotes_stricmp(_T("section"), sName.c_str())) {
+ CQuotesProviderBase::CQuoteSection qs;
+ if (true == parse_section(pNode, qs))
+ aSections.push_back(qs);
}
+ else if (0 == quotes_stricmp(_T("Name"), sName.c_str()))
+ res.m_pi.m_sName = pNode->GetText();
+ else if (0 == quotes_stricmp(_T("ref"), sName.c_str()))
+ res.m_pi.m_sURL = pNode->GetText();
+ else if (0 == quotes_stricmp(_T("url"), sName.c_str()))
+ res.m_sURL = pNode->GetText();
}
}
-
- res.m_qs = CQuotesProviderBase::CQuoteSection(res.m_pi.m_sName, aSections);
- return res;
}
- CQuotesProviderBase::CXMLFileInfo init_xml_info(LPCTSTR pszFileName, bool& rbSucceded)
- {
- rbSucceded = false;
- tstring sIniFile = get_ini_file_name(pszFileName);
- return parse_ini_file(sIniFile, rbSucceded);
- }
+ res.m_qs = CQuotesProviderBase::CQuoteSection(res.m_pi.m_sName, aSections);
+ return res;
+}
+
+CQuotesProviderBase::CXMLFileInfo init_xml_info(LPCTSTR pszFileName, bool& rbSucceded)
+{
+ rbSucceded = false;
+ tstring sIniFile = get_ini_file_name(pszFileName);
+ return parse_ini_file(sIniFile, rbSucceded);
}
CQuotesProviderBase::CQuotesProviderBase()
@@ -187,8 +153,7 @@ CQuotesProviderBase::~CQuotesProviderBase() bool CQuotesProviderBase::Init()
{
bool bSucceded = m_pXMLInfo != NULL;
- if (!m_pXMLInfo)
- {
+ if (!m_pXMLInfo) {
CQuotesProviderVisitorDbSettings visitor;
Accept(visitor);
assert(visitor.m_pszXMLIniFileName);
@@ -246,426 +211,337 @@ void CQuotesProviderBase::DeleteContact(MCONTACT hContact) TContracts::iterator i = std::find(m_aContacts.begin(), m_aContacts.end(), hContact);
if (i != m_aContacts.end())
- {
m_aContacts.erase(i);
- }
}
void CQuotesProviderBase::SetContactStatus(MCONTACT hContact, int nNewStatus)
{
int nStatus = db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_STATUS, ID_STATUS_OFFLINE);
- if (nNewStatus != nStatus)
- {
+ if (nNewStatus != nStatus) {
db_set_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_STATUS, nNewStatus);
- if (ID_STATUS_ONLINE != nNewStatus)
- {
+ if (ID_STATUS_ONLINE != nNewStatus) {
db_unset(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME);
tstring sSymbol = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL);
if (false == sSymbol.empty())
- {
db_set_ts(hContact, LIST_MODULE_NAME, CONTACT_LIST_NAME, sSymbol.c_str());
- }
SetContactExtraImage(hContact, eiEmpty);
}
}
}
-namespace
+class CTendency
{
- class CTendency
+ enum { NumValues = 2 };
+ enum EComparison
{
- enum{ NumValues = 2 };
- enum EComparison
- {
- NonValid,
- Greater,
- Less,
- Equal,
- GreaterOrEqual,
- LessOrEqual
- };
-
- public:
- enum EResult
- {
- NotChanged,
- Up,
- Down
- };
-
- public:
- CTendency() : m_nComparison(NonValid){}
-
- bool Parse(const IQuotesProvider* pProvider, const tstring& rsFrmt, MCONTACT hContact)
- {
- m_abValueFlags[0] = false;
- m_abValueFlags[1] = false;
- m_nComparison = NonValid;
- bool bValid = true;
- int nCurValue = 0;
- for (tstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end() && bValid && nCurValue < NumValues;)
- {
- TCHAR chr = *i;
- switch (chr)
- {
- default:
- if (false == std::isspace(chr))
- {
- bValid = false;
- }
- else
- {
- ++i;
- }
- break;
- case _T('%'):
- ++i;
- if (i != rsFrmt.end())
- {
- TCHAR t = *i;
- ++i;
- CQuotesProviderVisitorTendency visitor(hContact, t);
- pProvider->Accept(visitor);
- if (false == visitor.IsValid())
- {
- bValid = false;
- }
- else
- {
- double d = visitor.GetResult();
- m_adValues[nCurValue] = d;
- m_abValueFlags[nCurValue] = true;
- ++nCurValue;
- }
- }
- else
- {
- bValid = false;
- }
- break;
- case _T('>'):
- m_nComparison = Greater;
- ++i;
- break;
- case _T('<'):
- m_nComparison = Less;
- ++i;
- break;
- case _T('='):
- switch (m_nComparison)
- {
- default:
- bValid = false;
- break;
- case NonValid:
- m_nComparison = Equal;
- break;
- case Greater:
- m_nComparison = GreaterOrEqual;
- break;
- case Less:
- m_nComparison = LessOrEqual;
- break;
- }
- ++i;
- break;
- }
- }
+ NonValid,
+ Greater,
+ Less,
+ Equal,
+ GreaterOrEqual,
+ LessOrEqual
+ };
- return (bValid && IsValid());
- }
+public:
+ enum EResult
+ {
+ NotChanged,
+ Up,
+ Down
+ };
- bool IsValid()const{ return (m_abValueFlags[0] && m_abValueFlags[1] && (m_nComparison != NonValid)); }
+public:
+ CTendency() : m_nComparison(NonValid) {}
- EResult Compare()const
- {
- switch (m_nComparison)
- {
- case Greater:
- if (true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
- {
- return NotChanged;
- }
- else if (m_adValues[0] > m_adValues[1])
- {
- return Up;
- }
- else //if(m_adValues[0] < m_adValues[1])
- {
- return Down;
- }
+ bool Parse(const IQuotesProvider* pProvider, const tstring& rsFrmt, MCONTACT hContact)
+ {
+ m_abValueFlags[0] = false;
+ m_abValueFlags[1] = false;
+ m_nComparison = NonValid;
+ bool bValid = true;
+ int nCurValue = 0;
+ for (tstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end() && bValid && nCurValue < NumValues;) {
+ TCHAR chr = *i;
+ switch (chr) {
+ default:
+ if (false == std::isspace(chr))
+ bValid = false;
+ else
+ ++i;
break;
- case GreaterOrEqual:
- if ((true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
- || (m_adValues[0] > m_adValues[1]))
- {
- return Up;
- }
- else //if(m_adValues[0] < m_adValues[1])
- {
- return Down;
+
+ case _T('%'):
+ ++i;
+ if (i != rsFrmt.end()) {
+ TCHAR t = *i;
+ ++i;
+ CQuotesProviderVisitorTendency visitor(hContact, t);
+ pProvider->Accept(visitor);
+ if (false == visitor.IsValid()) {
+ bValid = false;
+ }
+ else {
+ double d = visitor.GetResult();
+ m_adValues[nCurValue] = d;
+ m_abValueFlags[nCurValue] = true;
+ ++nCurValue;
+ }
}
+ else bValid = false;
break;
- case Less:
- if (true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
- {
- return NotChanged;
- }
- else if (m_adValues[0] < m_adValues[1])
- {
- return Up;
- }
- else //if(m_adValues[0] > m_adValues[1])
- {
- return Down;
- }
+ case _T('>'):
+ m_nComparison = Greater;
+ ++i;
break;
- case LessOrEqual:
- if ((true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
- || (m_adValues[0] < m_adValues[1]))
- {
- return Up;
- }
- else //if(m_adValues[0] > m_adValues[1])
- {
- return Down;
- }
+ case _T('<'):
+ m_nComparison = Less;
+ ++i;
break;
- case Equal:
- if (true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
- {
- return Up;
- }
- else
- {
- return Down;
+ case _T('='):
+ switch (m_nComparison) {
+ default:
+ bValid = false;
+ break;
+ case NonValid:
+ m_nComparison = Equal;
+ break;
+ case Greater:
+ m_nComparison = GreaterOrEqual;
+ break;
+ case Less:
+ m_nComparison = LessOrEqual;
+ break;
}
+ ++i;
break;
}
- return NotChanged;
}
- private:
- double m_adValues[NumValues];
- bool m_abValueFlags[NumValues];
- EComparison m_nComparison;
- };
+ return (bValid && IsValid());
+ }
- tstring format_rate(const IQuotesProvider* pProvider,
- MCONTACT hContact,
- const tstring& rsFrmt)
+ bool IsValid()const { return (m_abValueFlags[0] && m_abValueFlags[1] && (m_nComparison != NonValid)); }
+
+ EResult Compare()const
{
- tstring sResult;
+ switch (m_nComparison) {
+ case Greater:
+ if (true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
+ return NotChanged;
+
+ if (m_adValues[0] > m_adValues[1])
+ return Up;
+ return Down;
+
+ case GreaterOrEqual:
+ if ((true == IsWithinAccuracy(m_adValues[0], m_adValues[1])) || (m_adValues[0] > m_adValues[1]))
+ return Up;
+ return Down;
+
+ case Less:
+ if (true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
+ return NotChanged;
+
+ if (m_adValues[0] < m_adValues[1])
+ return Up;
+ return Down;
+
+ case LessOrEqual:
+ if ((true == IsWithinAccuracy(m_adValues[0], m_adValues[1])) || (m_adValues[0] < m_adValues[1]))
+ return Up;
+ return Down;
+
+ case Equal:
+ if (true == IsWithinAccuracy(m_adValues[0], m_adValues[1]))
+ return Up;
+ return Down;
+ }
+ return NotChanged;
+ }
- for (tstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end();)
- {
- TCHAR chr = *i;
- switch (chr)
- {
- default:
- sResult += chr;
- ++i;
- break;
- case _T('\\'):
- ++i;
- if (i != rsFrmt.end())
- {
- TCHAR t = *i;
- switch (t)
- {
- case _T('%'):sResult += _T("%"); break;
- case _T('t'):sResult += _T("\t"); break;
- case _T('n'):sResult += _T("\n"); break;
- case _T('\\'):sResult += _T("\\"); break;
- default:sResult += chr; sResult += t; break;
- }
- ++i;
- }
- else
- {
- sResult += chr;
+private:
+ double m_adValues[NumValues];
+ bool m_abValueFlags[NumValues];
+ EComparison m_nComparison;
+};
+
+tstring format_rate(const IQuotesProvider *pProvider, MCONTACT hContact, const tstring &rsFrmt)
+{
+ tstring sResult;
+
+ for (tstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end();) {
+ TCHAR chr = *i;
+ switch (chr) {
+ default:
+ sResult += chr;
+ ++i;
+ break;
+
+ case _T('\\'):
+ ++i;
+ if (i != rsFrmt.end()) {
+ TCHAR t = *i;
+ switch (t) {
+ case _T('%'): sResult += _T("%"); break;
+ case _T('t'): sResult += _T("\t"); break;
+ case _T('n'): sResult += _T("\n"); break;
+ case _T('\\'): sResult += _T("\\"); break;
+ default: sResult += chr; sResult += t; break;
}
- break;
- case _T('%'):
++i;
- if (i != rsFrmt.end())
- {
- chr = *i;
-
- byte nWidth = 0;
- if (::isdigit(chr))
- {
- nWidth = chr - 0x30;
- ++i;
- if (i == rsFrmt.end())
- {
- sResult += chr;
- break;
- }
- else
- {
- chr = *i;
- }
- }
+ }
+ else sResult += chr;
+ break;
- CQuotesProviderVisitorFormater visitor(hContact, chr, nWidth);
- pProvider->Accept(visitor);
- const tstring& s = visitor.GetResult();
- sResult += s;
+ case _T('%'):
+ ++i;
+ if (i != rsFrmt.end()) {
+ chr = *i;
+
+ byte nWidth = 0;
+ if (::isdigit(chr)) {
+ nWidth = chr - 0x30;
++i;
+ if (i == rsFrmt.end()) {
+ sResult += chr;
+ break;
+ }
+ else chr = *i;
}
- else
- {
- sResult += chr;
- }
- break;
+
+ CQuotesProviderVisitorFormater visitor(hContact, chr, nWidth);
+ pProvider->Accept(visitor);
+ const tstring& s = visitor.GetResult();
+ sResult += s;
+ ++i;
}
+ else sResult += chr;
+ break;
}
-
- return sResult;
}
- void log_to_file(const IQuotesProvider* pProvider,
- MCONTACT hContact,
- const tstring& rsLogFileName,
- const tstring& rsFormat)
- {
- // USES_CONVERSION;
- // const char* pszPath = CT2A(rsLogFileName.c_str());
- std::string sPath = quotes_t2a(rsLogFileName.c_str());
-
- std::string::size_type n = sPath.find_last_of("\\/");
- if (std::string::npos != n)
- {
- sPath.erase(n);
- }
- DWORD dwAttributes = ::GetFileAttributesA(sPath.c_str());
- if ((0xffffffff == dwAttributes) || (0 == (dwAttributes&FILE_ATTRIBUTE_DIRECTORY)))
- CreateDirectoryTree(sPath.c_str());
-
- tofstream file(rsLogFileName.c_str(), std::ios::app | std::ios::out);
- file.imbue(GetSystemLocale());
- if (file.good())
- {
- tstring s = format_rate(pProvider, hContact, rsFormat);
- file << s;
- }
- }
+ return sResult;
+}
- void log_to_history(const IQuotesProvider* pProvider,
- MCONTACT hContact,
- time_t nTime,
- const tstring& rsFormat)
- {
+void log_to_file(const IQuotesProvider* pProvider,
+ MCONTACT hContact,
+ const tstring& rsLogFileName,
+ const tstring& rsFormat)
+{
+ std::string sPath = quotes_t2a(rsLogFileName.c_str());
+
+ std::string::size_type n = sPath.find_last_of("\\/");
+ if (std::string::npos != n)
+ sPath.erase(n);
+
+ DWORD dwAttributes = ::GetFileAttributesA(sPath.c_str());
+ if ((0xffffffff == dwAttributes) || (0 == (dwAttributes&FILE_ATTRIBUTE_DIRECTORY)))
+ CreateDirectoryTree(sPath.c_str());
+
+ tofstream file(rsLogFileName.c_str(), std::ios::app | std::ios::out);
+ file.imbue(GetSystemLocale());
+ if (file.good()) {
tstring s = format_rate(pProvider, hContact, rsFormat);
- T2Utf psz(s.c_str());
-
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = QUOTES_PROTOCOL_NAME;
- dbei.timestamp = static_cast<DWORD>(nTime);
- dbei.flags = DBEF_READ | DBEF_UTF;
- dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.cbBlob = (int)::mir_strlen(psz) + 1;
- dbei.pBlob = (PBYTE)(char*)psz;
- db_event_add(hContact, &dbei);
+ file << s;
}
+}
- bool do_set_contact_extra_icon(MCONTACT hContact, const CTendency& tendency)
- {
- CTendency::EResult nComparison = tendency.Compare();
+void log_to_history(const IQuotesProvider* pProvider,
+ MCONTACT hContact,
+ time_t nTime,
+ const tstring& rsFormat)
+{
+ tstring s = format_rate(pProvider, hContact, rsFormat);
+ T2Utf psz(s.c_str());
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = QUOTES_PROTOCOL_NAME;
+ dbei.timestamp = static_cast<DWORD>(nTime);
+ dbei.flags = DBEF_READ | DBEF_UTF;
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = (int)::mir_strlen(psz) + 1;
+ dbei.pBlob = (PBYTE)(char*)psz;
+ db_event_add(hContact, &dbei);
+}
- //if(true == IsWithinAccuracy(dCurrRate,dPrevRate))
- if (CTendency::NotChanged == nComparison)
- return SetContactExtraImage(hContact, eiNotChanged);
+bool do_set_contact_extra_icon(MCONTACT hContact, const CTendency& tendency)
+{
+ CTendency::EResult nComparison = tendency.Compare();
- if (CTendency::Up == nComparison)//(dCurrRate > dPrevRate)
- return SetContactExtraImage(hContact, eiUp);
+ if (CTendency::NotChanged == nComparison)
+ return SetContactExtraImage(hContact, eiNotChanged);
- if (CTendency::Down == nComparison)//(dCurrRate < dPrevRate)
- return SetContactExtraImage(hContact, eiDown);
+ if (CTendency::Up == nComparison)
+ return SetContactExtraImage(hContact, eiUp);
- return false;
- }
+ if (CTendency::Down == nComparison)
+ return SetContactExtraImage(hContact, eiDown);
- bool show_popup(const IQuotesProvider* pProvider,
- MCONTACT hContact,
- const CTendency& tendency,
- const tstring& rsFormat,
- const CPopupSettings& ps)
- {
- if (1 == ServiceExists(MS_POPUP_ADDPOPUPT))
- {
- POPUPDATAT ppd;
- memset(&ppd, 0, sizeof(ppd));
- ppd.lchContact = hContact;
- //if((true == bValidPrevRate))
- if (tendency.IsValid())
- {
- CTendency::EResult nComparison = tendency.Compare();
- if (CTendency::NotChanged == nComparison)//(true == IsWithinAccuracy(dRate,dPrevRate))
- {
- ppd.lchIcon = Quotes_LoadIconEx(ICON_STR_QUOTE_NOT_CHANGED);
- }
- else if (CTendency::Up == nComparison)//(dRate > dPrevRate)
- {
- ppd.lchIcon = Quotes_LoadIconEx(ICON_STR_QUOTE_UP);
- }
- else if (CTendency::Down == nComparison)
- {
- ppd.lchIcon = Quotes_LoadIconEx(ICON_STR_QUOTE_DOWN);
- }
- }
+ return false;
+}
- CQuotesProviderVisitorFormater visitor(hContact, _T('s'), 0);
- pProvider->Accept(visitor);
- const tstring& sTitle = visitor.GetResult();
- mir_tstrncpy(ppd.lptzContactName, sTitle.c_str(), MAX_CONTACTNAME);
+bool show_popup(const IQuotesProvider* pProvider,
+ MCONTACT hContact,
+ const CTendency& tendency,
+ const tstring& rsFormat,
+ const CPopupSettings& ps)
+{
+ if (!ServiceExists(MS_POPUP_ADDPOPUPT))
+ return false;
- mir_safe_string<TCHAR> ss(variables_parsedup((TCHAR*)rsFormat.c_str(), 0, hContact));
- tstring sText = format_rate(pProvider, hContact, ss.m_p);
- mir_tstrncpy(ppd.lptzText, sText.c_str(), MAX_SECONDLINE);
+ POPUPDATAT ppd;
+ memset(&ppd, 0, sizeof(ppd));
+ ppd.lchContact = hContact;
- if (CPopupSettings::colourDefault == ps.GetColourMode())
- {
- ppd.colorText = CPopupSettings::GetDefColourText();
- ppd.colorBack = CPopupSettings::GetDefColourBk();
- }
- else
- {
- ppd.colorText = ps.GetColourText();
- ppd.colorBack = ps.GetColourBk();
- }
+ if (tendency.IsValid()) {
+ CTendency::EResult nComparison = tendency.Compare();
+ if (CTendency::NotChanged == nComparison)
+ ppd.lchIcon = Quotes_LoadIconEx(IDI_ICON_NOTCHANGED);
+ else if (CTendency::Up == nComparison)
+ ppd.lchIcon = Quotes_LoadIconEx(IDI_ICON_UP);
+ else if (CTendency::Down == nComparison)
+ ppd.lchIcon = Quotes_LoadIconEx(IDI_ICON_DOWN);
+ }
- switch (ps.GetDelayMode())
- {
- default:
- assert(!"Unknown popup delay mode");
- case CPopupSettings::delayFromPopup:
- ppd.iSeconds = 0;
- break;
- case CPopupSettings::delayPermanent:
- ppd.iSeconds = -1;
- break;
- case CPopupSettings::delayCustom:
- ppd.iSeconds = ps.GetDelayTimeout();
- break;
- }
+ CQuotesProviderVisitorFormater visitor(hContact, _T('s'), 0);
+ pProvider->Accept(visitor);
+ const tstring& sTitle = visitor.GetResult();
+ mir_tstrncpy(ppd.lptzContactName, sTitle.c_str(), MAX_CONTACTNAME);
- LPARAM lp = 0;
- if (false == ps.GetHistoryFlag())
- {
- lp |= 0x08;
- }
+ mir_safe_string<TCHAR> ss(variables_parsedup((TCHAR*)rsFormat.c_str(), 0, hContact));
+ tstring sText = format_rate(pProvider, hContact, ss.m_p);
+ mir_tstrncpy(ppd.lptzText, sText.c_str(), MAX_SECONDLINE);
- return (0 == CallService(MS_POPUP_ADDPOPUPT, reinterpret_cast<WPARAM>(&ppd), lp));
- }
- else
- {
- return false;
- }
+ if (CPopupSettings::colourDefault == ps.GetColourMode()) {
+ ppd.colorText = CPopupSettings::GetDefColourText();
+ ppd.colorBack = CPopupSettings::GetDefColourBk();
+ }
+ else {
+ ppd.colorText = ps.GetColourText();
+ ppd.colorBack = ps.GetColourBk();
+ }
+
+ switch (ps.GetDelayMode()) {
+ default:
+ assert(!"Unknown popup delay mode");
+ case CPopupSettings::delayFromPopup:
+ ppd.iSeconds = 0;
+ break;
+ case CPopupSettings::delayPermanent:
+ ppd.iSeconds = -1;
+ break;
+ case CPopupSettings::delayCustom:
+ ppd.iSeconds = ps.GetDelayTimeout();
+ break;
}
+
+ LPARAM lp = 0;
+ if (false == ps.GetHistoryFlag())
+ lp |= 0x08;
+
+ return (0 == CallService(MS_POPUP_ADDPOPUPT, reinterpret_cast<WPARAM>(&ppd), lp));
}
void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, const tstring& rsSymbol/* = ""*/)
@@ -673,16 +549,12 @@ void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, cons time_t nTime = ::time(NULL);
if (false == rsSymbol.empty())
- {
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL, rsSymbol.c_str());
- }
double dPrev = 0.0;
bool bValidPrev = Quotes_DBReadDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_CURR_VALUE, dPrev);
if (true == bValidPrev)
- {
Quotes_DBWriteDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_PREV_VALUE, dPrev);
- }
Quotes_DBWriteDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_CURR_VALUE, dRate);
db_set_dw(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FETCH_TIME, nTime);
@@ -691,17 +563,14 @@ void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, cons tostringstream oNick;
oNick.imbue(GetSystemLocale());
- if (false == m_sContactListFormat.empty())
- {
+ if (false == m_sContactListFormat.empty()) {
tstring s = format_rate(this, hContact, m_sContactListFormat);
oNick << s;
}
- else
- {
+ else {
if (true == sSymbol.empty())
- {
sSymbol = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL);
- }
+
oNick << std::setfill(_T(' ')) << std::setw(10) << std::left << sSymbol << std::setw(6) << std::right << dRate;
}
CTendency tendency;
@@ -713,13 +582,9 @@ void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, cons tstring sStatusMsg = format_rate(this, hContact, m_sStatusMsgFormat);
if (false == sStatusMsg.empty())
- {
db_set_ts(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME, sStatusMsg.c_str());
- }
else
- {
db_unset(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME);
- }
bool bUseContactSpecific = (db_get_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_CONTACT_SPEC_SETTINGS, 0) > 0);
@@ -728,32 +593,27 @@ void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, cons WORD dwMode = (bUseContactSpecific)
? db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG, static_cast<WORD>(lmDisabled))
: global_settings.GetLogMode();
- if (dwMode&lmExternalFile)
- {
+ if (dwMode&lmExternalFile) {
bool bAdd = true;
bool bOnlyIfChanged = (bUseContactSpecific)
? (db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG_FILE_CONDITION, 1) > 0)
: global_settings.GetLogOnlyChangedFlag();
- if (true == bOnlyIfChanged)
- {
+ if (true == bOnlyIfChanged) {
bAdd = ((false == bValidPrev) || (false == IsWithinAccuracy(dRate, dPrev)));
}
- if (true == bAdd)
- {
+ if (true == bAdd) {
tstring sLogFileName = (bUseContactSpecific)
? Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG_FILE, global_settings.GetLogFileName().c_str())
: global_settings.GetLogFileName();
- if (true == sSymbol.empty())
- {
+ if (true == sSymbol.empty()) {
sSymbol = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL);
}
sLogFileName = GenerateLogFileName(sLogFileName, sSymbol);
tstring sFormat = global_settings.GetLogFormat();
- if (bUseContactSpecific)
- {
+ if (bUseContactSpecific) {
CQuotesProviderVisitorDbSettings visitor;
Accept(visitor);
sFormat = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_LOG_FILE, visitor.m_pszDefLogFileFormat);
@@ -762,19 +622,16 @@ void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, cons log_to_file(this, hContact, sLogFileName, sFormat);
}
}
- if (dwMode&lmInternalHistory)
- {
+ if (dwMode&lmInternalHistory) {
bool bAdd = true;
bool bOnlyIfChanged = (bUseContactSpecific)
? (db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_HISTORY_CONDITION, 1) > 0)
: global_settings.GetHistoryOnlyChangedFlag();
- if (true == bOnlyIfChanged)
- {
+ if (true == bOnlyIfChanged) {
bAdd = ((false == bValidPrev) || (false == IsWithinAccuracy(dRate, dPrev)));
}
- if (true == bAdd)
- {
+ if (true == bAdd) {
tstring sFormat = (bUseContactSpecific)
? Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_HISTORY, global_settings.GetHistoryFormat().c_str())
: global_settings.GetHistoryFormat();
@@ -783,14 +640,12 @@ void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, cons }
}
- if (dwMode&lmPopup)
- {
+ if (dwMode&lmPopup) {
bool bOnlyIfChanged = (bUseContactSpecific)
? (1 == db_get_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_POPUP_CONDITION, 1) > 0)
: global_settings.GetShowPopupIfValueChangedFlag();
if ((false == bOnlyIfChanged)
- || ((true == bOnlyIfChanged) && (true == bValidPrev) && (false == IsWithinAccuracy(dRate, dPrev))))
- {
+ || ((true == bOnlyIfChanged) && (true == bValidPrev) && (false == IsWithinAccuracy(dRate, dPrev)))) {
tstring sFormat = (bUseContactSpecific)
? Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_POPUP, global_settings.GetPopupFormat().c_str())
: global_settings.GetPopupFormat();
@@ -801,11 +656,7 @@ void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, cons }
}
-
- // if((true == IsOnline()))
- {
- SetContactStatus(hContact, ID_STATUS_ONLINE);
- }
+ SetContactStatus(hContact, ID_STATUS_ONLINE);
}
MCONTACT CQuotesProviderBase::CreateNewContact(const tstring& rsName)
@@ -830,67 +681,53 @@ MCONTACT CQuotesProviderBase::CreateNewContact(const tstring& rsName) return hContact;
}
-namespace
+DWORD get_refresh_timeout_miliseconds(const CQuotesProviderVisitorDbSettings& visitor)
{
- DWORD get_refresh_timeout_miliseconds(const CQuotesProviderVisitorDbSettings& visitor)
- {
- if (!g_bAutoUpdate)
- {
- return INFINITE;
- }
+ if (!g_bAutoUpdate)
+ return INFINITE;
- assert(visitor.m_pszDbRefreshRateType);
- assert(visitor.m_pszDbRefreshRateValue);
+ assert(visitor.m_pszDbRefreshRateType);
+ assert(visitor.m_pszDbRefreshRateValue);
- int nRefreshRateType = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateType, RRT_MINUTES);
- if (nRefreshRateType < RRT_SECONDS || nRefreshRateType > RRT_HOURS)
- {
- nRefreshRateType = RRT_MINUTES;
- }
+ int nRefreshRateType = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateType, RRT_MINUTES);
+ if (nRefreshRateType < RRT_SECONDS || nRefreshRateType > RRT_HOURS)
+ nRefreshRateType = RRT_MINUTES;
- DWORD nTimeout = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateValue, 1);
- switch (nRefreshRateType)
- {
- default:
- case RRT_SECONDS:
- if (nTimeout < 1 || nTimeout > 60)
- {
- nTimeout = 1;
- }
- nTimeout *= 1000;
- break;
- case RRT_MINUTES:
- if (nTimeout < 1 || nTimeout > 60)
- {
- nTimeout = 1;
- }
- nTimeout *= 1000 * 60;
- break;
- case RRT_HOURS:
- if (nTimeout < 1 || nTimeout > 24)
- {
- nTimeout = 1;
- }
- nTimeout *= 1000 * 60 * 60;
- break;
- }
+ DWORD nTimeout = db_get_w(NULL, QUOTES_MODULE_NAME, visitor.m_pszDbRefreshRateValue, 1);
+ switch (nRefreshRateType) {
+ default:
+ case RRT_SECONDS:
+ if (nTimeout < 1 || nTimeout > 60)
+ nTimeout = 1;
- return nTimeout;
+ nTimeout *= 1000;
+ break;
+ case RRT_MINUTES:
+ if (nTimeout < 1 || nTimeout > 60)
+ nTimeout = 1;
+
+ nTimeout *= 1000 * 60;
+ break;
+ case RRT_HOURS:
+ if (nTimeout < 1 || nTimeout > 24)
+ nTimeout = 1;
+
+ nTimeout *= 1000 * 60 * 60;
+ break;
}
+
+ return nTimeout;
}
-namespace
+class CBoolGuard
{
- class CBoolGuard
- {
- public:
- CBoolGuard(bool& rb) : m_b(rb){ m_b = true; }
- ~CBoolGuard(){ m_b = false; }
+public:
+ CBoolGuard(bool& rb) : m_b(rb) { m_b = true; }
+ ~CBoolGuard() { m_b = false; }
- private:
- bool m_b;
- };
-}
+private:
+ bool m_b;
+};
void CQuotesProviderBase::Run()
{
@@ -902,7 +739,8 @@ void CQuotesProviderBase::Run() m_sStatusMsgFormat = Quotes_DBGetStringT(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbStatusMsgFormat, visitor.m_pszDefStatusMsgFormat);
m_sTendencyFormat = Quotes_DBGetStringT(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbTendencyFormat, visitor.m_pszDefTendencyFormat);
- enum{
+ enum
+ {
STOP_THREAD = 0,
SETTINGS_CHANGED = 1,
REFRESH_CONTACT = 2,
@@ -922,49 +760,47 @@ void CQuotesProviderBase::Run() bool bGoToBed = false;
- if (g_bAutoUpdate)
- {
+ if (g_bAutoUpdate) {
CBoolGuard bg(m_bRefreshInProgress);
RefreshQuotes(anContacts);
}
- while (false == bGoToBed)
- {
+ while (false == bGoToBed) {
anContacts.clear();
DWORD dwBegin = ::GetTickCount();
DWORD dwResult = ::WaitForMultipleObjects(COUNT_SYNC_OBJECTS, anEvents, FALSE, nTimeout);
- switch (dwResult)
- {
+ switch (dwResult) {
case WAIT_FAILED:
assert(!"WaitForMultipleObjects failed");
bGoToBed = true;
break;
+
case WAIT_ABANDONED_0 + STOP_THREAD:
case WAIT_ABANDONED_0 + SETTINGS_CHANGED:
case WAIT_ABANDONED_0 + REFRESH_CONTACT:
assert(!"WaitForMultipleObjects abandoned");
+
case WAIT_OBJECT_0 + STOP_THREAD:
bGoToBed = true;
break;
+
case WAIT_OBJECT_0 + SETTINGS_CHANGED:
nTimeout = get_refresh_timeout_miliseconds(visitor);
m_sContactListFormat = Quotes_DBGetStringT(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbDisplayNameFormat, visitor.m_pszDefDisplayFormat);
m_sStatusMsgFormat = Quotes_DBGetStringT(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbStatusMsgFormat, visitor.m_pszDefStatusMsgFormat);
m_sTendencyFormat = Quotes_DBGetStringT(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbTendencyFormat, visitor.m_pszDefTendencyFormat);
-
{
mir_cslock lck(m_cs);
anContacts = m_aContacts;
}
break;
case WAIT_OBJECT_0 + REFRESH_CONTACT:
- {
- DWORD dwTimeRest = ::GetTickCount() - dwBegin;
- if (INFINITE != nTimeout && dwTimeRest < nTimeout)
{
- nTimeout -= dwTimeRest;
- }
+ DWORD dwTimeRest = ::GetTickCount() - dwBegin;
+ if (INFINITE != nTimeout && dwTimeRest < nTimeout) {
+ nTimeout -= dwTimeRest;
+ }
{
mir_cslock lck(m_cs);
@@ -976,8 +812,8 @@ void CQuotesProviderBase::Run() CBoolGuard bg(m_bRefreshInProgress);
RefreshQuotes(anContacts);
}
- }
- break;
+ }
+ break;
case WAIT_TIMEOUT:
nTimeout = get_refresh_timeout_miliseconds(visitor);
{
@@ -989,6 +825,7 @@ void CQuotesProviderBase::Run() RefreshQuotes(anContacts);
}
break;
+
default:
assert(!"What is the hell?");
}
@@ -1000,7 +837,7 @@ void CQuotesProviderBase::Run() void CQuotesProviderBase::OnEndRun()
{
TContracts anContacts;
- {// for CCritSection
+ {
mir_cslock lck(m_cs);
anContacts = m_aContacts;
m_aRefreshingContacts.clear();
@@ -1010,7 +847,7 @@ void CQuotesProviderBase::OnEndRun() std::for_each(anContacts.begin(), anContacts.end(), boost::bind(&SetContactStatus, _1, ID_STATUS_OFFLINE));
}
-void CQuotesProviderBase::Accept(CQuotesProviderVisitor& visitor)const
+void CQuotesProviderBase::Accept(CQuotesProviderVisitor &visitor)const
{
visitor.Visit(*this);
}
@@ -1026,7 +863,7 @@ void CQuotesProviderBase::RefreshAllContacts() {// for CCritSection
mir_cslock lck(m_cs);
m_aRefreshingContacts.clear();
- std::for_each(std::begin(m_aContacts), std::end(m_aContacts), [&](MCONTACT hContact){m_aRefreshingContacts.push_back(hContact); });
+ std::for_each(std::begin(m_aContacts), std::end(m_aContacts), [&](MCONTACT hContact) { m_aRefreshingContacts.push_back(hContact); });
}
BOOL b = ::SetEvent(m_hEventRefreshContact);
@@ -1043,32 +880,3 @@ void CQuotesProviderBase::RefreshContact(MCONTACT hContact) BOOL b = ::SetEvent(m_hEventRefreshContact);
assert(b && "Failed to set event");
}
-
-// void CQuotesProviderBase::SetContactExtraIcon(MCONTACT hContact)const
-// {
-// // tstring s = DBGetStringT(hContact,LIST_MODULE_NAME,CONTACT_LIST_NAME);
-// // tostringstream o;
-// // o << "Request on " << s << " refreshing\nIs online " << IsOnline() << ", is in progress " << m_bRefreshInProgress << "\n";
-//
-// bool bResult = false;
-// if(/*true == IsOnline() && */(false == m_bRefreshInProgress))
-// {
-// CTendency tendency;
-// if(tendency.Parse(this,m_sTendencyFormat,hContact) && (false == m_bRefreshInProgress))
-// {
-// bResult = do_set_contact_extra_icon(hContact,tendency);
-// }
-// // double dCurrRate = 0.0;
-// // double dPrevRate = 0.0;
-// // if((true == Quotes_DBReadDouble(hContact,QUOTES_PROTOCOL_NAME,DB_STR_QUOTE_CURR_VALUE,dCurrRate))
-// // && (true == Quotes_DBReadDouble(hContact,QUOTES_PROTOCOL_NAME,DB_STR_QUOTE_PREV_VALUE,dPrevRate))
-// // && (false == m_bRefreshInProgress))
-// // {
-// // // o << "Curr rate = " << dCurrRate << ", prev rate " << dPrevRate << "\n";
-// // bResult = do_set_contact_extra_icon(hContact,dCurrRate,dPrevRate);
-// // }
-// }
-//
-// // o << "Result is " << bResult;
-// // LogIt(Info,o.str());
-// }
diff --git a/plugins/Quotes/src/QuotesProviderDukasCopy.cpp b/plugins/Quotes/src/QuotesProviderDukasCopy.cpp index 43e91012c6..08b13fdd68 100644 --- a/plugins/Quotes/src/QuotesProviderDukasCopy.cpp +++ b/plugins/Quotes/src/QuotesProviderDukasCopy.cpp @@ -8,17 +8,14 @@ CQuotesProviderDukasCopy::~CQuotesProviderDukasCopy() {
}
-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 CQuotesProviderDukasCopy::IsQuoteWatched(const CQuote& rQuote)const
@@ -32,10 +29,9 @@ bool CQuotesProviderDukasCopy::WatchForQuote(const CQuote& rQuote, bool bWatch) const tstring& sQuoteID = rQuote.GetID();
TContracts::iterator i =
std::find_if(m_aContacts.begin(), m_aContacts.end(),
- boost::bind(is_quote_id_equal, _1, sQuoteID));
+ boost::bind(is_quote_id_equal, _1, sQuoteID));
- if ((false == bWatch) && (i != m_aContacts.end()))
- {
+ if ((false == bWatch) && (i != m_aContacts.end())) {
MCONTACT hContact = *i;
{// for CCritSection
mir_cslock lck(m_cs);
@@ -45,14 +41,11 @@ bool CQuotesProviderDukasCopy::WatchForQuote(const CQuote& rQuote, bool bWatch) CallService(MS_DB_CONTACT_DELETE, WPARAM(hContact), 0);
return true;
}
- else if ((true == bWatch) && (i == m_aContacts.end()))
- {
+ else if ((true == 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())
- {
+ if (false == rQuote.GetName().empty()) {
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_DESCRIPTION, rQuote.GetName().c_str());
}
@@ -70,149 +63,109 @@ tstring CQuotesProviderDukasCopy::BuildHTTPURL()const {
mir_cslock lck(m_cs);
- for (TContracts::const_iterator i = m_aContacts.begin(); i != m_aContacts.end(); ++i)
- {
+ for (TContracts::const_iterator i = m_aContacts.begin(); i != m_aContacts.end(); ++i) {
MCONTACT hContact = *i;
tstring sID = get_quote_id(hContact);
if (false == sID.empty())
- {
sURL << sID << _T(",");
- }
}
}
return sURL.str();
}
-namespace
+struct CEconomicRateInfo
{
- struct CEconomicRateInfo
- {
- CEconomicRateInfo() : m_dCurRate(0.0), m_dPrevRate(0.0) {}
- tstring m_sName;
- double m_dCurRate;
- double m_dPrevRate;
- tstring m_sID;
- };
-
- typedef std::vector<CEconomicRateInfo> TEconomicRates;
- typedef IHTMLNode::THTMLNodePtr THTMLNodePtr;
+ CEconomicRateInfo() : m_dCurRate(0.0), m_dPrevRate(0.0) {}
+ tstring m_sName;
+ double m_dCurRate;
+ double m_dPrevRate;
+ tstring m_sID;
+};
- bool string2double(const TCHAR* pszText, double& rValue)
- {
- assert(pszText);
- try
- {
- rValue = boost::lexical_cast<double>(pszText);
- }
- catch (boost::bad_lexical_cast &)
- {
- return false;
- }
+typedef std::vector<CEconomicRateInfo> TEconomicRates;
+typedef IHTMLNode::THTMLNodePtr THTMLNodePtr;
- return true;
+bool string2double(const TCHAR* pszText, double& rValue)
+{
+ assert(pszText);
+ try {
+ rValue = boost::lexical_cast<double>(pszText);
+ }
+ catch (boost::bad_lexical_cast &) {
+ return false;
}
+ return true;
+}
- void parse_row(const THTMLNodePtr& pRow, TEconomicRates& raRates)
- {
- CEconomicRateInfo ri;
- ri.m_sID = pRow->GetAttribute(_T("sid"));
- if (false == ri.m_sID.empty())
- {
- unsigned short cColsHandled = 0;
- tostringstream sSidID;
- sSidID << _T("id") << ri.m_sID;
- size_t cNodes = pRow->GetChildCount();
- for (size_t i = 0; i < cNodes && cColsHandled < 2; ++i)
- {
- THTMLNodePtr pCol = pRow->GetChildPtr(i);
- if (pCol)
- {
- tstring sColID = pCol->GetAttribute(_T("id"));
- if (false == sColID.empty())
- {
- if (0 == quotes_stricmp(sColID.c_str(), _T("stock")))
- {
- ri.m_sName = pCol->GetText();
- if (false == ri.m_sName.empty())
- {
- ++cColsHandled;
- }
+
+void parse_row(const THTMLNodePtr& pRow, TEconomicRates& raRates)
+{
+ CEconomicRateInfo ri;
+ ri.m_sID = pRow->GetAttribute(_T("sid"));
+ if (false == ri.m_sID.empty()) {
+ unsigned short cColsHandled = 0;
+ tostringstream sSidID;
+ sSidID << _T("id") << ri.m_sID;
+ size_t cNodes = pRow->GetChildCount();
+ for (size_t i = 0; i < cNodes && cColsHandled < 2; ++i) {
+ THTMLNodePtr pCol = pRow->GetChildPtr(i);
+ if (pCol) {
+ tstring sColID = pCol->GetAttribute(_T("id"));
+ if (false == sColID.empty()) {
+ if (0 == quotes_stricmp(sColID.c_str(), _T("stock"))) {
+ ri.m_sName = pCol->GetText();
+ if (false == ri.m_sName.empty()) {
+ ++cColsHandled;
}
- else if (0 == quotes_stricmp(sSidID.str().c_str(), sColID.c_str()))
- {
- tstring sRate = pCol->GetText();
- if ((false == sRate.empty()) && (true == string2double(sRate.c_str(), ri.m_dCurRate)))
- {
- ri.m_dPrevRate = ri.m_dCurRate;
- ++cColsHandled;
- tstring sOldRate = pCol->GetAttribute(_T("oldPrice"));
- if (false == sOldRate.empty())
- {
- string2double(sOldRate.c_str(), ri.m_dPrevRate);
- }
+ }
+ else if (0 == quotes_stricmp(sSidID.str().c_str(), sColID.c_str())) {
+ tstring sRate = pCol->GetText();
+ if ((false == sRate.empty()) && (true == string2double(sRate.c_str(), ri.m_dCurRate))) {
+ ri.m_dPrevRate = ri.m_dCurRate;
+ ++cColsHandled;
+ tstring sOldRate = pCol->GetAttribute(_T("oldPrice"));
+ if (false == sOldRate.empty()) {
+ string2double(sOldRate.c_str(), ri.m_dPrevRate);
}
}
}
}
}
-
- if (2 == cColsHandled)
- {
- raRates.push_back(ri);
- }
}
+
+ if (2 == cColsHandled)
+ raRates.push_back(ri);
}
+}
- // void parse_table(const THTMLNodePtr& pNode,TEconomicRates& raRates)
- // {
- // size_t cNodes = pNode->GetChildCount();
- // for(size_t i = 0;i < cNodes;++i)
- // {
- // THTMLNodePtr pChild = pNode->GetChildPtr(i);
- // if(pChild && pChild->Is(IHTMLNode::TableRow))
- // {
- // parse_row(pChild,raRates);
- // }
- // }
- //
- // }
-
- void parser_html_node(const THTMLNodePtr& pNode, TEconomicRates& raRates)
- {
- size_t cNodes = pNode->GetChildCount();
- for (size_t i = 0; i < cNodes; ++i)
- {
- THTMLNodePtr pChild = pNode->GetChildPtr(i);
- if (pChild && pChild->Is(IHTMLNode::TableRow))
- {
- parse_row(pChild, raRates);
- }
- }
+void parser_html_node(const THTMLNodePtr& pNode, TEconomicRates& raRates)
+{
+ size_t cNodes = pNode->GetChildCount();
+ for (size_t i = 0; i < cNodes; ++i) {
+ THTMLNodePtr pChild = pNode->GetChildPtr(i);
+ if (pChild && pChild->Is(IHTMLNode::TableRow))
+ parse_row(pChild, raRates);
}
+}
- bool parse_HTML(const tstring& sHTML, TEconomicRates& raRates)
- {
- IHTMLEngine::THTMLParserPtr pHTMLParser = CModuleInfo::GetHTMLEngine()->GetParserPtr();
- THTMLNodePtr pRoot = pHTMLParser->ParseString(sHTML);
- if (pRoot)
- {
- parser_html_node(pRoot, raRates);
- return true;
- }
- else
- {
- return false;
- }
+bool parse_HTML(const tstring& sHTML, TEconomicRates& raRates)
+{
+ IHTMLEngine::THTMLParserPtr pHTMLParser = CModuleInfo::GetHTMLEngine()->GetParserPtr();
+ THTMLNodePtr pRoot = pHTMLParser->ParseString(sHTML);
+ if (pRoot) {
+ parser_html_node(pRoot, raRates);
+ return true;
}
+
+ return false;
}
void CQuotesProviderDukasCopy::RefreshQuotes(TContracts& anContacts)
{
- if (CModuleInfo::GetInstance().GetExtendedStatusFlag())
- {
+ if (CModuleInfo::GetInstance().GetExtendedStatusFlag()) {
std::for_each(anContacts.begin(), anContacts.end(),
boost::bind(SetContactStatus, _1, ID_STATUS_OCCUPIED));
}
@@ -221,28 +174,23 @@ void CQuotesProviderDukasCopy::RefreshQuotes(TContracts& anContacts) CHTTPSession http;
// LogIt(Info,sURL);
- if (true == http.OpenURL(sURL))
- {
+ if (true == http.OpenURL(sURL)) {
// if(true == IsOnline())
{
tstring sHTML;
- if (true == http.ReadResponce(sHTML))
- {
+ if (true == http.ReadResponce(sHTML)) {
// LogIt(Info,sHTML);
// if(true == IsOnline())
{
TEconomicRates aRates;
if (true == parse_HTML(sHTML, aRates)
- && (true == IsOnline()))
- {
- for (TEconomicRates::const_iterator it = aRates.begin(); (it != aRates.end()) && (true == IsOnline()); ++it)
- {
+ && (true == IsOnline())) {
+ for (TEconomicRates::const_iterator it = aRates.begin(); (it != aRates.end()) && (true == IsOnline()); ++it) {
const CEconomicRateInfo& ri = *it;
TContracts::iterator i = std::find_if(anContacts.begin(), anContacts.end(),
boost::bind(is_quote_id_equal, _1, ri.m_sID));
- if (i != anContacts.end() && (true == IsOnline()))
- {
+ if (i != anContacts.end() && (true == IsOnline())) {
MCONTACT hContact = *i;
anContacts.erase(i);
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(),
- ["e](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(),
+ ["e](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;
}
}
diff --git a/plugins/Quotes/src/QuotesProviderGoogle.cpp b/plugins/Quotes/src/QuotesProviderGoogle.cpp index c375d1506f..87e05f09c7 100644 --- a/plugins/Quotes/src/QuotesProviderGoogle.cpp +++ b/plugins/Quotes/src/QuotesProviderGoogle.cpp @@ -8,24 +8,21 @@ CQuotesProviderGoogle::~CQuotesProviderGoogle() {
}
-namespace
+inline tstring make_contact_name(const tstring& rsSymbolFrom, const tstring& rsSymbolTo)
{
- inline tstring make_contact_name(const tstring& rsSymbolFrom, const tstring& rsSymbolTo)
- {
- tostringstream o;
- o << rsSymbolFrom << _T("/") << rsSymbolTo;
- return o.str();
- }
+ tostringstream o;
+ o << rsSymbolFrom << _T("/") << 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 == quotes_stricmp(from.GetID().c_str(), sFrom.c_str()))
- && (0 == quotes_stricmp(to.GetID().c_str(), sTo.c_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 == quotes_stricmp(from.GetID().c_str(), sFrom.c_str()))
+ && (0 == quotes_stricmp(to.GetID().c_str(), sTo.c_str())));
}
bool CQuotesProviderGoogle::WatchForRate(const CRateInfo& ri,
@@ -33,28 +30,23 @@ bool CQuotesProviderGoogle::WatchForRate(const CRateInfo& ri, {
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()))
- {
+ 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)
- {
+ if (hContact) {
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_ID, ri.m_from.GetID().c_str());
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_ID, ri.m_to.GetID().c_str());
- if (false == ri.m_from.GetName().empty())
- {
+ if (false == ri.m_from.GetName().empty()) {
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_FROM_DESCRIPTION, ri.m_from.GetName().c_str());
}
- if (false == ri.m_to.GetName().empty())
- {
+ if (false == ri.m_to.GetName().empty()) {
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_TO_DESCRIPTION, ri.m_to.GetName().c_str());
}
return true;
}
}
- else if ((false == bWatch) && (i != m_aContacts.end()))
- {
+ else if ((false == bWatch) && (i != m_aContacts.end())) {
MCONTACT hContact = *i;
{// for CCritSection
mir_cslock lck(m_cs);
@@ -75,8 +67,7 @@ size_t CQuotesProviderGoogle::GetWatchedRateCount()const bool CQuotesProviderGoogle::GetWatchedRateInfo(size_t nIndex, CRateInfo& rRateInfo)
{
- if (nIndex < m_aContacts.size())
- {
+ 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);
@@ -87,75 +78,65 @@ bool CQuotesProviderGoogle::GetWatchedRateInfo(size_t nIndex, CRateInfo& rRateIn rRateInfo.m_to = CQuote(sSymbolTo, sSymbolTo, sDescTo);
return true;
}
- else
- {
+ else {
return false;
}
}
-namespace
+static tstring build_url(const tstring& rsURL, const tstring& from, const tstring& to, double dAmount)
{
- tstring build_url(const tstring& rsURL, const tstring& from, const tstring& to, double dAmount)
- {
- tostringstream o;
- o << rsURL << _T("?a=") << std::fixed << dAmount << _T("&from=") << from << _T("&to=") << to;
- return o.str();
- }
- 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;
+ tostringstream o;
+ o << rsURL << _T("?a=") << std::fixed << dAmount << _T("&from=") << from << _T("&to=") << to;
+ return o.str();
+}
- bool parse_html_node(const THTMLNodePtr& pNode, double& rdRate)
- {
- tstring sID = pNode->GetAttribute(_T("id"));
- if ((false == sID.empty()) && (0 == quotes_stricmp(sID.c_str(), _T("currency_converter_result"))))
- {
- size_t cChild = pNode->GetChildCount();
- // assert(1 == cChild);
- if (cChild > 0)
- {
- THTMLNodePtr pChild = pNode->GetChildPtr(0);
- tstring sRate = pChild->GetText();
+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);
+}
- tistringstream input(sRate);
- input >> rdRate;
+typedef IHTMLNode::THTMLNodePtr THTMLNodePtr;
- return ((false == input.bad()) && (false == input.fail()));
- }
+bool parse_html_node(const THTMLNodePtr& pNode, double& rdRate)
+{
+ tstring sID = pNode->GetAttribute(_T("id"));
+ if ((false == sID.empty()) && (0 == quotes_stricmp(sID.c_str(), _T("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;
- }
+ }
+ 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;
- }
+ 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;
}
}
@@ -166,25 +147,20 @@ void CQuotesProviderGoogle::RefreshQuotes(TContracts& anContacts) bool bUseExtendedStatus = CModuleInfo::GetInstance().GetExtendedStatusFlag();
- for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i)
- {
+ for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i) {
MCONTACT hContact = *i;
- if (bUseExtendedStatus)
- {
+ if (bUseExtendedStatus) {
SetContactStatus(hContact, ID_STATUS_OCCUPIED);
}
tstring sFullURL = build_url(hContact, sURL);
// LogIt(Info,sFullURL);
- if ((true == http.OpenURL(sFullURL)) && (true == IsOnline()))
- {
+ if ((true == http.OpenURL(sFullURL)) && (true == IsOnline())) {
tstring sHTML;
- if ((true == http.ReadResponce(sHTML)) && (true == IsOnline()))
- {
+ if ((true == http.ReadResponce(sHTML)) && (true == IsOnline())) {
double dRate = 0.0;
- if ((true == parse_responce(sHTML, dRate)) && (true == IsOnline()))
- {
+ if ((true == parse_responce(sHTML, dRate)) && (true == IsOnline())) {
WriteContactRate(hContact, dRate);
continue;
}
@@ -195,114 +171,104 @@ void CQuotesProviderGoogle::RefreshQuotes(TContracts& anContacts) }
}
-namespace
+inline tstring make_quote_name(const CQuotesProviderGoogle::CQuote& rQuote)
{
- inline tstring make_quote_name(const CQuotesProviderGoogle::CQuote& rQuote)
- {
- const tstring& rsDesc = rQuote.GetName();
- return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
- }
-
- 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;
- }
+ const tstring& rsDesc = rQuote.GetName();
+ return((false == rsDesc.empty()) ? rsDesc : rQuote.GetSymbol());
+}
- assert(!"We should never get here!");
- return NULL;
+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;
}
- 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);
- }
+ assert(!"We should never get here!");
+ return NULL;
+}
- return CQuotesProviderGoogle::CQuoteSection();
+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);
}
- 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 CQuotesProviderGoogle::CQuoteSection();
+}
- return make_contact_name(rFrom.GetSymbol(), rTo.GetSymbol());
- }
+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());
- typedef std::vector<CQuotesProviderGoogle::CRateInfo> TWatchedRates;
- TWatchedRates g_aWatchedRates;
+ return make_contact_name(rFrom.GetSymbol(), rTo.GetSymbol());
+}
- bool is_equal_rate(const CQuotesProviderGoogle::CRateInfo& riL, const CQuotesProviderGoogle::CRateInfo& riR)
- {
- return ((0 == quotes_stricmp(riL.m_from.GetID().c_str(), riR.m_from.GetID().c_str()))
- && ((0 == quotes_stricmp(riL.m_to.GetID().c_str(), riR.m_to.GetID().c_str()))));
- }
+typedef std::vector<CQuotesProviderGoogle::CRateInfo> TWatchedRates;
+TWatchedRates g_aWatchedRates;
- INT_PTR CALLBACK GoogleOptDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- CQuotesProviderGoogle* pProvider = get_google_provider();
+bool is_equal_rate(const CQuotesProviderGoogle::CRateInfo& riL, const CQuotesProviderGoogle::CRateInfo& riR)
+{
+ return ((0 == quotes_stricmp(riL.m_from.GetID().c_str(), riR.m_from.GetID().c_str()))
+ && ((0 == quotes_stricmp(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);
+ CCommonDlgProcData d(pProvider);
+ CommonOptionDlgProc(hdlg, message, wParam, lParam, d);
- switch (message) {
- case WM_NOTIFY:
+ switch (message) {
+ case WM_NOTIFY:
{
LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lParam);
- switch (pNMHDR->code)
- {
+ 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);
+ 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));
+ 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();
+ pProvider->RefreshSettings();
+ }
}
- }
- break;
+ break;
}
}
break;
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hdlg);
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+ {
g_aWatchedRates.clear();
HWND hcbxFrom = ::GetDlgItem(hdlg, IDC_COMBO_CONVERT_FROM);
@@ -310,8 +276,7 @@ namespace const CQuotesProviderGoogle::CQuoteSection& rSection = get_quotes();
size_t cQuotes = rSection.GetQuoteCount();
- for (size_t i = 0; i < cQuotes; ++i)
- {
+ 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();
@@ -320,14 +285,11 @@ namespace }
pProvider = get_google_provider();
- if (pProvider)
- {
+ if (pProvider) {
size_t cWatchedRates = pProvider->GetWatchedRateCount();
- for (size_t i = 0; i < cWatchedRates; ++i)
- {
+ for (size_t i = 0; i < cWatchedRates; ++i) {
CQuotesProviderGoogle::CRateInfo ri;
- if (true == pProvider->GetWatchedRateInfo(i, 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();
@@ -340,16 +302,15 @@ namespace ::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:
+
+ 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));
@@ -357,27 +318,25 @@ namespace EnableWindow(GetDlgItem(hdlg, IDC_BUTTON_ADD), bEnableAddButton);
}
break;
- case IDC_LIST_RATES:
+ 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:
+ }
+ 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))
- {
+ 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))
- {
+ if ((nFrom < cQuotes) && (nTo < cQuotes)) {
CQuotesProviderGoogle::CRateInfo ri;
ri.m_from = rSection.GetQuote(nFrom);
ri.m_to = rSection.GetQuote(nTo);
@@ -392,35 +351,31 @@ namespace }
}
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;
+ 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;
}
-
- return FALSE;
+ break;
}
+
+ return FALSE;
}
void CQuotesProviderGoogle::ShowPropertyPage(WPARAM wp, OPTIONSDIALOGPAGE &odp)
@@ -442,30 +397,18 @@ double CQuotesProviderGoogle::Convert(double dAmount, const CQuote& from, const tstring sFullURL = build_url(GetURL(), from.GetID(), to.GetID(), dAmount);
CHTTPSession http;
- if ((true == http.OpenURL(sFullURL)))
- {
+ if ((true == http.OpenURL(sFullURL))) {
tstring sHTML;
- if ((true == http.ReadResponce(sHTML)))
- {
+ if ((true == http.ReadResponce(sHTML))) {
double dResult = 0.0;
if ((true == parse_responce(sHTML, dResult)))
- {
return dResult;
- }
- else
- {
- throw std::runtime_error(Translate("Error occurred during html parsing."));
- }
- }
- else
- {
- throw std::runtime_error(Translate("Error occurred during site access."));
+
+ 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."));
- }
+ else throw std::runtime_error(Translate("Error occurred during site access."));
return 0.0;
}
@@ -488,11 +431,7 @@ MCONTACT CQuotesProviderGoogle::GetContactByID(const tstring& rsFromID, const ts 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;
- }
- else
- {
- return NULL;
- }
+
+ return NULL;
}
diff --git a/plugins/Quotes/src/QuotesProviderGoogleFinance.cpp b/plugins/Quotes/src/QuotesProviderGoogleFinance.cpp index f4bbc2fe7f..f9a561ad7b 100644 --- a/plugins/Quotes/src/QuotesProviderGoogleFinance.cpp +++ b/plugins/Quotes/src/QuotesProviderGoogleFinance.cpp @@ -8,280 +8,231 @@ CQuotesProviderGoogleFinance::~CQuotesProviderGoogleFinance() {
}
-namespace
+static tstring build_url(MCONTACT hContact, const tstring& rsURL)
{
- tstring build_url(MCONTACT hContact, const tstring& rsURL)
- {
- tostringstream o;
- o << rsURL << _T("?q=") << Quotes_DBGetStringT(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_ID);
- return o.str();
- }
+ tostringstream o;
+ o << rsURL << _T("?q=") << Quotes_DBGetStringT(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_ID);
+ return o.str();
+}
- struct CGoogleInfo
+struct CGoogleInfo
+{
+ enum
{
- enum
- {
- giRate = 0x0001,
- giOpen = 0x0002,
- giPercentChangeAfterHours = 0x0004,
- giPercentChangeToYesterdayClose = 0x0008
- };
- CGoogleInfo()
- : m_dRate(0.0), m_dOpenValue(0.0), m_dPercentChangeAfterHours(0.0), m_dPercentChangeToYersterdayClose(0.0), m_nFlags(0){}
- // tstring m_sCmpID;
- tstring m_sCmpName;
- double m_dRate;
- double m_dOpenValue;
- double m_dPercentChangeAfterHours;
- double m_dPercentChangeToYersterdayClose;
-
- // tstring m_sRateID;
- // tstring m_sDiffID;
- byte m_nFlags;
+ giRate = 0x0001,
+ giOpen = 0x0002,
+ giPercentChangeAfterHours = 0x0004,
+ giPercentChangeToYesterdayClose = 0x0008
};
- tstring make_rate_id_value(const tstring& rsCmpID, int nFlags)
+ CGoogleInfo()
+ : m_dRate(0.0), m_dOpenValue(0.0), m_dPercentChangeAfterHours(0.0), m_dPercentChangeToYersterdayClose(0.0), m_nFlags(0)
{
- tostringstream o;
- o << _T("ref_") << rsCmpID;
- switch (nFlags)
- {
- default:
- assert(!"Unknown type of value");
- case CGoogleInfo::giRate:
- o << _T("_l");
- break;
- case CGoogleInfo::giPercentChangeAfterHours:
- o << _T("_ecp");
- break;
- case CGoogleInfo::giPercentChangeToYesterdayClose:
- o << _T("_cp");
- break;
- }
-
- return o.str();
}
- tstring get_var_value(const tstring& rsHTML, LPCTSTR pszVarName, size_t cVarNameLength)
- {
- tstring sResult;
- tstring::size_type n = rsHTML.find(pszVarName);
- if (tstring::npos != n)
- {
- size_t cLengthHTML = rsHTML.size();
- for (size_t i = n + cVarNameLength; i < cLengthHTML; ++i)
- {
- TCHAR c = rsHTML[i];
- if (_T(';') == c)
- {
- break;
- }
- else
- {
- sResult.push_back(c);
- }
- }
- }
+ tstring m_sCmpName;
+ double m_dRate;
+ double m_dOpenValue;
+ double m_dPercentChangeAfterHours;
+ double m_dPercentChangeToYersterdayClose;
+ byte m_nFlags;
+};
- return sResult;
+tstring make_rate_id_value(const tstring& rsCmpID, int nFlags)
+{
+ tostringstream o;
+ o << _T("ref_") << rsCmpID;
+ switch (nFlags) {
+ default:
+ assert(!"Unknown type of value");
+ case CGoogleInfo::giRate:
+ o << _T("_l");
+ break;
+ case CGoogleInfo::giPercentChangeAfterHours:
+ o << _T("_ecp");
+ break;
+ case CGoogleInfo::giPercentChangeToYesterdayClose:
+ o << _T("_cp");
+ break;
}
- tstring get_company_id(const tstring& rsHTML)
- {
- static LPCTSTR pszVarName = _T("setCompanyId(");
- static size_t cVarNameLength = mir_tstrlen(pszVarName);
-
- tstring sResult;
- tstring::size_type n = rsHTML.find(pszVarName);
- if (tstring::npos != n)
- {
- size_t cLengthHTML = rsHTML.size();
- for (size_t i = n + cVarNameLength; i < cLengthHTML; ++i)
- {
- TCHAR c = rsHTML[i];
- if (_T(')') == c)
- {
- break;
- }
- else
- {
- sResult.push_back(c);
- }
- }
+ return o.str();
+}
+
+tstring get_var_value(const tstring& rsHTML, LPCTSTR pszVarName, size_t cVarNameLength)
+{
+ tstring sResult;
+ tstring::size_type n = rsHTML.find(pszVarName);
+ if (tstring::npos != n) {
+ size_t cLengthHTML = rsHTML.size();
+ for (size_t i = n + cVarNameLength; i < cLengthHTML; ++i) {
+ TCHAR c = rsHTML[i];
+ if (_T(';') == c)
+ break;
+
+ sResult.push_back(c);
}
- return sResult;
- // return get_var_value(rsHTML,pszVarName,cVarNameLength);
}
- tstring get_company_name(const tstring& rsHTML)
- {
- static LPCTSTR pszVarName = _T("var _companyName = ");
- static size_t cVarNameLength = mir_tstrlen(pszVarName);
+ return sResult;
+}
- tstring s = get_var_value(rsHTML, pszVarName, cVarNameLength);
- if (s.size() > 0 && _T('\'') == s[0])
- {
- s.erase(s.begin());
+tstring get_company_id(const tstring& rsHTML)
+{
+ static LPCTSTR pszVarName = _T("setCompanyId(");
+ static size_t cVarNameLength = mir_tstrlen(pszVarName);
+
+ tstring sResult;
+ tstring::size_type n = rsHTML.find(pszVarName);
+ if (tstring::npos != n) {
+ size_t cLengthHTML = rsHTML.size();
+ for (size_t i = n + cVarNameLength; i < cLengthHTML; ++i) {
+ TCHAR c = rsHTML[i];
+ if (_T(')') == c)
+ break;
+
+ sResult.push_back(c);
}
+ }
+ return sResult;
+}
- if (s.size() > 0 && _T('\'') == s[s.size() - 1])
- {
- s.erase(s.rbegin().base() - 1);
- }
+tstring get_company_name(const tstring& rsHTML)
+{
+ static LPCTSTR pszVarName = _T("var _companyName = ");
+ static size_t cVarNameLength = mir_tstrlen(pszVarName);
- return s;
- }
+ tstring s = get_var_value(rsHTML, pszVarName, cVarNameLength);
+ if (s.size() > 0 && _T('\'') == s[0])
+ s.erase(s.begin());
- bool get_double_value(const tstring& rsText, double& rdValue)
- {
- tistringstream input(rsText);
- input.imbue(std::locale("English_United States.1252"));
- input >> rdValue;
+ if (s.size() > 0 && _T('\'') == s[s.size() - 1])
+ s.erase(s.rbegin().base() - 1);
- if ((true == input.bad()) || (true == input.fail()))
- {
- tistringstream inputSys(rsText);
- input.imbue(GetSystemLocale());
- input >> rdValue;
- return (false == inputSys.bad()) && (false == inputSys.fail());
- }
- else
- {
- return true;
- }
+ return s;
+}
+
+bool get_double_value(const tstring& rsText, double& rdValue)
+{
+ tistringstream input(rsText);
+ input.imbue(std::locale("English_United States.1252"));
+ input >> rdValue;
+
+ if ((true == input.bad()) || (true == input.fail())) {
+ tistringstream inputSys(rsText);
+ input.imbue(GetSystemLocale());
+ input >> rdValue;
+ return (false == inputSys.bad()) && (false == inputSys.fail());
}
- bool get_rate(const IHTMLNode::THTMLNodePtr& pRate, CGoogleInfo& rInfo)
- {
- tstring sRate = pRate->GetText();
+ return true;
+}
- if (true == get_double_value(sRate, rInfo.m_dRate))
- {
- rInfo.m_nFlags |= CGoogleInfo::giRate;
- return true;
- }
- else
- {
- return false;
- }
+bool get_rate(const IHTMLNode::THTMLNodePtr& pRate, CGoogleInfo& rInfo)
+{
+ tstring sRate = pRate->GetText();
+
+ if (true == get_double_value(sRate, rInfo.m_dRate)) {
+ rInfo.m_nFlags |= CGoogleInfo::giRate;
+ return true;
}
- bool get_inline_data(const IHTMLNode::THTMLNodePtr& pNode, CGoogleInfo& rInfo)
- {
- size_t cChild = pNode->GetChildCount();
- for (size_t i = 0; i < cChild; ++i)
- {
- IHTMLNode::THTMLNodePtr pChild = pNode->GetChildPtr(i);
- size_t c = pChild->GetChildCount();
- assert(2 == c);
- if (c >= 2)
- {
- IHTMLNode::THTMLNodePtr pName = pChild->GetChildPtr(0);
-
- tstring sName = pName->GetText();
- if (0 == quotes_stricmp(sName.c_str(), _T("Open")))
- {
- IHTMLNode::THTMLNodePtr pValue = pChild->GetChildPtr(1);
- tstring sValue = pValue->GetText();
- if (true == get_double_value(sValue, rInfo.m_dOpenValue))
- {
- rInfo.m_nFlags |= CGoogleInfo::giOpen;
- }
- return true;
+ return false;
+}
+
+bool get_inline_data(const IHTMLNode::THTMLNodePtr& pNode, CGoogleInfo& rInfo)
+{
+ size_t cChild = pNode->GetChildCount();
+ for (size_t i = 0; i < cChild; ++i) {
+ IHTMLNode::THTMLNodePtr pChild = pNode->GetChildPtr(i);
+ size_t c = pChild->GetChildCount();
+ assert(2 == c);
+ if (c >= 2) {
+ IHTMLNode::THTMLNodePtr pName = pChild->GetChildPtr(0);
+
+ tstring sName = pName->GetText();
+ if (0 == quotes_stricmp(sName.c_str(), _T("Open"))) {
+ IHTMLNode::THTMLNodePtr pValue = pChild->GetChildPtr(1);
+ tstring sValue = pValue->GetText();
+ if (true == get_double_value(sValue, rInfo.m_dOpenValue)) {
+ rInfo.m_nFlags |= CGoogleInfo::giOpen;
}
+ return true;
}
}
-
- return false;
}
- bool get_dif_value(const IHTMLNode::THTMLNodePtr& pNode, CGoogleInfo& rInfo, int nItem)
- {
- tstring sDiff = pNode->GetText();
- // this value is in brackets and it has percentage sign.
- // Remove these symbols.
- for (tstring::iterator i = sDiff.begin(); i != sDiff.end();)
- {
- TCHAR s = *i;
- if (_T('(') == s || _T(')') == s || _T('%') == s)
- {
- i = sDiff.erase(i);
- }
- else
- {
- ++i;
- }
- }
+ return false;
+}
- double* pValue = NULL;
- switch (nItem)
- {
- case CGoogleInfo::giPercentChangeAfterHours:
- pValue = &rInfo.m_dPercentChangeAfterHours;
- break;
- case CGoogleInfo::giPercentChangeToYesterdayClose:
- pValue = &rInfo.m_dPercentChangeToYersterdayClose;
- break;
- }
+bool get_dif_value(const IHTMLNode::THTMLNodePtr& pNode, CGoogleInfo& rInfo, int nItem)
+{
+ tstring sDiff = pNode->GetText();
+ // this value is in brackets and it has percentage sign.
+ // Remove these symbols.
+ for (tstring::iterator i = sDiff.begin(); i != sDiff.end();) {
+ TCHAR s = *i;
+ if (_T('(') == s || _T(')') == s || _T('%') == s)
+ i = sDiff.erase(i);
+ else
+ ++i;
+ }
- assert(pValue);
+ double* pValue = NULL;
+ switch (nItem) {
+ case CGoogleInfo::giPercentChangeAfterHours:
+ pValue = &rInfo.m_dPercentChangeAfterHours;
+ break;
+ case CGoogleInfo::giPercentChangeToYesterdayClose:
+ pValue = &rInfo.m_dPercentChangeToYersterdayClose;
+ break;
+ }
- if ((pValue) && (true == get_double_value(sDiff, *pValue)))
- {
- rInfo.m_nFlags |= nItem;
- return true;
- }
- else
- {
- return false;
- }
+ assert(pValue);
+ if ((pValue) && (true == get_double_value(sDiff, *pValue))) {
+ rInfo.m_nFlags |= nItem;
+ return true;
}
- bool parse_responce(const tstring& rsHTML, CGoogleInfo& rInfo)
- {
- IHTMLEngine::THTMLParserPtr pHTMLParser = CModuleInfo::GetHTMLEngine()->GetParserPtr();
- IHTMLNode::THTMLNodePtr pRoot = pHTMLParser->ParseString(rsHTML);
- if (pRoot)
- {
- tstring sCmpID = get_company_id(rsHTML);
- if (false == sCmpID.empty())
- {
- tstring sRateID = make_rate_id_value(sCmpID, CGoogleInfo::giRate);
- IHTMLNode::THTMLNodePtr pRate = pRoot->GetElementByID(sRateID);
- if (pRate && get_rate(pRate, rInfo))
- {
- rInfo.m_sCmpName = get_company_name(rsHTML);
-
- IHTMLNode::THTMLNodePtr pInline = pRoot->GetElementByID(_T("snap-data"));
- if (pInline)
- {
- get_inline_data(pInline, rInfo);
- }
+ return false;
+}
- tstring sDiffID = make_rate_id_value(sCmpID, CGoogleInfo::giPercentChangeAfterHours);
- IHTMLNode::THTMLNodePtr pDiff = pRoot->GetElementByID(sDiffID);
- if (pDiff)
- {
- get_dif_value(pDiff, rInfo, CGoogleInfo::giPercentChangeAfterHours);
- }
+bool parse_responce(const tstring& rsHTML, CGoogleInfo& rInfo)
+{
+ IHTMLEngine::THTMLParserPtr pHTMLParser = CModuleInfo::GetHTMLEngine()->GetParserPtr();
+ IHTMLNode::THTMLNodePtr pRoot = pHTMLParser->ParseString(rsHTML);
+ if (pRoot) {
+ tstring sCmpID = get_company_id(rsHTML);
+ if (false == sCmpID.empty()) {
+ tstring sRateID = make_rate_id_value(sCmpID, CGoogleInfo::giRate);
+ IHTMLNode::THTMLNodePtr pRate = pRoot->GetElementByID(sRateID);
+ if (pRate && get_rate(pRate, rInfo)) {
+ rInfo.m_sCmpName = get_company_name(rsHTML);
+
+ IHTMLNode::THTMLNodePtr pInline = pRoot->GetElementByID(_T("snap-data"));
+ if (pInline) {
+ get_inline_data(pInline, rInfo);
+ }
- sDiffID = make_rate_id_value(sCmpID, CGoogleInfo::giPercentChangeToYesterdayClose);
- pDiff = pRoot->GetElementByID(sDiffID);
- if (pDiff)
- {
- get_dif_value(pDiff, rInfo, CGoogleInfo::giPercentChangeToYesterdayClose);
- }
+ tstring sDiffID = make_rate_id_value(sCmpID, CGoogleInfo::giPercentChangeAfterHours);
+ IHTMLNode::THTMLNodePtr pDiff = pRoot->GetElementByID(sDiffID);
+ if (pDiff) {
+ get_dif_value(pDiff, rInfo, CGoogleInfo::giPercentChangeAfterHours);
+ }
- return true;
+ sDiffID = make_rate_id_value(sCmpID, CGoogleInfo::giPercentChangeToYesterdayClose);
+ pDiff = pRoot->GetElementByID(sDiffID);
+ if (pDiff) {
+ get_dif_value(pDiff, rInfo, CGoogleInfo::giPercentChangeToYesterdayClose);
}
- //return (true == parse_html_node(pRoot,rInfo));
+ return true;
}
}
-
- return false;
}
+
+ return false;
}
void CQuotesProviderGoogleFinance::RefreshQuotes(TContracts& anContacts)
@@ -290,44 +241,31 @@ void CQuotesProviderGoogleFinance::RefreshQuotes(TContracts& anContacts) tstring sURL = GetURL();
bool bUseExtendedStatus = CModuleInfo::GetInstance().GetExtendedStatusFlag();
- for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i)
- {
+ for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i) {
MCONTACT hContact = *i;
if (bUseExtendedStatus)
- {
SetContactStatus(hContact, ID_STATUS_OCCUPIED);
- }
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()))
- {
- // LogIt(Info,sHTML);
+ if ((true == http.OpenURL(sFullURL)) && (true == IsOnline())) {
+ tstring sHTML;
+ if ((true == http.ReadResponce(sHTML)) && (true == IsOnline())) {
CGoogleInfo Info;
parse_responce(sHTML, Info);
- if (true == IsOnline())
- {
- if (Info.m_nFlags&CGoogleInfo::giRate)
- {
- if (Info.m_nFlags&CGoogleInfo::giOpen)
- {
+ if (true == IsOnline()) {
+ if (Info.m_nFlags&CGoogleInfo::giRate) {
+ if (Info.m_nFlags&CGoogleInfo::giOpen) {
Quotes_DBWriteDouble(hContact, QUOTES_MODULE_NAME, DB_STR_GOOGLE_FINANCE_OPEN_VALUE, Info.m_dOpenValue);
}
- if (Info.m_nFlags&CGoogleInfo::giPercentChangeAfterHours)
- {
+ if (Info.m_nFlags&CGoogleInfo::giPercentChangeAfterHours) {
Quotes_DBWriteDouble(hContact, QUOTES_MODULE_NAME, DB_STR_GOOGLE_FINANCE_DIFF, Info.m_dPercentChangeAfterHours);
}
- if (Info.m_nFlags&CGoogleInfo::giPercentChangeToYesterdayClose)
- {
+ if (Info.m_nFlags&CGoogleInfo::giPercentChangeToYesterdayClose) {
Quotes_DBWriteDouble(hContact, QUOTES_MODULE_NAME, DB_STR_GOOGLE_FINANCE_PERCENT_CHANGE_TO_YERSTERDAY_CLOSE, Info.m_dPercentChangeToYersterdayClose);
}
- if (false == Info.m_sCmpName.empty())
- {
+ if (false == Info.m_sCmpName.empty()) {
db_set_ts(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_DESCRIPTION, Info.m_sCmpName.c_str());
}
@@ -340,13 +278,10 @@ void CQuotesProviderGoogleFinance::RefreshQuotes(TContracts& anContacts) SetContactStatus(hContact, ID_STATUS_NA);
}
-
}
-
void CQuotesProviderGoogleFinance::Accept(CQuotesProviderVisitor& visitor)const
{
CQuotesProviderFinance::Accept(visitor);
visitor.Visit(*this);
}
-
diff --git a/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp b/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp index 4b58a3af51..b6bb075b88 100644 --- a/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp +++ b/plugins/Quotes/src/QuotesProviderVisitorFormater.cpp @@ -19,15 +19,12 @@ const tstring& CQuotesProviderVisitorFormater::GetResult()const void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderDukasCopy&)
{
if (_T('d') == m_chr || _T('D') == m_chr)
- {
m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_DESCRIPTION);
- }
}
void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderGoogle&)
{
- switch (m_chr)
- {
+ switch (m_chr) {
case _T('F'):
m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_FROM_DESCRIPTION);
break;
@@ -43,41 +40,33 @@ void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderGoogle&) }
}
-namespace
+static bool get_fetch_time(MCONTACT hContact, time_t& rTime)
{
- bool get_fetch_time(MCONTACT hContact, time_t& rTime)
- {
- DBVARIANT dbv;
- if (db_get(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_FETCH_TIME, &dbv) || (DBVT_DWORD != dbv.type))
- return false;
-
- rTime = dbv.dVal;
- return true;
- }
+ DBVARIANT dbv;
+ if (db_get(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_FETCH_TIME, &dbv) || (DBVT_DWORD != dbv.type))
+ return false;
- tstring format_fetch_time(const CQuotesProviderBase&, MCONTACT hContact, const tstring& rsFormat)
- {
- time_t nTime;
- if (true == get_fetch_time(hContact, nTime))
- {
- boost::posix_time::ptime time = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(boost::posix_time::from_time_t(nTime));
- tostringstream k;
- k.imbue(std::locale(GetSystemLocale(), new ttime_facet(rsFormat.c_str())));
- k << time;
- return k.str();
- }
+ rTime = dbv.dVal;
+ return true;
+}
- return tstring();
+static tstring format_fetch_time(const CQuotesProviderBase&, MCONTACT hContact, const tstring& rsFormat)
+{
+ time_t nTime;
+ if (true == get_fetch_time(hContact, nTime)) {
+ boost::posix_time::ptime time = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(boost::posix_time::from_time_t(nTime));
+ tostringstream k;
+ k.imbue(std::locale(GetSystemLocale(), new ttime_facet(rsFormat.c_str())));
+ k << time;
+ return k.str();
}
+
+ return tstring();
}
void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderBase& rProvider)
{
- switch (m_chr)
- {
- // default:
- // m_sResult = m_chr;
- // break;
+ switch (m_chr) {
case _T('%'):
case _T('\t'):
case _T('\\'):
@@ -90,23 +79,19 @@ void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderBase& rProvider) m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_SYMBOL);
break;
case _T('X'):
- //m_sResult = format_fetch_time(rProvider,m_hContact,_T("%H:%M:%S"));
m_sResult = format_fetch_time(rProvider, m_hContact, Quotes_GetTimeFormat(true));
break;
case _T('x'):
- //m_sResult = format_fetch_time(rProvider,m_hContact,_T("%d.%m.%y"));
m_sResult = format_fetch_time(rProvider, m_hContact, Quotes_GetDateFormat(true));
break;
case _T('t'):
- {
- tstring sFrmt = Quotes_GetDateFormat(true);
- sFrmt += _T(" ");
- sFrmt += Quotes_GetTimeFormat(true);
- m_sResult = format_fetch_time(rProvider, m_hContact, sFrmt);
-
- //m_sResult = format_fetch_time(rProvider,m_hContact,_T("%d.%m.%y %H:%M:%S"));
- }
- break;
+ {
+ tstring sFrmt = Quotes_GetDateFormat(true);
+ sFrmt += _T(" ");
+ sFrmt += Quotes_GetTimeFormat(true);
+ m_sResult = format_fetch_time(rProvider, m_hContact, sFrmt);
+ }
+ break;
case _T('r'):
case _T('R'):
FormatDoubleHelper(DB_STR_QUOTE_CURR_VALUE);
@@ -114,19 +99,12 @@ void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderBase& rProvider) case _T('p'):
FormatDoubleHelper(DB_STR_QUOTE_PREV_VALUE);
break;
- // case _T('c'):
- // FormatChangeValueHelper(false);
- // break;
- // case _T('C'):
- // FormatChangeValueHelper(true);
- // break;
}
}
void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderGoogleFinance&/* rProvider*/)
{
- switch (m_chr)
- {
+ switch (m_chr) {
case _T('o'):
FormatDoubleHelper(DB_STR_GOOGLE_FINANCE_OPEN_VALUE);
break;
@@ -142,21 +120,17 @@ void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderGoogleFinance&/* }
}
-namespace
+tstring format_double(double dValue, int nWidth)
{
- tstring format_double(double dValue, int nWidth)
- {
- tostringstream o;
- o.imbue(GetSystemLocale());
+ tostringstream o;
+ o.imbue(GetSystemLocale());
- if (nWidth > 0 && nWidth <= 9)
- {
- o << std::setprecision(nWidth) << std::showpoint << std::fixed;
- }
- o << dValue;
+ if (nWidth > 0 && nWidth <= 9)
+ o << std::setprecision(nWidth) << std::showpoint << std::fixed;
- return o.str();
- }
+ o << dValue;
+
+ return o.str();
}
void CQuotesProviderVisitorFormater::FormatDoubleHelper(LPCSTR pszDbSet,
@@ -164,19 +138,14 @@ void CQuotesProviderVisitorFormater::FormatDoubleHelper(LPCSTR pszDbSet, {
double d = 0.0;
if (true == Quotes_DBReadDouble(m_hContact, QUOTES_MODULE_NAME, pszDbSet, d))
- {
m_sResult = format_double(d, m_nWidth);
- }
else
- {
m_sResult = sInvalid;
- }
}
void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderYahoo&)
{
- switch (m_chr)
- {
+ switch (m_chr) {
case _T('o'):
FormatDoubleHelper(DB_STR_YAHOO_OPEN_VALUE);
break;
@@ -196,5 +165,4 @@ void CQuotesProviderVisitorFormater::Visit(const CQuotesProviderYahoo&) m_sResult = Quotes_DBGetStringT(m_hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_DESCRIPTION);
break;
}
-
}
diff --git a/plugins/Quotes/src/QuotesProviderVisitorTendency.cpp b/plugins/Quotes/src/QuotesProviderVisitorTendency.cpp index 1a62a289f1..a4899909e1 100644 --- a/plugins/Quotes/src/QuotesProviderVisitorTendency.cpp +++ b/plugins/Quotes/src/QuotesProviderVisitorTendency.cpp @@ -7,8 +7,7 @@ CQuotesProviderVisitorTendency::CQuotesProviderVisitorTendency(MCONTACT hContact void CQuotesProviderVisitorTendency::Visit(const CQuotesProviderBase&)
{
- switch (m_chr)
- {
+ switch (m_chr) {
case _T('r'):
case _T('R'):
GetValue(DB_STR_QUOTE_CURR_VALUE);
@@ -21,8 +20,7 @@ void CQuotesProviderVisitorTendency::Visit(const CQuotesProviderBase&) void CQuotesProviderVisitorTendency::Visit(const CQuotesProviderGoogleFinance&)
{
- switch (m_chr)
- {
+ switch (m_chr) {
case _T('o'):
GetValue(DB_STR_GOOGLE_FINANCE_OPEN_VALUE);
break;
@@ -37,8 +35,7 @@ void CQuotesProviderVisitorTendency::Visit(const CQuotesProviderGoogleFinance&) void CQuotesProviderVisitorTendency::Visit(const CQuotesProviderYahoo&)
{
- switch (m_chr)
- {
+ switch (m_chr) {
case _T('o'):
GetValue(DB_STR_YAHOO_OPEN_VALUE);
break;
@@ -55,10 +52,8 @@ void CQuotesProviderVisitorTendency::Visit(const CQuotesProviderYahoo&) GetValue(DB_STR_YAHOO_DAY_LOW);
break;
}
-
}
-
void CQuotesProviderVisitorTendency::GetValue(LPCSTR pszDbKeyName)
{
m_bValid = Quotes_DBReadDouble(m_hContact, QUOTES_MODULE_NAME, pszDbKeyName, m_dResult);
diff --git a/plugins/Quotes/src/QuotesProviderYahoo.cpp b/plugins/Quotes/src/QuotesProviderYahoo.cpp index ab09978d39..9b9ad36c4f 100644 --- a/plugins/Quotes/src/QuotesProviderYahoo.cpp +++ b/plugins/Quotes/src/QuotesProviderYahoo.cpp @@ -1,69 +1,50 @@ #include "stdafx.h"
-namespace
+void remove_quotes(tstring& s)
{
- void remove_quotes(tstring& s)
- {
- if (*s.begin() == _T('"'))
- {
- s.erase(s.begin());
- }
- if (*s.rbegin() == _T('"'))
- {
- tstring::iterator i(s.begin());
- std::advance(i, s.size() - 1);
- s.erase(i);
- }
- }
+ if (*s.begin() == _T('"'))
+ s.erase(s.begin());
- void remove_end_of_line(tstring& s)
- {
- if (*s.rbegin() == _T('\n'))
- {
- tstring::iterator i(s.begin());
- std::advance(i, s.size() - 1);
- s.erase(i);
- }
- if (*s.rbegin() == _T('\r'))
- {
- tstring::iterator i(s.begin());
- std::advance(i, s.size() - 1);
- s.erase(i);
- }
+ if (*s.rbegin() == _T('"')) {
+ tstring::iterator i(s.begin());
+ std::advance(i, s.size() - 1);
+ s.erase(i);
}
+}
- bool t2d(const tstring& s, double& d)
- {
- tistringstream stream(s);
- stream >> d;
- return ((false == stream.fail()) && (false == stream.bad()));
- // try
- // {
- // d = boost::lexical_cast<double>(s);
- // return true;
- // }
- // catch(boost::bad_lexical_cast& e)
- // {
- // }
- // return false;
+void remove_end_of_line(tstring& s)
+{
+ if (*s.rbegin() == _T('\n')) {
+ tstring::iterator i(s.begin());
+ std::advance(i, s.size() - 1);
+ s.erase(i);
+ }
+ if (*s.rbegin() == _T('\r')) {
+ tstring::iterator i(s.begin());
+ std::advance(i, s.size() - 1);
+ s.erase(i);
}
+}
- typedef std::vector<tstring> TStrings;
+bool t2d(const tstring& s, double& d)
+{
+ tistringstream stream(s);
+ stream >> d;
+ return ((false == stream.fail()) && (false == stream.bad()));
+}
- bool get_double_from_parsed_line(MCONTACT hContact, const TStrings& rasParsedLine, size_t nIndex, const char* pszDbName)
- {
- if (rasParsedLine.size() > nIndex)
- {
- double d = 0.0;
- if (true == t2d(rasParsedLine[nIndex], d))
- {
- return Quotes_DBWriteDouble(hContact, QUOTES_MODULE_NAME, pszDbName, d);
- }
- }
+typedef std::vector<tstring> TStrings;
- db_set_ts(hContact, QUOTES_MODULE_NAME, pszDbName, _T(""));
- return false;
+bool get_double_from_parsed_line(MCONTACT hContact, const TStrings& rasParsedLine, size_t nIndex, const char* pszDbName)
+{
+ if (rasParsedLine.size() > nIndex) {
+ double d = 0.0;
+ if (true == t2d(rasParsedLine[nIndex], d))
+ return Quotes_DBWriteDouble(hContact, QUOTES_MODULE_NAME, pszDbName, d);
}
+
+ db_set_ts(hContact, QUOTES_MODULE_NAME, pszDbName, _T(""));
+ return false;
}
void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts)
@@ -75,59 +56,47 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts) TQuoteID2ContractHandles aQuoteID2Handles;
tostringstream oURL;
oURL << sURL << _T("dioksin.txt?s=");
- for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i)
- {
+ for (TContracts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i) {
MCONTACT hContact = *i;
if (bUseExtendedStatus)
- {
SetContactStatus(hContact, ID_STATUS_OCCUPIED);
- }
tstring sQuoteID = Quotes_DBGetStringT(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_ID);
aQuoteID2Handles[sQuoteID] = hContact;
if (i != anContacts.begin())
- {
oURL << _T("+");
- }
+
oURL << sQuoteID;
}
- if (true == IsOnline())
- {
+ if (true == IsOnline()) {
oURL << _T("&f=snl1ohgpc1");
CHTTPSession http;
- if ((true == http.OpenURL(oURL.str())) && (true == IsOnline()))
- {
+ if ((true == http.OpenURL(oURL.str())) && (true == IsOnline())) {
tstring sFile;
- if ((true == http.ReadResponce(sFile)) && (true == IsOnline()))
- {
+ if ((true == http.ReadResponce(sFile)) && (true == IsOnline())) {
tistringstream out_str(sFile.c_str());
- while (false == out_str.eof())
- {
+ while (false == out_str.eof()) {
tstring sLine;
std::getline(out_str, sLine);
- if (false == sLine.empty())
- {
+ if (false == sLine.empty()) {
remove_end_of_line(sLine);
TStrings asStrings;
- for (tstring::size_type nPos = sLine.find(_T(',')); nPos != tstring::npos; nPos = sLine.find(_T(',')))
- {
+ for (tstring::size_type nPos = sLine.find(_T(',')); nPos != tstring::npos; nPos = sLine.find(_T(','))) {
tstring::iterator i(sLine.begin());
std::advance(i, nPos);
tstring s(sLine.begin(), i);
remove_quotes(s);
asStrings.push_back(s);
- if (i != sLine.end())
- {
+ if (i != sLine.end()) {
std::advance(i, 1);
}
sLine.erase(sLine.begin(), i);
}
- if (false == sLine.empty())
- {
+ if (false == sLine.empty()) {
remove_quotes(sLine);
if (false == sLine.empty())
@@ -135,8 +104,7 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts) }
size_t cItems = asStrings.size();
- if (cItems >= 3)
- {
+ if (cItems >= 3) {
enum
{
indexSymbol = 0,
@@ -149,12 +117,10 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts) indexChange
};
auto it3 = aQuoteID2Handles.find(asStrings[indexSymbol]);
- if (it3 != aQuoteID2Handles.end())
- {
+ if (it3 != aQuoteID2Handles.end()) {
MCONTACT hContact = it3->second;
double dRate = 0.0;
- if (true == t2d(asStrings[indexLastTrade], dRate))
- {
+ if (true == t2d(asStrings[indexLastTrade], dRate)) {
db_set_ts(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_DESCRIPTION, asStrings[indexName].c_str());
get_double_from_parsed_line(hContact, asStrings, indexOpen, DB_STR_YAHOO_OPEN_VALUE);
@@ -172,10 +138,9 @@ void CQuotesProviderYahoo::RefreshQuotes(TContracts& anContacts) }
}
- if (true == IsOnline())
- {
+ if (true == IsOnline()) {
std::for_each(aQuoteID2Handles.begin(), aQuoteID2Handles.end(),
- [](const TQuoteID2ContractHandles::value_type& pair){SetContactStatus(pair.second, ID_STATUS_NA); });
+ [](const TQuoteID2ContractHandles::value_type& pair) { SetContactStatus(pair.second, ID_STATUS_NA); });
}
}
}
diff --git a/plugins/Quotes/src/QuotesProviders.cpp b/plugins/Quotes/src/QuotesProviders.cpp index 1c61395d55..1edbfc7825 100644 --- a/plugins/Quotes/src/QuotesProviders.cpp +++ b/plugins/Quotes/src/QuotesProviders.cpp @@ -17,17 +17,12 @@ const CQuotesProviders::TQuotesProviders& CQuotesProviders::GetProviders()const return m_apProviders;
}
-namespace
+template<class T>void create_provider(CQuotesProviders::TQuotesProviders& apProviders)
{
- template<class T>void create_provider(CQuotesProviders::TQuotesProviders& apProviders)
- {
- CQuotesProviders::TQuotesProviderPtr pProvider(new T);
- if (pProvider->Init())
- {
- apProviders.push_back(pProvider);
- }
- }
-}
+ CQuotesProviders::TQuotesProviderPtr pProvider(new T);
+ if (pProvider->Init())
+ apProviders.push_back(pProvider);
+};
void CQuotesProviders::CreateProviders()
{
@@ -42,17 +37,13 @@ void CQuotesProviders::ClearProviders() m_apProviders.clear();
}
-namespace
+void convert_contact_settings(MCONTACT hContact)
{
- void convert_contact_settings(MCONTACT hContact)
- {
- WORD dwLogMode = db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG, static_cast<WORD>(lmDisabled));
- if ((dwLogMode&lmInternalHistory) || (dwLogMode&lmExternalFile))
- {
- db_set_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_CONTACT_SPEC_SETTINGS, 1);
- }
- }
+ WORD dwLogMode = db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG, static_cast<WORD>(lmDisabled));
+ if ((dwLogMode&lmInternalHistory) || (dwLogMode&lmExternalFile))
+ db_set_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_CONTACT_SPEC_SETTINGS, 1);
}
+
void CQuotesProviders::InitProviders()
{
CreateProviders();
@@ -60,16 +51,12 @@ void CQuotesProviders::InitProviders() const WORD nCurrentVersion = 17;
WORD nVersion = db_get_w(NULL, QUOTES_MODULE_NAME, LAST_RUN_VERSION, 1);
- for (MCONTACT hContact = db_find_first(QUOTES_MODULE_NAME); hContact; hContact = db_find_next(hContact, QUOTES_MODULE_NAME))
- {
+ for (MCONTACT hContact = db_find_first(QUOTES_MODULE_NAME); hContact; hContact = db_find_next(hContact, QUOTES_MODULE_NAME)) {
TQuotesProviderPtr pProvider = GetContactProviderPtr(hContact);
- if (pProvider)
- {
+ if (pProvider) {
pProvider->AddContact(hContact);
if (nVersion < nCurrentVersion)
- {
convert_contact_settings(hContact);
- }
}
}
@@ -80,15 +67,11 @@ CQuotesProviders::TQuotesProviderPtr CQuotesProviders::GetContactProviderPtr(MCO {
char* szProto = GetContactProto(hContact);
if (NULL == szProto || 0 != ::_stricmp(szProto, QUOTES_PROTOCOL_NAME))
- {
return TQuotesProviderPtr();
- }
tstring sProvider = Quotes_DBGetStringT(hContact, QUOTES_MODULE_NAME, DB_STR_QUOTE_PROVIDER);
if (true == sProvider.empty())
- {
return TQuotesProviderPtr();
- }
return FindProvider(sProvider);
}
@@ -96,12 +79,10 @@ CQuotesProviders::TQuotesProviderPtr CQuotesProviders::GetContactProviderPtr(MCO CQuotesProviders::TQuotesProviderPtr CQuotesProviders::FindProvider(const tstring& rsName)const
{
TQuotesProviderPtr pResult;
- for (TQuotesProviders::const_iterator i = m_apProviders.begin(); i != m_apProviders.end(); ++i)
- {
+ for (TQuotesProviders::const_iterator i = m_apProviders.begin(); i != m_apProviders.end(); ++i) {
const TQuotesProviderPtr& pProvider = *i;
const IQuotesProvider::CProviderInfo& rInfo = pProvider->GetInfo();
- if (0 == ::quotes_stricmp(rsName.c_str(), rInfo.m_sName.c_str()))
- {
+ if (0 == ::quotes_stricmp(rsName.c_str(), rInfo.m_sName.c_str())) {
pResult = pProvider;
break;
}
diff --git a/plugins/Quotes/src/SettingsDlg.cpp b/plugins/Quotes/src/SettingsDlg.cpp index 501b3b7aef..e58f70833f 100644 --- a/plugins/Quotes/src/SettingsDlg.cpp +++ b/plugins/Quotes/src/SettingsDlg.cpp @@ -2,158 +2,153 @@ #define WINDOW_PREFIX_SETTINGS "Edit Settings_"
-namespace
+LPCTSTR g_pszVariableQuoteName = _T("%quotename%");
+LPCTSTR g_pszVariableUserProfile = _T("%miranda_userdata%");
+
+void update_file_controls(HWND hDlg)
{
- LPCTSTR g_pszVariableQuoteName = _T("%quotename%");
- LPCTSTR g_pszVariableUserProfile = _T("%miranda_userdata%");
-
- void update_file_controls(HWND hDlg)
- {
- bool bEnable = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_EXTERNAL_FILE));
-
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_FILE_NAME), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_SELECT_FILE), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_BROWSE), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_LOG_FILE_FORMAT), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_LOG_FILE_FORMAT), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_LOG_FILE_DESCRIPTION), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_LOG_FILE_CONDITION), bEnable);
- }
+ bool bEnable = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_EXTERNAL_FILE));
- void update_history_controls(HWND hDlg)
- {
- bool bEnable = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_INTERNAL_HISTORY));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_FILE_NAME), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_SELECT_FILE), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_BROWSE), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_LOG_FILE_FORMAT), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_LOG_FILE_FORMAT), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_LOG_FILE_DESCRIPTION), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_LOG_FILE_CONDITION), bEnable);
+}
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_HISTORY_FORMAT), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_HISTORY_FORMAT), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_HISTORY_DESCRIPTION), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_HISTORY_CONDITION), bEnable);
- }
+void update_history_controls(HWND hDlg)
+{
+ bool bEnable = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_INTERNAL_HISTORY));
- void update_popup_controls(HWND hDlg)
- {
- bool bEnable = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_SHOW_POPUP));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_POPUP_FORMAT), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_POPUP_FORMAT), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_FORMAT_DESCRIPTION), bEnable);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_SETTINGS), bEnable);
- }
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_HISTORY_FORMAT), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_HISTORY_FORMAT), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_HISTORY_DESCRIPTION), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_HISTORY_CONDITION), bEnable);
+}
- bool enable_popup_controls(HWND hDlg)
- {
- bool bIsPopupServiceEnabled = 1 == ServiceExists(MS_POPUP_ADDPOPUPT);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP), bIsPopupServiceEnabled);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_POPUP_FORMAT), bIsPopupServiceEnabled);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED), bIsPopupServiceEnabled);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_POPUP_FORMAT), bIsPopupServiceEnabled);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_FORMAT_DESCRIPTION), bIsPopupServiceEnabled);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_SETTINGS), bIsPopupServiceEnabled);
-
- return bIsPopupServiceEnabled;
- }
+void update_popup_controls(HWND hDlg)
+{
+ bool bEnable = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_SHOW_POPUP));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_POPUP_FORMAT), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_POPUP_FORMAT), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_FORMAT_DESCRIPTION), bEnable);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_SETTINGS), bEnable);
+}
- void update_all_controls(HWND hDlg)
- {
- bool bIsCheckedContactSpec = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_CONTACT_SPECIFIC));
- bool bIsCheckedExternal = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_EXTERNAL_FILE));
-
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_EXTERNAL_FILE), bIsCheckedContactSpec);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_FILE_NAME), (bIsCheckedContactSpec&&bIsCheckedExternal));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_SELECT_FILE), (bIsCheckedContactSpec&&bIsCheckedExternal));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_BROWSE), (bIsCheckedContactSpec&&bIsCheckedExternal));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_LOG_FILE_FORMAT), (bIsCheckedContactSpec&&bIsCheckedExternal));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_LOG_FILE_FORMAT), (bIsCheckedContactSpec&&bIsCheckedExternal));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_LOG_FILE_DESCRIPTION), (bIsCheckedContactSpec&&bIsCheckedExternal));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_LOG_FILE_CONDITION), (bIsCheckedContactSpec&&bIsCheckedExternal));
-
- bool bIsCheckedHistory = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_INTERNAL_HISTORY));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_INTERNAL_HISTORY), bIsCheckedContactSpec);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_HISTORY_FORMAT), (bIsCheckedContactSpec&&bIsCheckedHistory));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_HISTORY_FORMAT), (bIsCheckedContactSpec&&bIsCheckedHistory));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_HISTORY_DESCRIPTION), (bIsCheckedContactSpec&&bIsCheckedHistory));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_HISTORY_CONDITION), (bIsCheckedContactSpec&&bIsCheckedHistory));
-
- bool bIsPopupServiceEnabled = 1 == ServiceExists(MS_POPUP_ADDPOPUPT);
- bool bIsCheckedShowPopup = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_SHOW_POPUP));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP), (bIsCheckedContactSpec&&bIsPopupServiceEnabled));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_POPUP_FORMAT), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_POPUP_FORMAT), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_FORMAT_DESCRIPTION), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_SETTINGS), (bIsCheckedContactSpec&&bIsPopupServiceEnabled));
- }
+bool enable_popup_controls(HWND hDlg)
+{
+ bool bIsPopupServiceEnabled = 1 == ServiceExists(MS_POPUP_ADDPOPUPT);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP), bIsPopupServiceEnabled);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_POPUP_FORMAT), bIsPopupServiceEnabled);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED), bIsPopupServiceEnabled);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_POPUP_FORMAT), bIsPopupServiceEnabled);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_FORMAT_DESCRIPTION), bIsPopupServiceEnabled);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_SETTINGS), bIsPopupServiceEnabled);
- std::vector<TCHAR> get_filter()
- {
- std::vector<TCHAR> aFilter;
- LPCTSTR pszFilterParts[] = { LPGENT("Log Files (*.txt,*.log)"), _T("*.txt;*.log"), LPGENT("All files (*.*)"), _T("*.*") };
- for (int i = 0; i < sizeof(pszFilterParts) / sizeof(pszFilterParts[0]); ++i)
- {
- tstring sPart = TranslateTS(pszFilterParts[i]);
- std::copy(sPart.begin(), sPart.end(), std::back_inserter(aFilter));
- aFilter.push_back(_T('\0'));
+ return bIsPopupServiceEnabled;
+}
- }
+void update_all_controls(HWND hDlg)
+{
+ bool bIsCheckedContactSpec = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_CONTACT_SPECIFIC));
+ bool bIsCheckedExternal = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_EXTERNAL_FILE));
+
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_EXTERNAL_FILE), bIsCheckedContactSpec);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_FILE_NAME), (bIsCheckedContactSpec&&bIsCheckedExternal));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_SELECT_FILE), (bIsCheckedContactSpec&&bIsCheckedExternal));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_BROWSE), (bIsCheckedContactSpec&&bIsCheckedExternal));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_LOG_FILE_FORMAT), (bIsCheckedContactSpec&&bIsCheckedExternal));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_LOG_FILE_FORMAT), (bIsCheckedContactSpec&&bIsCheckedExternal));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_LOG_FILE_DESCRIPTION), (bIsCheckedContactSpec&&bIsCheckedExternal));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_LOG_FILE_CONDITION), (bIsCheckedContactSpec&&bIsCheckedExternal));
+
+ bool bIsCheckedHistory = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_INTERNAL_HISTORY));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_INTERNAL_HISTORY), bIsCheckedContactSpec);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_HISTORY_FORMAT), (bIsCheckedContactSpec&&bIsCheckedHistory));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_HISTORY_FORMAT), (bIsCheckedContactSpec&&bIsCheckedHistory));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_HISTORY_DESCRIPTION), (bIsCheckedContactSpec&&bIsCheckedHistory));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_HISTORY_CONDITION), (bIsCheckedContactSpec&&bIsCheckedHistory));
+
+ bool bIsPopupServiceEnabled = 1 == ServiceExists(MS_POPUP_ADDPOPUPT);
+ bool bIsCheckedShowPopup = (1 == ::IsDlgButtonChecked(hDlg, IDC_CHECK_SHOW_POPUP));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP), (bIsCheckedContactSpec&&bIsPopupServiceEnabled));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_EDIT_POPUP_FORMAT), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_STATIC_POPUP_FORMAT), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_FORMAT_DESCRIPTION), (bIsCheckedContactSpec&&bIsPopupServiceEnabled&&bIsCheckedShowPopup));
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_SETTINGS), (bIsCheckedContactSpec&&bIsPopupServiceEnabled));
+}
+
+std::vector<TCHAR> get_filter()
+{
+ std::vector<TCHAR> aFilter;
+ LPCTSTR pszFilterParts[] = { LPGENT("Log Files (*.txt,*.log)"), _T("*.txt;*.log"), LPGENT("All files (*.*)"), _T("*.*") };
+ for (int i = 0; i < sizeof(pszFilterParts) / sizeof(pszFilterParts[0]); ++i) {
+ tstring sPart = TranslateTS(pszFilterParts[i]);
+ std::copy(sPart.begin(), sPart.end(), std::back_inserter(aFilter));
aFilter.push_back(_T('\0'));
- return aFilter;
+
}
- void select_log_file(HWND hDlg)
- {
- std::vector<TCHAR> aFileBuffer(_MAX_PATH * 2, _T('\0'));
- LPTSTR pszFile = &*aFileBuffer.begin();
-
- std::vector<TCHAR> aFilterBuffer = get_filter();
- LPCTSTR pszFilter = &*aFilterBuffer.begin();
-
- OPENFILENAME ofn = { 0 };
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = hDlg;
- ofn.lpstrFile = pszFile;
- ofn.nMaxFile = (DWORD)aFileBuffer.size();
- ofn.lpstrFilter = pszFilter;
- ofn.nFilterIndex = 1;
- ofn.hInstance = g_hInstance;
- ofn.lpstrDefExt = _T("log");
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
-
- BOOL b = GetOpenFileName(&ofn);
- if (TRUE == b)
- {
- SetDlgItemText(hDlg, IDC_EDIT_FILE_NAME, ofn.lpstrFile);
- }
+ aFilter.push_back(_T('\0'));
+ return aFilter;
+}
+void select_log_file(HWND hDlg)
+{
+ std::vector<TCHAR> aFileBuffer(_MAX_PATH * 2, _T('\0'));
+ LPTSTR pszFile = &*aFileBuffer.begin();
+
+ std::vector<TCHAR> aFilterBuffer = get_filter();
+ LPCTSTR pszFilter = &*aFilterBuffer.begin();
+
+ OPENFILENAME ofn = { 0 };
+ ofn.lStructSize = sizeof(OPENFILENAME);
+ ofn.hwndOwner = hDlg;
+ ofn.lpstrFile = pszFile;
+ ofn.nMaxFile = (DWORD)aFileBuffer.size();
+ ofn.lpstrFilter = pszFilter;
+ ofn.nFilterIndex = 1;
+ ofn.hInstance = g_hInstance;
+ ofn.lpstrDefExt = _T("log");
+ ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;
+
+ BOOL b = GetOpenFileName(&ofn);
+ if (TRUE == b) {
+ SetDlgItemText(hDlg, IDC_EDIT_FILE_NAME, ofn.lpstrFile);
}
+}
- struct CSettingWindowParam
- {
- CSettingWindowParam(MCONTACT hContact) : m_hContact(hContact), m_pPopupSettings(NULL){}
- ~CSettingWindowParam(){ delete m_pPopupSettings; }
+struct CSettingWindowParam
+{
+ CSettingWindowParam(MCONTACT hContact) : m_hContact(hContact), m_pPopupSettings(NULL) {}
+ ~CSettingWindowParam() { delete m_pPopupSettings; }
- MCONTACT m_hContact;
- CPopupSettings* m_pPopupSettings;
- };
+ MCONTACT m_hContact;
+ CPopupSettings* m_pPopupSettings;
+};
- inline CSettingWindowParam* get_param(HWND hWnd)
- {
- return reinterpret_cast<CSettingWindowParam*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
- }
+inline CSettingWindowParam* get_param(HWND hWnd)
+{
+ return reinterpret_cast<CSettingWindowParam*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
+}
- void update_popup_controls_settings(HWND hDlg)
- {
- bool bIsColoursEnabled = 1 == IsDlgButtonChecked(hDlg, IDC_RADIO_USER_DEFINED_COLOURS);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_BGCOLOR), bIsColoursEnabled);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_TEXTCOLOR), bIsColoursEnabled);
+void update_popup_controls_settings(HWND hDlg)
+{
+ bool bIsColoursEnabled = 1 == IsDlgButtonChecked(hDlg, IDC_RADIO_USER_DEFINED_COLOURS);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_BGCOLOR), bIsColoursEnabled);
+ ::EnableWindow(::GetDlgItem(hDlg, IDC_TEXTCOLOR), bIsColoursEnabled);
- bool bIsDelayEnabled = 1 == IsDlgButtonChecked(hDlg, IDC_DELAYCUSTOM);
- ::EnableWindow(::GetDlgItem(hDlg, IDC_DELAY), bIsDelayEnabled);
+ 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)
- {
- switch (msg)
- {
- case WM_INITDIALOG:
+INT_PTR CALLBACK EditPopupSettingsDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
{
CPopupSettings* pSettings = reinterpret_cast<CPopupSettings*>(lp);
TranslateDialogDefault(hWnd);
@@ -164,8 +159,7 @@ namespace ::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())
- {
+ switch (pSettings->GetDelayMode()) {
default:
assert(!"Unknown delay mode. Please, fix it");
case CPopupSettings::delayFromPopup:
@@ -187,21 +181,22 @@ namespace ::SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pSettings));
}
return TRUE;
- case WM_COMMAND:
- switch (LOWORD(wp))
- {
- case IDC_RADIO_DEFAULT_COLOURS:
- case IDC_RADIO_USER_DEFINED_COLOURS:
- case IDC_DELAYFROMPU:
- case IDC_DELAYCUSTOM:
- case IDC_DELAYPERMANENT:
- update_popup_controls_settings(hWnd);
- break;
- case IDCANCEL:
- ::EndDialog(hWnd, IDCANCEL);
- break;
- case IDOK:
+ case WM_COMMAND:
+ switch (LOWORD(wp)) {
+ case IDC_RADIO_DEFAULT_COLOURS:
+ case IDC_RADIO_USER_DEFINED_COLOURS:
+ case IDC_DELAYFROMPU:
+ case IDC_DELAYCUSTOM:
+ case IDC_DELAYPERMANENT:
+ update_popup_controls_settings(hWnd);
+ break;
+
+ case IDCANCEL:
+ ::EndDialog(hWnd, IDCANCEL);
+ break;
+
+ case IDOK:
{
CPopupSettings* pSettings = reinterpret_cast<CPopupSettings*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
@@ -210,43 +205,30 @@ namespace UINT nDelay = ::GetDlgItemInt(hWnd, IDC_DELAY, &bOk, FALSE);
CPopupSettings::EDelayMode nModeDelay = pSettings->GetDelayMode();
if (1 == ::IsDlgButtonChecked(hWnd, IDC_DELAYFROMPU))
- {
nModeDelay = CPopupSettings::delayFromPopup;
- }
- else if (1 == ::IsDlgButtonChecked(hWnd, IDC_DELAYCUSTOM))
- {
+ else if (1 == ::IsDlgButtonChecked(hWnd, IDC_DELAYCUSTOM)) {
if (TRUE == bOk)
- {
nModeDelay = CPopupSettings::delayCustom;
- }
- else
- {
+ else {
prepare_edit_ctrl_for_error(::GetDlgItem(hWnd, IDC_DELAY));
Quotes_MessageBox(hWnd, TranslateT("Enter integer value"), MB_OK | MB_ICONERROR);
bError = true;
}
}
else if (1 == ::IsDlgButtonChecked(hWnd, IDC_DELAYPERMANENT))
- {
nModeDelay = CPopupSettings::delayPermanent;
- }
- if (false == bError)
- {
+
+ if (false == bError) {
pSettings->SetDelayMode(nModeDelay);
if (TRUE == bOk)
- {
pSettings->SetDelayTimeout(nDelay);
- }
+
pSettings->SetHistoryFlag((1 == IsDlgButtonChecked(hWnd, IDC_CHECK_DONT_USE_POPUPHISTORY)));
if (1 == ::IsDlgButtonChecked(hWnd, IDC_RADIO_DEFAULT_COLOURS))
- {
pSettings->SetColourMode(CPopupSettings::colourDefault);
- }
else if (1 == ::IsDlgButtonChecked(hWnd, IDC_RADIO_USER_DEFINED_COLOURS))
- {
pSettings->SetColourMode(CPopupSettings::colourUserDefined);
- }
pSettings->SetColourBk(static_cast<COLORREF>(::SendDlgItemMessage(hWnd, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0)));
pSettings->SetColourText(static_cast<COLORREF>(::SendDlgItemMessage(hWnd, IDC_TEXTCOLOR, CPM_GETCOLOUR, 0, 0)));
@@ -255,21 +237,20 @@ namespace }
}
break;
- }
- break;
}
-
- return FALSE;
+ break;
}
- INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
- {
- switch (msg)
- {
- case WM_INITDIALOG:
+ return FALSE;
+}
+
+INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hWnd);
{
MCONTACT hContact = MCONTACT(lp);
- TranslateDialogDefault(hWnd);
MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX_SETTINGS, false);
assert(hWL);
@@ -300,8 +281,7 @@ namespace ::CheckDlgButton(hWnd, IDC_CHECK_EXTERNAL_FILE, nCheck ? BST_CHECKED : BST_UNCHECKED);
tstring sLogFileName = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG_FILE);
- if (true == sLogFileName.empty())
- {
+ if (true == sLogFileName.empty()) {
sLogFileName = GenerateLogFileName(setGlobal.GetLogFileName(), Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL), glfnResolveQuoteName);
}
::SetDlgItemText(hWnd, IDC_EDIT_FILE_NAME, sLogFileName.c_str());
@@ -328,69 +308,57 @@ namespace ::ShowWindow(hWnd, SW_SHOW);
}
break;
- case WM_COMMAND:
- switch (LOWORD(wp))
- {
- case IDC_BUTTON_HISTORY_DESCRIPTION:
- case IDC_BUTTON_LOG_FILE_DESCRIPTION:
- case IDC_BUTTON_POPUP_FORMAT_DESCRIPTION:
- if (BN_CLICKED == HIWORD(wp))
- {
- CQuotesProviders::TQuotesProviderPtr pProvider = CModuleInfo::GetQuoteProvidersPtr()->GetContactProviderPtr(get_param(hWnd)->m_hContact);
- show_variable_list(hWnd, pProvider.get());
- }
- break;
- case IDC_CHECK_CONTACT_SPECIFIC:
- if (BN_CLICKED == HIWORD(wp))
- {
- update_all_controls(hWnd);
- }
- break;
- case IDC_CHECK_EXTERNAL_FILE:
- if (BN_CLICKED == HIWORD(wp))
- {
- update_file_controls(hWnd);
- }
- break;
- case IDC_CHECK_INTERNAL_HISTORY:
- if (BN_CLICKED == HIWORD(wp))
- {
- update_history_controls(hWnd);
- }
- break;
- case IDC_CHECK_SHOW_POPUP:
- if (BN_CLICKED == HIWORD(wp))
- {
- update_popup_controls(hWnd);
- }
- break;
- case IDC_BUTTON_BROWSE:
- if (BN_CLICKED == HIWORD(wp))
- {
- select_log_file(hWnd);
- }
- break;
- case IDC_BUTTON_POPUP_SETTINGS:
- if (BN_CLICKED == HIWORD(wp))
- {
- CSettingWindowParam* pParam = get_param(hWnd);
- if (!pParam->m_pPopupSettings)
- {
- CQuotesProviders::TQuotesProviderPtr pProvider = CModuleInfo::GetQuoteProvidersPtr()->GetContactProviderPtr(pParam->m_hContact);
-
- pParam->m_pPopupSettings = new CPopupSettings(pProvider.get());
- pParam->m_pPopupSettings->InitForContact(pParam->m_hContact);
- }
+ case WM_COMMAND:
+ switch (LOWORD(wp)) {
+ case IDC_BUTTON_HISTORY_DESCRIPTION:
+ case IDC_BUTTON_LOG_FILE_DESCRIPTION:
+ case IDC_BUTTON_POPUP_FORMAT_DESCRIPTION:
+ if (BN_CLICKED == HIWORD(wp)) {
+ CQuotesProviders::TQuotesProviderPtr pProvider = CModuleInfo::GetQuoteProvidersPtr()->GetContactProviderPtr(get_param(hWnd)->m_hContact);
+ show_variable_list(hWnd, pProvider.get());
+ }
+ break;
- DialogBoxParam(g_hInstance,
- MAKEINTRESOURCE(IDD_DIALOG_POPUP),
- hWnd,
- EditPopupSettingsDlgProc, reinterpret_cast<LPARAM>(pParam->m_pPopupSettings));
+ case IDC_CHECK_CONTACT_SPECIFIC:
+ if (BN_CLICKED == HIWORD(wp))
+ update_all_controls(hWnd);
+ break;
+ case IDC_CHECK_EXTERNAL_FILE:
+ if (BN_CLICKED == HIWORD(wp))
+ update_file_controls(hWnd);
+ break;
+ case IDC_CHECK_INTERNAL_HISTORY:
+ if (BN_CLICKED == HIWORD(wp))
+ update_history_controls(hWnd);
+ break;
+ case IDC_CHECK_SHOW_POPUP:
+ if (BN_CLICKED == HIWORD(wp))
+ update_popup_controls(hWnd);
+ break;
+ case IDC_BUTTON_BROWSE:
+ if (BN_CLICKED == HIWORD(wp))
+ select_log_file(hWnd);
+ break;
+
+ case IDC_BUTTON_POPUP_SETTINGS:
+ if (BN_CLICKED == HIWORD(wp)) {
+ CSettingWindowParam* pParam = get_param(hWnd);
+ if (!pParam->m_pPopupSettings) {
+ CQuotesProviders::TQuotesProviderPtr pProvider = CModuleInfo::GetQuoteProvidersPtr()->GetContactProviderPtr(pParam->m_hContact);
+
+ pParam->m_pPopupSettings = new CPopupSettings(pProvider.get());
+ pParam->m_pPopupSettings->InitForContact(pParam->m_hContact);
}
- break;
- case IDOK:
+ DialogBoxParam(g_hInstance,
+ MAKEINTRESOURCE(IDD_DIALOG_POPUP),
+ hWnd,
+ EditPopupSettingsDlgProc, reinterpret_cast<LPARAM>(pParam->m_pPopupSettings));
+ }
+ break;
+
+ case IDOK:
{
CSettingWindowParam* pParam = get_param(hWnd);
MCONTACT hContact = pParam->m_hContact;
@@ -400,21 +368,15 @@ namespace WORD nLogMode = lmDisabled;
UINT nCheck = ::IsDlgButtonChecked(hWnd, IDC_CHECK_EXTERNAL_FILE);
if (1 == nCheck)
- {
nLogMode |= lmExternalFile;
- }
nCheck = ::IsDlgButtonChecked(hWnd, IDC_CHECK_INTERNAL_HISTORY);
if (1 == nCheck)
- {
nLogMode |= lmInternalHistory;
- }
nCheck = ::IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_POPUP);
if (1 == nCheck)
- {
nLogMode |= lmPopup;
- }
bool bOk = true;
HWND hwndLogFile = ::GetDlgItem(hWnd, IDC_EDIT_FILE_NAME);
@@ -423,24 +385,20 @@ namespace tstring sLogFile = get_window_text(hwndLogFile);
tstring sLogFileFormat = get_window_text(hwndLogFileFrmt);
tstring sHistoryFormat = get_window_text(hwndHistoryFrmt);
- if ((nLogMode&lmExternalFile))
- {
- if (true == sLogFile.empty())
- {
+ if ((nLogMode&lmExternalFile)) {
+ if (true == sLogFile.empty()) {
prepare_edit_ctrl_for_error(hwndLogFile);
Quotes_MessageBox(hWnd, TranslateT("Enter log file name."), MB_OK | MB_ICONERROR);
bOk = false;
}
- else if (true == sLogFileFormat.empty())
- {
+ else if (true == sLogFileFormat.empty()) {
prepare_edit_ctrl_for_error(hwndLogFileFrmt);
Quotes_MessageBox(hWnd, TranslateT("Enter log file format."), MB_OK | MB_ICONERROR);
bOk = false;
}
}
- if ((true == bOk) && (nLogMode&lmInternalHistory) && (true == sHistoryFormat.empty()))
- {
+ if ((true == bOk) && (nLogMode&lmInternalHistory) && (true == sHistoryFormat.empty())) {
prepare_edit_ctrl_for_error(hwndHistoryFrmt);
Quotes_MessageBox(hWnd, TranslateT("Enter history format."), MB_OK | MB_ICONERROR);
bOk = false;
@@ -448,15 +406,13 @@ namespace HWND hwndPopupFrmt = ::GetDlgItem(hWnd, IDC_EDIT_POPUP_FORMAT);
tstring sPopupFormat = get_window_text(hwndPopupFrmt);
- if ((true == bOk) && (nLogMode&lmPopup) && (true == sPopupFormat.empty()))
- {
+ if ((true == bOk) && (nLogMode&lmPopup) && (true == sPopupFormat.empty())) {
prepare_edit_ctrl_for_error(hwndPopupFrmt);
Quotes_MessageBox(hWnd, TranslateT("Enter popup window format."), MB_OK | MB_ICONERROR);
bOk = false;
}
- if (true == bOk)
- {
+ if (true == bOk) {
UINT nIfChangedHistory = IsDlgButtonChecked(hWnd, IDC_CHECK_HISTORY_CONDITION);
UINT nIfChangedFile = IsDlgButtonChecked(hWnd, IDC_CHECK_LOG_FILE_CONDITION);
bool bIfChangedPopup = (1 == IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED));
@@ -471,8 +427,7 @@ namespace db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_HISTORY, sHistoryFormat.c_str());
db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_POPUP, sPopupFormat.c_str());
- if (pParam->m_pPopupSettings)
- {
+ if (pParam->m_pPopupSettings) {
pParam->m_pPopupSettings->SaveForContact(hContact);
}
@@ -480,58 +435,50 @@ namespace }
}
break;
- case IDCANCEL:
- DestroyWindow(hWnd);
- break;
- }
- break;
- case WM_CLOSE:
+
+ case IDCANCEL:
DestroyWindow(hWnd);
break;
- case WM_DESTROY:
- {
- CSettingWindowParam* pParam = get_param(hWnd);
- SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
-
- MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX_SETTINGS, false);
- assert(hWL);
- WindowList_Remove(hWL, hWnd);
- Utils_SaveWindowPosition(hWnd, pParam->m_hContact, QUOTES_MODULE_NAME, WINDOW_PREFIX_SETTINGS);
- delete pParam;
}
break;
- }
- return FALSE;
+ case WM_CLOSE:
+ DestroyWindow(hWnd);
+ break;
+
+ case WM_DESTROY:
+ CSettingWindowParam* pParam = get_param(hWnd);
+ SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
+
+ MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX_SETTINGS, false);
+ assert(hWL);
+ WindowList_Remove(hWL, hWnd);
+ Utils_SaveWindowPosition(hWnd, pParam->m_hContact, QUOTES_MODULE_NAME, WINDOW_PREFIX_SETTINGS);
+ delete pParam;
+ break;
}
-}
+ return FALSE;
+}
void ShowSettingsDlg(MCONTACT hContact)
{
MWindowList hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX_SETTINGS, true);
assert(hWL);
HWND hWnd = WindowList_Find(hWL, hContact);
- if (NULL != hWnd)
- {
+ if (NULL != hWnd) {
SetForegroundWindow(hWnd);
SetFocus(hWnd);
}
- else
- {
- CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_CONTACT_SETTINGS), NULL, EditSettingsPerContactDlgProc, LPARAM(hContact));
- }
+ else CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_CONTACT_SETTINGS), NULL, EditSettingsPerContactDlgProc, LPARAM(hContact));
}
//////////////////////////////////////////////////////////////////////////
-namespace
+INT_PTR CALLBACK EditSettingsPerProviderDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
- INT_PTR CALLBACK EditSettingsPerProviderDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
- {
- switch (msg)
- {
- case WM_INITDIALOG:
+ switch (msg) {
+ case WM_INITDIALOG:
{
TranslateDialogDefault(hWnd);
CAdvProviderSettings* pAdvSettings = reinterpret_cast<CAdvProviderSettings*>(lp);
@@ -562,34 +509,29 @@ namespace ::CheckDlgButton(hWnd, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED, (pAdvSettings->GetShowPopupIfValueChangedFlag()) ? BST_CHECKED : BST_UNCHECKED);
if (true == enable_popup_controls(hWnd))
- {
update_popup_controls(hWnd);
- }
-
+
::SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pAdvSettings));
}
return TRUE;
- case WM_COMMAND:
- switch (LOWORD(wp))
- {
- case IDOK:
+
+ case WM_COMMAND:
+ switch (LOWORD(wp)) {
+ case IDOK:
{
WORD nLogMode = lmDisabled;
UINT nCheck = ::IsDlgButtonChecked(hWnd, IDC_CHECK_EXTERNAL_FILE);
- if (1 == nCheck)
- {
+ if (1 == nCheck) {
nLogMode |= lmExternalFile;
}
nCheck = ::IsDlgButtonChecked(hWnd, IDC_CHECK_INTERNAL_HISTORY);
- if (1 == nCheck)
- {
+ if (1 == nCheck) {
nLogMode |= lmInternalHistory;
}
nCheck = ::IsDlgButtonChecked(hWnd, IDC_CHECK_SHOW_POPUP);
- if (1 == nCheck)
- {
+ if (1 == nCheck) {
nLogMode |= lmPopup;
}
@@ -600,16 +542,13 @@ namespace tstring sLogFile = get_window_text(hwndLogFile);
tstring sLogFileFormat = get_window_text(hwndLogFileFrmt);
- if ((nLogMode&lmExternalFile))
- {
- if (true == sLogFile.empty())
- {
+ if ((nLogMode&lmExternalFile)) {
+ if (true == sLogFile.empty()) {
prepare_edit_ctrl_for_error(hwndLogFile);
Quotes_MessageBox(hWnd, TranslateT("Enter log file name."), MB_OK | MB_ICONERROR);
bOk = false;
}
- else if (true == sLogFileFormat.empty())
- {
+ else if (true == sLogFileFormat.empty()) {
prepare_edit_ctrl_for_error(hwndLogFileFrmt);
Quotes_MessageBox(hWnd, TranslateT("Enter log file format."), MB_OK | MB_ICONERROR);
bOk = false;
@@ -618,8 +557,7 @@ namespace HWND hwndHistoryFrmt = ::GetDlgItem(hWnd, IDC_EDIT_HISTORY_FORMAT);
tstring sHistoryFormat = get_window_text(hwndHistoryFrmt);
- if ((true == bOk) && (nLogMode&lmInternalHistory) && (true == sHistoryFormat.empty()))
- {
+ if ((true == bOk) && (nLogMode&lmInternalHistory) && (true == sHistoryFormat.empty())) {
prepare_edit_ctrl_for_error(hwndHistoryFrmt);
Quotes_MessageBox(hWnd, TranslateT("Enter history format."), MB_OK | MB_ICONERROR);
bOk = false;
@@ -627,15 +565,13 @@ namespace HWND hwndPopupFrmt = ::GetDlgItem(hWnd, IDC_EDIT_POPUP_FORMAT);
tstring sPopupFormat = get_window_text(hwndPopupFrmt);
- if ((true == bOk) && (nLogMode&lmPopup) && (true == sPopupFormat.empty()))
- {
+ if ((true == bOk) && (nLogMode&lmPopup) && (true == sPopupFormat.empty())) {
prepare_edit_ctrl_for_error(hwndPopupFrmt);
Quotes_MessageBox(hWnd, TranslateT("Enter popup window format."), MB_OK | MB_ICONERROR);
bOk = false;
}
- if (true == bOk)
- {
+ if (true == bOk) {
CAdvProviderSettings* pAdvSettings = reinterpret_cast<CAdvProviderSettings*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
pAdvSettings->SetLogMode(nLogMode);
@@ -651,57 +587,51 @@ namespace }
}
break;
- case IDCANCEL:
- ::EndDialog(hWnd, IDCANCEL);
- break;
- case IDC_BUTTON_HISTORY_DESCRIPTION:
- case IDC_BUTTON_LOG_FILE_DESCRIPTION:
- case IDC_BUTTON_POPUP_FORMAT_DESCRIPTION:
- if (BN_CLICKED == HIWORD(wp))
- {
- const CAdvProviderSettings* pAdvSettings = reinterpret_cast<CAdvProviderSettings*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
- show_variable_list(hWnd, pAdvSettings->GetProviderPtr());
- }
- break;
- case IDC_CHECK_EXTERNAL_FILE:
- if (BN_CLICKED == HIWORD(wp))
- {
- update_file_controls(hWnd);
- }
- break;
- case IDC_CHECK_INTERNAL_HISTORY:
- if (BN_CLICKED == HIWORD(wp))
- {
- update_history_controls(hWnd);
- }
- break;
- case IDC_CHECK_SHOW_POPUP:
- if (BN_CLICKED == HIWORD(wp))
- {
- update_popup_controls(hWnd);
- }
- break;
- case IDC_BUTTON_BROWSE:
- if (BN_CLICKED == HIWORD(wp))
- {
- select_log_file(hWnd);
- }
- break;
- case IDC_BUTTON_POPUP_SETTINGS:
- {
+
+ case IDCANCEL:
+ ::EndDialog(hWnd, IDCANCEL);
+ break;
+
+ case IDC_BUTTON_HISTORY_DESCRIPTION:
+ case IDC_BUTTON_LOG_FILE_DESCRIPTION:
+ case IDC_BUTTON_POPUP_FORMAT_DESCRIPTION:
+ if (BN_CLICKED == HIWORD(wp)) {
const CAdvProviderSettings* pAdvSettings = reinterpret_cast<CAdvProviderSettings*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
- DialogBoxParam(g_hInstance,
- MAKEINTRESOURCE(IDD_DIALOG_POPUP),
- hWnd,
- EditPopupSettingsDlgProc, reinterpret_cast<LPARAM>(pAdvSettings->GetPopupSettingsPtr()));
-
+ show_variable_list(hWnd, pAdvSettings->GetProviderPtr());
}
break;
- }
+
+ case IDC_CHECK_EXTERNAL_FILE:
+ if (BN_CLICKED == HIWORD(wp))
+ update_file_controls(hWnd);
+ break;
+
+ case IDC_CHECK_INTERNAL_HISTORY:
+ if (BN_CLICKED == HIWORD(wp))
+ update_history_controls(hWnd);
+ break;
+
+ case IDC_CHECK_SHOW_POPUP:
+ if (BN_CLICKED == HIWORD(wp))
+ update_popup_controls(hWnd);
+ break;
+
+ case IDC_BUTTON_BROWSE:
+ if (BN_CLICKED == HIWORD(wp))
+ select_log_file(hWnd);
+ break;
+
+ case IDC_BUTTON_POPUP_SETTINGS:
+ const CAdvProviderSettings* pAdvSettings = reinterpret_cast<CAdvProviderSettings*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
+ DialogBoxParam(g_hInstance,
+ MAKEINTRESOURCE(IDD_DIALOG_POPUP),
+ hWnd,
+ EditPopupSettingsDlgProc, reinterpret_cast<LPARAM>(pAdvSettings->GetPopupSettingsPtr()));
break;
}
- return FALSE;
+ break;
}
+ return FALSE;
}
CAdvProviderSettings::CAdvProviderSettings(const IQuotesProvider* pQuotesProvider)
@@ -731,8 +661,7 @@ CAdvProviderSettings::CAdvProviderSettings(const IQuotesProvider* pQuotesProvide m_bIsOnlyChangedHistory = 1 == db_get_b(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbHistoryCondition, 0);
m_sLogFileName = Quotes_DBGetStringT(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbLogFile);
- if (true == m_sLogFileName.empty())
- {
+ if (true == m_sLogFileName.empty()) {
m_sLogFileName = g_pszVariableUserProfile;
m_sLogFileName += _T("\\Quotes\\");
m_sLogFileName += g_pszVariableQuoteName;
@@ -783,8 +712,7 @@ void CAdvProviderSettings::SaveToDb()const db_set_ts(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupFormat, m_sPopupFormat.c_str());
db_set_b(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupCondition, m_bShowPopupIfValueChanged);
- if (nullptr != m_pPopupSettings)
- {
+ if (nullptr != m_pPopupSettings) {
db_set_b(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupColourMode, static_cast<BYTE>(m_pPopupSettings->GetColourMode()));
db_set_dw(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupBkColour, m_pPopupSettings->GetColourBk());
db_set_dw(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupTextColour, m_pPopupSettings->GetColourText());
@@ -877,9 +805,7 @@ void CAdvProviderSettings::SetShowPopupIfValueChangedFlag(bool val) CPopupSettings* CAdvProviderSettings::GetPopupSettingsPtr()const
{
if (nullptr == m_pPopupSettings)
- {
m_pPopupSettings = new CPopupSettings(m_pQuotesProvider);
- }
return m_pPopupSettings;
}
@@ -905,16 +831,13 @@ CPopupSettings::CPopupSettings(const IQuotesProvider* pQuotesProvider) BYTE m = db_get_b(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupColourMode, static_cast<BYTE>(m_modeColour));
if (m >= colourDefault && m <= colourUserDefined)
- {
m_modeColour = static_cast<EColourMode>(m);
- }
m_rgbBkg = db_get_dw(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupBkColour, m_rgbBkg);
m_rgbText = db_get_dw(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupTextColour, m_rgbText);
m = db_get_b(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupDelayMode, static_cast<BYTE>(m_modeDelay));
- if (m >= delayFromPopup && m <= delayPermanent)
- {
+ if (m >= delayFromPopup && m <= delayPermanent) {
m_modeDelay = static_cast<EDelayMode>(m);
}
m_wDelay = db_get_w(NULL, QUOTES_PROTOCOL_NAME, visitor.m_pszDbPopupDelayTimeout, m_wDelay);
@@ -936,8 +859,7 @@ COLORREF CPopupSettings::GetDefColourText() void CPopupSettings::InitForContact(MCONTACT hContact)
{
BYTE m = db_get_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_POPUP_COLOUR_MODE, static_cast<BYTE>(m_modeColour));
- if (m >= CPopupSettings::colourDefault && m <= CPopupSettings::colourUserDefined)
- {
+ if (m >= CPopupSettings::colourDefault && m <= CPopupSettings::colourUserDefined) {
m_modeColour = static_cast<CPopupSettings::EColourMode>(m);
}
@@ -945,8 +867,7 @@ void CPopupSettings::InitForContact(MCONTACT hContact) m_rgbText = db_get_dw(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_POPUP_COLOUR_TEXT, m_rgbText);
m = db_get_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_POPUP_DELAY_MODE, static_cast<BYTE>(m_modeDelay));
- if (m >= CPopupSettings::delayFromPopup && m <= CPopupSettings::delayPermanent)
- {
+ if (m >= CPopupSettings::delayFromPopup && m <= CPopupSettings::delayPermanent) {
m_modeDelay = static_cast<CPopupSettings::EDelayMode>(m);
}
m_wDelay = db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_POPUP_DELAY_TIMEOUT, m_wDelay);
@@ -1034,47 +955,35 @@ bool ShowSettingsDlg(HWND hWndParent, CAdvProviderSettings* pAdvSettings) reinterpret_cast<LPARAM>(pAdvSettings)));
}
-namespace
+static void replace_invalid_char(tstring::value_type& rChar, tstring::value_type repl)
{
- void replace_invalid_char(tstring::value_type& rChar, tstring::value_type repl)
- {
- static const TCHAR charInvalidSigns[] = { _T('\\'), _T('/'), _T(':'), _T('*'), _T('?'), _T('\"'), _T('<'), _T('>'), _T('|') };
+ static const TCHAR charInvalidSigns[] = { _T('\\'), _T('/'), _T(':'), _T('*'), _T('?'), _T('\"'), _T('<'), _T('>'), _T('|') };
- for (int i = 0; i < sizeof(charInvalidSigns) / sizeof(charInvalidSigns[0]); ++i)
- {
- if (rChar == charInvalidSigns[i])
- {
- rChar = repl;
- break;
- }
+ for (int i = 0; i < sizeof(charInvalidSigns) / sizeof(charInvalidSigns[0]); ++i) {
+ if (rChar == charInvalidSigns[i]) {
+ rChar = repl;
+ break;
}
}
-
}
-tstring GenerateLogFileName(const tstring& rsLogFilePattern,
- const tstring& rsQuoteSymbol,
- int nFlags/* = glfnResolveAll*/)
+tstring GenerateLogFileName(const tstring &rsLogFilePattern, const tstring &rsQuoteSymbol, int nFlags)
{
tstring sPath = rsLogFilePattern;
- if (nFlags&glfnResolveQuoteName)
- {
+ if (nFlags&glfnResolveQuoteName) {
assert(false == rsQuoteSymbol.empty());
tstring::size_type n = sPath.find(g_pszVariableQuoteName);
- if (tstring::npos != n)
- {
+ if (tstring::npos != n) {
tstring s = rsQuoteSymbol;
std::for_each(s.begin(), s.end(), boost::bind(replace_invalid_char, _1, _T('_')));
sPath.replace(n, mir_tstrlen(g_pszVariableQuoteName), s.c_str());
}
}
- if (nFlags & glfnResolveUserProfile)
- {
- TCHAR* ptszParsedName = Utils_ReplaceVarsT(sPath.c_str());
- if (ptszParsedName)
- {
+ if (nFlags & glfnResolveUserProfile) {
+ TCHAR *ptszParsedName = Utils_ReplaceVarsT(sPath.c_str());
+ if (ptszParsedName) {
sPath = ptszParsedName;
mir_free(ptszParsedName);
}
@@ -1088,16 +997,12 @@ tstring GetContactLogFileName(MCONTACT hContact) tstring result;
const CQuotesProviders::TQuotesProviderPtr& pProvider = CModuleInfo::GetQuoteProvidersPtr()->GetContactProviderPtr(hContact);
- if (pProvider)
- {
+ if (pProvider) {
tstring sPattern;
bool bUseContactSpecific = (db_get_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_CONTACT_SPEC_SETTINGS, 0) > 0);
if (bUseContactSpecific)
- {
sPattern = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG_FILE);
- }
- else
- {
+ else {
CAdvProviderSettings global_settings(pProvider.get());
sPattern = global_settings.GetLogFileName();
}
@@ -1112,8 +1017,7 @@ tstring GetContactName(MCONTACT hContact) {
tstring sDescription = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_DESCRIPTION);
if (sDescription.empty())
- {
sDescription = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL);
- }
+
return sDescription;
}
diff --git a/plugins/Quotes/src/WinCtrlHelper.cpp b/plugins/Quotes/src/WinCtrlHelper.cpp index 3edd248631..9ca18a6811 100644 --- a/plugins/Quotes/src/WinCtrlHelper.cpp +++ b/plugins/Quotes/src/WinCtrlHelper.cpp @@ -1,14 +1,11 @@ #include "stdafx.h"
-namespace
+static INT_PTR CALLBACK VariableListDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
- INT_PTR CALLBACK VariableListDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
- {
- switch (msg)
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hWnd);
{
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hWnd);
const IQuotesProvider* pProvider = reinterpret_cast<const IQuotesProvider*>(lp);
CQuotesProviderVisitorFormatSpecificator visitor;
pProvider->Accept(visitor);
@@ -23,16 +20,14 @@ namespace ::SetDlgItemText(hWnd, IDC_EDIT_VARIABLE, o.str().c_str());
}
break;
- case WM_COMMAND:
- if (BN_CLICKED == HIWORD(wp) && (IDOK == LOWORD(wp) || IDCANCEL == LOWORD(wp)))
- {
- ::EndDialog(hWnd, IDOK);
- }
- break;
- }
- return FALSE;
+ case WM_COMMAND:
+ if (BN_CLICKED == HIWORD(wp) && (IDOK == LOWORD(wp) || IDCANCEL == LOWORD(wp)))
+ ::EndDialog(hWnd, IDOK);
+ break;
}
+
+ return FALSE;
}
void show_variable_list(HWND hwndParent, const IQuotesProvider* pProvider)
diff --git a/plugins/Quotes/src/WorkingThread.cpp b/plugins/Quotes/src/WorkingThread.cpp deleted file mode 100644 index f53b795226..0000000000 --- a/plugins/Quotes/src/WorkingThread.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "StdAfx.h"
-
-void WorkingThread(void* pParam)
-{
- IQuotesProvider* pProvider = reinterpret_cast<IQuotesProvider*>(pParam);
- assert(pProvider);
-
- if (pProvider)
- {
- pProvider->Run();
- }
-}
diff --git a/plugins/Quotes/src/WorkingThread.h b/plugins/Quotes/src/WorkingThread.h deleted file mode 100644 index a77734bb85..0000000000 --- a/plugins/Quotes/src/WorkingThread.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __cd52f1a3_63b2_44f0_a0a9_48c203958fa4_WorkingThread_h__
-#define __cd52f1a3_63b2_44f0_a0a9_48c203958fa4_WorkingThread_h__
-
-void WorkingThread(void* pParam);
-
-#endif //__cd52f1a3_63b2_44f0_a0a9_48c203958fa4_WorkingThread_h__
diff --git a/plugins/Quotes/src/XMLEngineMI.cpp b/plugins/Quotes/src/XMLEngineMI.cpp index 6cd1ca5863..93d87ce87c 100644 --- a/plugins/Quotes/src/XMLEngineMI.cpp +++ b/plugins/Quotes/src/XMLEngineMI.cpp @@ -1,125 +1,91 @@ #include "StdAfx.h"
-namespace
+class CXMLNodeMI : public IXMLNode, private boost::noncopyable
{
- class CXMLNodeMI : public IXMLNode,
- private boost::noncopyable
- {
- public:
- typedef boost::shared_ptr<IXMLNode> TXMLNodePtr;
+public:
+ typedef boost::shared_ptr<IXMLNode> TXMLNodePtr;
- public:
- explicit CXMLNodeMI(HXML hXMl, bool bDestroy = false) : m_hXML(hXMl), m_bDestroy(bDestroy)
- {
- assert(m_hXML);
- }
+public:
+ explicit CXMLNodeMI(HXML hXMl, bool bDestroy = false) : m_hXML(hXMl), m_bDestroy(bDestroy)
+ {
+ assert(m_hXML);
+ }
- virtual ~CXMLNodeMI()
- {
- if (m_bDestroy)
- {
- xmlDestroyNode(m_hXML);
- }
- }
+ virtual ~CXMLNodeMI()
+ {
+ if (m_bDestroy)
+ xmlDestroyNode(m_hXML);
+ }
- virtual size_t GetChildCount()const
- {
- return xmlGetChildCount(m_hXML);
- }
+ virtual size_t GetChildCount()const
+ {
+ return xmlGetChildCount(m_hXML);
+ }
- virtual TXMLNodePtr GetChildNode(size_t nIndex)const
- {
- HXML h = xmlGetChild(m_hXML, (int)nIndex);
- if (h)
- {
- return TXMLNodePtr(new CXMLNodeMI(h));
- }
- else
- {
- return TXMLNodePtr();
- }
- }
+ virtual TXMLNodePtr GetChildNode(size_t nIndex)const
+ {
+ HXML h = xmlGetChild(m_hXML, (int)nIndex);
+ if (h)
+ return TXMLNodePtr(new CXMLNodeMI(h));
- virtual tstring GetText()const
- {
- tstring sResult;
- LPCTSTR psz = xmlGetText(m_hXML);
- if (psz)
- {
- sResult = psz;
- }
+ return TXMLNodePtr();
+ }
- return sResult;
- }
+ virtual tstring GetText()const
+ {
+ tstring sResult;
+ LPCTSTR psz = xmlGetText(m_hXML);
+ if (psz)
+ sResult = psz;
- virtual tstring GetName()const
- {
- tstring sResult;
- LPCTSTR psz = xmlGetName(m_hXML);
- if (psz)
- {
- sResult = psz;
- }
+ return sResult;
+ }
- return sResult;
- }
+ virtual tstring GetName()const
+ {
+ tstring sResult;
+ LPCTSTR psz = xmlGetName(m_hXML);
+ if (psz)
+ sResult = psz;
- virtual bool AddChild(const TXMLNodePtr& pNode)
- {
- CXMLNodeMI* pXML = dynamic_cast<CXMLNodeMI*>(pNode.get());
- if (pXML)
- {
- xmlAddChild2(pXML->m_hXML, m_hXML);
- pXML->m_bDestroy = false;
- return true;
- }
- else
- {
- return false;
- }
- }
+ return sResult;
+ }
- virtual bool AddAttribute(const tstring& rsName, const tstring& rsValue)
- {
- xmlAddAttr(m_hXML, rsName.c_str(), rsValue.c_str());
+ virtual bool AddChild(const TXMLNodePtr& pNode)
+ {
+ CXMLNodeMI* pXML = dynamic_cast<CXMLNodeMI*>(pNode.get());
+ if (pXML) {
+ xmlAddChild2(pXML->m_hXML, m_hXML);
+ pXML->m_bDestroy = false;
return true;
}
- virtual tstring GetAttributeValue(const tstring& rsAttrName)
- {
- LPCTSTR pszValue = xmlGetAttrValue(m_hXML, rsAttrName.c_str());
- return ((NULL != pszValue) ? tstring(pszValue) : tstring());
- }
+ return false;
+ }
- virtual void Write(tostream& o)const
- {
- // struct safe_string
- // {
- // safe_string(LPTSTR p):m_p(p){}
- // ~safe_string(){xmlFree(m_p);}
- //
- // LPTSTR m_p;
- // };
- //
- // struct mir_safe_string
- // {
- // mir_safe_string(LPSTR p) : m_p(p){}
- // ~mir_safe_string(){mir_free(m_p);}
- //
- // LPSTR m_p;
- // };
-
-
- safe_string<TCHAR> ss(xmlToString(m_hXML, NULL));
- if (ss.m_p)
- o << (char*)T2Utf(ss.m_p);
- }
+ virtual bool AddAttribute(const tstring& rsName, const tstring& rsValue)
+ {
+ xmlAddAttr(m_hXML, rsName.c_str(), rsValue.c_str());
+ return true;
+ }
- private:
- HXML m_hXML;
- bool m_bDestroy;
- };
-}
+ virtual tstring GetAttributeValue(const tstring& rsAttrName)
+ {
+ LPCTSTR pszValue = xmlGetAttrValue(m_hXML, rsAttrName.c_str());
+ return ((NULL != pszValue) ? tstring(pszValue) : tstring());
+ }
+
+ virtual void Write(tostream& o)const
+ {
+ safe_string<TCHAR> ss(xmlToString(m_hXML, NULL));
+ if (ss.m_p)
+ o << (char*)T2Utf(ss.m_p);
+ }
+
+private:
+ HXML m_hXML;
+ bool m_bDestroy;
+};
CXMLEngineMI::CXMLEngineMI()
{
@@ -131,38 +97,23 @@ CXMLEngineMI::~CXMLEngineMI() IXMLNode::TXMLNodePtr CXMLEngineMI::LoadFile(const tstring& rsFileName)const
{
- // struct mir_safe_string
- // {
- // mir_safe_string(LPTSTR p) : m_p(p){}
- // ~mir_safe_string(){mir_free(m_p);}
- //
- // LPTSTR m_p;
- // };
-
-
IXMLNode::TXMLNodePtr pResult;
FILE* stream;
- if (0 == ::_tfopen_s(&stream, rsFileName.c_str(), _T("r")))
- {
+ if (0 == ::_tfopen_s(&stream, rsFileName.c_str(), _T("r"))) {
struct _stat st;
- if (-1 != ::_fstat(::_fileno(stream), &st))
- {
+ if (-1 != ::_fstat(::_fileno(stream), &st)) {
std::vector<char> aBuffer(st.st_size + 1);
char* pBuffer = &*(aBuffer.begin());
size_t cBytes = ::fread(pBuffer, sizeof(char), st.st_size, stream);
- if (cBytes > 0 && cBytes <= static_cast<size_t>(st.st_size))
- {
+ if (cBytes > 0 && cBytes <= static_cast<size_t>(st.st_size)) {
pBuffer[cBytes] = '\0';
int nLen = (int)cBytes;
mir_safe_string<TCHAR> ss(mir_utf8decodeT(pBuffer));
- if (ss.m_p)
- {
+ if (ss.m_p) {
HXML h = xmlParseString(ss.m_p, &nLen, NULL);
if (h)
- {
pResult = IXMLNode::TXMLNodePtr(new CXMLNodeMI(h, true));
- }
}
}
}
@@ -172,39 +123,30 @@ IXMLNode::TXMLNodePtr CXMLEngineMI::LoadFile(const tstring& rsFileName)const return pResult;
}
-namespace
+static IXMLNode::TXMLNodePtr create_node(const tstring& rsName, const tstring& rsText, bool bIsDecl)
{
- IXMLNode::TXMLNodePtr create_node(const tstring& rsName, const tstring& rsText, bool bIsDecl)
- {
- IXMLNode::TXMLNodePtr pResult;
- HXML h = xmlCreateNode(rsName.c_str(), rsText.c_str(), bIsDecl);
- if (h)
- {
- pResult = IXMLNode::TXMLNodePtr(new CXMLNodeMI(h, true));
- }
+ IXMLNode::TXMLNodePtr pResult;
+ HXML h = xmlCreateNode(rsName.c_str(), rsText.c_str(), bIsDecl);
+ if (h)
+ pResult = IXMLNode::TXMLNodePtr(new CXMLNodeMI(h, true));
- return pResult;
- }
+ return pResult;
}
bool CXMLEngineMI::SaveFile(const tstring& rsFileName, const IXMLNode::TXMLNodePtr& pNode)const
{
CXMLNodeMI* pXML = dynamic_cast<CXMLNodeMI*>(pNode.get());
- if (pXML)
- {
+ if (pXML) {
tofstream file(rsFileName.c_str());
- if (file.good())
- {
+ if (file.good()) {
IXMLNode::TXMLNodePtr pRoot(create_node(_T("xml"), tstring(), true));
- if (pRoot)
- {
+ if (pRoot) {
pRoot->AddAttribute(_T("version"), _T("1.0"));
pRoot->AddAttribute(_T("encoding"), _T("UTF-8"));
file << *pRoot;
}
- if (file.good())
- {
+ if (file.good()) {
file << *pNode;
}
}
@@ -218,4 +160,4 @@ bool CXMLEngineMI::SaveFile(const tstring& rsFileName, const IXMLNode::TXMLNodeP IXMLNode::TXMLNodePtr CXMLEngineMI::CreateNode(const tstring& rsName, const tstring& rsText)const
{
return create_node(rsName, rsText, false);
-}
\ No newline at end of file +}
diff --git a/plugins/Quotes/src/stdafx.h b/plugins/Quotes/src/stdafx.h index 7787056d13..bd1842fbd6 100644 --- a/plugins/Quotes/src/stdafx.h +++ b/plugins/Quotes/src/stdafx.h @@ -81,7 +81,6 @@ inline int quotes_stricmp(LPCTSTR p1, LPCTSTR p2) #include "resource.h"
#include "version.h"
-#include "WorkingThread.h"
#include "IconLib.h"
#include "QuoteInfoDlg.h"
#include "ModuleInfo.h"
|