From 3791ce0c509d1d7a64cbba67015db38f4db5404c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 18 Feb 2014 18:37:18 +0000 Subject: - introducing ME_DB_EVENT_MARKED_READ - an event being called upon the call of db_event_markRead; - various m_database.h related code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@8165 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/delphi/m_database.inc | 7 ++++ include/m_database.h | 69 ++++++++++++++++++----------------- plugins/NewEventNotify/src/main.cpp | 2 +- plugins/NewEventNotify/src/popup.cpp | 19 ++++------ plugins/TabSRMM/src/msglog.cpp | 4 +- protocols/IcqOscarJ/src/icq_proto.cpp | 3 +- protocols/Twitter/src/proto.cpp | 2 +- src/core/stdmsg/src/msglog.cpp | 4 +- src/core/stduihist/history.cpp | 37 ++++++++----------- src/modules/database/dbutils.cpp | 64 ++++++++++++++++---------------- 10 files changed, 106 insertions(+), 105 deletions(-) diff --git a/include/delphi/m_database.inc b/include/delphi/m_database.inc index eefe7657d8..7a5cda29b5 100644 --- a/include/delphi/m_database.inc +++ b/include/delphi/m_database.inc @@ -360,6 +360,13 @@ const } ME_DB_EVENT_FILTER_ADD:PAnsiChar = 'DB/Event/FilterAdd'; + { + wParam : HCONTACT + lParam : HANDLE + Affect : Called when an event is marked read + } + ME_DB_EVENT_MARKED_READ:PAnsiChar = 'DB/Event/Marked/Read'; + { wParam : HCONTACT lParam : HANDLE diff --git a/include/m_database.h b/include/m_database.h index 01922171f8..7f9d4a921d 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -25,10 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef M_DATABASE_H__ #define M_DATABASE_H__ 1 -#ifndef M_CORE_H__ - #include -#endif - /******************* DATABASE MODULE ***************************/ /* Notes (as I think of them): @@ -69,8 +65,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /******************** GENERALLY USEFUL STUFF***********************/ -#include - #if !defined(M_SYSTEM_H__) #include "m_system.h" #endif @@ -142,23 +136,23 @@ Implemented in the dbchecker plugins, thus it might not exist /************************* Contact ********************************/ typedef struct { - const char *szModule; // pointer to name of the module that wrote the + const char *szModule; // pointer to name of the module that wrote the // setting to get - const char *szSetting; // pointer to name of the setting to get - DBVARIANT *pValue; // pointer to variant to receive the value + const char *szSetting; // pointer to name of the setting to get + DBVARIANT *pValue; // pointer to variant to receive the value } DBCONTACTGETSETTING; typedef struct { - const char *szModule; // pointer to name of the module that wrote the + const char *szModule; // pointer to name of the module that wrote the // setting to get - const char *szSetting; // pointer to name of the setting to get - DBVARIANT value; // variant containing the value to set + const char *szSetting; // pointer to name of the setting to get + DBVARIANT value; // variant containing the value to set } DBCONTACTWRITESETTING; /* db/contact/enumsettings v0.1.0.1+ Lists all the settings a specific modules has stored in the database for a specific contact. -wParam = (WPARAM)(HANDLE)hContact +wParam = (WPARAM)(MCONTACT)hContact lParam = (LPARAM)(DBCONTACTENUMSETTINGS*)&dbces Returns the return value of the last call to pfnEnumProc, or -1 if there are no settings for that module/contact pair @@ -171,10 +165,10 @@ you want to keep it for longer you must allocation your own storage. typedef int (*DBSETTINGENUMPROC)(const char *szSetting, LPARAM lParam); typedef struct { DBSETTINGENUMPROC pfnEnumProc; - LPARAM lParam; //passed direct to pfnEnumProc - const char *szModule; //name of the module to get settings for - DWORD ofsSettings; //filled by the function to contain the offset from - //the start of the database of the requested settings group. + LPARAM lParam; // passed direct to pfnEnumProc + const char *szModule; // name of the module to get settings for + DWORD ofsSettings; // filled by the function to contain the offset from + // the start of the database of the requested settings group. } DBCONTACTENUMSETTINGS; #define MS_DB_CONTACT_ENUMSETTINGS "DB/Contact/EnumSettings" @@ -189,7 +183,7 @@ and contact/findnext /* DB/Contact/Delete Deletes the contact hContact from the database and all events and settings associated with it. - wParam = (WPARAM)(HANDLE)hContact + wParam = (WPARAM)(MCONTACT)hContact lParam = 0 Returns 0 on success or nonzero if hContact was invalid Please don't try to delete the user contact (hContact = NULL) @@ -234,20 +228,17 @@ Always returns 0. typedef struct { - int cbSize; // structure size in bytes - char* module; // event module name - int eventType; // event id, unique for this module - char* descr; // event type description (i.e. "File Transfer") - char* textService; // service name for MS_DB_EVENT_GETTEXT (0.8+, default Module+'/GetEventText'+EvtID) - char* iconService; // service name for MS_DB_EVENT_GETICON (0.8+, default Module+'/GetEventIcon'+EvtID) + int cbSize; // structure size in bytes + LPSTR module; // event module name + int eventType; // event id, unique for this module + LPSTR descr; // event type description (i.e. "File Transfer") + LPSTR textService; // service name for MS_DB_EVENT_GETTEXT (0.8+, default Module+'/GetEventText'+EvtID) + LPSTR iconService; // service name for MS_DB_EVENT_GETICON (0.8+, default Module+'/GetEventIcon'+EvtID) HANDLE eventIcon; // icolib handle to eventicon (0.8+, default 'eventicon_'+Module+EvtID) - DWORD flags; // flags, combination of the DETF_* + DWORD flags; // flags, combination of the DETF_* } DBEVENTTYPEDESCR; -#define DBEVENTTYPEDESCR_SIZE sizeof(DBEVENTTYPEDESCR) -#define DBEVENTTYPEDESCR_SIZE_V1 (offsetof(DBEVENTTYPEDESCR, textService)) - // constants for default event behaviour #define DETF_HISTORY 1 // show event in history #define DETF_MSGWINDOW 2 // show event in message window @@ -447,7 +438,7 @@ lParam = (LPARAM)(char*)szModuleName - the module name to be deleted /* DB/Event/Added event Called when a new event has been added to the event chain for a contact - wParam = (WPARAM)(HANDLE)hContact + wParam = (WPARAM)(MCONTACT)hContact lParam = (LPARAM)(HANDLE)hDbEvent hDbEvent is a valid handle to the event. hContact is a valid handle to the contact to which hDbEvent refers. @@ -465,7 +456,7 @@ passed to db_event_add. The point of this hook is to stop any unwanted database events, to stop an event being added, return 1, to allow the event to pass through return 0. - wParam = (WPARAM)(HANDLE)hContact + wParam = (WPARAM)(MCONTACT)hContact lParam = (LPARAM)&DBEVENTINFO Any changed made to the said DBEVENTINFO are also passed along to the database, @@ -473,9 +464,19 @@ therefore it is possible to shape the data, however DO NOT DO THIS. */ #define ME_DB_EVENT_FILTER_ADD "DB/Event/FilterAdd" +/* DB/Event/Marked/Read event +Called when an event is marked read +wParam = (WPARAM)(MCONTACT)hContact +lParam = (LPARAM)(HANDLE)hDbEvent +hDbEvent is a valid handle to the event. +hContact is a valid handle to the contact to which hDbEvent refers, and will +remain valid. +*/ +#define ME_DB_EVENT_MARKED_READ "DB/Event/Marked/Read" + /* DB/Event/Deleted event Called when an event is about to be deleted from the event chain for a contact - wParam = (WPARAM)(HANDLE)hContact + wParam = (WPARAM)(MCONTACT)hContact lParam = (LPARAM)(HANDLE)hDbEvent hDbEvent is a valid handle to the event which is about to be deleted, but it won't be once your hook has returned. @@ -488,7 +489,7 @@ usual, stop other hooks from being called. /* DB/Contact/Added event Called when a new contact has been added to the database - wParam = (WPARAM)(HANDLE)hContact + wParam = (WPARAM)(MCONTACT)hContact lParam = 0 hContact is a valid handle to the new contact. Contacts are initially created without any settings, so if you hook this event @@ -498,7 +499,7 @@ you will almost certainly also want to hook db/contact/settingchanged as well. /* DB/Contact/Deleted event Called when an contact is about to be deleted - wParam = (WPARAM)(HANDLE)hContact + wParam = (WPARAM)(MCONTACT)hContact lParam = 0 hContact is a valid handle to the contact which is about to be deleted, but it won't be once your hook has returned. @@ -510,7 +511,7 @@ Deleting a contact invalidates all events in its chain. /* DB/Contact/SettingChanged event Called when a contact has had one of its settings changed - wParam = (WPARAM)(HANDLE)hContact + wParam = (WPARAM)(MCONTACT)hContact lParam = (LPARAM)(DBCONTACTWRITESETTING*)&dbcws hContact is a valid handle to the contact that has changed. This event will be triggered many times rapidly when a whole bunch of values diff --git a/plugins/NewEventNotify/src/main.cpp b/plugins/NewEventNotify/src/main.cpp index a100978f0a..7a946b16cf 100644 --- a/plugins/NewEventNotify/src/main.cpp +++ b/plugins/NewEventNotify/src/main.cpp @@ -78,7 +78,7 @@ int HookedNewEvent(WPARAM hContact, LPARAM lParam) if (ServiceExists(MS_DB_EVENT_GETTYPE)) { DBEVENTTYPEDESCR *pei = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbe.szModule, (LPARAM)dbe.eventType); // ignore events according to flags - if (pei && pei->cbSize >= DBEVENTTYPEDESCR_SIZE && pei->flags & DETF_NONOTIFY) + if (pei && pei->flags & DETF_NONOTIFY) return 0; } diff --git a/plugins/NewEventNotify/src/popup.cpp b/plugins/NewEventNotify/src/popup.cpp index 3f1ce3646a..d1d196dc9e 100644 --- a/plugins/NewEventNotify/src/popup.cpp +++ b/plugins/NewEventNotify/src/popup.cpp @@ -336,18 +336,15 @@ static TCHAR* GetEventPreview(DBEVENTINFO *dbei) default: if (ServiceExists(MS_DB_EVENT_GETTYPE)) { - DBEVENTTYPEDESCR* pei = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); + DBEVENTTYPEDESCR *pei = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); // support for custom database event types - if (pei && pei->cbSize >= DBEVENTTYPEDESCR_SIZE_V1) { - // preview requested - if (dbei->pBlob) { - DBEVENTGETTEXT svc = {dbei, DBVT_TCHAR, CP_ACP}; - TCHAR *pet = (TCHAR*)CallService(MS_DB_EVENT_GETTEXT, 0, (LPARAM)&svc); - if (pet) { - // we've got event text, move to our memory space - comment1 = mir_tstrdup(pet); - mir_free(pet); - } + if (pei && dbei->pBlob) { + DBEVENTGETTEXT svc = {dbei, DBVT_TCHAR, CP_ACP}; + TCHAR *pet = (TCHAR*)CallService(MS_DB_EVENT_GETTEXT, 0, (LPARAM)&svc); + if (pet) { + // we've got event text, move to our memory space + comment1 = mir_tstrdup(pet); + mir_free(pet); } commentFix = pei->descr; } diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index 13642b5f72..29605d0d7c 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -552,8 +552,8 @@ int TSAPI DbEventIsShown(TWindowData *dat, DBEVENTINFO *dbei) int DbEventIsForMsgWindow(DBEVENTINFO *dbei) { - DBEVENTTYPEDESCR* et = ( DBEVENTTYPEDESCR* )CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); - return et && ( et->flags & DETF_MSGWINDOW ); + DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); + return et && (et->flags & DETF_MSGWINDOW); } static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, HANDLE hDbEvent, int prefixParaBreak, LogStreamData *streamData) diff --git a/protocols/IcqOscarJ/src/icq_proto.cpp b/protocols/IcqOscarJ/src/icq_proto.cpp index a42f46a33e..25e216f21d 100644 --- a/protocols/IcqOscarJ/src/icq_proto.cpp +++ b/protocols/IcqOscarJ/src/icq_proto.cpp @@ -197,8 +197,7 @@ CIcqProto::CIcqProto(const char* aProtoName, const TCHAR* aUserName) : m_hDirectNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); // Register custom database events - DBEVENTTYPEDESCR eventType = { 0 }; - eventType.cbSize = DBEVENTTYPEDESCR_SIZE; + DBEVENTTYPEDESCR eventType = { sizeof(eventType) }; eventType.eventType = ICQEVENTTYPE_MISSEDMESSAGE; eventType.module = m_szModuleName; eventType.descr = "Missed message notifications"; diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp index 8f02b0ba1f..b2e1bf021f 100644 --- a/protocols/Twitter/src/proto.cpp +++ b/protocols/Twitter/src/proto.cpp @@ -374,7 +374,7 @@ int TwitterProto::OnModulesLoaded(WPARAM,LPARAM) gcr.iMaxText = 159; CallService(MS_GC_REGISTER,0,reinterpret_cast(&gcr)); - DBEVENTTYPEDESCR evt = {sizeof(evt)}; + DBEVENTTYPEDESCR evt = { sizeof(evt) }; evt.eventType = TWITTER_DB_EVENT_TYPE_TWEET; evt.module = m_szModuleName; evt.descr = "Tweet"; diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 1aedcf4640..be5e960c5f 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -245,8 +245,8 @@ static char *SetToStyle(int style) int DbEventIsForMsgWindow(DBEVENTINFO *dbei) { - DBEVENTTYPEDESCR* et = ( DBEVENTTYPEDESCR* )CallService(MS_DB_EVENT_GETTYPE, ( WPARAM )dbei->szModule, ( LPARAM )dbei->eventType ); - return et && ( et->flags & DETF_MSGWINDOW ); + DBEVENTTYPEDESCR *et = ( DBEVENTTYPEDESCR* )CallService(MS_DB_EVENT_GETTYPE, ( WPARAM )dbei->szModule, ( LPARAM )dbei->eventType ); + return et && (et->flags & DETF_MSGWINDOW); } int DbEventIsShown(DBEVENTINFO * dbei, SrmmWindowData *dat) diff --git a/src/core/stduihist/history.cpp b/src/core/stduihist/history.cpp index 13c08b692a..af51a6e95d 100644 --- a/src/core/stduihist/history.cpp +++ b/src/core/stduihist/history.cpp @@ -86,14 +86,12 @@ static void GetObjectDescription(DBEVENTINFO *dbei, TCHAR* str, int cbStr) break; default: - { - DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); - if (et && (et->flags & DETF_HISTORY)) { - GetMessageDescription(dbei, str, cbStr); - } - else - str[ 0 ] = 0; -} } } + DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); + if (et && (et->flags & DETF_HISTORY)) + GetMessageDescription(dbei, str, cbStr); + else + *str = 0; +} } static void GetObjectSummary(DBEVENTINFO *dbei, TCHAR* str, int cbStr) { @@ -116,21 +114,18 @@ static void GetObjectSummary(DBEVENTINFO *dbei, TCHAR* str, int cbStr) break; default: - { - DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); - if (et && (et->flags & DETF_HISTORY)) { - pszTmp = mir_a2t(et->descr); - pszSrc = TranslateTS(pszTmp); - break; - } - else { - str[ 0 ] = 0; - return; - } } } + DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); + if (et && (et->flags & DETF_HISTORY)) { + pszTmp = mir_a2t(et->descr); + pszSrc = TranslateTS(pszTmp); + break; + } + *str = 0; + return; + } _tcsncpy(str, (const TCHAR*)pszSrc, cbStr); - str[ cbStr-1 ] = 0; - + str[cbStr-1] = 0; mir_free(pszTmp); } diff --git a/src/modules/database/dbutils.cpp b/src/modules/database/dbutils.cpp index 6f9bb2a9c8..d560fd7be8 100644 --- a/src/modules/database/dbutils.cpp +++ b/src/modules/database/dbutils.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\..\core\commonheaders.h" #include "profilemanager.h" -static int CompareEventTypes(const DBEVENTTYPEDESCR* p1, const DBEVENTTYPEDESCR* p2) +static int CompareEventTypes(const DBEVENTTYPEDESCR *p1, const DBEVENTTYPEDESCR *p2) { int result = strcmp(p1->module, p2->module); if (result) @@ -40,44 +40,46 @@ static BOOL bModuleInitialized = FALSE; static INT_PTR DbEventTypeRegister(WPARAM, LPARAM lParam) { - DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)lParam; - if (eventTypes.getIndex(et) == -1) { - DBEVENTTYPEDESCR* p = (DBEVENTTYPEDESCR*)mir_calloc(sizeof(DBEVENTTYPEDESCR)); - p->cbSize = DBEVENTTYPEDESCR_SIZE; - p->module = mir_strdup(et->module); - p->eventType = et->eventType; - p->descr = mir_strdup(et->descr); - if (et->cbSize == DBEVENTTYPEDESCR_SIZE) { - if (et->textService) - p->textService = mir_strdup(et->textService); - if (et->iconService) - p->iconService = mir_strdup(et->iconService); - p->eventIcon = et->eventIcon; - p->flags = et->flags; - } - if (!p->textService) { - char szServiceName[100]; - mir_snprintf(szServiceName, sizeof(szServiceName), "%s/GetEventText%d", p->module, p->eventType); - p->textService = mir_strdup(szServiceName); - } - if (!p->iconService) { - char szServiceName[100]; - mir_snprintf(szServiceName, sizeof(szServiceName), "%s/GetEventIcon%d", p->module, p->eventType); - p->iconService = mir_strdup(szServiceName); - } - eventTypes.insert(p); - } + DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)lParam; + if (et == NULL || et->cbSize != sizeof(DBEVENTTYPEDESCR)) + return 0; + + if (eventTypes.getIndex(et) != -1) + return 0; + DBEVENTTYPEDESCR *p = (DBEVENTTYPEDESCR*)mir_calloc(sizeof(DBEVENTTYPEDESCR)); + p->cbSize = sizeof(DBEVENTTYPEDESCR); + p->module = mir_strdup(et->module); + p->eventType = et->eventType; + p->descr = mir_strdup(et->descr); + if (et->textService) + p->textService = mir_strdup(et->textService); + if (et->iconService) + p->iconService = mir_strdup(et->iconService); + p->eventIcon = et->eventIcon; + p->flags = et->flags; + + if (!p->textService) { + char szServiceName[100]; + mir_snprintf(szServiceName, sizeof(szServiceName), "%s/GetEventText%d", p->module, p->eventType); + p->textService = mir_strdup(szServiceName); + } + if (!p->iconService) { + char szServiceName[100]; + mir_snprintf(szServiceName, sizeof(szServiceName), "%s/GetEventIcon%d", p->module, p->eventType); + p->iconService = mir_strdup(szServiceName); + } + eventTypes.insert(p); return 0; } static INT_PTR DbEventTypeGet(WPARAM wParam, LPARAM lParam) { DBEVENTTYPEDESCR tmp; - int idx; - tmp.module = (char*)wParam; tmp.eventType = lParam; + + int idx; if (!List_GetIndex((SortedList*)&eventTypes, &tmp, &idx)) return 0; @@ -358,7 +360,7 @@ void UnloadEventsModule() return; for (int i=0; i < eventTypes.getCount(); i++) { - DBEVENTTYPEDESCR* p = eventTypes[i]; + DBEVENTTYPEDESCR *p = eventTypes[i]; mir_free(p->module); mir_free(p->descr); mir_free(p->textService); -- cgit v1.2.3