summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-08-09 20:15:51 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-08-09 20:15:51 +0300
commit3ae61fd1e898ae97669acf30e514ce98985d1fe8 (patch)
treecd3a63b7d524f2a8214076a0ff67d238fbe5bdbf /plugins
parent5b15ed8d1ba3fa49b68b95597483c6700d8ec258 (diff)
fixes #1538 (MirOTR menu items are disaplyed for non-IM contacts)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MirOTR/src/svcs_menu.cpp91
-rw-r--r--plugins/MirOTR/src/version.h2
2 files changed, 48 insertions, 45 deletions
diff --git a/plugins/MirOTR/src/svcs_menu.cpp b/plugins/MirOTR/src/svcs_menu.cpp
index 0dc6a16897..d0104d60dc 100644
--- a/plugins/MirOTR/src/svcs_menu.cpp
+++ b/plugins/MirOTR/src/svcs_menu.cpp
@@ -5,45 +5,46 @@ static HGENMENU hStopItem, hStartItem;
////////////////////////////////
///////// Menu Services ////////
///////////////////////////////
-int StartOTR(MCONTACT hContact) {
+int StartOTR(MCONTACT hContact)
+{
const char *proto = GetContactProto(hContact);
if (!proto) return 1; // error
char *uname = contact_get_id(hContact);
if (!uname) return 1; // error
DWORD pol = db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
- if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy;
-
+ if (pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy;
+
lib_cs_lock();
- #ifndef MIROTR_PROTO_HELLO_MSG
+#ifndef MIROTR_PROTO_HELLO_MSG
char *msg = otrl_proto_default_query_msg(MODULENAME, pol);
otr_gui_inject_message((void*)hContact, proto, proto, uname, msg ? msg : MIROTR_PROTO_HELLO);
free(msg);
- #else
- wchar_t* nick=ProtoGetNickname(proto);
- if(nick){
+#else
+ wchar_t* nick = ProtoGetNickname(proto);
+ if (nick) {
wchar_t msg[1024];
- wchar_t* msgend = msg+_countof(msg)-1;
+ wchar_t* msgend = msg + _countof(msg) - 1;
wchar_t* msgoff = msg;
- for(const char* c=MIROTR_PROTO_HELLO; *c; *msgoff++=*c++);
+ for (const char* c = MIROTR_PROTO_HELLO; *c; *msgoff++ = *c++);
*msgoff++ = '\n';
- for(const wchar_t* c=nick; *c && msgoff<msgend; *msgoff++=*c++);
- for(const wchar_t* c=MIROTR_PROTO_HELLO_MSG; *c && msgoff<msgend; *msgoff++=*c++);
+ for (const wchar_t* c = nick; *c && msgoff < msgend; *msgoff++ = *c++);
+ for (const wchar_t* c = MIROTR_PROTO_HELLO_MSG; *c && msgoff < msgend; *msgoff++ = *c++);
LCID langid = Langpack_GetDefaultLocale();
- if(langid != 0x0409/*US*/ && langid != 0x1009/*CA*/ && langid != 0x0809/*GB*/){ // non english
- const wchar_t* translated=TranslateW(MIROTR_PROTO_HELLO_MSG);
- if(mir_wstrcmp(MIROTR_PROTO_HELLO_MSG,translated)){
+ if (langid != 0x0409/*US*/ && langid != 0x1009/*CA*/ && langid != 0x0809/*GB*/) { // non english
+ const wchar_t* translated = TranslateW(MIROTR_PROTO_HELLO_MSG);
+ if (mir_wstrcmp(MIROTR_PROTO_HELLO_MSG, translated)) {
*msgoff++ = '\n';
- for(const wchar_t* c=nick; *c && msgoff<msgend; *msgoff++=*c++);
- for(const wchar_t* c=translated; *c && msgoff<msgend; *msgoff++=*c++);
+ for (const wchar_t* c = nick; *c && msgoff < msgend; *msgoff++ = *c++);
+ for (const wchar_t* c = translated; *c && msgoff < msgend; *msgoff++ = *c++);
}
}
- *msgoff='\0';
+ *msgoff = '\0';
mir_free(nick);
-
+
T2Utf msg_utf8(msg);
otr_gui_inject_message((void*)hContact, proto, proto, uname, msg_utf8 ? msg_utf8 : MIROTR_PROTO_HELLO);
}
- #endif
+#endif
mir_free(uname);
return 0;
}
@@ -53,10 +54,10 @@ INT_PTR SVC_StartOTR(WPARAM hContact, LPARAM)
wchar_t buff[512];
MCONTACT hSub = db_mc_getMostOnline(hContact);
- if(hSub != 0)
+ if (hSub != 0)
hContact = hSub;
- if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0 ) {
+ if (options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0) {
mir_snwprintf(buff, TranslateW(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact));
ShowError(buff);
return 0;
@@ -73,15 +74,15 @@ INT_PTR SVC_RefreshOTR(WPARAM hContact, LPARAM)
wchar_t buff[512];
MCONTACT hSub = db_mc_getMostOnline(hContact);
- if(hSub != 0)
+ if (hSub != 0)
hContact = hSub;
- if ( options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0 ) {
+ if (options.bHaveSecureIM && CallService("SecureIM/IsContactSecured", hContact, 0) != 0) {
mir_snwprintf(buff, 512, TranslateW(LANG_OTR_SECUREIM_STARTED), contact_get_nameT(hContact));
ShowError(buff);
return 0;
}
-
+
mir_snwprintf(buff, TranslateW(LANG_SESSION_TRY_CONTINUE_OTR), contact_get_nameT(hContact));
ShowMessage(hContact, buff);
@@ -96,7 +97,7 @@ int otr_disconnect_contact(MCONTACT hContact)
MCONTACT hSub = db_mc_getMostOnline(hContact);
if (hSub != 0)
hContact = hSub;
-
+
const char *proto = GetContactProto(hContact);
if (!proto) return 1; // error
char *uname = contact_get_id(hContact);
@@ -124,13 +125,13 @@ INT_PTR SVC_StopOTR(WPARAM hContact, LPARAM)
INT_PTR SVC_VerifyOTR(WPARAM hContact, LPARAM)
{
MCONTACT hSub = db_mc_getMostOnline(hContact);
- if(hSub != 0)
+ if (hSub != 0)
hContact = hSub;
ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
if (!context)
return 1;
-
+
//VerifyContextDialog(context);
SMPInitDialog(context);
return 0;
@@ -141,7 +142,7 @@ INT_PTR SVC_ToggleHTMLOTR(WPARAM hContact, LPARAM)
MCONTACT hSub = db_mc_getMostOnline(hContact);
if (hSub != 0)
hContact = hSub;
-
+
if (db_get_b(hContact, MODULENAME, "HTMLConv", 0))
db_set_b(hContact, MODULENAME, "HTMLConv", 0);
else
@@ -167,7 +168,7 @@ void InitMenu()
mi.pszService = MS_OTR_MENUSTOP;
mi.hIcolibItem = IcoLib_GetIconHandle(ICON_PRIVATE);
hStopItem = Menu_AddContactMenuItem(&mi);
-
+
mi.uid.d[7]++;
mi.name.w = _A2W(LANG_START_OTR);
mi.pszService = MS_OTR_MENUSTART;
@@ -179,29 +180,31 @@ void InitMenu()
int SVC_PrebuildContactMenu(WPARAM hContact, LPARAM)
{
+ Menu_ShowItem(hStartItem, false);
+ Menu_ShowItem(hStopItem, false);
+
const char *proto = GetContactProto(hContact);
- DWORD pol = CONTACT_DEFAULT_POLICY;
-
- if (!proto || db_get_b(hContact, proto, "ChatRoom", 0) == 1) {
-hide_all:
- Menu_ShowItem(hStartItem, false);
- Menu_ShowItem(hStopItem, false);
+ if (!proto || db_get_b(hContact, proto, "ChatRoom", 0) == 1)
return 0;
- }
-
- if(proto && mir_strcmp(proto, META_PROTO) == 0) {
+
+ if (proto && mir_strcmp(proto, META_PROTO) == 0) {
// make menu act as per most online subcontact
hContact = db_mc_getMostOnline(hContact);
if (!hContact)
- goto hide_all;
+ return 0;
proto = GetContactProto(hContact);
}
- pol = db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
- if(pol == CONTACT_DEFAULT_POLICY) pol = options.default_policy;
-
- if(pol == OTRL_POLICY_NEVER || pol == OTRL_POLICY_ALWAYS)
- goto hide_all;
+ INT_PTR caps = CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0);
+ if ((caps & PF1_IM) == 0)
+ return 0;
+
+ DWORD pol = db_get_dw(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
+ if (pol == CONTACT_DEFAULT_POLICY)
+ pol = options.default_policy;
+
+ if (pol == OTRL_POLICY_NEVER || pol == OTRL_POLICY_ALWAYS)
+ return 0;
ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
TrustLevel encrypted = otr_context_get_trust(context);
diff --git a/plugins/MirOTR/src/version.h b/plugins/MirOTR/src/version.h
index bfe6b1cf86..74d7a2ca6f 100644
--- a/plugins/MirOTR/src/version.h
+++ b/plugins/MirOTR/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 14
#define __RELEASE_NUM 1
-#define __BUILD_NUM 16
+#define __BUILD_NUM 17
#include <stdver.h>