/* 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_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(NULL)); startedTime = time(NULL); } bool ScriverHTMLBuilder::isDbEventShown(DBEVENTINFO * dbei) { switch (dbei->eventType) { case EVENTTYPE_MESSAGE: return 1; case EVENTTYPE_STATUSCHANGE: // if (dbei->flags & DBEF_READ) return 0; return 1; case EVENTTYPE_URL: return 1; case EVENTTYPE_FILE: return 1; } return 0; } void ScriverHTMLBuilder::loadMsgDlgFont(int i, LOGFONTA * lf, COLORREF * colour) { char str[32]; int style; DBVARIANT dbv; if (colour) { mir_snprintf(str, SIZEOF(str), "SRMFont%dCol", i); *colour = db_get_dw(NULL, SRMMMOD, str, 0x000000); } if (lf) { mir_snprintf(str, SIZEOF(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, SIZEOF(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, SIZEOF(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, SIZEOF(str), "SRMFont%d", i); if (db_get(NULL, SRMMMOD, str, &dbv)) lstrcpyA(lf->lfFaceName, "Verdana"); else { lstrcpynA(lf->lfFaceName, dbv.pszVal, sizeof(lf->lfFaceName)); db_free(&dbv); } } } char *ScriverHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mode) { static char szResult[512]; char str[80]; char format[20]; DBTIMETOSTRING dbtts; szResult[0] = '\0'; format[0] = '\0'; dbtts.cbDest = 70; dbtts.szDest = str; dbtts.szFormat = format; if ((mode == 0 || mode == 1) && (dwFlags & SMF_LOG_SHOWDATE)) { struct tm tm_now, tm_today; time_t now = time(NULL); 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) { strcpy(szResult, Translate("Today")); if (mode == 0) { strcat(szResult, ","); } } else if(dwFlags & SMF_LOG_USERELATIVEDATE && check > (today - 86400)) { strcpy(szResult, Translate("Yesterday")); if (mode == 0) { strcat(szResult, ","); } } else { if(dwFlags & SMF_LOG_USELONGDATE) strcpy(format, "D"); else strcpy(format, "d"); } } if (mode == 0 || mode == 2) { if (mode == 0 && (dwFlags & SMF_LOG_SHOWDATE)) { strcat(format, " "); } strcat(format, (dwFlags & SMF_LOG_SHOWSECONDS) ? "s" : "t"); } if (format[0] != '\0') { // CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, check, (LPARAM) & dbtts); CallService(MS_DB_TIME_TIMESTAMPTOSTRING, check, (LPARAM) & dbtts); //_tcsncat(szResult, str, 500); strncat(szResult, str, 500); } lstrcpynA(szResult, ptrA(mir_utf8encode(szResult)), 500); return szResult; } void ScriverHTMLBuilder::buildHead(IEView *view, IEVIEWEVENT *event) { LOGFONTA lf; COLORREF color; char *output = NULL; int outputSize; ProtocolSettings *protoSettings = getSRMMProtocolSettings(event->hContact); if (protoSettings == NULL) { return; } if (protoSettings->getSRMMMode() == Options::MODE_TEMPLATE) { buildHeadTemplate(view, event, protoSettings); return; } if (protoSettings->getSRMMMode() == Options::MODE_CSS) { const char *externalCSS = protoSettings->getSRMMCssFilename(); if (strncmp(externalCSS, "http://", 7)) { Utils::appendText(&output, &outputSize, "
\n", externalCSS); } else { Utils::appendText(&output, &outputSize, "\n", externalCSS); } } else { HDC hdc = GetDC(NULL); int logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); Utils::appendText(&output, &outputSize, ""); Utils::appendText(&output, &outputSize, "\n"); } if (output != NULL) { view->write(output); free(output); } 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!=NULL && (eventIdx < event->count || event->count==-1); eventData = eventData->next, eventIdx++) { const char *className = ""; int outputSize; char *output; output = NULL; 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 ? isSent ? "divNoticeRTL" : "divNoticeRTL" : isSent ? "divNotice" : "divNotice"; } Utils::appendText(&output, &outputSize, "