From 8128db96b8cb2078a82f49fd6026b618560d6d8f Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Mon, 14 Jul 2008 10:54:04 +0000 Subject: reorganised settings overrides git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@418 4f64403b-2f21-0410-a795-97e2b3489a10 --- meta2/settings.cpp | 117 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 30 deletions(-) (limited to 'meta2/settings.cpp') diff --git a/meta2/settings.cpp b/meta2/settings.cpp index cd5cf4c..20427be 100644 --- a/meta2/settings.cpp +++ b/meta2/settings.cpp @@ -2,11 +2,10 @@ #include "settings.h" #include "core_functions.h" -PLUGINLINK *core_link = 0; -typedef int (*ServiceFunc)(const char *,WPARAM,LPARAM); -ServiceFunc coreCallService, coreCallServiceSync; +MIRANDASERVICE oldGetSetting, oldGetSettingStr, oldGetSettingStatic; -int ServiceFuncRedirect(const char *service,WPARAM wParam, LPARAM lParam, ServiceFunc coreServiceFunc) { +/* +int ServiceFuncRedirect(const char *service,WPARAM wParam, LPARAM lParam) { if(wParam ==0 || strncmp(service, "DB/Contact/", 11) != 0 || (strcmp(MS_DB_CONTACT_GETSETTING, service) != 0 @@ -18,7 +17,7 @@ int ServiceFuncRedirect(const char *service,WPARAM wParam, LPARAM lParam, Servic ) ) { - return coreServiceFunc(service, wParam, lParam); + return coreCallService(service, wParam, lParam); } HANDLE hContact = (HANDLE)wParam; @@ -26,9 +25,9 @@ int ServiceFuncRedirect(const char *service,WPARAM wParam, LPARAM lParam, Servic DBCONTACTENUMSETTINGS *ces = (DBCONTACTENUMSETTINGS *)lParam; if(IsMetacontact(hContact) && strcmp(ces->szModule, MODULE) != 0) { HANDLE hSub = Meta_GetActive(hContact); - return coreServiceFunc(service, (WPARAM)hSub, lParam); + return coreCallService(service, (WPARAM)hSub, lParam); } else - return coreServiceFunc(service, wParam, lParam); + return coreCallService(service, wParam, lParam); } const char *szSetting = 0, *szModule = 0; @@ -48,6 +47,7 @@ int ServiceFuncRedirect(const char *service,WPARAM wParam, LPARAM lParam, Servic if(szModule == 0 || szSetting == 0 || strcmp(szModule, "Protocol") == 0 || strcmp(szModule, "_Filter") == 0 + || strcmp(szModule, "CList") == 0 || (strcmp(szModule, MODULE) == 0 && (strcmp(szSetting, META_ID) == 0 || strcmp(szSetting, "IsSubcontact") == 0 @@ -62,58 +62,115 @@ int ServiceFuncRedirect(const char *service,WPARAM wParam, LPARAM lParam, Servic || strcmp(szSetting, "Status") == 0)) || !IsMetacontact(hContact)) { - return coreServiceFunc(service, wParam, lParam); + return coreCallService(service, wParam, lParam); } HANDLE hMeta = hContact; HANDLE hSub = Meta_GetActive(hMeta); char *subProto; if(hSub == 0 || (subProto = ContactProto(hSub)) == 0) // no most online - fail - return coreServiceFunc(service, wParam, lParam); + return coreCallService(service, wParam, lParam); int ret = 1; if(read) { - if((ret = coreServiceFunc(service, (WPARAM)hMeta, lParam)) != 0) { + DBCONTACTGETSETTING *cgs = (DBCONTACTGETSETTING *)lParam; + DBCONTACTGETSETTING cgs_save = *cgs; + if((ret = coreCallService(service, (WPARAM)hMeta, lParam)) != 0) { + *cgs = cgs_save; // if the setting does not exist in the metacontact, get it from the most online subcontact - if((ret = coreServiceFunc(service, (WPARAM)hSub, lParam)) != 0) { + if((ret = coreCallService(service, (WPARAM)hSub, lParam)) != 0) { // if it does not exist in the subcontact and we're using the meta proto module, try changing the module to the subcontact proto module if(strcmp(szModule, MODULE) == 0) { if(subProto) { - DBCONTACTGETSETTING *cgs = (DBCONTACTGETSETTING *)lParam; + *cgs = cgs_save; cgs->szModule = subProto; - ret = coreServiceFunc(service, (WPARAM)hSub, lParam); + ret = coreCallService(service, (WPARAM)hSub, lParam); } } } } } else { - // write to the sub - DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; - if(strcmp(szModule, MODULE) == 0) - cws->szModule = subProto; - ret = coreServiceFunc(service, (WPARAM)hSub, lParam); + // write to the sub? + + //DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam; + //if(strcmp(szModule, MODULE) == 0) + // cws->szModule = subProto; + //ret = coreCallService(service, (WPARAM)hSub, lParam); } return ret; } +*/ + +int MyOverride(WPARAM wParam, LPARAM lParam, MIRANDASERVICE oldService) { + HANDLE hMeta = (HANDLE)wParam; + DBCONTACTGETSETTING *cgs = (DBCONTACTGETSETTING *)lParam; + if(cgs->szModule == 0 || cgs->szSetting == 0 + || strcmp(cgs->szModule, "Protocol") == 0 + || strcmp(cgs->szModule, "_Filter") == 0 + || strcmp(cgs->szModule, "CList") == 0 + || (strcmp(cgs->szModule, MODULE) == 0 + && (strcmp(cgs->szSetting, META_ID) == 0 + || strcmp(cgs->szSetting, "IsSubcontact") == 0 + || strcmp(cgs->szSetting, "Default") == 0 + || strcmp(cgs->szSetting, "Handle") == 0 + || strcmp(cgs->szSetting, "WindowOpen") == 0 + || strcmp(cgs->szSetting, "ParentMetaID") == 0 + || strcmp(cgs->szSetting, "Default") == 0 + || strcmp(cgs->szSetting, "ForceDefault") == 0 + || strcmp(cgs->szSetting, "ForceSend") == 0 + || strcmp(cgs->szSetting, "TempDefault") == 0 + || strcmp(cgs->szSetting, "Status") == 0)) + || !IsMetacontact(hMeta)) + { + return oldService(wParam, lParam); + } + + HANDLE hSub = Meta_GetActive(hMeta); + char *subProto; + if(hSub == 0 || (subProto = ContactProto(hSub)) == 0) // no most online - fail + return oldService(wParam, lParam); + + int ret; + DBCONTACTGETSETTING cgs_save = *cgs; + if((ret = oldService((WPARAM)hMeta, lParam)) != 0) { + *cgs = cgs_save; + // if the setting does not exist in the metacontact, get it from the most online subcontact + if((ret = oldService((WPARAM)hSub, lParam)) != 0) { + // if it does not exist in the subcontact and we're using the meta proto module, try changing the module to the subcontact proto module + if(strcmp(cgs->szModule, MODULE) == 0) { + if(subProto) { + *cgs = cgs_save; + cgs->szModule = subProto; + ret = oldService((WPARAM)hSub, lParam); + } + } + } + } + + return ret; +} + +int MyGetSetting(WPARAM wParam, LPARAM lParam) { + return MyOverride(wParam, lParam, oldGetSetting); +} -int CallServiceRedirect(const char *service,WPARAM wParam, LPARAM lParam) { - return ServiceFuncRedirect(service, wParam, lParam, coreCallService); +int MyGetSettingStr(WPARAM wParam, LPARAM lParam) { + return MyOverride(wParam, lParam, oldGetSettingStr); } -int CallServiceSyncRedirect(const char *service,WPARAM wParam, LPARAM lParam) { - return ServiceFuncRedirect(service, wParam, lParam, coreCallServiceSync); +int MyGetSettingStatic(WPARAM wParam, LPARAM lParam) { + return MyOverride(wParam, lParam, oldGetSettingStatic); } -void InitSettings(PLUGINLINK *link) { - core_link = link; - coreCallService = core_link->CallService; - coreCallServiceSync = core_link->CallServiceSync; - core_link->CallService = CallServiceRedirect; - core_link->CallServiceSync = CallServiceSyncRedirect; +void InitSettings() { + oldGetSetting = (MIRANDASERVICE)CallService(MS_PLUGINS_HOOKSERVICE, (WPARAM)MS_DB_CONTACT_GETSETTING, (LPARAM)MyGetSetting); + oldGetSettingStr = (MIRANDASERVICE)CallService(MS_PLUGINS_HOOKSERVICE, (WPARAM)MS_DB_CONTACT_GETSETTING_STR, (LPARAM)MyGetSettingStr); + oldGetSettingStatic = (MIRANDASERVICE)CallService(MS_PLUGINS_HOOKSERVICE, (WPARAM)MS_DB_CONTACT_GETSETTINGSTATIC, (LPARAM)MyGetSettingStatic); } void DeinitSettings() { - core_link->CallService = coreCallService; - core_link->CallServiceSync = coreCallServiceSync; + CallService(MS_PLUGINS_HOOKSERVICE, (WPARAM)MS_DB_CONTACT_GETSETTING, (LPARAM)oldGetSetting); + CallService(MS_PLUGINS_HOOKSERVICE, (WPARAM)MS_DB_CONTACT_GETSETTING_STR, (LPARAM)oldGetSettingStr); + CallService(MS_PLUGINS_HOOKSERVICE, (WPARAM)MS_DB_CONTACT_GETSETTINGSTATIC, (LPARAM)oldGetSettingStatic); } \ No newline at end of file -- cgit v1.2.3