summaryrefslogtreecommitdiff
path: root/plugins/StatusManager/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-05-11 21:06:49 +0200
committerGeorge Hazan <ghazan@miranda.im>2018-05-11 21:06:49 +0200
commit200c0cb2bdd04e840701d32cff7e3a893874727f (patch)
tree6d2aa3a9f96e71cb325381509fd6c1a792ea0c84 /plugins/StatusManager/src
parent3d50f70b2f577ac732ef83cb9094705ec190c489 (diff)
fixes #1349 (Miranda crashes on coming back from auto away)
Diffstat (limited to 'plugins/StatusManager/src')
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp2
-rw-r--r--plugins/StatusManager/src/KeepStatus/keepstatus.cpp6
-rw-r--r--plugins/StatusManager/src/StartupStatus/ss_profiles.cpp2
-rw-r--r--plugins/StatusManager/src/StartupStatus/startupstatus.cpp2
-rw-r--r--plugins/StatusManager/src/commonstatus.cpp59
-rw-r--r--plugins/StatusManager/src/commonstatus.h2
-rw-r--r--plugins/StatusManager/src/confirmdialog.cpp28
-rw-r--r--plugins/StatusManager/src/version.h4
8 files changed, 42 insertions, 63 deletions
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
index 5ca571ec9d..ae7c2bd791 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
@@ -324,7 +324,7 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD)
if (confirm)
confirmDialog = ShowConfirmDialogEx(&ps, db_get_w(0, AAAMODULENAME, SETTING_CONFIRMDELAY, 5));
else if (statusChanged)
- CallService(MS_CS_SETSTATUSEX, (WPARAM)&ps, 0);
+ SetStatusEx(ps);
}
}
diff --git a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
index 1209e46f5c..5b130f024a 100644
--- a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
+++ b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
@@ -198,7 +198,7 @@ static int SetCurrentStatus()
}
}
ProcessPopup(KS_CONN_STATE_RETRY, (LPARAM)ps.getArray());
- return CallService(MS_CS_SETSTATUSEX, (WPARAM)&ps, 0);
+ return SetStatusEx(ps);
}
static int StatusChange(WPARAM wParam, LPARAM lParam)
@@ -243,7 +243,7 @@ static int CSStatusChange(WPARAM wParam, LPARAM)
return 0;
}
-static int CSStatusChangeEx(WPARAM wParam, LPARAM)
+static int CSStatusChangeEx(WPARAM wParam, LPARAM pCount)
{
// the status was changed by commonstatus (new)
if (wParam != 0) {
@@ -251,7 +251,7 @@ static int CSStatusChangeEx(WPARAM wParam, LPARAM)
if (protoSettings == nullptr)
return -1;
- for (int i = 0; i < protoList.getCount(); i++) {
+ for (int i = 0; i < pCount; i++) {
auto psi = protoSettings[i];
if (psi->m_szName == nullptr)
continue;
diff --git a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp
index 2aba9ad8d8..46db3d1299 100644
--- a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp
+++ b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp
@@ -204,7 +204,7 @@ INT_PTR LoadAndSetProfile(WPARAM iProfileNo, LPARAM)
char setting[64];
mir_snprintf(setting, "%d_%s", profile, SETTING_SHOWCONFIRMDIALOG);
if (!db_get_b(0, SSMODULENAME, setting, 0))
- CallService(MS_CS_SETSTATUSEX, (WPARAM)&ps, 0);
+ SetStatusEx(ps);
else
ShowConfirmDialogEx(&ps, db_get_dw(0, SSMODULENAME, SETTING_DLGTIMEOUT, 5));
}
diff --git a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp
index 6eb6bb820a..a4e67e1b31 100644
--- a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp
+++ b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp
@@ -215,7 +215,7 @@ static void CALLBACK SetStatusTimed(HWND, UINT, UINT_PTR, DWORD)
if (it->ssDisabled)
it->m_status = ID_STATUS_DISABLED;
- CallService(MS_CS_SETSTATUSEX, (WPARAM)&ps, 0);
+ SetStatusEx(ps);
}
static int OnOkToExit(WPARAM, LPARAM)
diff --git a/plugins/StatusManager/src/commonstatus.cpp b/plugins/StatusManager/src/commonstatus.cpp
index 1fa60745dd..371dfeae1a 100644
--- a/plugins/StatusManager/src/commonstatus.cpp
+++ b/plugins/StatusManager/src/commonstatus.cpp
@@ -69,7 +69,6 @@ TProtoSettings::TProtoSettings(const TProtoSettings &p)
char* StatusModeToDbSetting(int status, const char *suffix);
DWORD StatusModeToProtoFlag(int status);
-INT_PTR SetStatusEx(WPARAM wParam, LPARAM lParam);
// some helpers from awaymsg.c ================================================================
@@ -144,9 +143,9 @@ wchar_t* GetDefaultStatusMessage(PROTOCOLSETTINGEX *ps, int newstatus)
return tMsg;
}
-static int equalsGlobalStatus(PROTOCOLSETTINGEX **ps)
+static int equalsGlobalStatus(TProtoSettings &ps)
{
- int j, pstatus = 0, gstatus = 0;
+ int pstatus = 0, gstatus = 0;
for (auto &it : protoList)
if (it->m_szMsg != nullptr && GetActualStatus(it) != ID_STATUS_OFFLINE)
@@ -157,9 +156,9 @@ static int equalsGlobalStatus(PROTOCOLSETTINGEX **ps)
continue;
pstatus = 0;
- for (j = 0; j < protoList.getCount(); j++)
- if (!mir_strcmp(pa->szModuleName, ps[j]->m_szName))
- pstatus = GetActualStatus(ps[j]);
+ for (auto &it : ps)
+ if (!mir_strcmp(pa->szModuleName, it->m_szName))
+ pstatus = GetActualStatus(it);
if (pstatus == 0)
pstatus = pa->iRealStatus;
@@ -215,22 +214,17 @@ static void SetStatusMsg(PROTOCOLSETTINGEX *ps, int newstatus)
mir_free(tszMsg);
}
-INT_PTR SetStatusEx(WPARAM wParam, LPARAM)
+int SetStatusEx(TProtoSettings &ps)
{
- PROTOCOLSETTINGEX** protoSettings = *(PROTOCOLSETTINGEX***)wParam;
- if (protoSettings == nullptr)
- return -1;
-
- int globStatus = equalsGlobalStatus(protoSettings);
+ int globStatus = equalsGlobalStatus(ps);
// issue with setting global status;
// things get messy because SRAway hooks ME_CLIST_STATUSMODECHANGE, so the status messages of SRAway and
// commonstatus will clash
- NotifyEventHooks(hCSStatusChangedExEvent, (WPARAM)&protoSettings, protoList.getCount());
+ NotifyEventHooks(hCSStatusChangedExEvent, (WPARAM)&ps, ps.getCount());
// set all status messages first
- for (int i = 0; i < protoList.getCount(); i++) {
- PROTOCOLSETTINGEX *p = protoSettings[i];
+ for (auto &p : ps) {
if (p->m_status == ID_STATUS_DISABLED)
continue;
@@ -239,7 +233,7 @@ INT_PTR SetStatusEx(WPARAM wParam, LPARAM)
continue;
}
// some checks
- int newstatus = GetActualStatus(protoSettings[i]);
+ int newstatus = GetActualStatus(p);
if (newstatus == 0) {
log_debugA("CommonStatus: incorrect status for %s (%d)", p->m_szName, p->m_status);
continue;
@@ -273,7 +267,7 @@ INT_PTR SetStatusEx(WPARAM wParam, LPARAM)
// set status message first
if (b_Caps1 && b_Caps3)
- SetStatusMsg(protoSettings[i], newstatus);
+ SetStatusMsg(p, newstatus);
// set the status
if (newstatus != oldstatus /*&& !(b_Caps1 && b_Caps3 && ServiceExists(MS_NAS_SETSTATE))*/) {
@@ -306,18 +300,6 @@ bool IsSuitableProto(PROTOACCOUNT *pa)
return (pa == nullptr) ? false : pa->IsVisible();
}
-static int CreateServices()
-{
- if (ServiceExists(MS_CS_SETSTATUSEX))
- return -1;
-
- hCSStatusChangedExEvent = CreateHookableEvent(ME_CS_STATUSCHANGEEX);
-
- CreateServiceFunction(MS_CS_SETSTATUSEX, SetStatusEx);
- CreateServiceFunction(MS_CS_GETPROTOCOUNT, GetProtocolCountService);
- return 0;
-}
-
static int onShutdown(WPARAM, LPARAM)
{
g_bMirandaLoaded = false;
@@ -325,10 +307,25 @@ static int onShutdown(WPARAM, LPARAM)
return 0;
}
+static INT_PTR SetStatusEx(WPARAM wParam, LPARAM pCount)
+{
+ PROTOCOLSETTINGEX **protoSettings = *(PROTOCOLSETTINGEX***)wParam;
+ if (protoSettings == nullptr)
+ return -1;
+
+ TProtoSettings ps;
+ for (int i = 0; i < pCount; i++)
+ ps.insert((SMProto*)protoSettings[i]);
+ return SetStatusEx(ps);
+}
+
int InitCommonStatus()
{
- if (!CreateServices())
- HookEvent(ME_SYSTEM_PRESHUTDOWN, onShutdown);
+ hCSStatusChangedExEvent = CreateHookableEvent(ME_CS_STATUSCHANGEEX);
+ CreateServiceFunction(MS_CS_SETSTATUSEX, SetStatusEx);
+ CreateServiceFunction(MS_CS_GETPROTOCOUNT, GetProtocolCountService);
+
+ HookEvent(ME_SYSTEM_PRESHUTDOWN, onShutdown);
return 0;
}
diff --git a/plugins/StatusManager/src/commonstatus.h b/plugins/StatusManager/src/commonstatus.h
index ee9fa8b128..1577f6a5a7 100644
--- a/plugins/StatusManager/src/commonstatus.h
+++ b/plugins/StatusManager/src/commonstatus.h
@@ -138,4 +138,6 @@ extern TProtoSettings protoList;
int CompareProtoSettings(const SMProto *p1, const SMProto *p2);
HWND ShowConfirmDialogEx(TProtoSettings *params, int _timeout);
+int SetStatusEx(TProtoSettings &ps);
+
#endif //COMMONSTATUSHEADER
diff --git a/plugins/StatusManager/src/confirmdialog.cpp b/plugins/StatusManager/src/confirmdialog.cpp
index a833408839..63c13658e0 100644
--- a/plugins/StatusManager/src/confirmdialog.cpp
+++ b/plugins/StatusManager/src/confirmdialog.cpp
@@ -27,27 +27,7 @@
static HWND win;
static int timeOut;
-struct TConfirmSetting : public PROTOCOLSETTINGEX
-{
- TConfirmSetting(const PROTOCOLSETTINGEX &x)
- {
- memcpy(this, &x, sizeof(PROTOCOLSETTINGEX));
- if (m_szMsg)
- m_szMsg = mir_wstrdup(m_szMsg);
- }
-
- ~TConfirmSetting()
- {
- mir_free(m_szMsg);
- }
-};
-
-static int CompareSettings(const TConfirmSetting* p1, const TConfirmSetting* p2)
-{
- return mir_strcmp(p1->m_szName, p2->m_szName);
-}
-
-static OBJLIST<TConfirmSetting> *confirmSettings;
+static TProtoSettings *confirmSettings;
static INT_PTR CALLBACK StatusMessageDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -385,7 +365,7 @@ static INT_PTR CALLBACK ConfirmDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
break;
case UM_CLOSECONFIRMDLG:
- CallService(MS_CS_SETSTATUSEX, (WPARAM)confirmSettings, 0);
+ SetStatusEx(*confirmSettings);
DestroyWindow(hwndDlg);
break;
@@ -400,11 +380,11 @@ static INT_PTR CALLBACK ConfirmDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
HWND ShowConfirmDialogEx(TProtoSettings *params, int _timeout)
{
delete confirmSettings;
- confirmSettings = new OBJLIST<TConfirmSetting>(10, CompareSettings);
+ confirmSettings = new TProtoSettings();
for (auto &it : *params)
if (it->m_status != ID_STATUS_DISABLED)
- confirmSettings->insert(new TConfirmSetting(*it));
+ confirmSettings->insert(new SMProto(*it));
timeOut = _timeout;
if (timeOut < 0)
diff --git a/plugins/StatusManager/src/version.h b/plugins/StatusManager/src/version.h
index 45db33e0dc..b16d6f952c 100644
--- a/plugins/StatusManager/src/version.h
+++ b/plugins/StatusManager/src/version.h
@@ -1,8 +1,8 @@
// plugin version part
#define __MAJOR_VERSION 1
-#define __MINOR_VERSION 1
+#define __MINOR_VERSION 2
#define __RELEASE_NUM 0
-#define __BUILD_NUM 4
+#define __BUILD_NUM 1
// other stuff for Version resource
#include <stdver.h>