void CQuotesProviderBase::SetContactExtraIcon(MCONTACT hContact)const { // tstring s = DBGetStringT(hContact,LIST_MODULE_NAME,CONTACT_LIST_NAME); // tostringstream o; // o << "Request on " << s << " refreshing\nIs online " << IsOnline() << ", is in progress " << m_bRefreshInProgress << "\n"; bool bResult = false; if(true == IsOnline() && (false == m_bRefreshInProgress)) { CTendency tendency; if(tendency.Parse(this,m_sTendencyFormat,hContact) && (false == m_bRefreshInProgress)) { bResult = do_set_contact_extra_icon(hContact,tendency); } // double dCurrRate = 0.0; // double dPrevRate = 0.0; // if((true == Quotes_DBReadDouble(hContact,QUOTES_PROTOCOL_NAME,DB_STR_QUOTE_CURR_VALUE,dCurrRate)) // && (true == Quotes_DBReadDouble(hContact,QUOTES_PROTOCOL_NAME,DB_STR_QUOTE_PREV_VALUE,dPrevRate)) // && (false == m_bRefreshInProgress)) // { // // o << "Curr rate = " << dCurrRate << ", prev rate " << dPrevRate << "\n"; // bResult = do_set_contact_extra_icon(hContact,dCurrRate,dPrevRate); // } } // o << "Result is " << bResult; // LogIt(Info,o.str()); }
bool do_set_contact_extra_icon(MCONTACT hContact, const CTendency& tendency) { CTendency::EResult nComparison = tendency.Compare(); if (CTendency::NotChanged == nComparison) return SetContactExtraImage(hContact, eiNotChanged); if (CTendency::Up == nComparison) return SetContactExtraImage(hContact, eiUp); if (CTendency::Down == nComparison) return SetContactExtraImage(hContact, eiDown); return false; }
void CQuotesProviderBase::WriteContactRate(MCONTACT hContact, double dRate, const tstring& rsSymbol/* = ""*/) { time_t nTime = ::time(NULL); if (false == rsSymbol.empty()) db_set_ts(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL, rsSymbol.c_str()); double dPrev = 0.0; bool bValidPrev = Quotes_DBReadDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_CURR_VALUE, dPrev); if (true == bValidPrev) Quotes_DBWriteDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_PREV_VALUE, dPrev); Quotes_DBWriteDouble(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_CURR_VALUE, dRate); db_set_dw(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FETCH_TIME, nTime); tstring sSymbol = rsSymbol; tostringstream oNick; oNick.imbue(GetSystemLocale()); if (false == m_sContactListFormat.empty()) { tstring s = format_rate(this, hContact, m_sContactListFormat); oNick << s; } else { if (true == sSymbol.empty()) sSymbol = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL); oNick << std::setfill(_T(' ')) << std::setw(10) << std::left << sSymbol << std::setw(6) << std::right << dRate; } CTendency tendency; if (true == tendency.Parse(this, m_sTendencyFormat, hContact)) do_set_contact_extra_icon(hContact, tendency); db_set_ts(hContact, LIST_MODULE_NAME, CONTACT_LIST_NAME, oNick.str().c_str()); tstring sStatusMsg = format_rate(this, hContact, m_sStatusMsgFormat); if (false == sStatusMsg.empty()) db_set_ts(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME, sStatusMsg.c_str()); else db_unset(hContact, LIST_MODULE_NAME, STATUS_MSG_NAME); bool bUseContactSpecific = (db_get_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_CONTACT_SPEC_SETTINGS, 0) > 0); CAdvProviderSettings global_settings(this); WORD dwMode = (bUseContactSpecific) ? db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG, static_cast<WORD>(lmDisabled)) : global_settings.GetLogMode(); if (dwMode&lmExternalFile) { bool bAdd = true; bool bOnlyIfChanged = (bUseContactSpecific) ? (db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG_FILE_CONDITION, 1) > 0) : global_settings.GetLogOnlyChangedFlag(); if (true == bOnlyIfChanged) { bAdd = ((false == bValidPrev) || (false == IsWithinAccuracy(dRate, dPrev))); } if (true == bAdd) { tstring sLogFileName = (bUseContactSpecific) ? Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_LOG_FILE, global_settings.GetLogFileName().c_str()) : global_settings.GetLogFileName(); if (true == sSymbol.empty()) { sSymbol = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_SYMBOL); } sLogFileName = GenerateLogFileName(sLogFileName, sSymbol); tstring sFormat = global_settings.GetLogFormat(); if (bUseContactSpecific) { CQuotesProviderVisitorDbSettings visitor; Accept(visitor); sFormat = Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_LOG_FILE, visitor.m_pszDefLogFileFormat); } log_to_file(this, hContact, sLogFileName, sFormat); } } if (dwMode&lmInternalHistory) { bool bAdd = true; bool bOnlyIfChanged = (bUseContactSpecific) ? (db_get_w(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_HISTORY_CONDITION, 1) > 0) : global_settings.GetHistoryOnlyChangedFlag(); if (true == bOnlyIfChanged) { bAdd = ((false == bValidPrev) || (false == IsWithinAccuracy(dRate, dPrev))); } if (true == bAdd) { tstring sFormat = (bUseContactSpecific) ? Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_HISTORY, global_settings.GetHistoryFormat().c_str()) : global_settings.GetHistoryFormat(); log_to_history(this, hContact, nTime, sFormat); } } if (dwMode&lmPopup) { bool bOnlyIfChanged = (bUseContactSpecific) ? (1 == db_get_b(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_POPUP_CONDITION, 1) > 0) : global_settings.GetShowPopupIfValueChangedFlag(); if ((false == bOnlyIfChanged) || ((true == bOnlyIfChanged) && (true == bValidPrev) && (false == IsWithinAccuracy(dRate, dPrev)))) { tstring sFormat = (bUseContactSpecific) ? Quotes_DBGetStringT(hContact, QUOTES_PROTOCOL_NAME, DB_STR_QUOTE_FORMAT_POPUP, global_settings.GetPopupFormat().c_str()) : global_settings.GetPopupFormat(); CPopupSettings ps = *(global_settings.GetPopupSettingsPtr()); ps.InitForContact(hContact); show_popup(this, hContact, tendency, sFormat, ps); } } SetContactStatus(hContact, ID_STATUS_ONLINE); }
bool show_popup(const IQuotesProvider* pProvider, MCONTACT hContact, const CTendency& tendency, const tstring& rsFormat, const CPopupSettings& ps) { if (!ServiceExists(MS_POPUP_ADDPOPUPT)) return false; POPUPDATAT ppd; memset(&ppd, 0, sizeof(ppd)); ppd.lchContact = hContact; if (tendency.IsValid()) { CTendency::EResult nComparison = tendency.Compare(); if (CTendency::NotChanged == nComparison) ppd.lchIcon = Quotes_LoadIconEx(IDI_ICON_NOTCHANGED); else if (CTendency::Up == nComparison) ppd.lchIcon = Quotes_LoadIconEx(IDI_ICON_UP); else if (CTendency::Down == nComparison) ppd.lchIcon = Quotes_LoadIconEx(IDI_ICON_DOWN); } CQuotesProviderVisitorFormater visitor(hContact, _T('s'), 0); pProvider->Accept(visitor); const tstring& sTitle = visitor.GetResult(); mir_tstrncpy(ppd.lptzContactName, sTitle.c_str(), MAX_CONTACTNAME); { ptrT ss(variables_parsedup((TCHAR*)rsFormat.c_str(), 0, hContact)); tstring sText = format_rate(pProvider, hContact, tstring(ss)); mir_tstrncpy(ppd.lptzText, sText.c_str(), MAX_SECONDLINE); } if (CPopupSettings::colourDefault == ps.GetColourMode()) { ppd.colorText = CPopupSettings::GetDefColourText(); ppd.colorBack = CPopupSettings::GetDefColourBk(); } else { ppd.colorText = ps.GetColourText(); ppd.colorBack = ps.GetColourBk(); } switch (ps.GetDelayMode()) { default: assert(!"Unknown popup delay mode"); case CPopupSettings::delayFromPopup: ppd.iSeconds = 0; break; case CPopupSettings::delayPermanent: ppd.iSeconds = -1; break; case CPopupSettings::delayCustom: ppd.iSeconds = ps.GetDelayTimeout(); break; } LPARAM lp = 0; if (false == ps.GetHistoryFlag()) lp |= 0x08; return (0 == CallService(MS_POPUP_ADDPOPUPT, reinterpret_cast<WPARAM>(&ppd), lp)); }