summaryrefslogtreecommitdiff
path: root/src/core/stdmsg/src/globals.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/stdmsg/src/globals.cpp')
-rw-r--r--src/core/stdmsg/src/globals.cpp99
1 files changed, 46 insertions, 53 deletions
diff --git a/src/core/stdmsg/src/globals.cpp b/src/core/stdmsg/src/globals.cpp
index 6d32aedc08..ee2b0550dc 100644
--- a/src/core/stdmsg/src/globals.cpp
+++ b/src/core/stdmsg/src/globals.cpp
@@ -21,8 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-struct GlobalMessageData *g_dat;
-static HANDLE g_hooks[4];
+GlobalMessageData g_dat;
static int dbaddedevent(WPARAM wParam, LPARAM lParam);
static int ackevent(WPARAM wParam, LPARAM lParam);
@@ -48,89 +47,86 @@ static int IconsChanged(WPARAM wParam, LPARAM lParam)
return 0;
}
-void InitGlobals()
+static int OnShutdown(WPARAM, LPARAM)
{
- g_dat = (struct GlobalMessageData *)mir_alloc(sizeof(struct GlobalMessageData));
- g_dat->hMessageWindowList = (HANDLE) CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0);
- g_hooks[0] = HookEvent(ME_DB_EVENT_ADDED, dbaddedevent);
- g_hooks[1] = HookEvent(ME_PROTO_ACK, ackevent);
- g_hooks[2] = HookEvent(ME_SKIN2_ICONSCHANGED, IconsChanged);
- g_hooks[3] = HookEvent(ME_AV_AVATARCHANGED, AvatarChanged);
-
- ReloadGlobals();
- InitIcons();
+ WindowList_Broadcast(g_dat.hMessageWindowList, WM_CLOSE, 0, 0);
+ return 0;
}
-void FreeGlobals()
+void InitGlobals()
{
- int i;
- mir_free(g_dat);
+ g_dat.hMessageWindowList = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0);
+
+ HookEvent(ME_DB_EVENT_ADDED, dbaddedevent);
+ HookEvent(ME_PROTO_ACK, ackevent);
+ HookEvent(ME_SKIN2_ICONSCHANGED, IconsChanged);
+ HookEvent(ME_AV_AVATARCHANGED, AvatarChanged);
+ HookEvent(ME_SYSTEM_SHUTDOWN, OnShutdown);
- for (i=0; i < SIZEOF(g_hooks); ++i)
- if (g_hooks[i])
- UnhookEvent(g_hooks[i]);
+ ReloadGlobals();
+ InitIcons();
}
void ReloadGlobals()
{
- g_dat->flags = 0;
+ g_dat.flags = 0;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWINFOLINE, SRMSGDEFSET_SHOWINFOLINE))
- g_dat->flags |= SMF_SHOWINFO;
+ g_dat.flags |= SMF_SHOWINFO;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWBUTTONLINE, SRMSGDEFSET_SHOWBUTTONLINE))
- g_dat->flags |= SMF_SHOWBTNS;
+ g_dat.flags |= SMF_SHOWBTNS;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SENDBUTTON, SRMSGDEFSET_SENDBUTTON))
- g_dat->flags |= SMF_SENDBTN;
+ g_dat.flags |= SMF_SENDBTN;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPING, SRMSGDEFSET_SHOWTYPING))
- g_dat->flags |= SMF_SHOWTYPING;
+ g_dat.flags |= SMF_SHOWTYPING;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGWIN, SRMSGDEFSET_SHOWTYPINGWIN))
- g_dat->flags |= SMF_SHOWTYPINGWIN;
+ g_dat.flags |= SMF_SHOWTYPINGWIN;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGNOWIN, SRMSGDEFSET_SHOWTYPINGNOWIN))
- g_dat->flags |= SMF_SHOWTYPINGTRAY;
+ g_dat.flags |= SMF_SHOWTYPINGTRAY;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWTYPINGCLIST, SRMSGDEFSET_SHOWTYPINGCLIST))
- g_dat->flags |= SMF_SHOWTYPINGCLIST;
+ g_dat.flags |= SMF_SHOWTYPINGCLIST;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWLOGICONS, SRMSGDEFSET_SHOWLOGICONS))
- g_dat->flags |= SMF_SHOWICONS;
+ g_dat.flags |= SMF_SHOWICONS;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWTIME, SRMSGDEFSET_SHOWTIME))
- g_dat->flags |= SMF_SHOWTIME;
+ g_dat.flags |= SMF_SHOWTIME;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_AVATARENABLE, SRMSGDEFSET_AVATARENABLE))
- g_dat->flags |= SMF_AVATAR;
+ g_dat.flags |= SMF_AVATAR;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWDATE, SRMSGDEFSET_SHOWDATE))
- g_dat->flags |= SMF_SHOWDATE;
+ g_dat.flags |= SMF_SHOWDATE;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWSECS, SRMSGDEFSET_SHOWSECS))
- g_dat->flags |= SMF_SHOWSECS;
+ g_dat.flags |= SMF_SHOWSECS;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_HIDENAMES, SRMSGDEFSET_HIDENAMES))
- g_dat->flags |= SMF_HIDENAMES;
+ g_dat.flags |= SMF_HIDENAMES;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_CHARCOUNT, SRMSGDEFSET_CHARCOUNT))
- g_dat->flags |= SMF_SHOWREADCHAR;
+ g_dat.flags |= SMF_SHOWREADCHAR;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SENDONENTER, SRMSGDEFSET_SENDONENTER))
- g_dat->flags |= SMF_SENDONENTER;
+ g_dat.flags |= SMF_SENDONENTER;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SENDONDBLENTER, SRMSGDEFSET_SENDONDBLENTER))
- g_dat->flags |= SMF_SENDONDBLENTER;
+ g_dat.flags |= SMF_SENDONDBLENTER;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_AUTOCLOSE, SRMSGDEFSET_AUTOCLOSE))
- g_dat->flags |= SMF_AUTOCLOSE;
+ g_dat.flags |= SMF_AUTOCLOSE;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_AUTOMIN, SRMSGDEFSET_AUTOMIN))
- g_dat->flags |= SMF_AUTOMIN;
+ g_dat.flags |= SMF_AUTOMIN;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_TYPINGUNKNOWN, SRMSGDEFSET_TYPINGUNKNOWN))
- g_dat->flags |= SMF_TYPINGUNKNOWN;
+ g_dat.flags |= SMF_TYPINGUNKNOWN;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_CTRLSUPPORT, SRMSGDEFSET_CTRLSUPPORT))
- g_dat->flags |= SMF_CTRLSUPPORT;
+ g_dat.flags |= SMF_CTRLSUPPORT;
if (db_get_b(NULL, SRMMMOD, SRMSGSET_SHOWFORMAT, SRMSGDEFSET_SHOWFORMAT))
- g_dat->flags |= SMF_SHOWFORMAT;
+ g_dat.flags |= SMF_SHOWFORMAT;
- g_dat->openFlags = DBGetContactSettingDword(NULL, SRMMMOD, SRMSGSET_POPFLAGS, SRMSGDEFSET_POPFLAGS);
- g_dat->nFlashMax = db_get_b(NULL, SRMMMOD, SRMSGSET_FLASHCOUNT, SRMSGDEFSET_FLASHCOUNT);
+ g_dat.openFlags = DBGetContactSettingDword(NULL, SRMMMOD, SRMSGSET_POPFLAGS, SRMSGDEFSET_POPFLAGS);
+ g_dat.nFlashMax = db_get_b(NULL, SRMMMOD, SRMSGSET_FLASHCOUNT, SRMSGDEFSET_FLASHCOUNT);
- g_dat->msgTimeout = DBGetContactSettingDword(NULL, SRMMMOD, SRMSGSET_MSGTIMEOUT, SRMSGDEFSET_MSGTIMEOUT);
- if (g_dat->msgTimeout < SRMSGSET_MSGTIMEOUT_MIN) g_dat->msgTimeout = SRMSGDEFSET_MSGTIMEOUT;
+ g_dat.msgTimeout = DBGetContactSettingDword(NULL, SRMMMOD, SRMSGSET_MSGTIMEOUT, SRMSGDEFSET_MSGTIMEOUT);
+ if (g_dat.msgTimeout < SRMSGSET_MSGTIMEOUT_MIN) g_dat.msgTimeout = SRMSGDEFSET_MSGTIMEOUT;
}
static int dbaddedevent(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
- if (hContact)
- {
- HWND h = WindowList_Find(g_dat->hMessageWindowList, hContact);
- if (h) SendMessage(h, HM_DBEVENTADDED, (WPARAM)hContact, lParam);
+ if (hContact) {
+ HWND h = WindowList_Find(g_dat.hMessageWindowList, hContact);
+ if (h)
+ SendMessage(h, HM_DBEVENTADDED, (WPARAM)hContact, lParam);
}
return 0;
}
@@ -138,10 +134,7 @@ static int dbaddedevent(WPARAM wParam, LPARAM lParam)
static int ackevent(WPARAM wParam, LPARAM lParam)
{
ACKDATA *pAck = (ACKDATA *)lParam;
-
- if (!pAck) return 0;
- if (pAck->type == ACKTYPE_MESSAGE)
- {
+ if (pAck && pAck->type == ACKTYPE_MESSAGE) {
msgQueue_processack(pAck->hContact, pAck->hProcess, pAck->result == ACKRESULT_SUCCESS, (char*)pAck->lParam);
if (pAck->result == ACKRESULT_SUCCESS)
@@ -153,7 +146,7 @@ static int ackevent(WPARAM wParam, LPARAM lParam)
int AvatarChanged(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
- HWND h = WindowList_Find(g_dat->hMessageWindowList, hContact);
+ HWND h = WindowList_Find(g_dat.hMessageWindowList, hContact);
if (h) SendMessage(h, HM_AVATARACK, wParam, lParam);
return 0;
}