summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Clist_modern/src/modern_clistevents.cpp126
-rw-r--r--plugins/Clist_nicer/src/clistevents.cpp190
-rw-r--r--src/modules/clist/clistevents.cpp167
3 files changed, 221 insertions, 262 deletions
diff --git a/plugins/Clist_modern/src/modern_clistevents.cpp b/plugins/Clist_modern/src/modern_clistevents.cpp
index 35b49b5a0e..9632f6665a 100644
--- a/plugins/Clist_modern/src/modern_clistevents.cpp
+++ b/plugins/Clist_modern/src/modern_clistevents.cpp
@@ -103,92 +103,78 @@ CListEvent* cliCreateEvent( void )
struct CListEvent* cli_AddEvent(CLISTEVENT *cle)
{
struct CListEvent* p = corecli.pfnAddEvent(cle);
- if ( p == NULL )
+ if (p == NULL)
return NULL;
- if (1) {
- if (p->cle.hContact != 0 && p->cle.hDbEvent != (HANDLE) 1 && !(p->cle.flags & CLEF_ONLYAFEW)) {
- int j;
- struct NotifyMenuItemExData *nmi = 0;
- char *szProto;
- TCHAR *szName;
- MENUITEMINFO mii = {0};
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_DATA | MIIM_BITMAP | MIIM_ID;
- if (p->cle.pszService && ( !strncmp("SRMsg/ReadMessage", p->cle.pszService, SIZEOF("SRMsg/ReadMessage"))
- || !strncmp("GChat/DblClickEvent", p->cle.pszService, SIZEOF("GChat/DblClickEvent"))))
-
- {
- // dup check only for msg events
- for (j = 0; j < GetMenuItemCount(g_CluiData.hMenuNotify); j++) {
- if (GetMenuItemInfo(g_CluiData.hMenuNotify, j, TRUE, &mii) != 0) {
- nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
- if (nmi != 0 && (HANDLE) nmi->hContact == (HANDLE) p->cle.hContact && nmi->iIcon == p->imlIconIndex)
- return p;
- } } }
-
- szProto = GetContactProto(p->cle.hContact);
- szName = pcli->pfnGetContactDisplayName(p->cle.hContact, 0);
- if (szProto && szName) {
- nmi = (struct NotifyMenuItemExData *) malloc(sizeof(struct NotifyMenuItemExData));
- if (nmi) {
- TCHAR szBuffer[128];
- TCHAR* szStatus = pcli->pfnGetStatusModeDescription(db_get_w(p->cle.hContact, szProto, "Status", ID_STATUS_OFFLINE), 0);
- TCHAR szwProto[64];
- MultiByteToWideChar(CP_ACP, 0, szProto, -1, szwProto, 64);
- szwProto[63] = 0;
- mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s: %s (%s)"), szwProto, szName, szStatus);
- szBuffer[127] = 0;
- AppendMenu(g_CluiData.hMenuNotify, MF_BYCOMMAND | MF_STRING, g_CluiData.wNextMenuID, szBuffer);
- mii.hbmpItem = HBMMENU_CALLBACK;
- nmi->hContact = p->cle.hContact;
- nmi->iIcon = p->imlIconIndex;
- nmi->hIcon = p->cle.hIcon;
- nmi->hDbEvent = p->cle.hDbEvent;
- mii.dwItemData = (ULONG_PTR) nmi;
- mii.wID = g_CluiData.wNextMenuID;
- SetMenuItemInfo(g_CluiData.hMenuNotify, g_CluiData.wNextMenuID, FALSE, &mii);
- p-> menuId = g_CluiData.wNextMenuID;
- g_CluiData.wNextMenuID++;
- if (g_CluiData.wNextMenuID > 0x7fff)
- g_CluiData.wNextMenuID = 1;
- g_CluiData.iIconNotify = p->imlIconIndex;
- }
+ if (p->cle.hContact != 0 && p->cle.hDbEvent != (HANDLE) 1 && !(p->cle.flags & CLEF_ONLYAFEW)) {
+ MENUITEMINFO mii = { sizeof(mii) };
+ mii.fMask = MIIM_DATA | MIIM_BITMAP | MIIM_ID;
+ if (p->cle.pszService &&
+ (!strncmp("SRMsg/ReadMessage", p->cle.pszService, SIZEOF("SRMsg/ReadMessage")) ||
+ !strncmp("GChat/DblClickEvent", p->cle.pszService, SIZEOF("GChat/DblClickEvent"))))
+ {
+ // dup check only for msg events
+ for (int j = 0; j < GetMenuItemCount(g_CluiData.hMenuNotify); j++) {
+ if (GetMenuItemInfo(g_CluiData.hMenuNotify, j, TRUE, &mii) != 0) {
+ NotifyMenuItemExData *nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
+ if (nmi != 0 && (HANDLE) nmi->hContact == (HANDLE) p->cle.hContact && nmi->iIcon == p->imlIconIndex)
+ return p;
+ } } }
+
+ char *szProto = GetContactProto(p->cle.hContact);
+ TCHAR *szName = pcli->pfnGetContactDisplayName(p->cle.hContact, 0);
+ if (szProto && szName) {
+ NotifyMenuItemExData *nmi = (struct NotifyMenuItemExData *) malloc(sizeof(struct NotifyMenuItemExData));
+ if (nmi) {
+ TCHAR szBuffer[128];
+ TCHAR* szStatus = pcli->pfnGetStatusModeDescription(db_get_w(p->cle.hContact, szProto, "Status", ID_STATUS_OFFLINE), 0);
+ TCHAR szwProto[64];
+ MultiByteToWideChar(CP_ACP, 0, szProto, -1, szwProto, 64);
+ szwProto[63] = 0;
+ mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s: %s (%s)"), szwProto, szName, szStatus);
+ szBuffer[127] = 0;
+ AppendMenu(g_CluiData.hMenuNotify, MF_BYCOMMAND | MF_STRING, g_CluiData.wNextMenuID, szBuffer);
+ mii.hbmpItem = HBMMENU_CALLBACK;
+ nmi->hContact = p->cle.hContact;
+ nmi->iIcon = p->imlIconIndex;
+ nmi->hIcon = p->cle.hIcon;
+ nmi->hDbEvent = p->cle.hDbEvent;
+ mii.dwItemData = (ULONG_PTR) nmi;
+ mii.wID = g_CluiData.wNextMenuID;
+ SetMenuItemInfo(g_CluiData.hMenuNotify, g_CluiData.wNextMenuID, FALSE, &mii);
+ p-> menuId = g_CluiData.wNextMenuID;
+ g_CluiData.wNextMenuID++;
+ if (g_CluiData.wNextMenuID > 0x7fff)
+ g_CluiData.wNextMenuID = 1;
+ g_CluiData.iIconNotify = p->imlIconIndex;
}
}
+ }
+ else if (p->cle.hContact != 0 && (p->cle.flags & CLEF_ONLYAFEW)) {
+ g_CluiData.iIconNotify = p->imlIconIndex;
+ g_CluiData.hUpdateContact = p->cle.hContact;
+ }
- else if (p->cle.hContact != 0 && (p->cle.flags & CLEF_ONLYAFEW))
- {
- g_CluiData.iIconNotify = p->imlIconIndex;
- g_CluiData.hUpdateContact = p->cle.hContact;
+ if (pcli->events.count > 0) {
+ g_CluiData.bEventAreaEnabled = TRUE;
+ if (g_CluiData.bNotifyActive == FALSE) {
+ g_CluiData.bNotifyActive = TRUE;
+ EventArea_HideShowNotifyFrame();
}
- if (pcli->events.count > 0) {
- g_CluiData.bEventAreaEnabled = TRUE;
- if (g_CluiData.bNotifyActive == FALSE) {
- g_CluiData.bNotifyActive = TRUE;
- EventArea_HideShowNotifyFrame();
- }
- }
- CLUI__cliInvalidateRect(g_CluiData.hwndEventFrame, NULL, FALSE);
}
+ CLUI__cliInvalidateRect(g_CluiData.hwndEventFrame, NULL, FALSE);
return p;
}
int cli_RemoveEvent(MCONTACT hContact, HANDLE hDbEvent)
{
- int i;
- int res = 0;
-
// Find the event that should be removed
- for (i=0; i < pcli->events.count; i++)
- {
+ int i;
+ for (i = 0; i < pcli->events.count; i++)
if ((pcli->events.items[i]->cle.hContact == hContact) && (pcli->events.items[i]->cle.hDbEvent == hDbEvent))
- {
break;
- }
- }
// Event was not found
if (i == pcli->events.count)
@@ -208,7 +194,7 @@ int cli_RemoveEvent(MCONTACT hContact, HANDLE hDbEvent)
}
}
- res = corecli.pfnRemoveEvent(hContact, hDbEvent);
+ int res = corecli.pfnRemoveEvent(hContact, hDbEvent);
if (pcli->events.count == 0) {
g_CluiData.bNotifyActive = FALSE;
diff --git a/plugins/Clist_nicer/src/clistevents.cpp b/plugins/Clist_nicer/src/clistevents.cpp
index 6ac09b985a..68527e01e0 100644
--- a/plugins/Clist_nicer/src/clistevents.cpp
+++ b/plugins/Clist_nicer/src/clistevents.cpp
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static HWND hwndEventFrame = 0;
HFONT __fastcall ChangeToFont(HDC hdc, struct ClcData *dat, int id, int *fontHeight);
-extern struct CListEvent* ( *saveAddEvent )(CLISTEVENT *cle);
+extern CListEvent* ( *saveAddEvent )(CLISTEVENT *cle);
extern int ( *saveRemoveEvent )(MCONTACT hContact, HANDLE hDbEvent);
extern FRAMEWND *wndFrameEventArea;
@@ -36,7 +36,8 @@ extern HPEN g_hPenCLUIFrames;
HWND g_hwndEventArea = 0;
-struct CListEvent {
+struct CListEvent
+{
int imlIconIndex;
int flashesDone;
CLISTEVENT cle;
@@ -45,7 +46,8 @@ struct CListEvent {
int imlIconOverlayIndex;
};
-struct CListImlIcon {
+struct CListImlIcon
+{
int index;
HICON hIcon;
};
@@ -55,11 +57,11 @@ extern HIMAGELIST hCListImages;
HANDLE hNotifyFrame = (HANDLE)-1;
-struct CListEvent* fnCreateEvent( void )
+CListEvent* fnCreateEvent( void )
{
- CListEvent *p = reinterpret_cast<CListEvent *>(mir_alloc(sizeof(struct CListEvent)));
+ CListEvent *p = reinterpret_cast<CListEvent *>(mir_alloc(sizeof(CListEvent)));
if (p)
- ZeroMemory(p, sizeof(struct CListEvent));
+ ZeroMemory(p, sizeof(CListEvent));
return p;
}
@@ -89,7 +91,7 @@ static CLISTEVENT* MyGetEvent(int iSelection)
int i;
for (i = 0; i < pcli->events.count; i++) {
- struct CListEvent* p = pcli->events.items[i];
+ CListEvent* p = pcli->events.items[i];
if (p->menuId == iSelection)
return &p->cle;
}
@@ -251,80 +253,76 @@ LRESULT CALLBACK EventAreaWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa
return TRUE;
}
-struct CListEvent* AddEvent(CLISTEVENT *cle)
+CListEvent* AddEvent(CLISTEVENT *cle)
{
- struct CListEvent* p = saveAddEvent(cle);
- if ( p == NULL )
+ CListEvent *p = saveAddEvent(cle);
+ if (p == NULL)
return NULL;
- if (1) {
- if (p->cle.hContact != 0 && p->cle.hDbEvent != (HANDLE)1 && !(p->cle.flags & CLEF_ONLYAFEW)) {
- int j;
- struct NotifyMenuItemExData *nmi = 0;
- char *szProto;
- TCHAR *szName;
- MENUITEMINFO mii = {0};
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_DATA | MIIM_BITMAP | MIIM_ID;
- if (p->cle.pszService && !strncmp("SRMsg/ReadMessage", p->cle.pszService, 17)) {
- // dup check only for msg events
- for (j = 0; j < GetMenuItemCount(cfg::dat.hMenuNotify); j++) {
- if (GetMenuItemInfo(cfg::dat.hMenuNotify, j, TRUE, &mii) != 0) {
- nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
- if (nmi != 0 && (HANDLE)nmi->hContact == (HANDLE)p->cle.hContact && nmi->iIcon == p->imlIconIndex)
- return p;
- } } }
-
- szProto = GetContactProto(p->cle.hContact);
- szName = pcli->pfnGetContactDisplayName(p->cle.hContact, 0);
- if (szProto && szName) {
- nmi = (struct NotifyMenuItemExData *) malloc(sizeof(struct NotifyMenuItemExData));
- if (nmi) {
- TCHAR szBuffer[128];
- TCHAR* szStatus = pcli->pfnGetStatusModeDescription(cfg::getWord(p->cle.hContact, szProto, "Status", ID_STATUS_OFFLINE), 0);
-
- TCHAR szwProto[64];
- MultiByteToWideChar(CP_ACP, 0, szProto, -1, szwProto, 64);
- szwProto[63] = 0;
- mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s: %s (%s)"), szwProto, szName, szStatus);
-
- szBuffer[127] = 0;
- AppendMenu(cfg::dat.hMenuNotify, MF_BYCOMMAND | MF_STRING, cfg::dat.wNextMenuID, szBuffer);
- mii.hbmpItem = HBMMENU_CALLBACK;
- nmi->hContact = p->cle.hContact;
- nmi->iIcon = p->imlIconIndex;
- nmi->hIcon = p->cle.hIcon;
- nmi->hDbEvent = p->cle.hDbEvent;
- mii.dwItemData = (ULONG_PTR) nmi;
- mii.wID = cfg::dat.wNextMenuID;
- SetMenuItemInfo(cfg::dat.hMenuNotify, cfg::dat.wNextMenuID, FALSE, &mii);
- p->menuId = cfg::dat.wNextMenuID;
- cfg::dat.wNextMenuID++;
- if (cfg::dat.wNextMenuID > 0x7fff)
- cfg::dat.wNextMenuID = 1;
- cfg::dat.hIconNotify = p->imlIconIndex;
- }
+ if (p->cle.hContact != 0 && p->cle.hDbEvent != (HANDLE)1 && !(p->cle.flags & CLEF_ONLYAFEW)) {
+ MENUITEMINFO mii = { sizeof(mii) };
+ mii.fMask = MIIM_DATA | MIIM_BITMAP | MIIM_ID;
+ if (p->cle.pszService && !strncmp("SRMsg/ReadMessage", p->cle.pszService, 17)) {
+ // dup check only for msg events
+ for (int j = 0; j < GetMenuItemCount(cfg::dat.hMenuNotify); j++) {
+ if (GetMenuItemInfo(cfg::dat.hMenuNotify, j, TRUE, &mii) != 0) {
+ NotifyMenuItemExData *nmi = (NotifyMenuItemExData*) mii.dwItemData;
+ if (nmi != 0 && (HANDLE)nmi->hContact == (HANDLE)p->cle.hContact && nmi->iIcon == p->imlIconIndex)
+ return p;
+ } } }
+
+ char *szProto = GetContactProto(p->cle.hContact);
+ TCHAR *szName = pcli->pfnGetContactDisplayName(p->cle.hContact, 0);
+ if (szProto && szName) {
+ NotifyMenuItemExData *nmi = (NotifyMenuItemExData*) malloc(sizeof(NotifyMenuItemExData));
+ if (nmi) {
+ TCHAR szBuffer[128];
+ TCHAR* szStatus = pcli->pfnGetStatusModeDescription(cfg::getWord(p->cle.hContact, szProto, "Status", ID_STATUS_OFFLINE), 0);
+
+ TCHAR szwProto[64];
+ MultiByteToWideChar(CP_ACP, 0, szProto, -1, szwProto, 64);
+ szwProto[63] = 0;
+ mir_sntprintf(szBuffer, SIZEOF(szBuffer), _T("%s: %s (%s)"), szwProto, szName, szStatus);
+
+ szBuffer[127] = 0;
+ AppendMenu(cfg::dat.hMenuNotify, MF_BYCOMMAND | MF_STRING, cfg::dat.wNextMenuID, szBuffer);
+ mii.hbmpItem = HBMMENU_CALLBACK;
+ nmi->hContact = p->cle.hContact;
+ nmi->iIcon = p->imlIconIndex;
+ nmi->hIcon = p->cle.hIcon;
+ nmi->hDbEvent = p->cle.hDbEvent;
+ mii.dwItemData = (ULONG_PTR)nmi;
+ mii.wID = cfg::dat.wNextMenuID;
+ SetMenuItemInfo(cfg::dat.hMenuNotify, cfg::dat.wNextMenuID, FALSE, &mii);
+ p->menuId = cfg::dat.wNextMenuID;
+ cfg::dat.wNextMenuID++;
+ if (cfg::dat.wNextMenuID > 0x7fff)
+ cfg::dat.wNextMenuID = 1;
+ cfg::dat.hIconNotify = p->imlIconIndex;
}
- } else if (p->cle.hContact != 0 && (p->cle.flags & CLEF_ONLYAFEW)) {
- cfg::dat.hIconNotify = p->imlIconIndex;
- cfg::dat.hUpdateContact = p->cle.hContact;
}
- if (cfg::dat.dwFlags & CLUI_STICKYEVENTS) {
- HANDLE hItem = (HANDLE)SendMessage(pcli->hwndContactTree, CLM_FINDCONTACT, (WPARAM) p->cle.hContact, 0);
- if (hItem) {
- SendMessage(pcli->hwndContactTree, CLM_SETSTICKY, (WPARAM) hItem, 1);
- pcli->pfnClcBroadcast(INTM_PROTOCHANGED, (WPARAM) p->cle.hContact, 0);
- }
+ }
+ else if (p->cle.hContact != 0 && (p->cle.flags & CLEF_ONLYAFEW)) {
+ cfg::dat.hIconNotify = p->imlIconIndex;
+ cfg::dat.hUpdateContact = p->cle.hContact;
+ }
+
+ if (cfg::dat.dwFlags & CLUI_STICKYEVENTS) {
+ HANDLE hItem = (HANDLE)SendMessage(pcli->hwndContactTree, CLM_FINDCONTACT, (WPARAM) p->cle.hContact, 0);
+ if (hItem) {
+ SendMessage(pcli->hwndContactTree, CLM_SETSTICKY, (WPARAM) hItem, 1);
+ pcli->pfnClcBroadcast(INTM_PROTOCHANGED, (WPARAM) p->cle.hContact, 0);
}
- if (pcli->events.count > 0) {
- cfg::dat.bEventAreaEnabled = TRUE;
- if (cfg::dat.notifyActive == 0) {
- cfg::dat.notifyActive = 1;
- HideShowNotifyFrame();
- }
+ }
+
+ if (pcli->events.count > 0) {
+ cfg::dat.bEventAreaEnabled = TRUE;
+ if (cfg::dat.notifyActive == 0) {
+ cfg::dat.notifyActive = 1;
+ HideShowNotifyFrame();
}
- InvalidateRect(hwndEventFrame, NULL, FALSE);
}
+ InvalidateRect(hwndEventFrame, NULL, FALSE);
return p;
}
@@ -335,33 +333,27 @@ struct CListEvent* AddEvent(CLISTEVENT *cle)
// Returns 0 if the event was successfully removed, or nonzero if the event was not found
int RemoveEvent(MCONTACT hContact, HANDLE hDbEvent)
{
- HANDLE hItem;
- int i;
- BOOL bUnstick = TRUE;
-
// Find the event that should be removed
- for (i = 0; i < pcli->events.count; i++) {
- if ((pcli->events.items[i]->cle.hContact == hContact) && (pcli->events.items[i]->cle.hDbEvent == hDbEvent)) {
+ int i;
+ for (i = 0; i < pcli->events.count; i++)
+ if ((pcli->events.items[i]->cle.hContact == hContact) && (pcli->events.items[i]->cle.hDbEvent == hDbEvent))
break;
- }
- }
// Event was not found
if (i == pcli->events.count)
return 1;
// remove event from the notify menu
- if (1) {
- if (pcli->events.items[i]->menuId > 0) {
- MENUITEMINFO mii = {0};
- mii.cbSize = sizeof(mii);
- mii.fMask = MIIM_DATA;
- if (GetMenuItemInfo(cfg::dat.hMenuNotify, pcli->events.items[i]->menuId, FALSE, &mii) != 0) {
- struct NotifyMenuItemExData *nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
- if (nmi && nmi->hContact == hContact && nmi->hDbEvent == hDbEvent) {
- free(nmi);
- DeleteMenu(cfg::dat.hMenuNotify, pcli->events.items[i]->menuId, MF_BYCOMMAND);
- } } } }
+ if (pcli->events.items[i]->menuId > 0) {
+ MENUITEMINFO mii = {0};
+ mii.cbSize = sizeof(mii);
+ mii.fMask = MIIM_DATA;
+ if (GetMenuItemInfo(cfg::dat.hMenuNotify, pcli->events.items[i]->menuId, FALSE, &mii) != 0) {
+ struct NotifyMenuItemExData *nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
+ if (nmi && nmi->hContact == hContact && nmi->hDbEvent == hDbEvent) {
+ free(nmi);
+ DeleteMenu(cfg::dat.hMenuNotify, pcli->events.items[i]->menuId, MF_BYCOMMAND);
+ } } }
saveRemoveEvent(hContact, hDbEvent);
@@ -372,14 +364,12 @@ int RemoveEvent(MCONTACT hContact, HANDLE hDbEvent)
HideShowNotifyFrame();
} }
- if (bUnstick) {
- // clear "sticky" (sort) status
-
- hItem = (HANDLE)SendMessage(pcli->hwndContactTree, CLM_FINDCONTACT, hContact, 0);
- if (hItem) {
- SendMessage(pcli->hwndContactTree, CLM_SETSTICKY, (WPARAM) hItem, 0);
- pcli->pfnClcBroadcast(INTM_PROTOCHANGED, hContact, 0);
- } }
+ // clear "sticky" (sort) status
+ HANDLE hItem = (HANDLE)SendMessage(pcli->hwndContactTree, CLM_FINDCONTACT, hContact, 0);
+ if (hItem) {
+ SendMessage(pcli->hwndContactTree, CLM_SETSTICKY, (WPARAM)hItem, 0);
+ pcli->pfnClcBroadcast(INTM_PROTOCHANGED, hContact, 0);
+ }
if (hContact == cfg::dat.hUpdateContact || (INT_PTR)hDbEvent == 1)
cfg::dat.hUpdateContact = 0;
diff --git a/src/modules/clist/clistevents.cpp b/src/modules/clist/clistevents.cpp
index 73b3abfb4c..10c728e187 100644
--- a/src/modules/clist/clistevents.cpp
+++ b/src/modules/clist/clistevents.cpp
@@ -50,11 +50,10 @@ static int disableIconFlash;
int fnGetImlIconIndex(HICON hIcon)
{
int i;
-
- for (i=0; i < imlIconCount; i++) {
+ for (i=0; i < imlIconCount; i++)
if (imlIcon[i].hIcon == hIcon)
return imlIcon[i].index;
- }
+
imlIcon = (struct CListImlIcon *) mir_realloc(imlIcon, sizeof(struct CListImlIcon) * (imlIconCount + 1));
imlIconCount++;
imlIcon[i].hIcon = hIcon;
@@ -64,21 +63,14 @@ int fnGetImlIconIndex(HICON hIcon)
static char * GetEventProtocol(int idx)
{
- if (cli.events.count && idx>=0 && idx<cli.events.count)
- {
- char *szProto;
- if (cli.events.items[idx]->cle.hContact == NULL)
- {
- if (cli.events.items[idx]->cle.flags&CLEF_PROTOCOLGLOBAL)
- szProto = cli.events.items[idx]->cle.lpszProtocol;
- else
- szProto = NULL;
- }
- else
- szProto = GetContactProto(cli.events.items[idx]->cle.hContact);
- return szProto;
- }
- return NULL;
+ if (!cli.events.count || idx < 0 && idx >= cli.events.count)
+ return NULL;
+
+ CListEvent *ev = cli.events.items[idx];
+ if (ev->cle.hContact != NULL)
+ return GetContactProto(ev->cle.hContact);
+
+ return (ev->cle.flags & CLEF_PROTOCOLGLOBAL) ? ev->cle.lpszProtocol : NULL;
}
static void ShowOneEventInTray(int idx)
@@ -88,13 +80,9 @@ static void ShowOneEventInTray(int idx)
static void ShowEventsInTray()
{
- int i;
- char ** pTrayProtos;
- char nTrayProtoCnt;
int nTrayCnt = cli.trayIconCount;
if (!cli.events.count || !nTrayCnt) return;
- if (cli.events.count == 1 || nTrayCnt == 1)
- {
+ if (cli.events.count == 1 || nTrayCnt == 1) {
ShowOneEventInTray(0); //for only one icon in tray show topmost event
return;
}
@@ -102,45 +90,45 @@ static void ShowEventsInTray()
// in case if we have several icons in tray and several events with different protocols
// lets use several icon to show events from protocols in different icons
cli.pfnLockTray();
- pTrayProtos = (char**)_alloca(sizeof(char*)*cli.trayIconCount);
- nTrayProtoCnt = 0;
- for (i=0; i<cli.trayIconCount; i++)
- {
+ char **pTrayProtos = (char**)_alloca(sizeof(char*)*cli.trayIconCount);
+ int nTrayProtoCnt = 0;
+ for (int i = 0; i < cli.trayIconCount; i++) {
if (cli.trayIcon[i].id == 0 || !cli.trayIcon[i].szProto) continue;
pTrayProtos[nTrayProtoCnt++] = cli.trayIcon[i].szProto;
}
- for (i=0; i<cli.events.count; i++)
- {
- char * iEventProto = GetEventProtocol(i);
- {
- int j;
- for (j = 0; j<nTrayProtoCnt; j++)
- if (iEventProto && pTrayProtos[j] && !lstrcmpA(pTrayProtos[j], iEventProto))
- break;
- if (j>=nTrayProtoCnt) j = 0; //event was not found so assume first icon
- if (pTrayProtos[j]) //if not already set
- ShowOneEventInTray(i); //show it
- pTrayProtos[j] = NULL; //and clear slot
- }
+
+ for (int i = 0; i < cli.events.count; i++) {
+ char *iEventProto = GetEventProtocol(i);
+
+ int j;
+ for (j = 0; j < nTrayProtoCnt; j++)
+ if (iEventProto && pTrayProtos[j] && !lstrcmpA(pTrayProtos[j], iEventProto))
+ break;
+ if (j >= nTrayProtoCnt) // event was not found so assume first icon
+ j = 0;
+ if (pTrayProtos[j]) // if not already set
+ ShowOneEventInTray(i); // show it
+ pTrayProtos[j] = NULL; // and clear slot
}
cli.pfnUnlockTray();
}
static VOID CALLBACK IconFlashTimer(HWND, UINT, UINT_PTR idEvent, DWORD)
{
- int i, j;
ShowEventsInTray();
- for (i=0; i < cli.events.count; i++) {
+
+ for (int i=0; i < cli.events.count; i++) {
+ int j;
for (j = 0; j < i; j++)
if (cli.events.items[j]->cle.hContact == cli.events.items[i]->cle.hContact)
break;
if (j >= i)
cli.pfnChangeContactIcon(cli.events.items[i]->cle.hContact, iconsOn || disableIconFlash ? cli.events.items[i]->imlIconIndex : 0, 0);
- //decrease eflashes in any case - no need to collect all events
- if (cli.events.items[i]->cle.flags & CLEF_ONLYAFEW) {
+
+ // decrease eflashes in any case - no need to collect all events
+ if (cli.events.items[i]->cle.flags & CLEF_ONLYAFEW)
if (0 >= --cli.events.items[i]->flashesDone)
cli.pfnRemoveEvent(cli.events.items[i]->cle.hContact, cli.events.items[i]->cle.hDbEvent);
- }
}
if (cli.events.count == 0) {
@@ -151,10 +139,9 @@ static VOID CALLBACK IconFlashTimer(HWND, UINT, UINT_PTR idEvent, DWORD)
iconsOn = !iconsOn;
}
-struct CListEvent* fnAddEvent(CLISTEVENT *cle)
+CListEvent* fnAddEvent(CLISTEVENT *cle)
{
int i;
- struct CListEvent* p;
if (cle == NULL || cle->cbSize != sizeof(CLISTEVENT))
return NULL;
@@ -166,23 +153,26 @@ struct CListEvent* fnAddEvent(CLISTEVENT *cle)
}
else i = cli.events.count;
- if ((p = (struct CListEvent*)cli.pfnCreateEvent()) == NULL)
+ CListEvent *p = cli.pfnCreateEvent();
+ if (p == NULL)
return NULL;
+ if (db_mc_isSub(cle->hContact))
+ cle->hContact = db_mc_getMeta(cle->hContact);
+
List_Insert((SortedList*)&cli.events, p, i);
p->cle = *cle;
p->imlIconIndex = fnGetImlIconIndex(cli.events.items[i]->cle.hIcon);
p->flashesDone = 12;
p->cle.pszService = mir_strdup(cli.events.items[i]->cle.pszService);
if (p->cle.flags & CLEF_UNICODE)
- p->cle.ptszTooltip = mir_tstrdup((TCHAR*)p->cle.ptszTooltip);
+ p->cle.ptszTooltip = mir_tstrdup(p->cle.ptszTooltip);
else
- p->cle.ptszTooltip = mir_a2u((char*)p->cle.pszTooltip); //if no flag defined it handled as unicode
+ p->cle.ptszTooltip = mir_a2u(p->cle.pszTooltip); //if no flag defined it handled as unicode
if (cli.events.count == 1) {
char *szProto;
- if (cle->hContact == NULL)
- {
- if (cle->flags&CLEF_PROTOCOLGLOBAL)
+ if (cle->hContact == NULL) {
+ if (cle->flags & CLEF_PROTOCOLGLOBAL)
szProto = cle->lpszProtocol;
else
szProto = NULL;
@@ -202,11 +192,8 @@ struct CListEvent* fnAddEvent(CLISTEVENT *cle)
// Returns 0 if the event was successfully removed, or nonzero if the event was not found
int fnRemoveEvent(MCONTACT hContact, HANDLE dbEvent)
{
- int i;
- char *szProto;
- int nSameProto = 0;
-
// Find the event that should be removed
+ int i;
for (i=0; i < cli.events.count; i++)
if ((cli.events.items[i]->cle.hContact == hContact) && (cli.events.items[i]->cle.hDbEvent == dbEvent))
break;
@@ -216,31 +203,28 @@ int fnRemoveEvent(MCONTACT hContact, HANDLE dbEvent)
return 1;
// Update contact's icon
- szProto = GetContactProto(hContact);
+ char *szProto = GetContactProto(hContact);
cli.pfnChangeContactIcon(cli.events.items[i]->cle.hContact,
- CallService(MS_CLIST_GETCONTACTICON, (WPARAM)cli.events.items[i]->cle.hContact, 1),
- 0);
+ CallService(MS_CLIST_GETCONTACTICON, (WPARAM)cli.events.items[i]->cle.hContact, 1), 0);
// Free any memory allocated to the event
cli.pfnFreeEvent(cli.events.items[i]);
List_Remove((SortedList*)&cli.events, i);
- {
- //count same protocoled events
- char * szEventProto;
- for (i=0; i < cli.events.count; i++)
- {
- if (cli.events.items[i]->cle.hContact)
- szEventProto = GetContactProto((cli.events.items[i]->cle.hContact));
- else if (cli.events.items[i]->cle.flags&CLEF_PROTOCOLGLOBAL)
- szEventProto = (char *) cli.events.items[i]->cle.lpszProtocol;
- else
- szEventProto = NULL;
- if (szEventProto && szProto && !lstrcmpA(szEventProto, szProto))
- nSameProto++;
-
- }
+ //count same protocoled events
+ int nSameProto = 0;
+ char *szEventProto;
+ for (int i = 0; i < cli.events.count; i++) {
+ if (cli.events.items[i]->cle.hContact)
+ szEventProto = GetContactProto((cli.events.items[i]->cle.hContact));
+ else if (cli.events.items[i]->cle.flags & CLEF_PROTOCOLGLOBAL)
+ szEventProto = (char *)cli.events.items[i]->cle.lpszProtocol;
+ else
+ szEventProto = NULL;
+ if (szEventProto && szProto && !lstrcmpA(szEventProto, szProto))
+ nSameProto++;
}
+
if (cli.events.count == 0 || nSameProto == 0) {
if (cli.events.count == 0)
KillTimer(NULL, flashTimerId);
@@ -277,7 +261,7 @@ int fnEventsProcessContactDoubleClick(MCONTACT hContact)
for (int i=0; i < cli.events.count; i++) {
if (cli.events.items[i]->cle.hContact == hContact) {
HANDLE hDbEvent = cli.events.items[i]->cle.hDbEvent;
- CallService(cli.events.items[i]->cle.pszService, (WPARAM) (HWND) NULL, (LPARAM) & cli.events.items[i]->cle);
+ CallService(cli.events.items[i]->cle.pszService, (WPARAM)(HWND)NULL, (LPARAM)& cli.events.items[i]->cle);
cli.pfnRemoveEvent(hContact, hDbEvent);
return 0;
}
@@ -294,17 +278,17 @@ int fnEventsProcessTrayDoubleClick(int index)
HANDLE hDbEvent;
int eventIndex = 0;
cli.pfnLockTray();
- if (cli.trayIconCount>1 && index>0) {
+ if (cli.trayIconCount > 1 && index > 0) {
int i;
- char * szProto = NULL;
- for (i=0; i<cli.trayIconCount; i++)
+ char *szProto = NULL;
+ for (i = 0; i < cli.trayIconCount; i++)
if (cli.trayIcon[i].id == index) {
szProto = cli.trayIcon[i].szProto;
if (i == 0) click_in_first_icon = TRUE;
break;
}
if (szProto) {
- for (i=0; i<cli.events.count; i++) {
+ for (i = 0; i < cli.events.count; i++) {
char * eventProto = NULL;
if (cli.events.items[i]->cle.hContact)
eventProto = GetContactProto(cli.events.items[i]->cle.hContact);
@@ -321,14 +305,14 @@ int fnEventsProcessTrayDoubleClick(int index)
//lets process backward try to find first event without desired proto in tray
int j;
if (click_in_first_icon)
- for (i=0; i<cli.events.count; i++) {
- char * eventProto = NULL;
+ for (i = 0; i < cli.events.count; i++) {
+ char *eventProto = NULL;
if (cli.events.items[i]->cle.hContact)
eventProto = GetContactProto(cli.events.items[i]->cle.hContact);
if (!eventProto)
eventProto = cli.events.items[i]->cle.lpszProtocol;
if (eventProto) {
- for (j = 0; j<cli.trayIconCount; j++)
+ for (j = 0; j < cli.trayIconCount; j++)
if (cli.trayIcon[j].szProto && !_strcmpi(eventProto, cli.trayIcon[j].szProto))
break;
@@ -350,7 +334,7 @@ int fnEventsProcessTrayDoubleClick(int index)
hContact = cli.events.items[eventIndex]->cle.hContact;
hDbEvent = cli.events.items[eventIndex]->cle.hDbEvent;
// ; may be better to show send msg?
- CallService(cli.events.items[eventIndex]->cle.pszService, (WPARAM) NULL, (LPARAM) & cli.events.items[eventIndex]->cle);
+ CallService(cli.events.items[eventIndex]->cle.pszService, (WPARAM)NULL, (LPARAM)& cli.events.items[eventIndex]->cle);
cli.pfnRemoveEvent(hContact, hDbEvent);
return 0;
}
@@ -417,12 +401,12 @@ int InitCListEvents(void)
return 0;
}
-struct CListEvent* fnCreateEvent(void)
+CListEvent* fnCreateEvent(void)
{
- return (struct CListEvent*)mir_calloc(sizeof(struct CListEvent));
+ return (CListEvent*)mir_calloc(sizeof(CListEvent));
}
-void fnFreeEvent(struct CListEvent* p)
+void fnFreeEvent(CListEvent* p)
{
mir_free(p->cle.pszService);
mir_free(p->cle.pszTooltip);
@@ -431,12 +415,11 @@ void fnFreeEvent(struct CListEvent* p)
void UninitCListEvents(void)
{
- int i;
-
- if (cli.events.count) KillTimer(NULL, flashTimerId);
+ if (cli.events.count)
+ KillTimer(NULL, flashTimerId);
- for (i=0; i < cli.events.count; i++)
- cli.pfnFreeEvent((struct CListEvent*)cli.events.items[i]);
+ for (int i=0; i < cli.events.count; i++)
+ cli.pfnFreeEvent((CListEvent*)cli.events.items[i]);
List_Destroy((SortedList*)&cli.events);
if (imlIcon != NULL)