/* 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 "stdafx.h" // srmm stuff #define SMF_LOG_SHOWNICK 1 #define SMF_LOG_SHOWTIME 2 #define SMF_LOG_SHOWDATE 4 #define SMF_LOG_SHOWICONS 8 #define SMF_LOG_SHOWSTATUSCHANGES 16 #define SMF_LOG_SHOWSECONDS 32 #define SMF_LOG_USERELATIVEDATE 64 #define SMF_LOG_USELONGDATE 128 #define SMF_LOG_GROUPMESSAGES 256 #define SMF_LOG_MARKFOLLOWUPS 512 #define SMF_LOG_MSGONNEWLINE 1024 #define SMF_LOG_DRAWLINES 2048 #define SRMMMOD "SRMM" #define SRMSGSET_SHOWLOGICONS "ShowLogIcon" #define SRMSGSET_HIDENAMES "HideNames" #define SRMSGSET_SHOWTIME "ShowTime" #define SRMSGSET_SHOWDATE "ShowDate" #define SRMSGSET_SHOWSTATUSCHANGES "ShowStatusChanges" #define SRMSGSET_SHOWSECONDS "ShowSeconds" #define SRMSGSET_USERELATIVEDATE "UseRelativeDate" #define SRMSGSET_USELONGDATE "UseLongDate" #define SRMSGSET_GROUPMESSAGES "GroupMessages" #define SRMSGSET_MARKFOLLOWUPS "MarkFollowUps" #define SRMSGSET_MESSAGEONNEWLINE "MessageOnNewLine" #define SRMSGSET_DRAWLINES "DrawLines" #define FONTF_BOLD 1 #define FONTF_ITALIC 2 #define FONTF_UNDERLINE 4 #define FONT_NUM 10 static const char *classNames[] = { ".messageOut", ".messageIn", ".nameOut", ".timeOut", ".colonOut", ".nameIn", ".timeIn", ".colonIn", ".inputArea", ".notices" }; ScriverHTMLBuilder::ScriverHTMLBuilder() { setLastEventType(-1); setLastEventTime(time(nullptr)); startedTime = time(nullptr); } bool ScriverHTMLBuilder::isDbEventShown(DBEVENTINFO * dbei) { switch (dbei->eventType) { case EVENTTYPE_MESSAGE: return 1; case EVENTTYPE_URL: return 1; case EVENTTYPE_FILE: return 1; default: return Utils::DbEventIsForMsgWindow(dbei); } } void ScriverHTMLBuilder::loadMsgDlgFont(int i, LOGFONTA * lf, COLORREF * colour) { char str[32]; int style; DBVARIANT dbv; if (colour) { mir_snprintf(str, "SRMFont%dCol", i); *colour = db_get_dw(NULL, SRMMMOD, str, 0x000000); } if (lf) { mir_snprintf(str, "SRMFont%dSize", i); lf->lfHeight = (char)db_get_b(NULL, SRMMMOD, str, 10); lf->lfHeight = abs(lf->lfHeight); lf->lfWidth = 0; lf->lfEscapement = 0; lf->lfOrientation = 0; mir_snprintf(str, "SRMFont%dSty", i); style = db_get_b(NULL, SRMMMOD, str, 0); lf->lfWeight = style & FONTF_BOLD ? FW_BOLD : FW_NORMAL; lf->lfItalic = style & FONTF_ITALIC ? 1 : 0; lf->lfUnderline = style & FONTF_UNDERLINE ? 1 : 0; lf->lfStrikeOut = 0; mir_snprintf(str, "SRMFont%dSet", i); lf->lfCharSet = db_get_b(NULL, SRMMMOD, 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, "SRMFont%d", i); if (db_get(NULL, SRMMMOD, str, &dbv)) mir_strcpy(lf->lfFaceName, "Verdana"); else { mir_strncpy(lf->lfFaceName, dbv.pszVal, sizeof(lf->lfFaceName)); db_free(&dbv); } } } char* ScriverHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mode) { static char szResult[512]; szResult[0] = '\0'; char str[80]; char format[20]; format[0] = '\0'; if ((mode == 0 || mode == 1) && (dwFlags & SMF_LOG_SHOWDATE)) { struct tm tm_now, tm_today; time_t now = time(nullptr); time_t today; tm_now = *localtime(&now); tm_today = tm_now; tm_today.tm_hour = tm_today.tm_min = tm_today.tm_sec = 0; today = mktime(&tm_today); if (dwFlags & SMF_LOG_USERELATIVEDATE && check >= today) { strncpy(szResult, Translate("Today"), _countof(szResult)-1); if (mode == 0) { mir_strcat(szResult, ","); } } else if (dwFlags & SMF_LOG_USERELATIVEDATE && check > (today - 86400)) { strncpy(szResult, Translate("Yesterday"), _countof(szResult)-1); if (mode == 0) { mir_strcat(szResult, ","); } } else { if (dwFlags & SMF_LOG_USELONGDATE) mir_strcpy(format, "D"); else mir_strcpy(format, "d"); } } if (mode == 0 || mode == 2) { if (mode == 0 && (dwFlags & SMF_LOG_SHOWDATE)) mir_strcat(format, " "); mir_strcat(format, (dwFlags & SMF_LOG_SHOWSECONDS) ? "s" : "t"); } if (format[0] != '\0') { TimeZone_ToString(check, format, str, _countof(str)); mir_strncat(szResult, str, _countof(szResult) - mir_strlen(szResult)); } mir_strncpy(szResult, ptrA(mir_utf8encode(szResult)), 500); return szResult; } void ScriverHTMLBuilder::buildHead(IEView *view, IEVIEWEVENT *event) { LOGFONTA lf; COLORREF color; ProtocolSettings *protoSettings = getSRMMProtocolSettings(event->hContact); if (protoSettings == nullptr) return; if (protoSettings->getSRMMMode() == Options::MODE_TEMPLATE) { buildHeadTemplate(view, event, protoSettings); return; } CMStringA str; if (protoSettings->getSRMMMode() == Options::MODE_CSS) { const char *externalCSS = protoSettings->getSRMMCssFilename(); if (strncmp(externalCSS, "http://", 7)) str.AppendFormat("
\n", externalCSS); else str.AppendFormat("\n", externalCSS); } else { HDC hdc = GetDC(nullptr); int logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(nullptr, hdc); str.Append(""); str.Append("\n"); } if (!str.IsEmpty()) view->write(str); setLastEventType(-1); } void ScriverHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event) { bool showColon; DWORD dwFlags = db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWTIME, 0) ? SMF_LOG_SHOWTIME : 0; dwFlags |= !db_get_b(NULL, SRMMMOD, SRMSGSET_HIDENAMES, 0) ? SMF_LOG_SHOWNICK : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWDATE, 0) ? SMF_LOG_SHOWDATE : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWLOGICONS, 0) ? SMF_LOG_SHOWICONS : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWSTATUSCHANGES, 0) ? SMF_LOG_SHOWSTATUSCHANGES : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWSECONDS, 0) ? SMF_LOG_SHOWSECONDS : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_USERELATIVEDATE, 0) ? SMF_LOG_USERELATIVEDATE : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_USELONGDATE, 0) ? SMF_LOG_USELONGDATE : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_GROUPMESSAGES, 0) ? SMF_LOG_GROUPMESSAGES : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_MARKFOLLOWUPS, 0) ? SMF_LOG_MARKFOLLOWUPS : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_MESSAGEONNEWLINE, 0) ? SMF_LOG_MSGONNEWLINE : 0; dwFlags |= db_get_b(NULL, SRMMMOD, SRMSGSET_DRAWLINES, 0) ? SMF_LOG_DRAWLINES : 0; ptrA szRealProto(getRealProto(event->hContact)); IEVIEWEVENTDATA* eventData = event->eventData; for (int eventIdx = 0; eventData != nullptr && (eventIdx < event->count || event->count == -1); eventData = eventData->next, eventIdx++) { const char *className = ""; bool isSent = (eventData->dwFlags & IEEDF_SENT) != 0; bool isRTL = (eventData->dwFlags & IEEDF_RTL) != 0; showColon = false; if (eventData->iType == IEED_EVENT_MESSAGE || eventData->iType == IEED_EVENT_STATUSCHANGE || eventData->iType == IEED_EVENT_URL || eventData->iType == IEED_EVENT_FILE) { int isGroupBreak = TRUE; if ((dwFlags & SMF_LOG_GROUPMESSAGES) && eventData->dwFlags == LOWORD(getLastEventType()) && eventData->iType == IEED_EVENT_MESSAGE && HIWORD(getLastEventType()) == IEED_EVENT_MESSAGE && (isSameDate(eventData->time, getLastEventTime())) && (((eventData->time < startedTime) == (getLastEventTime() < startedTime)) || !(eventData->dwFlags & IEEDF_READ))) { isGroupBreak = FALSE; } 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); /* Scriver-specific formatting */ if ((dwFlags & SMF_LOG_DRAWLINES) && isGroupBreak && getLastEventType() != -1) { if (eventData->iType == IEED_EVENT_MESSAGE) className = isRTL ? isSent ? "divOutGridRTL" : "divInGridRTL" : isSent ? "divOutGrid" : "divInGrid"; else className = isRTL ? isSent ? "divNoticeGridRTL" : "divNoticeGridRTL" : isSent ? "divNoticeGrid" : "divNoticeGrid"; } else { if (eventData->iType == IEED_EVENT_MESSAGE) className = isRTL ? (isSent ? "divOutRTL" : "divInRTL") : (isSent ? "divOut" : "divIn"); else className = isRTL ? "divNoticeRTL" : (isSent ? "divNotice" : "divNotice"); } CMStringA str; str.AppendFormat("