/* IEView Plugin for Miranda IM Copyright (C) 2005-2010 Piotr Piastucki This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "ieview_common.h" // srmm stuff #define SMF_LOG_SHOWNICK 1 #define SMF_LOG_SHOWTIME 2 #define SMF_LOG_SHOWDATES 4 #define SMF_LOG_SHOWICONS 8 #define HPPMOD "HistoryPlusPlus" #define SRMSGSET_SHOWICONS "ShowIcons" #define FONTF_BOLD 1 #define FONTF_ITALIC 2 #define FONTF_UNDERLINE 4 #define DIV_FONT_NUM 7 static const char *divClassNames[] = { ".divMessageOut", ".divMessageIn", ".divFileOut", ".divFileIn", ".divUrlOut", ".divUrlIn", ".divSystem" }; static const char *dbDivSettingNames[] = { "OutMes", "IncMes", "OutFil", "IncFil", "OutUrl", "IncUrl", "Added" }; #define SPAN_FONT_NUM 4 static const char *spanClassNames[] = { ".nameOut", ".nameIn", ".timeOut", ".timeIn", }; static const char *dbSpanSettingNames[] = { "Profile", "Contact", "ProfileDate", "ContactDate", }; HistoryHTMLBuilder::HistoryHTMLBuilder() { setLastEventType(-1); setLastEventTime(time(NULL)); startedTime = time(NULL); } bool HistoryHTMLBuilder::isDbEventShown(DBEVENTINFO * dbei) { switch (dbei->eventType) { case EVENTTYPE_MESSAGE: return 1; default: return Utils::DbEventIsForHistory(dbei); } } char *HistoryHTMLBuilder::timestampToString(time_t check) { static char szResult[512]; char str[80]; DBTIMETOSTRING dbtts; dbtts.cbDest = 70; dbtts.szDest = str; szResult[0] = '\0'; dbtts.szFormat = (char *)"d t"; CallService(MS_DB_TIME_TIMESTAMPTOSTRING, check, (LPARAM)& dbtts); strncat(szResult, str, SIZEOF(szResult) - mir_strlen(szResult)); mir_strncpy(szResult, ptrA(mir_utf8encode(szResult)), 500); return szResult; } void HistoryHTMLBuilder::loadMsgDlgFont(const char *dbSetting, LOGFONTA * lf, COLORREF * colour, COLORREF * bkgColour) { char str[128]; int style; DBVARIANT dbv; if (bkgColour) { mir_snprintf(str, SIZEOF(str), "Back.%s", dbSetting); *bkgColour = db_get_dw(NULL, HPPMOD, str, 0xFFFFFF); } if (colour) { mir_snprintf(str, SIZEOF(str), "Font.%s.Color", dbSetting); *colour = db_get_dw(NULL, HPPMOD, str, 0x000000); } if (lf) { mir_snprintf(str, SIZEOF(str), "Font.%s.Size", dbSetting); lf->lfHeight = (char)db_get_b(NULL, HPPMOD, str, 10); lf->lfWidth = 0; lf->lfEscapement = 0; lf->lfOrientation = 0; mir_snprintf(str, SIZEOF(str), "Font.%s.Style.Bold", dbSetting); style = db_get_b(NULL, HPPMOD, str, 0); lf->lfWeight = style & FONTF_BOLD ? FW_BOLD : FW_NORMAL; mir_snprintf(str, SIZEOF(str), "Font.%s.Style.Italic", dbSetting); style = db_get_b(NULL, HPPMOD, str, 0) << 1; lf->lfItalic = style & FONTF_ITALIC ? 1 : 0; lf->lfUnderline = style & FONTF_UNDERLINE ? 1 : 0; lf->lfStrikeOut = 0; mir_snprintf(str, SIZEOF(str), "Font.%s.Charset", dbSetting); lf->lfCharSet = db_get_b(NULL, HPPMOD, str, DEFAULT_CHARSET); lf->lfOutPrecision = OUT_DEFAULT_PRECIS; lf->lfClipPrecision = CLIP_DEFAULT_PRECIS; lf->lfQuality = DEFAULT_QUALITY; lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; mir_snprintf(str, SIZEOF(str), "Font.%s.Name", dbSetting); if (db_get(NULL, HPPMOD, str, &dbv)) mir_strcpy(lf->lfFaceName, "Verdana"); else { mir_strncpy(lf->lfFaceName, dbv.pszVal, sizeof(lf->lfFaceName)); db_free(&dbv); } } } const char *HistoryHTMLBuilder::getTemplateFilename(ProtocolSettings * protoSettings) { return protoSettings->getHistoryTemplateFilename(); } int HistoryHTMLBuilder::getFlags(ProtocolSettings * protoSettings) { return protoSettings->getHistoryFlags(); } void HistoryHTMLBuilder::buildHead(IEView *view, IEVIEWEVENT *event) { LOGFONTA lf; int i; COLORREF color, bkgColor; ProtocolSettings *protoSettings = getHistoryProtocolSettings(event->hContact); if (protoSettings == NULL) return; if (protoSettings->getHistoryMode() == Options::MODE_TEMPLATE) { buildHeadTemplate(view, event, protoSettings); return; } CMStringA str; if (protoSettings->getHistoryMode() == Options::MODE_CSS) { const char *externalCSS = protoSettings->getHistoryCssFilename(); str.AppendFormat("
\n", externalCSS); } else { str.Append(""); str.Append("\n"); } if (!str.IsEmpty()) view->write(str); setLastEventType(-1); } void HistoryHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event) { DWORD dwFlags = db_get_b(NULL, HPPMOD, SRMSGSET_SHOWICONS, 0) ? SMF_LOG_SHOWICONS : 0; ptrA szRealProto(getRealProto(event->hContact)); IEVIEWEVENTDATA* eventData = event->eventData; for (int eventIdx = 0; eventData != NULL && (eventIdx < event->count || event->count == -1); eventData = eventData->next, eventIdx++) { CMStringA str; bool isSent = (eventData->dwFlags & IEEDF_SENT) != 0; if (eventData->iType == IEED_EVENT_MESSAGE || eventData->iType == IEED_EVENT_STATUSCHANGE || eventData->iType == IEED_EVENT_URL || eventData->iType == IEED_EVENT_FILE) { ptrA szName, szText; if (eventData->dwFlags & IEEDF_UNICODE_NICK) szName = encodeUTF8(event->hContact, szRealProto, eventData->pszNickW, ENF_NAMESMILEYS, true); else szName = encodeUTF8(event->hContact, szRealProto, eventData->pszNick, ENF_NAMESMILEYS, true); if (eventData->dwFlags & IEEDF_UNICODE_TEXT) szText = encodeUTF8(event->hContact, szRealProto, eventData->pszTextW, eventData->iType == IEED_EVENT_MESSAGE ? ENF_ALL : 0, isSent); else szText = encodeUTF8(event->hContact, szRealProto, eventData->pszText, event->codepage, eventData->iType == IEED_EVENT_MESSAGE ? ENF_ALL : 0, isSent); /* History++-specific formatting */ const char *iconFile = NULL; switch (eventData->iType) { case IEED_EVENT_SYSTEM: str.AppendFormat("