summaryrefslogtreecommitdiff
path: root/plugins/StatusPlugins/AdvancedAutoAway/trigger_aaa.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
commit48540940b6c28bb4378abfeb500ec45a625b37b6 (patch)
tree2ef294c0763e802f91d868bdef4229b6868527de /plugins/StatusPlugins/AdvancedAutoAway/trigger_aaa.cpp
parent5c350913f011e119127baeb32a6aedeb4f0d33bc (diff)
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/StatusPlugins/AdvancedAutoAway/trigger_aaa.cpp')
-rw-r--r--plugins/StatusPlugins/AdvancedAutoAway/trigger_aaa.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/plugins/StatusPlugins/AdvancedAutoAway/trigger_aaa.cpp b/plugins/StatusPlugins/AdvancedAutoAway/trigger_aaa.cpp
new file mode 100644
index 0000000000..e803c2dab4
--- /dev/null
+++ b/plugins/StatusPlugins/AdvancedAutoAway/trigger_aaa.cpp
@@ -0,0 +1,161 @@
+#include "../commonstatus.h"
+#include "advancedautoaway.h"
+#include <m_trigger.h>
+#include "trigger_aaa.h"
+#include "../resource.h"
+
+extern HINSTANCE hInst;
+static HANDLE hAAAStateChangedHook;
+
+static int AAAStateChanged(WPARAM wParam, LPARAM lParam) {
+
+ AUTOAWAYSETTING *aas;
+ DWORD triggerID;
+ REPORTINFO ri;
+ TRIGGERDATA td;
+ BOOL bReport;
+
+ aas = (AUTOAWAYSETTING *)lParam;
+ triggerID = 0;
+ do {
+ triggerID = (DWORD)CallService(MS_TRIGGER_FINDNEXTTRIGGERID, triggerID, (LPARAM)TRIGGERNAME);
+ if (triggerID == 0) {
+ continue;
+ }
+ bReport = FALSE;
+ switch (aas->curState) {
+ case STATUS1_SET:
+ if (DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_ENTERFIRST, 0)) {
+ bReport = TRUE;
+ }
+ break;
+ case STATUS2_SET:
+ if (DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_ENTERSECOND, 0)) {
+ bReport = TRUE;
+ }
+ break;
+ case SET_ORGSTATUS:
+ if ( (aas->oldState == STATUS1_SET) && (DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVEFIRST, 0)) ) {
+ bReport = TRUE;;
+ }
+ if ( (aas->oldState == STATUS2_SET) && (DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVESECOND, 0)) ) {
+ bReport = TRUE;;
+ }
+ break;
+ case HIDDEN_ACTIVE:
+ if (DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_BECOMEACTIVE, 0)) {
+ bReport = TRUE;
+ }
+ break;
+ case ACTIVE:
+ if (aas->oldState == HIDDEN_ACTIVE) {
+ char setting[128];
+ char *szProto;
+
+ szProto = DBGetContactSettingByte(NULL, MODULENAME, SETTING_SAMESETTINGS, 0)?SETTING_ALL:aas->protocolSetting->szName;
+ _snprintf(setting, sizeof(setting), "%s_Lv1Status", szProto);
+ if ( (aas->protocolSetting->lastStatus == DBGetContactSettingWord(NULL, MODULENAME, setting, ID_STATUS_AWAY)) && DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVEFIRST, 0) ) {
+ bReport = TRUE;
+ }
+
+ _snprintf(setting, sizeof(setting), "%s_Lv2Status", szProto);
+ if ( (aas->protocolSetting->lastStatus == DBGetContactSettingWord(NULL, MODULENAME, setting, ID_STATUS_NA)) && DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVESECOND, 0) ) {
+ bReport = TRUE;
+ }
+ }
+ break;
+ }
+ if (!bReport) {
+ continue;
+ }
+ ZeroMemory(&td, sizeof(td));
+ td.cbSize = sizeof(td);
+ td.dFlags = DF_PROTO|DF_STATUS|DF_TEXT;
+ td.szProto = td.szText = aas->protocolSetting->szName;
+ td.status = aas->protocolSetting->status;
+ ZeroMemory(&ri, sizeof(REPORTINFO));
+ ri.cbSize = sizeof(REPORTINFO);
+ ri.triggerID = triggerID;
+ ri.pszName = TRIGGERNAME;
+ ri.flags = TRG_PERFORM;
+ ri.td = &td;
+ CallService(MS_TRIGGER_REPORTEVENT, 0, (LPARAM)&ri);
+ } while (triggerID != 0);
+
+ return 0;
+}
+
+static INT_PTR CALLBACK DlgProcOptsAAAStateChange(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
+
+ switch (msg) {
+ case WM_INITDIALOG: {
+ DWORD triggerID;
+
+ TranslateDialogDefault(hwndDlg);
+ triggerID = (DWORD)lParam;
+ CheckDlgButton(hwndDlg, IDC_ENTERFIRST, DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_ENTERFIRST, 0)?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_ENTERSECOND, DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_ENTERSECOND, 0)?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_LEAVEFIRST, DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVEFIRST, 0)?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_LEAVESECOND, DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVESECOND, 0)?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_BECOMEACTIVE, DBGetTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_BECOMEACTIVE, 0)?BST_CHECKED:BST_UNCHECKED);
+ break;
+ }
+
+ case TM_ADDTRIGGER: {
+ // wParam = trigger ID
+ DWORD triggerID;
+
+ triggerID = (DWORD)wParam;
+ DBWriteTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_ENTERFIRST, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ENTERFIRST));
+ DBWriteTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_ENTERSECOND, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_ENTERSECOND));
+ DBWriteTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVEFIRST, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_LEAVEFIRST));
+ DBWriteTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_LEAVESECOND, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_LEAVESECOND));
+ DBWriteTriggerSettingByte(triggerID, NULL, MODULENAME, SETTING_BECOMEACTIVE, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_BECOMEACTIVE));
+ break;
+ }
+
+ case TM_DELTRIGGER: {
+ // wParam = triggerID
+ DWORD triggerID;
+ REMOVETRIGGERSETTINGS rts;
+
+ triggerID = (DWORD)wParam;
+ 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 InitTrigger() {
+
+ TRIGGERREGISTER tr;
+
+ if (!ServiceExists(MS_TRIGGER_REGISTERTRIGGER)) {
+ return -1;
+ }
+ ZeroMemory(&tr, sizeof(tr));
+ tr.cbSize = sizeof(tr);
+ tr.pszName = TRIGGERNAME;
+ tr.hInstance = hInst;
+ tr.pfnDlgProc = DlgProcOptsAAAStateChange;
+ tr.pszTemplate = MAKEINTRESOURCEA(IDD_TRG_AAASTATECHANGE);
+ tr.dFlags = DF_STATUS|DF_PROTO;
+ CallService(MS_TRIGGER_REGISTERTRIGGER, 0, (LPARAM)&tr);
+ hAAAStateChangedHook = HookEvent(ME_AAA_STATECHANGED, AAAStateChanged);
+
+ return 0;
+}
+
+int DeInitTrigger() {
+
+ UnhookEvent(hAAAStateChangedHook);
+
+ return 0;
+} \ No newline at end of file