/*
Facebook plugin for Miranda Instant Messenger
_____________________________________________
Copyright © 2009-11 Michal Zelinka, 2011-13 Robert Pösel
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "common.h"
extern OBJLIST g_Instances;
static IconItem icons[] =
{
{ LPGEN("Facebook icon"), "facebook", IDI_FACEBOOK },
{ LPGEN("Mind"), "mind", IDI_MIND },
{ LPGEN("Poke"), "poke", IDI_POKE },
{ LPGEN("Notification"), "notification", IDI_NOTIFICATION },
{ LPGEN("Newsfeed"), "newsfeed", IDI_NEWSFEED },
{ LPGEN("Cancel friendship"), "authRevoke", IDI_AUTH_REVOKE },
{ LPGEN("Cancel friendship request"), "authRevokeReq", IDI_AUTH_REVOKE },
{ LPGEN("Request friendship"), "authAsk", IDI_AUTH_ASK },
{ LPGEN("Approve friendship"), "authGrant", IDI_AUTH_GRANT },
{ LPGEN("Visit friendship details"), "friendship", IDI_FRIENDS },
{ LPGEN("Visit profile"), "homepage", 0 },
};
// TODO: uninit
void InitIcons(void)
{
Icon_Register(g_hInstance, "Protocols/Facebook", icons, SIZEOF(icons)-1, "Facebook");
icons[SIZEOF(icons)-1].hIcolib = LoadSkinnedIconHandle(SKINICON_EVENT_URL);
}
HANDLE GetIconHandle(const char* name)
{
for(size_t i=0; i
INT_PTR GlobalService(WPARAM wParam,LPARAM lParam)
{
FacebookProto *proto = GetInstanceByHContact(reinterpret_cast(wParam));
return proto ? (proto->*Fcn)(wParam,lParam) : 0;
}
static int PrebuildContactMenu(WPARAM wParam,LPARAM lParam)
{
for (size_t i=0; i(wParam));
return proto ? proto->OnPrebuildContactMenu(wParam,lParam) : 0;
}
void InitContactMenus()
{
HookEvent(ME_CLIST_PREBUILDCONTACTMENU,PrebuildContactMenu);
CLISTMENUITEM mi = {sizeof(mi)};
mi.position=-2000006000;
mi.icolibItem = GetIconHandle("homepage");
mi.pszName = GetIconDescription("homepage");
mi.pszService = "FacebookProto/VisitProfile";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::VisitProfile>);
g_hContactMenuItems[CMI_VISIT_PROFILE] = Menu_AddContactMenuItem(&mi);
mi.position=-2000006001;
mi.icolibItem = GetIconHandle("friendship");
mi.pszName = GetIconDescription("friendship");
mi.pszService = "FacebookProto/VisitFriendship";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::VisitFriendship>);
g_hContactMenuItems[CMI_VISIT_FRIENDSHIP] = Menu_AddContactMenuItem(&mi);
mi.position=-2000006002;
mi.icolibItem = GetIconHandle("poke");
mi.pszName = GetIconDescription("poke");
mi.pszService = "FacebookProto/Poke";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::Poke>);
g_hContactMenuItems[CMI_POKE] = Menu_AddContactMenuItem(&mi);
mi.position=-2000006010;
mi.icolibItem = GetIconHandle("authRevoke");
mi.pszName = GetIconDescription("authRevoke");
mi.pszService = "FacebookProto/CancelFriendship";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::CancelFriendship>);
g_hContactMenuItems[CMI_AUTH_REVOKE] = Menu_AddContactMenuItem(&mi);
mi.position=-2000006011;
mi.icolibItem = GetIconHandle("authRevokeReq");
mi.pszName = GetIconDescription("authRevokeReq");
mi.pszService = "FacebookProto/CancelFriendshipRequest";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::OnCancelFriendshipRequest>);
g_hContactMenuItems[CMI_AUTH_CANCEL] = Menu_AddContactMenuItem(&mi);
mi.position=-2000006012;
mi.icolibItem = GetIconHandle("authAsk");
mi.pszName = GetIconDescription("authAsk");
mi.pszService = "FacebookProto/RequestFriendship";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::RequestFriendship>);
g_hContactMenuItems[CMI_AUTH_ASK] = Menu_AddContactMenuItem(&mi);
mi.position=-2000006013;
mi.icolibItem = GetIconHandle("authGrant");
mi.pszName = GetIconDescription("authGrant");
mi.pszService = "FacebookProto/ApproveFriendship";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::ApproveFriendship>);
g_hContactMenuItems[CMI_AUTH_GRANT] = Menu_AddContactMenuItem(&mi);
}
void UninitContactMenus()
{
for(size_t i=0; i(wParam);
bool isChatroom = db_get_b(hContact, m_szModuleName, "ChatRoom", 0) > 0;
Menu_ShowItem(g_hContactMenuItems[CMI_VISIT_PROFILE], true);
Menu_ShowItem(g_hContactMenuItems[CMI_VISIT_FRIENDSHIP], !isChatroom);
if (!isOffline() && !isChatroom)
{
bool ctrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
BYTE type = db_get_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0);
Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_ASK], ctrlPressed || type == FACEBOOK_CONTACT_NONE || !type);
Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_GRANT], ctrlPressed || type == FACEBOOK_CONTACT_APPROVE);
Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_REVOKE], ctrlPressed || type == FACEBOOK_CONTACT_FRIEND);
Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_CANCEL], ctrlPressed || type == FACEBOOK_CONTACT_REQUEST);
Menu_ShowItem(g_hContactMenuItems[CMI_POKE], true);
}
return 0;
}
int FacebookProto::OnBuildStatusMenu(WPARAM wParam,LPARAM lParam)
{
char text[200];
strcpy(text,m_szModuleName);
char *tDest = text+strlen(text);
CLISTMENUITEM mi = {sizeof(mi)};
mi.pszService = text;
HGENMENU hRoot = MO_GetProtoRootMenu(m_szModuleName);
if (hRoot == NULL) {
mi.popupPosition = 500085000;
mi.hParentMenu = HGENMENU_ROOT;
mi.flags = CMIF_ROOTPOPUP | CMIF_TCHAR | CMIF_KEEPUNTRANSLATED | (this->isOnline() ? 0 : CMIF_GRAYED);
mi.icolibItem = GetIconHandle("facebook");
mi.ptszName = m_tszUserName;
hRoot = m_hMenuRoot = Menu_AddProtoMenuItem(&mi);
} else {
if (m_hMenuRoot)
CallService(MS_CLIST_REMOVEMAINMENUITEM, (WPARAM)m_hMenuRoot, 0);
m_hMenuRoot = NULL;
}
mi.flags = CMIF_CHILDPOPUP | (this->isOnline() ? 0 : CMIF_GRAYED);
mi.position = 201001;
CreateProtoService(m_szModuleName,"/Mind",&FacebookProto::OnMind,this);
strcpy(tDest,"/Mind");
mi.hParentMenu = hRoot;
mi.pszName = LPGEN("Mind...");
mi.icolibItem = GetIconHandle("mind");
m_hStatusMind = Menu_AddProtoMenuItem(&mi);
CreateProtoService(m_szModuleName,"/VisitProfile",&FacebookProto::VisitProfile,this);
strcpy(tDest,"/VisitProfile");
mi.flags = CMIF_CHILDPOPUP;
mi.pszName = LPGEN("Visit Profile");
mi.icolibItem = GetIconHandle("homepage");
// TODO RM: remember and properly free in destructor?
/*m_hStatusMind = */Menu_AddProtoMenuItem(&mi);
// Services...
mi.pszName = LPGEN("Services...");
strcpy(tDest, "/Services");
mi.flags = CMIF_CHILDPOPUP | (this->isOnline() ? 0 : CMIF_GRAYED);
mi.icolibItem = NULL;
m_hMenuServicesRoot = Menu_AddProtoMenuItem(&mi);
CreateProtoService(m_szModuleName,"/RefreshBuddyList",&FacebookProto::RefreshBuddyList,this);
strcpy(tDest,"/RefreshBuddyList");
mi.flags = CMIF_ROOTHANDLE;
mi.pszName = LPGEN("Refresh Buddy List");
mi.pszPopupName = LPGEN("Services");
mi.icolibItem = NULL;
mi.hParentMenu = m_hMenuServicesRoot;
Menu_AddProtoMenuItem(&mi);
CreateProtoService(m_szModuleName,"/CheckFriendRequests",&FacebookProto::CheckFriendRequests,this);
strcpy(tDest,"/CheckFriendRequests");
mi.flags = CMIF_ROOTHANDLE;
mi.pszName = LPGEN("Check Friends Requests");
mi.icolibItem = NULL;
mi.hParentMenu = m_hMenuServicesRoot;
Menu_AddProtoMenuItem(&mi);
CreateProtoService(m_szModuleName,"/CheckNewsfeeds",&FacebookProto::CheckNewsfeeds,this);
strcpy(tDest,"/CheckNewsfeeds");
mi.flags = CMIF_ROOTHANDLE;
mi.pszName = LPGEN("Check Newsfeeds");
mi.pszPopupName = LPGEN("Services");
mi.icolibItem = NULL;
mi.hParentMenu = m_hMenuServicesRoot;
Menu_AddProtoMenuItem(&mi);
return 0;
}
void FacebookProto::ToggleStatusMenuItems(BOOL bEnable)
{
CLISTMENUITEM clmi = {sizeof(clmi)};
clmi.flags = CMIM_FLAGS | ((bEnable) ? 0 : CMIF_GRAYED);
Menu_ModifyItem(m_hMenuRoot, &clmi);
Menu_ModifyItem(m_hStatusMind, &clmi);
Menu_ModifyItem(m_hMenuServicesRoot, &clmi);
}