diff options
Diffstat (limited to 'plugins/Variables/src/trigger_variables.cpp')
-rw-r--r-- | plugins/Variables/src/trigger_variables.cpp | 228 |
1 files changed, 0 insertions, 228 deletions
diff --git a/plugins/Variables/src/trigger_variables.cpp b/plugins/Variables/src/trigger_variables.cpp deleted file mode 100644 index 75920eb453..0000000000 --- a/plugins/Variables/src/trigger_variables.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/*
- Variables Plugin for Miranda-IM (www.miranda-im.org)
- Copyright 2003-2006 P. Boon
-
- This program is mir_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 "variables.h"
-
-static TRG_VAR_CACHE *tvc = NULL;
-static int tvcCount = 0;
-static unsigned int stringChangeTimerID = 0;
-
-static int addToCache(DWORD triggerID)
-{
- /* triggerID must be in the DB */
- DBVARIANT dbv;
-
- for (int i=0; i < tvcCount; i++) {
- if (tvc[i].triggerID == triggerID) {
- mir_free(tvc[i].parsedText);
- MoveMemory(&tvc[i], &tvc[tvcCount-1], sizeof(TRG_VAR_CACHE));
- tvcCount -= 1;
- }
- }
- if ( DBGetTriggerSettingTString(triggerID, NULL, MODULENAME, SETTING_TRIGGERTEXT, &dbv))
- return -1;
-
- tvc = ( TRG_VAR_CACHE* )mir_realloc(tvc, (tvcCount+1)*sizeof(TRG_VAR_CACHE));
- if (tvc == NULL)
- return -1;
-
- tvc[tvcCount].triggerID = triggerID;
- tvc[tvcCount].parsedText = variables_parsedup(dbv.ptszVal, NULL, NULL);
- // it stays in our own mem space!
- if (tvc[tvcCount].parsedText == NULL)
- return -1;
-
- tvcCount += 1;
- db_free(&dbv);
- return 0;
-}
-
-static int removeFromCache(DWORD triggerID) {
-
- int i;
-
- for (i=0;i<tvcCount;i++) {
- if (tvc[i].triggerID == triggerID) {
- mir_free(tvc[i].parsedText);
- MoveMemory(&tvc[i], &tvc[tvcCount-1], sizeof(TRG_VAR_CACHE));
- tvcCount -= 1;
- }
- }
-
- return 0;
-}
-
-static VOID CALLBACK checkStringsTimer(HWND hwnd,UINT message,UINT_PTR idEvent,DWORD dwTime)
-{
- DWORD triggerID = 0;
- do {
- triggerID = (DWORD)CallService(MS_TRIGGER_FINDNEXTTRIGGERID, triggerID, (LPARAM)TRIGGERNAME);
- if (triggerID == 0) {
- continue;
- }
- for (int i=0; i < tvcCount; i++) {
- if (triggerID != tvc[i].triggerID)
- continue;
-
- DBVARIANT dbv;
- if (!DBGetTriggerSettingTString(tvc[i].triggerID, NULL, MODULENAME, SETTING_TRIGGERTEXT, &dbv)) {
- TCHAR *parsedText = variables_parsedup(dbv.ptszVal, NULL, NULL);
- if (parsedText == NULL)
- continue;
-
- if (!_tcscmp(tvc[i].parsedText, parsedText)) {
- mir_free(parsedText);
- continue;
- }
-
- TRIGGERDATA td = { 0 };
- td.cbSize = sizeof(td);
- td.dFlags = DF_TEXT;
- td.tszText = parsedText;
-
- REPORTINFO ri = { 0 };
- ri.cbSize = sizeof(REPORTINFO);
- ri.triggerID = tvc[i].triggerID;
- ri.pszName = TRIGGERNAME;
- ri.flags = TRG_PERFORM;
- ri.td = &td;
-
- CallService(MS_TRIGGER_REPORTEVENT, 0, (LPARAM)&ri);
- mir_free(tvc[i].parsedText);
- tvc[i].parsedText = parsedText;
- db_free(&dbv);
- }
- }
- }
- while (triggerID != 0);
-}
-
-INT_PTR CALLBACK DlgProcOptsStringChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
-
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- {
- DBVARIANT dbv;
- DWORD triggerID;
-
- triggerID = (DWORD)lParam;
- if (!DBGetTriggerSetting(triggerID, NULL, MODULENAME, SETTING_TRIGGERTEXT, &dbv)) {
- SetDlgItemTextA(hwndDlg, IDC_FORMATTEXT, dbv.pszVal);
- db_free(&dbv);
- }
- variables_skin_helpbutton(hwndDlg, IDC_SHOWHELP);
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDC_SHOWHELP:
- variables_showhelp(hwndDlg, IDC_FORMATTEXT, VHF_FULLDLG|VHF_SETLASTSUBJECT, NULL, NULL);
- break;
- }
- break;
-
- case TM_ADDTRIGGER:
- // wParam = trigger ID
- // lParam = (TRIGGERREGISTER *)
- {
- DWORD triggerID = (DWORD)wParam;
- TCHAR *tszFormatText = Hlp_GetDlgItemText(hwndDlg, IDC_FORMATTEXT);
- if (tszFormatText != NULL) {
- DBWriteTriggerSettingTString(triggerID, NULL, MODULENAME, SETTING_TRIGGERTEXT, tszFormatText);
- mir_free(tszFormatText);
- }
- addToCache(triggerID);
- }
- break;
-
- case TM_DELTRIGGER:
- // wParam = triggerID
- // lParam = (TRIGGEREGISTER *) may be 0
- {
- REMOVETRIGGERSETTINGS rts;
-
- DWORD triggerID = (DWORD)wParam;
- removeFromCache(triggerID);
- rts.cbSize = sizeof(REMOVETRIGGERSETTINGS);
- rts.prefix = PREFIX_TRIGGERID;
- rts.id = triggerID;
- rts.hContact = NULL;
- rts.szModule = MODULENAME;
- CallService(MS_TRIGGER_REMOVESETTINGS, 0, (LPARAM)&rts);
- }
- break;
- }
-
- return FALSE;
-}
-
-int initTriggerModule()
-{
- log_debugA("Variables: initTriggerModule");
- if (!ServiceExists(MS_TRIGGER_REGISTERTRIGGER)) {
- log_debugA("Variables: %s does not exist", MS_TRIGGER_REGISTERTRIGGER);
- return -1;
- }
-
- TRIGGERREGISTER tr = { 0 };
- tr.cbSize = sizeof(tr);
- tr.pszName = TRIGGERNAME;
- tr.hInstance = hInst;
- tr.pfnDlgProc = DlgProcOptsStringChange;
- tr.pszTemplate = MAKEINTRESOURCEA(IDD_TRG_STRINGCHANGE);
- tr.dFlags = DF_TEXT|DF_TCHAR;
- int res = CallService(MS_TRIGGER_REGISTERTRIGGER, 0, (LPARAM)&tr);
- log_debugA("Variables: %s registered (%d)", TRIGGERNAME, res);
-
- ACTIONREGISTER ar = { 0 };
- ar.cbSize = sizeof(ACTIONREGISTER);
- ar.pszName = "Variables: Parse string";
- ar.hInstance = hInst;
- ar.pfnDlgProc = DlgProcOptsParseString;
- ar.pszTemplate = MAKEINTRESOURCEA(IDD_ACT_PARSESTRING);
- ar.actionFunction = ParseStringAction;
- ar.flags = ARF_FUNCTION|ARF_TCHAR;
- CallService(MS_TRIGGER_REGISTERACTION, 0, (LPARAM)&ar);
-
- CONDITIONREGISTER cr = { 0 };
- cr.cbSize = sizeof(CONDITIONREGISTER);
- cr.pszName = "Variables: Condition";
- cr.hInstance = hInst;
- cr.pfnDlgProc = DlgProcOptsCondition;
- cr.pszTemplate = MAKEINTRESOURCEA(IDD_CND_PARSESTRING);
- cr.conditionFunction = ParseStringCondition;
- cr.flags = CRF_FUNCTION|CRF_TCHAR;
- CallService(MS_TRIGGER_REGISTERCONDITION, 0, (LPARAM)&cr);
-
- // fill cache
- DWORD triggerID = 0;
- do {
- triggerID = (DWORD)CallService(MS_TRIGGER_FINDNEXTTRIGGERID, triggerID, (LPARAM)TRIGGERNAME);
- if (triggerID == 0) {
- continue;
- }
- addToCache(triggerID);
- }
- while (triggerID != 0);
-
- stringChangeTimerID = SetTimer(NULL, 0, CHECKSTRINGDELAY, checkStringsTimer);
- return res;
-}
|