From 931a7dc1ac0dbc7e6c1083583ced915e572f5b47 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 2 Mar 2019 12:32:44 +0300 Subject: all protocols (even virtual ones) moved to the Protocols folder --- protocols/WebView/src/main.cpp | 285 +++++++ protocols/WebView/src/resource.h | 139 +++ protocols/WebView/src/stdafx.cxx | 18 + protocols/WebView/src/stdafx.h | 36 + protocols/WebView/src/version.h | 13 + protocols/WebView/src/webview.cpp | 481 +++++++++++ protocols/WebView/src/webview.h | 254 ++++++ protocols/WebView/src/webview_alerts.cpp | 839 ++++++++++++++++++ protocols/WebView/src/webview_cleanup.cpp | 797 ++++++++++++++++++ protocols/WebView/src/webview_datawnd.cpp | 514 +++++++++++ protocols/WebView/src/webview_getdata.cpp | 511 +++++++++++ protocols/WebView/src/webview_opts.cpp | 1265 ++++++++++++++++++++++++++++ protocols/WebView/src/webview_services.cpp | 458 ++++++++++ 13 files changed, 5610 insertions(+) create mode 100644 protocols/WebView/src/main.cpp create mode 100644 protocols/WebView/src/resource.h create mode 100644 protocols/WebView/src/stdafx.cxx create mode 100644 protocols/WebView/src/stdafx.h create mode 100644 protocols/WebView/src/version.h create mode 100644 protocols/WebView/src/webview.cpp create mode 100644 protocols/WebView/src/webview.h create mode 100644 protocols/WebView/src/webview_alerts.cpp create mode 100644 protocols/WebView/src/webview_cleanup.cpp create mode 100644 protocols/WebView/src/webview_datawnd.cpp create mode 100644 protocols/WebView/src/webview_getdata.cpp create mode 100644 protocols/WebView/src/webview_opts.cpp create mode 100644 protocols/WebView/src/webview_services.cpp (limited to 'protocols/WebView/src') diff --git a/protocols/WebView/src/main.cpp b/protocols/WebView/src/main.cpp new file mode 100644 index 0000000000..d53964c0af --- /dev/null +++ b/protocols/WebView/src/main.cpp @@ -0,0 +1,285 @@ +/* + * A plugin for Miranda IM which displays web page text in a window. + * Copyright (C) 2005 Vincent Joyce. + * + * Miranda IM: the free icq client for MS Windows + * Copyright (C) 2000-2 Richard Hughes, Roland Rabien & Tristan Van de Vreede + * + * 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" +#include "webview.h" + +MWindowList hWindowList; +HNETLIBUSER hNetlibUser; +HANDLE hHookDisplayDataAlert, hHookAlertPopup, hHookAlertWPopup, hHookErrorPopup, hHookAlertOSD; + +CMPlugin g_plugin; + +static HMODULE hRichEd = nullptr; + +///////////////////////////////////////////////////////////////////////////////////////// + +PLUGININFOEX pluginInfoEx = { + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // {CD5427FB-5320-4f65-B4BF-86B7CF7B5087} + {0xcd5427fb, 0x5320, 0x4f65, {0xb4, 0xbf, 0x86, 0xb7, 0xcf, 0x7b, 0x50, 0x87}} +}; + +CMPlugin::CMPlugin() : + PLUGIN(MODULENAME, pluginInfoEx) +{ + RegisterProtocol(PROTOTYPE_PROTOCOL); + SetUniqueId("PreserveName"); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +void InitServices() +{ + CreateProtoServiceFunction(MODULENAME, PS_GETCAPS, GetCaps); + CreateProtoServiceFunction(MODULENAME, PS_GETNAME, GetName); + CreateProtoServiceFunction(MODULENAME, PS_LOADICON, BPLoadIcon); + CreateProtoServiceFunction(MODULENAME, PS_SETSTATUS, SetStatus); + CreateProtoServiceFunction(MODULENAME, PS_GETSTATUS, GetStatus); + CreateProtoServiceFunction(MODULENAME, PS_BASICSEARCH, BasicSearch); + CreateProtoServiceFunction(MODULENAME, PS_ADDTOLIST, AddToList); + CreateProtoServiceFunction(MODULENAME, PSS_GETINFO, GetInfo); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +void ChangeContactStatus(int con_stat) +{ + WORD status_code = 0; + if (con_stat == 0) + status_code = ID_STATUS_OFFLINE; + if (con_stat == 1) + status_code = ID_STATUS_ONLINE; + if (con_stat == 2) + status_code = ID_STATUS_AWAY; + if (con_stat == 3) + status_code = ID_STATUS_NA; + + for (auto &hContact : Contacts(MODULENAME)) + g_plugin.setWord(hContact, "Status", status_code); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; + +///////////////////////////////////////////////////////////////////////////////////////// + +int CMPlugin::Load() +{ + HookEvent(ME_CLIST_DOUBLECLICKED, Doubleclick); + + hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_CONTEXT)); + hRichEd = LoadLibrary(L"Msftedit.dll"); + + /*TIMERS*/ + if ((g_plugin.getDword(REFRESH_KEY, TIME) != 0)) { + timerId = SetTimer(nullptr, 0, ((g_plugin.getDword(REFRESH_KEY, TIME)) * MINUTE), timerfunc); + g_plugin.setDword(COUNTDOWN_KEY, 0); + Countdown = SetTimer(nullptr, 0, MINUTE, Countdownfunc); + } + + InitialiseGlobals(); + + // register netlib handle + char tempNdesc[50]; + mir_snprintf(tempNdesc, "%s connection settings", MODULENAME); + + NETLIBUSER nlu = {}; + nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS; + nlu.szSettingsModule = MODULENAME; + nlu.szDescriptiveName.a = tempNdesc; + hNetlibUser = Netlib_RegisterUser(&nlu); + + //protocol services + InitServices(); + + //add sound event to options + g_plugin.addSound("webviewalert", _A2W(MODULENAME), LPGENW("Alert event")); + + //value is 1 if menu is disabled + g_plugin.setByte(MENU_IS_DISABLED_KEY, 1); + + CMenuItem mi(&g_plugin); + mi.flags = CMIF_UNICODE; + if ( g_plugin.getByte(MENU_OFF, 0)) { + //value is 0 if menu is enabled + g_plugin.setByte(MENU_IS_DISABLED_KEY, 0); + + mi.root = g_plugin.addRootMenu(MO_MAIN, _A2W(MODULENAME), 20200001); + Menu_ConfigureItem(mi.root, MCI_OPT_UID, "403BE07B-7954-4F3E-B318-4301571776B8"); + + /*DISABLE WEBVIEW*/ + SET_UID(mi, 0xdedeb697, 0xfc10, 0x4622, 0x8b, 0x97, 0x74, 0x39, 0x32, 0x68, 0xa7, 0x7b); + CreateServiceFunction("DisableWebview", AutoUpdateMCmd); + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SITE)); + if (g_plugin.getByte(DISABLE_AUTOUPDATE_KEY, 0)) + mi.name.w = LPGENW("Auto update disabled"); + else + mi.name.w = LPGENW("Auto update enabled"); + mi.pszService = "DisableWebview"; + hMenuItem1 = Menu_AddMainMenuItem(&mi); + + // Update all webview contacts + SET_UID(mi, 0xf324ede, 0xfdf, 0x498a, 0x8f, 0x49, 0x6d, 0x2a, 0x9f, 0xda, 0x58, 0x6); + CreateServiceFunction("UpdateAll", UpdateAllMenuCommand); + mi.position = 500090002; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_UPDATEALL)); + mi.name.w = LPGENW("Update all Webview sites"); + mi.pszService = "UpdateAll"; + Menu_AddMainMenuItem(&mi); + + // Mark All Webview Sites As Read + SET_UID(mi, 0x1fa5fa21, 0x2ee1, 0x4372, 0xae, 0x3e, 0x3b, 0x96, 0xac, 0xd, 0xe8, 0x49); + CreateServiceFunction("MarkAllSitesRead", MarkAllReadMenuCommand); + mi.position = 500090099; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_MARKALLREAD)); + mi.name.w = LPGENW("Mark all Webview sites as read"); + mi.pszService = "MarkAllSitesRead"; + Menu_AddMainMenuItem(&mi); + + // open cache directory + SET_UID(mi, 0xfed046a8, 0xaae5, 0x4cbe, 0xa8, 0xc, 0x3c, 0x50, 0x3e, 0x3e, 0x9b, 0x15); + CreateServiceFunction("OpenCacheFolder", OpenCacheDir); + mi.position = 500090099; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_FOLDER)); + mi.name.w = LPGENW("Open cache folder"); + mi.pszService = "OpenCacheFolder"; + Menu_AddMainMenuItem(&mi); + + // Countdown test + SET_UID(mi, 0xbb1a94a9, 0xca63, 0x4966, 0x98, 0x48, 0x8b, 0x3f, 0x9d, 0xac, 0x6a, 0x10); + CreateServiceFunction("Countdown", CountdownMenuCommand); + mi.flags |= CMIF_KEEPUNTRANSLATED; + wchar_t countername[100]; + mir_snwprintf(countername, TranslateT("%d minutes to update"), g_plugin.getDword(COUNTDOWN_KEY, 0)); + mi.position = 600090099; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_UPDATEALL)); + mi.name.w = countername; + mi.pszService = "Countdown"; + hMenuItemCountdown = Menu_AddMainMenuItem(&mi); + } + + // contact menu + mi.flags = CMIF_UNICODE; + + SET_UID(mi, 0xadc6a9a4, 0xdf7, 0x4f63, 0x89, 0x11, 0x8e, 0x42, 0x1d, 0xd6, 0x29, 0x31); + CreateServiceFunction("Open web page", WebsiteMenuCommand); + mi.position = 100; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_URL)); + mi.pszService = "Open web page"; + mi.name.w = LPGENW("Open web page"); + Menu_AddContactMenuItem(&mi, MODULENAME); + + SET_UID(mi, 0x9d803e61, 0xc929, 0x4c6e, 0x9e, 0x7, 0x93, 0x0, 0xab, 0x14, 0x13, 0x50); + CreateServiceFunction("OpenClose Window", DataWndMenuCommand); + mi.pszService = "OpenClose Window"; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SHOW_HIDE)); + mi.name.w = LPGENW("Open/Close window"); + Menu_AddContactMenuItem(&mi, MODULENAME); + + SET_UID(mi, 0x3840cc71, 0xcc85, 0x448d, 0xb5, 0xc8, 0x1a, 0x7d, 0xfe, 0xf0, 0x8, 0x85); + mi.position = 2222220; + mi.pszService = "UpdateData"; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_UPDATE)); + mi.name.w = LPGENW("Update data"); + Menu_AddContactMenuItem(&mi, MODULENAME); + + SET_UID(mi, 0xd1ab586c, 0x2c71, 0x429c, 0xb1, 0x79, 0x7b, 0x3a, 0x1d, 0x4a, 0xc1, 0x7d); + CreateServiceFunction("ContactOptions", CntOptionsMenuCommand); + mi.pszService = "ContactOptions"; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_OPTIONS)); + mi.name.w = LPGENW("Contact options"); + Menu_AddContactMenuItem(&mi, MODULENAME); + + SET_UID(mi, 0xe4cda597, 0x9def, 0x4f54, 0x8a, 0xc6, 0x69, 0x3b, 0x5a, 0x7d, 0x77, 0xb6); + CreateServiceFunction("ContactAlertOpts", CntAlertMenuCommand); + mi.pszService = "ContactAlertOpts"; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_ALERT)); + mi.name.w = LPGENW("Contact alert options"); + Menu_AddContactMenuItem(&mi, MODULENAME); + + SET_UID(mi, 0x63fdeed8, 0xf880, 0x423f, 0x95, 0xae, 0x20, 0x8c, 0x86, 0x3c, 0x5, 0xd8); + CreateServiceFunction("PingWebsite", PingWebsiteMenuCommand); + mi.pszService = "PingWebsite"; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_PING)); + mi.name.w = LPGENW("Ping web site"); + Menu_AddContactMenuItem(&mi, MODULENAME); + + SET_UID(mi, 0x28fd36de, 0x6ce1, 0x43d0, 0xa1, 0x6e, 0x98, 0x71, 0x53, 0xe8, 0xc9, 0xf4); + CreateServiceFunction("StopDataProcessing", StpPrcssMenuCommand); + mi.pszService = "StopDataProcessing"; + mi.hIcolibItem = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_STOP)); + mi.name.w = LPGENW("Stop data processing"); + Menu_AddContactMenuItem(&mi, MODULENAME); + + hWindowList = WindowList_Create(); + + HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged); + HookEvent(ME_DB_CONTACT_DELETED, SiteDeleted); + HookEvent(ME_OPT_INITIALISE, OptInitialise); + + g_plugin.setByte(HAS_CRASHED_KEY, 1); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +int CMPlugin::Unload() +{ + ChangeContactStatus(0); + + KillTimer(nullptr, timerId); + KillTimer(nullptr, Countdown); + + g_plugin.setByte(HAS_CRASHED_KEY, 0); + SavewinSettings(); + if (hRichEd) + FreeLibrary(hRichEd); + + if (hNetlibUser) { + Netlib_CloseHandle(hNetlibUser); + hNetlibUser = nullptr; + } + + if (hHookDisplayDataAlert) + DestroyHookableEvent(hHookDisplayDataAlert); + if (hHookAlertPopup) + DestroyHookableEvent(hHookAlertPopup); + if (hHookAlertWPopup) + DestroyHookableEvent(hHookAlertWPopup); + + if (h_font != nullptr) + DeleteObject(h_font); + if (hMenu) + DestroyMenu(hMenu); + WindowList_Destroy(hWindowList); + return 0; +} diff --git a/protocols/WebView/src/resource.h b/protocols/WebView/src/resource.h new file mode 100644 index 0000000000..d0203c7cab --- /dev/null +++ b/protocols/WebView/src/resource.h @@ -0,0 +1,139 @@ +#define UNI 1 + +#define IDC_STATIC -1 + +#define IDI_SITE 101 +#define IDI_STICK 102 +#define IDI_UNSTICK 103 +#define IDI_URL 104 +#define IDI_OPTIONS 105 +#define IDI_UPDATE 106 +#define IDI_SHOW_HIDE 107 +#define IDI_FIND 108 +#define IDI_ALERT 110 +#define IDI_FOLDER 111 +#define IDI_UPDATEALL 112 +#define IDI_MARKALLREAD 113 +#define IDI_PING 114 +#define IDI_STOP 115 + + +#define IDC_UPDATE_ONSTART 300 +#define IDC_DBLE_WEB 301 +#define IDC_DBLE_WIN 302 +#define IDC_UPDATE_ON_OPEN 303 +#define IDC_UPDATE_ONALERT 304 + +#define IDD_OPT 443 +#define IDC_DISABLEMENU 446 +#define IDC_OPEN_WEBPAGE 447 +#define IDC_TIME 450 + +#define IDC_BGCOLOR 451 +#define IDC_TXTCOLOR 452 +#define IDC_RESTART 453 +#define IDC_CLEAN 457 +#define IDC_SUPPRESS 458 +#define IDC_SPIN1 461 +#define IDC_HIDE_STATUS_ICON 464 +#define IDC_RWSPACE 465 +#define IDC_RWSPC_TEXT 466 +#define IDC_TYPEFACE 467 +#define IDC_FONT_BOLD 468 +#define IDC_FONT_ITALIC 469 +#define IDC_FONT_UNDERLINE 470 +#define IDC_FONTSIZE 471 +#define IDC_U_SE_STRINGS 475 +#define IDC_U_ALLSITE 476 +#define IDC_ERROR_POPUP 477 +#define IDC_START_DELAY 480 +#define IDC_SPIN2 481 +#define IDC_STARTDELAYTXT 482 +#define IDC_STDELAYSECTXT 483 +#define IDC_SAVE_INDIVID_POS 484 +#define IDC_ADV_GRP 485 +#define IDC_NO_PROTECT 486 +#define IDC_NOT_RECOMND_TXT 487 +#define IDC_SCRIPT 488 +#define IDC_DATAPOPUP 489 + +#define IDR_CONTEXT 500 +#define IDM_CUT 501 +#define IDM_PASTE 502 +#define IDM_DELETE 503 +#define IDM_CLEAR_ALL 504 +#define IDM_COPY 505 +#define IDM_COPYALL 506 +#define IDM_SELECTALL 507 + +#define IDC_SITE_NAME 551 +#define IDC_ERR_CHK 552 +#define IDC_APPEND 554 +#define IDC_FILENAME 555 +#define IDC_BROWSE 556 +#define IDC_SAVE_AS_RAW 557 +//#define IDC_AGENT 557//temp + +#define IDD_DISPLAY_DATA 600 +#define IDC_OPEN_URL 601 +#define IDC_DATA 602 +#define IDC_UPDATE_BUTTON 603 +#define IDC_STICK_BUTTON 604 +#define IDC_FIND_BUTTON 605 +#define IDC_STATUSBAR 606 +#define IDC_OPTIONS_BUTTON 607 +#define IDC_ALERT_BUTTON 608 +//#define IDC_HIDDEN_URL 609 +#define IDC_STOP 609 + +#define IDC_ERRORMSG 620 + +#define IDD_CONTACT_OPT 700 +#define IDC_END 701 +#define IDC_START 702 +#define IDC_URL 703 +#define IDC_OPT_CANCEL 704 +#define IDC_OPT_APPLY 705 +#define IDC_CPY_STRINGS 706 + + +#define IDD_FIND 750 +#define IDC_FINDWHAT 751 +#define IDC_OK 752 +#define IDC_CANCEL 753 +#define IDC_SEARCH_COMPLETE 754 + +#define IDD_ALRT_OPT 801 +#define IDC_ENABLE_ALERTS 802 +#define IDC_OK2 803 +#define IDC_ALERT_STRING 804 +#define IDC_ALERT_TYPE 807 +#define IDC_EVENT_TYPE 808 +#define IDC_ALERT_CANCEL 809 +#define IDC_ALERT_APPLY 810 +#define IDC_START2 811 +#define IDC_END2 812 +#define IDC_ADD_DATE_NAME 813 +#define IDC_DELAY 814 +#define IDC_PREFIX 815 +#define IDC_SUFFIX 816 +#define IDC_24_HOUR 817 +#define IDC_ALWAYS_LOG 818 + +#define IDD_POPUP 850 +#define IDC_POP_BGCOLOUR 851 +#define IDC_POP_TEXTCOLOUR 852 +#define IDC_PD1 853 +#define IDC_PD2 854 +//#define IDC_PD3 855 +#define IDC_PREVIEW 856 +#define IDC_POP_USEWINCOLORS 857 +#define IDC_POP_USESAMECOLORS 858 +#define IDC_POP_USECUSTCOLORS 859 +#define IDC_LCLK_WINDOW 860 +#define IDC_LCLK_WEB_PGE 861 +#define IDC_LCLK_DISMISS 862 +#define IDC_RCLK_WINDOW 863 +#define IDC_RCLK_WEB_PGE 864 +#define IDC_RCLK_DISMISS 865 +//#define IDC_PUALERT 866 diff --git a/protocols/WebView/src/stdafx.cxx b/protocols/WebView/src/stdafx.cxx new file mode 100644 index 0000000000..1b563fc866 --- /dev/null +++ b/protocols/WebView/src/stdafx.cxx @@ -0,0 +1,18 @@ +/* +Copyright (C) 2012-19 Miranda NG team (https://miranda-ng.org) + +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 version 2 +of the License. + +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, see . +*/ + +#include "stdafx.h" \ No newline at end of file diff --git a/protocols/WebView/src/stdafx.h b/protocols/WebView/src/stdafx.h new file mode 100644 index 0000000000..91a1ac63c1 --- /dev/null +++ b/protocols/WebView/src/stdafx.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "resource.h" +#include "version.h" diff --git a/protocols/WebView/src/version.h b/protocols/WebView/src/version.h new file mode 100644 index 0000000000..c2030de835 --- /dev/null +++ b/protocols/WebView/src/version.h @@ -0,0 +1,13 @@ +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 1 +#define __RELEASE_NUM 3 +#define __BUILD_NUM 2 + +#include + +#define __PLUGIN_NAME "Webview" +#define __FILENAME "Webview.dll" +#define __DESCRIPTION "Adds web pages as contacts to your contact list and can display text and/or issue change alerts from those pages in a window." +#define __AUTHOR "Vincent Joyce" +#define __AUTHORWEB "https://miranda-ng.org/p/WebView/" +#define __COPYRIGHT "© 2011 Vincent Joyce" diff --git a/protocols/WebView/src/webview.cpp b/protocols/WebView/src/webview.cpp new file mode 100644 index 0000000000..87e5baf4a1 --- /dev/null +++ b/protocols/WebView/src/webview.cpp @@ -0,0 +1,481 @@ +/* +* A plugin for Miranda IM which displays web page text in a window Copyright +* (C) 2005 Vincent Joyce. +* +* Miranda IM: the free icq client for MS Windows Copyright (C) 2000-2 +* Richard Hughes, Roland Rabien & Tristan Van de Vreede +* +* 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" +#include "webview.h" + +char* WndClass = "WEBWnd"; +WNDCLASSEX wincl; +MSG messages; +DWORD winheight; +int StartUpDelay = 0; + +int Xposition, Yposition; +int WindowHeight, WindowWidth; +COLORREF BackgoundClr, TextClr; + +UINT_PTR timerId; +UINT_PTR Countdown; +LOGFONT g_lf; +HFONT h_font; +HMENU hMenu; +int bpStatus; +HGENMENU hMenuItem1; +HGENMENU hMenuItemCountdown; + +/*****************************************************************************/ +void ChangeMenuItem1() +{ + // Enable or Disable auto updates + LPCTSTR ptszName; + if (!g_plugin.getByte(DISABLE_AUTOUPDATE_KEY, 0)) + ptszName = LPGENW("Auto update enabled"); + else + ptszName = LPGENW("Auto update disabled"); + + Menu_ModifyItem(hMenuItem1, ptszName, LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SITE))); +} + +/*****************************************************************************/ +void ChangeMenuItemCountdown() +{ + // countdown + HICON hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_UPDATEALL)); + + wchar_t countername[100]; + mir_snwprintf(countername, TranslateT("%d minutes to update"), g_plugin.getDword(COUNTDOWN_KEY, 0)); + + Menu_ModifyItem(hMenuItemCountdown, countername, hIcon, CMIF_KEEPUNTRANSLATED); +} + +/*****************************************************************************/ +static int CALLBACK EnumFontsProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX*, int, LPARAM lParam) +{ + if (!IsWindow((HWND)lParam)) + return FALSE; + if (SendMessage((HWND)lParam, CB_FINDSTRINGEXACT, -1, (LPARAM)lpelfe->elfLogFont.lfFaceName) == CB_ERR) + SendMessage((HWND)lParam, CB_ADDSTRING, 0, (LPARAM)lpelfe->elfLogFont.lfFaceName); + return TRUE; +} + +void FillFontListThread(void *param) +{ + HDC hdc = GetDC((HWND)param); + + LOGFONT lf = { 0 }; + g_lf.lfCharSet = DEFAULT_CHARSET; + g_lf.lfFaceName[0] = 0; + g_lf.lfPitchAndFamily = 0; + EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)EnumFontsProc, (LPARAM)GetDlgItem((HWND)param, IDC_TYPEFACE), 0); + ReleaseDC((HWND)param, hdc); +} + +/*****************************************************************************/ +void TxtclrLoop() +{ + for (auto &hContact : Contacts(MODULENAME)) { + HWND hwndDlg = WindowList_Find(hWindowList, hContact); + SetDlgItemText(hwndDlg, IDC_DATA, L""); + InvalidateRect(hwndDlg, nullptr, 1); + } +} + +/*****************************************************************************/ +void BGclrLoop() +{ + for (auto &hContact : Contacts(MODULENAME)) { + HWND hwndDlg = (WindowList_Find(hWindowList, hContact)); + SetDlgItemText(hwndDlg, IDC_DATA, L""); + SendDlgItemMessage(hwndDlg, IDC_DATA, EM_SETBKGNDCOLOR, 0, BackgoundClr); + InvalidateRect(hwndDlg, nullptr, 1); + } +} + +/*****************************************************************************/ +void StartUpdate(void*) +{ + StartUpDelay = 1; + Sleep(((g_plugin.getDword(START_DELAY_KEY, 0)) * SECOND)); + + for (auto &hContact : Contacts(MODULENAME)) + GetData((void*)hContact); + + StartUpDelay = 0; +} + +/*****************************************************************************/ +void ContactLoop(void*) +{ + if (StartUpDelay == 0) { + for (auto &hContact : Contacts(MODULENAME)) { + GetData((void*)hContact); + Sleep(10); // avoid 100% CPU + } + } + + WAlertPopup(NULL, TranslateT("All Webview sites have been updated.")); +} + +/*****************************************************************************/ +INT_PTR MarkAllReadMenuCommand(WPARAM, LPARAM) +{ + ChangeContactStatus(1); + return 0; +} + +/*****************************************************************************/ +void InitialiseGlobals(void) +{ + Xposition = g_plugin.getDword(Xpos_WIN_KEY, 0); + Yposition = g_plugin.getDword(Ypos_WIN_KEY, 0); + + if (Yposition == -32000) + Yposition = 100; + + if (Xposition == -32000) + Xposition = 100; + + BackgoundClr = g_plugin.getDword(BG_COLOR_KEY, Def_color_bg); + TextClr = g_plugin.getDword(TXT_COLOR_KEY, Def_color_txt); + + WindowHeight = g_plugin.getDword(WIN_HEIGHT_KEY, Def_win_height); + WindowWidth = g_plugin.getDword(WIN_WIDTH_KEY, Def_win_width); +} + +/*****************************************************************************/ +int Doubleclick(WPARAM wParam, LPARAM) +{ + MCONTACT hContact = wParam; + char *szProto = GetContactProto(hContact); + if (mir_strcmp(MODULENAME, szProto)) + return 0; + + int action = g_plugin.getByte(hContact, DBLE_WIN_KEY, 1); + if (action == 0) { + ptrW url(g_plugin.getWStringA(hContact, "URL")); + Utils_OpenUrlW(url); + + g_plugin.setWord(hContact, "Status", ID_STATUS_ONLINE); + } + else if (action == 1) { + HWND hwndDlg = WindowList_Find(hWindowList, hContact); + if (hwndDlg) { + SetForegroundWindow(hwndDlg); + SetFocus(hwndDlg); + } + else { + hwndDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DISPLAY_DATA), nullptr, DlgProcDisplayData, (LPARAM)hContact); + HWND hTopmost = g_plugin.getByte(hContact, ON_TOP_KEY, 0) ? HWND_TOPMOST : HWND_NOTOPMOST; + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM)((HICON)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + + if (g_plugin.getByte(SAVE_INDIVID_POS_KEY, 0)) + SetWindowPos(hwndDlg, hTopmost, + g_plugin.getDword(hContact, "WVx", 100), // Xposition, + g_plugin.getDword(hContact, "WVy", 100), // Yposition, + g_plugin.getDword(hContact, "WVwidth", 412), // WindowWidth, + g_plugin.getDword(hContact, "WVheight", 350), 0); // WindowHeight, + else + SetWindowPos(hwndDlg, HWND_TOPMOST, Xposition, Yposition, WindowWidth, WindowHeight, 0); + } + + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + + if (g_plugin.getByte(UPDATE_ON_OPEN_KEY, 0)) { + if (g_plugin.getByte(hContact, ENABLE_ALERTS_KEY, 0)) + mir_forkthread(ReadFromFile, (void*)hContact); + else + mir_forkthread(GetData, (void*)hContact); + g_plugin.setWord(hContact, "Status", ID_STATUS_ONLINE); + } + } + + return 1; +} + +/*****************************************************************************/ +int SendToRichEdit(HWND hWindow, char *truncated, COLORREF rgbText, COLORREF rgbBack) +{ + DBVARIANT dbv; + DWORD bold = 0; + DWORD italic = 0; + DWORD underline = 0; + + SetDlgItemText(hWindow, IDC_DATA, L""); + + CHARFORMAT2 cfFM; + memset(&cfFM, 0, sizeof(cfFM)); + cfFM.cbSize = sizeof(CHARFORMAT2); + cfFM.dwMask = CFM_COLOR | CFM_CHARSET | CFM_FACE | ENM_LINK | ENM_MOUSEEVENTS | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_SIZE; + + if (g_plugin.getByte(FONT_BOLD_KEY, 0)) + bold = CFE_BOLD; + + if (g_plugin.getByte(FONT_ITALIC_KEY, 0)) + italic = CFE_ITALIC; + + if (g_plugin.getByte(FONT_UNDERLINE_KEY, 0)) + underline = CFE_UNDERLINE; + + cfFM.dwEffects = bold | italic | underline; + + if (!g_plugin.getWString(FONT_FACE_KEY, &dbv)) { + mir_wstrcpy(cfFM.szFaceName, dbv.pwszVal); + db_free(&dbv); + } + else mir_wstrcpy(cfFM.szFaceName, Def_font_face); + + HDC hDC = GetDC(hWindow); + cfFM.yHeight = (BYTE)MulDiv(abs(g_lf.lfHeight), 120, GetDeviceCaps(GetDC(hWindow), LOGPIXELSY)) * (g_plugin.getByte(FONT_SIZE_KEY, 14)); + ReleaseDC(hWindow, hDC); + + cfFM.bCharSet = g_plugin.getByte(FONT_SCRIPT_KEY, 0); + cfFM.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; + cfFM.crTextColor = rgbText; + cfFM.crBackColor = rgbBack; + SendDlgItemMessage(hWindow, IDC_DATA, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)& cfFM); + + SendDlgItemMessage(hWindow, IDC_DATA, EM_SETSEL, 0, -1); + SendDlgItemMessageA(hWindow, IDC_DATA, EM_REPLACESEL, FALSE, (LPARAM)truncated); + SendDlgItemMessage(hWindow, IDC_DATA, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cfFM); + return 1; +} + +/*****************************************************************************/ +void CALLBACK timerfunc(HWND, UINT, UINT_PTR, DWORD) +{ + g_plugin.setByte(HAS_CRASHED_KEY, 0); + + if (!(g_plugin.getByte(OFFLINE_STATUS, 1))) + if (!(g_plugin.getByte(DISABLE_AUTOUPDATE_KEY, 0))) + mir_forkthread(ContactLoop); + + g_plugin.setDword(COUNTDOWN_KEY, 0); +} + +/*****************************************************************************/ +void CALLBACK Countdownfunc(HWND, UINT, UINT_PTR, DWORD) +{ + DWORD timetemp = g_plugin.getDword(COUNTDOWN_KEY, 100); + if (timetemp <= 0) { + timetemp = g_plugin.getDword(REFRESH_KEY, TIME); + g_plugin.setDword(COUNTDOWN_KEY, timetemp); + } + + g_plugin.setDword(COUNTDOWN_KEY, timetemp - 1); + + ChangeMenuItemCountdown(); +} + +/*****************************************************************************/ + +int OptInitialise(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = {}; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT); + odp.szGroup.a = LPGEN("Network"); + odp.szTitle.a = MODULENAME; + odp.pfnDlgProc = DlgProcOpt; + odp.flags = ODPF_BOLDGROUPS; + g_plugin.addOptions(wParam, &odp); + + // if popup service exists + if ((ServiceExists(MS_POPUP_ADDPOPUPW))) { + odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUP); + odp.szGroup.a = LPGEN("Popups"); + odp.pfnDlgProc = DlgPopUpOpts; + g_plugin.addOptions(wParam, &odp); + } + return 0; +} + +/*****************************************************************************/ +void FontSettings(void) +{ + g_lf.lfHeight = 16; + g_lf.lfWidth = 0; + g_lf.lfEscapement = 0; + g_lf.lfOrientation = 0; + g_lf.lfWeight = FW_NORMAL; + g_lf.lfItalic = FALSE; + g_lf.lfUnderline = FALSE; + g_lf.lfStrikeOut = 0; + g_lf.lfCharSet = ANSI_CHARSET; + g_lf.lfOutPrecision = OUT_DEFAULT_PRECIS; + g_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; + g_lf.lfQuality = DEFAULT_QUALITY; + g_lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN; + mir_wstrcpy(g_lf.lfFaceName, Def_font_face); +} + +/*****************************************************************************/ +int ModulesLoaded(WPARAM, LPARAM) +{ + hHookDisplayDataAlert = CreateHookableEvent(ME_DISPLAYDATA_ALERT); + HookEvent(ME_DISPLAYDATA_ALERT, DataWndAlertCommand); + + hHookAlertPopup = CreateHookableEvent(ME_POPUP_ALERT); + HookEvent(ME_POPUP_ALERT, PopupAlert); + + hHookErrorPopup = CreateHookableEvent(ME_POPUP_ERROR); + HookEvent(ME_POPUP_ERROR, ErrorMsgs); + + hHookAlertOSD = CreateHookableEvent(ME_OSD_ALERT); + HookEvent(ME_OSD_ALERT, OSDAlert); + + FontSettings(); + h_font = CreateFontIndirect(&g_lf); + + // get data on startup + if (g_plugin.getByte(UPDATE_ONSTART_KEY, 0)) + mir_forkthread(StartUpdate); + + return 0; +} + +/*****************************************************************************/ +INT_PTR DataWndMenuCommand(WPARAM wParam, LPARAM) +{ + MCONTACT hContact = wParam; + HWND hwndDlg = WindowList_Find(hWindowList, hContact); + if (hwndDlg != nullptr) { + DestroyWindow(hwndDlg); + return 0; + } + + HWND hTopmost = g_plugin.getByte(hContact, ON_TOP_KEY, 0) ? HWND_TOPMOST : HWND_NOTOPMOST; + hwndDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DISPLAY_DATA), nullptr, DlgProcDisplayData, (LPARAM)hContact); + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); + if (g_plugin.getByte(SAVE_INDIVID_POS_KEY, 0)) + SetWindowPos(hwndDlg, hTopmost, + g_plugin.getDword(hContact, "WVx", 100), // Xposition, + g_plugin.getDword(hContact, "WVy", 100), // Yposition, + g_plugin.getDword(hContact, "WVwidth", 100), // WindowWidth, + g_plugin.getDword(hContact, "WVheight", 100), 0); // WindowHeight, + else + SetWindowPos(hwndDlg, HWND_TOPMOST, Xposition, Yposition, WindowWidth, WindowHeight, 0); + + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + + if (g_plugin.getByte(UPDATE_ON_OPEN_KEY, 0)) { + if (g_plugin.getByte(hContact, ENABLE_ALERTS_KEY, 0)) + mir_forkthread(ReadFromFile, (void*)hContact); + else + mir_forkthread(GetData, (void*)hContact); + g_plugin.setWord(hContact, "Status", ID_STATUS_ONLINE); + } + + return 0; +} + +/*****************************************************************************/ +INT_PTR UpdateAllMenuCommand(WPARAM, LPARAM) +{ + mir_forkthread(ContactLoop); + return 0; +} + +/*****************************************************************************/ +INT_PTR AutoUpdateMCmd(WPARAM, LPARAM) +{ + if (g_plugin.getByte(DISABLE_AUTOUPDATE_KEY, 0)) + g_plugin.setByte(DISABLE_AUTOUPDATE_KEY, 0); + else + g_plugin.setByte(DISABLE_AUTOUPDATE_KEY, 1); + + ChangeMenuItem1(); + return 0; +} + +/*****************************************************************************/ +INT_PTR AddContactMenuCommand(WPARAM, LPARAM) +{ + db_set_s(0, "FindAdd", "LastSearched", MODULENAME); + CallService(MS_FINDADD_FINDADD, 0, 0); + return 0; +} + +/*****************************************************************************/ +int OnTopMenuCommand(WPARAM, LPARAM, MCONTACT singlecontact) +{ + int ontop = 0; + int done = 0; + + if (((g_plugin.getByte(singlecontact, ON_TOP_KEY))) && done == 0) { + g_plugin.setByte(singlecontact, ON_TOP_KEY, 0); + ontop = 0; + done = 1; + } + if ((!(g_plugin.getByte(singlecontact, ON_TOP_KEY, 0))) && done == 0) { + g_plugin.setByte(singlecontact, ON_TOP_KEY, 1); + ontop = 1; + done = 1; + } + return 0; +} + +/*****************************************************************************/ +INT_PTR WebsiteMenuCommand(WPARAM wParam, LPARAM) +{ + MCONTACT hContact = wParam; + ptrW url(g_plugin.getWStringA(hContact, "URL")); + if (url) + Utils_OpenUrlW(url); + + g_plugin.setWord(hContact, "Status", ID_STATUS_ONLINE); + return 0; +} + +/*****************************************************************************/ +int UpdateMenuCommand(WPARAM, LPARAM, MCONTACT singlecontact) +{ + mir_forkthread(GetData, (void*)singlecontact); + return 0; +} + +/*****************************************************************************/ +int ContactMenuItemUpdateData(WPARAM wParam, LPARAM lParam) +{ + UpdateMenuCommand(wParam, lParam, wParam); + return 0; +} + +/*****************************************************************************/ +INT_PTR CntOptionsMenuCommand(WPARAM wParam, LPARAM) +{ + DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CONTACT_OPT), nullptr, DlgProcContactOpt, wParam); + return 0; +} + +/*****************************************************************************/ +INT_PTR CntAlertMenuCommand(WPARAM wParam, LPARAM) +{ + DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ALRT_OPT), nullptr, DlgProcAlertOpt, wParam); + return 0; +} + +/*****************************************************************************/ +INT_PTR CountdownMenuCommand(WPARAM, LPARAM) +{ + return 0; +} diff --git a/protocols/WebView/src/webview.h b/protocols/WebView/src/webview.h new file mode 100644 index 0000000000..e7bdd6c57b --- /dev/null +++ b/protocols/WebView/src/webview.h @@ -0,0 +1,254 @@ +/* + * A plugin for Miranda IM which displays web page text in a window Copyright + * (C) 2005 Vincent Joyce. + * + * Miranda IM: the free icq client for MS Windows Copyright (C) 2000-2 + * Richard Hughes, Roland Rabien & Tristan Van de Vreede + * + * 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. + */ + +#pragma once + +#define CFM_BACKCOLOR 0x04000000 + +#define MODULENAME "WebView" + +#define MENU_OFF "DisableMenu" +#define REFRESH_KEY "Refresh interval" +#define ON_TOP_KEY "Always on top" +#define OFFLINE_STATUS "OfflineOnBoot" +#define URL_KEY "URL" +#define START_STRING_KEY "Start_string" +#define END_STRING_KEY "End_String" +#define DBLE_WIN_KEY "Doub_click_win" +#define HIDE_STATUS_ICON_KEY "Hide_Status_Icon" +#define HAS_CRASHED_KEY "Has_Crashed" +#define U_ALLSITE_KEY "UseAllTheWebsite" +#define MENU_IS_DISABLED_KEY "MainMenuReallyDisabled" +#define UPDATE_ONALERT_KEY "WND_UPDATE_OALERY_ONLY" +#define DISABLE_AUTOUPDATE_KEY "Disable_Auto_Update" +#define RWSPACE_KEY "level_of_wspace_removal" +#define PRESERVE_NAME_KEY "PreserveName" +#define CLEAR_DISPLAY_KEY "Remove_tags_whitespace" +#define ALRT_S_STRING_KEY "ALRT_S_STRING" +#define ALRT_E_STRING_KEY "ALRT_E_STRING" +#define ALRT_INDEX_KEY "AlertIndex" +#define EVNT_INDEX_KEY "EventIndex" +#define START_DELAY_KEY "StartUpDelay" +#define ALWAYS_LOG_KEY "AlwaysLogToFile" +#define SAVE_INDIVID_POS_KEY "SaveIndividWinPos" +#define NO_PROTECT_KEY "NoDownloadProtection" +#define SAVE_AS_RAW_KEY "SaveAsRaw" +#define FONT_SCRIPT_KEY "FontScript" +#define STOP_KEY "StopProcessing" +#define DATA_POPUP_KEY "DisplayDataPopup" +#define COUNTDOWN_KEY "Countdown" + +#define MINUTE 60000 +#define SECOND 1000 + +#define MS_UPDATE_ALL "Webview/UpdateAll" +#define MS_ADD_SITE "Webview/AddSite" +#define MS_AUTO_UPDATE "Webview/AutoUpdate" + +#define CACHE_FILE_KEY "Filename" + +#define Xpos_WIN_KEY "win_Xpos" +#define Ypos_WIN_KEY "win_Ypos" +#define BG_COLOR_KEY "BgColor" +#define TXT_COLOR_KEY "TxtColor" +#define WIN_HEIGHT_KEY "Height" +#define SUPPRESS_ERR_KEY "Suppress error messages" +#define WIN_WIDTH_KEY "Width" +#define FILE_KEY "Filename" +#define APPEND_KEY "Append" +#define UPDATE_ONSTART_KEY "update_onboot" +#define UPDATE_ON_OPEN_KEY "update_on_Window_open" +#define FONT_FACE_KEY "FontFace" +#define FONT_BOLD_KEY "FontBold" +#define FONT_ITALIC_KEY "FontItalic" +#define FONT_UNDERLINE_KEY "FontUnderline" +#define FONT_SIZE_KEY "FontSize" +#define ERROR_POPUP_KEY "UsePopupPlugin" +#define ENABLE_ALERTS_KEY "EnableAlerts" +#define ALERT_STRING_KEY "ALERTSTRING" +#define ALERT_TYPE_KEY "Alert_Type" +#define APND_DATE_NAME_KEY "AppendDateContact" +#define POP_DELAY_KEY "PopUpDelay" +#define POP_BG_CLR_KEY "PopBGClr" +#define POP_TXT_CLR_KEY "PopTxtClr" +#define POP_USEWINCLRS_KEY "PopUseWinClrs" +#define CONTACT_PREFIX_KEY "PrefixDateContact" +#define USE_24_HOUR_KEY "Use24hourformat" +#define POP_USESAMECLRS_KEY "PopUseSameClrs" +#define POP_USECUSTCLRS_KEY "PopUseCustomClrs" +#define LCLK_WINDOW_KEY "LeftClkWindow" +#define LCLK_WEB_PGE_KEY "LeftClkWebPage" +#define LCLK_DISMISS_KEY "LeftClkDismiss" +#define RCLK_WINDOW_KEY "RightClkWindow" +#define RCLK_WEB_PGE_KEY "RightClkWebPage" +#define RCLK_DISMISS_KEY "RightClkDismiss" + +#define TIME 60 +#define Def_color_bg 0x00ffffff +#define Def_color_txt 0x00000000 +#define Def_font_face L"Courier" +#define Def_font_size 14 +#define HK_SHOWHIDE 3001 + +#define MAXSIZE1 250000 +#define MAXSIZE2 500000 +#define MAXSIZE3 1000000 + +#define Def_win_height 152 +#define Def_win_width 250 + +///////////////////////////////////////////////////////////////////////////////////////// +// lets get rid of some warnings + +void CodetoSymbol(char *truncated); +void GetData(void *param); +void FillFontListThread(void *); + +INT_PTR CALLBACK DlgProcDisplayData(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK DlgProcAlertOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK DlgProcOpt(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + +int DataWndAlertCommand(WPARAM wParam, LPARAM lParam); +int PopupAlert(WPARAM wParam, LPARAM lParam); +int ErrorMsgs(WPARAM wParam, LPARAM lParam); +int OSDAlert(WPARAM wParam, LPARAM lParam); + +void ReadFromFile(void *hContact); + +///////////////////////////////////////////////////////////////////////////////////////// +// some globals for window settings + +extern int Xposition, Yposition, WindowHeight, WindowWidth; +extern COLORREF BackgoundClr, TextClr; +extern UINT_PTR timerId, Countdown; +extern LOGFONT g_lf; +extern HFONT h_font; +extern HMENU hMenu; +extern int bpStatus; +extern HNETLIBUSER hNetlibUser; +extern MWindowList hWindowList; +extern HGENMENU hMenuItem1, hMenuItemCountdown; +extern char optionsname[80]; + +///////////////////////////////////////////////////////////////////////////////////////// +// lets get rid of some warnings + +void CALLBACK timerfunc(HWND, UINT, UINT_PTR, DWORD); +void CALLBACK Countdownfunc(HWND, UINT, UINT_PTR, DWORD); +void SavewinSettings(void); +void ValidatePosition(HWND hwndDlg); +int ModulesLoaded(WPARAM wParam, LPARAM lParam); +wchar_t* FixButtonText(wchar_t *url, size_t len); +int ContactMenuItemUpdateData (WPARAM wParam, LPARAM lParam); + +int Doubleclick(WPARAM wParam, LPARAM lParam); +int DBSettingChanged(WPARAM wParam, LPARAM lParam); + +int SendToRichEdit(HWND hWindow, char *truncated, COLORREF rgbText, COLORREF rgbBack); + +///////////////////////////////////////////////////////////////////////////////////////// +// Services + +INT_PTR GetCaps(WPARAM wParam, LPARAM lParam); +INT_PTR GetName(WPARAM wParam, LPARAM lParam); +INT_PTR BPLoadIcon(WPARAM wParam, LPARAM lParam); // BPLoadIcon + +INT_PTR SetStatus(WPARAM wParam, LPARAM lParam); +INT_PTR GetStatus(WPARAM wParam, LPARAM lParam); + +INT_PTR BasicSearch(WPARAM wParam, LPARAM lParam); +INT_PTR AddToList(WPARAM wParam, LPARAM lParam); +INT_PTR GetInfo(WPARAM wParam, LPARAM lParam); + +INT_PTR OpenCacheDir(WPARAM wParam, LPARAM lParam); + +INT_PTR UpdateAllMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR CountdownMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR MarkAllReadMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR WebsiteMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR AddContactMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR CntOptionsMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR CntAlertMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR DataWndMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR PingWebsiteMenuCommand(WPARAM wParam, LPARAM lParam); +INT_PTR StpPrcssMenuCommand(WPARAM wParam, LPARAM lParam); + +int UpdateMenuCommand(WPARAM wParam, LPARAM lParam, MCONTACT singlecontact); +int OnTopMenuCommand(WPARAM wParam, LPARAM lParam, MCONTACT singlecontact); + +///////////////////////////////////////////////////////////////////////////////////////// +void ChangeContactStatus(int con_stat); +void InitialiseGlobals(void); +void FontSettings(void); + +///////////////////////////////////////////////////////////////////////////////////////// + +void Removewhitespace(char *truncated); +void RemoveInvis(char *truncated, int AmountWspcRem); +void RemoveTabs(char *truncated); +void FastTagFilter(char *truncated); +void EraseBlock(char *truncated); +void EraseSymbols(char *truncated); +int ProcessAlerts(MCONTACT hContact, char *truncated, char *tstr, char *contactname, int notpresent); + +INT_PTR CALLBACK DlgPopUpOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK DlgProcFind(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +int DataDialogResize(HWND hwndDlg, LPARAM lParam, UTILRESIZECONTROL * urc); +int OptInitialise(WPARAM, LPARAM); + +void Filter(char *truncated); +void TxtclrLoop(); +void BGclrLoop(); +void ContactLoop(void *dummy); +void NumSymbols(char *truncated); + +INT_PTR AutoUpdateMCmd(WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK DlgProcContactOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +int SiteDeleted(WPARAM wParam, LPARAM lParam); + +int WErrorPopup(MCONTACT hContact, wchar_t *textdisplay); +int WAlertPopup(MCONTACT hContact, wchar_t *displaytext); + +///////////////////////////////////////////////////////////////////////////////////////// +// wrappers + +extern HANDLE hHookDisplayDataAlert; +#define ME_DISPLAYDATA_ALERT "Miranda/ALERT/DISPLAYDATA" + +extern HANDLE hHookAlertPopup; +#define ME_POPUP_ALERT "Miranda/ALERT/POPUP" + +extern HANDLE hHookErrorPopup; +#define ME_POPUP_ERROR "Miranda/ERROR/POPUP" + +extern HANDLE hHookAlertOSD; +#define ME_OSD_ALERT "Miranda/ALERT/OSD" + +///////////////////////////////////////////////////////////////////////////////////////// + +struct CMPlugin : public PLUGIN +{ + CMPlugin(); + + int Load() override; + int Unload() override; +}; diff --git a/protocols/WebView/src/webview_alerts.cpp b/protocols/WebView/src/webview_alerts.cpp new file mode 100644 index 0000000000..1b068f099e --- /dev/null +++ b/protocols/WebView/src/webview_alerts.cpp @@ -0,0 +1,839 @@ +/* +* A plugin for Miranda IM which displays web page text in a window Copyright +* (C) 2005 Vincent Joyce. +* +* Miranda IM: the free icq client for MS Windows Copyright (C) 2000-2 +* Richard Hughes, Roland Rabien & Tristan Van de Vreede +* +* 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" +#include "webview.h" + +/*****************************************************************************/ +int CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) { + case WM_COMMAND: + case WM_CONTEXTMENU: + MCONTACT hContact = PUGetContact(hWnd); + ptrW url(g_plugin.getWStringA(hContact, URL_KEY)); + + if (message == WM_COMMAND) { // left click + if (hContact != NULL) { + // open data window + if (g_plugin.getByte(LCLK_WINDOW_KEY, 0)) { + NotifyEventHooks(hHookDisplayDataAlert, (int)hContact, 0); + mir_forkthread(GetData, (void*)hContact); + PUDeletePopup(hWnd); + } + // open url + if (g_plugin.getByte(LCLK_WEB_PGE_KEY, 0)) { + Utils_OpenUrlW(url); + PUDeletePopup(hWnd); + g_plugin.setWord(wParam, "Status", ID_STATUS_ONLINE); + } + // dismiss + if (g_plugin.getByte(LCLK_DISMISS_KEY, 1)) + PUDeletePopup(hWnd); + } + else if (hContact == NULL) + PUDeletePopup(hWnd); + } + else if (message == WM_CONTEXTMENU) { // right click + if (hContact != NULL) { + // open datA window + if (g_plugin.getByte(RCLK_WINDOW_KEY, 0)) { + NotifyEventHooks(hHookDisplayDataAlert, (int)hContact, 0); + mir_forkthread(GetData, (void*)hContact); + PUDeletePopup(hWnd); + } + // open url + if (g_plugin.getByte(RCLK_WEB_PGE_KEY, 1)) { + Utils_OpenUrlW(url); + PUDeletePopup(hWnd); + g_plugin.setWord(wParam, "Status", ID_STATUS_ONLINE); + } + // dismiss + if (g_plugin.getByte(RCLK_DISMISS_KEY, 0)) + PUDeletePopup(hWnd); + } + else if (hContact == NULL) + PUDeletePopup(hWnd); + } + break; + } + + return DefWindowProc(hWnd, message, wParam, lParam); +} + +/*****************************************************************************/ +int WDisplayDataAlert(MCONTACT hContact) +{ + NotifyEventHooks(hHookDisplayDataAlert, hContact, 0); + return 0; +} + +/*****************************************************************************/ +int WAlertPopup(MCONTACT hContact, wchar_t *displaytext) +{ + NotifyEventHooks(hHookAlertPopup, hContact, (LPARAM)displaytext); + return 0; +} + +/*****************************************************************************/ +int WErrorPopup(MCONTACT hContact, wchar_t *textdisplay) +{ + NotifyEventHooks(hHookErrorPopup, hContact, (LPARAM)textdisplay); + return 0; +} + +/*****************************************************************************/ +int WAlertOSD(MCONTACT hContact, wchar_t *displaytext) +{ + NotifyEventHooks(hHookAlertOSD, hContact, (LPARAM)displaytext); + return 0; +} + +/*****************************************************************************/ +int PopupAlert(WPARAM hContact, LPARAM lParam) +{ + POPUPDATAW ppd = { 0 }; + + if (hContact != 0) + mir_wstrncpy(ppd.lpwzContactName, ptrW(g_plugin.getWStringA(hContact, PRESERVE_NAME_KEY)), _countof(ppd.lpwzContactName)); + else + mir_wstrcpy(ppd.lpwzContactName, _A2W(MODULENAME)); + + ppd.lchContact = hContact; + ppd.lchIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_SITE)); + + wchar_t *displaytext = (wchar_t*)lParam; + if ((mir_wstrlen(displaytext) == MAX_SECONDLINE) || (mir_wstrlen(displaytext) > MAX_SECONDLINE)) + mir_snwprintf(ppd.lpwzText, displaytext); + else if (mir_wstrlen(displaytext) < MAX_SECONDLINE) + mir_snwprintf(ppd.lpwzText, displaytext); + + if (g_plugin.getByte(POP_USECUSTCLRS_KEY, 0)) { + ppd.colorBack = g_plugin.getDword(POP_BG_CLR_KEY, Def_color_bg); + ppd.colorText = g_plugin.getDword(POP_TXT_CLR_KEY, Def_color_txt); + } + else if (g_plugin.getByte(POP_USEWINCLRS_KEY, 0)) { + ppd.colorBack = GetSysColor(COLOR_BTNFACE); + ppd.colorText = GetSysColor(COLOR_WINDOWTEXT); + } + else if (g_plugin.getByte(POP_USESAMECLRS_KEY, 1)) { + ppd.colorBack = BackgoundClr; + ppd.colorText = TextClr; + } + + ppd.PluginWindowProc = nullptr; + ppd.iSeconds = g_plugin.getDword(POP_DELAY_KEY, 0); + + if (ServiceExists(MS_POPUP_ADDPOPUPW)) + CallService(MS_POPUP_ADDPOPUPW, (WPARAM)&ppd, 0); + + return 0; +} + +/*****************************************************************************/ +int OSDAlert(WPARAM hContact, LPARAM lParam) +{ + char contactname[255], newdisplaytext[2000]; + contactname[0] = 0; + + if (hContact != NULL) { + DBVARIANT dbv; + if (!g_plugin.getString(hContact, PRESERVE_NAME_KEY, &dbv)) { + strncpy_s(contactname, _countof(contactname), dbv.pszVal, _TRUNCATE); + db_free(&dbv); + } + } + if (contactname[0] == 0) + strncpy_s(contactname, _countof(contactname), MODULENAME, _TRUNCATE); + + char *displaytext = (char*)lParam; + mir_snprintf(newdisplaytext, "%s: %s", contactname, Translate(displaytext)); + + if (ServiceExists("OSD/Announce")) + CallService("OSD/Announce", (WPARAM)newdisplaytext, 0); + + return 0; +} + +/*****************************************************************************/ +int ErrorMsgs(WPARAM wParam, LPARAM lParam) +{ + MCONTACT hContact = wParam; + wchar_t newdisplaytext[2000], *displaytext = (wchar_t*)lParam; + + if (g_plugin.getByte(SUPPRESS_ERR_KEY, 0)) + return 0; + + wchar_t *ptszContactName = Clist_GetContactDisplayName(hContact); + if (ServiceExists(MS_POPUP_ADDPOPUPW) && g_plugin.getByte(ERROR_POPUP_KEY, 0)) { + mir_snwprintf(newdisplaytext, L"%s\n%s", ptszContactName, displaytext); + PUShowMessageW(newdisplaytext, SM_WARNING); + } + else if (ServiceExists("OSD/Announce") && g_plugin.getByte(ERROR_POPUP_KEY, 0)) { + mir_snwprintf(newdisplaytext, L"%s: %s", ptszContactName, TranslateW(displaytext)); + CallService("OSD/Announce", (WPARAM)newdisplaytext, 0); + } + + Clist_TrayNotifyW(nullptr, ptszContactName, TranslateW(displaytext), NIIF_ERROR, 15000); + return 0; +} + +/*****************************************************************************/ +void SaveToFile(MCONTACT hContact, char *truncated) +{ + char *mode; + if (!g_plugin.getByte(hContact, APPEND_KEY, 0)) + mode = "w"; + else + mode = "a"; + + char url[300]; url[0] = '\0'; + DBVARIANT dbv; + if (!g_plugin.getString(hContact, URL_KEY, &dbv)) { + strncpy_s(url, _countof(url), dbv.pszVal, _TRUNCATE); + db_free(&dbv); + } + + if (g_plugin.getString(hContact, FILE_KEY, &dbv)) + return; + + FILE *pfile = fopen(dbv.pszVal, mode); + if (pfile == nullptr) + WErrorPopup(hContact, TranslateT("Cannot write to file")); + else { + char timestring[128], timeprefix[32]; + char temptime1[32], temptime2[32]; + + time_t ftime = time(0); + struct tm *nTime = localtime(&ftime); + + mir_snprintf(timeprefix, " %s ", Translate("Last updated on")); + strftime(temptime1, 32, " %a, %b %d, %Y ", nTime); + strftime(temptime2, 32, " %I:%M %p.", nTime); + mir_snprintf(timestring, "(%s)%s\n%s,%s\n", MODULENAME, url, temptime1, temptime2); + + fputs(timestring, pfile); + fwrite(truncated, mir_strlen(truncated), 1, pfile); + fputs("\n\n", pfile); + fclose(pfile); + } + + db_free(&dbv); +} + +/*****************************************************************************/ +int ProcessAlerts(MCONTACT hContact, char *truncated, char *tstr, char *contactname, int notpresent) +{ + char alertstring[255]; + wchar_t displaystring[300]; + FILE *pcachefile; + DBVARIANT tdbv; + int wasAlert = 0; + + int statalertpos = 0, disalertpos = 0, statalertposend = 0; + char*alertpos; + char Alerttempstring[300], Alerttempstring2[300]; + static char cachecompare[MAXSIZE1]; + static char raw[MAXSIZE1]; + + int alertIndex = 0, eventIndex = 0; + + char tempraw[MAXSIZE1]; + memset(&tempraw, 0, sizeof(tempraw)); + memset(&raw, 0, sizeof(raw)); + + strncpy(tempraw, truncated, _countof(tempraw)); + + memset(&alertstring, 0, sizeof(alertstring)); + memset(&Alerttempstring, 0, sizeof(Alerttempstring)); + memset(&Alerttempstring2, 0, sizeof(Alerttempstring2)); + memset(&cachecompare, 0, sizeof(cachecompare)); + + // alerts + if (g_plugin.getByte(hContact, ENABLE_ALERTS_KEY, 0)) { // ALERTS + alertIndex = g_plugin.getByte(hContact, ALRT_INDEX_KEY, 0); + eventIndex = g_plugin.getByte(hContact, EVNT_INDEX_KEY, 0); + if (notpresent) { + if (alertIndex == 0) { // Popup + Sleep(1000); + WAlertPopup(hContact, TranslateT("Start/end strings not found or strings not set.")); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 1) { // log to file + if (!g_plugin.getString(hContact, FILE_KEY, &tdbv)) { + int AmountWspcRem = 0; + + if (!g_plugin.getByte(hContact, SAVE_AS_RAW_KEY, 0)) { + CodetoSymbol(tempraw); + Sleep(100); // avoid 100% CPU + + EraseBlock(tempraw); + Sleep(100); // avoid 100% CPU + + FastTagFilter(tempraw); + Sleep(100); // avoid 100% CPU + + NumSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + EraseSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + AmountWspcRem = g_plugin.getByte(hContact, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + + SaveToFile(hContact, tempraw); + db_free(&tdbv); + + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + } + else if (alertIndex == 3) { + WAlertOSD(hContact, TranslateT("Alert start/end strings not found or strings not set.")); + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (eventIndex == 2) { + WDisplayDataAlert(hContact); + + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + + HWND hwndDlg = (WindowList_Find(hWindowList, hContact)); + + SetDlgItemText(hwndDlg, IDC_STATUSBAR, TranslateT("Start/end strings not found or strings not set.")); + } + else MessageBox(nullptr, TranslateT("Start/end strings not found or strings not set."), _A2W(MODULENAME), MB_OK); + } + + if (eventIndex == 0) { // string present + if (!g_plugin.getString(hContact, ALERT_STRING_KEY, &tdbv)) { + strncpy_s(alertstring, _countof(alertstring), tdbv.pszVal, _TRUNCATE); + db_free(&tdbv); + + if ((strstr(tempraw, alertstring)) != nullptr) { // // ENDALERT EVENT:CHECK FOR STRING + // there was an alert + wasAlert = 1; + + // play sound? + Skin_PlaySound("webviewalert"); + // + if ((!notpresent)) { + if (alertIndex == 0) { // popup + mir_snwprintf(displaystring, L"%s \"%S\" %s.", Translate("The string"), alertstring, Translate("has been found on the web page")); + WAlertPopup(hContact, displaystring); + + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } // + else if (alertIndex == 1) { + if (!g_plugin.getString(hContact, FILE_KEY, &tdbv)) { + int AmountWspcRem = 0; + if (!g_plugin.getByte(hContact, SAVE_AS_RAW_KEY, 0)) { + CodetoSymbol(tempraw); + Sleep(100); // avoid 100% CPU + + EraseBlock(tempraw); + Sleep(100); // avoid 100% CPU + + FastTagFilter(tempraw); + Sleep(100); // avoid 100% CPU + + NumSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + EraseSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + AmountWspcRem = g_plugin.getByte(hContact, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + SaveToFile(hContact, tempraw); + db_free(&tdbv); + + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + } + else if (alertIndex == 3) { + mir_snwprintf(displaystring, L"%s \"%s\" %s.", TranslateT("The string"), alertstring, TranslateT("has been found on the web page")); + WAlertOSD(hContact, displaystring); + + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 2) { + WDisplayDataAlert(hContact); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + + HWND hwndDlg = WindowList_Find(hWindowList, hContact); + SetDlgItemText(hwndDlg, IDC_STATUSBAR, TranslateT("Download successful; about to process data...")); + } + else MessageBox(nullptr, TranslateT("Unknown alert type."), _A2W(MODULENAME), MB_OK); + } + } + } + } + else if (eventIndex == 1) { // webpage changed + // TEST GET NAME FOR CACHE + wchar_t cachepath[MAX_PATH], cachedirectorypath[MAX_PATH], newcachepath[MAX_PATH + 50]; + GetModuleFileName(g_plugin.getInst(), cachepath, _countof(cachepath)); + wchar_t *cacheend = wcsrchr(cachepath, '\\'); + cacheend++; + *cacheend = '\0'; + + mir_snwprintf(cachedirectorypath, L"%s%S%S", cachepath, MODULENAME, "cache\\"); + CreateDirectory(cachedirectorypath, nullptr); + mir_snwprintf(newcachepath, L"%s%S%S%S%S", cachepath, MODULENAME, "cache\\", contactname, ".txt"); + // file exists? + if (_waccess(newcachepath, 0) != -1) { + if ((pcachefile = _wfopen(newcachepath, L"r")) == nullptr) + WErrorPopup((UINT_PTR)contactname, TranslateT("Cannot read from file")); + else { + memset(&cachecompare, 0, sizeof(cachecompare)); + fread(cachecompare, sizeof(cachecompare), 1, pcachefile); + fclose(pcachefile); + } + } + // write to cache + if ((pcachefile = _wfopen(newcachepath, L"w")) == nullptr) + WErrorPopup((UINT_PTR)contactname, TranslateT("Cannot write to file 1")); + else { + fwrite(tempraw, mir_strlen(tempraw), 1, pcachefile); //smaller cache + fclose(pcachefile); + g_plugin.setWString(hContact, CACHE_FILE_KEY, newcachepath); + } + // end write to cache + + if (strncmp(tempraw, cachecompare, mir_strlen(tempraw)) != 0) { //lets try this instead + // play sound? + Skin_PlaySound("webviewalert"); + // there was an alert + wasAlert = 1; + + if (!notpresent) { + if (alertIndex == 0) { // popup + WAlertPopup(hContact, TranslateT("The web page has changed.")); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 3) { // osd + WAlertOSD(hContact, TranslateT("The web page has changed.")); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 1) { // log + if (!g_plugin.getString(hContact, FILE_KEY, &tdbv)) { + int AmountWspcRem = 0; + + if (!g_plugin.getByte(hContact, SAVE_AS_RAW_KEY, 0)) { + CodetoSymbol(tempraw); + Sleep(100); // avoid 100% CPU + + EraseBlock(tempraw); + Sleep(100); // avoid 100% CPU + + FastTagFilter(tempraw); + Sleep(100); // avoid 100% CPU + + NumSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + EraseSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + AmountWspcRem = g_plugin.getByte(hContact, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + + SaveToFile(hContact, tempraw); + db_free(&tdbv); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + } + else if (alertIndex == 2) { // window + WDisplayDataAlert(hContact); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else MessageBox(nullptr, TranslateT("Unknown alert type."), _A2W(MODULENAME), MB_OK); + } + } + } + + if (eventIndex == 2) { // part of webpage changed + Alerttempstring[0] = Alerttempstring2[0] = 0; + if (!g_plugin.getString(hContact, ALRT_S_STRING_KEY, &tdbv)) { + strncpy_s(Alerttempstring, _countof(Alerttempstring), tdbv.pszVal, _TRUNCATE); + db_free(&tdbv); + } + if (!g_plugin.getString(hContact, ALRT_E_STRING_KEY, &tdbv)) { + strncpy_s(Alerttempstring2, _countof(Alerttempstring2), tdbv.pszVal, _TRUNCATE); + db_free(&tdbv); + } + + // putting data into string + if (((strstr(tempraw, Alerttempstring)) != nullptr) && ((strstr(tempraw, Alerttempstring2)) != nullptr)) { + //start string + alertpos = strstr(tempraw, Alerttempstring); + statalertpos = alertpos - tempraw; + + memset(&alertpos, 0, sizeof(alertpos)); + //end string + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + (int)mir_strlen(Alerttempstring2); + + if (statalertpos > statalertposend) { + memset(&tempraw, ' ', statalertpos); + memset(&alertpos, 0, sizeof(alertpos)); + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + (int)mir_strlen(Alerttempstring2); + } + + if (statalertpos < statalertposend) { + memset(&raw, 0, sizeof(raw)); + + //start string + alertpos = strstr(tempraw, Alerttempstring); + statalertpos = alertpos - tempraw; + + //end string + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + (int)mir_strlen(Alerttempstring2); + + if (statalertpos > statalertposend) { + memset(&tempraw, ' ', statalertpos); + memset(&alertpos, 0, sizeof(alertpos)); + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + (int)mir_strlen(Alerttempstring2); + } + disalertpos = 0; + + //write selected data to string + strncpy(raw, &tempraw[statalertpos], (statalertposend - statalertpos)); + raw[(statalertposend - statalertpos)] = '\0'; + } + } // end putting data into string + else { // start and/or end string not present + if (alertIndex == 0) { // popup + Sleep(1000); + WAlertPopup(hContact, TranslateT("Alert start/end strings not found or strings not set.")); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 1) { // LOG + if (!notpresent) { // dont log to file twice if both types of start/end strings not present + if (!g_plugin.getString(hContact, FILE_KEY, &tdbv)) { + int AmountWspcRem = 0; + if (!g_plugin.getByte(hContact, SAVE_AS_RAW_KEY, 0)) { + CodetoSymbol(tempraw); + Sleep(100); // avoid 100% CPU + + EraseBlock(tempraw); + Sleep(100); // avoid 100% CPU + + FastTagFilter(tempraw); + Sleep(100); // avoid 100% CPU + + NumSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + EraseSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + AmountWspcRem = g_plugin.getByte(hContact, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + + SaveToFile(hContact, tempraw); + db_free(&tdbv); + // contactlist name + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + } + } + else if (alertIndex == 3) { // osd + WAlertOSD(hContact, TranslateT("Alert start/end strings not found or strings not set.")); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 2) { // window + WDisplayDataAlert(hContact); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + + HWND hwndDlg = (WindowList_Find(hWindowList, hContact)); + SetDlgItemText(hwndDlg, IDC_STATUSBAR, TranslateT("Alert start/end strings not found or strings not set.")); + } + else MessageBox(nullptr, TranslateT("Alert start/end strings not found or strings not set."), _A2W(MODULENAME), MB_OK); + + g_plugin.setWord(hContact, "Status", ID_STATUS_AWAY); + } + + /////////////// + if (((strstr(tempraw, Alerttempstring)) != nullptr) && ((strstr(tempraw, Alerttempstring2)) != nullptr)) { + // TEST GET NAME FOR CACHE + wchar_t cachepath[MAX_PATH], cachedirectorypath[MAX_PATH], newcachepath[MAX_PATH + 50]; + GetModuleFileName(g_plugin.getInst(), cachepath, _countof(cachepath)); + wchar_t *cacheend = wcsrchr(cachepath, '\\'); + cacheend++; + *cacheend = '\0'; + + mir_snwprintf(cachedirectorypath, L"%s%S%S", cachepath, MODULENAME, "cache\\"); + CreateDirectory(cachedirectorypath, nullptr); + mir_snwprintf(newcachepath, L"%s%S%S%S%S", cachepath, MODULENAME, "cache\\", contactname, ".txt"); + // file exists? + if (_waccess(newcachepath, 0) != -1) { + if ((pcachefile = _wfopen(newcachepath, L"r")) == nullptr) + WErrorPopup((UINT_PTR)contactname, TranslateT("Cannot read from file")); + else { + memset(&cachecompare, 0, sizeof(cachecompare)); + fread(cachecompare, sizeof(cachecompare), 1, pcachefile); + fclose(pcachefile); + } + } + // write to cache + if ((pcachefile = _wfopen(newcachepath, L"w")) == nullptr) + WErrorPopup((UINT_PTR)contactname, TranslateT("Cannot write to file 2")); + else { + fwrite(raw, mir_strlen(raw), 1, pcachefile); //smaller cache + g_plugin.setWString(hContact, CACHE_FILE_KEY, newcachepath); + fclose(pcachefile); + } + // end write to cache + if (strncmp(raw, cachecompare, (mir_strlen(raw))) != 0) { //lets try this instead + // play sound? + Skin_PlaySound("webviewalert"); + // there was an alert + wasAlert = 1; + + if (!notpresent) { + if (alertIndex == 0) { // popup + WAlertPopup(hContact, TranslateT("Specific part of the web page has changed.")); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 3) { // osd + WAlertOSD(hContact, TranslateT("Specific part of the web page has changed.")); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else if (alertIndex == 1) { // log to file + if (!g_plugin.getString(hContact, FILE_KEY, &tdbv)) { + int AmountWspcRem = 0; + if (!g_plugin.getByte(hContact, SAVE_AS_RAW_KEY, 0)) { + CodetoSymbol(tempraw); + Sleep(100); // avoid 100% CPU + + EraseBlock(tempraw); + Sleep(100); // avoid 100% CPU + + FastTagFilter(tempraw); + Sleep(100); // avoid 100% CPU + + NumSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + EraseSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + AmountWspcRem = g_plugin.getByte(hContact, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + + SaveToFile(hContact, tempraw); + db_free(&tdbv); + // contactlist name + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + } + else if (alertIndex == 2) { // window + WDisplayDataAlert(hContact); + // contactlist name// + if (g_plugin.getByte(hContact, APND_DATE_NAME_KEY, 0)) + db_set_s(hContact, "CList", "MyHandle", tstr); + } + else MessageBox(nullptr, TranslateT("Unknown alert type."), _A2W(MODULENAME), MB_OK); + } + } + } + } // alert type + } + // end alerts + + //if always log to file option is enabled do this + if (wasAlert && alertIndex != 1) { // dont do for log to file alert + if (g_plugin.getByte(hContact, ALWAYS_LOG_KEY, 0)) { + if (!g_plugin.getString(hContact, FILE_KEY, &tdbv)) { + int AmountWspcRem = 0; + + if (!g_plugin.getByte(hContact, SAVE_AS_RAW_KEY, 0)) { + CodetoSymbol(tempraw); + Sleep(100); // avoid 100% CPU + + EraseBlock(tempraw); + Sleep(100); // avoid 100% CPU + + FastTagFilter(tempraw); + Sleep(100); // avoid 100% CPU + + NumSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + EraseSymbols(tempraw); + Sleep(100); // avoid 100% CPU + + AmountWspcRem = g_plugin.getByte(hContact, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + + SaveToFile(hContact, tempraw); + db_free(&tdbv); + } + } + } + strncpy(truncated, tempraw, mir_strlen(truncated)); + return wasAlert; +} + +/*****************************************************************************/ +int DataWndAlertCommand(WPARAM wParam, LPARAM) +{ + MCONTACT hContact = wParam; + if (WindowList_Find(hWindowList, hContact)) + return 0; + + HWND hwndDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DISPLAY_DATA), nullptr, DlgProcDisplayData, hContact); + HWND hTopmost = g_plugin.getByte(hContact, ON_TOP_KEY, 0) ? HWND_TOPMOST : HWND_NOTOPMOST; + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM)((HICON)LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + if (g_plugin.getByte(SAVE_INDIVID_POS_KEY, 0)) + SetWindowPos(hwndDlg, hTopmost, + g_plugin.getDword(hContact, "WVx", 100), // Xposition, + g_plugin.getDword(hContact, "WVy", 100), // Yposition, + g_plugin.getDword(hContact, "WVwidth", 100), // WindowWidth, + g_plugin.getDword(hContact, "WVheight", 100), 0); // WindowHeight, + else + SetWindowPos(hwndDlg, HWND_TOPMOST, Xposition, Yposition, WindowWidth, WindowHeight, 0); + + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + return 0; +} + +/*****************************************************************************/ +void ReadFromFile(void *param) +{ + MCONTACT hContact = (UINT_PTR)param; + + DBVARIANT dbv; + char truncated[MAXSIZE1]; + int AmountWspcRem = 0; + int fileexists = 0; + + HWND hwndDlg = WindowList_Find(hWindowList, hContact); + + char contactname[100]; contactname[0] = 0; + if (!db_get_s(hContact, "CList", "MyHandle", &dbv)) { + strncpy_s(contactname, _countof(contactname), dbv.pszVal, _TRUNCATE); + db_free(&dbv); + } + + if (g_plugin.getString(hContact, CACHE_FILE_KEY, &dbv)) + return; + + FILE *pfile; + if ((pfile = fopen(dbv.pszVal, "r")) == nullptr) { + SendToRichEdit(hwndDlg, Translate("Cannot read from cache file"), TextClr, BackgoundClr); + fileexists = 0; + } + else { + fread(truncated, sizeof(truncated), 1, pfile); + fclose(pfile); + fileexists = 1; + } + + db_free(&dbv); + + if (fileexists) { + CodetoSymbol(truncated); + Sleep(100); // avoid 100% CPU + + EraseBlock(truncated); + Sleep(100); // avoid 100% CPU + + FastTagFilter(truncated); + Sleep(100); // avoid 100% CPU + + NumSymbols(truncated); + Sleep(100); // avoid 100% CPU + + EraseSymbols(truncated); + Sleep(100); // avoid 100% CPU + + AmountWspcRem = g_plugin.getByte(hContact, RWSPACE_KEY, 0); + RemoveInvis(truncated, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(truncated); + + SendToRichEdit(hwndDlg, truncated, TextClr, BackgoundClr); + SetDlgItemText(hwndDlg, IDC_STATUSBAR, TranslateT("Loaded from cache")); + } +} diff --git a/protocols/WebView/src/webview_cleanup.cpp b/protocols/WebView/src/webview_cleanup.cpp new file mode 100644 index 0000000000..af620f7351 --- /dev/null +++ b/protocols/WebView/src/webview_cleanup.cpp @@ -0,0 +1,797 @@ +/* +* A plugin for Miranda IM which displays web page text in a window Copyright +* (C) 2005 Vincent Joyce. +* +* Miranda IM: the free icq client for MS Windows Copyright (C) 2000-2 +* Richard Hughes, Roland Rabien & Tristan Van de Vreede +* +* 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" +#include "webview.h" + +// /////////////////////// +// characters and symbols// +// /////////////////////// + +#define AMOUNT3 164 + +char*CharacterCodes[AMOUNT3] = +{ + """, + "&", + "<", + ">", + " ", + "¡", + "¢", + "£", + "¤", + "¥", + "¦", + "§", + "¨", + "©", + "ª", + "«", + "¬", + "­", + "®", + "¯", + "°", + "±", + "²", + "³", + "´", + "µ", + "¶", + "·", + "¸", + "¹", + "º", + "»", + "¼", + "½", + "¾", + "¿", + "À", + "Á", + "Â", + "Ã", + "Ä", + "Å", + "Æ", + "Ç", + "È", + "É", + "Ê", + "Ë", + "Ì", + "Í", + "Î", + "Ï", + "Ð", + "Ñ", + "Ò", + "Ó", + "Ô", + "Õ", + "Ö", + "×", + "Ø", + "Ù", + "Ú", + "Û", + "Ü", + "Ý", + "Þ", + "ß", + "à", + "á", + "â", + "ã", + "ä", + "å", + "æ", + "ç", + "è", + "é", + "ê", + "ë", + "ì", + "í", + "î", + "ï", + "ð", + "ñ", + "ò", + "ó", + "ô", + "õ", + "ö", + "÷", + "ø", + "ù", + "ú", + "û", + "ü", + "ý", + "þ", + "&yumil;", + "Œ", // greater that 255, extra latin characters + "œ", + "Š", + "š", + "Ÿ", + "ƒ", + "ˆ", + "˜", + "Œ", + "œ", + "Š", + "š", + "Ÿ", + "ƒ", + "ˆ", + "˜", + "–", // Misc other characters + "—", + "‘", + "’", + "‚", + "“", + "”", + "„", + "†", + "‡", + "•", + "…", + "‰", + "‹", + "›", + "€", + "ℑ", + "ℜ", + "™", + "–", + "—", + "‘", + "’", + "‚", + "“", + "”", + "„", + "†", + "‡", + "•", + "…", + "‰", + "‹", + "›", + "€", + "ℑ", + "ℜ", + "™", + " ", + " ", + " ", + " ", + " ", + " ", + "õ", // symbols without numeric code + "¿", + "¦", + "¯"}; + +char Characters[AMOUNT3] = +{ + '\"', + '&', + '<', + '>', + ' ', + '¡', + '¢', + '£', + '¤', + '¥', + '¦', + '§', + '¨', + '©', + 'ª', + '«', + '¬', + '­', + '®', + '¯', + '°', + '±', + '²', + '³', + '´', + 'µ', + '¶', + '·', + '¸', + '¹', + 'º', + '»', + '¼', + '½', + '¾', + '¿', + 'À', + 'Á', + 'Â', + 'Ã', + 'Ä', + 'Å', + 'Æ', + 'Ç', + 'È', + 'É', + 'Ê', + 'Ë', + 'Ì', + 'Í', + 'Î', + 'Ï', + 'Ð', + 'Ñ', + 'Ò', + 'Ó', + 'Ô', + 'Õ', + 'Ö', + '×', + 'Ø', + 'Ù', + 'Ú', + 'Û', + 'Ü', + 'Ý', + 'Þ', + 'ß', + 'à', + 'á', + 'â', + 'ã', + 'ä', + 'å', + 'æ', + 'ç', + 'è', + 'é', + 'ê', + 'ë', + 'ì', + 'í', + 'î', + 'ï', + 'ð', + 'ñ', + 'ò', + 'ó', + 'ô', + 'õ', + 'ö', + '÷', + 'ø', + 'ù', + 'ú', + 'û', + 'ü', + 'ý', + 'þ', + 'ÿ', + 'Œ', // greater than 255 extra latin characters + 'œ', + 'Š', + 'š', + 'Ÿ', + 'ƒ', + 'ˆ', + '˜', + 'Œ', + 'œ', + 'Š', + 'š', + 'Ÿ', + 'ƒ', + 'ˆ', + '˜', + '–', + '—', // misc other characters + '‘', + '’', + '‚', + '“', + '”', + '„', + '†', + '‡', + '•', + '…', + '‰', + '‹', + '›', + '€', + 'I', + 'R', + '™', + '–', + '—', + '‘', + '’', + '‚', + '“', + '”', + '„', + '†', + '‡', + '•', + '…', + '‰', + '‹', + '›', + '€', + 'I', + 'R', + '™', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + 'õ', + '¿', + '¦', + '¯'}; + +/*****************************************************************************/ +void CodetoSymbol(char *truncated) +{ + int counter = 0; + int position = 0, recpos = 0; + static char *stringfrompos; + + for (int n = 0; n < AMOUNT3; n++) { + while (true) { // loop forever + Sleep(1); // avoid 100% CPU + + if ( strstr(truncated, CharacterCodes[n]) != nullptr) { // does character code exist? + stringfrompos = strstr(truncated, CharacterCodes[n]); + + position = stringfrompos - truncated; + counter = 0; + while (counter != mir_strlen(CharacterCodes[n])) { + truncated[position + counter] = ' '; + counter++; + } + + truncated[(position + counter) - 1] = Characters[n]; + strncpy(&truncated[position], &truncated[position + mir_strlen(CharacterCodes[n])] - 1, mir_strlen(&truncated[position]) - 1); + } // end does character code exist? + + if (recpos == position) + break; // break out of loop if doesn't find new character code + + recpos = position; + } // end loop forever + } // for +} + +/*****************************************************************************/ +void EraseBlock(char *truncated) +{ + int counter = 0; + int positionStart = 0, positionEnd = 0; + char *stringfrompos; + int BlockLength = 0; + + char* tempraw = (char*)malloc(MAXSIZE1); + if (truncated) + strncpy(tempraw, truncated, MAXSIZE1); + + // /////////////////////////// + + while (true) { + Sleep(1); // avoid 100% CPU + // /get start and end of block + + if (strstr(tempraw, "") != nullptr) // does tag exist? + { + stringfrompos = strstr(tempraw, "-->"); + positionEnd = stringfrompos - tempraw; + } + BlockLength = (positionEnd - positionStart) + 3; + + if ((strstr(tempraw, "") == nullptr)) + break; + + ///////////////////////////////////////// + + if (strstr(tempraw, "