summaryrefslogtreecommitdiff
path: root/plugins/StatusManager/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/StatusManager/src')
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp10
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp70
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h2
-rw-r--r--plugins/StatusManager/src/KeepStatus/keepstatus.cpp244
-rw-r--r--plugins/StatusManager/src/KeepStatus/ks_options.cpp6
-rw-r--r--plugins/StatusManager/src/StartupStatus/ss_options.cpp6
-rw-r--r--plugins/StatusManager/src/StartupStatus/ss_profiles.cpp2
-rw-r--r--plugins/StatusManager/src/StartupStatus/startupstatus.cpp40
-rw-r--r--plugins/StatusManager/src/commonstatus.cpp18
-rw-r--r--plugins/StatusManager/src/main.cpp15
-rw-r--r--plugins/StatusManager/src/options.cpp34
-rw-r--r--plugins/StatusManager/src/stdafx.h2
-rw-r--r--plugins/StatusManager/src/version.h8
13 files changed, 259 insertions, 198 deletions
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
index 3f48a7bee4..3a733b9074 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
@@ -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(autoAwaySettings, false);
}
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(autoAwaySettings, false);
}
break;
}
@@ -429,16 +429,16 @@ int AutoAwayOptInitialise(WPARAM wParam, LPARAM)
odp.szTab.a = LPGEN("General");
odp.pfnDlgProc = DlgProcAutoAwayGeneralOpts;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GENAUTOAWAY);
- Options_AddPage(wParam, &odp);
+ Options_AddPage(wParam, &odp, AAALangPack);
odp.szTab.a = LPGEN("Rules");
odp.pfnDlgProc = DlgProcAutoAwayRulesOpts;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_AUTOAWAY);
- Options_AddPage(wParam, &odp);
+ Options_AddPage(wParam, &odp, AAALangPack);
odp.szTab.a = LPGEN("Status messages");
odp.pfnDlgProc = DlgProcAutoAwayMsgOpts;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_AUTOAWAYMSG);
- Options_AddPage(wParam, &odp);
+ Options_AddPage(wParam, &odp, AAALangPack);
return 0;
}
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
index aba644ffd4..41e09bc0bf 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
@@ -49,7 +49,10 @@ TAAAProtoSetting::~TAAAProtoSetting()
/////////////////////////////////////////////////////////////////////////////////////////
-HANDLE hStateChangedEvent = nullptr;
+int AAALangPack;
+
+static HANDLE hStateChangedEvent = nullptr;
+static HANDLE hEvents[4];
static BOOL ignoreLockKeys = FALSE;
static BOOL ignoreSysKeys = FALSE;
@@ -86,16 +89,21 @@ extern char *StatusModeToDbSetting(int status, const char *suffix);
/////////////////////////////////////////////////////////////////////////////////////////
// Load from DB
-void AAALoadOptions(TAAAProtoSettingList &loadSettings, BOOL override)
+void AAAUnloadOptions(bool bOverride)
{
- // if override is enabled, samesettings will be ignored (for options loading)
- int monitorMiranda = FALSE; // use windows hooks?
- int monitorAll = FALSE; // use windows hooks?
-
- if (!override)
+ if (!bOverride)
UnhookWindowsHooks();
if (hAutoAwayTimer != 0)
KillTimer(nullptr, hAutoAwayTimer);
+}
+
+void AAALoadOptions(TAAAProtoSettingList &loadSettings, bool bOverride)
+{
+ // 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);
ignoreLockKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNLOCK, FALSE);
ignoreSysKeys = db_get_b(0, AAAMODULENAME, SETTING_IGNSYSKEYS, FALSE);
@@ -106,12 +114,12 @@ void AAALoadOptions(TAAAProtoSettingList &loadSettings, BOOL override)
for (int i = 0; i < loadSettings.getCount(); i++) {
char* protoName;
- if ((db_get_b(0, AAAMODULENAME, SETTING_SAMESETTINGS, 0)) && !override)
+ if ((db_get_b(0, AAAMODULENAME, SETTING_SAMESETTINGS, 0)) && !bOverride)
protoName = SETTING_ALL;
else
protoName = loadSettings[i].m_szName;
LoadAutoAwaySetting(loadSettings[i], protoName);
- if (!override) {
+ if (!bOverride) {
if (loadSettings[i].optionFlags & FLAG_MONITORMIRANDA)
monitorMiranda = TRUE;
else if (ignoreLockKeys || ignoreSysKeys || ignoreAltCombo || (monitorMouse != monitorKeyboard))
@@ -539,24 +547,17 @@ static LRESULT CALLBACK KeyBoardHookFunction(int code, WPARAM wParam, LPARAM lPa
static int AutoAwayShutdown(WPARAM, LPARAM)
{
- KillTimer(nullptr, hAutoAwayTimer);
-
-#ifdef TRIGGERPLUGIN
- DeInitTrigger();
-#endif
- UnhookWindowsHooks();
- DestroyHookableEvent(hStateChangedEvent);
-
- autoAwaySettings.destroy();
+ AAAUnloadOptions(false);
return 0;
}
int AAAModuleLoaded(WPARAM, LPARAM)
{
- HookEvent(ME_PROTO_ACCLISTCHANGED, OnAAAAccChanged);
- HookEvent(ME_OPT_INITIALISE, AutoAwayOptInitialise);
- HookEvent(ME_SYSTEM_PRESHUTDOWN, AutoAwayShutdown);
- HookEvent(ME_PROTO_ACK, ProcessProtoAck);
+ 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);
+
mouseStationaryTimer = 0;
lastInput = lastMirandaInput = GetTickCount();
@@ -574,17 +575,36 @@ int AAAModuleLoaded(WPARAM, LPARAM)
////////////////////////////////////////////////////////////////////////////////////////
- AAALoadOptions(autoAwaySettings, FALSE);
+ AAALoadOptions(autoAwaySettings, false);
return 0;
}
void AdvancedAutoAwayLoad()
{
- HookEvent(ME_SYSTEM_MODULESLOADED, AAAModuleLoaded);
+ AAALangPack = GetPluginLangId(MIID_LAST, 0);
+
+ if (g_bMirandaLoaded) {
+ AAAModuleLoaded(0, 0);
+ AutoAwayOptInitialise(0, 0);
+ }
+ else HookEvent(ME_SYSTEM_MODULESLOADED, AAAModuleLoaded);
+
hStateChangedEvent = CreateHookableEvent(ME_AAA_STATECHANGED);
}
void AdvancedAutoAwayUnload()
{
- DestroyHookableEvent(hStateChangedEvent);
+ if (g_bMirandaLoaded)
+ AutoAwayShutdown(0, 0);
+
+ KillModuleOptions(AAALangPack);
+
+ for (int i = 0; i < _countof(hEvents); i++) {
+ UnhookEvent(hEvents[i]);
+ hEvents[i] = nullptr;
+ }
+
+ DestroyHookableEvent(hStateChangedEvent); hStateChangedEvent = nullptr;
+
+ autoAwaySettings.destroy();
}
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h
index 6feb889b99..43f9637d79 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h
+++ b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.h
@@ -79,6 +79,6 @@ typedef OBJLIST<TAAAProtoSetting> TAAAProtoSettingList;
extern TAAAProtoSettingList autoAwaySettings;
int LoadAutoAwaySetting(TAAAProtoSetting &autoAwaySetting, char *protoName);
-void AAALoadOptions(TAAAProtoSettingList &settings, BOOL override);
+void AAALoadOptions(TAAAProtoSettingList &settings, bool override);
#endif
diff --git a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
index 0aca873733..7ac0eb0dd2 100644
--- a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
+++ b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
@@ -19,19 +19,10 @@
#include "..\stdafx.h"
-struct TimerInfo
-{
- int timer;
- int timeout;
- BOOL restart;
- int result;
- HANDLE hEvent;
-};
-
-HANDLE hMainThread = nullptr;
-unsigned long mainThreadId = 0;
+int KSLangPack;
-HANDLE hConnectionEvent = nullptr;
+static HANDLE hConnectionEvent = nullptr;
+static HANDLE hServices[4], hEvents[3];
static mir_cs GenTimerCS, GenStatusCS, CheckContinueslyCS;
@@ -67,7 +58,6 @@ static int showConnectionPopups = 0;
// prototypes
static int StartTimer(int timer, int timeout, BOOL restart);
static int StopTimer(int timer);
-static void GetCurrentConnectionSettings();
static int ProcessProtoAck(WPARAM wParam, LPARAM lParam);
static VOID CALLBACK CheckConnectingTimer(HWND hwnd, UINT message, UINT_PTR idEvent, DWORD dwTime);
static VOID CALLBACK CheckAckStatusTimer(HWND hwnd, UINT message, UINT_PTR idEvent, DWORD dwTime);
@@ -88,6 +78,8 @@ static DWORD CALLBACK MessageWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
// options.c
extern int KeepStatusOptionsInit(WPARAM wparam, LPARAM);
+/////////////////////////////////////////////////////////////////////////////////////////
+
TKSSettings::TKSSettings(PROTOACCOUNT *pa)
{
m_szName = pa->szModuleName;
@@ -102,7 +94,9 @@ TKSSettings::~TKSSettings()
free(m_szMsg);
}
-int KSLoadOptions()
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void KSUnloadOptions()
{
UnhookEvent(hProtoAckHook);
UnhookEvent(hStatusChangeHook);
@@ -118,7 +112,20 @@ int KSLoadOptions()
StopTimer(IDT_CHECKCONN | IDT_PROCESSACK | IDT_AFTERCHECK | IDT_CHECKCONTIN | IDT_CHECKCONNECTING);
- GetCurrentConnectionSettings();
+ connectionSettings.destroy();
+}
+
+int KSLoadOptions()
+{
+ KSUnloadOptions();
+
+ int count;
+ PROTOACCOUNT** protos;
+ Proto_EnumAccounts(&count, &protos);
+
+ for (int i = 0; i < count; i++)
+ if (IsSuitableProto(protos[i]))
+ connectionSettings.insert(new TKSSettings(protos[i]));
if (db_get_b(0, KSMODULENAME, SETTING_CHECKCONNECTION, FALSE)) {
if (db_get_b(0, KSMODULENAME, SETTING_CONTCHECK, FALSE)) {
@@ -151,18 +158,7 @@ int KSLoadOptions()
return 0;
}
-static void GetCurrentConnectionSettings()
-{
- connectionSettings.destroy();
-
- int count;
- PROTOACCOUNT** protos;
- Proto_EnumAccounts(&count, &protos);
-
- for (int i = 0; i < count; i++)
- if (IsSuitableProto(protos[i]))
- connectionSettings.insert(new TKSSettings(protos[i]));
-}
+/////////////////////////////////////////////////////////////////////////////////////////
static PROTOCOLSETTINGEX** GetCurrentProtoSettingsCopy()
{
@@ -350,80 +346,85 @@ static int CSStatusChangeEx(WPARAM wParam, LPARAM)
return 0;
}
-static int StartTimerFunction(int timer, int timeout, BOOL restart)
+struct TimerInfo
+{
+ int timer;
+ int timeout;
+ BOOL restart;
+};
+
+static INT_PTR CALLBACK StartTimerApcProc(void *param)
{
+ TimerInfo *ti = (TimerInfo *)param;
int res = 0;
mir_cslock lck(GenTimerCS);
- log_debugA("StartTimer: %d, %d, %d", timer, timeout, restart);
+ log_debugA("StartTimer: %d, %d, %d", ti->timer, ti->timeout, ti->restart);
log_debugA("ack: %u, chk: %u, aft: %u, cnt: %u, con: %u", processAckTimerId, checkConnectionTimerId, afterCheckTimerId, checkContinTimerId, checkConnectingTimerId);
- if (timer & IDT_PROCESSACK) {
+ if (ti->timer & IDT_PROCESSACK) {
res = (processAckTimerId == 0) ? 0 : 1;
- if (((processAckTimerId == 0) && (checkConnectionTimerId == 0)) || (restart)) {
- if (timeout != -1) {
- if (restart)
+ if (((processAckTimerId == 0) && (checkConnectionTimerId == 0)) || (ti->restart)) {
+ if (ti->timeout != -1) {
+ if (ti->restart)
KillTimer(nullptr, processAckTimerId);
- if (timeout == 0)
- processAckTimerId = SetTimer(nullptr, 0, ackDelay, CheckAckStatusTimer);
- else
- processAckTimerId = SetTimer(nullptr, 0, timeout, CheckAckStatusTimer);
+ if (ti->timeout == 0)
+ ti->timeout = ackDelay;
+ processAckTimerId = SetTimer(nullptr, 0, ti->timeout, CheckAckStatusTimer);
}
}
}
- if (timer & IDT_CHECKCONN) {
+ if (ti->timer & IDT_CHECKCONN) {
res = (checkConnectionTimerId == 0 ? 0 : 1) || res;
- if ((checkConnectionTimerId == 0) || (restart)) {
- if (timeout != -1) {
- if (restart)
+ if ((checkConnectionTimerId == 0) || (ti->restart)) {
+ if (ti->timeout != -1) {
+ if (ti->restart)
KillTimer(nullptr, checkConnectionTimerId);
- if (timeout == 0)
- checkConnectionTimerId = SetTimer(nullptr, 0, initDelay, CheckConnectionTimer);
- else
- checkConnectionTimerId = SetTimer(nullptr, 0, timeout, CheckConnectionTimer);
+
+ if (ti->timeout == 0)
+ ti->timeout = initDelay;
+ checkConnectionTimerId = SetTimer(nullptr, 0, ti->timeout, CheckConnectionTimer);
}
}
}
- if (timer & IDT_AFTERCHECK) {
+ if (ti->timer & IDT_AFTERCHECK) {
res = (afterCheckTimerId == 0 ? 0 : 1) || res;
- if ((afterCheckTimerId == 0) || (restart)) {
- if (timeout != -1) {
- if (restart)
+ if ((afterCheckTimerId == 0) || (ti->restart)) {
+ if (ti->timeout != -1) {
+ if (ti->restart)
KillTimer(nullptr, afterCheckTimerId);
- if (timeout == 0)
- afterCheckTimerId = SetTimer(nullptr, 0, initDelay / 2, AfterCheckTimer);
- else
- afterCheckTimerId = SetTimer(nullptr, 0, timeout, AfterCheckTimer);
+
+ if (ti->timeout == 0)
+ ti->timeout = initDelay / 2;
+ afterCheckTimerId = SetTimer(nullptr, 0, ti->timeout, AfterCheckTimer);
}
}
}
- if (timer & IDT_CHECKCONTIN) {
+ if (ti->timer & IDT_CHECKCONTIN) {
res = (checkContinTimerId == 0 ? 0 : 1) || res;
- if ((checkContinTimerId == 0) || (restart)) {
- if (timeout != -1) {
- if (restart)
+ if ((checkContinTimerId == 0) || (ti->restart)) {
+ if (ti->timeout != -1) {
+ if (ti->restart)
KillTimer(nullptr, checkContinTimerId);
- if (timeout == 0) {
- checkContinTimerId = SetTimer(nullptr, 0, 1000 * db_get_dw(0, KSMODULENAME, SETTING_CNTDELAY, CHECKCONTIN_DELAY), CheckContinueslyTimer);
- }
- else
- checkContinTimerId = SetTimer(nullptr, 0, timeout, CheckContinueslyTimer);
+
+ if (ti->timeout == 0)
+ ti->timeout = 1000 * db_get_dw(0, KSMODULENAME, SETTING_CNTDELAY, CHECKCONTIN_DELAY);
+ checkContinTimerId = SetTimer(nullptr, 0, ti->timeout, CheckContinueslyTimer);
}
}
}
- if (timer & IDT_CHECKCONNECTING) {
+ if (ti->timer & IDT_CHECKCONNECTING) {
res = (checkConnectingTimerId == 0 ? 0 : 1) || res;
- if ((checkConnectingTimerId == 0) || (restart)) {
- if (timeout != -1) {
- if (restart)
+ if ((checkConnectingTimerId == 0) || (ti->restart)) {
+ if (ti->timeout != -1) {
+ if (ti->restart)
KillTimer(nullptr, checkConnectingTimerId);
- if (timeout == 0) {
- timeout = initDelay / 2;
- }
- checkConnectingTimerId = SetTimer(nullptr, 0, timeout, CheckConnectingTimer);
+ if (ti->timeout == 0)
+ ti->timeout = initDelay / 2;
+ checkConnectingTimerId = SetTimer(nullptr, 0, ti->timeout, CheckConnectingTimer);
}
}
}
@@ -433,30 +434,10 @@ static int StartTimerFunction(int timer, int timeout, BOOL restart)
return res;
}
-static VOID CALLBACK StartTimerApcProc(ULONG_PTR param)
-{
- struct TimerInfo *ti = (struct TimerInfo *)param;
- log_debugA("StartTimerApcProc %d %d %d", ti->timer, ti->timeout, ti->restart);
- ti->result = StartTimerFunction(ti->timer, ti->timeout, ti->restart);
- SetEvent(ti->hEvent);
-}
-
static int StartTimer(int timer, int timeout, BOOL restart)
{
- if (GetCurrentThreadId() == mainThreadId)
- return StartTimerFunction(timer, timeout, restart);
-
- TimerInfo *ti = (TimerInfo*)calloc(1, sizeof(struct TimerInfo));
- ti->timer = timer;
- ti->timeout = timeout;
- ti->restart = restart;
- ti->hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
- QueueUserAPC(StartTimerApcProc, hMainThread, (ULONG_PTR)ti);
- WaitForSingleObject(ti->hEvent, INFINITE);
- CloseHandle(ti->hEvent);
- int res = ti->result;
- free(ti);
- return res;
+ TimerInfo ti = { timer, timeout, restart };
+ return CallFunctionSync(&StartTimerApcProc, &ti);
}
static int StopTimer(int timer)
@@ -743,9 +724,9 @@ static VOID CALLBACK AfterCheckTimer(HWND, UINT, UINT_PTR, DWORD)
StopChecking();
}
-static void CheckContinueslyFunction(void *)
+static void CheckContinuouslyFunction(void *)
{
- Thread_SetName("KeepStatus: CheckContinueslyFunction");
+ Thread_SetName("KeepStatus: CheckContinuouslyFunction");
static int pingFailures = 0;
@@ -764,13 +745,13 @@ static void CheckContinueslyFunction(void *)
continue;
if (shouldBeStatus != ID_STATUS_OFFLINE) {
- log_debugA("CheckContinueslyFunction: %s should be %d", cs.m_szName, shouldBeStatus);
+ log_debugA("CheckContinuouslyFunction: %s should be %d", cs.m_szName, shouldBeStatus);
doPing = true;
}
}
if (!doPing) {
- log_debugA("CheckContinueslyFunction: All protocols should be offline, no need to check connection");
+ log_debugA("CheckContinuouslyFunction: All protocols should be offline, no need to check connection");
return;
}
@@ -810,9 +791,9 @@ static void CheckContinueslyFunction(void *)
else
pingFailures++;
- log_debugA("CheckContinueslyFunction: pinging %s (result: %d/%d)", host, bLastPingResult, pingFailures);
+ log_debugA("CheckContinuouslyFunction: pinging %s (result: %d/%d)", host, bLastPingResult, pingFailures);
}
- else log_debugA("CheckContinueslyFunction: unable to resolve %s", host);
+ else log_debugA("CheckContinuouslyFunction: unable to resolve %s", host);
start = end;
while (*start == ' ')
@@ -839,16 +820,16 @@ static void CheckContinueslyFunction(void *)
continue;
if (IsStatusConnecting(CallProtoService(protos[i]->szModuleName, PS_GETSTATUS, 0, 0))) {
- log_debugA("CheckContinueslyFunction: %s is connecting", protos[i]->szModuleName);
+ log_debugA("CheckContinuouslyFunction: %s is connecting", protos[i]->szModuleName);
continue; // connecting, leave alone
}
if (IsProtocolEnabledService(0, (LPARAM)protos[i]->szModuleName)) {
- log_debugA("CheckContinueslyFunction: forcing %s offline", protos[i]->szModuleName);
+ log_debugA("CheckContinuouslyFunction: forcing %s offline", protos[i]->szModuleName);
CallProtoService(protos[i]->szModuleName, PS_SETSTATUS, (WPARAM)ID_STATUS_OFFLINE, 0);
}
}
if (StartTimer(IDT_CHECKCONN | IDT_PROCESSACK, -1, FALSE)) {// are our 'set offlines' noticed?
- log_debugA("CheckContinueslyFunction: currently checking");
+ log_debugA("CheckContinuouslyFunction: currently checking");
return;
}
log_infoA("KeepStatus: connection lost! (continuesly check)");
@@ -864,9 +845,9 @@ static void CheckContinueslyFunction(void *)
static VOID CALLBACK CheckContinueslyTimer(HWND, UINT, UINT_PTR, DWORD)
{
if (db_get_b(0, KSMODULENAME, SETTING_BYPING, FALSE))
- mir_forkthread(CheckContinueslyFunction, nullptr);
+ mir_forkthread(CheckContinuouslyFunction, nullptr);
else
- CheckContinueslyFunction(nullptr);
+ CheckContinuouslyFunction(nullptr);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1180,20 +1161,12 @@ int OnKSAccChanged(WPARAM wParam, LPARAM lParam)
static int onShutdown(WPARAM, LPARAM)
{
- UnhookEvent(hStatusChangeHook);
- UnhookEvent(hProtoAckHook);
- UnhookEvent(hCSStatusChangeHook);
- UnhookEvent(hCSStatusChangeExHook);
-
- StopTimer(IDT_CHECKCONN | IDT_PROCESSACK | IDT_AFTERCHECK | IDT_CHECKCONTIN);
- if (IsWindow(hMessageWindow))
- DestroyWindow(hMessageWindow);
-
- connectionSettings.destroy();
-
+ KSUnloadOptions();
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
int KSModuleLoaded(WPARAM, LPARAM)
{
protoList = (OBJLIST<PROTOCOLSETTINGEX>*)&connectionSettings;
@@ -1201,31 +1174,46 @@ int KSModuleLoaded(WPARAM, LPARAM)
hMessageWindow = nullptr;
KSLoadOptions();
- HookEvent(ME_OPT_INITIALISE, KeepStatusOptionsInit);
- HookEvent(ME_SYSTEM_PRESHUTDOWN, onShutdown);
- HookEvent(ME_PROTO_ACCLISTCHANGED, OnKSAccChanged);
+ hEvents[0] = HookEvent(ME_OPT_INITIALISE, KeepStatusOptionsInit);
+ hEvents[1] = HookEvent(ME_SYSTEM_PRESHUTDOWN, onShutdown);
+ hEvents[2] = HookEvent(ME_PROTO_ACCLISTCHANGED, OnKSAccChanged);
return 0;
}
void KeepStatusLoad()
{
- HookEvent(ME_SYSTEM_MODULESLOADED, KSModuleLoaded);
+ KSLangPack = GetPluginLangId(MIID_LAST, 0);
- CreateHookableEvent(ME_KS_CONNECTIONEVENT);
+ if (g_bMirandaLoaded) {
+ KSModuleLoaded(0, 0);
+ KeepStatusOptionsInit(0, 0);
+ }
+ else HookEvent(ME_SYSTEM_MODULESLOADED, KSModuleLoaded);
- CreateServiceFunction(MS_KS_STOPRECONNECTING, StopReconnectingService);
- CreateServiceFunction(MS_KS_ENABLEPROTOCOL, EnableProtocolService);
- CreateServiceFunction(MS_KS_ISPROTOCOLENABLED, IsProtocolEnabledService);
- CreateServiceFunction(MS_KS_ANNOUNCESTATUSCHANGE, AnnounceStatusChangeService);
+ hConnectionEvent = CreateHookableEvent(ME_KS_CONNECTIONEVENT);
- DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hMainThread, THREAD_SET_CONTEXT, FALSE, 0);
- mainThreadId = GetCurrentThreadId();
+ hServices[0] = CreateServiceFunction(MS_KS_STOPRECONNECTING, StopReconnectingService);
+ hServices[1] = CreateServiceFunction(MS_KS_ENABLEPROTOCOL, EnableProtocolService);
+ hServices[2] = CreateServiceFunction(MS_KS_ISPROTOCOLENABLED, IsProtocolEnabledService);
+ hServices[3] = CreateServiceFunction(MS_KS_ANNOUNCESTATUSCHANGE, AnnounceStatusChangeService);
}
void KeepStatusUnload()
{
- if (hMainThread)
- CloseHandle(hMainThread);
+ if (g_bMirandaLoaded)
+ onShutdown(0, 0);
+
+ KillModuleOptions(KSLangPack);
+
+ for (int i = 0; i < _countof(hServices); i++) {
+ DestroyServiceFunction(hServices[i]);
+ hServices[i] = nullptr;
+ }
+
+ for (int i = 0; i < _countof(hEvents); i++) {
+ UnhookEvent(hEvents[i]);
+ hEvents[i] = nullptr;
+ }
- DestroyHookableEvent(hConnectionEvent);
+ DestroyHookableEvent(hConnectionEvent); hConnectionEvent = nullptr;
}
diff --git a/plugins/StatusManager/src/KeepStatus/ks_options.cpp b/plugins/StatusManager/src/KeepStatus/ks_options.cpp
index cafe9d1f39..7fb763b926 100644
--- a/plugins/StatusManager/src/KeepStatus/ks_options.cpp
+++ b/plugins/StatusManager/src/KeepStatus/ks_options.cpp
@@ -456,12 +456,12 @@ int KeepStatusOptionsInit(WPARAM wparam, LPARAM)
odp.szTab.a = LPGEN("Basic");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_KS_BASIC);
odp.pfnDlgProc = DlgProcKSBasicOpts;
- Options_AddPage(wparam, &odp);
+ Options_AddPage(wparam, &odp, KSLangPack);
odp.szTab.a = LPGEN("Advanced");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_KS_ADV);
odp.pfnDlgProc = DlgProcKSAdvOpts;
- Options_AddPage(wparam, &odp);
+ Options_AddPage(wparam, &odp, KSLangPack);
if (ServiceExists(MS_POPUP_ADDPOPUPT)) {
memset(&odp, 0, sizeof(odp));
@@ -472,7 +472,7 @@ int KeepStatusOptionsInit(WPARAM wparam, LPARAM)
odp.szTitle.a = LPGEN("Keep status");
odp.pfnDlgProc = PopupOptDlgProc;
odp.flags = ODPF_BOLDGROUPS;
- Options_AddPage(wparam, &odp);
+ Options_AddPage(wparam, &odp, KSLangPack);
}
return 0;
}
diff --git a/plugins/StatusManager/src/StartupStatus/ss_options.cpp b/plugins/StatusManager/src/StartupStatus/ss_options.cpp
index cbb2aed627..1fdf8141bd 100644
--- a/plugins/StatusManager/src/StartupStatus/ss_options.cpp
+++ b/plugins/StatusManager/src/StartupStatus/ss_options.cpp
@@ -918,7 +918,7 @@ public:
int StartupStatusOptionsInit(WPARAM wparam, LPARAM)
{
- OPTIONSDIALOGPAGE odp = { 0 };
+ OPTIONSDIALOGPAGE odp = {};
odp.hInstance = hInst;
odp.szGroup.a = LPGEN("Status");
odp.szTitle.a = LPGEN("Startup status");
@@ -927,12 +927,12 @@ int StartupStatusOptionsInit(WPARAM wparam, LPARAM)
odp.szTab.a = LPGEN("General");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_STARTUPSTATUS);
odp.pfnDlgProc = StartupStatusOptDlgProc;
- Options_AddPage(wparam, &odp);
+ Options_AddPage(wparam, &odp, SSLangPack);
odp.szTab.a = LPGEN("Status profiles");
odp.pszTemplate = nullptr;
odp.pfnDlgProc = nullptr;
odp.pDialog = new CSSAdvancedOptDlg();
- Options_AddPage(wparam, &odp);
+ Options_AddPage(wparam, &odp, SSLangPack);
return 0;
}
diff --git a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp
index d90a5a890b..19f9d05ecd 100644
--- a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp
+++ b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp
@@ -328,7 +328,9 @@ int DeinitProfilesModule()
for (int i = 0; i < pceCount; i++)
free(pce[i].szProto);
free(pce);
+ pce = nullptr;
}
+ pceCount = 0;
UnregisterHotKeys();
RemoveTopToolbarButtons();
diff --git a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp
index 15c5ac289d..1f051800e6 100644
--- a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp
+++ b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp
@@ -19,6 +19,9 @@
#include "..\stdafx.h"
+int SSLangPack;
+
+static HANDLE hServices[3], hEvents[4];
static UINT_PTR setStatusTimerId = 0;
static TSettingsList startupSettings(10, SSCompareSettings);
@@ -394,12 +397,12 @@ int SSModuleLoaded(WPARAM, LPARAM)
InitProfileModule();
- HookEvent(ME_PROTO_ACCLISTCHANGED, OnSSAccChanged);
- HookEvent(ME_OPT_INITIALISE, StartupStatusOptionsInit);
+ hEvents[0] = HookEvent(ME_PROTO_ACCLISTCHANGED, OnSSAccChanged);
+ hEvents[1] = HookEvent(ME_OPT_INITIALISE, StartupStatusOptionsInit);
/* shutdown hook for normal shutdown */
- HookEvent(ME_SYSTEM_OKTOEXIT, OnOkToExit);
- HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown);
+ hEvents[2] = HookEvent(ME_SYSTEM_OKTOEXIT, OnOkToExit);
+ hEvents[3] = HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown);
/* message window for poweroff */
hMessageWindow = CreateWindowEx(0, L"STATIC", nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr);
SetWindowLongPtr(hMessageWindow, GWLP_WNDPROC, (LONG_PTR)MessageWndProc);
@@ -481,7 +484,13 @@ static INT_PTR SrvGetProfile(WPARAM wParam, LPARAM lParam)
void StartupStatusLoad()
{
- HookEvent(ME_SYSTEM_MODULESLOADED, SSModuleLoaded);
+ SSLangPack = GetPluginLangId(MIID_LAST, 0);
+
+ if (g_bMirandaLoaded) {
+ SSModuleLoaded(0, 0);
+ StartupStatusOptionsInit(0, 0);
+ }
+ else HookEvent(ME_SYSTEM_MODULESLOADED, SSModuleLoaded);
if (db_get_b(0, SSMODULENAME, SETTING_SETPROFILE, 1) || db_get_b(0, SSMODULENAME, SETTING_OFFLINECLOSE, 0))
db_set_w(0, "CList", "Status", (WORD)ID_STATUS_OFFLINE);
@@ -496,14 +505,29 @@ void StartupStatusLoad()
}
// Create service functions; the get functions are created here; they don't rely on commonstatus
- CreateServiceFunction(MS_SS_GETPROFILE, SrvGetProfile);
- CreateServiceFunction(MS_SS_GETPROFILECOUNT, GetProfileCount);
- CreateServiceFunction(MS_SS_GETPROFILENAME, GetProfileName);
+ hServices[0] = CreateServiceFunction(MS_SS_GETPROFILE, SrvGetProfile);
+ hServices[1] = CreateServiceFunction(MS_SS_GETPROFILECOUNT, GetProfileCount);
+ hServices[2] = CreateServiceFunction(MS_SS_GETPROFILENAME, GetProfileName);
LoadProfileModule();
}
void StartupStatusUnload()
{
+ if (g_bMirandaLoaded)
+ OnShutdown(0, 0);
+
+ KillModuleOptions(SSLangPack);
+
+ for (int i = 0; i < _countof(hServices); i++) {
+ DestroyServiceFunction(hServices[i]);
+ hServices[i] = nullptr;
+ }
+
+ for (int i = 0; i < _countof(hEvents); i++) {
+ UnhookEvent(hEvents[i]);
+ hEvents[i] = nullptr;
+ }
+
DeinitProfilesModule();
}
diff --git a/plugins/StatusManager/src/commonstatus.cpp b/plugins/StatusManager/src/commonstatus.cpp
index 146b69a96d..fe1860ecb3 100644
--- a/plugins/StatusManager/src/commonstatus.cpp
+++ b/plugins/StatusManager/src/commonstatus.cpp
@@ -30,8 +30,6 @@ OBJLIST<PROTOCOLSETTINGEX> *protoList;
char* StatusModeToDbSetting(int status, const char *suffix);
DWORD StatusModeToProtoFlag(int status);
INT_PTR SetStatusEx(WPARAM wParam, LPARAM lParam);
-int InitCommonStatus();
-int GetProtoCount();
// some helpers from awaymsg.c ================================================================
char *StatusModeToDbSetting(int status, const char *suffix)
@@ -252,16 +250,6 @@ INT_PTR SetStatusEx(WPARAM wParam, LPARAM)
static INT_PTR GetProtocolCountService(WPARAM, LPARAM)
{
- return GetProtoCount();
-}
-
-bool IsSuitableProto(PROTOACCOUNT *pa)
-{
- return (pa == nullptr) ? false : (pcli->pfnGetProtocolVisibility(pa->szModuleName) != 0);
-}
-
-int GetProtoCount()
-{
int pCount = 0, count;
PROTOACCOUNT **accs;
Proto_EnumAccounts(&count, &accs);
@@ -273,6 +261,11 @@ int GetProtoCount()
return pCount;
}
+bool IsSuitableProto(PROTOACCOUNT *pa)
+{
+ return (pa == nullptr) ? false : (pcli->pfnGetProtocolVisibility(pa->szModuleName) != 0);
+}
+
static int CreateServices()
{
if (ServiceExists(MS_CS_SETSTATUSEX))
@@ -287,6 +280,7 @@ static int CreateServices()
static int onShutdown(WPARAM, LPARAM)
{
+ g_bMirandaLoaded = false;
DestroyHookableEvent(hCSStatusChangedExEvent);
return 0;
}
diff --git a/plugins/StatusManager/src/main.cpp b/plugins/StatusManager/src/main.cpp
index e1cdb19222..7e5b41fd5d 100644
--- a/plugins/StatusManager/src/main.cpp
+++ b/plugins/StatusManager/src/main.cpp
@@ -62,7 +62,6 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
MUUID Interfaces[2] = {0};
MUUID miidAutoAway = MIID_AUTOAWAY;
-
MUUID* GetInterfaces(void)
{
if (IsSubPluginEnabled(AAAMODULENAME))
@@ -75,8 +74,11 @@ extern "C" __declspec(dllexport) MUUID* MirandaInterfaces = GetInterfaces();
/////////////////////////////////////////////////////////////////////////////////////////
// plugin's entry point
+bool g_bMirandaLoaded = false;
+
int OnModulesLoaded(WPARAM, LPARAM)
{
+ g_bMirandaLoaded = true;
HookEvent(ME_OPT_INITIALISE, CSubPluginsOptionsDlg::OnOptionsInit);
return 0;
}
@@ -96,7 +98,6 @@ extern "C" int __declspec(dllexport) Load(void)
StartupStatusLoad();
if (IsSubPluginEnabled(AAAMODULENAME))
AdvancedAutoAwayLoad();
-
return 0;
}
@@ -105,9 +106,11 @@ extern "C" int __declspec(dllexport) Load(void)
extern "C" int __declspec(dllexport) Unload(void)
{
- KeepStatusUnload();
- StartupStatusUnload();
- AdvancedAutoAwayUnload();
-
+ if (IsSubPluginEnabled(KSMODULENAME))
+ KeepStatusUnload();
+ if (IsSubPluginEnabled(SSMODULENAME))
+ StartupStatusUnload();
+ if (IsSubPluginEnabled(AAAMODULENAME))
+ AdvancedAutoAwayUnload();
return 0;
}
diff --git a/plugins/StatusManager/src/options.cpp b/plugins/StatusManager/src/options.cpp
index 3c5a33799c..dcb6739741 100644
--- a/plugins/StatusManager/src/options.cpp
+++ b/plugins/StatusManager/src/options.cpp
@@ -35,13 +35,41 @@ void CSubPluginsOptionsDlg::OnApply()
{
char setting[128];
mir_snprintf(setting, "%s_enabled", KSMODULENAME);
- db_set_b(0, MODULENAME, setting, m_enableKeepStatus.GetState());
+ int bEnabled = m_enableKeepStatus.GetState();
+ if (bEnabled != db_get_b(0, MODULENAME, setting)) {
+ db_set_b(0, MODULENAME, setting, m_enableKeepStatus.GetState());
+
+ if (bEnabled)
+ KeepStatusLoad();
+ else
+ KeepStatusUnload();
+ }
+
mir_snprintf(setting, "%s_enabled", SSMODULENAME);
- db_set_b(0, MODULENAME, setting, m_enableStartupStatus.GetState());
+ bEnabled = m_enableStartupStatus.GetState();
+ if (bEnabled != db_get_b(0, MODULENAME, setting)) {
+ db_set_b(0, MODULENAME, setting, m_enableStartupStatus.GetState());
+
+ if (bEnabled)
+ StartupStatusLoad();
+ else
+ StartupStatusUnload();
+ }
+
mir_snprintf(setting, "%s_enabled", AAAMODULENAME);
- db_set_b(0, MODULENAME, setting, m_enableAdvancedAutoAway.GetState());
+ bEnabled = m_enableAdvancedAutoAway.GetState();
+ if (bEnabled != db_get_b(0, MODULENAME, setting)) {
+ db_set_b(0, MODULENAME, setting, m_enableAdvancedAutoAway.GetState());
+
+ if (bEnabled)
+ AdvancedAutoAwayLoad();
+ else
+ AdvancedAutoAwayUnload();
+ }
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
int CSubPluginsOptionsDlg::OnOptionsInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
diff --git a/plugins/StatusManager/src/stdafx.h b/plugins/StatusManager/src/stdafx.h
index fbf6746322..92e55b158c 100644
--- a/plugins/StatusManager/src/stdafx.h
+++ b/plugins/StatusManager/src/stdafx.h
@@ -34,6 +34,8 @@
#include "AdvancedAutoAway\advancedautoaway.h"
extern HINSTANCE hInst;
+extern bool g_bMirandaLoaded;
+extern int AAALangPack, KSLangPack, SSLangPack;
bool IsSubPluginEnabled(const char *name);
diff --git a/plugins/StatusManager/src/version.h b/plugins/StatusManager/src/version.h
index 1a33b23ec3..0f0117171f 100644
--- a/plugins/StatusManager/src/version.h
+++ b/plugins/StatusManager/src/version.h
@@ -1,8 +1,8 @@
// plugin version part
-#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 11
-#define __RELEASE_NUM 2
-#define __BUILD_NUM 3
+#define __MAJOR_VERSION 1
+#define __MINOR_VERSION 0
+#define __RELEASE_NUM 1
+#define __BUILD_NUM 1
// other stuff for Version resource
#include <stdver.h>