From 2eb1daf5d940beac69c2cf9de0d27c74adb03a37 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 28 Jul 2013 11:52:10 +0000 Subject: WebView (not compilable yet): - projects for Visual Studio; - correct source folders; git-svn-id: http://svn.miranda-ng.org/main/trunk@5506 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/WebView/src/Version.h | 14 + plugins/WebView/src/main.cpp | 346 ++++++ plugins/WebView/src/resource.h | 138 +++ plugins/WebView/src/stdafx.cpp | 18 + plugins/WebView/src/stdafx.h | 39 + plugins/WebView/src/webview.cpp | 1083 +++++++++++++++++++ plugins/WebView/src/webview.h | 423 ++++++++ plugins/WebView/src/webview_alerts.cpp | 1306 ++++++++++++++++++++++ plugins/WebView/src/webview_cleanup.cpp | 633 +++++++++++ plugins/WebView/src/webview_common.h | 174 +++ plugins/WebView/src/webview_datawnd.cpp | 999 +++++++++++++++++ plugins/WebView/src/webview_getdata.cpp | 957 ++++++++++++++++ plugins/WebView/src/webview_opts.cpp | 1742 ++++++++++++++++++++++++++++++ plugins/WebView/src/webview_private.h | 23 + plugins/WebView/src/webview_services.cpp | 772 +++++++++++++ 15 files changed, 8667 insertions(+) create mode 100644 plugins/WebView/src/Version.h create mode 100644 plugins/WebView/src/main.cpp create mode 100644 plugins/WebView/src/resource.h create mode 100644 plugins/WebView/src/stdafx.cpp create mode 100644 plugins/WebView/src/stdafx.h create mode 100644 plugins/WebView/src/webview.cpp create mode 100644 plugins/WebView/src/webview.h create mode 100644 plugins/WebView/src/webview_alerts.cpp create mode 100644 plugins/WebView/src/webview_cleanup.cpp create mode 100644 plugins/WebView/src/webview_common.h create mode 100644 plugins/WebView/src/webview_datawnd.cpp create mode 100644 plugins/WebView/src/webview_getdata.cpp create mode 100644 plugins/WebView/src/webview_opts.cpp create mode 100644 plugins/WebView/src/webview_private.h create mode 100644 plugins/WebView/src/webview_services.cpp (limited to 'plugins/WebView/src') diff --git a/plugins/WebView/src/Version.h b/plugins/WebView/src/Version.h new file mode 100644 index 0000000000..65c0ab9893 --- /dev/null +++ b/plugins/WebView/src/Version.h @@ -0,0 +1,14 @@ +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 1 +#define __RELEASE_NUM 3 +#define __BUILD_NUM 0 + +#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM + +#define __PLUGIN_NAME "Webview Protocol" +#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 __AUTHOREMAIL "ungoliante666@hotmail.com" +#define __AUTHORWEB "http://miranda-ng.org/p/WebView/" +#define __COPYRIGHT "© 2011 Vincent Joyce" diff --git a/plugins/WebView/src/main.cpp b/plugins/WebView/src/main.cpp new file mode 100644 index 0000000000..4fd58a9e79 --- /dev/null +++ b/plugins/WebView/src/main.cpp @@ -0,0 +1,346 @@ +/* + * 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_common.h" + +static HANDLE hAddSite = NULL; +static HANDLE hAutoUpdate = NULL; +static HANDLE hNetlibUser = NULL; +static HANDLE hWindowList = NULL; +HMODULE hRichEd = NULL; +int hLangpack = 0; + +PLUGININFOEX pluginInfoEx = { + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // {CD5427FB-5320-4f65-B4BF-86B7CF7B5087} + {0xcd5427fb, 0x5320, 0x4f65, { 0xb4, 0xbf, 0x86, 0xb7, 0xcf, 0x7b, 0x50, 0x87}} +}; + +/********************************/ + +int WebsiteContactCommand(WPARAM wParam, LPARAM lParam) +{ + WebsiteMenuCommand((WPARAM) wParam, (LPARAM) lParam); + return 0; +} + +/*******************************/ + +/*******************************/ + +void InitServices() +{ + char SvcFunc[100]; + + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PS_GETCAPS); + CreateServiceFunction(SvcFunc, GetCaps); + + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PS_GETNAME); + CreateServiceFunction(SvcFunc, GetName); + + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PS_LOADICON); + CreateServiceFunction(SvcFunc, BPLoadIcon); + + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PS_SETSTATUS); + CreateServiceFunction(SvcFunc, SetStatus); + + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PS_GETSTATUS); + CreateServiceFunction(SvcFunc, GetStatus); + // + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PS_BASICSEARCH); + CreateServiceFunction(SvcFunc, BasicSearch); + + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PS_ADDTOLIST); + CreateServiceFunction(SvcFunc, AddToList); + + strcpy(SvcFunc, MODULENAME); + strcat(SvcFunc, PSS_GETINFO); + CreateServiceFunction(SvcFunc, 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 (HANDLE hContact = db_find_first(MODULENAME); hContact != NULL; hContact = db_find_next(hContact, MODULENAME)) + db_set_w(hContact, MODULENAME, "Status", status_code); +} + +/***********************/ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + hInst = hinstDLL; + return TRUE; +} + +/*******************/ +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfoEx; +} + +/******************/ +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; + +/************************/ +extern "C" int __declspec(dllexport) Unload(void) +{ + ChangeContactStatus(0); + + KillTimer(NULL, timerId); + KillTimer(NULL, Countdown); + + db_set_b(NULL, MODULENAME, HAS_CRASHED_KEY, 0); + SavewinSettings(); + if (hRichEd) + FreeLibrary(hRichEd); + + if (hNetlibUser) + Netlib_CloseHandle(hNetlibUser); + if (hHookDisplayDataAlert) + UnhookEvent(hHookDisplayDataAlert); + if (hHookAlertPopup) + UnhookEvent(hHookAlertPopup); + if (hHookAlertWPopup) + UnhookEvent(hHookAlertWPopup); + + hNetlibUser = NULL; + if (h_font != NULL) + DeleteObject(h_font); + if (hMenu) + DestroyMenu(hMenu); + if (hAddSite) + UnhookEvent(hAddSite); + if (hWindowList ) + UnhookEvent(hWindowList); + + DestroyServiceFunction(0); + + return 0; +} + +/***************************************/ +extern "C" int __declspec(dllexport) Load() +{ + mir_getLP(&pluginInfoEx); + + char countername[100]; + DBVARIANT dbv; + HGENMENU hRoot; + + strncpy_s(optionsname, MODULENAME, sizeof(optionsname)); + optionsname[0] = toupper(optionsname[0]); + + HookEvent(ME_CLIST_DOUBLECLICKED, Doubleclick); + + hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT)); + hRichEd = LoadLibraryA("Riched20.dll"); + + /*TIMERS*/ + if ((db_get_dw(NULL, MODULENAME, REFRESH_KEY, 0) != 0)) { + timerId = SetTimer(NULL, 0, ((db_get_dw(NULL, MODULENAME, REFRESH_KEY, 0)) * MINUTE), (TIMERPROC) timerfunc); + db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, 0); + Countdown = SetTimer(NULL, 0, MINUTE, (TIMERPROC) Countdownfunc); + } + + CheckDbKeys(); + InitialiseGlobals(); + + // register netlib handle + char tempNdesc[50]; + mir_snprintf(tempNdesc, SIZEOF(tempNdesc), "%s connection settings", MODULENAME); + + NETLIBUSER nlu = { sizeof(nlu) }; + nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS; + nlu.szSettingsModule = MODULENAME; + nlu.szDescriptiveName = tempNdesc; + hNetlibUser = (HANDLE) CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM) & nlu); + + // register webview protocol + PROTOCOLDESCRIPTOR pd = { sizeof(pd) }; + pd.szName = MODULENAME; + pd.type = PROTOTYPE_PROTOCOL; + CallService(MS_PROTO_REGISTERMODULE, 0, (LPARAM)&pd); + + //protocol services + InitServices(); + + //add sound event to options + SkinAddNewSoundEx("webviewalert", optionsname, Translate("Alert Event")); + + //add module to known list + db_set_s(NULL, "KnownModules", "Webview Protocol", MODULENAME); + + //value is 1 if menu is disabled + db_set_b(NULL, MODULENAME, MENU_IS_DISABLED_KEY, 1); + + CLISTMENUITEM mi = { sizeof(mi) }; + if ( db_get_b(NULL, MODULENAME, MENU_OFF, 0)) { + //value is 0 if menu is enabled + db_set_b(NULL, MODULENAME, MENU_IS_DISABLED_KEY, 0); + + /*DISABLE WEBVIEW*/ + CreateServiceFunction("DisableWebview", AutoUpdateMCmd); + + mi.position = 20200001; + mi.pszPopupName = optionsname; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SITE)); + if (db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0)) + mi.pszName = "Auto Update Disabled"; + + if (!(db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0))) + mi.pszName = "Auto Update Enabled"; + + mi.pszService = "DisableWebview"; + hMenuItem1 = Menu_AddMainMenuItem(&mi); + + /* + * Update all webview contacts + */ + + CreateServiceFunction("UpdateAll", UpdateAllMenuCommand); + + mi.position = 500090002; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_UPDATEALL)); + mi.pszName = "Update All Webview Sites"; + mi.pszService = "UpdateAll"; + Menu_AddMainMenuItem(&mi); + + /* + * Mark All Webview Sites Read + */ + + CreateServiceFunction("MarkAllSitesRead", MarkAllReadMenuCommand); + + mi.position = 500090099; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_MARKALLREAD)); + mi.pszName = "Mark All Webview Sites Read"; + mi.pszService = "MarkAllSitesRead"; + Menu_AddMainMenuItem(&mi); + + /* + * open cache directory + */ + CreateServiceFunction("OpenCacheFolder", OpenCacheDir); + mi.position = 500090099; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_FOLDER)); + mi.pszName = "Open Cache Folder"; + mi.pszService = "OpenCacheFolder"; + Menu_AddMainMenuItem(&mi); + + /* + * Countdown test + */ + + CreateServiceFunction("Countdown", CountdownMenuCommand); + + mi.position = 600090099;; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_UPDATEALL)); + mi.pszContactOwner = NULL; + sprintf(countername, "%d Minutes to Update", db_get_dw(NULL, MODULENAME, COUNTDOWN_KEY, 0)); + mi.pszName = countername; + + mi.pszService = "Countdown"; + hMenuItemCountdown = Menu_AddMainMenuItem(&mi); + } + + /* + * contact menu + */ + CreateServiceFunction("Open web page", WebsiteMenuCommand); + mi.position = 100; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_URL)); + mi.pszContactOwner = MODULENAME; + mi.pszService = "Open web page"; + mi.pszName = "Open web page"; + Menu_AddContactMenuItem(&mi); + + CreateServiceFunction("OpenClose Window", DataWndMenuCommand); + mi.pszService = "OpenClose Window"; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SHOW_HIDE)); + mi.pszName = "Open/Close window"; + Menu_AddContactMenuItem(&mi); + + mi.position = 2222220; + mi.pszService = "UpdateData"; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_UPDATE)); + mi.pszName = "Update Data"; + Menu_AddContactMenuItem(&mi); + + CreateServiceFunction("ContactOptions", CntOptionsMenuCommand); + mi.pszService = "ContactOptions"; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_OPTIONS)); + mi.pszName = "Contact Options"; + Menu_AddContactMenuItem(&mi); + + CreateServiceFunction("ContactAlertOpts", CntAlertMenuCommand); + mi.pszService = "ContactAlertOpts"; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ALERT)); + mi.pszName = "Contact Alert Options"; + Menu_AddContactMenuItem(&mi); + + CreateServiceFunction("PingWebsite", PingWebsiteMenuCommand); + mi.pszService = "PingWebsite"; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PING)); + mi.pszName = "Ping Web Site"; + Menu_AddContactMenuItem(&mi); + + CreateServiceFunction("StopDataProcessing", StpPrcssMenuCommand); + mi.pszService = "StopDataProcessing"; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_STOP)); + mi.pszName = "Stop Data Processing"; + Menu_AddContactMenuItem(&mi); + + hWindowList = (HANDLE) CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0); + + HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged); + HookEvent(ME_DB_CONTACT_DELETED, SiteDeleted); + + db_set_b(NULL, MODULENAME, HAS_CRASHED_KEY, 1); + return 0; +} diff --git a/plugins/WebView/src/resource.h b/plugins/WebView/src/resource.h new file mode 100644 index 0000000000..108b7303b8 --- /dev/null +++ b/plugins/WebView/src/resource.h @@ -0,0 +1,138 @@ +#define UNI 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_STATIC 444 +#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/plugins/WebView/src/stdafx.cpp b/plugins/WebView/src/stdafx.cpp new file mode 100644 index 0000000000..1ddfafbbbd --- /dev/null +++ b/plugins/WebView/src/stdafx.cpp @@ -0,0 +1,18 @@ +/* +Copyright (C) 2012-13 Miranda NG Project (http://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/plugins/WebView/src/stdafx.h b/plugins/WebView/src/stdafx.h new file mode 100644 index 0000000000..3a9966067a --- /dev/null +++ b/plugins/WebView/src/stdafx.h @@ -0,0 +1,39 @@ +#define _CRT_SECURE_NO_WARNINGS + +#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 +#include +#include + +#include "resource.h" +#include "Version.h" diff --git a/plugins/WebView/src/webview.cpp b/plugins/WebView/src/webview.cpp new file mode 100644 index 0000000000..6e693b5726 --- /dev/null +++ b/plugins/WebView/src/webview.cpp @@ -0,0 +1,1083 @@ +/* + * 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" + +static HANDLE hAddSite = NULL; +static HANDLE hAutoUpdate = NULL; +char*WndClass = "WEBWnd"; +WNDCLASSEX wincl; +MSG messages; +DWORD winheight; +int StartUpDelay = 0; + +/*************************/ +void ChangeMenuItem1() +{ + /* + * Enable or Disable auto updates + */ + ZeroMemory(&mi, sizeof(mi)); + mi.cbSize = sizeof(mi); + mi.flags = CMIM_NAME | CMIM_ICON; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SITE)); + + if (!(db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0))) + mi.pszName = Translate("Auto Update Enabled"); + + if ((db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0))) + mi.pszName = Translate("Auto Update Disabled"); + + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM) hMenuItem1, (LPARAM) & mi); +} + +/**********************/ + + +/*************************/ +void ChangeMenuItemCountdown() +{ + /* + * countdown + */ + + ZeroMemory(&mi, sizeof(mi)); + mi.cbSize = sizeof(mi); + mi.flags = CMIM_NAME | CMIM_ICON; + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_UPDATEALL)); + + char countername[100]; + sprintf(countername, "%d Minutes to Update", db_get_dw(NULL, MODULENAME, COUNTDOWN_KEY, 0)); + mi.pszName = countername; + + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM) hMenuItemCountdown, (LPARAM) & mi); +} + +/**********************/ + + + +/*********************/ +static int CALLBACK EnumFontsProc(ENUMLOGFONTEX * lpelfe, NEWTEXTMETRICEX * lpntme, int FontType, 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(HWND hwndDlg) +{ + LOGFONT lf = {0}; + HDC hdc = GetDC(hwndDlg); + + lf.lfCharSet = DEFAULT_CHARSET; + lf.lfFaceName[0] = 0; + lf.lfPitchAndFamily = 0; + EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC) EnumFontsProc, (LPARAM) GetDlgItem(hwndDlg, IDC_TYPEFACE), 0); + ReleaseDC(hwndDlg, hdc); + return; +} +/*********************/ + +/*******************************/ + +void TxtclrLoop() +{ + HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + char*szProto; + + while (hContact != NULL) + { + szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); + // + if (szProto != NULL && !lstrcmp(MODULENAME, szProto)) + { + + HWND hwndDlg = (WindowList_Find(hWindowList, hContact)); + + SetDlgItemText(hwndDlg, IDC_DATA, ""); + InvalidateRect(hwndDlg, NULL, 1); + } + // + hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0); + } + +} +/***************************/ +/*******************************/ + +void BGclrLoop() +{ + HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + char*szProto; + + while (hContact != NULL) + { + szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); + // + if (szProto != NULL && !lstrcmp(MODULENAME, szProto)) + { + + HWND hwndDlg = (WindowList_Find(hWindowList, hContact)); + + SetDlgItemText(hwndDlg, IDC_DATA, ""); + SendMessage(GetDlgItem(hwndDlg, IDC_DATA), EM_SETBKGNDCOLOR, 0, BackgoundClr); + InvalidateRect(hwndDlg, NULL, 1); + } + // + hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0); + } + +} +/***************************/ + +void StartUpdate(void *dummy) +{ + HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + char*szProto; + + StartUpDelay = 1; + + Sleep(((db_get_dw(NULL, MODULENAME, START_DELAY_KEY, 0)) * SECOND)); + + while (hContact != NULL) + { + szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); + // + if (szProto != NULL && !lstrcmp(MODULENAME, szProto)) + GetData(hContact); + // + hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0); + } + StartUpDelay = 0; +} +/*******************************/ + +void ContactLoop(void *dummy) +{ + HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + char*szProto; + char galert[300]; + + if (StartUpDelay == 0) + { + + while (hContact != NULL) + { + szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); + // + if (szProto != NULL && !lstrcmp(MODULENAME, szProto)) + + GetData(hContact); + //forkthread(GetData, 0, hContact); + Sleep(10); // avoid 100% CPU + // + + hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0); + } + } + sprintf(galert, "%s", (Translate("All Webview sites have been updated."))); + WAlertPopup((WPARAM) NULL, galert); +} + +/***************************/ + + +/****************************/ + /**********************/ +int MarkAllReadMenuCommand(WPARAM wParam, LPARAM lParam) +{ + ChangeContactStatus(1); + return 0; +} +/*************************/ + +/****************************/ + + + + +/**********************/ +void InitialiseGlobals(void) +{ + + Xposition = db_get_dw(NULL, MODULENAME, Xpos_WIN_KEY, 0); + + Yposition = db_get_dw(NULL, MODULENAME, Ypos_WIN_KEY, 0); + + if (Yposition == -32000) + Yposition = 100; + + if (Xposition == -32000) + Xposition = 100; + + BackgoundClr = db_get_dw(NULL, MODULENAME, BG_COLOR_KEY, 0); + + TextClr = db_get_dw(NULL, MODULENAME, TXT_COLOR_KEY, 0); + + WindowHeight = db_get_dw(NULL, MODULENAME, WIN_HEIGHT_KEY, 0); + + WindowWidth = db_get_dw(NULL, MODULENAME, WIN_WIDTH_KEY, 0); + +} +/********************************/ + +/***************************/ +int Doubleclick(WPARAM wParam, LPARAM lParam) +{ + DBVARIANT dbv; + char*szProto = NULL; + char url[300]; + + url[0] = '\0'; + + szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); + +// write default values first time contact is double clicked + if (DBGetContactSetting((HANDLE) wParam, MODULENAME, DBLE_WIN_KEY, &dbv)) + { + if (!(lstrcmp(MODULENAME, szProto))) + db_set_b((HANDLE) wParam, MODULENAME, DBLE_WIN_KEY, 1); + } + + //szProto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, wParam, 0); + + if (szProto != NULL) + { + if (!(lstrcmp(MODULENAME, szProto))) + { + // + if (!(db_get_b((HANDLE) wParam, MODULENAME, DBLE_WIN_KEY, 0))) + { + DBGetContactSetting((HANDLE) wParam, MODULENAME, "URL", &dbv); + wsprintf(url, "%s", dbv.pszVal); + CallService(MS_UTILS_OPENURL, 1, (WPARAM) url); + DBFreeVariant(&dbv); + db_set_w((HANDLE) wParam, MODULENAME, "Status", ID_STATUS_ONLINE); + } + // + + if ((db_get_b((HANDLE) wParam, MODULENAME, DBLE_WIN_KEY, 0))) + { + HWND hwndDlg; + + if ((hwndDlg = (WindowList_Find(hWindowList, (HANDLE) wParam)))) + { + SetForegroundWindow(hwndDlg); + SetFocus(hwndDlg); + } else + { + hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DISPLAY_DATA), NULL, DlgProcDisplayData, (LPARAM) (HANDLE) wParam); + + if (db_get_b((HANDLE) wParam, MODULENAME, ON_TOP_KEY, 0)) + { + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) ((HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + + if ((db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))) + { + SetWindowPos( + hwndDlg, + HWND_TOPMOST, + db_get_dw((HANDLE) wParam, MODULENAME, "WVx", 100), // Xposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVy", 100), // Yposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVwidth", 412), // WindowWidth, + db_get_dw((HANDLE) wParam, MODULENAME, "WVheight", 350), // WindowHeight, + 0); + } else + { + SetWindowPos( + hwndDlg, + HWND_TOPMOST, + Xposition, + Yposition, + WindowWidth, + WindowHeight, + 0); + } + + } + if (!(db_get_b((HANDLE) wParam, MODULENAME, ON_TOP_KEY, 0))) + {// + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) ((HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_UNSTICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + + if ((db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))) + { + SetWindowPos( + hwndDlg, + HWND_NOTOPMOST, + db_get_dw((HANDLE) wParam, MODULENAME, "WVx", 100), // Xposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVy", 100), // Yposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVwidth", 412), // WindowWidth, + db_get_dw((HANDLE) wParam, MODULENAME, "WVheight", 350), // WindowHeight, + 0); + } else + { + SetWindowPos( + hwndDlg, + HWND_NOTOPMOST, + Xposition, + Yposition, + WindowWidth, + WindowHeight, + 0); + } + + } + } + // + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + // + + if ((db_get_b(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, 0))) + { + if ((db_get_b((HANDLE) wParam, MODULENAME, ENABLE_ALERTS_KEY, 0))) + forkthread(ReadFromFile, 0, (HANDLE) wParam); + else + forkthread(GetData, 0, (HANDLE) wParam); + db_set_w((HANDLE) wParam, MODULENAME, "Status", ID_STATUS_ONLINE); + } + } + // + return 1; + } + } + return 0; +} +/**************************/ + +/***************************/ +//int SendToRichEdit(HWND hWindow, char *truncated, COLORREF rgbText, COLORREF rgbBack) +int SendToRichEdit(HWND hWindow, TCHAR *truncated, COLORREF rgbText, COLORREF rgbBack) +{ + + CHARFORMAT2 cfFM; + DBVARIANT dbv; + DWORD bold = 0; + DWORD italic = 0; + DWORD underline = 0; + + // + + // ////// + int len; + + //MessageBox(NULL, "Test", "0", MB_OK); + + + len = GetWindowTextLength(GetDlgItem(hWindow, IDC_DATA)); + + // + SetDlgItemText(hWindow, IDC_DATA, ""); + + //MessageBox(NULL, "Test", "1", MB_OK); + + // + ZeroMemory(&cfFM, 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 ((db_get_b(NULL, MODULENAME, FONT_BOLD_KEY, 0))) + bold = CFE_BOLD; + + if ((db_get_b(NULL, MODULENAME, FONT_ITALIC_KEY, 0))) + italic = CFE_ITALIC; + + if ((db_get_b(NULL, MODULENAME, FONT_UNDERLINE_KEY, 0))) + underline = CFE_UNDERLINE; + + cfFM.dwEffects = bold | italic | underline; + + // ///////// + + //MessageBox(NULL, "Test", "2", MB_OK); + + /**/ + if (!DBGetContactSetting(NULL, MODULENAME, FONT_FACE_KEY, &dbv)) + { +/* +#ifdef UNICODE_VERISON + MultiByteToWideChar(CP_ACP, 0, (TCHAR *) cfFM.szFaceName, -1, (wchar_t *) dbv.pszVal, 200); +#endif +*/ +//#ifndef UNICODE_VERISON + lstrcpy(cfFM.szFaceName, dbv.pszVal); +//#endif + DBFreeVariant(&dbv); + } + /**/ + + //MessageBox(NULL, "Test", "3", MB_OK); +// + + HDC hDC; + hDC = GetDC(hWindow); + cfFM.yHeight = (BYTE) MulDiv(abs(lf.lfHeight), 120, GetDeviceCaps(GetDC(hWindow), LOGPIXELSY)) * (db_get_b(NULL, MODULENAME, FONT_SIZE_KEY, 0)); + ReleaseDC(hWindow, hDC); +// + cfFM.bCharSet = db_get_b(NULL, MODULENAME, FONT_SCRIPT_KEY, 1); + + cfFM.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; + + cfFM.crTextColor = rgbText; + + cfFM.crBackColor = rgbBack; + + SendMessage(GetDlgItem(hWindow, IDC_DATA), EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) & cfFM); + + //MessageBox(NULL, "Test", "4", MB_OK); + +// ////////////////////////// + + SendDlgItemMessage(hWindow, IDC_DATA, EM_SETSEL, 0, -1); + + // MessageBox(NULL, "Test", "5", MB_OK); +//// +#ifdef UNICODE_VERISON + + wchar_t tmp4[strlen(truncated)]; + + + int c = lstrlenA(truncated); + +MultiByteToWideChar(CP_UTF8, 0, (CHAR *)truncated, -1, tmp4, strlen(truncated)); + + + +//SetDlgItemTextW(hwndDlg, IDC_DATA, (wchar_t *)&tmp2); +//MessageBoxW(NULL, tmp2, L"OOOO", MB_OK); +SendDlgItemMessageW(hWindow, IDC_DATA, EM_REPLACESEL, FALSE, (LPARAM) tmp4); + #endif + +#ifndef UNICODE_VERISON + SendDlgItemMessage(hWindow, IDC_DATA, EM_REPLACESEL, FALSE, (LPARAM) truncated); + #endif +//// + // MessageBox(NULL, "Test", "6", MB_OK); + + SendMessage(GetDlgItem(hWindow, IDC_DATA), EM_SETCHARFORMAT, SCF_ALL, (LPARAM) & cfFM); + // MessageBox(NULL, "Test", "7", MB_OK); + + return 1; +} + +/*************************/ + +/*******************************/ +void timerfunc(void) +{ + db_set_b(NULL, MODULENAME, HAS_CRASHED_KEY, 0); + + if (!(db_get_b(NULL, MODULENAME, OFFLINE_STATUS, 0))) + { + if (!(db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0))) + forkthread(ContactLoop, 0, NULL); + } + + db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, 0); +} +/*******************************/ + + +/*******************************/ +void Countdownfunc(void) +{ +DWORD timetemp=100; +//char tempcnterchar[100]; +DBVARIANT dbv; + +timetemp=(db_get_dw(NULL, MODULENAME, COUNTDOWN_KEY, (DWORD)&dbv)); + DBFreeVariant(&dbv); + +// sprintf(tempcnterchar, "%d", timetemp); +//MessageBox(NULL, tempcnterchar, "1", MB_OK); + + if((timetemp < 0) || (timetemp ==0)) + { + timetemp=(db_get_dw(NULL, MODULENAME, REFRESH_KEY, (DWORD)&dbv)); + db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, timetemp); + DBFreeVariant(&dbv); + } + +//sprintf(tempcnterchar, "%d", timetemp); +//MessageBox(NULL, tempcnterchar, "2", MB_OK); + +timetemp = timetemp - 1; + + + +db_set_dw(NULL, MODULENAME, COUNTDOWN_KEY, timetemp); + +//sprintf(tempcnterchar, "%d", timetemp); +//MessageBox(NULL, tempcnterchar, "3", MB_OK); + + ChangeMenuItemCountdown(); + +} +/*******************************/ + +/****************/ +static int OptInitialise(WPARAM wParam, LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp = {0}; + + ZeroMemory(&odp, sizeof(odp)); + odp.cbSize = sizeof(odp); + odp.position = 0; + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCE(IDD_OPT); + odp.pszGroup = Translate("Network"); + odp.pszTitle = optionsname; + odp.pfnDlgProc = DlgProcOpt; + odp.flags = ODPF_BOLDGROUPS; + odp.expertOnlyControls = expertOnlyControls; + odp.nExpertOnlyControls = sizeof(expertOnlyControls) / sizeof(expertOnlyControls[0]); + CallService(MS_OPT_ADDPAGE, wParam, (LPARAM) & odp); + + // if popup service exists + if ((ServiceExists(MS_POPUP_ADDPOPUP))) + { + ZeroMemory(&odp, sizeof(odp)); + odp.cbSize = sizeof(odp); + odp.position = 100000000; + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCE(IDD_POPUP); + odp.pszTitle = optionsname; + odp.pszGroup = Translate("PopUps"); + odp.groupPosition = 910000000; + odp.flags = ODPF_BOLDGROUPS; + odp.pfnDlgProc = DlgPopUpOpts; + CallService(MS_OPT_ADDPAGE, wParam, (LPARAM) & odp); + } + return 0; +} +/***************/ + +/**********/ + +void FontSettings(void) +{ + char fontfacename[20]; + + ZeroMemory(&fontfacename, sizeof(fontfacename)); + + lf.lfHeight = 16; + lf.lfWidth = 0; + lf.lfEscapement = 0; + lf.lfOrientation = 0; + lf.lfWeight = FW_NORMAL; + lf.lfItalic = FALSE; + lf.lfUnderline = FALSE; + lf.lfStrikeOut = 0; + lf.lfCharSet = ANSI_CHARSET; + lf.lfOutPrecision = OUT_DEFAULT_PRECIS; + lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; + lf.lfQuality = DEFAULT_QUALITY; + lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN; + lstrcpy(lf.lfFaceName, "Courier"); + +} + +/************/ +int ModulesLoaded(WPARAM wParam, LPARAM lParam) +{ + HookEvent(ME_OPT_INITIALISE, OptInitialise); + + hHookDisplayDataAlert = CreateHookableEvent(ME_DISPLAYDATA_ALERT); + HookEvent(ME_DISPLAYDATA_ALERT, DataWndAlertCommand); + + hHookAlertPopup = CreateHookableEvent(ME_POPUP_ALERT); + HookEvent(ME_POPUP_ALERT, PopupAlert); + + hHookAlertWPopup = CreateHookableEvent(ME_WPOPUP_ALERT); + HookEvent(ME_WPOPUP_ALERT, WPopupAlert); + + hHookErrorPopup = CreateHookableEvent(ME_POPUP_ERROR); + HookEvent(ME_POPUP_ERROR, ErrorMsgs); + + hHookAlertOSD = CreateHookableEvent(ME_OSD_ALERT); + HookEvent(ME_OSD_ALERT, OSDAlert); + + FontSettings(); + + h_font = CreateFontIndirect(&lf); + +// get data on startup + if ((db_get_b(NULL, MODULENAME, UPDATE_ONSTART_KEY, 0))) + forkthread(StartUpdate, 0, NULL); + +/****END ALWAYS****/ + + return 0; +} +/*********/ + +/***********************/ +int DataWndMenuCommand(WPARAM wParam, LPARAM lParam) +{ + HWND hwndDlg; + + if ((hwndDlg = (WindowList_Find(hWindowList, (HANDLE) wParam)))) + { + DestroyWindow(hwndDlg); + return 0; + } else + { + + hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DISPLAY_DATA), NULL, DlgProcDisplayData, (LPARAM) (HANDLE) wParam); + + if (db_get_b((HANDLE) wParam, MODULENAME, ON_TOP_KEY, 0)) + { + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) ((HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + if ((db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))) + { + SetWindowPos( + hwndDlg, + HWND_TOPMOST, + db_get_dw((HANDLE) wParam, MODULENAME, "WVx", 100), // Xposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVy", 100), // Yposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVwidth", 100), // WindowWidth, + db_get_dw((HANDLE) wParam, MODULENAME, "WVheight", 100), // WindowHeight, + 0); + } else + { + SetWindowPos( + hwndDlg, + HWND_TOPMOST, + Xposition, + Yposition, + WindowWidth, + WindowHeight, + 0); + + } + } + if (!(db_get_b((HANDLE) wParam, MODULENAME, ON_TOP_KEY, 0))) + {// + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) ((HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_UNSTICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + + if ((db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))) + { + SetWindowPos( + hwndDlg, + HWND_NOTOPMOST, + db_get_dw((HANDLE) wParam, MODULENAME, "WVx", 100), // Xposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVy", 100), // Yposition, + db_get_dw((HANDLE) wParam, MODULENAME, "WVwidth", 100), // WindowWidth, + db_get_dw((HANDLE) wParam, MODULENAME, "WVheight", 100), // WindowHeight, + 0); + } else + { + SetWindowPos( + hwndDlg, + HWND_NOTOPMOST, + Xposition, + Yposition, + WindowWidth, + WindowHeight, + 0); + } + + } + } + + // + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + // + if ((db_get_b(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, 0))) + { + if ((db_get_b((HANDLE) wParam, MODULENAME, ENABLE_ALERTS_KEY, 0))) + forkthread(ReadFromFile, 0, (HANDLE) wParam); + else + forkthread(GetData, 0, (HANDLE) wParam); + db_set_w((HANDLE) wParam, MODULENAME, "Status", ID_STATUS_ONLINE); + } + + return 0; +} + +/***********************/ + +/**********************/ +INT_PTR UpdateAllMenuCommand(WPARAM wParam, LPARAM lParam) +{ + forkthread(ContactLoop, 0, NULL); + return 0; +} +/*************************/ + +/************************/ +INT_PTR AutoUpdateMCmd(WPARAM wParam, LPARAM lParam) +{ + if (db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0)) + db_set_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0); + else if (!(db_get_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0))) + db_set_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 1); + + ChangeMenuItem1(); + return 0; +} +/**********************/ + +/***************************/ +int AddContactMenuCommand(WPARAM wParam, LPARAM lParam) +{ + db_set_s(NULL, "FindAdd", "LastSearched", MODULENAME); + CallService(MS_FINDADD_FINDADD, 0, 0); + return 0; +} +/***************************/ + +/***********************/ +int OnTopMenuCommand(WPARAM wParam, LPARAM lParam, HANDLE singlecontact) +{ + int ontop = 0; + int done = 0; + + if (((db_get_b(singlecontact, MODULENAME, ON_TOP_KEY, 0))) && done == 0) + { + db_set_b(singlecontact, MODULENAME, ON_TOP_KEY, 0); + ontop = 0; + done = 1; + } + if ((!(db_get_b(singlecontact, MODULENAME, ON_TOP_KEY, 0))) && done == 0) + { + db_set_b(singlecontact, MODULENAME, ON_TOP_KEY, 1); + ontop = 1; + done = 1; + } + return 0; +} +/*********************/ + +/********************/ +int WebsiteMenuCommand(WPARAM wParam, LPARAM lParam) +{ + DBVARIANT dbv; + char url[300]; + + url[0] = '\0'; +// + DBGetContactSetting((HANDLE) wParam, MODULENAME, "URL", &dbv); + wsprintf(url, "%s", dbv.pszVal); + CallService(MS_UTILS_OPENURL, 1, (WPARAM) url); + DBFreeVariant(&dbv); + db_set_w((HANDLE) wParam, MODULENAME, "Status", ID_STATUS_ONLINE); +// / + + return 0; +} +/*******************/ + + + +/****************/ +int UpdateMenuCommand(WPARAM wParam, LPARAM lParam, HANDLE singlecontact) +{ + + forkthread(GetData, 0, singlecontact); + + return 0; +} + +/***************/ + + +/*******************/ +int ContactMenuItemUpdateData (WPARAM wParam, LPARAM lParam) +{ +UpdateMenuCommand(wParam, lParam, (HANDLE) wParam); +return 0; +} +/*******************/ + + + +/********************/ +int CntOptionsMenuCommand(WPARAM wParam, LPARAM lParam) +{ + +HWND hwndDlg; + + if ((hwndDlg = (WindowList_Find(hWindowList, (HANDLE) wParam)))) + { + DestroyWindow(hwndDlg); + return 0; + } else + { + hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CONTACT_OPT ), NULL, DlgProcContactOpt, (LPARAM) (HANDLE) wParam); + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + } + return 0; +} +/*******************/ + +/********************/ +int CntAlertMenuCommand(WPARAM wParam, LPARAM lParam) +{ + +HWND hwndDlg; + + if ((hwndDlg = (WindowList_Find(hWindowList, (HANDLE) wParam)))) + { + DestroyWindow(hwndDlg); + return 0; + } else + { + hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ALRT_OPT), NULL, DlgProcAlertOpt, (LPARAM) (HANDLE) wParam); + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + } + return 0; +} +/*******************/ + +int CountdownMenuCommand(WPARAM wParam, LPARAM lParam) +{ + + return 0; +} + +/**************/ + +void CheckDbKeys(void) +{ + DBVARIANT dbv; + + if (DBGetContactSetting(NULL, MODULENAME, HAS_CRASHED_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, HAS_CRASHED_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, UPDATE_ONSTART_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, UPDATE_ONSTART_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, MENU_OFF, &dbv)) + { + db_set_b(NULL, MODULENAME, MENU_OFF, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, Ypos_WIN_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, Ypos_WIN_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, Xpos_WIN_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, Xpos_WIN_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, REFRESH_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, REFRESH_KEY, TIME); + DBFreeVariant(&dbv); + } + + if (DBGetContactSetting(NULL, MODULENAME, BG_COLOR_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, BG_COLOR_KEY, Def_color_bg); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, TXT_COLOR_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, TXT_COLOR_KEY, Def_color_txt); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, WIN_HEIGHT_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, WIN_HEIGHT_KEY, 152); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, SUPPRESS_ERR_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, SUPPRESS_ERR_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, WIN_WIDTH_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, WIN_WIDTH_KEY, 250); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, OFFLINE_STATUS, &dbv)) + { + db_set_b(NULL, MODULENAME, OFFLINE_STATUS, 1); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, UPDATE_ON_OPEN_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, FONT_FACE_KEY, &dbv)) + { + db_set_s(NULL, MODULENAME, FONT_FACE_KEY, "Courier"); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, FONT_BOLD_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, FONT_BOLD_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, FONT_ITALIC_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, FONT_ITALIC_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, FONT_UNDERLINE_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, FONT_UNDERLINE_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, FONT_SIZE_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, FONT_SIZE_KEY, 14); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, ERROR_POPUP_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, ERROR_POPUP_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, POP_DELAY_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, POP_DELAY_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, POP_BG_CLR_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, POP_BG_CLR_KEY, Def_color_bg); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, POP_TXT_CLR_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, POP_TXT_CLR_KEY, Def_color_txt); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, POP_USEWINCLRS_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, POP_USEWINCLRS_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, MENU_IS_DISABLED_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, MENU_IS_DISABLED_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, UPDATE_ONALERT_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, UPDATE_ONALERT_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, DISABLE_AUTOUPDATE_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, POP_USESAMECLRS_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, POP_USESAMECLRS_KEY, 1); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, POP_USECUSTCLRS_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, POP_USECUSTCLRS_KEY, 0); + DBFreeVariant(&dbv); + } + // + if (DBGetContactSetting(NULL, MODULENAME, LCLK_WINDOW_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, LCLK_WINDOW_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, LCLK_WEB_PGE_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, LCLK_WEB_PGE_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, LCLK_DISMISS_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, LCLK_DISMISS_KEY, 1); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, RCLK_WINDOW_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, RCLK_WINDOW_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, RCLK_WEB_PGE_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, RCLK_WEB_PGE_KEY, 1); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, RCLK_DISMISS_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, RCLK_DISMISS_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, START_DELAY_KEY, &dbv)) + { + db_set_dw(NULL, MODULENAME, START_DELAY_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, NO_PROTECT_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, NO_PROTECT_KEY, 0); + DBFreeVariant(&dbv); + } + if (DBGetContactSetting(NULL, MODULENAME, FONT_SCRIPT_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, FONT_SCRIPT_KEY, 0); + DBFreeVariant(&dbv); + } + + if (DBGetContactSetting(NULL, MODULENAME, DATA_POPUP_KEY, &dbv)) + { + db_set_b(NULL, MODULENAME, DATA_POPUP_KEY, 0); + DBFreeVariant(&dbv); + } + +// if (DBGetContactSetting(NULL, MODULENAME, INBUILTPOP_KEY, &dbv)) +// { +// db_set_b(NULL, MODULENAME, INBUILTPOP_KEY, 0); +// DBFreeVariant(&dbv); +// } + + +} + +/***************/ diff --git a/plugins/WebView/src/webview.h b/plugins/WebView/src/webview.h new file mode 100644 index 0000000000..d78adc247c --- /dev/null +++ b/plugins/WebView/src/webview.h @@ -0,0 +1,423 @@ +/* + * 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. + */ + +#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 INBUILTPOP_KEY "UseInbuiltPopupAlert" + +#define TIME 60 +#define Def_color_bg 0x00ffffff +#define Def_color_txt 0x00000000 +#define HK_SHOWHIDE 3001 + +#define MAXSIZE1 250000 +#define MAXSIZE2 500000 +#define MAXSIZE3 1000000 + +static UINT expertOnlyControls[] = +{IDC_ADV_GRP, + IDC_NO_PROTECT, +IDC_NOT_RECOMND_TXT}; + +//lets get rid of some warnings +void ErrorMsgs(char *contactname, char *displaytext); +void CodetoSymbol(char *truncated); +static void GetData(void *hContact); +BOOL CALLBACK DlgProcDisplayData(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +void FillFontListThread(HWND hwndDlg); +static BOOL CALLBACK DlgProcAlertOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +int DataWndAlertCommand(void *AContact); + + + // /////////////////////// +// 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', + '™', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + 'õ', + '¿', + '¦', +'¯'}; diff --git a/plugins/WebView/src/webview_alerts.cpp b/plugins/WebView/src/webview_alerts.cpp new file mode 100644 index 0000000000..285d3d34ea --- /dev/null +++ b/plugins/WebView/src/webview_alerts.cpp @@ -0,0 +1,1306 @@ +/* + * 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" + +static HANDLE hWindowList = NULL; + +/**********************************/ +int CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact; + char popupurl[300]; + DBVARIANT dbv; + + hContact = PUGetContact(hWnd); + + ZeroMemory(&popupurl, sizeof(popupurl)); + DBGetContactSetting(hContact, MODULENAME, URL_KEY, &dbv); + _snprintf(popupurl, sizeof(popupurl), "%s", dbv.pszVal); + DBFreeVariant(&dbv); + + switch (message) + { + case WM_COMMAND: + case WM_CONTEXTMENU: + { + if (message == WM_COMMAND) // left click + { + if(hContact != NULL) + { + // open data window + + if ((db_get_b(NULL, MODULENAME, LCLK_WINDOW_KEY, 0))) + { + NotifyEventHooks(hHookDisplayDataAlert, (int) hContact, 0); + forkthread(GetData, 0, hContact); + PUDeletePopUp(hWnd); + } + // open url + if ((db_get_b(NULL, MODULENAME, LCLK_WEB_PGE_KEY, 0))) + { + CallService(MS_UTILS_OPENURL, (WPARAM) 1, (LPARAM) popupurl); + PUDeletePopUp(hWnd); + db_set_w((HANDLE) wParam, MODULENAME, "Status", ID_STATUS_ONLINE); + } + // dismiss + if ((db_get_b(NULL, MODULENAME, LCLK_DISMISS_KEY, 0))) + { + PUDeletePopUp(hWnd); + } + + + } + + else if(hContact == NULL) + PUDeletePopUp(hWnd); + + } + + + + else if (message == WM_CONTEXTMENU) // right click + + { + if(hContact != NULL) + { + + // open datA window + + if ((db_get_b(NULL, MODULENAME, RCLK_WINDOW_KEY, 0))) + { + NotifyEventHooks(hHookDisplayDataAlert, (int) hContact, 0); + forkthread(GetData, 0, hContact); + PUDeletePopUp(hWnd); + } + // open url + if ((db_get_b(NULL, MODULENAME, RCLK_WEB_PGE_KEY, 0))) + { + CallService(MS_UTILS_OPENURL, (WPARAM) 1, (LPARAM) popupurl); + PUDeletePopUp(hWnd); + db_set_w((HANDLE) wParam, MODULENAME, "Status", ID_STATUS_ONLINE); + } + // dismiss + if ((db_get_b(NULL, MODULENAME, RCLK_DISMISS_KEY, 0))) + { + PUDeletePopUp(hWnd); + } + } + else if(hContact == NULL) + PUDeletePopUp(hWnd); + } + + + + } + break; + } + + return DefWindowProc(hWnd, message, wParam, lParam); +} +/*********************************/ + +/*******************/ +int WDisplayDataAlert(void *AContact) +{ + NotifyEventHooks(hHookDisplayDataAlert, (int) AContact, 0); + return 0; +} +/**************/ + +/*******************/ +int WAlertPopup(WPARAM hContact, char *displaytext) +{ + NotifyEventHooks(hHookAlertPopup, (WPARAM) hContact, (LPARAM) displaytext); + return 0; +} +/**************/ + +/*******************/ +//int WAlertPopup(WPARAM hContact, char *displaytext) +int WAlertWPopup(WPARAM hContact, WCHAR *displaytext) +{ + NotifyEventHooks(hHookAlertWPopup, (WPARAM) hContact, (LPARAM) displaytext); + return 0; +} +/**************/ + + +/*******************/ +int WErrorPopup(char *namecontact, char *textdisplay) +{ + NotifyEventHooks(hHookErrorPopup, (WPARAM) namecontact, (LPARAM) textdisplay); + return 0; +} +/**************/ +/*******************/ +int WAlertOSD(WPARAM hContact, char *displaytext) +{ + NotifyEventHooks(hHookAlertOSD, (WPARAM) hContact, (LPARAM) displaytext); + return 0; +} +/**************/ + +/********************/ + +int WPopupAlert(WPARAM wParam, WCHAR *displaytext) +{ + POPUPDATAW ppd; + DWORD delay = 0; + DWORD colorBack, colorText; + char contactname[255]; + DBVARIANT dbv; + char delaystr[4]; + + // setup the popup + ZeroMemory(&ppd, sizeof(POPUPDATAW)); + ZeroMemory(&contactname, sizeof(contactname)); + +if( ((HANDLE)wParam) != NULL) +{ + DBGetContactSetting((HANDLE) wParam, MODULENAME, PRESERVE_NAME_KEY, &dbv); + _snprintf(contactname, sizeof(contactname), "%s", dbv.pszVal); + DBFreeVariant(&dbv); +} +else +_snprintf(contactname, sizeof(contactname), "%s", MODULENAME); + + + ppd.lchContact = (HANDLE) wParam; + // + MultiByteToWideChar(CP_UTF8, 0, contactname, -1, ppd.lptzContactName, strlen(contactname)); + // + ppd.lchIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SITE)); + // + if ((wcslen(displaytext) == MAX_SECONDLINE) || (wcslen(displaytext) > MAX_SECONDLINE)) + _snwprintf(ppd.lptzText,MAX_SECONDLINE -1, displaytext); + else if (wcslen(displaytext) < MAX_SECONDLINE) + swprintf(ppd.lptzText, displaytext); + + // + if ((db_get_b(NULL, MODULENAME, POP_USECUSTCLRS_KEY, 0))) + { + colorBack = db_get_dw(NULL, MODULENAME, POP_BG_CLR_KEY, 0); + colorText = db_get_dw(NULL, MODULENAME, POP_TXT_CLR_KEY, 0); + } + if ((db_get_b(NULL, MODULENAME, POP_USEWINCLRS_KEY, 0))) + { + colorBack = GetSysColor(COLOR_BTNFACE); + colorText = GetSysColor(COLOR_WINDOWTEXT); + } + if ((db_get_b(NULL, MODULENAME, POP_USESAMECLRS_KEY, 0))) + { + colorBack = BackgoundClr; + colorText = TextClr; + } + ppd.colorBack = colorBack; + ppd.colorText = colorText; + // + ppd.PluginWindowProc = NULL; + // + //ppd.iSeconds = (atol("5")); + delay = db_get_dw(NULL, MODULENAME, POP_DELAY_KEY, 0); + ppd.iSeconds = delay; + // + + if (ServiceExists(MS_POPUP_ADDPOPUPW)) + CallService(MS_POPUP_ADDPOPUPW, (WPARAM) &ppd, 0); + + + + + + ////////////////////////////////////////////////////////////////////// + +// if ((db_get_b(NULL, MODULENAME, INBUILTPOP_KEY, 0))) +// PUShowMessage(displaytext, SM_NOTIFY); +// else +// { +// } + + return 0; + +} +/********************/ +/********************/ + +int PopupAlert(WPARAM wParam, char *displaytext) +{ + POPUPDATAEX ppd; + DWORD delay = 0; + DWORD colorBack, colorText; + char contactname[255]; + DBVARIANT dbv; + char delaystr[4]; + + // setup the popup + ZeroMemory(&ppd, sizeof(POPUPDATA)); + ZeroMemory(&contactname, sizeof(contactname)); + +if( ((HANDLE)wParam) != NULL) +{ + DBGetContactSetting((HANDLE) wParam, MODULENAME, PRESERVE_NAME_KEY, &dbv); + _snprintf(contactname, sizeof(contactname), "%s", dbv.pszVal); + DBFreeVariant(&dbv); +} +else +_snprintf(contactname, sizeof(contactname), "%s", MODULENAME); + + + + ppd.lchContact = (HANDLE) wParam; + strcpy(ppd.lpzContactName, contactname); + ppd.lchIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SITE)); + // + //sprintf(ppd.lpzText, Translate("This is a preview popup.")); + if ((strlen(displaytext) == MAX_SECONDLINE) || (strlen(displaytext) > MAX_SECONDLINE)) + _snprintf(ppd.lpzText,MAX_SECONDLINE -1, "%s", displaytext); + else if (strlen(displaytext) < MAX_SECONDLINE) + sprintf(ppd.lpzText, Translate(displaytext)); + // + if ((db_get_b(NULL, MODULENAME, POP_USECUSTCLRS_KEY, 0))) + { + colorBack = db_get_dw(NULL, MODULENAME, POP_BG_CLR_KEY, 0); + colorText = db_get_dw(NULL, MODULENAME, POP_TXT_CLR_KEY, 0); + } + if ((db_get_b(NULL, MODULENAME, POP_USEWINCLRS_KEY, 0))) + { + colorBack = GetSysColor(COLOR_BTNFACE); + colorText = GetSysColor(COLOR_WINDOWTEXT); + } + if ((db_get_b(NULL, MODULENAME, POP_USESAMECLRS_KEY, 0))) + { + colorBack = BackgoundClr; + colorText = TextClr; + } + ppd.colorBack = colorBack; + ppd.colorText = colorText; + // + ppd.PluginWindowProc = NULL; + // + //ppd.iSeconds = (atol("5")); + delay = db_get_dw(NULL, MODULENAME, POP_DELAY_KEY, 0); + ppd.iSeconds = delay; + // + + if (ServiceExists(MS_POPUP_ADDPOPUPEX)) + CallService(MS_POPUP_ADDPOPUPEX, (WPARAM) &ppd, 0); + + + + + ////////////////////////////////////////////////////////////////////// + +// if ((db_get_b(NULL, MODULENAME, INBUILTPOP_KEY, 0))) +// PUShowMessage(displaytext, SM_NOTIFY); +// else +// { +// } + + return 0; + +} +/********************/ + +/********************/ + +int OSDAlert(WPARAM wParam, char *displaytext) +{ + char contactname[255]; + DBVARIANT dbv; + char newdisplaytext[2000]; + + ZeroMemory(&contactname, sizeof(contactname)); + ZeroMemory(&newdisplaytext, sizeof(newdisplaytext)); + + +if(((HANDLE)wParam) != NULL) +{ + DBGetContactSetting((HANDLE) wParam, MODULENAME, PRESERVE_NAME_KEY, &dbv); + _snprintf(contactname, sizeof(contactname), "%s", dbv.pszVal); + DBFreeVariant(&dbv); +} +else +_snprintf(contactname, sizeof(contactname), "%s", MODULENAME); + + + _snprintf(newdisplaytext, sizeof(newdisplaytext), "%s: %s", contactname, Translate(displaytext)); + + if (ServiceExists("OSD/Announce")) + CallService("OSD/Announce", (WPARAM) newdisplaytext, 0); + + return 0; +} +/********************/ + +/*****************/ +void ErrorMsgs(char *contactname, char *displaytext) +{ + char newdisplaytext[2000]; + + if (!(db_get_b(NULL, MODULENAME, SUPPRESS_ERR_KEY, 0))) + { + if ((ServiceExists(MS_POPUP_ADDPOPUP) != 0) && ((db_get_b(NULL, MODULENAME, ERROR_POPUP_KEY, 0)))) + { + _snprintf(newdisplaytext, sizeof(newdisplaytext), "%s\n%s", contactname, displaytext); + PUShowMessage(newdisplaytext, SM_WARNING); + } else if ((ServiceExists("OSD/Announce") != 0) && ((db_get_b(NULL, MODULENAME, ERROR_POPUP_KEY, 0)))) + { + _snprintf(newdisplaytext, sizeof(newdisplaytext), "%s: %s", contactname, Translate(displaytext)); + CallService("OSD/Announce", (WPARAM) newdisplaytext, 0); + } else if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) + { + MIRANDASYSTRAYNOTIFY webview_tip = {0}; + + webview_tip.cbSize = sizeof(MIRANDASYSTRAYNOTIFY); + webview_tip.szProto = NULL; + webview_tip.szInfoTitle = contactname; + webview_tip.szInfo = Translate(displaytext); + webview_tip.dwInfoFlags = NIIF_ERROR; + webview_tip.uTimeout = 15000; + CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM) &webview_tip); + } // //////////// + + } +} +/********************/ + +/***************************/ +void SaveToFile(char *AContact, char *truncated) +{ + FILE *pfile; + char*mode; + DBVARIANT dbv; + char url[300]; + char contactname[100]; + + ZeroMemory(&contactname, sizeof(contactname)); + DBGetContactSetting(AContact, "CList", "MyHandle", &dbv); + _snprintf(contactname, sizeof(contactname), "%s", dbv.pszVal); + DBFreeVariant(&dbv); + + if (!(db_get_b(AContact, MODULENAME, APPEND_KEY, 0))) + mode = "w"; + else + mode = "a"; + + url[0] = '\0'; + + DBGetContactSetting(AContact, MODULENAME, URL_KEY, &dbv); + _snprintf(url, sizeof(url), "%s", dbv.pszVal); + + DBFreeVariant(&dbv); + + DBGetContactSetting(AContact, MODULENAME, FILE_KEY, &dbv); + if ((pfile = fopen(dbv.pszVal, mode)) == NULL) + { + WErrorPopup(contactname, Translate("Cannot write to file")); + } else + { +// + + char tstr[128]; + char timestring[128]; + char timeprefix[32]; + char temptime1[32]; + char temptime2[32]; + char temptime[128]; + time_t ftime; + struct tm *nTime; + + ZeroMemory(&tstr, sizeof(tstr)); + ZeroMemory(&temptime, sizeof(temptime)); + ZeroMemory(&timeprefix, sizeof(timeprefix)); + ZeroMemory(&temptime1, sizeof(temptime1)); + ZeroMemory(&temptime2, sizeof(temptime2)); + ZeroMemory(×tring, sizeof(timestring)); + + setlocale(LC_ALL, ""); + + ftime = time(NULL); + nTime = localtime(&ftime); + + _snprintf(timeprefix, sizeof(timeprefix), " %s ", (Translate("Last updated on"))); + strftime(temptime1, 32, " %a, %b %d, %Y ", nTime); + strftime(temptime2, 32, " %I:%M %p.", nTime); + _snprintf(timestring, sizeof(timestring), "(%s)%s\n%s,%s\n", MODULENAME, url, temptime1, temptime2); + + fputs(timestring, pfile); +// + + fwrite(truncated, strlen(truncated), 1, pfile); + + fputs("\n\n", pfile); + + fclose(pfile); + } + + DBFreeVariant(&dbv); +} + +/***************************/ + +/**************************/ +int ProcessAlerts(HANDLE AContact, char *truncated, char *tstr, char *contactname, int notpresent) +{ + + char alertstring[255]; + char displaystring[300]; + FILE *pcachefile; + char cachepath[MAX_PATH]; + char cachedirectorypath[MAX_PATH]; + char newcachepath[MAX_PATH + 50]; + char*cacheend; + 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]; + + // + char tempraw[MAXSIZE1]; + char statustext[200]; + int alertIndex = 0; + int eventIndex = 0; + +//MessageBox(NULL, contactname, "pro-contname2", MB_OK); + + ZeroMemory(&tempraw, sizeof(tempraw)); + ZeroMemory(&raw, sizeof(raw)); + + strncpy(tempraw, truncated, sizeof(tempraw)); + + ZeroMemory(&alertstring, sizeof(alertstring)); + ZeroMemory(&cachepath, sizeof(cachepath)); + ZeroMemory(&cachedirectorypath, sizeof(cachedirectorypath)); + ZeroMemory(&newcachepath, sizeof(newcachepath)); + ZeroMemory(&Alerttempstring, sizeof(Alerttempstring)); + ZeroMemory(&Alerttempstring2, sizeof(Alerttempstring2)); + ZeroMemory(&cachecompare, sizeof(cachecompare)); + + // + + // alerts + if ((db_get_b(AContact, MODULENAME, ENABLE_ALERTS_KEY, 0))) // ALERTS + // + // ARE + // ENABLED + + { + + if (!DBGetContactSetting(AContact, MODULENAME, ALRT_INDEX_KEY, &tdbv)) // TYPES + // + // OF + // ALERTS + + { + alertIndex = db_get_b(AContact, MODULENAME, ALRT_INDEX_KEY, 0); + DBFreeVariant(&tdbv); + + if (!DBGetContactSetting(AContact, MODULENAME, EVNT_INDEX_KEY, &tdbv)) + { + + eventIndex = db_get_b(AContact, MODULENAME, EVNT_INDEX_KEY, 0); + DBFreeVariant(&tdbv); + } + if ((notpresent)) + { + if (alertIndex == 0) // Popup + + { + Sleep(1000); + sprintf(displaystring, "%s", (Translate("Start/end strings not found or strings not set."))); + WAlertPopup((WPARAM) AContact, displaystring); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } // + + else if (alertIndex == 1) // log to file + + { + if (!DBGetContactSetting(AContact, MODULENAME, FILE_KEY, &tdbv)) + { + int AmountWspcRem = 0; + + if (!(db_get_b(AContact, MODULENAME, 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 = db_get_b(AContact, MODULENAME, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + // + SaveToFile(AContact, tempraw); + DBFreeVariant(&tdbv); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } + } // + + else if (alertIndex == 3) // osd + + { + WAlertOSD((WPARAM) AContact, Translate("Alert start/end strings not found or strings not set.")); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } else if (eventIndex == 2) // window + + { + WDisplayDataAlert(AContact); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + + HWND hwndDlg = (WindowList_Find(hWindowList, AContact)); + + ZeroMemory(&statustext, sizeof(statustext)); + _snprintf(statustext, sizeof(statustext), " %s", Translate("Start/end strings not found or strings not set.")); + SetDlgItemText(hwndDlg, IDC_STATUSBAR, statustext); + } // + + else + MessageBox(NULL, Translate("Start/end strings not found or strings not set."), MODULENAME, MB_OK); + } + if (eventIndex == 0) // string present + + { + + if (!DBGetContactSetting(AContact, MODULENAME, ALERT_STRING_KEY, &tdbv)) + { + strncpy(alertstring, tdbv.pszVal, sizeof(alertstring)); + DBFreeVariant(&tdbv); + + if ((strstr(tempraw, alertstring)) != 0) + { // // ENDALERT EVENT:CHECK FOR STRING + + // there was an alert + wasAlert = 1; + + // play sound? + SkinPlaySound("webviewalert"); + // + if ((!notpresent)) + { + + if (alertIndex == 0) // popup + + { + sprintf(displaystring, "%s \"%s\" %s.", (Translate("The string")), alertstring, (Translate("has been found on the web page"))); + WAlertPopup((WPARAM) AContact, displaystring); + + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } // + + else if (alertIndex == 1) // LOG + + { + if (!DBGetContactSetting(AContact, MODULENAME, FILE_KEY, &tdbv)) + { + + int AmountWspcRem = 0; + + if (!(db_get_b(AContact, MODULENAME, 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 = db_get_b(AContact, MODULENAME, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + // + } + SaveToFile(AContact, tempraw); + DBFreeVariant(&tdbv); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } + } // + + else if (alertIndex == 3) // osd + + { + sprintf(displaystring, "%s \"%s\" %s.", (Translate("The string")), alertstring, (Translate("has been found on the web page"))); + WAlertOSD((WPARAM) AContact, displaystring); + + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } else if (alertIndex == 2) // window + + { + WDisplayDataAlert(AContact); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + + HWND hwndDlg = (WindowList_Find(hWindowList, AContact)); + + ZeroMemory(&statustext, sizeof(statustext)); + _snprintf(statustext, sizeof(statustext), " %s", Translate("Download successful; about to process data...")); + SetDlgItemText(hwndDlg, IDC_STATUSBAR, statustext); + } // + + else + MessageBox(NULL, Translate("Unknown Alert Type."), MODULENAME, MB_OK); + } + // + } // // END ALERT EVENT:CHECK FOR STRING + + } // alert string + + } else if (eventIndex == 1) // webpage changed + + { + + // TEST GET NAME FOR CACHE + GetModuleFileName(hInst, cachepath, sizeof(cachepath)); + cacheend = strrchr(cachepath, '\\'); + cacheend++; + *cacheend = '\0'; + + _snprintf(cachedirectorypath, sizeof(cachedirectorypath), "%s%s%s", cachepath, MODULENAME, "cache\\"); + CreateDirectory(cachedirectorypath, NULL); + _snprintf(newcachepath, sizeof(newcachepath), "%s%s%s%s%s", cachepath, MODULENAME, "cache\\", contactname, ".txt"); + // file exists? + if ((_access(newcachepath, 0)) != -1) + { + if ((pcachefile = fopen(newcachepath, "r")) == NULL) + { + WErrorPopup(contactname, Translate("Cannot read from file")); + } else + { + ZeroMemory(&cachecompare, sizeof(cachecompare)); + fread(cachecompare, sizeof(cachecompare), 1, pcachefile); + fclose(pcachefile); + } + } + // write to cache + if ((pcachefile = fopen(newcachepath, "w")) == NULL) + { + WErrorPopup(contactname, Translate("Cannot write to file 1")); + MessageBox(NULL, newcachepath, "1", MB_OK); + } else + { + + fwrite(tempraw, strlen(tempraw), 1, pcachefile); //smaller cache + fclose(pcachefile); + db_set_s(AContact, MODULENAME, CACHE_FILE_KEY, newcachepath); + } + // end write to cache + + if (strncmp(tempraw, cachecompare, (strlen(tempraw))) != 0) //lets try this instead + { + + // play sound? + SkinPlaySound("webviewalert"); + // there was an alert + wasAlert = 1; + + if ((!notpresent)) + { + + if (alertIndex == 0) // popup + + { + WAlertPopup((WPARAM) AContact, Translate("The Web Page Has Changed.")); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } // + + else if (alertIndex == 3) // osd + + { + WAlertOSD((WPARAM) AContact, Translate("The Web Page Has Changed.")); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } else if (alertIndex == 1) // log + + { + if (!DBGetContactSetting(AContact, MODULENAME, FILE_KEY, &tdbv)) + { + int AmountWspcRem = 0; + + if (!(db_get_b(AContact, MODULENAME, 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 = db_get_b(AContact, MODULENAME, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + // + SaveToFile(AContact, tempraw); + DBFreeVariant(&tdbv); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } + } // + + else if (alertIndex == 2) // window + + { + WDisplayDataAlert(AContact); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } // + + else + MessageBox(NULL, Translate("Unknown Alert Type."), MODULENAME, MB_OK); + } + } + } +// + + if (eventIndex == 2) // part of webpage changed + + { + + // ////////// + // + DBGetContactSetting(AContact, MODULENAME, ALRT_S_STRING_KEY, &tdbv); + _snprintf(Alerttempstring, sizeof(Alerttempstring), "%s", tdbv.pszVal); + DBFreeVariant(&tdbv); + // + DBGetContactSetting(AContact, MODULENAME, ALRT_E_STRING_KEY, &tdbv); + _snprintf(Alerttempstring2, sizeof(Alerttempstring2), "%s", tdbv.pszVal); + DBFreeVariant(&tdbv); + // + + // putting data into string + if (((strstr(tempraw, Alerttempstring)) != 0) && ((strstr(tempraw, Alerttempstring2)) != 0)) + { + +//start string + alertpos = strstr(tempraw, Alerttempstring); + statalertpos = alertpos - tempraw; +// + ZeroMemory(&alertpos, sizeof(alertpos)); +//end string + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + strlen(Alerttempstring2); +// + if (statalertpos > statalertposend) + { + memset(&tempraw, ' ', statalertpos); + ZeroMemory(&alertpos, sizeof(alertpos)); + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + strlen(Alerttempstring2); + } + if (statalertpos < statalertposend) + { + ZeroMemory(&raw, sizeof(raw)); + +//start string + alertpos = strstr(tempraw, Alerttempstring); + statalertpos = alertpos - tempraw; +// + +//end string + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + strlen(Alerttempstring2); +// + + if (statalertpos > statalertposend) + { + memset(&tempraw, ' ', statalertpos); + ZeroMemory(&alertpos, sizeof(alertpos)); + alertpos = strstr(tempraw, Alerttempstring2); + statalertposend = alertpos - tempraw + 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); + sprintf(displaystring, "%s", (Translate("Alert start/end strings not found or strings not set."))); + WAlertPopup((WPARAM) AContact, displaystring); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "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 (!DBGetContactSetting(AContact, MODULENAME, FILE_KEY, &tdbv)) + { + int AmountWspcRem = 0; + + if (!(db_get_b(AContact, MODULENAME, 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 = db_get_b(AContact, MODULENAME, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + // + SaveToFile(AContact, tempraw); + DBFreeVariant(&tdbv); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } + } + } // + + else if (alertIndex == 3) // osd + + { + WAlertOSD((WPARAM) AContact, Translate("Alert start/end strings not found or strings not set.")); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } else if (alertIndex == 2) // window + + { + WDisplayDataAlert(AContact); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + + HWND hwndDlg = (WindowList_Find(hWindowList, AContact)); + + ZeroMemory(&statustext, sizeof(statustext)); + _snprintf(statustext, sizeof(statustext), " %s", Translate("Alert start/end strings not found or strings not set.")); + SetDlgItemText(hwndDlg, IDC_STATUSBAR, statustext); + } // + + else + MessageBox(NULL, Translate("Alert start/end strings not found or strings not set."), MODULENAME, MB_OK); + db_set_w(AContact, MODULENAME, "Status", ID_STATUS_AWAY); + } + +/////////////// + + if (((strstr(tempraw, Alerttempstring)) != 0) && ((strstr(tempraw, Alerttempstring2)) != 0)) + { + + // TEST GET NAME FOR CACHE + GetModuleFileName(hInst, cachepath, sizeof(cachepath)); + cacheend = strrchr(cachepath, '\\'); + cacheend++; + *cacheend = '\0'; + + _snprintf(cachedirectorypath, sizeof(cachedirectorypath), "%s%s%s", cachepath, MODULENAME, "cache\\"); + CreateDirectory(cachedirectorypath, NULL); + _snprintf(newcachepath, sizeof(newcachepath), "%s%s%s%s%s", cachepath, MODULENAME, "cache\\", contactname, ".txt"); + // file exists? + if ((_access(newcachepath, 0)) != -1) + { + if ((pcachefile = fopen(newcachepath, "r")) == NULL) + { + WErrorPopup(contactname, Translate("Cannot read from file")); + } else + { + ZeroMemory(&cachecompare, sizeof(cachecompare)); + fread(cachecompare, sizeof(cachecompare), 1, pcachefile); + fclose(pcachefile); + } + } + // write to cache + if ((pcachefile = fopen(newcachepath, "w")) == NULL) + { + WErrorPopup(contactname, Translate("Cannot write to file 2")); + } else + { + fwrite(raw, strlen(raw), 1, pcachefile); //smaller cache + db_set_s(AContact, MODULENAME, CACHE_FILE_KEY, newcachepath); + fclose(pcachefile); + } + // end write to cache + if (strncmp(raw, cachecompare, (strlen(raw))) != 0) //lets try this instead + { + + // play sound? + SkinPlaySound("webviewalert"); + // there was an alert + wasAlert = 1; + + if ((!notpresent)) + { + + if (alertIndex == 0) // popup + + { + WAlertPopup((WPARAM) AContact, Translate("Specific Part Of The Web Page Has Changed.")); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } // + + else if (alertIndex == 3) // osd + + { + WAlertOSD((WPARAM) AContact, Translate("Specific Part Of The Web Page Has Changed.")); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } else if (alertIndex == 1) // log to file + + { + if (!DBGetContactSetting(AContact, MODULENAME, FILE_KEY, &tdbv)) + { + int AmountWspcRem = 0; + + if (!(db_get_b(AContact, MODULENAME, 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 = db_get_b(AContact, MODULENAME, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + // + SaveToFile(AContact, tempraw); + DBFreeVariant(&tdbv); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } + } // + + else if (alertIndex == 2) // window + + { + WDisplayDataAlert(AContact); + // contactlist name// + if ((db_get_b(AContact, MODULENAME, APND_DATE_NAME_KEY, 0))) + db_set_s(AContact, "CList", "MyHandle", tstr); + } // + + else + MessageBox(NULL, Translate("Unknown Alert Type."), MODULENAME, MB_OK); + } + } + } + } +// + } // alert type + + } + // end alerts + +//if always log to file option is enabled do this + if (wasAlert) + { + if (alertIndex != 1) // dont do for log to file alert + + { + if ((db_get_b(AContact, MODULENAME, ALWAYS_LOG_KEY, 0))) + { + if (!DBGetContactSetting(AContact, MODULENAME, FILE_KEY, &tdbv)) + { + int AmountWspcRem = 0; + + if (!(db_get_b(AContact, MODULENAME, 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 = db_get_b(AContact, MODULENAME, RWSPACE_KEY, 0); + RemoveInvis(tempraw, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(tempraw); + } + // + SaveToFile(AContact, tempraw); + DBFreeVariant(&tdbv); + } + } + } + } + strncpy(truncated, tempraw, strlen(truncated)); + + return wasAlert; +} +/**************************/ + +/***********************/ +int DataWndAlertCommand(void *AContact) +{ + HWND hwndDlg; + + if ((hwndDlg = (WindowList_Find(hWindowList, (HANDLE) AContact)))) + { + return 0; + } + hwndDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DISPLAY_DATA), NULL, DlgProcDisplayData, (LPARAM) (HANDLE) AContact); + + if (db_get_b(AContact, MODULENAME, ON_TOP_KEY, 0)) + { + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) ((HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_STICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + if ((db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))) + { + SetWindowPos( + hwndDlg, + HWND_TOPMOST, + db_get_dw(AContact, MODULENAME, "WVx", 100), // Xposition, + db_get_dw(AContact, MODULENAME, "WVy", 100), // Yposition, + db_get_dw(AContact, MODULENAME, "WVwidth", 100), // WindowWidth, + db_get_dw(AContact, MODULENAME, "WVheight", 100), // WindowHeight, + 0); + } else + { + SetWindowPos( + hwndDlg, + HWND_TOPMOST, + Xposition, + Yposition, + WindowWidth, + WindowHeight, + 0); + } + + } + if (!(db_get_b(AContact, MODULENAME, ON_TOP_KEY, 0))) + {// + SendDlgItemMessage(hwndDlg, IDC_STICK_BUTTON, BM_SETIMAGE, IMAGE_ICON, (LPARAM) ((HICON) LoadImage(hInst, MAKEINTRESOURCE(IDI_UNSTICK), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0))); + + if ((db_get_b(NULL, MODULENAME, SAVE_INDIVID_POS_KEY, 0))) + { + SetWindowPos( + hwndDlg, + HWND_NOTOPMOST, + db_get_dw(AContact, MODULENAME, "WVx", 100), // Xposition, + db_get_dw(AContact, MODULENAME, "WVy", 100), // Yposition, + db_get_dw(AContact, MODULENAME, "WVwidth", 100), // WindowWidth, + db_get_dw(AContact, MODULENAME, "WVheight", 100), // WindowHeight, + 0); + } else + { + SetWindowPos( + hwndDlg, + HWND_NOTOPMOST, + Xposition, + Yposition, + WindowWidth, + WindowHeight, + 0); + } + } + ShowWindow(hwndDlg, SW_SHOW); + SetActiveWindow(hwndDlg); + + return 0; +} + +/***********************/ +/***************************/ +static void ReadFromFile(void *AContact) +{ + FILE *pfile; + DBVARIANT dbv; + char contactname[100]; + char truncated[MAXSIZE1]; + int AmountWspcRem = 0; + int fileexists = 0; + + + HWND hwndDlg = (WindowList_Find(hWindowList, AContact)); + + ZeroMemory(&contactname, sizeof(contactname)); + DBGetContactSetting(AContact, "CList", "MyHandle", &dbv); + _snprintf(contactname, sizeof(contactname), "%s", dbv.pszVal); + DBFreeVariant(&dbv); + + + +//// + DBGetContactSetting(AContact, MODULENAME, CACHE_FILE_KEY, &dbv); +//// + if ((pfile = fopen(dbv.pszVal, "r")) == NULL) + { + //WErrorPopup(contactname, Translate("Cannot read from cache file")); + SendToRichEdit(hwndDlg, + Translate("Cannot read from cache file"), + TextClr, + BackgoundClr); + fileexists =0; + } + else + { + fread(truncated, sizeof(truncated), 1, pfile); + fclose(pfile); + fileexists =1; + } + + DBFreeVariant(&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 = db_get_b(AContact, MODULENAME, RWSPACE_KEY, 0); + RemoveInvis(truncated, AmountWspcRem); + Sleep(100); // avoid 100% CPU + + Removewhitespace(truncated); + + SendToRichEdit(hwndDlg, + truncated, + TextClr, + BackgoundClr); + + SetDlgItemText(hwndDlg, IDC_STATUSBAR, Translate("Loaded From Cache")); + + } /// +} + +/***************************/ diff --git a/plugins/WebView/src/webview_cleanup.cpp b/plugins/WebView/src/webview_cleanup.cpp new file mode 100644 index 0000000000..03fef944e5 --- /dev/null +++ b/plugins/WebView/src/webview_cleanup.cpp @@ -0,0 +1,633 @@ +/* + * 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" + +/************************/ +void CodetoSymbol(char *truncated) +{ + int counter = 0; + int position = 0, recpos = 0, n; + static char *stringfrompos; + + for (n = 0; n < AMOUNT3; n++) + { + + while (1) // loop forever + + { + Sleep(1); // avoid 100% CPU + + if (((strstr(truncated, CharacterCodes[n])) != 0)) +// does character code exist? + { + + if (strstr(truncated, CharacterCodes[n]) != 0) + { + stringfrompos = strstr(truncated, CharacterCodes[n]); + } + position = stringfrompos - truncated; + counter = 0; + while (counter != (strlen(CharacterCodes[n]))) + { + truncated[position + counter] = ' '; + counter++; + } + + truncated[(position + counter) - 1] = Characters[n]; + +// + strncpy(&truncated[position], &truncated[position + strlen(CharacterCodes[n])] - 1, 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; + char*tempraw; + int BlockLength = 0; + +// ////// + + tempraw = malloc(MAXSIZE1); + + if (truncated) + strncpy(tempraw, truncated, MAXSIZE1); + +// /////////////////////////// + +// 1// + + while (1) + { + Sleep(1); // avoid 100% CPU + // /get start and end of block + + if (strstr(tempraw, "") != 0) // does tag exist? + + { + stringfrompos = strstr(tempraw, "-->"); + positionEnd = stringfrompos - tempraw; + } + BlockLength = (positionEnd - positionStart) + 3; + + if ((strstr(tempraw, "") == 0)) + break; + +///////////////////////////////////////// + + // ///////// + if (strstr(tempraw, "