From bfc32bdd14834d3293c0f909f5b83756144fc17f Mon Sep 17 00:00:00 2001 From: unitraxx Date: Fri, 23 Aug 2013 00:49:46 +0000 Subject: [PATCH] Remove friend and cancel request added in the client. Server-side still need to be implemented. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13553 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gui/online/user_info_dialog.stkgui | 2 + src/online/current_user.cpp | 66 +++++++++++++++++++ src/online/current_user.hpp | 14 ++++ .../dialogs/user_info_dialog.cpp | 45 ++++++++++--- .../dialogs/user_info_dialog.hpp | 1 + 5 files changed, 119 insertions(+), 9 deletions(-) diff --git a/data/gui/online/user_info_dialog.stkgui b/data/gui/online/user_info_dialog.stkgui index ba78d0bda..ae9e16d46 100644 --- a/data/gui/online/user_info_dialog.stkgui +++ b/data/gui/online/user_info_dialog.stkgui @@ -21,6 +21,8 @@ + pushDialog( new UserInfoDialog(id, info_text,!m_success, true), true); + } + + // ============================================================================ + + void CurrentUser::requestCancelFriend(const uint32_t friend_id) const + { + assert(isRegisteredUser()); + CurrentUser::CancelFriendRequest * request = new CurrentUser::CancelFriendRequest(); + request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + request->setParameter("action", std::string("cancel-friend-request")); + request->setParameter("token", getToken()); + request->setParameter("userid", getID()); + request->setParameter("friendid", friend_id); + HTTPManager::get()->addRequest(request); + } + + void CurrentUser::CancelFriendRequest::callback() + { + uint32_t id(0); + m_result->get("friendid", &id); + irr::core::stringw info_text(""); + if(m_success) + { + CurrentUser::get()->getProfile()->removeFriend(id); + ProfileManager::get()->moveToCache(id); + ProfileManager::get()->getProfileByID(id)->deleteRelationalInfo(); + OnlineProfileFriends::getInstance()->refreshFriendsList(); + info_text = _("Friend request cancelled!"); + } + else + info_text = m_info; + GUIEngine::DialogQueue::get()->pushDialog( new UserInfoDialog(id, info_text,!m_success, true), true); + + } + + // ============================================================================ + + void CurrentUser::requestRemoveFriend(const uint32_t friend_id) const + { + assert(isRegisteredUser()); + CurrentUser::RemoveFriendRequest * request = new CurrentUser::RemoveFriendRequest(); + request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php"); + request->setParameter("action", std::string("remove-friend-request")); + request->setParameter("token", getToken()); + request->setParameter("userid", getID()); + request->setParameter("friendid", friend_id); + HTTPManager::get()->addRequest(request); + } + + void CurrentUser::RemoveFriendRequest::callback() + { + uint32_t id(0); + m_result->get("friendid", &id); + irr::core::stringw info_text(""); + if(m_success) + { + CurrentUser::get()->getProfile()->removeFriend(id); + ProfileManager::get()->moveToCache(id); + ProfileManager::get()->getProfileByID(id)->deleteRelationalInfo(); + OnlineProfileFriends::getInstance()->refreshFriendsList(); + info_text = _("Friend removed!"); + } + else + info_text = m_info; + GUIEngine::DialogQueue::get()->pushDialog( new UserInfoDialog(id, info_text,!m_success, true), true); + } // ============================================================================ void CurrentUser::requestPoll() diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp index 3dcf8f936..3e2f31b00 100644 --- a/src/online/current_user.hpp +++ b/src/online/current_user.hpp @@ -102,6 +102,18 @@ namespace Online{ DeclineFriendRequest() : XMLRequest(true) {} }; + class RemoveFriendRequest : public XMLRequest { + virtual void callback (); + public: + RemoveFriendRequest() : XMLRequest(true) {} + }; + + class CancelFriendRequest : public XMLRequest { + virtual void callback (); + public: + CancelFriendRequest() : XMLRequest(true) {} + }; + class PollRequest : public XMLRequest { virtual void callback (); public: @@ -156,6 +168,8 @@ namespace Online{ void requestFriendRequest(const uint32_t friend_id) const; void requestAcceptFriend(const uint32_t friend_id) const; void requestDeclineFriend(const uint32_t friend_id) const; + void requestRemoveFriend(const uint32_t friend_id) const; + void requestCancelFriend(const uint32_t friend_id) const; const XMLRequest * requestUserSearch(const irr::core::stringw & search_string) const; diff --git a/src/states_screens/dialogs/user_info_dialog.cpp b/src/states_screens/dialogs/user_info_dialog.cpp index 850418979..4bfd72012 100644 --- a/src/states_screens/dialogs/user_info_dialog.cpp +++ b/src/states_screens/dialogs/user_info_dialog.cpp @@ -47,6 +47,8 @@ void UserInfoDialog::load() loadFromFile("online/user_info_dialog.stkgui"); if(m_error) m_info_widget->setErrorColor(); + m_name_widget->setText(m_profile->getUserName(),false); + m_info_widget->setText(m_info, false); } void UserInfoDialog::beforeAddingWidgets() @@ -57,12 +59,13 @@ void UserInfoDialog::beforeAddingWidgets() m_processing = false; m_name_widget = getWidget("name"); assert(m_name_widget != NULL); - m_name_widget->setText(m_profile->getUserName(),false); m_info_widget = getWidget("info"); assert(m_info_widget != NULL); - m_info_widget->setText(m_info, false); + m_options_widget = getWidget("options"); assert(m_options_widget != NULL); + m_remove_widget = getWidget("remove"); + assert(m_remove_widget != NULL); m_friend_widget = getWidget("friend"); assert(m_friend_widget != NULL); m_accept_widget = getWidget("accept"); @@ -77,20 +80,35 @@ void UserInfoDialog::beforeAddingWidgets() m_accept_widget->setVisible(false); m_decline_widget->setVisible(false); - if(m_profile->isFriend() || m_profile->isCurrentUser()) + m_remove_widget->setVisible(false); + if(m_profile->isCurrentUser()) + { m_friend_widget->setVisible(false); + } + if(m_profile->isFriend()) + { + m_friend_widget->setVisible(false); + m_remove_widget->setVisible(true); + } Profile::RelationInfo * relation_info = m_profile->getRelationInfo(); if(relation_info != NULL) { - if(relation_info->isPending() && relation_info->isAsker()) - { - m_accept_widget->setVisible(true); - m_decline_widget->setVisible(true); - } - if(relation_info->isPending()) + { m_friend_widget->setVisible(false); + if(relation_info->isAsker()) + { + m_accept_widget->setVisible(true); + m_decline_widget->setVisible(true); + } + else + { + m_remove_widget->setVisible(true); + m_remove_widget->setLabel("Cancel"); + //FIXME set text to cancel? + } + } } } @@ -126,6 +144,15 @@ GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& even m_processing = true; return GUIEngine::EVENT_BLOCK; } + else if(selection == m_remove_widget->m_properties[PROP_ID]) + { + if(m_profile->getRelationInfo()->isPending()) + CurrentUser::get()->requestCancelFriend(m_profile->getID()); + else + CurrentUser::get()->requestRemoveFriend(m_profile->getID()); + m_processing = true; + return GUIEngine::EVENT_BLOCK; + } else if(selection == m_accept_widget->m_properties[PROP_ID]) { CurrentUser::get()->requestAcceptFriend(m_profile->getID()); diff --git a/src/states_screens/dialogs/user_info_dialog.hpp b/src/states_screens/dialogs/user_info_dialog.hpp index 5b64be329..c9f16eec3 100644 --- a/src/states_screens/dialogs/user_info_dialog.hpp +++ b/src/states_screens/dialogs/user_info_dialog.hpp @@ -51,6 +51,7 @@ private: GUIEngine::LabelWidget * m_info_widget; GUIEngine::RibbonWidget * m_options_widget; + GUIEngine::IconButtonWidget * m_remove_widget; GUIEngine::IconButtonWidget * m_friend_widget; GUIEngine::IconButtonWidget * m_accept_widget; GUIEngine::IconButtonWidget * m_decline_widget;