From 15855fa84a09fd1fd486d357c38db0f2bd181e74 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 4 Mar 2014 23:23:45 +0000 Subject: HistoryStats compiles ok now git-svn-id: http://svn.miranda-ng.org/main/trunk@8399 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/HistoryStats/src/column_chatduration.cpp | 257 +++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 plugins/HistoryStats/src/column_chatduration.cpp (limited to 'plugins/HistoryStats/src/column_chatduration.cpp') diff --git a/plugins/HistoryStats/src/column_chatduration.cpp b/plugins/HistoryStats/src/column_chatduration.cpp new file mode 100644 index 0000000000..b21dc451b4 --- /dev/null +++ b/plugins/HistoryStats/src/column_chatduration.cpp @@ -0,0 +1,257 @@ +#include "_globals.h" +#include "column_chatduration.h" + +/* + * ColChatDuration + */ + +ColChatDuration::ColChatDuration() + : m_nVisMode(3), m_bGraph(true), m_bDetail(true), + m_hVisMode(NULL), m_hGraph(NULL), m_hDetail(NULL) +{ +} + +void ColChatDuration::impl_copyConfig(const Column* pSource) +{ + const ColChatDuration& src = *reinterpret_cast(pSource); + + m_nVisMode = src.m_nVisMode; + m_bGraph = src.m_bGraph; + m_bDetail = src.m_bDetail; +} + +void ColChatDuration::impl_configRead(const SettingsTree& settings) +{ + m_nVisMode = settings.readIntRanged(con::KeyVisMode, 3, 0, 3); + m_bGraph = settings.readBool (con::KeyGraph , true); + m_bDetail = settings.readBool (con::KeyDetail , true); +} + +void ColChatDuration::impl_configWrite(SettingsTree& settings) const +{ + settings.writeInt (con::KeyVisMode, m_nVisMode); + settings.writeBool(con::KeyGraph , m_bGraph ); + settings.writeBool(con::KeyDetail , m_bDetail ); +} + +void ColChatDuration::impl_configToUI(OptionsCtrl& Opt, OptionsCtrl::Item hGroup) +{ + OptionsCtrl::Item hTemp; + + /**/hTemp = Opt.insertGroup(hGroup, i18n(muT("Chat duration type"))); + /**/ m_hVisMode = Opt.insertRadio(hTemp, NULL, i18n(muT("Minimum"))); + /**/ Opt.insertRadio(hTemp, m_hVisMode, i18n(muT("Average"))); + /**/ Opt.insertRadio(hTemp, m_hVisMode, i18n(muT("Maximum"))); + /**/ Opt.insertRadio(hTemp, m_hVisMode, i18n(muT("Total (sum of all chats)"))); + /**/m_hGraph = Opt.insertCheck(hGroup, i18n(muT("Show bar graph for chat duration type"))); + /**/m_hDetail = Opt.insertCheck(hGroup, i18n(muT("Other information in tooltip"))); + + Opt.setRadioChecked(m_hVisMode, m_nVisMode); + Opt.checkItem (m_hGraph , m_bGraph ); + Opt.checkItem (m_hDetail , m_bDetail ); +} + +void ColChatDuration::impl_configFromUI(OptionsCtrl& Opt) +{ + m_nVisMode = Opt.getRadioChecked(m_hVisMode); + m_bGraph = Opt.isItemChecked (m_hGraph ); + m_bDetail = Opt.isItemChecked (m_hDetail ); +} + +Column::StyleList ColChatDuration::impl_outputGetAdditionalStyles(IDProvider& idp) +{ + StyleList l; + + if (m_bGraph) + { + m_CSS = idp.getID(); + + l.push_back(StylePair(muT("td.") + m_CSS, muT("vertical-align: middle; padding: 2px 2px 2px 2px;"))); + l.push_back(StylePair(muT("td.") + m_CSS + muT(" div.n"), muT("text-align: center;"))); + + if (!usePNG()) + { + l.push_back(StylePair(muT("div.") + m_CSS, muT("position: relative; left: 50%; margin-left: -35px; width: 70px; height: 15px; background-color: ") + utils::colorToHTML(con::ColorBarBack) + muT(";"))); + l.push_back(StylePair(muT("div.") + m_CSS + muT(" div"), muT("position: absolute; top: 0px; left: 0px; height: 15px; overflow: hidden; background-color: ") + utils::colorToHTML(con::ColorBar) + muT(";"))); + } + } + + return l; +} + +void ColChatDuration::impl_outputRenderHeader(ext::ostream& tos, int row, int rowSpan) const +{ + static const mu_text* szVisModeDesc[] = { + I18N(muT("Minimum chat duration")), + I18N(muT("Average chat duration")), + I18N(muT("Maximum chat duration")), + I18N(muT("Total chat duration")), + }; + + if (row == 1) + { + writeRowspanTD(tos, getCustomTitle(i18n(muT("Chat duration")), i18n(szVisModeDesc[m_nVisMode])) + (m_bGraph ? muT("
") : muT("")), row, 1, rowSpan); + } +} + +void ColChatDuration::impl_columnDataAfterOmit() +{ + // AFTER, i.e. contacts are trimmed to what user will see + + if (m_bGraph) + { + static DWORD (Contact::*getChatDurX[4])() const = { + &Contact::getChatDurMin, + &Contact::getChatDurAvg, + &Contact::getChatDurMax, + &Contact::getChatDurSum, + }; + + m_nMaxForGraph = 1; + + upto_each_(i, getStatistic()->countContacts()) + { + const Contact& cur = getStatistic()->getContact(i); + + if (cur.isChatDurValid()) + { + m_nMaxForGraph = max(m_nMaxForGraph, (cur.*getChatDurX[m_nVisMode])()); + } + } + + if (m_nVisMode != 3) + { + if (getStatistic()->hasOmitted() && getStatistic()->getOmitted().isChatDurValid()) + { + m_nMaxForGraph = max(m_nMaxForGraph, (getStatistic()->getOmitted().*getChatDurX[m_nVisMode])()); + } + + if (getStatistic()->hasTotals() && getStatistic()->getTotals().isChatDurValid()) + { + m_nMaxForGraph = max(m_nMaxForGraph, (getStatistic()->getTotals().*getChatDurX[m_nVisMode])()); + } + } + } +} + +void ColChatDuration::impl_outputRenderRow(ext::ostream& tos, const Contact& contact, DisplayType display) +{ + static DWORD (Contact::*getChatDurX[4])() const = { + &Contact::getChatDurMin, + &Contact::getChatDurAvg, + &Contact::getChatDurMax, + &Contact::getChatDurSum, + }; + + // begin output + if (m_bGraph) + { + tos << muT(""); + } + else + { + tos << muT("\">"); + } + + if (m_bGraph) + { + tos << muT("
") + << utils::htmlEscape(strAll[m_nVisMode]); + + if (display == asContact || m_nVisMode != 3) + { + int barW = static_cast(70.0 * (contact.*getChatDurX[m_nVisMode])() / m_nMaxForGraph); + + if (m_nVisMode != 3 && !contact.isChatDurValid()) + { + barW = 0; + } + + if (usePNG()) + { + // draw graph + Canvas canvas(70, 15); + + canvas.fillBackground(con::ColorBarBack); + + HDC hDC = canvas.beginDraw(); + + SetBkColor(hDC, con::ColorBar); + ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &utils::rect(0, 0, barW, 15), NULL, 0, NULL); + + canvas.endDraw(); + + // write PNG file + ext::string strFinalFile; + + if (getStatistic()->newFilePNG(canvas, strFinalFile)) + { + tos << muT("
"); + } + } + else + { + tos << muT("
") + << muT("
") + << muT("
"); + } + } + + tos << muT("
"); + } + else + { + tos << utils::htmlEscape(strAll[m_nVisMode]); + } + + tos << muT("") << ext::endl; +} -- cgit v1.2.3