summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2013-05-16 09:57:54 +0000
committerRobert Pösel <robyer@seznam.cz>2013-05-16 09:57:54 +0000
commit99f1e39a46f191bf60bc138206437bb5ce00834b (patch)
tree0e6bd70691121e3dbde39d8c34278a1b24e69e29 /protocols/FacebookRM/src
parenta55fb1498da50152f3b21248e9b21781c0bb5b7b (diff)
Facebook: Added contact menu item to open Frindship details.
Small cleanup of code. git-svn-id: http://svn.miranda-ng.org/main/trunk@4666 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/proto.cpp155
-rw-r--r--protocols/FacebookRM/src/proto.h1
-rw-r--r--protocols/FacebookRM/src/theme.cpp26
-rw-r--r--protocols/FacebookRM/src/theme.h11
4 files changed, 99 insertions, 94 deletions
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index 1d3e8383bd..61d07d41b2 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -164,14 +164,12 @@ int FacebookProto::SetStatus(int new_status)
break;
}
- if (m_iStatus == ID_STATUS_CONNECTING)
- {
+ if (m_iStatus == ID_STATUS_CONNECTING) {
LOG("===== Status is connecting, no change");
return 0;
}
- if (m_iStatus == m_iDesiredStatus)
- {
+ if (m_iStatus == m_iDesiredStatus) {
LOG("===== Statuses are same, no change");
return 0;
}
@@ -179,14 +177,12 @@ int FacebookProto::SetStatus(int new_status)
facy.invisible_ = (new_status == ID_STATUS_INVISIBLE);
ForkThread(&FacebookProto::ChangeStatus, this);
-
return 0;
}
int FacebookProto::SetAwayMsg(int status, const PROTOCHAR *msg)
{
- if (!msg)
- {
+ if (!msg) {
last_status_msg_.clear();
return 0;
}
@@ -196,9 +192,8 @@ int FacebookProto::SetAwayMsg(int status, const PROTOCHAR *msg)
utils::mem::detract(narrow);
if (isOnline() && getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS))
- {
ForkThread(&FacebookProto::SetAwayMsgWorker, this, NULL);
- }
+
return 0;
}
@@ -245,13 +240,11 @@ HANDLE FacebookProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE, false, fbu.real_name.c_str());
if (hContact) {
- if (flags & PALF_TEMPORARY)
- {
+ if (flags & PALF_TEMPORARY) {
db_set_b(hContact, "Clist", "Hidden", 1);
db_set_b(hContact, "Clist", "NotOnList", 1);
}
- else if (db_get_b(hContact, "CList", "NotOnList", 0))
- {
+ else if (db_get_b(hContact, "CList", "NotOnList", 0)) {
db_unset(hContact, "CList", "Hidden");
db_unset(hContact, "CList", "NotOnList");
}
@@ -271,36 +264,31 @@ int FacebookProto::AuthRequest(HANDLE hContact,const PROTOCHAR *message)
int FacebookProto::Authorize(HANDLE hDbEvent)
{
- if (!isOffline() && hDbEvent)
- {
- HANDLE hContact = HContactFromAuthEvent(hDbEvent);
- if (hContact == INVALID_HANDLE_VALUE)
- return 1;
+ if (!hDbEvent || isOffline())
+ return 1;
- return ApproveFriendship((WPARAM)hContact, NULL);
- }
+ HANDLE hContact = HContactFromAuthEvent(hDbEvent);
+ if (hContact == INVALID_HANDLE_VALUE)
+ return 1;
- return 1;
+ return ApproveFriendship((WPARAM)hContact, NULL);
}
int FacebookProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason)
{
+ if (!hDbEvent || isOffline())
+ return 1;
- if (!isOffline() && hDbEvent)
- {
- HANDLE hContact = HContactFromAuthEvent(hDbEvent);
- if (hContact == INVALID_HANDLE_VALUE)
- return 1;
-
- // TODO: hide from facebook requests list
+ HANDLE hContact = HContactFromAuthEvent(hDbEvent);
+ if (hContact == INVALID_HANDLE_VALUE)
+ return 1;
- if (db_get_b(hContact, "CList", "NotOnList", 0))
- CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
+ // TODO: hide from facebook requests list
- return 0;
- }
+ if (db_get_b(hContact, "CList", "NotOnList", 0))
+ CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
- return 1;
+ return 0;
}
//////////////////////////////////////////////////////////////////////////////
@@ -465,32 +453,48 @@ int FacebookProto::VisitProfile(WPARAM wParam,LPARAM lParam)
{
HANDLE hContact = reinterpret_cast<HANDLE>(wParam);
+ // TODO: why isn't wParam == 0 when is status menu moved to main menu?
+ if (wParam == 0 || !IsMyContact(hContact))
+ return 1;
+
std::string url = FACEBOOK_URL_PROFILE;
- DBVARIANT dbv;
- // TODO: why isn't wParam == 0 when is status menu moved to main menu?
- if (wParam != 0 && IsMyContact(hContact)) {
- if (!db_get_s(hContact, m_szModuleName, "Homepage", &dbv)) {
- // Homepage link already present, get it
- url = dbv.pszVal;
- db_free(&dbv);
- } else if (!db_get_s(hContact, m_szModuleName, FACEBOOK_KEY_ID, &dbv)) {
- // No homepage link, create and save it
- url += dbv.pszVal;
- db_set_s(hContact, m_szModuleName, "Homepage", url.c_str());
- db_free(&dbv);
- }
+ mir_ptr<char> val = db_get_sa(hContact, m_szModuleName, "Homepage");
+ if (val != NULL) {
+ // Homepage link already present, get it
+ url = val;
+ } else {
+ // No homepage link, create and save it
+ val = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ url += val;
+ db_set_s(hContact, m_szModuleName, "Homepage", url.c_str());
}
CallService(MS_UTILS_OPENURL, 1, reinterpret_cast<LPARAM>(url.c_str()));
+ return 0;
+}
+
+int FacebookProto::VisitFriendship(WPARAM wParam,LPARAM lParam)
+{
+ HANDLE hContact = reinterpret_cast<HANDLE>(wParam);
+
+ if (wParam == 0 || !IsMyContact(hContact))
+ return 1;
+
+ mir_ptr<char> id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ std::string url = FACEBOOK_URL_PROFILE;
+ url += facy.self_.user_id;
+ url += "&and=" + std::string(id);
+
+ CallService(MS_UTILS_OPENURL, 1, reinterpret_cast<LPARAM>(url.c_str()));
return 0;
}
int FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam)
{
if (wParam == NULL || isOffline())
- return 0;
+ return 1;
bool deleting = (lParam == 1);
@@ -501,34 +505,26 @@ int FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam)
|| (deleting && db_get_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0) != FACEBOOK_CONTACT_FRIEND))
return 0;
- DBVARIANT dbv;
- TCHAR tstr[256];
-
- if (!db_get_ts(hContact, m_szModuleName, FACEBOOK_KEY_NAME, &dbv)) {
- mir_sntprintf(tstr,SIZEOF(tstr),TranslateT("Do you want to cancel your friendship with '%s'?"), dbv.ptszVal);
- db_free(&dbv);
- } else if (!db_get_ts(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) {
- mir_sntprintf(tstr,SIZEOF(tstr),TranslateT("Do you want to cancel your friendship with '%s'?"), dbv.ptszVal);
- db_free(&dbv);
- }
+ mir_ptr<TCHAR> tname = db_get_tsa(hContact, m_szModuleName, FACEBOOK_KEY_NAME);
+ if (tname == NULL)
+ tname = db_get_tsa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ TCHAR tstr[256];
if (MessageBox(0, tstr, m_tszUserName, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDYES) {
- if (!db_get_s(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv))
- {
- std::string* id = new std::string(dbv.pszVal);
+ mir_ptr<char> id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ if (id == NULL)
+ return 1;
- if (deleting) {
- facebook_user* fbu = facy.buddies.find((*id));
- if (fbu != NULL) {
- fbu->handle = NULL;
- }
- }
+ std::string *val = new std::string(id);
- ForkThread(&FacebookProto::DeleteContactFromServer, this, (void*)id);
- db_free(&dbv);
+ if (deleting) {
+ facebook_user *fbu = facy.buddies.find(*val);
+ if (fbu != NULL)
+ fbu->handle = NULL;
}
+ ForkThread(&FacebookProto::DeleteContactFromServer, this, (void*)val);
}
return 0;
@@ -537,40 +533,37 @@ int FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam)
int FacebookProto::RequestFriendship(WPARAM wParam,LPARAM lParam)
{
if (wParam == NULL || isOffline())
- return 0;
+ return 1;
HANDLE hContact = reinterpret_cast<HANDLE>(wParam);
- DBVARIANT dbv;
- if (!db_get_s(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv))
- {
- std::string* id = new std::string(dbv.pszVal);
- ForkThread(&FacebookProto::AddContactToServer, this, (void*)id);
- db_free(&dbv);
- }
-
+ mir_ptr<char> id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID);
+ if (id == NULL)
+ return 1;
+
+ ForkThread(&FacebookProto::AddContactToServer, this, new std::string(id));
return 0;
}
int FacebookProto::ApproveFriendship(WPARAM wParam,LPARAM lParam)
{
if (wParam == NULL || isOffline())
- return 0;
+ return 1;
HANDLE *hContact = new HANDLE(reinterpret_cast<HANDLE>(wParam));
- ForkThread(&FacebookProto::ApproveContactToServer, this, (void*)hContact);
+ ForkThread(&FacebookProto::ApproveContactToServer, this, (void*)hContact);
return 0;
}
int FacebookProto::OnCancelFriendshipRequest(WPARAM wParam,LPARAM lParam)
{
if (wParam == NULL || isOffline())
- return 0;
+ return 1;
HANDLE *hContact = new HANDLE(reinterpret_cast<HANDLE>(wParam));
- ForkThread(&FacebookProto::CancelFriendsRequest, this, (void*)hContact);
+ ForkThread(&FacebookProto::CancelFriendsRequest, this, (void*)hContact);
return 0;
}
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index 0616d3c2b0..3383be21a7 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -106,6 +106,7 @@ public:
int __cdecl GetAvatarInfo(WPARAM, LPARAM);
int __cdecl GetAvatarCaps(WPARAM, LPARAM);
int __cdecl VisitProfile(WPARAM, LPARAM);
+ int __cdecl VisitFriendship(WPARAM, LPARAM);
int __cdecl CancelFriendship(WPARAM, LPARAM);
int __cdecl RequestFriendship(WPARAM, LPARAM);
int __cdecl ApproveFriendship(WPARAM, LPARAM);
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp
index a1a539a196..31eb90cb70 100644
--- a/protocols/FacebookRM/src/theme.cpp
+++ b/protocols/FacebookRM/src/theme.cpp
@@ -27,21 +27,23 @@ extern OBJLIST<FacebookProto> g_Instances;
static IconItem icons[] =
{
{ LPGEN("Facebook Icon"), "facebook", IDI_FACEBOOK },
- { LPGEN("Mind"), "mind", IDI_MIND },
+ { LPGEN("Mind"), "mind", IDI_MIND },
{ 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 Profile"), "homepage", 0 },
+ { LPGEN("Visit Profile"), "homepage", 0 },
+ { LPGEN("Friendship Details"), "friendship", 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);
+ icons[SIZEOF(icons)-2].hIcolib = LoadSkinnedIconHandle(SKINICON_EVENT_URL);
+ icons[SIZEOF(icons)-1].hIcolib = LoadSkinnedIconHandle(SKINICON_EVENT_URL);
}
HANDLE GetIconHandle(const char* name)
@@ -108,27 +110,34 @@ void InitContactMenus()
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("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=-2000006001;
+ mi.position=-2000006003;
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=-2000006002;
+ mi.position=-2000006004;
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=-2000006003;
+ mi.position=-2000006005;
mi.icolibItem = GetIconHandle("authGrant");
mi.pszName = GetIconDescription("authGrant");
mi.pszService = "FacebookProto/ApproveFriendship";
@@ -145,13 +154,14 @@ void UninitContactMenus()
int FacebookProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
{
HANDLE hContact = reinterpret_cast<HANDLE>(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() && !db_get_b(hContact, m_szModuleName, "ChatRoom", 0))
+ 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);
diff --git a/protocols/FacebookRM/src/theme.h b/protocols/FacebookRM/src/theme.h
index e86bfa995b..f472b4f9ce 100644
--- a/protocols/FacebookRM/src/theme.h
+++ b/protocols/FacebookRM/src/theme.h
@@ -30,9 +30,10 @@ void UninitContactMenus(void);
/* Contact menu item indexes */
#define CMI_VISIT_PROFILE 0
-#define CMI_AUTH_REVOKE 1
-#define CMI_AUTH_ASK 2
-#define CMI_AUTH_GRANT 3
-#define CMI_AUTH_CANCEL 4
+#define CMI_VISIT_FRIENDSHIP 1
+#define CMI_AUTH_REVOKE 2
+#define CMI_AUTH_ASK 3
+#define CMI_AUTH_GRANT 4
+#define CMI_AUTH_CANCEL 5
-#define CMITEMS_COUNT 5 \ No newline at end of file
+#define CMITEMS_COUNT 6 \ No newline at end of file