diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/llfacebookconnect.cpp | 69 | ||||
-rw-r--r-- | indra/newview/llfacebookconnect.h | 19 | ||||
-rw-r--r-- | indra/newview/llfloatersocial.cpp | 86 | ||||
-rw-r--r-- | indra/newview/llfloatersocial.h | 60 | ||||
-rwxr-xr-x | indra/newview/llpanelpeople.cpp | 26 | ||||
-rwxr-xr-x | indra/newview/llpanelpeople.h | 2 |
6 files changed, 177 insertions, 85 deletions
diff --git a/indra/newview/llfacebookconnect.cpp b/indra/newview/llfacebookconnect.cpp index 5d6c496275..30fb63084b 100644 --- a/indra/newview/llfacebookconnect.cpp +++ b/indra/newview/llfacebookconnect.cpp @@ -38,7 +38,9 @@ #include "llimagepng.h" #include "llimagejpeg.h" #include "lltrans.h" +#include "llevents.h" +boost::scoped_ptr<LLEventPump> LLFacebookConnect::sStateWatcher(new LLEventStream("FacebookConnectState")); // Local functions void log_facebook_connect_error(const std::string& request, U32 status, const std::string& reason, const std::string& code, const std::string& description) @@ -93,11 +95,6 @@ public: { LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); } - - LLFacebookConnectResponder(LLFacebookConnect::connect_callback_t cb) : mConnectCallback(cb) - { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); - } virtual void completed(U32 status, const std::string& reason, const LLSD& content) { @@ -107,11 +104,6 @@ public: // Grab some graph data now that we are connected LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); - - if (mConnectCallback) - { - mConnectCallback(); - } } else { @@ -127,9 +119,6 @@ public: LLFacebookConnect::instance().openFacebookWeb(content["location"]); } } - -private: - LLFacebookConnect::connect_callback_t mConnectCallback; }; /////////////////////////////////////////////////////////////////////////////// @@ -139,8 +128,15 @@ class LLFacebookShareResponder : public LLHTTPClient::Responder LOG_CLASS(LLFacebookShareResponder); public: - LLFacebookShareResponder() {} - LLFacebookShareResponder(LLFacebookConnect::share_callback_t cb) : mShareCallback(cb) {} + LLFacebookShareResponder() + { + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POSTING); + } + + LLFacebookShareResponder(LLFacebookConnect::share_callback_t cb) : mShareCallback(cb) + { + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POSTING); + } virtual void completed(U32 status, const std::string& reason, const LLSD& content) { @@ -148,9 +144,12 @@ public: { toast_user_for_success(); LL_DEBUGS("FacebookConnect") << "Post successful. content: " << content << LL_ENDL; + + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); } else { + LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_POST_FAILED); log_facebook_connect_error("Share", status, reason, content.get("error_code"), content.get("error_description")); } @@ -208,11 +207,6 @@ public: LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); } - LLFacebookConnectedResponder(bool auto_connect, LLFacebookConnect::connect_callback_t cb) : mAutoConnect(auto_connect), mConnectCallback(cb) - { - LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTION_IN_PROGRESS); - } - virtual void completed(U32 status, const std::string& reason, const LLSD& content) { if (isGoodStatus(status)) @@ -220,11 +214,6 @@ public: LL_DEBUGS("FacebookConnect") << "Connect successful. content: " << content << LL_ENDL; LLFacebookConnect::instance().setConnectionState(LLFacebookConnect::FB_CONNECTED); - - if (mConnectCallback) - { - mConnectCallback(); - } } else { @@ -250,7 +239,6 @@ public: private: bool mAutoConnect; - LLFacebookConnect::connect_callback_t mConnectCallback; }; /////////////////////////////////////////////////////////////////////////////// @@ -306,13 +294,13 @@ std::string LLFacebookConnect::getFacebookConnectURL(const std::string& route) return url; } -void LLFacebookConnect::connectToFacebook(const std::string& auth_code, connect_callback_t cb) +void LLFacebookConnect::connectToFacebook(const std::string& auth_code) { LLSD body; if (!auth_code.empty()) body["code"] = auth_code; - LLHTTPClient::put(getFacebookConnectURL("/connection"), body, new LLFacebookConnectResponder(cb)); + LLHTTPClient::put(getFacebookConnectURL("/connection"), body, new LLFacebookConnectResponder()); } void LLFacebookConnect::disconnectFromFacebook() @@ -320,21 +308,21 @@ void LLFacebookConnect::disconnectFromFacebook() LLHTTPClient::del(getFacebookConnectURL("/connection"), new LLFacebookDisconnectResponder()); } -void LLFacebookConnect::getConnectionToFacebook(bool auto_connect, connect_callback_t cb) +void LLFacebookConnect::checkConnectionToFacebook(bool auto_connect) { - if ((mConnectionState == FB_NOT_CONNECTED) || (mConnectionState == FB_CONNECTION_FAILED)) + if ((mConnectionState == FB_NOT_CONNECTED) || (mConnectionState == FB_CONNECTION_FAILED) || (mConnectionState == FB_POST_FAILED)) { const bool follow_redirects = false; - const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; - LLHTTPClient::get(getFacebookConnectURL("/connection"), new LLFacebookConnectedResponder(auto_connect, cb), + const F32 timeout = HTTP_REQUEST_EXPIRY_SECS; + LLHTTPClient::get(getFacebookConnectURL("/connection"), new LLFacebookConnectedResponder(auto_connect), LLSD(), timeout, follow_redirects); } } void LLFacebookConnect::loadFacebookFriends() { - const bool follow_redirects=false; - const F32 timeout=HTTP_REQUEST_EXPIRY_SECS; + const bool follow_redirects = false; + const F32 timeout = HTTP_REQUEST_EXPIRY_SECS; LLHTTPClient::get(getFacebookConnectURL("/friends"), new LLFacebookFriendsResponder(), LLSD(), timeout, follow_redirects); } @@ -451,6 +439,19 @@ void LLFacebookConnect::clearContent() mContent = LLSD(); } +void LLFacebookConnect::setConnectionState(LLFacebookConnect::EConnectionState connection_state) +{ + if (mConnectionState != connection_state) + { + LLSD state_info; + state_info["enum"] = connection_state; + sStateWatcher->post(state_info); + } + + mConnectionState = connection_state; +} + + diff --git a/indra/newview/llfacebookconnect.h b/indra/newview/llfacebookconnect.h index 1044c05e45..ddff87385e 100644 --- a/indra/newview/llfacebookconnect.h +++ b/indra/newview/llfacebookconnect.h @@ -31,6 +31,8 @@ #include "llsingleton.h" #include "llimage.h" +class LLEventPump; + /** * @class LLFacebookConnect * @@ -46,16 +48,17 @@ public: FB_NOT_CONNECTED = 0, FB_CONNECTION_IN_PROGRESS = 1, FB_CONNECTED = 2, - FB_CONNECTION_FAILED = 3 + FB_CONNECTION_FAILED = 3, + FB_POSTING = 4, + FB_POST_FAILED = 5 }; - typedef boost::function<void()> connect_callback_t; typedef boost::function<void(bool ok)> share_callback_t; typedef boost::function<void()> content_updated_callback_t; - void connectToFacebook(const std::string& auth_code = "", connect_callback_t cb = connect_callback_t()); // Initiate the complete FB connection. Please use getConnectionToFacebook() in normal use. - void disconnectFromFacebook(); // Disconnect from the FBC service. - void getConnectionToFacebook(bool auto_connect = false, connect_callback_t cb = connect_callback_t()); // Check if an access token is available on the FBC service. If not, call connectToFacebook(). + void connectToFacebook(const std::string& auth_code = ""); // Initiate the complete FB connection. Please use checkConnectionToFacebook() in normal use. + void disconnectFromFacebook(); // Disconnect from the FBC service. + void checkConnectionToFacebook(bool auto_connect = false); // Check if an access token is available on the FBC service. If not, call connectToFacebook(). void loadFacebookFriends(); void postCheckin(const std::string& location, const std::string& name, const std::string& description, const std::string& picture, const std::string& message); @@ -72,9 +75,9 @@ public: void storeContent(const LLSD& content); const LLSD& getContent() const; - void setConnectionState(EConnectionState connection_state) { mConnectionState = connection_state; } + void setConnectionState(EConnectionState connection_state); + bool isConnected() { return ((mConnectionState == FB_CONNECTED) || (mConnectionState == FB_POSTING)); } EConnectionState getConnectionState() { return mConnectionState; } - bool isConnected() { return (mConnectionState == FB_CONNECTED); } S32 generation() { return mGeneration; } void openFacebookWeb(std::string url); @@ -94,6 +97,8 @@ private: share_callback_t mSharePhotoCallback; share_callback_t mUpdateStatusCallback; content_updated_callback_t mContentUpdatedCallback; + + static boost::scoped_ptr<LLEventPump> sStateWatcher; }; #endif // LL_LLFACEBOOKCONNECT_H diff --git a/indra/newview/llfloatersocial.cpp b/indra/newview/llfloatersocial.cpp index ddbaa2d704..684b177f24 100644 --- a/indra/newview/llfloatersocial.cpp +++ b/indra/newview/llfloatersocial.cpp @@ -88,7 +88,7 @@ void LLSocialStatusPanel::draw() if (mMessageTextEditor && mPostStatusButton) { std::string message = mMessageTextEditor->getValue().asString(); - mPostStatusButton->setEnabled(!message.empty() && LLFacebookConnect::instance().isConnected()); + mPostStatusButton->setEnabled(!message.empty()); } LLPanel::draw(); @@ -101,8 +101,18 @@ void LLSocialStatusPanel::onSend() std::string message = mMessageTextEditor->getValue().asString(); if (!message.empty()) { - LLFacebookConnect::instance().updateStatus(message); - + // Connect to Facebook if necessary and then post + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().updateStatus(message); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLSocialStatusPanel", boost::bind(&LLSocialStatusPanel::onConnectedToFacebook, this, _1, message)); + LLFacebookConnect::instance().checkConnectionToFacebook(true); + } + + // Close the floater once "Post" has been pushed LLFloater* floater = getParentByType<LLFloater>(); if (floater) { @@ -112,6 +122,18 @@ void LLSocialStatusPanel::onSend() } } +bool LLSocialStatusPanel::onConnectedToFacebook(const LLSD& data, const std::string& message) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLSocialStatusPanel"); + + LLFacebookConnect::instance().updateStatus(message); + } + + return false; +} + /////////////////////////// //LLSocialPhotoPanel/////// /////////////////////////// @@ -233,8 +255,6 @@ void LLSocialPhotoPanel::draw() mThumbnailPlaceholder->draw(); gGL.popUIMatrix(); } - - mPostButton->setEnabled(LLFacebookConnect::instance().isConnected()); } LLSnapshotLivePreview* LLSocialPhotoPanel::getPreviewView() @@ -302,7 +322,18 @@ void LLSocialPhotoPanel::onSend() } LLSnapshotLivePreview* previewp = getPreviewView(); - LLFacebookConnect::instance().sharePhoto(previewp->getFormattedImage(), caption); + + // Connect to Facebook if necessary and then post + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().sharePhoto(previewp->getFormattedImage(), caption); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLSocialPhotoPanel", boost::bind(&LLSocialPhotoPanel::onConnectedToFacebook, this, _1, previewp->getFormattedImage(), caption)); + LLFacebookConnect::instance().checkConnectionToFacebook(true); + } + updateControls(); // Close the floater once "Post" has been pushed @@ -313,6 +344,18 @@ void LLSocialPhotoPanel::onSend() } } +bool LLSocialPhotoPanel::onConnectedToFacebook(const LLSD& data, LLPointer<LLImageFormatted> image, const std::string& caption) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLSocialPhotoPanel"); + + LLFacebookConnect::instance().sharePhoto(image, caption); + } + + return false; +} + void LLSocialPhotoPanel::updateControls() { LLSnapshotLivePreview* previewp = getPreviewView(); @@ -482,8 +525,7 @@ void LLSocialCheckinPanel::draw() mMapCheckBox->setEnabled(true); mMapCheckBox->set(mMapCheckBoxValue); } - mPostButton->setEnabled(LLFacebookConnect::instance().isConnected()); - + LLPanel::draw(); } @@ -508,8 +550,16 @@ void LLSocialCheckinPanel::onSend() // Get the caption std::string caption = getChild<LLUICtrl>("place_caption")->getValue().asString(); - // Post all that to Facebook - LLFacebookConnect::instance().postCheckin(slurl_string, region_name, description, map_url, caption); + // Connect to Facebook if necessary and then post + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().postCheckin(slurl_string, region_name, description, map_url, caption); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLSocialCheckinPanel", boost::bind(&LLSocialCheckinPanel::onConnectedToFacebook, this, _1, slurl_string, region_name, description, map_url, caption)); + LLFacebookConnect::instance().checkConnectionToFacebook(true); + } // Close the floater once "Post" has been pushed LLFloater* floater = getParentByType<LLFloater>(); @@ -519,6 +569,18 @@ void LLSocialCheckinPanel::onSend() } } +bool LLSocialCheckinPanel::onConnectedToFacebook(const LLSD& data, const std::string& location, const std::string& name, const std::string& description, const std::string& picture, const std::string& message) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLSocialCheckinPanel"); + + LLFacebookConnect::instance().postCheckin(location, name, description, picture, message); + } + + return false; +} + //////////////////////// //LLFloaterSocial/////// //////////////////////// @@ -539,8 +601,6 @@ void LLFloaterSocial::onCancel() BOOL LLFloaterSocial::postBuild() { - // Initiate a connection to Facebook (getConnectionToFacebook() handles the already connected state) - LLFacebookConnect::instance().getConnectionToFacebook(true); // Keep tab of the Photo Panel mSocialPhotoPanel = static_cast<LLSocialPhotoPanel*>(getChild<LLUICtrl>("panel_social_photo")); // Connection status widgets @@ -601,12 +661,14 @@ void LLFloaterSocial::draw() case LLFacebookConnect::FB_NOT_CONNECTED: break; case LLFacebookConnect::FB_CONNECTION_IN_PROGRESS: + case LLFacebookConnect::FB_POSTING: mStatusLoadingText->setVisible(true); mStatusLoadingIndicator->setVisible(true); break; case LLFacebookConnect::FB_CONNECTED: break; case LLFacebookConnect::FB_CONNECTION_FAILED: + case LLFacebookConnect::FB_POST_FAILED: mStatusErrorText->setVisible(true); break; } diff --git a/indra/newview/llfloatersocial.h b/indra/newview/llfloatersocial.h index f90deb9f85..07236c2838 100644 --- a/indra/newview/llfloatersocial.h +++ b/indra/newview/llfloatersocial.h @@ -42,6 +42,7 @@ public: BOOL postBuild(); void draw(); void onSend(); + bool onConnectedToFacebook(const LLSD& data, const std::string& message); private: LLUICtrl* mMessageTextEditor; @@ -50,41 +51,40 @@ private: class LLSocialPhotoPanel : public LLPanel { - public: - LLSocialPhotoPanel(); - ~LLSocialPhotoPanel(); + LLSocialPhotoPanel(); + ~LLSocialPhotoPanel(); - BOOL postBuild(); - void draw(); + BOOL postBuild(); + void draw(); - LLSnapshotLivePreview* getPreviewView(); - void onVisibilityChange(const LLSD& new_visibility); - void onClickNewSnapshot(); - void onSend(); + LLSnapshotLivePreview* getPreviewView(); + void onVisibilityChange(const LLSD& new_visibility); + void onClickNewSnapshot(); + void onSend(); + bool onConnectedToFacebook(const LLSD& data, LLPointer<LLImageFormatted> image, const std::string& caption); - void updateControls(); - void updateResolution(BOOL do_update); - void checkAspectRatio(S32 index); - void setNeedRefresh(bool need); - LLUICtrl* getRefreshBtn(); + void updateControls(); + void updateResolution(BOOL do_update); + void checkAspectRatio(S32 index); + void setNeedRefresh(bool need); + LLUICtrl* getRefreshBtn(); private: - - LLHandle<LLView> mPreviewHandle; - - LLUICtrl * mSnapshotPanel; - LLUICtrl * mResolutionComboBox; - LLUICtrl * mRefreshBtn; - LLUICtrl * mRefreshLabel; - LLUICtrl * mSucceessLblPanel; - LLUICtrl * mFailureLblPanel; - LLUICtrl * mThumbnailPlaceholder; - LLUICtrl * mCaptionTextBox; - LLUICtrl * mLocationCheckbox; - LLUICtrl * mPostButton; - - bool mNeedRefresh; + LLHandle<LLView> mPreviewHandle; + + LLUICtrl * mSnapshotPanel; + LLUICtrl * mResolutionComboBox; + LLUICtrl * mRefreshBtn; + LLUICtrl * mRefreshLabel; + LLUICtrl * mSucceessLblPanel; + LLUICtrl * mFailureLblPanel; + LLUICtrl * mThumbnailPlaceholder; + LLUICtrl * mCaptionTextBox; + LLUICtrl * mLocationCheckbox; + LLUICtrl * mPostButton; + + bool mNeedRefresh; }; class LLSocialCheckinPanel : public LLPanel @@ -94,6 +94,8 @@ public: BOOL postBuild(); void draw(); void onSend(); + bool onConnectedToFacebook(const LLSD& data, const std::string& location, const std::string& name, const std::string& description, const std::string& picture, const std::string& message); + private: std::string mMapUrl; LLPointer<LLViewerFetchedTexture> mMapTexture; diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp index bd4813f945..8c8cad0743 100755 --- a/indra/newview/llpanelpeople.cpp +++ b/indra/newview/llpanelpeople.cpp @@ -839,16 +839,36 @@ void LLPanelPeople::updateRecentList() mRecentList->setDirty(); } +bool LLPanelPeople::onConnectedToFacebook(const LLSD& data) +{ + if (data.get("enum").asInteger() == LLFacebookConnect::FB_CONNECTED) + { + LLEventPumps::instance().obtain("FacebookConnectState").stopListening("LLPanelPeople"); + + LLFacebookConnect::instance().loadFacebookFriends(); + } + + return false; +} + void LLPanelPeople::updateFacebookList(bool visible) { - if(visible) + if (visible) { LLFacebookConnect::instance().setContentUpdatedCallback(boost::bind(&LLPanelPeople::updateSuggestedFriendList, this)); if (mTryToConnectToFbc) - { + { // try to reconnect to facebook! - LLFacebookConnect::instance().getConnectionToFacebook(false, boost::bind(&LLFacebookConnect::loadFacebookFriends, &LLFacebookConnect::instance())); + if (LLFacebookConnect::instance().isConnected()) + { + LLFacebookConnect::instance().loadFacebookFriends(); + } + else + { + LLEventPumps::instance().obtain("FacebookConnectState").listen("LLPanelPeople", boost::bind(&LLPanelPeople::onConnectedToFacebook, this, _1)); + LLFacebookConnect::instance().checkConnectionToFacebook(); + } // don't try again mTryToConnectToFbc = false; diff --git a/indra/newview/llpanelpeople.h b/indra/newview/llpanelpeople.h index 666702a08c..c6ee7b8165 100755 --- a/indra/newview/llpanelpeople.h +++ b/indra/newview/llpanelpeople.h @@ -126,6 +126,8 @@ private: void onFriendListRefreshComplete(LLUICtrl*ctrl, const LLSD& param); + bool onConnectedToFacebook(const LLSD& data); + void setAccordionCollapsedByUser(LLUICtrl* acc_tab, bool collapsed); void setAccordionCollapsedByUser(const std::string& name, bool collapsed); bool isAccordionCollapsedByUser(LLUICtrl* acc_tab); |