diff options
author | Merov Linden <merov@lindenlab.com> | 2013-12-04 21:17:04 -0800 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2013-12-04 21:17:04 -0800 |
commit | 0dfc7f6145b0c179ee66dbc7539b7c3d9a68cc37 (patch) | |
tree | 7cce8cf627609aec932923679fd811a671bd3b9c /indra/newview/llfloatertwitter.cpp | |
parent | f5b356a7d4b51fbf509926295cb38d3a1e8442e3 (diff) | |
parent | 5a23bf50bcee13a5841f680b13ca480753d367a1 (diff) |
Pull merge from lindenlab/viewer-acme
Diffstat (limited to 'indra/newview/llfloatertwitter.cpp')
-rw-r--r-- | indra/newview/llfloatertwitter.cpp | 116 |
1 files changed, 87 insertions, 29 deletions
diff --git a/indra/newview/llfloatertwitter.cpp b/indra/newview/llfloatertwitter.cpp index 06d0fb5542..18a1fcbba9 100644 --- a/indra/newview/llfloatertwitter.cpp +++ b/indra/newview/llfloatertwitter.cpp @@ -65,7 +65,9 @@ mResolutionComboBox(NULL), mRefreshBtn(NULL), mWorkingLabel(NULL), mThumbnailPlaceholder(NULL), +mStatusCounterLabel(NULL), mStatusTextBox(NULL), +mLocationCheckbox(NULL), mPhotoCheckbox(NULL), mPostButton(NULL) { @@ -91,8 +93,12 @@ BOOL LLTwitterPhotoPanel::postBuild() mRefreshBtn = getChild<LLUICtrl>("new_snapshot_btn"); mWorkingLabel = getChild<LLUICtrl>("working_lbl"); mThumbnailPlaceholder = getChild<LLUICtrl>("thumbnail_placeholder"); + mStatusCounterLabel = getChild<LLUICtrl>("status_counter_label"); mStatusTextBox = getChild<LLUICtrl>("photo_status"); + mLocationCheckbox = getChild<LLUICtrl>("add_location_cb"); + mLocationCheckbox->setCommitCallback(boost::bind(&LLTwitterPhotoPanel::onAddLocationToggled, this)); mPhotoCheckbox = getChild<LLUICtrl>("add_photo_cb"); + mPhotoCheckbox->setCommitCallback(boost::bind(&LLTwitterPhotoPanel::onAddPhotoToggled, this)); mPostButton = getChild<LLUICtrl>("post_photo_btn"); mCancelButton = getChild<LLUICtrl>("cancel_photo_btn"); @@ -109,30 +115,12 @@ void LLTwitterPhotoPanel::draw() mStatusTextBox->setEnabled(no_ongoing_connection); mResolutionComboBox->setEnabled(no_ongoing_connection && mPhotoCheckbox->getValue().asBoolean()); mRefreshBtn->setEnabled(no_ongoing_connection && mPhotoCheckbox->getValue().asBoolean()); + mLocationCheckbox->setEnabled(no_ongoing_connection); mPhotoCheckbox->setEnabled(no_ongoing_connection); + bool add_location = mLocationCheckbox->getValue().asBoolean(); bool add_photo = mPhotoCheckbox->getValue().asBoolean(); - - // Restrict the status text length to Twitter's character limit - LLTextEditor* status_text_box = dynamic_cast<LLTextEditor*>(mStatusTextBox); - if (status_text_box) - { - int max_status_length = add_photo ? 100 : 140; - status_text_box->setMaxTextLength(max_status_length); - if (!add_photo) - { - if (mOldStatusText.length() > status_text_box->getText().length() && status_text_box->getText() == mOldStatusText.substr(0, status_text_box->getText().length())) - { - status_text_box->setText(mOldStatusText); - } - mOldStatusText = ""; - } - if (status_text_box->getText().length() > max_status_length) - { - mOldStatusText = status_text_box->getText(); - status_text_box->setText(mOldStatusText.substr(0, max_status_length)); - } - } + updateStatusTextLength(false); // Display the preview if one is available if (previewp && previewp->getThumbnailImage()) @@ -169,7 +157,7 @@ void LLTwitterPhotoPanel::draw() mWorkingLabel->setVisible(!(previewp && previewp->getSnapshotUpToDate())); // Enable Post if we have a preview to send and no on going connection being processed - mPostButton->setEnabled(no_ongoing_connection && ((add_photo && previewp && previewp->getSnapshotUpToDate()) || !mStatusTextBox->getValue().asString().empty())); + mPostButton->setEnabled(no_ongoing_connection && ((add_photo && previewp && previewp->getSnapshotUpToDate()) || add_location || !mStatusTextBox->getValue().asString().empty())); // Draw the rest of the panel on top of it LLPanel::draw(); @@ -213,6 +201,18 @@ void LLTwitterPhotoPanel::onVisibilityChange(const LLSD& new_visibility) } } +void LLTwitterPhotoPanel::onAddLocationToggled() +{ + bool add_location = mLocationCheckbox->getValue().asBoolean(); + updateStatusTextLength(!add_location); +} + +void LLTwitterPhotoPanel::onAddPhotoToggled() +{ + bool add_photo = mPhotoCheckbox->getValue().asBoolean(); + updateStatusTextLength(!add_photo); +} + void LLTwitterPhotoPanel::onClickNewSnapshot() { LLSnapshotLivePreview* previewp = getPreviewView(); @@ -261,6 +261,26 @@ void LLTwitterPhotoPanel::sendPhoto() { // Get the status text std::string status = mStatusTextBox->getValue().asString(); + + // Add the location if required + bool add_location = mLocationCheckbox->getValue().asBoolean(); + if (add_location) + { + // Get the SLURL for the location + LLSLURL slurl; + LLAgentUI::buildSLURL(slurl); + std::string slurl_string = slurl.getSLURLString(); + + // Add query parameters so Google Analytics can track incoming clicks! + slurl_string += DEFAULT_PHOTO_QUERY_PARAMETERS; + + // Add it to the status (pretty crude, but we don't have a better option with photos) + if (status.empty()) + status = slurl_string; + else + status = status + " " + slurl_string; + } + // Add the photo if required bool add_photo = mPhotoCheckbox->getValue().asBoolean(); @@ -292,6 +312,44 @@ void LLTwitterPhotoPanel::clearAndClose() } } +void LLTwitterPhotoPanel::updateStatusTextLength(BOOL restore_old_status_text) +{ + bool add_location = mLocationCheckbox->getValue().asBoolean(); + bool add_photo = mPhotoCheckbox->getValue().asBoolean(); + + // Restrict the status text length to Twitter's character limit + LLTextEditor* status_text_box = dynamic_cast<LLTextEditor*>(mStatusTextBox); + if (status_text_box) + { + int max_status_length = 140 - (add_location ? 40 : 0) - (add_photo ? 40 : 0); + status_text_box->setMaxTextLength(max_status_length); + if (restore_old_status_text) + { + if (mOldStatusText.length() > status_text_box->getText().length() && status_text_box->getText() == mOldStatusText.substr(0, status_text_box->getText().length())) + { + status_text_box->setText(mOldStatusText); + } + if (mOldStatusText.length() <= max_status_length) + { + mOldStatusText = ""; + } + } + if (status_text_box->getText().length() > max_status_length) + { + if (mOldStatusText.length() < status_text_box->getText().length() || status_text_box->getText() != mOldStatusText.substr(0, status_text_box->getText().length())) + { + mOldStatusText = status_text_box->getText(); + } + status_text_box->setText(mOldStatusText.substr(0, max_status_length)); + } + + // Update the status character counter + int characters_remaining = max_status_length - status_text_box->getText().length(); + mStatusCounterLabel->setValue(characters_remaining); + } + +} + void LLTwitterPhotoPanel::updateControls() { LLSnapshotLivePreview* previewp = getPreviewView(); @@ -564,7 +622,7 @@ void LLTwitterAccountPanel::onDisconnect() //////////////////////// LLFloaterTwitter::LLFloaterTwitter(const LLSD& key) : LLFloater(key), - mSocialPhotoPanel(NULL), + mTwitterPhotoPanel(NULL), mStatusErrorText(NULL), mStatusLoadingText(NULL), mStatusLoadingIndicator(NULL) @@ -580,7 +638,7 @@ void LLFloaterTwitter::onCancel() BOOL LLFloaterTwitter::postBuild() { // Keep tab of the Photo Panel - mSocialPhotoPanel = static_cast<LLTwitterPhotoPanel*>(getChild<LLUICtrl>("panel_twitter_photo")); + mTwitterPhotoPanel = static_cast<LLTwitterPhotoPanel*>(getChild<LLUICtrl>("panel_twitter_photo")); // Connection status widgets mStatusErrorText = getChild<LLTextBox>("connection_error_text"); mStatusLoadingText = getChild<LLTextBox>("connection_loading_text"); @@ -590,14 +648,14 @@ BOOL LLFloaterTwitter::postBuild() void LLFloaterTwitter::showPhotoPanel() { - LLTabContainer* parent = dynamic_cast<LLTabContainer*>(mSocialPhotoPanel->getParent()); + LLTabContainer* parent = dynamic_cast<LLTabContainer*>(mTwitterPhotoPanel->getParent()); if (!parent) { llwarns << "Cannot find panel container" << llendl; return; } - parent->selectTabPanel(mSocialPhotoPanel); + parent->selectTabPanel(mTwitterPhotoPanel); } // static @@ -607,7 +665,7 @@ void LLFloaterTwitter::preUpdate() if (instance) { //Will set file size text to 'unknown' - instance->mSocialPhotoPanel->updateControls(); + instance->mTwitterPhotoPanel->updateControls(); } } @@ -618,11 +676,11 @@ void LLFloaterTwitter::postUpdate() if (instance) { //Will set the file size text - instance->mSocialPhotoPanel->updateControls(); + instance->mTwitterPhotoPanel->updateControls(); // The refresh button is initially hidden. We show it after the first update, // i.e. after snapshot is taken - LLUICtrl * refresh_button = instance->mSocialPhotoPanel->getRefreshBtn(); + LLUICtrl * refresh_button = instance->mTwitterPhotoPanel->getRefreshBtn(); if (!refresh_button->getVisible()) { |