diff options
30 files changed, 408 insertions, 702 deletions
diff --git a/protocols/CurrencyRates/Forex.vcxproj b/protocols/CurrencyRates/Forex.vcxproj index 4fd5b7ee2b..38e83636c8 100644 --- a/protocols/CurrencyRates/Forex.vcxproj +++ b/protocols/CurrencyRates/Forex.vcxproj @@ -38,10 +38,8 @@ <ClCompile Include="src\ExtraImages.cpp" /> <ClCompile Include="src\Forex.cpp" /> <ClCompile Include="src\HTTPSession.cpp" /> - <ClCompile Include="src\IconLib.cpp" /> <ClCompile Include="src\ImportExport.cpp" /> <ClCompile Include="src\Locale.cpp" /> - <ClCompile Include="src\Log.cpp" /> <ClCompile Include="src\ModuleInfo.cpp" /> <ClCompile Include="src\SettingsDlg.cpp" /> <ClCompile Include="src\stdafx.cxx"> @@ -50,7 +48,6 @@ <ClCompile Include="src\WinCtrlHelper.cpp" /> <ClInclude Include="src\Chart.h" /> <ClInclude Include="src\CommonOptionDlg.h" /> - <ClInclude Include="src\CreateFilePath.h" /> <ClInclude Include="src\CurrencyConverter.h" /> <ClInclude Include="src\CurrencyRateChart.h" /> <ClInclude Include="src\CurrencyRateInfoDlg.h" /> @@ -64,7 +61,6 @@ <ClInclude Include="src\ImportExport.h" /> <ClInclude Include="src\IsWithinAccuracy.h" /> <ClInclude Include="src\Locale.h" /> - <ClInclude Include="src\Log.h" /> <ClInclude Include="src\ModuleInfo.h" /> <ClInclude Include="src\resource.h" /> <ClInclude Include="src\SettingsDlg.h" /> diff --git a/protocols/CurrencyRates/Forex.vcxproj.filters b/protocols/CurrencyRates/Forex.vcxproj.filters index 9e5d0d3b9e..0e9cb672fb 100644 --- a/protocols/CurrencyRates/Forex.vcxproj.filters +++ b/protocols/CurrencyRates/Forex.vcxproj.filters @@ -38,18 +38,12 @@ <ClCompile Include="src\HTTPSession.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="src\IconLib.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="src\ImportExport.cpp"> <Filter>Source Files</Filter> </ClCompile> <ClCompile Include="src\Locale.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="src\Log.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="src\ModuleInfo.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -70,9 +64,6 @@ <ClInclude Include="src\CommonOptionDlg.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="src\CreateFilePath.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="src\CurrencyConverter.h"> <Filter>Header Files</Filter> </ClInclude> @@ -112,9 +103,6 @@ <ClInclude Include="src\Locale.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="src\Log.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="src\ModuleInfo.h"> <Filter>Header Files</Filter> </ClInclude> diff --git a/protocols/CurrencyRates/src/CommonOptionDlg.cpp b/protocols/CurrencyRates/src/CommonOptionDlg.cpp index 56b857d331..1e58db1b17 100644 --- a/protocols/CurrencyRates/src/CommonOptionDlg.cpp +++ b/protocols/CurrencyRates/src/CommonOptionDlg.cpp @@ -50,7 +50,7 @@ void CommonOptionDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp, CCommonDlgPr 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])); + ::SendMessage(hwndCombo, CB_ADDSTRING, 0, LPARAM(pszRefreshRateTypes[i])); int nRefreshRateType = g_plugin.getWord(DB_KEY_RefreshRateType, RRT_MINUTES); if (nRefreshRateType < RRT_SECONDS || nRefreshRateType > RRT_HOURS) @@ -166,8 +166,8 @@ void CommonOptionDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp, CCommonDlgPr HWND hEdit = ::GetDlgItem(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT); assert(IsWindow(hEdit)); - std::wstring s = get_window_text(hEdit); - if (true == s.empty()) { + CMStringW s = get_window_text(hEdit); + if (s.IsEmpty()) { prepare_edit_ctrl_for_error(hEdit); CurrencyRates_MessageBox(hWnd, TranslateT("Enter text to display in contact list."), MB_OK | MB_ICONERROR); bOk = FALSE; @@ -190,17 +190,10 @@ void CommonOptionDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp, CCommonDlgPr g_plugin.setWord(DB_KEY_RefreshRateType, nType); g_plugin.setWord(DB_KEY_RefreshRateValue, nRefreshRate); - std::wstring s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT)); - g_plugin.setWString(DB_KEY_DisplayNameFormat, s.c_str()); - - s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_STATUS_MESSAGE_FORMAT)); - g_plugin.setWString(DB_KEY_StatusMsgFormat, s.c_str()); - - s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_TENDENCY_FORMAT)); - g_plugin.setWString(DB_KEY_TendencyFormat, s.c_str()); - - s = get_window_text(::GetDlgItem(hWnd, IDC_EDIT_PERSONAL_KEY)); - g_plugin.setWString(DB_KEY_ApiKey, s.c_str()); + g_plugin.setWString(DB_KEY_DisplayNameFormat, get_window_text(::GetDlgItem(hWnd, IDC_EDIT_CONTACT_LIST_FORMAT))); + g_plugin.setWString(DB_KEY_StatusMsgFormat, get_window_text(::GetDlgItem(hWnd, IDC_EDIT_STATUS_MESSAGE_FORMAT))); + g_plugin.setWString(DB_KEY_TendencyFormat, get_window_text(::GetDlgItem(hWnd, IDC_EDIT_TENDENCY_FORMAT))); + g_plugin.setWString(DB_KEY_ApiKey, get_window_text(::GetDlgItem(hWnd, IDC_EDIT_PERSONAL_KEY))); CAdvProviderSettings* pAdvSet = get_adv_settings(rData.m_pCurrencyRatesProvider, false); if (pAdvSet) diff --git a/protocols/CurrencyRates/src/CreateFilePath.cpp b/protocols/CurrencyRates/src/CreateFilePath.cpp index 04621eca64..3b2faadd1a 100644 --- a/protocols/CurrencyRates/src/CreateFilePath.cpp +++ b/protocols/CurrencyRates/src/CreateFilePath.cpp @@ -1,6 +1,6 @@ #include "StdAfx.h" -std::wstring CreateFilePath(const std::wstring &rsName) +CMStringW CreateFilePath(const CMStringW &rsName) { wchar_t szPath[_MAX_PATH]; ::GetModuleFileName(g_plugin.getInst(), szPath, _MAX_PATH); @@ -9,9 +9,7 @@ std::wstring CreateFilePath(const std::wstring &rsName) if (p) *p = 0; - std::wstring s(rsName); + CMStringW s(rsName); FixInvalidChars(s); - std::wostringstream o; - o << szPath << L"\\CurrencyRates\\" << s; - return o.str(); -}
\ No newline at end of file + return CMStringW(szPath) + L"\\CurrencyRates\\" + s; +} diff --git a/protocols/CurrencyRates/src/CreateFilePath.h b/protocols/CurrencyRates/src/CreateFilePath.h deleted file mode 100644 index 6f11a24601..0000000000 --- a/protocols/CurrencyRates/src/CreateFilePath.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _aaf3bee6_cee7_4023_8848_5911ad7a9660_CreateFilePath_h__ -#define _aaf3bee6_cee7_4023_8848_5911ad7a9660_CreateFilePath_h__ - -std::wstring CreateFilePath(const std::wstring& rsName); - -#endif //_aaf3bee6_cee7_4023_8848_5911ad7a9660_CreateFilePath_h__ diff --git a/protocols/CurrencyRates/src/CurrencyConverter.cpp b/protocols/CurrencyRates/src/CurrencyConverter.cpp index e624f8233c..a129edd784 100644 --- a/protocols/CurrencyRates/src/CurrencyConverter.cpp +++ b/protocols/CurrencyRates/src/CurrencyConverter.cpp @@ -31,10 +31,10 @@ CCurrencyRateSection get_currencyrates(const CCurrencyRatesProviderCurrencyConve return CCurrencyRateSection(); } -inline std::wstring make_currencyrate_name(const CCurrencyRate &rCurrencyRate) +inline CMStringW make_currencyrate_name(const CCurrencyRate &rCurrencyRate) { - const std::wstring &rsDesc = rCurrencyRate.GetName(); - return((false == rsDesc.empty()) ? rsDesc : rCurrencyRate.GetSymbol()); + const CMStringW &rsDesc = rCurrencyRate.GetName(); + return((false == rsDesc.IsEmpty()) ? rsDesc : rCurrencyRate.GetSymbol()); } inline void update_convert_button(HWND hDlg) @@ -58,22 +58,6 @@ inline void update_swap_button(HWND hDlg) EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SWAP), bEnableButton); } -inline std::wstring double2str(double dValue) -{ - wchar_t str[40]; - swprintf_s(str, L"%.2lf", dValue); - return str; -} - -inline bool str2double(const std::wstring& s, double& d) -{ - std::wistringstream 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) { @@ -89,18 +73,17 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM HWND hcbxFrom = ::GetDlgItem(hDlg, IDC_COMBO_CONVERT_FROM); HWND hcbxTo = ::GetDlgItem(hDlg, IDC_COMBO_CONVERT_INTO); - std::wstring sFromCurrencyRateID = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_STR_CC_CURRENCYRATE_FROM_ID); - std::wstring sToCurrencyRateID = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_STR_CC_CURRENCYRATE_TO_ID); + CMStringW sFromCurrencyRateID = g_plugin.getMStringW(DB_STR_CC_CURRENCYRATE_FROM_ID); + CMStringW sToCurrencyRateID = g_plugin.getMStringW(DB_STR_CC_CURRENCYRATE_TO_ID); const auto pProvider = get_currency_converter_provider(); const auto& rSection = get_currencyrates(pProvider); auto cCurrencyRates = rSection.GetCurrencyRateCount(); for (auto i = 0u; i < cCurrencyRates; ++i) { const auto& rCurrencyRate = rSection.GetCurrencyRate(i); - std::wstring sName = make_currencyrate_name(rCurrencyRate); - 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)); + CMStringW sName = make_currencyrate_name(rCurrencyRate); + LRESULT nFrom = ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, LPARAM(sName.c_str())); + LRESULT nTo = ::SendMessage(hcbxTo, CB_ADDSTRING, 0, LPARAM(sName.c_str())); if (0 == mir_wstrcmpi(rCurrencyRate.GetID().c_str(), sFromCurrencyRateID.c_str())) { ::SendMessage(hcbxFrom, CB_SETCURSEL, nFrom, 0); @@ -111,15 +94,15 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM } } + wchar_t str[40]; double dAmount = 1.0; CurrencyRates_DBReadDouble(NULL, MODULENAME, DB_STR_CC_AMOUNT, dAmount); - ::SetDlgItemText(hDlg, IDC_EDIT_VALUE, double2str(dAmount).c_str()); + swprintf_s(str, L"%.2lf", dAmount); + ::SetDlgItemText(hDlg, IDC_EDIT_VALUE, str); - const ICurrencyRatesProvider::CProviderInfo& pi = pProvider->GetInfo(); - std::wostringstream o; - o << TranslateT("Info provided by") << L" <a href=\"" << pi.m_sURL << L"\">" << pi.m_sName << L"</a>"; - - ::SetDlgItemText(hDlg, IDC_SYSLINK_PROVIDER, o.str().c_str()); + auto &pi = pProvider->GetInfo(); + CMStringW provInfo(FORMAT, L"%s <a href=\"%s\">%s</a>", TranslateT("Info provided by"), pi.m_sURL.c_str(), pi.m_sName.c_str()); + ::SetDlgItemText(hDlg, IDC_SYSLINK_PROVIDER, provInfo); ::SendDlgItemMessage(hDlg, IDC_BUTTON_SWAP, BM_SETIMAGE, IMAGE_ICON, LPARAM(g_plugin.getIcon(IDI_ICON_SWAP))); @@ -179,10 +162,8 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM case IDC_BUTTON_CONVERT: { HWND hwndAmount = GetDlgItem(hDlg, IDC_EDIT_VALUE); - std::wstring sText = get_window_text(hwndAmount); - double dAmount = 1.0; - if ((true == str2double(sText, dAmount)) && (dAmount > 0.0)) { + if (swscanf(get_window_text(hwndAmount), L"%lf", &dAmount) == 1 && dAmount > 0.0) { CurrencyRates_DBWriteDouble(NULL, MODULENAME, DB_STR_CC_AMOUNT, dAmount); size_t nFrom = static_cast<size_t>(::SendDlgItemMessage(hDlg, IDC_COMBO_CONVERT_FROM, CB_GETCURSEL, 0, 0)); diff --git a/protocols/CurrencyRates/src/CurrencyRateChart.cpp b/protocols/CurrencyRates/src/CurrencyRateChart.cpp index a3208811a4..315a14144d 100644 --- a/protocols/CurrencyRates/src/CurrencyRateChart.cpp +++ b/protocols/CurrencyRates/src/CurrencyRateChart.cpp @@ -66,11 +66,11 @@ INT_PTR CurrencyRatesMenu_Chart(WPARAM wp, LPARAM /*lp*/) if(auto hWnd = ::FindWindow(nullptr,_T("Miranda CurrencyRates Chart"))) { COPYDATASTRUCT copydata_struct; - copydata_struct.cbData = static_cast<DWORD>(sLogFileName.size()*sizeof(TCHAR)); + copydata_struct.cbData = static_cast<DWORD>(sLogFileName.GetLength() * sizeof(TCHAR)); copydata_struct.lpData = const_cast<void*>(static_cast<const void*>(sLogFileName.c_str())); copydata_struct.dwData = 0x1945; - SendMessage(hWnd,WM_COPYDATA,0,reinterpret_cast<LPARAM>(©data_struct)); + SendMessage(hWnd,WM_COPYDATA,0,LPARAM(©data_struct)); } else { diff --git a/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp b/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp index cc4b1b2de8..c24045470c 100644 --- a/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp +++ b/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp @@ -36,8 +36,7 @@ INT_PTR CALLBACK CurrencyRateInfoDlgProcImpl(MCONTACT hContact, HWND hdlg, UINT TranslateDialogDefault(hdlg); { - std::wstring sDescription = GetContactName(hContact); - ::SetDlgItemTextW(hdlg, IDC_STATIC_CURRENCYRATE_NAME, sDescription.c_str()); + ::SetDlgItemTextW(hdlg, IDC_STATIC_CURRENCYRATE_NAME, GetContactName(hContact)); double dRate = 0.0; if (true == CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_PREV_VALUE, dRate)) { @@ -62,10 +61,8 @@ INT_PTR CALLBACK CurrencyRateInfoDlgProcImpl(MCONTACT hContact, HWND hdlg, UINT } const ICurrencyRatesProvider::CProviderInfo& pi = GetContactProviderPtr(hContact)->GetInfo(); - std::wostringstream o; - o << TranslateT("Info provided by") << L" <a href=\"" << pi.m_sURL << L"\">" << pi.m_sName << L"</a>"; - - ::SetDlgItemTextW(hdlg, IDC_SYSLINK_PROVIDER, o.str().c_str()); + CMStringW provInfo(FORMAT, L"%s <a href=\"%s\">%s</a>", TranslateT("Info provided by"), pi.m_sURL.c_str(), pi.m_sName.c_str()); + ::SetDlgItemTextW(hdlg, IDC_SYSLINK_PROVIDER, provInfo); } return TRUE; @@ -119,10 +116,10 @@ INT_PTR CurrencyRatesMenu_EditSettings(WPARAM wp, LPARAM) namespace { - bool get_log_file(MCONTACT hContact, std::wstring& rsLogfile) + bool get_log_file(MCONTACT hContact, CMStringW &rsLogfile) { rsLogfile = GetContactLogFileName(hContact); - return ((rsLogfile.empty()) ? false : true); + return !rsLogfile.IsEmpty(); } } @@ -132,8 +129,8 @@ INT_PTR CurrencyRatesMenu_OpenLogFile(WPARAM wp, LPARAM) if (NULL == hContact) return 0; - std::wstring sLogFileName; - if ((true == get_log_file(hContact, sLogFileName)) && (false == sLogFileName.empty())) + CMStringW sLogFileName; + if ((true == get_log_file(hContact, sLogFileName)) && (false == sLogFileName.IsEmpty())) ::ShellExecute(nullptr, L"open", sLogFileName.c_str(), nullptr, nullptr, SW_SHOWNORMAL); return 0; @@ -239,10 +236,8 @@ int CurrencyRates_PrebuildContactMenu(WPARAM wp, LPARAM) Menu_EnableItem(g_hMenuRefresh, true); - std::wstring sLogFileName; - bool bThereIsLogFile = (true == get_log_file(hContact, sLogFileName)) - && (false == sLogFileName.empty()) && (0 == _waccess(sLogFileName.c_str(), 04)); - if (true == bThereIsLogFile) { + CMStringW sLogFileName; + if (get_log_file(hContact, sLogFileName) && !sLogFileName.IsEmpty() && !_waccess(sLogFileName, 04)) { #ifdef CHART_IMPLEMENT Menu_EnableItem(g_hMenuChart, true); #endif diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp index 0d973d39eb..1235e254f1 100644 --- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp +++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp @@ -8,23 +8,18 @@ struct CXMLFileInfo CXMLFileInfo() : m_qs(L"Unknown") {} ICurrencyRatesProvider::CProviderInfo m_pi; CCurrencyRateSection m_qs; - std::wstring m_sURL; + CMStringW m_sURL; }; -inline std::wstring get_ini_file_name(LPCTSTR pszFileName) -{ - return CreateFilePath(pszFileName); -} - bool parse_currencyrate(const TiXmlNode *pTop, CCurrencyRate &q) { - std::wstring sSymbol, sDescription, sID; + CMStringW sSymbol, sDescription, sID; for (auto *pNode : TiXmlEnum(pTop)) { const char *sName = pNode->Value(); if (!mir_strcmpi(sName, "symbol")) { sSymbol = GetNodeText(pNode); - if (sSymbol.empty()) + if (sSymbol.IsEmpty()) return false; } else if (!mir_strcmpi(sName, "description")) { @@ -32,7 +27,7 @@ bool parse_currencyrate(const TiXmlNode *pTop, CCurrencyRate &q) } else if (!mir_strcmpi(sName, "id")) { sID = GetNodeText(pNode); - if (sID.empty()) + if (sID.IsEmpty()) return false; } } @@ -45,7 +40,7 @@ bool parse_section(const TiXmlNode *pTop, CCurrencyRateSection &qs) { CCurrencyRateSection::TSections aSections; CCurrencyRateSection::TCurrencyRates aCurrencyRates; - std::wstring sSectionName; + CMStringW sSectionName; for (auto *pNode : TiXmlEnum(pTop)) { const char *sName = pNode->Value(); @@ -61,7 +56,7 @@ bool parse_section(const TiXmlNode *pTop, CCurrencyRateSection &qs) } else if (!mir_strcmpi(sName, "name")) { sSectionName = GetNodeText(pNode); - if (sSectionName.empty()) + if (sSectionName.IsEmpty()) return false; } } @@ -84,7 +79,7 @@ const TiXmlNode* find_provider(const TiXmlNode *pRoot) return nullptr; } -CXMLFileInfo parse_ini_file(const std::wstring &rsXMLFile, bool &rbSucceded) +CXMLFileInfo parse_ini_file(const CMStringW &rsXMLFile, bool &rbSucceded) { CXMLFileInfo res; CCurrencyRateSection::TSections aSections; @@ -118,7 +113,7 @@ CXMLFileInfo parse_ini_file(const std::wstring &rsXMLFile, bool &rbSucceded) CXMLFileInfo init_xml_info(LPCTSTR pszFileName, bool& rbSucceded) { rbSucceded = false; - std::wstring sIniFile = get_ini_file_name(pszFileName); + CMStringW sIniFile = CreateFilePath(pszFileName); return parse_ini_file(sIniFile, rbSucceded); } @@ -156,7 +151,7 @@ const CCurrencyRateSection& CCurrencyRatesProviderBase::GetCurrencyRates() const return m_pXMLInfo->m_qs; } -const std::wstring& CCurrencyRatesProviderBase::GetURL() const +const CMStringW& CCurrencyRatesProviderBase::GetURL() const { return m_pXMLInfo->m_sURL; } @@ -224,15 +219,15 @@ public: public: CTendency() : m_nComparison(NonValid) {} - bool Parse(CCurrencyRatesProviderBase *pProvider, const std::wstring& rsFrmt, MCONTACT hContact) + bool Parse(CCurrencyRatesProviderBase *pProvider, const CMStringW &rsFrmt, MCONTACT hContact) { m_abValueFlags[0] = false; m_abValueFlags[1] = false; m_nComparison = NonValid; bool bValid = true; int nCurValue = 0; - for (std::wstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end() && bValid && nCurValue < NumValues;) { - wchar_t chr = *i; + for (int i = 0; i < rsFrmt.GetLength() && bValid && nCurValue < NumValues;) { + wchar_t chr = rsFrmt[i]; switch (chr) { default: if (false == std::isspace(chr)) @@ -243,8 +238,8 @@ public: case '%': ++i; - if (i != rsFrmt.end()) { - wchar_t t = *i; + if (i != rsFrmt.GetLength()) { + wchar_t t = rsFrmt[i]; ++i; double d; @@ -333,12 +328,12 @@ private: EComparison m_nComparison; }; -std::wstring format_rate(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, const std::wstring &rsFrmt) +CMStringW format_rate(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, const CMStringW &rsFrmt) { - std::wstring sResult; + CMStringW sResult; - for (std::wstring::const_iterator i = rsFrmt.begin(); i != rsFrmt.end();) { - wchar_t chr = *i; + for (int i = 0; i < rsFrmt.GetLength(); ) { + wchar_t chr = rsFrmt[i]; switch (chr) { default: sResult += chr; @@ -347,8 +342,8 @@ std::wstring format_rate(const ICurrencyRatesProvider *pProvider, MCONTACT hCont case '\\': ++i; - if (i != rsFrmt.end()) { - wchar_t t = *i; + if (i != rsFrmt.GetLength()) { + wchar_t t = rsFrmt[i]; switch (t) { case '%': sResult += L"%"; break; case 't': sResult += L"\t"; break; @@ -363,18 +358,18 @@ std::wstring format_rate(const ICurrencyRatesProvider *pProvider, MCONTACT hCont case '%': ++i; - if (i != rsFrmt.end()) { - chr = *i; + if (i != rsFrmt.GetLength()) { + chr = rsFrmt[i]; byte nWidth = 0; if (::isdigit(chr)) { nWidth = chr - 0x30; ++i; - if (i == rsFrmt.end()) { + if (i == rsFrmt.GetLength()) { sResult += chr; break; } - else chr = *i; + else chr = rsFrmt[i]; } sResult += pProvider->FormatSymbol(hContact, chr, nWidth); @@ -388,27 +383,21 @@ std::wstring format_rate(const ICurrencyRatesProvider *pProvider, MCONTACT hCont return sResult; } -void log_to_file(const ICurrencyRatesProvider *pProvider, - MCONTACT hContact, - const std::wstring& rsLogFileName, - const std::wstring& rsFormat) +void log_to_file(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, const CMStringW &rsLogFileName, const CMStringW &rsFormat) { - CreatePathToFileW(rsLogFileName.c_str()); + CreatePathToFileW(rsLogFileName); - std::wofstream file(rsLogFileName.c_str(), std::ios::app | std::ios::out); + std::wofstream file(rsLogFileName, std::ios::app | std::ios::out); file.imbue(GetSystemLocale()); if (file.good()) { - std::wstring s = format_rate(pProvider, hContact, rsFormat); + CMStringW s = format_rate(pProvider, hContact, rsFormat); file << s; } } -void log_to_history(const ICurrencyRatesProvider *pProvider, - MCONTACT hContact, - time_t nTime, - const std::wstring& rsFormat) +void log_to_history(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, time_t nTime, const CMStringW &rsFormat) { - std::wstring s = format_rate(pProvider, hContact, rsFormat); + CMStringW s = format_rate(pProvider, hContact, rsFormat); T2Utf psz(s.c_str()); DBEVENTINFO dbei = {}; @@ -437,11 +426,7 @@ bool do_set_contact_extra_icon(MCONTACT hContact, const CTendency& tendency) return false; } -bool show_popup(const ICurrencyRatesProvider *pProvider, - MCONTACT hContact, - const CTendency& tendency, - const std::wstring& rsFormat, - const CPopupSettings& ps) +bool show_popup(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, const CTendency &tendency, const CMStringW &rsFormat, const CPopupSettings &ps) { POPUPDATAW ppd; memset(&ppd, 0, sizeof(ppd)); @@ -460,8 +445,7 @@ bool show_popup(const ICurrencyRatesProvider *pProvider, mir_wstrncpy(ppd.lpwzContactName, pProvider->FormatSymbol(hContact, 's').c_str(), MAX_CONTACTNAME); { ptrW ss(variables_parsedup((wchar_t*)rsFormat.c_str(), nullptr, hContact)); - std::wstring sText = format_rate(pProvider, hContact, std::wstring(ss)); - mir_wstrncpy(ppd.lpwzText, sText.c_str(), MAX_SECONDLINE); + mir_wstrncpy(ppd.lpwzText, format_rate(pProvider, hContact, ss.get()), MAX_SECONDLINE); } if (CPopupSettings::colourDefault == ps.GetColourMode()) { @@ -494,11 +478,11 @@ bool show_popup(const ICurrencyRatesProvider *pProvider, return (0 == PUAddPopupW(&ppd, lp)); } -void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, const std::wstring& rsSymbol/* = ""*/) +void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, const CMStringW &rsSymbol/* = ""*/) { time_t nTime = ::time(0); - if (false == rsSymbol.empty()) + if (false == rsSymbol.IsEmpty()) g_plugin.setWString(hContact, DB_STR_CURRENCYRATE_SYMBOL, rsSymbol.c_str()); double dPrev = 0.0; @@ -509,30 +493,28 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat CurrencyRates_DBWriteDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_CURR_VALUE, dRate); g_plugin.setDword(hContact, DB_STR_CURRENCYRATE_FETCH_TIME, nTime); - std::wstring sSymbol = rsSymbol; + CMStringW sSymbol = rsSymbol; - std::wostringstream oNick; - oNick.imbue(GetSystemLocale()); - if (false == m_sContactListFormat.empty()) { - std::wstring s = format_rate(this, hContact, m_sContactListFormat); - oNick << s; + CMStringW wszNick; + if (false == m_sContactListFormat.IsEmpty()) { + wszNick = format_rate(this, hContact, m_sContactListFormat); } else { - if (true == sSymbol.empty()) - sSymbol = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_SYMBOL); + if (sSymbol.IsEmpty()) + sSymbol = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_SYMBOL); - oNick << std::setfill(L' ') << std::setw(10) << std::left << sSymbol << std::setw(6) << std::right << dRate; + wszNick.Format(L"%-10s %.6lf", sSymbol.c_str(), dRate); } - CTendency tendency; + CTendency tendency; if (true == tendency.Parse(this, m_sTendencyFormat, hContact)) do_set_contact_extra_icon(hContact, tendency); - db_set_ws(hContact, LIST_MODULE_NAME, CONTACT_LIST_NAME, oNick.str().c_str()); + db_set_ws(hContact, LIST_MODULE_NAME, CONTACT_LIST_NAME, wszNick); - std::wstring sStatusMsg = format_rate(this, hContact, m_sStatusMsgFormat); - if (false == sStatusMsg.empty()) - db_set_ws(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME, sStatusMsg.c_str()); + CMStringW sStatusMsg = format_rate(this, hContact, m_sStatusMsgFormat); + if (!sStatusMsg.IsEmpty()) + db_set_ws(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME, sStatusMsg); else db_unset(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME); @@ -552,19 +534,19 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat bAdd = ((false == bValidPrev) || (false == IsWithinAccuracy(dRate, dPrev))); } if (true == bAdd) { - std::wstring sLogFileName = (bUseContactSpecific) - ? CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_LOG_FILE, global_settings.GetLogFileName().c_str()) + CMStringW sLogFileName = (bUseContactSpecific) + ? g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_LOG_FILE, global_settings.GetLogFileName().c_str()) : global_settings.GetLogFileName(); - if (true == sSymbol.empty()) { - sSymbol = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_SYMBOL); + if (true == sSymbol.IsEmpty()) { + sSymbol = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_SYMBOL); } sLogFileName = GenerateLogFileName(sLogFileName, sSymbol); - std::wstring sFormat = global_settings.GetLogFormat(); + CMStringW sFormat = global_settings.GetLogFormat(); if (bUseContactSpecific) - sFormat = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_FORMAT_LOG_FILE, DB_DEF_LogFormat); + sFormat = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_FORMAT_LOG_FILE, DB_DEF_LogFormat); log_to_file(this, hContact, sLogFileName, sFormat); } @@ -579,8 +561,8 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat bAdd = ((false == bValidPrev) || (false == IsWithinAccuracy(dRate, dPrev))); } if (true == bAdd) { - std::wstring sFormat = (bUseContactSpecific) - ? CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_FORMAT_HISTORY, global_settings.GetHistoryFormat().c_str()) + CMStringW sFormat = (bUseContactSpecific) + ? g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_FORMAT_HISTORY, global_settings.GetHistoryFormat().c_str()) : global_settings.GetHistoryFormat(); log_to_history(this, hContact, nTime, sFormat); @@ -591,10 +573,9 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat bool bOnlyIfChanged = (bUseContactSpecific) ? (1 == g_plugin.getByte(hContact, DB_STR_CURRENCYRATE_POPUP_CONDITION, 1) > 0) : global_settings.GetShowPopupIfValueChangedFlag(); - if ((false == bOnlyIfChanged) - || ((true == bOnlyIfChanged) && (true == bValidPrev) && (false == IsWithinAccuracy(dRate, dPrev)))) { - std::wstring sFormat = (bUseContactSpecific) - ? CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_FORMAT_POPUP, global_settings.GetPopupFormat().c_str()) + if (!bOnlyIfChanged || (bOnlyIfChanged && bValidPrev && !IsWithinAccuracy(dRate, dPrev))) { + CMStringW sFormat = (bUseContactSpecific) + ? g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_FORMAT_POPUP, global_settings.GetPopupFormat().c_str()) : global_settings.GetPopupFormat(); CPopupSettings ps = *(global_settings.GetPopupSettingsPtr()); @@ -606,15 +587,14 @@ void CCurrencyRatesProviderBase::WriteContactRate(MCONTACT hContact, double dRat SetContactStatus(hContact, ID_STATUS_ONLINE); } -MCONTACT CCurrencyRatesProviderBase::CreateNewContact(const std::wstring& rsName) +MCONTACT CCurrencyRatesProviderBase::CreateNewContact(const CMStringW &rsName) { MCONTACT hContact = db_add_contact(); Proto_AddToContact(hContact, MODULENAME); - std::wstring sProvName = GetInfo().m_sName; - g_plugin.setWString(hContact, DB_STR_CURRENCYRATE_PROVIDER, sProvName.c_str()); - g_plugin.setWString(hContact, DB_STR_CURRENCYRATE_SYMBOL, rsName.c_str()); - db_set_ws(hContact, LIST_MODULE_NAME, CONTACT_LIST_NAME, rsName.c_str()); + g_plugin.setWString(hContact, DB_STR_CURRENCYRATE_PROVIDER, GetInfo().m_sName); + g_plugin.setWString(hContact, DB_STR_CURRENCYRATE_SYMBOL, rsName); + db_set_ws(hContact, LIST_MODULE_NAME, CONTACT_LIST_NAME, rsName); mir_cslock lck(m_cs); m_aContacts.push_back(hContact); @@ -669,9 +649,9 @@ private: void CCurrencyRatesProviderBase::Run() { DWORD nTimeout = get_refresh_timeout_miliseconds(); - m_sContactListFormat = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_DisplayNameFormat, DB_DEF_DisplayNameFormat); - m_sStatusMsgFormat = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_StatusMsgFormat, DB_DEF_StatusMsgFormat); - m_sTendencyFormat = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_TendencyFormat, DB_DEF_TendencyFormat); + m_sContactListFormat = g_plugin.getMStringW(DB_KEY_DisplayNameFormat, DB_DEF_DisplayNameFormat); + m_sStatusMsgFormat = g_plugin.getMStringW(DB_KEY_StatusMsgFormat, DB_DEF_StatusMsgFormat); + m_sTendencyFormat = g_plugin.getMStringW(DB_KEY_TendencyFormat, DB_DEF_TendencyFormat); enum { @@ -721,9 +701,9 @@ void CCurrencyRatesProviderBase::Run() case WAIT_OBJECT_0 + SETTINGS_CHANGED: nTimeout = get_refresh_timeout_miliseconds(); - m_sContactListFormat = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_DisplayNameFormat, DB_DEF_DisplayNameFormat); - m_sStatusMsgFormat = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_StatusMsgFormat, DB_DEF_StatusMsgFormat); - m_sTendencyFormat = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_TendencyFormat, DB_DEF_TendencyFormat); + m_sContactListFormat = g_plugin.getMStringW(DB_KEY_DisplayNameFormat, DB_DEF_DisplayNameFormat); + m_sStatusMsgFormat = g_plugin.getMStringW(DB_KEY_StatusMsgFormat, DB_DEF_StatusMsgFormat); + m_sTendencyFormat = g_plugin.getMStringW(DB_KEY_TendencyFormat, DB_DEF_TendencyFormat); { mir_cslock lck(m_cs); anContacts = m_aContacts; @@ -808,18 +788,19 @@ void CCurrencyRatesProviderBase::RefreshContact(MCONTACT hContact) void CCurrencyRatesProviderBase::FillFormat(TFormatSpecificators &array) const { - array.push_back(CFormatSpecificator(L"%S", TranslateT("Source of Information"))); - array.push_back(CFormatSpecificator(L"%r", TranslateT("Rate Value"))); - array.push_back(CFormatSpecificator(L"%p", TranslateT("Previous Rate Value"))); - array.push_back(CFormatSpecificator(L"%X", TranslateT("Fetch Time"))); - array.push_back(CFormatSpecificator(L"%x", TranslateT("Fetch Date"))); - array.push_back(CFormatSpecificator(L"%t", TranslateT("Fetch Time and Date"))); - array.push_back(CFormatSpecificator(L"\\%", TranslateT("Percentage Character (%)"))); - array.push_back(CFormatSpecificator(L"\\t", TranslateT("Tabulation"))); - array.push_back(CFormatSpecificator(L"\\\\", TranslateT("Left slash (\\)"))); + array.push_back(CFormatSpecificator(L"%S", LPGENW("Source of information"))); + array.push_back(CFormatSpecificator(L"%r", LPGENW("Rate value"))); + array.push_back(CFormatSpecificator(L"%d", LPGENW("Rate delta"))); + array.push_back(CFormatSpecificator(L"%p", LPGENW("Previous rate value"))); + array.push_back(CFormatSpecificator(L"%X", LPGENW("Fetch time"))); + array.push_back(CFormatSpecificator(L"%x", LPGENW("Fetch date"))); + array.push_back(CFormatSpecificator(L"%t", LPGENW("Fetch time and date"))); + array.push_back(CFormatSpecificator(L"\\%", LPGENW("Percent character (%)"))); + array.push_back(CFormatSpecificator(L"\\t", LPGENW("Tabulation"))); + array.push_back(CFormatSpecificator(L"\\\\", LPGENW("Left slash (\\)"))); } -bool CCurrencyRatesProviderBase::ParseSymbol(MCONTACT hContact, wchar_t c, double &d) +bool CCurrencyRatesProviderBase::ParseSymbol(MCONTACT hContact, wchar_t c, double &d) const { switch (c) { case 'r': @@ -829,6 +810,14 @@ bool CCurrencyRatesProviderBase::ParseSymbol(MCONTACT hContact, wchar_t c, doubl case 'p': case 'P': return CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_PREV_VALUE, d); + + case 'd': + case 'D': + double v1, v2; + if (CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_CURR_VALUE, v1) && CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_PREV_VALUE, v2)) { + d = v1 - v2; + return true; + } } return false; @@ -846,32 +835,29 @@ static bool get_fetch_time(MCONTACT hContact, time_t &rTime) return true; } -static std::wstring format_fetch_time(MCONTACT hContact, const std::wstring &rsFormat) +static CMStringW format_fetch_time(MCONTACT hContact, const wchar_t *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)); - std::wostringstream k; - k.imbue(std::locale(GetSystemLocale(), new ttime_facet(rsFormat.c_str()))); - k << time; - return k.str(); + wchar_t buf[200]; + wcsftime(buf, _countof(buf), rsFormat, localtime(&nTime)); + return buf; } - return std::wstring(); + return CMStringW(); } -static std::wstring format_double(double dValue, int nWidth) +static CMStringW format_double(double dValue, int nWidth) { - wchar_t str[100], format[] = L"%.6lf"; + wchar_t format[] = L"%.6lf"; if (nWidth > 0 && nWidth <= 9) format[2] = '0' + nWidth; - swprintf_s(str, format, dValue); - return str; + return CMStringW(FORMAT, format, dValue); } -std::wstring CCurrencyRatesProviderBase::FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth) const +CMStringW CCurrencyRatesProviderBase::FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth) const { - std::wstring ret; + CMStringW ret; double d = 0.0; switch (c) { @@ -881,10 +867,10 @@ std::wstring CCurrencyRatesProviderBase::FormatSymbol(MCONTACT hContact, wchar_t ret = c; break; case 'S': - ret = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_PROVIDER); + ret = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_PROVIDER); break; case 's': - ret = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_SYMBOL); + ret = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_SYMBOL); break; case 'X': ret = format_fetch_time(hContact, CurrencyRates_GetTimeFormat(true)); @@ -894,23 +880,15 @@ std::wstring CCurrencyRatesProviderBase::FormatSymbol(MCONTACT hContact, wchar_t break; case 't': { - std::wstring sFrmt = CurrencyRates_GetDateFormat(true); + CMStringW sFrmt = CurrencyRates_GetDateFormat(true); sFrmt += L" "; sFrmt += CurrencyRates_GetTimeFormat(true); ret = format_fetch_time(hContact, sFrmt); } break; - case 'r': - case 'R': - if (true == CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_CURR_VALUE, d)) - ret = format_double(d, nWidth); - else - ret = L"-"; - break; - - case 'p': - case 'P': - if (true == CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_PREV_VALUE, d)) + + default: + if (ParseSymbol(hContact, c, d)) ret = format_double(d, nWidth); else ret = L"-"; diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h index f85887887f..6a2256d0e8 100644 --- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h +++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.h @@ -6,18 +6,16 @@ class CCurrencyRate { -public: - CCurrencyRate(const std::wstring& rsID = L"", const std::wstring& rsSymbol = L"", const std::wstring& rsName = L"") - : m_sSymbol(rsSymbol), m_sName(rsName), m_sID(rsID){} + CMStringW m_sSymbol, m_sName, m_sID; - const std::wstring& GetSymbol() const{ return m_sSymbol; } - const std::wstring& GetName() const{ return m_sName; } - const std::wstring& GetID() const{ return m_sID; } +public: + CCurrencyRate(const CMStringW &rsID = L"", const CMStringW &rsSymbol = L"", const CMStringW &rsName = L"") : + m_sSymbol(rsSymbol), m_sName(rsName), m_sID(rsID) + {} -private: - std::wstring m_sSymbol; - std::wstring m_sName; - std::wstring m_sID; + const CMStringW& GetSymbol() const{ return m_sSymbol; } + const CMStringW& GetName() const{ return m_sName; } + const CMStringW& GetID() const{ return m_sID; } }; ///////////////////////////////////////////////////////////////////////////////////////// @@ -29,11 +27,17 @@ public: typedef std::vector<CCurrencyRateSection> TSections; typedef std::vector<CCurrencyRate> TCurrencyRates; +private: + CMStringW m_sName; + TSections m_aSections; + TCurrencyRates m_aCurrencyRates; + public: - CCurrencyRateSection(const std::wstring& rsName = L"", const TSections& raSections = TSections(), const TCurrencyRates& raCurrencyRates = TCurrencyRates()) - : m_sName(rsName), m_aSections(raSections), m_aCurrencyRates(raCurrencyRates){} + CCurrencyRateSection(const CMStringW &rsName = L"", const TSections &raSections = TSections(), const TCurrencyRates &raCurrencyRates = TCurrencyRates()) : + m_sName(rsName), m_aSections(raSections), m_aCurrencyRates(raCurrencyRates) + {} - const std::wstring& GetName() const + const CMStringW& GetName() const { return m_sName; } @@ -57,11 +61,6 @@ public: { return ((nIndex < m_aCurrencyRates.size()) ? m_aCurrencyRates[nIndex] : CCurrencyRate()); } - -private: - std::wstring m_sName; - TSections m_aSections; - TCurrencyRates m_aCurrencyRates; }; ///////////////////////////////////////////////////////////////////////////////////////// @@ -77,9 +76,9 @@ class CCurrencyRatesProviderBase : public ICurrencyRatesProvider HANDLE m_hEventSettingsChanged; HANDLE m_hEventRefreshContact; - std::wstring m_sContactListFormat; - std::wstring m_sStatusMsgFormat; - std::wstring m_sTendencyFormat; + CMStringW m_sContactListFormat; + CMStringW m_sStatusMsgFormat; + CMStringW m_sTendencyFormat; TContacts m_aRefreshingContacts; bool m_bRefreshInProgress; @@ -102,15 +101,15 @@ public: void RefreshContact(MCONTACT hContact) override; void FillFormat(TFormatSpecificators&) const override; - bool ParseSymbol(MCONTACT hContact, wchar_t c, double &d) override; - std::wstring FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth = 0) const override; + bool ParseSymbol(MCONTACT hContact, wchar_t c, double &d) const override; + CMStringW FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth = 0) const override; protected: - const std::wstring& GetURL() const; - MCONTACT CreateNewContact(const std::wstring& rsName); + const CMStringW& GetURL() const; + MCONTACT CreateNewContact(const CMStringW &rsName); static bool IsOnline(); static void SetContactStatus(MCONTACT hContact, int nNewStatus); - void WriteContactRate(MCONTACT hContact, double dRate, const std::wstring& rsSymbol = L""); + void WriteContactRate(MCONTACT hContact, double dRate, const CMStringW &rsSymbol = L""); virtual void RefreshCurrencyRates(TContacts &anContacts) = 0; diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp index ef439cb2fe..9b1bfdc31a 100644 --- a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp +++ b/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.cpp @@ -1,45 +1,30 @@ #include "stdafx.h" #include "CurrencyRatesProviderCurrencyConverter.h" -#include <boost\property_tree\ptree.hpp> -#include <boost\property_tree\json_parser.hpp> -std::wstring build_url(const std::wstring &rsURL, const std::wstring &from, const std::wstring &to) +CMStringW build_url(const CMStringW &rsURL, const CMStringW &from, const CMStringW &to) { - std::wostringstream o; - o << rsURL << L"?q=" << from << L"_" << to << "&compact=ultra"; + CMStringW res = rsURL + L"?q=" + from + L"_" + to + L"&compact=ultra"; ptrA szApiKey(g_plugin.getStringA(DB_KEY_ApiKey)); if (szApiKey != nullptr) - o << "&apiKey=" << szApiKey.get(); - return o.str(); + res.AppendFormat(L"&apiKey=%S", szApiKey.get()); + return res; } -std::wstring build_url(MCONTACT hContact, const std::wstring &rsURL) +CMStringW build_url(MCONTACT hContact, const CMStringW &rsURL) { - std::wstring sFrom = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_FROM_ID); - std::wstring sTo = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_TO_ID); + CMStringW sFrom = g_plugin.getMStringW(hContact, DB_STR_FROM_ID); + CMStringW sTo = g_plugin.getMStringW(hContact, DB_STR_TO_ID); return build_url(rsURL, sFrom, sTo); } -bool parse_responce(const std::wstring &rsJSON, double &dRate) +bool parse_response(const CMStringW &rsJSON, double &dRate) { - try { - boost::property_tree::ptree pt; - std::istringstream i_stream(currencyrates_t2a(rsJSON.c_str())); - - boost::property_tree::read_json(i_stream, pt); - if (!pt.empty()) { - auto pt_nested = pt.begin()->second; - dRate = pt_nested.get_value<double>(); - } - else { - dRate = pt.get_value<double>(); - } + setlocale(LC_NUMERIC, "en_US"); + JSONNode root = JSONNode::parse(_T2A(rsJSON)); + if (!root) + return false; - return true; - } - catch (boost::property_tree::ptree_error&) { - } - return false; + return 1 == swscanf(root.at(json_index_t(0)).as_mstring(), L"%lf", &dRate); } using TWatchedRates = std::vector<CCurrencyRatesProviderCurrencyConverter::TRateInfo>; @@ -57,23 +42,21 @@ INT_PTR CALLBACK OptDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPara return nullptr; }; - auto make_currencyrate_name = [](const CCurrencyRate &rCurrencyRate)->std::wstring + auto make_currencyrate_name = [](const CCurrencyRate &rCurrencyRate)->CMStringW { - const std::wstring& rsDesc = rCurrencyRate.GetName(); - return((false == rsDesc.empty()) ? rsDesc : rCurrencyRate.GetSymbol()); + auto &rsDesc = rCurrencyRate.GetName(); + return((false == rsDesc.IsEmpty()) ? rsDesc : rCurrencyRate.GetSymbol()); }; - auto make_contact_name = [](const std::wstring &rsSymbolFrom, const std::wstring &rsSymbolTo)->std::wstring + auto make_contact_name = [](const CMStringW &rsSymbolFrom, const CMStringW &rsSymbolTo)->CMStringW { - std::wostringstream o; - o << rsSymbolFrom << L"/" << rsSymbolTo; - return o.str(); + return rsSymbolFrom + L"/" + rsSymbolTo; }; - auto make_rate_name = [make_contact_name](const CCurrencyRatesProviderCurrencyConverter::TRateInfo &ri)->std::wstring + auto make_rate_name = [make_contact_name](const CCurrencyRatesProviderCurrencyConverter::TRateInfo &ri)->CMStringW { - if ((false == ri.first.GetName().empty()) && (false == ri.second.GetName().empty())) + if ((false == ri.first.GetName().IsEmpty()) && (false == ri.second.GetName().IsEmpty())) return make_contact_name(ri.first.GetName(), ri.second.GetName()); return make_contact_name(ri.first.GetSymbol(), ri.second.GetSymbol()); @@ -140,10 +123,9 @@ INT_PTR CALLBACK OptDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPara auto cCurrencyRates = rSection.GetCurrencyRateCount(); for (auto i = 0u; i < cCurrencyRates; ++i) { const auto& rCurrencyRate = rSection.GetCurrencyRate(i); - std::wstring sName = make_currencyrate_name(rCurrencyRate); - LPCTSTR pszName = sName.c_str(); - ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName)); - ::SendMessage(hcbxTo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszName)); + CMStringW sName = make_currencyrate_name(rCurrencyRate); + ::SendMessage(hcbxFrom, CB_ADDSTRING, 0, LPARAM(sName.c_str())); + ::SendMessage(hcbxTo, CB_ADDSTRING, 0, LPARAM(sName.c_str())); } auto cWatchedRates = pProvider->GetWatchedRateCount(); @@ -151,9 +133,8 @@ INT_PTR CALLBACK OptDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPara CCurrencyRatesProviderCurrencyConverter::TRateInfo ri; if (true == pProvider->GetWatchedRateInfo(i, ri)) { g_aWatchedRates.push_back(ri); - std::wstring sRate = make_rate_name(ri); - LPCTSTR pszRateName = sRate.c_str(); - ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRateName)); + CMStringW sRate = make_rate_name(ri); + ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, LPARAM(sRate.c_str())); } } @@ -207,9 +188,8 @@ INT_PTR CALLBACK OptDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPara g_aWatchedRates.push_back(ri); - std::wstring sRate = make_rate_name(ri); - LPCTSTR pszRateName = sRate.c_str(); - ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pszRateName)); + CMStringW sRate = make_rate_name(ri); + ::SendDlgItemMessage(hdlg, IDC_LIST_RATES, LB_ADDSTRING, 0, LPARAM(sRate.c_str())); PropSheet_Changed(::GetParent(hdlg), hdlg); } } @@ -261,17 +241,17 @@ void CCurrencyRatesProviderCurrencyConverter::ShowPropertyPage(WPARAM wp, OPTION void CCurrencyRatesProviderCurrencyConverter::RefreshCurrencyRates(TContacts &anContacts) { CHTTPSession http; - std::wstring sURL = GetURL(); + CMStringW sURL = GetURL(); for (TContacts::const_iterator i = anContacts.begin(); i != anContacts.end() && IsOnline(); ++i) { MCONTACT hContact = *i; - std::wstring sFullURL = build_url(hContact, sURL); + CMStringW sFullURL = build_url(hContact, sURL); if ((true == http.OpenURL(sFullURL)) && (true == IsOnline())) { - std::wstring sHTML; + CMStringW sHTML; if ((true == http.ReadResponce(sHTML)) && (true == IsOnline())) { double dRate = 0.0; - if ((true == parse_responce(sHTML, dRate)) && (true == IsOnline())) { + if ((true == parse_response(sHTML, dRate)) && (true == IsOnline())) { WriteContactRate(hContact, dRate); continue; } @@ -284,14 +264,14 @@ void CCurrencyRatesProviderCurrencyConverter::RefreshCurrencyRates(TContacts &an double CCurrencyRatesProviderCurrencyConverter::Convert(double dAmount, const CCurrencyRate &from, const CCurrencyRate &to) const { - std::wstring sFullURL = build_url(GetURL(), from.GetID(), to.GetID()); + CMStringW sFullURL = build_url(GetURL(), from.GetID(), to.GetID()); CHTTPSession http; if ((true == http.OpenURL(sFullURL))) { - std::wstring sHTML; + CMStringW sHTML; if ((true == http.ReadResponce(sHTML))) { double dResult = 0.0; - if ((true == parse_responce(sHTML, dResult))) + if ((true == parse_response(sHTML, dResult))) return dResult * dAmount; throw std::runtime_error(Translate("Error occurred during HTML parsing.")); @@ -314,10 +294,10 @@ bool CCurrencyRatesProviderCurrencyConverter::GetWatchedRateInfo(size_t nIndex, return false; MCONTACT hContact = m_aContacts[nIndex]; - std::wstring sSymbolFrom = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_FROM_ID); - std::wstring sSymbolTo = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_TO_ID); - std::wstring sDescFrom = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_FROM_DESCRIPTION); - std::wstring sDescTo = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_TO_DESCRIPTION); + CMStringW sSymbolFrom = g_plugin.getMStringW(hContact, DB_STR_FROM_ID); + CMStringW sSymbolTo = g_plugin.getMStringW(hContact, DB_STR_TO_ID); + CMStringW sDescFrom = g_plugin.getMStringW(hContact, DB_STR_FROM_DESCRIPTION); + CMStringW sDescTo = g_plugin.getMStringW(hContact, DB_STR_TO_DESCRIPTION); rRateInfo.first = CCurrencyRate(sSymbolFrom, sSymbolFrom, sDescFrom); rRateInfo.second = CCurrencyRate(sSymbolTo, sSymbolTo, sDescTo); @@ -328,30 +308,26 @@ bool CCurrencyRatesProviderCurrencyConverter::WatchForRate(const TRateInfo &ri, { auto i = std::find_if(m_aContacts.begin(), m_aContacts.end(), [&ri](auto hContact)->bool { - std::wstring sFrom = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_FROM_ID); - std::wstring sTo = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_TO_ID); - return ((0 == mir_wstrcmpi(ri.first.GetID().c_str(), sFrom.c_str())) - && (0 == mir_wstrcmpi(ri.second.GetID().c_str(), sTo.c_str()))); + CMStringW sFrom = g_plugin.getMStringW(hContact, DB_STR_FROM_ID); + CMStringW sTo = g_plugin.getMStringW(hContact, DB_STR_TO_ID); + return !mir_wstrcmpi(ri.first.GetID().c_str(), sFrom.c_str()) && !mir_wstrcmpi(ri.second.GetID().c_str(), sTo.c_str()); }); - auto make_contact_name = [](const std::wstring &rsSymbolFrom, const std::wstring &rsSymbolTo)->std::wstring + auto make_contact_name = [](const CMStringW &rsSymbolFrom, const CMStringW &rsSymbolTo)->CMStringW { - std::wostringstream o; - o << rsSymbolFrom << L"/" << rsSymbolTo; - return o.str(); + return rsSymbolFrom + L"/" + rsSymbolTo; }; - if ((true == bWatch) && (i == m_aContacts.end())) { - std::wstring sName = make_contact_name(ri.first.GetSymbol(), ri.second.GetSymbol()); + CMStringW sName = make_contact_name(ri.first.GetSymbol(), ri.second.GetSymbol()); MCONTACT hContact = CreateNewContact(sName); if (hContact) { g_plugin.setWString(hContact, DB_STR_FROM_ID, ri.first.GetID().c_str()); g_plugin.setWString(hContact, DB_STR_TO_ID, ri.second.GetID().c_str()); - if (false == ri.first.GetName().empty()) { + if (false == ri.first.GetName().IsEmpty()) { g_plugin.setWString(hContact, DB_STR_FROM_DESCRIPTION, ri.first.GetName().c_str()); } - if (false == ri.second.GetName().empty()) { + if (false == ri.second.GetName().IsEmpty()) { g_plugin.setWString(hContact, DB_STR_TO_DESCRIPTION, ri.second.GetName().c_str()); } @@ -372,15 +348,15 @@ bool CCurrencyRatesProviderCurrencyConverter::WatchForRate(const TRateInfo &ri, return false; } -MCONTACT CCurrencyRatesProviderCurrencyConverter::GetContactByID(const std::wstring& rsFromID, const std::wstring& rsToID) const +MCONTACT CCurrencyRatesProviderCurrencyConverter::GetContactByID(const CMStringW &rsFromID, const CMStringW &rsToID) const { mir_cslock lck(m_cs); auto i = std::find_if(m_aContacts.begin(), m_aContacts.end(), [rsFromID, rsToID](MCONTACT hContact)->bool { - std::wstring sFrom = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_FROM_ID); - std::wstring sTo = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_TO_ID); - return ((0 == mir_wstrcmpi(rsFromID.c_str(), sFrom.c_str())) && (0 == mir_wstrcmpi(rsToID.c_str(), sTo.c_str()))); + CMStringW sFrom = g_plugin.getMStringW(hContact, DB_STR_FROM_ID); + CMStringW sTo = g_plugin.getMStringW(hContact, DB_STR_TO_ID); + return !mir_wstrcmpi(rsFromID.c_str(), sFrom.c_str()) && !mir_wstrcmpi(rsToID.c_str(), sTo.c_str()); }); if (i != m_aContacts.end()) @@ -393,27 +369,27 @@ void CCurrencyRatesProviderCurrencyConverter::FillFormat(TFormatSpecificators &a { CSuper::FillFormat(array); - array.push_back(CFormatSpecificator(L"%F", TranslateT("From Currency Full Name"))); - array.push_back(CFormatSpecificator(L"%f", TranslateT("From Currency Short Name"))); - array.push_back(CFormatSpecificator(L"%I", TranslateT("Into Currency Full Name"))); - array.push_back(CFormatSpecificator(L"%i", TranslateT("Into Currency Short Name"))); - array.push_back(CFormatSpecificator(L"%s", TranslateT("Short notation for \"%f/%i\""))); + array.push_back(CFormatSpecificator(L"%F", LPGENW("From Currency Full Name"))); + array.push_back(CFormatSpecificator(L"%f", LPGENW("From Currency Short Name"))); + array.push_back(CFormatSpecificator(L"%I", LPGENW("Into Currency Full Name"))); + array.push_back(CFormatSpecificator(L"%i", LPGENW("Into Currency Short Name"))); + array.push_back(CFormatSpecificator(L"%s", LPGENW("Short notation for \"%f/%i\""))); } -std::wstring CCurrencyRatesProviderCurrencyConverter::FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth) const +CMStringW CCurrencyRatesProviderCurrencyConverter::FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth) const { switch (c) { case 'F': - return CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_FROM_DESCRIPTION); + return g_plugin.getMStringW(hContact, DB_STR_FROM_DESCRIPTION); case 'f': - return CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_FROM_ID); + return g_plugin.getMStringW(hContact, DB_STR_FROM_ID); case 'I': - return CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_TO_DESCRIPTION); + return g_plugin.getMStringW(hContact, DB_STR_TO_DESCRIPTION); case 'i': - return CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_TO_ID); + return g_plugin.getMStringW(hContact, DB_STR_TO_ID); } return CSuper::FormatSymbol(hContact, c, nWidth); diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h b/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h index 4b8e15be05..0bb2f6225f 100644 --- a/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h +++ b/protocols/CurrencyRates/src/CurrencyRatesProviderCurrencyConverter.h @@ -20,7 +20,7 @@ public: size_t GetWatchedRateCount() const; bool GetWatchedRateInfo(size_t nIndex, TRateInfo &rRateInfo); bool WatchForRate(const TRateInfo &ri, bool bWatch); - MCONTACT GetContactByID(const std::wstring &rsFromID, const std::wstring &rsToID) const; + MCONTACT GetContactByID(const CMStringW &rsFromID, const CMStringW &rsToID) const; private: void FillFormat(TFormatSpecificators &) const override; @@ -28,5 +28,5 @@ private: void ShowPropertyPage(WPARAM wp, OPTIONSDIALOGPAGE &odp) override; MCONTACT ImportContact(const TiXmlNode*) override; - std::wstring FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth) const override; + CMStringW FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth) const override; }; diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp index 1b35055c26..0bb5481867 100644 --- a/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp +++ b/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp @@ -62,8 +62,8 @@ ICurrencyRatesProvider* GetContactProviderPtr(MCONTACT hContact) if (nullptr == szProto || 0 != ::_stricmp(szProto, MODULENAME)) return nullptr; - std::wstring sProvider = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_PROVIDER); - if (true == sProvider.empty()) + CMStringW sProvider = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_PROVIDER); + if (sProvider.IsEmpty()) return nullptr; return FindProvider(sProvider); @@ -71,11 +71,11 @@ ICurrencyRatesProvider* GetContactProviderPtr(MCONTACT hContact) ///////////////////////////////////////////////////////////////////////////////////////// -ICurrencyRatesProvider* FindProvider(const std::wstring& rsName) +ICurrencyRatesProvider* FindProvider(const CMStringW &rsName) { for (auto &pProvider : g_apProviders) { const ICurrencyRatesProvider::CProviderInfo& rInfo = pProvider->GetInfo(); - if (0 == ::mir_wstrcmpi(rsName.c_str(), rInfo.m_sName.c_str())) + if (!mir_wstrcmpi(rsName.c_str(), rInfo.m_sName.c_str())) return pProvider; } diff --git a/protocols/CurrencyRates/src/DBUtils.cpp b/protocols/CurrencyRates/src/DBUtils.cpp index acc4debddb..05e0e79c05 100644 --- a/protocols/CurrencyRates/src/DBUtils.cpp +++ b/protocols/CurrencyRates/src/DBUtils.cpp @@ -1,20 +1,12 @@ #include "StdAfx.h" -std::wstring GetNodeText(const TiXmlElement *pNode) +CMStringW GetNodeText(const TiXmlElement *pNode) { auto *pszText = pNode->GetText(); if (pszText) return Utf2T(pszText).get(); - return std::wstring(); -} - -std::wstring CurrencyRates_DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *pszDefValue) -{ - if (pszDefValue == nullptr) - pszDefValue = L""; - - return std::wstring(ptrW(db_get_wsa(hContact, szModule, szSetting, pszDefValue))); + return CMStringW(); } bool CurrencyRates_DBWriteDouble(MCONTACT hContact, const char *szModule, const char *szSetting, double dValue) @@ -35,9 +27,14 @@ bool CurrencyRates_DBReadDouble(MCONTACT hContact, const char *szModule, const c return bResult; } -void FixInvalidChars(std::wstring &s) +void FixInvalidChars(CMStringW &s) { - for (auto &c : s) - if (wcschr(L"\\/:*?\"<>|", c)) - c = '_'; + s.Replace('\\', '_'); + s.Replace('/', '_'); + s.Replace(':', '_'); + s.Replace('*', '_'); + s.Replace('\"', '_'); + s.Replace('<', '_'); + s.Replace('>', '_'); + s.Replace('/', '_'); } diff --git a/protocols/CurrencyRates/src/DBUtils.h b/protocols/CurrencyRates/src/DBUtils.h index 4ff975d0f1..ed133c2a22 100644 --- a/protocols/CurrencyRates/src/DBUtils.h +++ b/protocols/CurrencyRates/src/DBUtils.h @@ -41,11 +41,9 @@ #define DB_KEY_TendencyFormat "CC_TendencyFormat" #define DB_DEF_TendencyFormat L"%r>%p" -void FixInvalidChars(std::wstring &s); +void FixInvalidChars(CMStringW &s); -std::wstring GetNodeText(const TiXmlElement*); - -std::wstring CurrencyRates_DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t* pszDefValue = nullptr); +CMStringW GetNodeText(const TiXmlElement*); bool CurrencyRates_DBWriteDouble(MCONTACT hContact, const char *szModule, const char *szSetting, double dValue); bool CurrencyRates_DBReadDouble(MCONTACT hContact, const char *szModule, const char *szSetting, double& rdValue); diff --git a/protocols/CurrencyRates/src/Forex.cpp b/protocols/CurrencyRates/src/Forex.cpp index 406787f59d..646357aeec 100644 --- a/protocols/CurrencyRates/src/Forex.cpp +++ b/protocols/CurrencyRates/src/Forex.cpp @@ -289,11 +289,26 @@ CMPlugin::CMPlugin() : ///////////////////////////////////////////////////////////////////////////////////////// -void CurrencyRates_IconsInit(); +static IconItem iconList[] = +{ + { LPGEN("Protocol icon"), "main", IDI_ICON_MAIN }, + { LPGEN("Auto Update Disabled"), "auto_update_disabled", IDI_ICON_DISABLED }, + { LPGEN("Currency Rate up"), "currencyrate_up", IDI_ICON_UP }, + { LPGEN("Currency Rate down"), "currencyrate_down", IDI_ICON_DOWN }, + { LPGEN("Currency Rate not changed"), "currencyrate_not_changed",IDI_ICON_NOTCHANGED }, + { LPGEN("Currency Rate Section"), "currencyrate_section", IDI_ICON_SECTION }, + { LPGEN("Currency Rate"), "currencyrate", IDI_ICON_CURRENCYRATE }, + { 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 } +}; int CMPlugin::Load(void) { - CurrencyRates_IconsInit(); + registerIcon(MODULENAME, iconList, MODULENAME); + CurrencyRates_InitExtraIcons(); InitProviders(); @@ -308,7 +323,6 @@ int CMPlugin::Load(void) CreateServiceFunction(MS_CURRENCYRATES_EXPORT, CurrencyRates_Export); CreateServiceFunction(MS_CURRENCYRATES_IMPORT, CurrencyRates_Import); - return 0; } diff --git a/protocols/CurrencyRates/src/HTTPSession.cpp b/protocols/CurrencyRates/src/HTTPSession.cpp index 12b556ab38..3c20328623 100644 --- a/protocols/CurrencyRates/src/HTTPSession.cpp +++ b/protocols/CurrencyRates/src/HTTPSession.cpp @@ -19,14 +19,13 @@ static int find_header(const NETLIBHTTPREQUEST* pRequest, const char* hdr) return -1; } -bool CHTTPSession::OpenURL(const std::wstring &rsURL) +bool CHTTPSession::OpenURL(const CMStringW &rsURL) { - std::string s = currencyrates_t2a(rsURL.c_str()); - m_szUrl = s.c_str(); + m_szUrl = rsURL; return true; } -bool CHTTPSession::ReadResponce(std::wstring &rsResponce) +bool CHTTPSession::ReadResponce(CMStringW &rsResponce) { if (m_szUrl.IsEmpty()) return false; @@ -61,7 +60,7 @@ bool CHTTPSession::ReadResponce(std::wstring &rsResponce) if ((-1 != nIndex) && (nullptr != strstr(_strlwr(pReply->headers[nIndex].szValue), "utf-8"))) rsResponce = ptrW(mir_utf8decodeW(buf)); else - rsResponce = currencyrates_a2t(buf); + rsResponce = _A2T(buf); bResult = true; } diff --git a/protocols/CurrencyRates/src/HTTPSession.h b/protocols/CurrencyRates/src/HTTPSession.h index 35cdbcee63..1b0baceb07 100644 --- a/protocols/CurrencyRates/src/HTTPSession.h +++ b/protocols/CurrencyRates/src/HTTPSession.h @@ -13,8 +13,8 @@ public: static bool Init(); - bool OpenURL(const std::wstring &rsURL); - bool ReadResponce(std::wstring &rsResponce); + bool OpenURL(const CMStringW &rsURL); + bool ReadResponce(CMStringW &rsResponce); }; #endif //__8C9706FF_6B05_4d0d_85B8_5724E5DC0BA4_HTTPSession_h__ diff --git a/protocols/CurrencyRates/src/ICurrencyRatesProvider.h b/protocols/CurrencyRates/src/ICurrencyRatesProvider.h index 7c91e60ac1..90eac87210 100644 --- a/protocols/CurrencyRates/src/ICurrencyRatesProvider.h +++ b/protocols/CurrencyRates/src/ICurrencyRatesProvider.h @@ -8,7 +8,7 @@ class CCurrencyRatesProviderVisitor; ///////////////////////////////////////////////////////////////////////////////////////// // CFormatSpecificator - array of variables to replace -using CFormatSpecificator = std::pair<std::wstring, std::wstring>; +using CFormatSpecificator = std::pair<const wchar_t *, const wchar_t *>; typedef std::vector<CFormatSpecificator> TFormatSpecificators; ///////////////////////////////////////////////////////////////////////////////////////// @@ -19,8 +19,8 @@ class ICurrencyRatesProvider : private boost::noncopyable public: struct CProviderInfo { - std::wstring m_sName; - std::wstring m_sURL; + CMStringW m_sName; + CMStringW m_sURL; }; public: @@ -41,8 +41,8 @@ public: virtual void RefreshContact(MCONTACT hContact) = 0; virtual void FillFormat(TFormatSpecificators&) const = 0; - virtual bool ParseSymbol(MCONTACT hContact, wchar_t c, double &d) = 0; - virtual std::wstring FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth = 0) const = 0; + virtual bool ParseSymbol(MCONTACT hContact, wchar_t c, double &d) const = 0; + virtual CMStringW FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth = 0) const = 0; virtual void Run() = 0; }; @@ -52,7 +52,7 @@ public: typedef std::vector<ICurrencyRatesProvider*> TCurrencyRatesProviders; extern TCurrencyRatesProviders g_apProviders; -ICurrencyRatesProvider* FindProvider(const std::wstring& rsName); +ICurrencyRatesProvider* FindProvider(const CMStringW &rsName); ICurrencyRatesProvider* GetContactProviderPtr(MCONTACT hContact); void InitProviders(); diff --git a/protocols/CurrencyRates/src/IconLib.cpp b/protocols/CurrencyRates/src/IconLib.cpp deleted file mode 100644 index 4d86d6e0c4..0000000000 --- a/protocols/CurrencyRates/src/IconLib.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "StdAfx.h" - -static IconItem iconList[] = -{ - { LPGEN("Protocol icon"), "main", IDI_ICON_MAIN }, - { LPGEN("Auto Update Disabled"), "auto_update_disabled", IDI_ICON_DISABLED }, - { LPGEN("Currency Rate up"), "currencyrate_up", IDI_ICON_UP }, - { LPGEN("Currency Rate down"), "currencyrate_down", IDI_ICON_DOWN }, - { LPGEN("Currency Rate not changed"), "currencyrate_not_changed",IDI_ICON_NOTCHANGED }, - { LPGEN("Currency Rate Section"), "currencyrate_section", IDI_ICON_SECTION }, - { LPGEN("Currency Rate"), "currencyrate", IDI_ICON_CURRENCYRATE }, - { 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 CurrencyRates_IconsInit() -{ - ::g_plugin.registerIcon(MODULENAME, iconList, MODULENAME); -} diff --git a/protocols/CurrencyRates/src/ImportExport.cpp b/protocols/CurrencyRates/src/ImportExport.cpp index fbdb257d32..ff6408d476 100644 --- a/protocols/CurrencyRates/src/ImportExport.cpp +++ b/protocols/CurrencyRates/src/ImportExport.cpp @@ -42,44 +42,43 @@ static int enum_contact_settings(const char *szSetting, void *lp) if (0 == db_get(ctx->m_hContact, ctx->m_pszModule, szSetting, &dbv)) { mir_safety_dbvar sdbvar(&dbv); - std::string sType; - std::wostringstream sValue; - sValue.imbue(GetSystemLocale()); + CMStringA sType; + CMStringW wszValue; switch (dbv.type) { case DBVT_BYTE: - sValue << dbv.bVal; + wszValue.Format(L"%d", dbv.bVal); sType = g_szXmlTypeByte; break; case DBVT_WORD: - sValue << dbv.wVal; + wszValue.Format(L"%d", dbv.wVal); sType = g_szXmlTypeWord; break; case DBVT_DWORD: - sValue << dbv.dVal; + wszValue.Format(L"%d", dbv.dVal); sType = g_szXmlTypeDword; break; case DBVT_ASCIIZ: sType = g_szXmlTypeAsciiz; if (dbv.pszVal) - sValue << dbv.pszVal; + wszValue = dbv.pszVal; break; case DBVT_WCHAR: sType = g_szXmlTypeWchar; if (dbv.pwszVal) - sValue << dbv.pwszVal; + wszValue = dbv.pwszVal; break; case DBVT_UTF8: sType = g_szXmlTypeUtf8; if (dbv.pszVal) - sValue << dbv.pszVal; + wszValue = dbv.pszVal; break; case DBVT_BLOB: sType = g_szXmlTypeBlob; if (dbv.pbVal) { ptrA buf(mir_base64_encode(dbv.pbVal, dbv.cpbVal)); if (buf) - sValue << buf; + wszValue = buf; } break; } @@ -88,8 +87,8 @@ static int enum_contact_settings(const char *szSetting, void *lp) pXmlName->SetText(szSetting); auto *pXmlValue = ctx->m_xmlDoc.NewElement(g_szXmlValue); - pXmlValue->SetText(T2Utf(sValue.str().c_str()).get()); - pXmlValue->SetAttribute(g_szXmlType, sType.c_str()); + pXmlValue->SetText(T2Utf(wszValue.c_str()).get()); + pXmlValue->SetAttribute(g_szXmlType, sType); auto *pXmlSet = ctx->m_xmlDoc.NewElement(g_szXmlSetting); pXmlSet->InsertEndChild(pXmlName); @@ -161,7 +160,7 @@ LPCTSTR prepare_filter(LPTSTR pszBuffer, size_t cBuffer) return pszBuffer; } -bool show_open_file_dialog(bool bOpen, std::wstring& rsFile) +bool show_open_file_dialog(bool bOpen, CMStringW &rsFile) { wchar_t szBuffer[MAX_PATH]; wchar_t szFilter[MAX_PATH]; @@ -198,13 +197,13 @@ bool show_open_file_dialog(bool bOpen, std::wstring& rsFile) INT_PTR CurrencyRates_Export(WPARAM wp, LPARAM lp) { - std::wstring sFileName; + CMStringW sFileName; const char* pszFile = reinterpret_cast<const char*>(lp); if (nullptr == pszFile) { if (false == show_open_file_dialog(false, sFileName)) return -1; } - else sFileName = currencyrates_a2t(pszFile); + else sFileName = _A2T(pszFile); TiXmlDocument doc; auto *pRoot = doc.NewElement(g_szXmlContacts); @@ -485,13 +484,13 @@ bool do_import(const TiXmlNode *pXmlRoot, UINT nFlags) INT_PTR CurrencyRates_Import(WPARAM wp, LPARAM lp) { - std::wstring sFileName; + CMStringW sFileName; const char* pszFile = reinterpret_cast<const char*>(lp); if (nullptr == pszFile) { if (false == show_open_file_dialog(true, sFileName)) return -1; } - else sFileName = currencyrates_a2t(pszFile); + else sFileName = _A2T(pszFile); FILE *in = _wfopen(sFileName.c_str(), L"rb"); if (in == nullptr) diff --git a/protocols/CurrencyRates/src/Locale.cpp b/protocols/CurrencyRates/src/Locale.cpp index 0e112749c4..758773233c 100644 --- a/protocols/CurrencyRates/src/Locale.cpp +++ b/protocols/CurrencyRates/src/Locale.cpp @@ -5,9 +5,9 @@ const std::locale GetSystemLocale() return std::locale(""); } -std::wstring get_int_registry_value(LPCTSTR pszValueName) +static CMStringW get_int_registry_value(LPCTSTR pszValueName) { - std::wstring sResult; + CMStringW sResult; HKEY hKey = nullptr; LONG lResult = ::RegOpenKeyEx(HKEY_CURRENT_USER, L"Control Panel\\International", 0, KEY_QUERY_VALUE, &hKey); @@ -16,14 +16,12 @@ std::wstring get_int_registry_value(LPCTSTR pszValueName) DWORD dwSize = 0; lResult = ::RegQueryValueEx(hKey, pszValueName, nullptr, &dwType, nullptr, &dwSize); if ((ERROR_SUCCESS == lResult) && ((REG_SZ == dwType) || (REG_EXPAND_SZ == dwType))) { - std::vector<wchar_t> 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)); + sResult.Truncate(dwSize); + ::RegQueryValueEx(hKey, pszValueName, nullptr, nullptr, LPBYTE(sResult.c_str()), &dwSize); } } - if (nullptr != hKey) { + if (hKey) { lResult = ::RegCloseKey(hKey); assert(ERROR_SUCCESS == lResult); } @@ -31,8 +29,9 @@ std::wstring get_int_registry_value(LPCTSTR pszValueName) return sResult; } -LPCTSTR date_win_2_boost(const std::wstring& sFrmt) +LPCTSTR CurrencyRates_GetDateFormat(bool bShort) { + CMStringW sFrmt = get_int_registry_value(bShort ? L"sShortDate" : L"sLongDate"); if (sFrmt == L"dd/MM/yy") return L"%d/%m/%y"; if (sFrmt == L"yyyy-MM-dd") @@ -40,20 +39,10 @@ LPCTSTR date_win_2_boost(const std::wstring& sFrmt) return L"%d.%m.%y"; } -LPCTSTR time_win_2_boost(const std::wstring& sFrmt) +LPCTSTR CurrencyRates_GetTimeFormat(bool bShort) { + CMStringW sFrmt = get_int_registry_value(bShort ? L"sShortTime" : L"sTimeFormat"); if (sFrmt == L"H:mm" || sFrmt == L"HH:mm") return L"%H:%M"; - return L"%H:%M:%S"; } - -LPCTSTR CurrencyRates_GetDateFormat(bool bShort) -{ - return date_win_2_boost(get_int_registry_value(bShort ? L"sShortDate" : L"sLongDate")); -} - -LPCTSTR CurrencyRates_GetTimeFormat(bool bShort) -{ - return time_win_2_boost(get_int_registry_value(bShort ? L"sShortTime" : L"sTimeFormat")); -} diff --git a/protocols/CurrencyRates/src/Log.cpp b/protocols/CurrencyRates/src/Log.cpp deleted file mode 100644 index e0a4141a49..0000000000 --- a/protocols/CurrencyRates/src/Log.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "StdAfx.h" - -namespace -{ - mir_cs g_Mutex; - - std::wstring get_log_file_name() - { - return CreateFilePath(L"CurrencyRates.log"); - } - - bool is_log_enabled() - { -#ifdef _DEBUG - return true; -#else - return (1 == g_plugin.getByte(DB_STR_ENABLE_LOG, false)); -#endif - } - - void do_log(const std::wstring& rsFileName, const std::wstring& rsMsg) - { - mir_cslock lck(g_Mutex); - std::wofstream file(rsFileName.c_str(), std::ios::ate | std::ios::app); - if (file.good()) - { - wchar_t szTime[20]; - _tstrtime_s(szTime); - file << szTime << L" ================================>\n" << rsMsg << L"\n\n"; - } - } -} - -void LogIt(const std::wstring& rsMsg) -{ - if (is_log_enabled()) - { - std::wstring sFileName = get_log_file_name(); - do_log(sFileName, rsMsg); - } -} diff --git a/protocols/CurrencyRates/src/Log.h b/protocols/CurrencyRates/src/Log.h deleted file mode 100644 index e8eab88533..0000000000 --- a/protocols/CurrencyRates/src/Log.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __653719be_16d6_4058_8555_8aa7d5404214_OutputDlg_h__ -#define __653719be_16d6_4058_8555_8aa7d5404214_OutputDlg_h__ - -enum ESeverity -{ - Info, - Warning, - Error -}; - -void LogIt(const std::wstring& rsMsg); - -#endif //__653719be_16d6_4058_8555_8aa7d5404214_OutputDlg_h__ diff --git a/protocols/CurrencyRates/src/SettingsDlg.cpp b/protocols/CurrencyRates/src/SettingsDlg.cpp index 18b5c768b6..36e1ad98d9 100644 --- a/protocols/CurrencyRates/src/SettingsDlg.cpp +++ b/protocols/CurrencyRates/src/SettingsDlg.cpp @@ -68,32 +68,24 @@ void update_all_controls(HWND hDlg) ::EnableWindow(::GetDlgItem(hDlg, IDC_BUTTON_POPUP_SETTINGS), (bIsCheckedContactSpec)); } -std::vector<wchar_t> get_filter() -{ - std::vector<wchar_t> aFilter; - LPCTSTR pszFilterParts[] = { LPGENW("Log Files (*.txt,*.log)"), L"*.txt;*.log", LPGENW("All files (*.*)"), L"*.*" }; - for (int i = 0; i < sizeof(pszFilterParts) / sizeof(pszFilterParts[0]); ++i) { - std::wstring sPart = TranslateW(pszFilterParts[i]); - std::copy(sPart.begin(), sPart.end(), std::back_inserter(aFilter)); - aFilter.push_back('\0'); +static LPCTSTR pszFilterParts[] = { LPGENW("Log Files (*.txt,*.log)"), L"*.txt;*.log", LPGENW("All files (*.*)"), L"*.*" }; - } - aFilter.push_back('\0'); - return aFilter; -} void select_log_file(HWND hDlg) { - std::vector<wchar_t> aFileBuffer(_MAX_PATH * 2, '\0'); - LPTSTR pszFile = &*aFileBuffer.begin(); - - std::vector<wchar_t> aFilterBuffer = get_filter(); - LPCTSTR pszFilter = &*aFilterBuffer.begin(); + wchar_t pszFile[MAX_PATH]; + + CMStringW pszFilter; + for (auto &it : pszFilterParts) { + pszFilter += it; + pszFilter.AppendChar(0); + } + pszFilter.AppendChar(0); OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hDlg; ofn.lpstrFile = pszFile; - ofn.nMaxFile = (DWORD)aFileBuffer.size(); + ofn.nMaxFile = _countof(pszFile); ofn.lpstrFilter = pszFilter; ofn.nFilterIndex = 1; ofn.hInstance = g_plugin.getInst(); @@ -242,8 +234,7 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L assert(hWL); WindowList_Add(hWL, hWnd, hContact); - std::wstring sName = GetContactName(hContact); - ::SetDlgItemText(hWnd, IDC_EDIT_NAME, sName.c_str()); + ::SetDlgItemText(hWnd, IDC_EDIT_NAME, GetContactName(hContact)); BYTE bUseContactSpecific = g_plugin.getByte(hContact, DB_STR_CONTACT_SPEC_SETTINGS, 0); ::CheckDlgButton(hWnd, IDC_CHECK_CONTACT_SPECIFIC, bUseContactSpecific ? BST_CHECKED : BST_UNCHECKED); @@ -255,8 +246,7 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L UINT nCheck = (dwLogMode & lmInternalHistory) ? 1 : 0; ::CheckDlgButton(hWnd, IDC_CHECK_INTERNAL_HISTORY, nCheck ? BST_CHECKED : BST_UNCHECKED); - std::wstring sHistoryFrmt = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_FORMAT_HISTORY, setGlobal.GetHistoryFormat().c_str()); - ::SetDlgItemText(hWnd, IDC_EDIT_HISTORY_FORMAT, sHistoryFrmt.c_str()); + ::SetDlgItemText(hWnd, IDC_EDIT_HISTORY_FORMAT, g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_FORMAT_HISTORY, setGlobal.GetHistoryFormat())); WORD wOnlyIfChanged = g_plugin.getWord(hContact, DB_STR_CURRENCYRATE_HISTORY_CONDITION, setGlobal.GetHistoryOnlyChangedFlag()); ::CheckDlgButton(hWnd, IDC_CHECK_HISTORY_CONDITION, (1 == wOnlyIfChanged) ? BST_CHECKED : BST_UNCHECKED); @@ -265,14 +255,12 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L nCheck = (dwLogMode & lmExternalFile) ? 1 : 0; ::CheckDlgButton(hWnd, IDC_CHECK_EXTERNAL_FILE, nCheck ? BST_CHECKED : BST_UNCHECKED); - std::wstring sLogFileName = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_LOG_FILE); - if (true == sLogFileName.empty()) { - sLogFileName = GenerateLogFileName(setGlobal.GetLogFileName(), CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_SYMBOL), glfnResolveCurrencyRateName); - } - ::SetDlgItemText(hWnd, IDC_EDIT_FILE_NAME, sLogFileName.c_str()); + CMStringW sLogFileName = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_LOG_FILE); + if (sLogFileName.IsEmpty()) + sLogFileName = GenerateLogFileName(setGlobal.GetLogFileName(), g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_SYMBOL), glfnResolveCurrencyRateName); + ::SetDlgItemText(hWnd, IDC_EDIT_FILE_NAME, sLogFileName); - std::wstring sLogFileFrmt = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_FORMAT_LOG_FILE, setGlobal.GetLogFormat().c_str()); - ::SetDlgItemText(hWnd, IDC_EDIT_LOG_FILE_FORMAT, sLogFileFrmt.c_str()); + ::SetDlgItemText(hWnd, IDC_EDIT_LOG_FILE_FORMAT, g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_FORMAT_LOG_FILE, setGlobal.GetLogFormat())); wOnlyIfChanged = g_plugin.getWord(hContact, DB_STR_CURRENCYRATE_LOG_FILE_CONDITION, setGlobal.GetLogOnlyChangedFlag()); ::CheckDlgButton(hWnd, IDC_CHECK_LOG_FILE_CONDITION, (1 == wOnlyIfChanged) ? BST_CHECKED : BST_UNCHECKED); @@ -280,8 +268,9 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L // popup nCheck = (dwLogMode & lmPopup) ? 1 : 0; ::CheckDlgButton(hWnd, IDC_CHECK_SHOW_POPUP, nCheck ? BST_CHECKED : BST_UNCHECKED); - std::wstring sPopupFrmt = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_FORMAT_POPUP, setGlobal.GetPopupFormat().c_str()); - ::SetDlgItemText(hWnd, IDC_EDIT_POPUP_FORMAT, sPopupFrmt.c_str()); + + ::SetDlgItemText(hWnd, IDC_EDIT_POPUP_FORMAT, g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_FORMAT_POPUP, setGlobal.GetPopupFormat().c_str())); + bool bOnlyIfChanged = 1 == g_plugin.getByte(hContact, DB_STR_CURRENCYRATE_POPUP_CONDITION, setGlobal.GetShowPopupIfValueChangedFlag()); ::CheckDlgButton(hWnd, IDC_CHECK_SHOW_POPUP_ONLY_VALUE_CHANGED, (bOnlyIfChanged) ? BST_CHECKED : BST_UNCHECKED); @@ -335,7 +324,7 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DIALOG_POPUP), hWnd, - EditPopupSettingsDlgProc, reinterpret_cast<LPARAM>(pParam->m_pPopupSettings)); + EditPopupSettingsDlgProc, LPARAM(pParam->m_pPopupSettings)); } break; @@ -363,31 +352,31 @@ INT_PTR CALLBACK EditSettingsPerContactDlgProc(HWND hWnd, UINT msg, WPARAM wp, L HWND hwndLogFile = ::GetDlgItem(hWnd, IDC_EDIT_FILE_NAME); HWND hwndLogFileFrmt = ::GetDlgItem(hWnd, IDC_EDIT_LOG_FILE_FORMAT); HWND hwndHistoryFrmt = ::GetDlgItem(hWnd, IDC_EDIT_HISTORY_FORMAT); - std::wstring sLogFile = get_window_text(hwndLogFile); - std::wstring sLogFileFormat = get_window_text(hwndLogFileFrmt); - std::wstring sHistoryFormat = get_window_text(hwndHistoryFrmt); + CMStringW sLogFile = get_window_text(hwndLogFile); + CMStringW sLogFileFormat = get_window_text(hwndLogFileFrmt); + CMStringW sHistoryFormat = get_window_text(hwndHistoryFrmt); if ((nLogMode & lmExternalFile)) { - if (true == sLogFile.empty()) { + if (sLogFile.IsEmpty()) { prepare_edit_ctrl_for_error(hwndLogFile); CurrencyRates_MessageBox(hWnd, TranslateT("Enter log file name."), MB_OK | MB_ICONERROR); bOk = false; } - else if (true == sLogFileFormat.empty()) { + else if (sLogFileFormat.IsEmpty()) { prepare_edit_ctrl_for_error(hwndLogFileFrmt); CurrencyRates_MessageBox(hWnd, TranslateT("Enter log file format."), MB_OK | MB_ICONERROR); bOk = false; } } - if ((true == bOk) && (nLogMode & lmInternalHistory) && (true == sHistoryFormat.empty())) { + if (bOk && (nLogMode & lmInternalHistory) && sHistoryFormat.IsEmpty()) { prepare_edit_ctrl_for_error(hwndHistoryFrmt); CurrencyRates_MessageBox(hWnd, TranslateT("Enter history format."), MB_OK | MB_ICONERROR); bOk = false; } HWND hwndPopupFrmt = ::GetDlgItem(hWnd, IDC_EDIT_POPUP_FORMAT); - std::wstring sPopupFormat = get_window_text(hwndPopupFrmt); - if ((true == bOk) && (nLogMode & lmPopup) && (true == sPopupFormat.empty())) { + CMStringW sPopupFormat = get_window_text(hwndPopupFrmt); + if (bOk && (nLogMode & lmPopup) && sPopupFormat.IsEmpty()) { prepare_edit_ctrl_for_error(hwndPopupFrmt); CurrencyRates_MessageBox(hWnd, TranslateT("Enter popup window format."), MB_OK | MB_ICONERROR); bOk = false; @@ -519,16 +508,16 @@ INT_PTR CALLBACK EditSettingsPerProviderDlgProc(HWND hWnd, UINT msg, WPARAM wp, HWND hwndLogFile = ::GetDlgItem(hWnd, IDC_EDIT_FILE_NAME); HWND hwndLogFileFrmt = ::GetDlgItem(hWnd, IDC_EDIT_LOG_FILE_FORMAT); - std::wstring sLogFile = get_window_text(hwndLogFile); - std::wstring sLogFileFormat = get_window_text(hwndLogFileFrmt); + CMStringW sLogFile = get_window_text(hwndLogFile); + CMStringW sLogFileFormat = get_window_text(hwndLogFileFrmt); if ((nLogMode & lmExternalFile)) { - if (true == sLogFile.empty()) { + if (true == sLogFile.IsEmpty()) { prepare_edit_ctrl_for_error(hwndLogFile); CurrencyRates_MessageBox(hWnd, TranslateT("Enter log file name."), MB_OK | MB_ICONERROR); bOk = false; } - else if (true == sLogFileFormat.empty()) { + else if (true == sLogFileFormat.IsEmpty()) { prepare_edit_ctrl_for_error(hwndLogFileFrmt); CurrencyRates_MessageBox(hWnd, TranslateT("Enter log file format."), MB_OK | MB_ICONERROR); bOk = false; @@ -536,16 +525,16 @@ INT_PTR CALLBACK EditSettingsPerProviderDlgProc(HWND hWnd, UINT msg, WPARAM wp, } HWND hwndHistoryFrmt = ::GetDlgItem(hWnd, IDC_EDIT_HISTORY_FORMAT); - std::wstring sHistoryFormat = get_window_text(hwndHistoryFrmt); - if ((true == bOk) && (nLogMode & lmInternalHistory) && (true == sHistoryFormat.empty())) { + CMStringW sHistoryFormat = get_window_text(hwndHistoryFrmt); + if ((true == bOk) && (nLogMode & lmInternalHistory) && (true == sHistoryFormat.IsEmpty())) { prepare_edit_ctrl_for_error(hwndHistoryFrmt); CurrencyRates_MessageBox(hWnd, TranslateT("Enter history format."), MB_OK | MB_ICONERROR); bOk = false; } HWND hwndPopupFrmt = ::GetDlgItem(hWnd, IDC_EDIT_POPUP_FORMAT); - std::wstring sPopupFormat = get_window_text(hwndPopupFrmt); - if ((true == bOk) && (nLogMode & lmPopup) && (true == sPopupFormat.empty())) { + CMStringW sPopupFormat = get_window_text(hwndPopupFrmt); + if ((true == bOk) && (nLogMode & lmPopup) && (true == sPopupFormat.IsEmpty())) { prepare_edit_ctrl_for_error(hwndPopupFrmt); CurrencyRates_MessageBox(hWnd, TranslateT("Enter popup window format."), MB_OK | MB_ICONERROR); bOk = false; @@ -606,7 +595,7 @@ INT_PTR CALLBACK EditSettingsPerProviderDlgProc(HWND hWnd, UINT msg, WPARAM wp, DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DIALOG_POPUP), hWnd, - EditPopupSettingsDlgProc, reinterpret_cast<LPARAM>(pAdvSettings->GetPopupSettingsPtr())); + EditPopupSettingsDlgProc, LPARAM(pAdvSettings->GetPopupSettingsPtr())); break; } break; @@ -625,21 +614,21 @@ CAdvProviderSettings::CAdvProviderSettings(const ICurrencyRatesProvider *pCurren assert(m_pCurrencyRatesProvider); m_wLogMode = g_plugin.getWord(DB_KEY_LogMode, static_cast<WORD>(lmDisabled)); - m_sFormatHistory = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_HistoryFormat, DB_DEF_HistoryFormat); + m_sFormatHistory = g_plugin.getMStringW(DB_KEY_HistoryFormat, DB_DEF_HistoryFormat); m_bIsOnlyChangedHistory = 1 == g_plugin.getByte(DB_KEY_HistoryCondition, 0); - m_sLogFileName = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_LogFile); - if (true == m_sLogFileName.empty()) { + m_sLogFileName = g_plugin.getMStringW(DB_KEY_LogFile); + if (true == m_sLogFileName.IsEmpty()) { m_sLogFileName = g_pszVariableUserProfile; m_sLogFileName += L"\\CurrencyRates\\"; m_sLogFileName += g_pszVariableCurrencyRateName; m_sLogFileName += L".log"; } - m_sFormatLogFile = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_LogFormat, DB_DEF_LogFormat); + m_sFormatLogFile = g_plugin.getMStringW(DB_KEY_LogFormat, DB_DEF_LogFormat); m_bIsOnlyChangedLogFile = (1 == g_plugin.getByte(DB_KEY_LogCondition, 0)); - m_sPopupFormat = CurrencyRates_DBGetStringW(NULL, MODULENAME, DB_KEY_PopupFormat, DB_DEF_PopupFormat); + m_sPopupFormat = g_plugin.getMStringW(DB_KEY_PopupFormat, DB_DEF_PopupFormat); m_bShowPopupIfValueChanged = (1 == g_plugin.getByte(DB_KEY_PopupCondition, 0)); } @@ -674,86 +663,6 @@ void CAdvProviderSettings::SaveToDb() const } } -WORD CAdvProviderSettings::GetLogMode() const -{ - return m_wLogMode; -} - -void CAdvProviderSettings::SetLogMode(WORD wMode) -{ - m_wLogMode = wMode; -} - -std::wstring CAdvProviderSettings::GetHistoryFormat() const -{ - return m_sFormatHistory; -} - -void CAdvProviderSettings::SetHistoryFormat(const std::wstring &rsFormat) -{ - m_sFormatHistory = rsFormat; -} - -bool CAdvProviderSettings::GetHistoryOnlyChangedFlag() const -{ - return m_bIsOnlyChangedHistory; -} - -void CAdvProviderSettings::SetHistoryOnlyChangedFlag(bool bMode) -{ - m_bIsOnlyChangedHistory = bMode; -} - -std::wstring CAdvProviderSettings::GetLogFileName() const -{ - return m_sLogFileName; -} - -void CAdvProviderSettings::SetLogFileName(const std::wstring &rsFile) -{ - m_sLogFileName = rsFile; -} - -std::wstring CAdvProviderSettings::GetLogFormat() const -{ - return m_sFormatLogFile; -} - -void CAdvProviderSettings::SetLogFormat(const std::wstring &rsFormat) -{ - m_sFormatLogFile = rsFormat; -} - -bool CAdvProviderSettings::GetLogOnlyChangedFlag() const -{ - return m_bIsOnlyChangedLogFile; -} - -void CAdvProviderSettings::SetLogOnlyChangedFlag(bool bMode) -{ - m_bIsOnlyChangedLogFile = bMode; -} - -const std::wstring &CAdvProviderSettings::GetPopupFormat() const -{ - return m_sPopupFormat; -} - -void CAdvProviderSettings::SetPopupFormat(const std::wstring &val) -{ - m_sPopupFormat = val; -} - -bool CAdvProviderSettings::GetShowPopupIfValueChangedFlag() const -{ - return m_bShowPopupIfValueChanged; -} - -void CAdvProviderSettings::SetShowPopupIfValueChangedFlag(bool val) -{ - m_bShowPopupIfValueChanged = val; -} - CPopupSettings *CAdvProviderSettings::GetPopupSettingsPtr() const { if (nullptr == m_pPopupSettings) @@ -897,21 +806,18 @@ bool ShowSettingsDlg(HWND hWndParent, CAdvProviderSettings *pAdvSettings) MAKEINTRESOURCE(IDD_PROVIDER_ADV_SETTINGS), hWndParent, EditSettingsPerProviderDlgProc, - reinterpret_cast<LPARAM>(pAdvSettings))); + LPARAM(pAdvSettings))); } -std::wstring GenerateLogFileName(const std::wstring &rsLogFilePattern, const std::wstring &rsCurrencyRateSymbol, int nFlags) +CMStringW GenerateLogFileName(const CMStringW &rsLogFilePattern, const CMStringW &rsCurrencyRateSymbol, int nFlags) { - std::wstring sPath = rsLogFilePattern; + CMStringW sPath = rsLogFilePattern; if (nFlags & glfnResolveCurrencyRateName) { - assert(false == rsCurrencyRateSymbol.empty()); + assert(false == rsCurrencyRateSymbol.IsEmpty()); - std::wstring::size_type n = sPath.find(g_pszVariableCurrencyRateName); - if (std::wstring::npos != n) { - std::wstring s = rsCurrencyRateSymbol; - FixInvalidChars(s); - sPath.replace(n, _countof(g_pszVariableCurrencyRateName) - 1, s.c_str()); - } + CMStringW s = rsCurrencyRateSymbol; + FixInvalidChars(s); + sPath.Replace(g_pszVariableCurrencyRateName, s); } if (nFlags & glfnResolveUserProfile) { @@ -925,32 +831,32 @@ std::wstring GenerateLogFileName(const std::wstring &rsLogFilePattern, const std return sPath; } -std::wstring GetContactLogFileName(MCONTACT hContact) +CMStringW GetContactLogFileName(MCONTACT hContact) { - std::wstring result; + CMStringW result; auto pProvider = GetContactProviderPtr(hContact); if (pProvider) { - std::wstring sPattern; + CMStringW sPattern; bool bUseContactSpecific = (g_plugin.getByte(hContact, DB_STR_CONTACT_SPEC_SETTINGS, 0) > 0); if (bUseContactSpecific) - sPattern = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_LOG_FILE); + sPattern = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_LOG_FILE); else { CAdvProviderSettings global_settings(pProvider); sPattern = global_settings.GetLogFileName(); } - result = GenerateLogFileName(sPattern, CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_SYMBOL)); + result = GenerateLogFileName(sPattern, g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_SYMBOL)); } return result; } -std::wstring GetContactName(MCONTACT hContact) +CMStringW GetContactName(MCONTACT hContact) { - std::wstring sDescription = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_DESCRIPTION); - if (sDescription.empty()) - sDescription = CurrencyRates_DBGetStringW(hContact, MODULENAME, DB_STR_CURRENCYRATE_SYMBOL); + CMStringW sDescription = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_DESCRIPTION); + if (sDescription.IsEmpty()) + sDescription = g_plugin.getMStringW(hContact, DB_STR_CURRENCYRATE_SYMBOL); return sDescription; } diff --git a/protocols/CurrencyRates/src/SettingsDlg.h b/protocols/CurrencyRates/src/SettingsDlg.h index 424b8c2eed..b3cf8c0114 100644 --- a/protocols/CurrencyRates/src/SettingsDlg.h +++ b/protocols/CurrencyRates/src/SettingsDlg.h @@ -56,47 +56,49 @@ private: class CAdvProviderSettings { + const ICurrencyRatesProvider *m_pCurrencyRatesProvider; + WORD m_wLogMode; + bool m_bIsOnlyChangedHistory; + bool m_bIsOnlyChangedLogFile; + bool m_bShowPopupIfValueChanged; + CMStringW m_sFormatHistory; + CMStringW m_sLogFileName; + CMStringW m_sFormatLogFile; + CMStringW m_sPopupFormat; + mutable CPopupSettings* m_pPopupSettings; + public: CAdvProviderSettings(const ICurrencyRatesProvider *pCurrencyRatesProvider); ~CAdvProviderSettings(); void SaveToDb() const; - const ICurrencyRatesProvider* GetProviderPtr() const; + __forceinline WORD GetLogMode() const { return m_wLogMode; } + __forceinline void SetLogMode(WORD wMode) { m_wLogMode = wMode; } - WORD GetLogMode() const; - void SetLogMode(WORD wMode); - std::wstring GetHistoryFormat() const; - void SetHistoryFormat(const std::wstring& rsFormat); - bool GetHistoryOnlyChangedFlag() const; - void SetHistoryOnlyChangedFlag(bool bMode); + __forceinline const CMStringW& GetHistoryFormat() const { return m_sFormatHistory; } + __forceinline void SetHistoryFormat(const CMStringW &rsFormat) { m_sFormatHistory = rsFormat; } - std::wstring GetLogFileName() const; - void SetLogFileName(const std::wstring& rsFile); - std::wstring GetLogFormat() const; - void SetLogFormat(const std::wstring& rsFormat); - bool GetLogOnlyChangedFlag() const; - void SetLogOnlyChangedFlag(bool bMode); + __forceinline bool GetHistoryOnlyChangedFlag() const { return m_bIsOnlyChangedHistory; } + __forceinline void SetHistoryOnlyChangedFlag(bool bMode) { m_bIsOnlyChangedHistory = bMode; } - const std::wstring& GetPopupFormat() const; - void SetPopupFormat(const std::wstring& val); + __forceinline const CMStringW& GetLogFileName() const { return m_sLogFileName; } + __forceinline void SetLogFileName(const CMStringW &rsFile) { m_sLogFileName = rsFile; } - bool GetShowPopupIfValueChangedFlag() const; - void SetShowPopupIfValueChangedFlag(bool val); + __forceinline const CMStringW& GetLogFormat() const { return m_sFormatLogFile; } + __forceinline void SetLogFormat(const CMStringW &rsFormat) { m_sFormatLogFile = rsFormat; } - CPopupSettings* GetPopupSettingsPtr() const; + __forceinline bool GetLogOnlyChangedFlag() const { return m_bIsOnlyChangedLogFile; } + __forceinline void SetLogOnlyChangedFlag(bool bMode) { m_bIsOnlyChangedLogFile = bMode; } -private: - const ICurrencyRatesProvider *m_pCurrencyRatesProvider; - WORD m_wLogMode; - std::wstring m_sFormatHistory; - bool m_bIsOnlyChangedHistory; - std::wstring m_sLogFileName; - std::wstring m_sFormatLogFile; - bool m_bIsOnlyChangedLogFile; - std::wstring m_sPopupFormat; - bool m_bShowPopupIfValueChanged; - mutable CPopupSettings* m_pPopupSettings; + __forceinline const CMStringW& GetPopupFormat() const { return m_sPopupFormat; } + __forceinline void SetPopupFormat(const CMStringW &val) { m_sPopupFormat = val; } + + __forceinline bool GetShowPopupIfValueChangedFlag() const { return m_bShowPopupIfValueChanged; } + __forceinline void SetShowPopupIfValueChangedFlag(bool val) { m_bShowPopupIfValueChanged = val; } + + const ICurrencyRatesProvider* GetProviderPtr() const; + CPopupSettings* GetPopupSettingsPtr() const; }; void ShowSettingsDlg(MCONTACT hContact); @@ -108,9 +110,10 @@ enum glfnResolveUserProfile = 0x0002, glfnResolveAll = glfnResolveCurrencyRateName | glfnResolveUserProfile, }; -std::wstring GenerateLogFileName(const std::wstring& rsLogFilePattern, const std::wstring& rsCurrencyRateSymbol, int nFlags = glfnResolveAll); -std::wstring GetContactLogFileName(MCONTACT hContact); -std::wstring GetContactName(MCONTACT hContact); + +CMStringW GenerateLogFileName(const CMStringW &rsLogFilePattern, const CMStringW &rsCurrencyRateSymbol, int nFlags = glfnResolveAll); +CMStringW GetContactLogFileName(MCONTACT hContact); +CMStringW GetContactName(MCONTACT hContact); #endif //__E211E4D9_383C_43BE_A787_7EF1D585B90D_SettingsDlg_h__ diff --git a/protocols/CurrencyRates/src/WinCtrlHelper.cpp b/protocols/CurrencyRates/src/WinCtrlHelper.cpp index 22dd5e0641..7d6087f44e 100644 --- a/protocols/CurrencyRates/src/WinCtrlHelper.cpp +++ b/protocols/CurrencyRates/src/WinCtrlHelper.cpp @@ -17,10 +17,10 @@ public: TFormatSpecificators aSpecificators; m_pProvider->FillFormat(aSpecificators); - std::wostringstream o; + CMStringW str; for (auto &spec : aSpecificators) - o << spec.first << '\t' << spec.second << L"\r\n"; - ::SetDlgItemText(m_hwnd, IDC_EDIT_VARIABLE, o.str().c_str()); + str.AppendFormat(L"%s\t%s\r\n", spec.first, TranslateW(spec.second)); + ::SetDlgItemTextW(m_hwnd, IDC_EDIT_VARIABLE, str); return true; } }; diff --git a/protocols/CurrencyRates/src/WinCtrlHelper.h b/protocols/CurrencyRates/src/WinCtrlHelper.h index 7cb2c0515e..132e091194 100644 --- a/protocols/CurrencyRates/src/WinCtrlHelper.h +++ b/protocols/CurrencyRates/src/WinCtrlHelper.h @@ -3,7 +3,7 @@ class ICurrencyRatesProvider; -inline std::wstring get_window_text(HWND hWnd) +inline CMStringW get_window_text(HWND hWnd) { int cBytes = ::GetWindowTextLength(hWnd); @@ -11,7 +11,7 @@ inline std::wstring get_window_text(HWND hWnd) LPTSTR pBuffer = &*(aBuf.begin()); ::GetWindowText(hWnd, pBuffer, cBytes + 1); - return std::wstring(pBuffer); + return CMStringW(pBuffer); } inline void prepare_edit_ctrl_for_error(HWND hwndEdit) @@ -25,7 +25,7 @@ void show_variable_list(HWND hwndParent, const ICurrencyRatesProvider *pProvider inline int CurrencyRates_MessageBox(HWND hWnd, LPCTSTR pszText, UINT nType = MB_OK) { - return ::MessageBox(hWnd, pszText, currencyrates_a2t(MIRANDANAME).c_str(), nType); + return ::MessageBox(hWnd, pszText, _A2T(MIRANDANAME), nType); } inline void spin_set_range(HWND hwndSpin, short nLower, short nUpper) diff --git a/protocols/CurrencyRates/src/stdafx.h b/protocols/CurrencyRates/src/stdafx.h index 987aeb87b8..5c30a6856e 100644 --- a/protocols/CurrencyRates/src/stdafx.h +++ b/protocols/CurrencyRates/src/stdafx.h @@ -19,19 +19,20 @@ #include <msapi/comptr.h> #include <newpluginapi.h> -#include <m_database.h> -#include <m_xml.h> #include <m_clist.h> -#include <m_langpack.h> -#include <m_options.h> -#include <m_protosvc.h> +#include <m_database.h> #include <m_extraicons.h> -#include <m_icolib.h> #include <m_genmenu.h> +#include <m_gui.h> +#include <m_icolib.h> +#include <m_json.h> +#include <m_langpack.h> #include <m_netlib.h> +#include <m_options.h> #include <m_popup.h> +#include <m_protosvc.h> #include <m_userinfo.h> -#include <m_gui.h> +#include <m_xml.h> #include <m_variables.h> #include <m_CurrencyRates.h> @@ -43,28 +44,6 @@ typedef boost::posix_time::wtime_input_facet ttime_input_facet; typedef boost::posix_time::wtime_facet ttime_facet; -inline std::string currencyrates_t2a(const wchar_t* t) -{ - std::string s; - char* p = mir_u2a(t); - if (p) { - s = p; - mir_free(p); - } - return s; -} - -inline std::wstring currencyrates_a2t(const char* s) -{ - std::wstring t; - wchar_t* p = mir_a2u(s); - if (p) { - t = p; - mir_free(p); - } - return t; -} - #include "resource.h" #include "version.h" #include "CurrencyRateInfoDlg.h" @@ -74,11 +53,9 @@ inline std::wstring currencyrates_a2t(const char* s) #include "CurrencyConverter.h" #include "WinCtrlHelper.h" #include "ImportExport.h" -#include "Log.h" #include "CommonOptionDlg.h" #include "EconomicRateInfo.h" #include "SettingsDlg.h" -#include "CreateFilePath.h" #include "Locale.h" #include "ExtraImages.h" #include "IsWithinAccuracy.h" @@ -91,6 +68,8 @@ inline std::wstring currencyrates_a2t(const char* s) #include "Chart.h" #endif +CMStringW CreateFilePath(const CMStringW &rsName); + struct CMPlugin : public PLUGIN<CMPlugin> { CMPlugin(); diff --git a/protocols/CurrencyRates/src/version.h b/protocols/CurrencyRates/src/version.h index 764539f356..98626250d1 100644 --- a/protocols/CurrencyRates/src/version.h +++ b/protocols/CurrencyRates/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 2 #define __RELEASE_NUM 1 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include <stdver.h> |