From d052a59d5fbbdd17035ed92fee43932381a1e5c9 Mon Sep 17 00:00:00 2001 From: pescuma Date: Sat, 26 Apr 2008 23:11:12 +0000 Subject: Handle metacontact change in the middle of chat Works with miranda 0.7 Version bump: 0.0.2.4 git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@89 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/emoticons/Docs/emoticons_changelog.txt | 8 + Plugins/emoticons/Docs/emoticons_version.txt | 2 +- Plugins/emoticons/EmoticonsSelectionLayout.cpp | 13 ++ Plugins/emoticons/GroupListEmoticons.cpp | 32 ++-- Plugins/emoticons/commons.h | 14 +- Plugins/emoticons/data/Plugins/Emoticons/AIM.emo | 2 +- .../emoticons/data/Plugins/Emoticons/Default.emo | 2 +- Plugins/emoticons/data/Plugins/Emoticons/ICQ.emo | 2 +- Plugins/emoticons/data/Plugins/Emoticons/MSN.emo | 2 +- .../emoticons/data/Plugins/Emoticons/MySpace.emo | 2 +- .../emoticons/data/Plugins/Emoticons/SAMETIME.emo | 2 +- Plugins/emoticons/data/Plugins/Emoticons/Skype.emo | 2 +- Plugins/emoticons/data/Plugins/Emoticons/YAHOO.emo | 2 +- Plugins/emoticons/emoticons.cpp | 162 ++++++++++++++++----- Plugins/emoticons/selwin.cpp | 21 +-- 15 files changed, 189 insertions(+), 79 deletions(-) (limited to 'Plugins') diff --git a/Plugins/emoticons/Docs/emoticons_changelog.txt b/Plugins/emoticons/Docs/emoticons_changelog.txt index ad38926..22bff39 100644 --- a/Plugins/emoticons/Docs/emoticons_changelog.txt +++ b/Plugins/emoticons/Docs/emoticons_changelog.txt @@ -2,6 +2,14 @@ Emoticons Changelog: +. 0.0.2.4 + * Handle metacontact change in the middle of chat + * Works with miranda 0.7 + +. 0.0.2.3 + + Send nudges throught nudge plugin (if possible) + * Better guess of number of columns in selection window + . 0.0.2.2 + Support for accounts and jabber transports * Fix for frame in selection window diff --git a/Plugins/emoticons/Docs/emoticons_version.txt b/Plugins/emoticons/Docs/emoticons_version.txt index 3ed91f8..d9e9c78 100644 --- a/Plugins/emoticons/Docs/emoticons_version.txt +++ b/Plugins/emoticons/Docs/emoticons_version.txt @@ -1 +1 @@ -Emoticons 0.0.2.2 \ No newline at end of file +Emoticons 0.0.2.4 \ No newline at end of file diff --git a/Plugins/emoticons/EmoticonsSelectionLayout.cpp b/Plugins/emoticons/EmoticonsSelectionLayout.cpp index ba99e16..5c58244 100644 --- a/Plugins/emoticons/EmoticonsSelectionLayout.cpp +++ b/Plugins/emoticons/EmoticonsSelectionLayout.cpp @@ -131,6 +131,19 @@ int EmoticonsSelectionLayout::GetNumOfCols(int num_emotes) int cols = num_emotes / MAX_LINES; if (num_emotes % MAX_LINES != 0) cols++; + + if (cols < MAX_COLS) + { + cols = max(cols, MIN_COLS); + for(int i = 2; i > -3; i--) + { + if (num_emotes % (cols+i) == 0) + { + cols += i; + return cols; + } + } + } return min(max(MIN_COLS, min(cols, MAX_COLS)), num_emotes); } diff --git a/Plugins/emoticons/GroupListEmoticons.cpp b/Plugins/emoticons/GroupListEmoticons.cpp index 1d45c2b..8447fb6 100644 --- a/Plugins/emoticons/GroupListEmoticons.cpp +++ b/Plugins/emoticons/GroupListEmoticons.cpp @@ -92,8 +92,7 @@ void GroupListEmoticons::Load() for(i = 0; i < ssd->module->emoticons.getCount(); i++) { Emoticon *e = ssd->module->emoticons[i]; - - if (e->service[0] != NULL && !ProtoServiceExists(ssd->proto, e->service[0])) + if (e->IgnoreFor(ssd->module)) continue; if (stricmp(e->group, current_group) != 0 || i == 0) @@ -139,15 +138,23 @@ void GroupListEmoticons::Load() Group &group = groups[i]; group.top = window.height; - // Recalc the num of cols int w = window.width - BORDER; - group.cols = w / (group.max_width + BORDER); + + // Recalc the num of cols + group.lines = GetNumOfLines(group.count, group.cols); + + int new_cols = w / (group.max_width + BORDER); + int new_lines = GetNumOfLines(group.count, new_cols); + if (new_lines < group.lines) + { + group.cols = new_cols; + group.lines = new_lines; + } + // If there is space left, put it into the emoticons group.max_width += (w - group.cols * (group.max_width + BORDER)) / group.cols; - group.lines = GetNumOfLines(group.count, group.cols); - if (group.name[0] != '\0') { RECT rc = CalcRect(group.name, groupFont); @@ -166,8 +173,7 @@ int GroupListEmoticons::CountGroups() for(int i = 1; i < ssd->module->emoticons.getCount(); i++) { Emoticon *e = ssd->module->emoticons[i]; - - if (e->service[0] != NULL && !ProtoServiceExists(ssd->proto, e->service[0])) + if (e->IgnoreFor(ssd->module)) continue; if (stricmp(e->group, current_group) != 0) @@ -196,8 +202,7 @@ void GroupListEmoticons::GetMaxEmoticonSize(Group &group) for(int i = group.start; i <= group.end; i++) { Emoticon *e = ssd->module->emoticons[i]; - - if (e->service[0] != NULL && !ProtoServiceExists(ssd->proto, e->service[0])) + if (e->IgnoreFor(ssd->module)) continue; int height, width; @@ -242,8 +247,7 @@ void GroupListEmoticons::CreateToolTips() for (int j = group.start; j <= group.end; j++) { Emoticon *e = ssd->module->emoticons[j]; - - if (e->service[0] != NULL && !ProtoServiceExists(ssd->proto, e->service[0])) + if (e->IgnoreFor(ssd->module)) continue; RECT rc = GetEmoticonRect(group, index); @@ -269,7 +273,7 @@ int GroupListEmoticons::GetIndex(Group &group, int line, int col) for (int j = group.start; j <= group.end; j++) { Emoticon *e = ssd->module->emoticons[j]; - if (e->service[0] != NULL && !ProtoServiceExists(ssd->proto, e->service[0])) + if (e->IgnoreFor(ssd->module)) continue; if (index == desired) @@ -497,7 +501,7 @@ void GroupListEmoticons::Draw(HDC hdc) for (int j = group.start; j <= group.end; j++) { Emoticon *e = ssd->module->emoticons[j]; - if (e->service[0] != NULL && !ProtoServiceExists(ssd->proto, e->service[0])) + if (e->IgnoreFor(ssd->module)) continue; RECT rc = GetEmoticonRect(group, index); diff --git a/Plugins/emoticons/commons.h b/Plugins/emoticons/commons.h index 32523bd..c148edb 100644 --- a/Plugins/emoticons/commons.h +++ b/Plugins/emoticons/commons.h @@ -44,7 +44,7 @@ using namespace std; // Miranda headers -#define MIRANDA_VER 0x0800 +#define MIRANDA_VER 0x0700 #include #include #include @@ -100,6 +100,7 @@ extern HANDLE hChangedEvent; struct EmoticonPack; +struct Module; struct EmoticonImage { @@ -132,7 +133,7 @@ struct Emoticon char *group; LIST texts; EmoticonImage *img; - char *service[3]; + char *service[6]; // For selection window HWND tt; @@ -141,8 +142,14 @@ struct Emoticon service[0] = NULL; service[1] = NULL; service[2] = NULL; + service[3] = NULL; + service[4] = NULL; + service[5] = NULL; } ~Emoticon(); + + BOOL IgnoreFor(Module *m); + }; @@ -209,6 +216,7 @@ struct Contact struct Dialog { + HANDLE hOriginalContact; Contact *contact; Module *module; @@ -234,6 +242,8 @@ HANDLE GetRealContact(HANDLE hContact); Module * GetContactModule(HANDLE hContact, const char *proto = NULL); void FillModuleImages(EmoticonPack *pack); +int CallEmoticonService(char *proto, HANDLE hContact, char *service, char *wparam, char *lparam); +BOOL EmoticonServiceExists(char *proto, char *service); diff --git a/Plugins/emoticons/data/Plugins/Emoticons/AIM.emo b/Plugins/emoticons/data/Plugins/Emoticons/AIM.emo index b871eac..f105410 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/AIM.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/AIM.emo @@ -24,4 +24,4 @@ [Nudge] -"service_nudge" = "Nudge", "" +"service_nudge" = "Nudge", "" diff --git a/Plugins/emoticons/data/Plugins/Emoticons/Default.emo b/Plugins/emoticons/data/Plugins/Emoticons/Default.emo index a672adc..44867f7 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/Default.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/Default.emo @@ -20,4 +20,4 @@ [Nudge] -"service_nudge" = "Nudge", "" +"service_nudge" = "Nudge", "" diff --git a/Plugins/emoticons/data/Plugins/Emoticons/ICQ.emo b/Plugins/emoticons/data/Plugins/Emoticons/ICQ.emo index 068a139..d95fa22 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/ICQ.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/ICQ.emo @@ -34,7 +34,7 @@ [Nudge] -"service_nudge" = "Nudge", "" +"service_nudge" = "Nudge", "" [tZer] diff --git a/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo b/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo index b3750d1..530377b 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo @@ -91,4 +91,4 @@ [Nudge] -"service_nudge" = "Send a nudge to everyone in this conversation", "" +"service_nudge" = "Send a nudge to everyone in this conversation", "" diff --git a/Plugins/emoticons/data/Plugins/Emoticons/MySpace.emo b/Plugins/emoticons/data/Plugins/Emoticons/MySpace.emo index 0bc93ee..4a602db 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/MySpace.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/MySpace.emo @@ -30,4 +30,4 @@ [Nudge] -"service_nudge" = "Nudge", "" +"service_nudge" = "Nudge", "" diff --git a/Plugins/emoticons/data/Plugins/Emoticons/SAMETIME.emo b/Plugins/emoticons/data/Plugins/Emoticons/SAMETIME.emo index a86fbc3..c248a41 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/SAMETIME.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/SAMETIME.emo @@ -25,4 +25,4 @@ [Nudge] -"service_nudge" = "Nudge", "" +"service_nudge" = "Nudge", "" diff --git a/Plugins/emoticons/data/Plugins/Emoticons/Skype.emo b/Plugins/emoticons/data/Plugins/Emoticons/Skype.emo index 9e8361b..541fbfc 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/Skype.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/Skype.emo @@ -335,4 +335,4 @@ [Nudge] -"service_nudge" = "Nudge", "" +"service_nudge" = "Nudge", "" diff --git a/Plugins/emoticons/data/Plugins/Emoticons/YAHOO.emo b/Plugins/emoticons/data/Plugins/Emoticons/YAHOO.emo index db4e62f..3e6bc85 100644 --- a/Plugins/emoticons/data/Plugins/Emoticons/YAHOO.emo +++ b/Plugins/emoticons/data/Plugins/Emoticons/YAHOO.emo @@ -96,4 +96,4 @@ [Nudge] -"service_nudge" = "Nudge", "" +"service_nudge" = "Nudge", "" diff --git a/Plugins/emoticons/emoticons.cpp b/Plugins/emoticons/emoticons.cpp index 5ec6769..629c2f0 100644 --- a/Plugins/emoticons/emoticons.cpp +++ b/Plugins/emoticons/emoticons.cpp @@ -30,7 +30,7 @@ PLUGININFOEX pluginInfo={ #else "Emoticons", #endif - PLUGIN_MAKE_VERSION(0,0,2,2), + PLUGIN_MAKE_VERSION(0,0,2,4), "Emoticons", "Ricardo Pescuma Domenecci", "", @@ -49,7 +49,7 @@ PLUGININFOEX pluginInfo={ HINSTANCE hInst; PLUGINLINK *pluginLink; -HANDLE hHooks[3] = {0}; +HANDLE hHooks[4] = {0}; HANDLE hServices[4] = {0}; HANDLE hChangedEvent; HANDLE hNetlibUser = 0; @@ -101,6 +101,7 @@ void ReleaseModuleImage(EmoticonImage *img); int ModulesLoaded(WPARAM wParam, LPARAM lParam); int PreShutdown(WPARAM wParam, LPARAM lParam); int MsgWindowEvent(WPARAM wParam, LPARAM lParam); +int DefaultMetaChanged(WPARAM wParam, LPARAM lParam); int ReplaceEmoticonsService(WPARAM wParam, LPARAM lParam); int GetInfo2Service(WPARAM wParam, LPARAM lParam); @@ -108,6 +109,7 @@ int ShowSelectionService(WPARAM wParam, LPARAM lParam); int LoadContactSmileysService(WPARAM wParam, LPARAM lParam); TCHAR *GetText(RichEditCtrl &rec, int start, int end); +const char * GetProtoID(const char *proto); LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); @@ -321,7 +323,10 @@ void InitFonts() int ModulesLoaded(WPARAM wParam, LPARAM lParam) { if (ServiceExists(MS_MC_GETPROTOCOLNAME)) + { metacontacts_proto = (char *) CallService(MS_MC_GETPROTOCOLNAME, 0, 0); + hHooks[3] = HookEvent(ME_MC_DEFAULTTCHANGED, &DefaultMetaChanged); + } has_anismiley = ServiceExists(MS_INSERTANISMILEY); @@ -1201,28 +1206,29 @@ HANDLE GetRealContact(HANDLE hContact) int MsgWindowEvent(WPARAM wParam, LPARAM lParam) { - MessageWindowEventData *event = (MessageWindowEventData *)lParam; - if (event == NULL) + MessageWindowEventData *evt = (MessageWindowEventData *)lParam; + if (evt == NULL) return 0; - if (event->cbSize < sizeof(MessageWindowEventData)) + if (evt->cbSize < sizeof(MessageWindowEventData)) return 0; - if (event->uType == MSG_WINDOW_EVT_OPEN) + if (evt->uType == MSG_WINDOW_EVT_OPEN) { - Module *m = GetContactModule(event->hContact); + Module *m = GetContactModule(evt->hContact); if (m == NULL) return 0; Dialog *dlg = (Dialog *) malloc(sizeof(Dialog)); ZeroMemory(dlg, sizeof(Dialog)); - dlg->contact = GetContact(event->hContact); + dlg->hOriginalContact = evt->hContact; + dlg->contact = GetContact(evt->hContact); dlg->module = m; - dlg->hwnd_owner = event->hwndWindow; + dlg->hwnd_owner = evt->hwndWindow; - LoadRichEdit(&dlg->input, event->hwndInput); - LoadRichEdit(&dlg->log, event->hwndLog); + LoadRichEdit(&dlg->input, evt->hwndInput); + LoadRichEdit(&dlg->log, evt->hwndLog); if (opts.replace_in_input) { @@ -1236,9 +1242,9 @@ int MsgWindowEvent(WPARAM wParam, LPARAM lParam) // dlg->log.old_edit_proc = (WNDPROC) SetWindowLong(dlg->log.hwnd, GWL_WNDPROC, (LONG) LogProc); dialogData[dlg->log.hwnd] = dlg; } - else if (event->uType == MSG_WINDOW_EVT_CLOSING) + else if (evt->uType == MSG_WINDOW_EVT_CLOSING) { - DialogMapType::iterator dlgit = dialogData.find(event->hwndWindow); + DialogMapType::iterator dlgit = dialogData.find(evt->hwndWindow); if (dlgit != dialogData.end()) { Dialog *dlg = dlgit->second; @@ -1253,9 +1259,9 @@ int MsgWindowEvent(WPARAM wParam, LPARAM lParam) free(dlg); } - dialogData.erase(event->hwndInput); - dialogData.erase(event->hwndLog); - dialogData.erase(event->hwndWindow); + dialogData.erase(evt->hwndInput); + dialogData.erase(evt->hwndLog); + dialogData.erase(evt->hwndWindow); } return 0; @@ -1303,7 +1309,7 @@ char *strtrim(char *str) return str; } - +/* BOOL HasProto(char *proto) { PROTOCOLDESCRIPTOR **protos; @@ -1326,7 +1332,7 @@ BOOL HasProto(char *proto) return FALSE; } - +*/ void LoadModules() { @@ -1429,7 +1435,7 @@ void HandleEmoLine(Module *m, char *tmp, char *group) int len = strlen(atxt); // Is a service - if (!strncmp(atxt, "service[i] = mir_strdup(params); if (pos == NULL) + { + params = NULL; break; + } params = pos + 1; } -// if (e->service[0] == NULL || e->service[0][0] == '\0' || !ProtoServiceExists(m->name, e->service[0])) -// { -// delete e; -// e = NULL; -// return; -// } + if (params != NULL && strncmp(params, "Wrapper:", 8) == 0) + { + params += 8; + for(int i = 3; i < 6; i++) + { + char *pos = strchr(params, ':'); + if (pos != NULL) + *pos = '\0'; + + e->service[i] = mir_strdup(params); + + if (pos == NULL) + break; + + params = pos + 1; + } + } } else e->texts.insert(txt); @@ -2031,32 +2051,41 @@ Module *GetModuleByName(const char *name) } +const char * GetProtoID(const char *proto) +{ + if (!ServiceExists(MS_PROTO_GETACCOUNT)) + return proto; + + PROTOACCOUNT *acc = ProtoGetAccount(proto); + if (acc == NULL) + return proto; + + return acc->szProtoName; +} + + Module * GetContactModule(HANDLE hContact, const char *proto) { if (hContact == NULL) { if (proto == NULL) return NULL; - return GetModule(proto); + return GetModule(GetProtoID(proto)); } hContact = GetRealContact(hContact); - proto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); + proto = (const char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (proto == NULL) return NULL; - PROTOACCOUNT *acc = ProtoGetAccount(proto); - if (acc == NULL) - return NULL; - - proto = acc->szProtoName; + const char *protoID = GetProtoID(proto); // Check for transports - if (stricmp("JABBER", proto) == 0) + if (stricmp("JABBER", protoID) == 0) { DBVARIANT dbv = {0}; - if (DBGetContactSettingString(hContact, acc->szModuleName, "Transport", &dbv) == 0) + if (DBGetContactSettingString(hContact, proto, "Transport", &dbv) == 0) { Module *ret = GetModule(dbv.pszVal); @@ -2074,11 +2103,11 @@ Module * GetContactModule(HANDLE hContact, const char *proto) if (m->derived.proto_name == NULL) continue; - if (stricmp(m->derived.proto_name, proto) != 0) + if (stricmp(m->derived.proto_name, protoID) != 0) continue; DBVARIANT dbv = {0}; - if (DBGetContactSettingString(NULL, acc->szModuleName, m->derived.db_key, &dbv) != 0) + if (DBGetContactSettingString(NULL, proto, m->derived.db_key, &dbv) != 0) continue; Module *ret = NULL; @@ -2091,7 +2120,7 @@ Module * GetContactModule(HANDLE hContact, const char *proto) return ret; } - return GetModule(proto); + return GetModule(protoID); } @@ -2227,6 +2256,11 @@ Emoticon::~Emoticon() texts.destroy(); } +BOOL Emoticon::IgnoreFor(Module *m) +{ + return service[0] != NULL && !EmoticonServiceExists(m->name, service[0]); +} + EmoticonPack::~EmoticonPack() { @@ -3013,4 +3047,58 @@ void log(const char *fmt, ...) va_end(va); CallService(MS_NETLIB_LOG, (WPARAM) hNetlibUser, (LPARAM) text); +} + +DWORD ConvertServiceParam(char *param, char *proto, HANDLE hContact) +{ + DWORD ret; + if (param == NULL) + ret = 0; + else if (stricmp("hContact", param) == 0) + ret = (DWORD) hContact; + else if (stricmp("protocol", param) == 0) + ret = (DWORD) proto; + else + ret = atoi(param); + return ret; +} + +int CallEmoticonService(char *proto, HANDLE hContact, char *service, char *wparam, char *lparam) +{ + if (service[0] == '/') + return CallProtoService(proto, service, ConvertServiceParam(wparam, proto, hContact), ConvertServiceParam(lparam, proto, hContact)); + else + return CallService(service, ConvertServiceParam(wparam, proto, hContact), ConvertServiceParam(lparam, proto, hContact)); +} + + +BOOL EmoticonServiceExists(char *proto, char *service) +{ + if (service[0] == '/') + return ProtoServiceExists(proto, service); + else + return ServiceExists(service); +} + + +int DefaultMetaChanged(WPARAM wParam, LPARAM lParam) +{ + HANDLE hMetaContact = (HANDLE) wParam; + HANDLE hDefaultContact = (HANDLE) lParam; + + Module *m = GetContactModule(hDefaultContact); + if (m == NULL) + return 0; + + for(DialogMapType::iterator it = dialogData.begin(); it != dialogData.begin(); it++) + { + Dialog *dlg = it->second; + if (dlg->hOriginalContact != hMetaContact) + continue; + + dlg->contact = GetContact(hDefaultContact); + dlg->module = m; + } + + return 0; } \ No newline at end of file diff --git a/Plugins/emoticons/selwin.cpp b/Plugins/emoticons/selwin.cpp index d0f7301..2bfe5f2 100644 --- a/Plugins/emoticons/selwin.cpp +++ b/Plugins/emoticons/selwin.cpp @@ -73,19 +73,6 @@ void AssertInsideScreen(RECT &rc) } -DWORD ConvertServiceParam(EmoticonsSelectionLayout *layout, char *param) -{ - DWORD ret; - if (param == NULL) - ret = 0; - else if (stricmp("hContact", param) == 0) - ret = (DWORD) layout->ssd->hContact; - else - ret = atoi(param); - return ret; -} - - INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) @@ -284,12 +271,12 @@ INT_PTR CALLBACK EmoticonSeletionDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPA if (layout->selection >= 0 && layout->ssd->hwndTarget != NULL) { Emoticon *e = layout->ssd->module->emoticons[layout->selection]; - if (e->service[0] != NULL) { - CallProtoService(layout->ssd->module->name, e->service[0], - ConvertServiceParam(layout, e->service[1]), - ConvertServiceParam(layout, e->service[2])); + if (e->service[3] != NULL && EmoticonServiceExists(layout->ssd->module->name, e->service[3])) + CallEmoticonService(layout->ssd->module->name, layout->ssd->hContact, e->service[3], e->service[4], e->service[5]); + else + CallEmoticonService(layout->ssd->module->name, layout->ssd->hContact, e->service[0], e->service[1], e->service[2]); } else if (opts.only_replace_isolated) { -- cgit v1.2.3