From afc1b562fdca819b1c24b0efc094f256bd45267a Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Thu, 21 Apr 2016 18:38:42 +0000 Subject: IEView: minor cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@16734 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/IEView/src/HTMLBuilder.cpp | 27 +++++++++++---------------- plugins/IEView/src/HistoryHTMLBuilder.h | 1 - plugins/IEView/src/IEView.cpp | 16 +++++++--------- plugins/IEView/src/IEView.h | 2 +- plugins/IEView/src/ScriverHTMLBuilder.h | 1 - plugins/IEView/src/TabSRMMHTMLBuilder.h | 1 - plugins/IEView/src/TemplateHTMLBuilder.cpp | 20 ++++++++++++-------- plugins/IEView/src/stdafx.h | 10 ++++++++++ 8 files changed, 41 insertions(+), 37 deletions(-) diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp index 8a84367ff5..9001a14640 100644 --- a/plugins/IEView/src/HTMLBuilder.cpp +++ b/plugins/IEView/src/HTMLBuilder.cpp @@ -175,29 +175,24 @@ void HTMLBuilder::setLastEventTime(DWORD t) bool HTMLBuilder::isSameDate(time_t time1, time_t time2) { - struct tm tm_t1, tm_t2; - tm_t1 = *localtime((time_t *)(&time1)); - tm_t2 = *localtime((time_t *)(&time2)); - if (tm_t1.tm_year == tm_t2.tm_year && tm_t1.tm_mon == tm_t2.tm_mon - && tm_t1.tm_mday == tm_t2.tm_mday) { - return true; - } - return false; + tm *tm_t1 = localtime(&time1), *tm_t2 = localtime(&time2); + return tm_t1->tm_year == tm_t2->tm_year && tm_t1->tm_mon == tm_t2->tm_mon && tm_t1->tm_mday == tm_t2->tm_mday; + } void HTMLBuilder::getUINs(MCONTACT hContact, char *&uinIn, char *&uinOut) { - CONTACTINFO ci; - char buf[128]; - char *szProto; + CONTACTINFO ci = { 0 }; + char buf[128] = { 0 }; + const char *szProto = GetContactProto(hContact); + hContact = getRealContact(hContact); - szProto = getProto(hContact); - memset(&ci, 0, sizeof(ci)); + ci.cbSize = sizeof(ci); ci.hContact = hContact; - ci.szProto = szProto; + ci.szProto = const_cast(szProto); ci.dwFlag = CNF_UNIQUEID; - buf[0] = 0; + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) { switch (ci.type) { case CNFT_ASCIIZ: @@ -211,6 +206,7 @@ void HTMLBuilder::getUINs(MCONTACT hContact, char *&uinIn, char *&uinOut) } uinIn = mir_utf8encode(buf); ci.hContact = NULL; + buf[0] = 0; if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) { switch (ci.type) { @@ -224,7 +220,6 @@ void HTMLBuilder::getUINs(MCONTACT hContact, char *&uinIn, char *&uinOut) } } uinOut = mir_utf8encode(buf); - mir_free(szProto); } wchar_t *HTMLBuilder::getContactName(MCONTACT hContact, const char *szProto) diff --git a/plugins/IEView/src/HistoryHTMLBuilder.h b/plugins/IEView/src/HistoryHTMLBuilder.h index df00dc7094..0a7b5386b0 100644 --- a/plugins/IEView/src/HistoryHTMLBuilder.h +++ b/plugins/IEView/src/HistoryHTMLBuilder.h @@ -30,7 +30,6 @@ class HistoryHTMLBuilder :public TemplateHTMLBuilder protected: void loadMsgDlgFont(const char *, LOGFONTA * lf, COLORREF * colour, COLORREF * bkgColour); char *timestampToString(time_t check); - DWORD startedTime; bool isDbEventShown(DBEVENTINFO * dbei); void appendEventNonTemplate(IEView *, IEVIEWEVENT *event); const char *getTemplateFilename(ProtocolSettings *); diff --git a/plugins/IEView/src/IEView.cpp b/plugins/IEView/src/IEView.cpp index 87a7350275..870924bab5 100644 --- a/plugins/IEView/src/IEView.cpp +++ b/plugins/IEView/src/IEView.cpp @@ -98,7 +98,7 @@ static LRESULT CALLBACK IEViewWindowProcedure(HWND hwnd, UINT message, WPARAM wP return DefWindowProc(hwnd, message, wParam, lParam); } -IEViewSink::IEViewSink(IEView *smptr) +IEViewSink::IEViewSink(IEView *smptr) : m_cRef(1) { ieWindow = smptr; } @@ -894,12 +894,12 @@ void IEView::writef(const char *fmt, ...) void IEView::navigate(const char *url) { - pWebBrowser->Navigate(_A2T(url), NULL, NULL, NULL, NULL); + pWebBrowser->Navigate(BSTR_PTR(_A2T(url)), NULL, NULL, NULL, NULL); } void IEView::navigate(const wchar_t *url) { - pWebBrowser->Navigate((WCHAR *)url, NULL, NULL, NULL, NULL); + pWebBrowser->Navigate(BSTR_PTR(url), NULL, NULL, NULL, NULL); } void IEView::documentClose() @@ -946,7 +946,7 @@ void IEView::clear(IEVIEWEVENT *event) { CComPtr document = getDocument(); if (document == NULL) { - pWebBrowser->Navigate(L"about:blank", NULL, NULL, NULL, NULL); + pWebBrowser->Navigate(BSTR_PTR(L"about:blank"), NULL, NULL, NULL, NULL); HRESULT hr = S_OK; CComPtr doc2; while ((doc2 == NULL) && (hr == S_OK)) { @@ -967,7 +967,7 @@ void IEView::clear(IEVIEWEVENT *event) VariantInit(&open_replace); CComPtr open_window; - document->open(SysAllocString(L"text/html"), open_name, open_features, open_replace, &open_window); + document->open(BSTR_PTR(L"text/html"), open_name, open_features, open_replace, &open_window); } if (builder != NULL) builder->clear(this, event); @@ -1062,7 +1062,7 @@ WCHAR* IEView::getHrefFromAnchor(CComPtr element) if (FAILED(element.QueryInterface(&pAnchor))) { VARIANT variant; WCHAR *url = NULL; - if (SUCCEEDED(element->getAttribute(L"href", 2, &variant)) && variant.vt == VT_BSTR) { + if (SUCCEEDED(element->getAttribute(BSTR_PTR(L"href"), 2, &variant)) && variant.vt == VT_BSTR) { url = mir_wstrdup(variant.bstrVal); ::SysFreeString(variant.bstrVal); } @@ -1126,14 +1126,12 @@ void IEView::saveDocument() if (document == NULL) return; - BSTR bCmd = SysAllocString(L"SaveAs"); VARIANT vValue; vValue.vt = VT_BOOL; vValue.boolVal = TRUE; VARIANT_BOOL vb; - document->execCommand(bCmd, VARIANT_FALSE, vValue, &vb); - ::SysFreeString(bCmd); + document->execCommand(BSTR_PTR(L"SaveAs"), VARIANT_FALSE, vValue, &vb); } void IEView::navigate(IEVIEWNAVIGATE *nav) diff --git a/plugins/IEView/src/IEView.h b/plugins/IEView/src/IEView.h index 7e43886922..f57dff663b 100644 --- a/plugins/IEView/src/IEView.h +++ b/plugins/IEView/src/IEView.h @@ -508,7 +508,7 @@ private: STDMETHOD(SetZoneMapping)(DWORD dwZone, LPCWSTR lpszPattern, DWORD dwFlags); STDMETHOD(GetZoneMappings)(DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags); - VARIANT IEView::CallJScript(const CMString strFunc, size_t nPCount, const CMString strArgs, ...); + VARIANT CallJScript(const CMString strFunc, size_t nPCount, const CMString strArgs, ...); IHTMLDocument2 *getDocument(); WCHAR* getHrefFromAnchor(CComPtr element); diff --git a/plugins/IEView/src/ScriverHTMLBuilder.h b/plugins/IEView/src/ScriverHTMLBuilder.h index 2d3a8bca51..289cda6cf4 100644 --- a/plugins/IEView/src/ScriverHTMLBuilder.h +++ b/plugins/IEView/src/ScriverHTMLBuilder.h @@ -30,7 +30,6 @@ class ScriverHTMLBuilder :public TemplateHTMLBuilder protected: void loadMsgDlgFont(int i, LOGFONTA * lf, COLORREF * colour); char *timestampToString(DWORD dwFlags, time_t check, int groupStart); - DWORD startedTime; bool isDbEventShown(DBEVENTINFO * dbei); void appendEventNonTemplate(IEView *, IEVIEWEVENT *event); public: diff --git a/plugins/IEView/src/TabSRMMHTMLBuilder.h b/plugins/IEView/src/TabSRMMHTMLBuilder.h index f707abe42d..fcca7d1053 100644 --- a/plugins/IEView/src/TabSRMMHTMLBuilder.h +++ b/plugins/IEView/src/TabSRMMHTMLBuilder.h @@ -30,7 +30,6 @@ class TabSRMMHTMLBuilder :public TemplateHTMLBuilder protected: virtual void loadMsgDlgFont(int i, LOGFONTA * lf, COLORREF * colour); char *timestampToString(DWORD dwFlags, time_t check, int isGroupBreak); - time_t startedTime; time_t getStartedTime(); virtual bool isDbEventShown(DWORD dwFlags, DBEVENTINFO * dbei); bool isDbEventShown(DBEVENTINFO * dbei); diff --git a/plugins/IEView/src/TemplateHTMLBuilder.cpp b/plugins/IEView/src/TemplateHTMLBuilder.cpp index f61646820c..ad7271e9a8 100644 --- a/plugins/IEView/src/TemplateHTMLBuilder.cpp +++ b/plugins/IEView/src/TemplateHTMLBuilder.cpp @@ -24,8 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. TemplateHTMLBuilder::TemplateHTMLBuilder() { iLastEventType = -1; - startedTime = time(NULL); - lastEventTime = time(NULL); + startedTime = lastEventTime = time(NULL); groupTemplate = NULL; } @@ -114,7 +113,7 @@ void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, Pr return; DBVARIANT dbv; - char tempBase[1024]; + char tempStr[1024]; char *szNameIn = NULL; char *szNameOut = NULL; @@ -127,12 +126,13 @@ void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, Pr MCONTACT hRealContact = getRealContact(event->hContact); char *szRealProto = getProto(hRealContact); char *szProto = getProto(event->pszProto, event->hContact); - tempBase[0] = '\0'; TemplateMap *tmpm = getTemplateMap(protoSettings); if (tmpm == NULL) return; + char tempBase[1024] = { 0 }; + mir_strcpy(tempBase, "file://"); mir_strncat(tempBase, tmpm->getFilename(), _countof(tempBase) - mir_strlen(tempBase)); char *pathrun = tempBase + mir_strlen(tempBase); @@ -285,6 +285,7 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, char tempBase[1024]; char tempStr[1024]; char szCID[32]; + char *szNameIn = NULL; char *szNameOut = NULL; char *szUIN = NULL; @@ -306,10 +307,13 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, if (tmpm != NULL) { mir_strcpy(tempBase, "file://"); mir_strcat(tempBase, tmpm->getFilename()); - char* pathrun = tempBase + mir_strlen(tempBase); - while ((*pathrun != '\\' && *pathrun != '/') && (pathrun > tempBase)) pathrun--; - pathrun++; - *pathrun = '\0'; + + char* pathrun = nullptr; + if (pathrun = strrchr(tempBase, '\\')) + ++pathrun = '\0'; + else if (pathrun = strrchr(tempBase, '/')) + ++pathrun = '\0'; + isGrouping = tmpm->isGrouping(); } char *szBase = mir_utf8encode(tempBase); diff --git a/plugins/IEView/src/stdafx.h b/plugins/IEView/src/stdafx.h index 51e408cf01..8ec7481c40 100644 --- a/plugins/IEView/src/stdafx.h +++ b/plugins/IEView/src/stdafx.h @@ -79,4 +79,14 @@ extern IEView *debugView; extern char *workingDirUtf8; extern HANDLE hHookOptionsChanged; +class BSTR_PTR +{ + BSTR _data; +public: + BSTR_PTR(const wchar_t *src) : _data(SysAllocString(src)) {} + ~BSTR_PTR() { SysFreeString(_data); } + size_t length() { return SysStringLen(_data); } + operator BSTR () { return _data; } +}; + #endif -- cgit v1.2.3