summaryrefslogtreecommitdiff
path: root/plugins/StatusManager/src/AdvancedAutoAway
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/StatusManager/src/AdvancedAutoAway')
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp32
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp120
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h52
3 files changed, 50 insertions, 154 deletions
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
index 3a733b9074..9e979e1230 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "..\stdafx.h"
-int LoadAutoAwaySetting(TAAAProtoSetting &autoAwaySetting, char* protoName);
+int LoadAutoAwaySetting(SMProto &autoAwaySetting, char* protoName);
INT_PTR CALLBACK DlgProcAutoAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
@@ -28,7 +28,7 @@ static BOOL bSettingSame = FALSE;
/////////////////////////////////////////////////////////////////////////////////////////
// Dialog service functions
-static int WriteAutoAwaySetting(TAAAProtoSetting &autoAwaySetting, char *protoName)
+static int WriteAutoAwaySetting(SMProto &autoAwaySetting, char *protoName)
{
char setting[128];
mir_snprintf(setting, "%s_OptionFlags", protoName);
@@ -47,7 +47,7 @@ static int WriteAutoAwaySetting(TAAAProtoSetting &autoAwaySetting, char *protoNa
return 0;
}
-static void SetDialogItems(HWND hwndDlg, TAAAProtoSetting *setting)
+static void SetDialogItems(HWND hwndDlg, SMProto *setting)
{
bool bIsTimed = (setting->optionFlags & FLAG_ONMOUSE) != 0;
bool bSetNA = (setting->optionFlags & FLAG_SETNA) != 0;
@@ -83,7 +83,7 @@ static void SetDialogItems(HWND hwndDlg, TAAAProtoSetting *setting)
EnableWindow(GetDlgItem(hwndDlg, IDC_PROTOCOL), !bSettingSame);
}
-static TAAAProtoSetting* GetSetting(HWND hwndDlg, TAAAProtoSetting *sameSetting)
+static SMProto* GetSetting(HWND hwndDlg, SMProto *sameSetting)
{
if (bSettingSame)
return sameSetting;
@@ -93,12 +93,12 @@ static TAAAProtoSetting* GetSetting(HWND hwndDlg, TAAAProtoSetting *sameSetting)
return nullptr;
INT_PTR iData = (INT_PTR)SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, CB_GETITEMDATA, iItem, 0);
- return (iData == -1) ? nullptr : (TAAAProtoSetting*)iData;
+ return (iData == -1) ? nullptr : (SMProto*)iData;
}
-static void SetDialogStatus(HWND hwndDlg, TAAAProtoSetting *sameSetting)
+static void SetDialogStatus(HWND hwndDlg, SMProto *sameSetting)
{
- TAAAProtoSetting *setting = GetSetting(hwndDlg, sameSetting);
+ SMProto *setting = GetSetting(hwndDlg, sameSetting);
if (setting == nullptr)
return;
@@ -119,17 +119,17 @@ static void SetDialogStatus(HWND hwndDlg, TAAAProtoSetting *sameSetting)
/////////////////////////////////////////////////////////////////////////////////////////
// Rules dialog window procedure
-int AAACompareSettings(const TAAAProtoSetting *p1, const TAAAProtoSetting *p2)
+int AAACompareSettings(const SMProto *p1, const SMProto *p2)
{
return mir_strcmp(p1->m_szName, p2->m_szName);
}
-static TAAAProtoSettingList optionSettings(10, AAACompareSettings);
+static TProtoSettings optionSettings(10, AAACompareSettings);
static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- static TAAAProtoSetting* sameSetting;
- TAAAProtoSetting *setting;
+ static SMProto* sameSetting;
+ SMProto *setting;
static int init;
switch (msg) {
@@ -138,15 +138,15 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM
TranslateDialogDefault(hwndDlg);
// copy the settings
- optionSettings = autoAwaySettings;
+ optionSettings = protoList;
- sameSetting = (TAAAProtoSetting*)malloc(sizeof(TAAAProtoSetting));
+ sameSetting = (SMProto*)malloc(sizeof(SMProto));
LoadAutoAwaySetting(*sameSetting, SETTING_ALL);
// fill list from currentProtoSettings
{
for (int i = 0; i < optionSettings.getCount(); i++) {
- TAAAProtoSetting &p = optionSettings[i];
+ SMProto &p = optionSettings[i];
int item = SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, CB_ADDSTRING, 0, (LPARAM)p.m_tszAccName);
SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, CB_SETITEMDATA, item, (LPARAM)&p);
}
@@ -342,7 +342,7 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM
for (int i = 0; i < optionSettings.getCount(); i++)
WriteAutoAwaySetting(optionSettings[i], optionSettings[i].m_szName);
}
- AAALoadOptions(autoAwaySettings, false);
+ AAALoadOptions();
}
break;
@@ -407,7 +407,7 @@ static INT_PTR CALLBACK DlgProcAutoAwayGeneralOpts(HWND hwndDlg, UINT msg, WPARA
db_set_w(0, AAAMODULENAME, SETTING_CONFIRMDELAY, (WORD)GetDlgItemInt(hwndDlg, IDC_CONFIRMDELAY, nullptr, FALSE));
db_set_b(0, AAAMODULENAME, SETTING_MONITORMOUSE, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MONITORMOUSE));
db_set_b(0, AAAMODULENAME, SETTING_MONITORKEYBOARD, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_MONITORKEYBOARD));
- AAALoadOptions(autoAwaySettings, false);
+ AAALoadOptions();
}
break;
}
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
index 81cff37ffd..b37830b90f 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
@@ -30,28 +30,9 @@
/////////////////////////////////////////////////////////////////////////////////////////
-TAAAProtoSettingList autoAwaySettings(10, AAACompareSettings);
-
-TAAAProtoSetting::TAAAProtoSetting(PROTOACCOUNT *pa)
-{
- m_szName = pa->szModuleName;
- m_tszAccName = pa->tszAccountName;
- m_lastStatus = m_status = originalStatusMode = ID_STATUS_CURRENT;
- m_szMsg = nullptr;
- curState = ACTIVE;
- mStatus = FALSE;
-}
-
-TAAAProtoSetting::~TAAAProtoSetting()
-{
- free(m_szMsg);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
int AAALangPack;
-static HANDLE hEvents[4];
+static HANDLE hEvents[3];
static BOOL ignoreLockKeys = FALSE;
static BOOL ignoreSysKeys = FALSE;
@@ -88,21 +69,20 @@ extern char *StatusModeToDbSetting(int status, const char *suffix);
/////////////////////////////////////////////////////////////////////////////////////////
// Load from DB
-void AAAUnloadOptions(bool bOverride)
+void AAAUnloadOptions()
{
- if (!bOverride)
- UnhookWindowsHooks();
+ UnhookWindowsHooks();
if (hAutoAwayTimer != 0)
KillTimer(nullptr, hAutoAwayTimer);
}
-void AAALoadOptions(TAAAProtoSettingList &loadSettings, bool bOverride)
+void AAALoadOptions()
{
// if bOverride is enabled, samesettings will be ignored (for options loading)
int monitorMiranda = FALSE; // use windows hooks?
int monitorAll = FALSE; // use windows hooks?
- AAAUnloadOptions(bOverride);
+ AAAUnloadOptions();
ignoreLockKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNLOCK, FALSE);
ignoreSysKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNSYSKEYS, FALSE);
@@ -111,19 +91,18 @@ void AAALoadOptions(TAAAProtoSettingList &loadSettings, bool bOverride)
monitorKeyboard = db_get_b(0, AAAMODULENAME, SETTING_MONITORKEYBOARD, TRUE);
lastInput = lastMirandaInput = GetTickCount();
- for (int i = 0; i < loadSettings.getCount(); i++) {
+ for (int i = 0; i < protoList.getCount(); i++) {
char* protoName;
- if ((db_get_b(0, AAAMODULENAME, SETTING_SAMESETTINGS, 0)) && !bOverride)
+ if ((db_get_b(0, AAAMODULENAME, SETTING_SAMESETTINGS, 0)))
protoName = SETTING_ALL;
else
- protoName = loadSettings[i].m_szName;
- LoadAutoAwaySetting(loadSettings[i], protoName);
- if (!bOverride) {
- if (loadSettings[i].optionFlags & FLAG_MONITORMIRANDA)
- monitorMiranda = TRUE;
- else if (ignoreLockKeys || ignoreSysKeys || ignoreAltCombo || (monitorMouse != monitorKeyboard))
- monitorAll = TRUE;
- }
+ protoName = protoList[i].m_szName;
+ LoadAutoAwaySetting(protoList[i], protoName);
+
+ if (protoList[i].optionFlags & FLAG_MONITORMIRANDA)
+ monitorMiranda = TRUE;
+ else if (ignoreLockKeys || ignoreSysKeys || ignoreAltCombo || (monitorMouse != monitorKeyboard))
+ monitorAll = TRUE;
}
if (db_get_b(0, "Idle", "AAEnable", 0))
@@ -133,7 +112,7 @@ void AAALoadOptions(TAAAProtoSettingList &loadSettings, bool bOverride)
hAutoAwayTimer = SetTimer(nullptr, 0, db_get_w(0, AAAMODULENAME, SETTING_AWAYCHECKTIMEINSECS, 5) * 1000, AutoAwayTimer);
}
-int LoadAutoAwaySetting(TAAAProtoSetting &autoAwaySetting, char* protoName)
+int LoadAutoAwaySetting(SMProto &autoAwaySetting, char* protoName)
{
char setting[128];
mir_snprintf(setting, "%s_OptionFlags", protoName);
@@ -165,8 +144,8 @@ static int ProcessProtoAck(WPARAM, LPARAM lParam)
return 0;
log_debugA("ProcessProtoAck: ack->szModule: %s", ack->szModule);
- for (int i = 0; i < autoAwaySettings.getCount(); i++) {
- TAAAProtoSetting &p = autoAwaySettings[i];
+ for (int i = 0; i < protoList.getCount(); i++) {
+ SMProto &p = protoList[i];
log_debugA("chk: %s", p.m_szName);
if (!mir_strcmp(p.m_szName, ack->szModule)) {
log_debugA("ack->szModule: %s p.statusChanged: %d", ack->szModule, p.statusChanged);
@@ -183,27 +162,6 @@ static int ProcessProtoAck(WPARAM, LPARAM lParam)
/////////////////////////////////////////////////////////////////////////////////////////
// Account control event
-int OnAAAAccChanged(WPARAM wParam, LPARAM lParam)
-{
- PROTOACCOUNT *pa = (PROTOACCOUNT*)lParam;
- switch (wParam) {
- case PRAC_ADDED:
- autoAwaySettings.insert(new TAAAProtoSetting(pa));
- break;
-
- case PRAC_REMOVED:
- for (int i = 0; i < autoAwaySettings.getCount(); i++) {
- if (!mir_strcmp(autoAwaySettings[i].m_szName, pa->szModuleName)) {
- autoAwaySettings.remove(i);
- break;
- }
- }
- break;
- }
-
- return 0;
-}
-
static char* status2descr(int status)
{
switch (status) {
@@ -216,7 +174,7 @@ static char* status2descr(int status)
return "ERROR";
}
-static int changeState(TAAAProtoSetting &setting, STATES newState)
+static int changeState(SMProto &setting, STATES newState)
{
if (setting.curState == newState)
return 0;
@@ -254,8 +212,8 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD)
int statusChanged = FALSE;
int confirm = FALSE;
- for (int i = 0; i < autoAwaySettings.getCount(); i++) {
- TAAAProtoSetting& aas = autoAwaySettings[i];
+ for (int i = 0; i < protoList.getCount(); i++) {
+ SMProto& aas = protoList[i];
aas.m_status = ID_STATUS_DISABLED;
BOOL bTrigger = false;
@@ -362,11 +320,11 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD)
changeState(aas, ACTIVE);
aas.sts1setTimer = 0;
}
- autoAwaySettings[i].mStatus = FALSE;
+ protoList[i].mStatus = FALSE;
}
if (confirm || statusChanged) {
- TAAAProtoSettingList ps = autoAwaySettings;
+ TProtoSettings ps = protoList;
for (int i = 0; i < ps.getCount(); i++) {
if (ps[i].m_szMsg)
ps[i].m_szMsg = wcsdup(ps[i].m_szMsg);
@@ -376,7 +334,7 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD)
}
if (confirm)
- confirmDialog = ShowConfirmDialogEx((TProtoSettings*)&ps, db_get_w(0, AAAMODULENAME, SETTING_CONFIRMDELAY, 5));
+ confirmDialog = ShowConfirmDialogEx(&ps, db_get_w(0, AAAMODULENAME, SETTING_CONFIRMDELAY, 5));
else if (statusChanged)
CallService(MS_CS_SETSTATUSEX, (WPARAM)&ps, 0);
}
@@ -545,35 +503,22 @@ static LRESULT CALLBACK KeyBoardHookFunction(int code, WPARAM wParam, LPARAM lPa
static int AutoAwayShutdown(WPARAM, LPARAM)
{
- AAAUnloadOptions(false);
+ AAAUnloadOptions();
return 0;
}
int AAAModuleLoaded(WPARAM, LPARAM)
{
- hEvents[0] = HookEvent(ME_PROTO_ACCLISTCHANGED, OnAAAAccChanged);
- hEvents[1] = HookEvent(ME_OPT_INITIALISE, AutoAwayOptInitialise);
- hEvents[2] = HookEvent(ME_SYSTEM_PRESHUTDOWN, AutoAwayShutdown);
- hEvents[3] = HookEvent(ME_PROTO_ACK, ProcessProtoAck);
+ hEvents[0] = HookEvent(ME_OPT_INITIALISE, AutoAwayOptInitialise);
+ hEvents[1] = HookEvent(ME_SYSTEM_PRESHUTDOWN, AutoAwayShutdown);
+ hEvents[2] = HookEvent(ME_PROTO_ACK, ProcessProtoAck);
mouseStationaryTimer = 0;
lastInput = lastMirandaInput = GetTickCount();
////////////////////////////////////////////////////////////////////////////////////////
- protoList = (OBJLIST<PROTOCOLSETTINGEX>*)&autoAwaySettings;
-
- int count;
- PROTOACCOUNT** protos;
- Proto_EnumAccounts(&count, &protos);
-
- for (int i = 0; i < count; i++)
- if (IsSuitableProto(protos[i]))
- autoAwaySettings.insert(new TAAAProtoSetting(protos[i]));
-
- ////////////////////////////////////////////////////////////////////////////////////////
-
- AAALoadOptions(autoAwaySettings, false);
+ AAALoadOptions();
return 0;
}
@@ -581,11 +526,10 @@ void AdvancedAutoAwayLoad()
{
AAALangPack = GetPluginLangId(MIID_LAST, 0);
- if (g_bMirandaLoaded) {
+ if (g_bMirandaLoaded)
AAAModuleLoaded(0, 0);
- AutoAwayOptInitialise(0, 0);
- }
- else HookEvent(ME_SYSTEM_MODULESLOADED, AAAModuleLoaded);
+ else
+ HookEvent(ME_SYSTEM_MODULESLOADED, AAAModuleLoaded);
}
void AdvancedAutoAwayUnload()
@@ -600,5 +544,5 @@ void AdvancedAutoAwayUnload()
it = nullptr;
}
- autoAwaySettings.destroy();
+ protoList.destroy();
}
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h
index 8ba6e3f606..b6ca5cbeb6 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h
+++ b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h
@@ -33,61 +33,13 @@
#define SETTING_NATIME_DEFAULT 20
#define SETTING_AWAYCHECKTIMEINSECS "CheckInterval"
-#define STATUS_RESET 1
-#define STATUS_AUTOAWAY 2
-#define STATUS_AUTONA 3
-
#define SETTING_MONITORMOUSE "MonitorMouse"
#define SETTING_MONITORKEYBOARD "MonitorKeyboard"
-#define FLAG_ONSAVER 0x0001 // db: set lv1 status on screensaver ?
-#define FLAG_ONMOUSE 0x0002 // db: set after inactivity ?
-#define FLAG_SETNA 0x0004 // db: set NA after xx of away time ?
-#define FLAG_CONFIRM 0x0008 // db: show confirm dialog ?
-#define FLAG_RESET 0x0010 // db: restore status ?
-#define FLAG_LV2ONINACTIVE 0x0020 // db: set lv2 only on inactivity
-#define FLAG_MONITORMIRANDA 0x0040 // db: monitor miranda activity only
-#define FLAG_ONLOCK 0x0080 // db: on work station lock
-#define FLAG_FULLSCREEN 0x0100 // db: on full screen
-
-typedef enum
-{
- ACTIVE, // user is active
- STATUS1_SET, // first status change happened
- STATUS2_SET, // second status change happened
- SET_ORGSTATUS, // user was active again, original status will be restored
- HIDDEN_ACTIVE // user is active, but this is not shown to the outside world
-} STATES;
-
-struct TAAAProtoSetting : public PROTOCOLSETTINGEX, public MZeroedObject
-{
- TAAAProtoSetting(PROTOACCOUNT *pa);
- ~TAAAProtoSetting();
-
- int originalStatusMode;
- STATES
- oldState,
- curState;
- BOOL statusChanged; // AAA changed the status, don't update mStatus
- BOOL mStatus; // status changed manually or not ?
- int optionFlags, // db: see above
- awayTime, // db: time to wait for inactivity
- naTime, // db: time to wait after away is set
- statusFlags; // db: set lv1 status if this is original status
- WORD lv1Status, // db
- lv2Status; // db
- unsigned int sts1setTimer;
-};
-
-int AAACompareSettings(const TAAAProtoSetting *p1, const TAAAProtoSetting *p2);
-
void AdvancedAutoAwayLoad();
void AdvancedAutoAwayUnload();
-typedef OBJLIST<TAAAProtoSetting> TAAAProtoSettingList;
-extern TAAAProtoSettingList autoAwaySettings;
-
-int LoadAutoAwaySetting(TAAAProtoSetting &autoAwaySetting, char *protoName);
-void AAALoadOptions(TAAAProtoSettingList &settings, bool override);
+int LoadAutoAwaySetting(SMProto&, char *protoName);
+void AAALoadOptions();
#endif