summaryrefslogtreecommitdiff
path: root/protocols/VKontakte
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2014-09-16 07:13:53 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2014-09-16 07:13:53 +0000
commit97e207d17f76808160865b254a5d61c3ab86cebf (patch)
treee65cbea8b28a842877862c1e86d9f1d5e4aa693b /protocols/VKontakte
parent74e64820552463c202c6772bb0f14050e113c66b (diff)
VKontakte:
Rework menu items Add ‘Visit profile’ menu items Remove ‘Reload all messages from vk.com’ for chats Some cosmetic changes git-svn-id: http://svn.miranda-ng.org/main/trunk@10467 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp68
-rw-r--r--protocols/VKontakte/src/vk_proto.h26
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp27
3 files changed, 102 insertions, 19 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index 69032ef1ef..fb2d928e52 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -39,7 +39,7 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
CreateProtoService(PS_CREATEACCMGRUI, &CVkProto::SvcCreateAccMgrUI);
CreateProtoService(PS_GETAVATARINFOT, &CVkProto::SvcGetAvatarInfo);
CreateProtoService(PS_GETAVATARCAPS, &CVkProto::SvcGetAvatarCaps);
- CreateProtoService(PS_SET_LISTENINGTO, &CVkProto::SetListeningTo);
+ CreateProtoService(PS_SET_LISTENINGTO, &CVkProto::SvcSetListeningTo);
HookProtoEvent(ME_OPT_INITIALISE, &CVkProto::OnOptionsInit);
@@ -76,6 +76,7 @@ CVkProto::~CVkProto()
{
Netlib_CloseHandle(m_hNetlibUser); m_hNetlibUser = NULL;
UninitQueue();
+ UnInitMenus();
vk_Instances.remove(this);
}
@@ -88,39 +89,76 @@ int CVkProto::OnModulesLoaded(WPARAM wParam, LPARAM lParam)
gcr.nColors = SIZEOF(sttColors);
gcr.pColors = sttColors;
CallServiceSync(MS_GC_REGISTER, NULL, (LPARAM)&gcr);
-
- CreateProtoService(PS_CREATECHAT, &CVkProto::SvcCreateChat);
-
+
HookProtoEvent(ME_GC_EVENT, &CVkProto::OnChatEvent);
HookProtoEvent(ME_GC_BUILDMENU, &CVkProto::OnGcMenuHook);
- char szService[100];
- mir_snprintf(szService, sizeof(szService), "%s%s", m_szModuleName, PS_CREATECHAT);
+ InitMenus();
+ return 0;
+}
+
+void CVkProto::InitMenus()
+{
+ HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &CVkProto::OnPreBuildContactMenu);
+
+ //Contact Menu Services
+ CreateProtoService(PS_GETALLSERVERHISTORY, &CVkProto::SvcGetAllServerHistory);
+ CreateProtoService(PS_VISITPROFILE, &CVkProto::SvcVisitProfile);
+ CreateProtoService(PS_CREATECHAT, &CVkProto::SvcCreateChat);
CLISTMENUITEM mi = { sizeof(mi) };
+ char szService[100];
+
+ // Proto menu
mi.flags = CMIF_CHILDPOPUP;
mi.hParentMenu = MO_GetProtoRootMenu(m_szModuleName);
+
+ mir_snprintf(szService, sizeof(szService), "%s%s", m_szModuleName, PS_CREATECHAT);
mi.pszService = szService;
- mi.position = 10009;
+ mi.position = 10009 + PMI_CREATECHAT;
mi.icolibItem = LoadSkinnedIconHandle(SKINICON_CHAT_JOIN);
mi.pszName = LPGEN("Create new chat");
- Menu_AddProtoMenuItem(&mi);
-
- //Server History
- CreateProtoService(PS_GETALLSERVERHISTORY, &CVkProto::SvcGetAllServerHistory);
-
- mir_snprintf(szService, sizeof(szService), "%s%s", m_szModuleName, PS_GETALLSERVERHISTORY);
+ g_hProtoMenuItems[PMI_CREATECHAT] = Menu_AddProtoMenuItem(&mi);
+
+ mir_snprintf(szService, sizeof(szService), "%s%s", m_szModuleName, PS_VISITPROFILE);
mi.pszService = szService;
+ mi.position = 10009 + PMI_VISITPROFILE;
+ mi.icolibItem = LoadSkinnedIconHandle(SKINICON_EVENT_URL);
+ mi.pszName = LPGEN("Visit profile");
+ g_hProtoMenuItems[PMI_VISITPROFILE] = Menu_AddProtoMenuItem(&mi);
+
+ //Contact Menu Items
mi.pszContactOwner = m_szModuleName;
mi.flags = CMIF_TCHAR;
- mi.position = -200001000+1;
+
+ mi.position = -200001000 + CMI_VISITPROFILE;
+ mi.ptszName = LPGENT("Visit profile");
+ g_hContactMenuItems[CMI_VISITPROFILE] = Menu_AddContactMenuItem(&mi);
+
+ mir_snprintf(szService, sizeof(szService), "%s%s", m_szModuleName, PS_GETALLSERVERHISTORY);
+ mi.position = -200001000 + CMI_GETALLSERVERHISTORY;
mi.icolibItem = LoadSkinnedIconHandle(SKINICON_OTHER_HISTORY);
mi.ptszName = LPGENT("Reload all messages from vk.com");
- Menu_AddContactMenuItem(&mi);
+ mi.pszService = szService;
+ g_hContactMenuItems[CMI_GETALLSERVERHISTORY] = Menu_AddContactMenuItem(&mi);
+}
+
+int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM)
+{
+ for (int i = 0; i < CMI_COUNT; i++)
+ Menu_ShowItem(g_hContactMenuItems[i], !isChatRoom(hContact));
return 0;
}
+void CVkProto::UnInitMenus()
+{
+ // ??? ProtoMenu
+
+ for (int i = 0; i < CMI_COUNT; i++)
+ CallService(MS_CLIST_REMOVECONTACTMENUITEM, (WPARAM)g_hContactMenuItems[i], 0);
+}
+
int CVkProto::OnPreShutdown(WPARAM wParam, LPARAM lParam)
{
m_bTerminated = true;
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 497b4da7c9..466ac13fdb 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PS_CREATECHAT "/CreateNewChat"
#define PS_GETALLSERVERHISTORY "/GetAllServerHystory"
+#define PS_VISITPROFILE "/VisitProfile"
#define MAXHISTORYMIDSPERONE 200
struct CVkProto;
@@ -191,9 +192,16 @@ struct CVkProto : public PROTO<CVkProto>
INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM);
INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM);
INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM);
- INT_PTR __cdecl SvcGetAllServerHistory(WPARAM wParam, LPARAM);
- INT_PTR __cdecl SetListeningTo(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcSetListeningTo(WPARAM, LPARAM);
+ //==== Menus ==========================================================================
+
+ INT_PTR __cdecl SvcVisitProfile(WPARAM hContact, LPARAM);
+ INT_PTR __cdecl SvcGetAllServerHistory(WPARAM hContact, LPARAM);
+ void InitMenus();
+ void UnInitMenus();
+ int __cdecl OnPreBuildContactMenu(WPARAM hContact, LPARAM);
+
//==== Misc ==========================================================================
TCHAR* GetUserStoredPassword(void);
@@ -249,6 +257,20 @@ private:
bool m_bTerminated, m_bServerDelivery;
CMStringA m_prevUrl;
+ enum CLMenuIndexes {
+ CMI_GETALLSERVERHISTORY,
+ CMI_VISITPROFILE,
+ CMI_COUNT
+ };
+ enum ProtoMenuIndexes {
+ PMI_CREATECHAT,
+ PMI_VISITPROFILE,
+ PMI_COUNT
+ };
+
+ HGENMENU g_hContactMenuItems[CMI_COUNT];
+ HGENMENU g_hProtoMenuItems[PMI_COUNT];
+
struct Cookie
{
Cookie(const CMStringA& name, const CMStringA& value, const CMStringA& domain) :
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index a67e88f833..7a68c79b52 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -230,7 +230,7 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
/////////////////////////////////////////////////////////////////////////////////////////
-static char fieldsName[] = "id, first_name, last_name, photo_100, sex, timezone, contacts, online, status, about";
+static char fieldsName[] = "id, first_name, last_name, photo_100, sex, timezone, contacts, online, status, about, domain";
void CVkProto::RetrieveUserInfo(LONG userID)
{
@@ -345,6 +345,10 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (szValue && *szValue)
setTString(hContact, "About", szValue);
+ szValue = json_as_string(json_get(pRecord, "domain"));
+ if (szValue && *szValue)
+ setTString(hContact, "domain", szValue);
+
}
}
@@ -438,6 +442,10 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
szValue = json_as_string(json_get(pInfo, "about"));
if (szValue && *szValue)
setTString(hContact, "About", szValue);
+
+ szValue = json_as_string(json_get(pInfo, "domain"));
+ if (szValue && *szValue)
+ setTString(hContact, "domain", szValue);
}
if (bCleanContacts)
@@ -761,7 +769,7 @@ void CVkProto::RetrieveStatusMsg(const CMString &StatusMsg)
<< VER_API);
}
-INT_PTR __cdecl CVkProto::SetListeningTo(WPARAM wParam, LPARAM lParam)
+INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam)
{
LISTENINGTOINFO *pliInfo = (LISTENINGTOINFO*)lParam;
CMStringW wszListeningTo;
@@ -782,6 +790,21 @@ INT_PTR __cdecl CVkProto::SetListeningTo(WPARAM wParam, LPARAM lParam)
return 0;
}
+INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM)
+{
+ LONG userID = getDword(hContact, "ID", -1);
+ ptrT tszDomain(db_get_tsa(hContact, m_szModuleName, "domain"));
+ CMString tszUrl("https://vk.com/");
+
+ if (tszDomain)
+ tszUrl.Append(tszDomain);
+ else
+ tszUrl.AppendFormat(_T("id%i"), userID);
+
+ CallService(MS_UTILS_OPENURL, (WPARAM)OUF_TCHAR, (LPARAM)tszUrl.GetBuffer());
+
+ return 0;
+}
INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM hContact, LPARAM)
{