diff options
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llfloatersocial.cpp | 385 | ||||
-rw-r--r-- | indra/newview/llfloatersocial.h | 39 |
2 files changed, 214 insertions, 210 deletions
diff --git a/indra/newview/llfloatersocial.cpp b/indra/newview/llfloatersocial.cpp index 35761d5cc8..dfc9024d54 100644 --- a/indra/newview/llfloatersocial.cpp +++ b/indra/newview/llfloatersocial.cpp @@ -64,6 +64,10 @@ std::string get_map_url() return map_url; } +/////////////////////////// +//LLSocialStatusPanel////// +/////////////////////////// + LLSocialStatusPanel::LLSocialStatusPanel() : mMessageTextEditor(NULL), mPostStatusButton(NULL) @@ -108,12 +112,21 @@ void LLSocialStatusPanel::onSend() } } +/////////////////////////// +//LLSocialPhotoPanel/////// +/////////////////////////// + LLSocialPhotoPanel::LLSocialPhotoPanel() : +mSnapshotPanel(NULL), +mResolutionComboBox(NULL), mRefreshBtn(NULL), mRefreshLabel(NULL), mSucceessLblPanel(NULL), mFailureLblPanel(NULL), -mThumbnailPlaceholder(NULL) +mThumbnailPlaceholder(NULL), +mCaptionTextBox(NULL), +mLocationCheckbox(NULL), +mPostButton(NULL) { mCommitCallbackRegistrar.add("PostToFacebook.Send", boost::bind(&LLSocialPhotoPanel::onSend, this)); } @@ -129,179 +142,21 @@ LLSocialPhotoPanel::~LLSocialPhotoPanel() BOOL LLSocialPhotoPanel::postBuild() { setVisibleCallback(boost::bind(&LLSocialPhotoPanel::onVisibilityChange, this, _2)); - - mPostButton = getChild<LLUICtrl>("post_btn"); + + mSnapshotPanel = getChild<LLUICtrl>("snapshot_panel"); mResolutionComboBox = getChild<LLUICtrl>("resolution_combobox"); - mResolutionComboBox->setCommitCallback(boost::bind(&LLSocialPhotoPanel::onResolutionComboCommit, this)); + mResolutionComboBox->setCommitCallback(boost::bind(&LLSocialPhotoPanel::updateResolution, this, TRUE)); mRefreshBtn = getChild<LLUICtrl>("new_snapshot_btn"); childSetAction("new_snapshot_btn", boost::bind(&LLSocialPhotoPanel::onClickNewSnapshot, this)); mRefreshLabel = getChild<LLUICtrl>("refresh_lbl"); mSucceessLblPanel = getChild<LLUICtrl>("succeeded_panel"); mFailureLblPanel = getChild<LLUICtrl>("failed_panel"); mThumbnailPlaceholder = getChild<LLUICtrl>("thumbnail_placeholder"); - - return LLPanel::postBuild(); -} - -void LLSocialPhotoPanel::onResolutionComboCommit() -{ - LLFloaterSocial* instance = LLFloaterReg::findTypedInstance<LLFloaterSocial>("social"); - updateResolution(mResolutionComboBox, instance); -} - -void LLSocialPhotoPanel::onClickNewSnapshot() -{ - LLSnapshotLivePreview* previewp = static_cast<LLSnapshotLivePreview*>(mPreviewHandle.get()); - //LLFloaterSnapshot *view = (LLFloaterSnapshot *)data; - if (previewp /*&& view*/) - { - //view->impl.setStatus(Impl::STATUS_READY); - lldebugs << "updating snapshot" << llendl; - previewp->updateSnapshot(TRUE); - } -} - -void LLSocialPhotoPanel::updateResolution(LLUICtrl* ctrl, void* data, BOOL do_update) -{ - LLComboBox* combobox = (LLComboBox*)ctrl; - LLFloaterSnapshot *view = (LLFloaterSnapshot *)data; - - if (!view || !combobox) - { - llassert(view && combobox); - return; - } - - std::string sdstring = combobox->getSelectedValue(); - LLSD sdres; - std::stringstream sstream(sdstring); - LLSDSerialize::fromNotation(sdres, sstream, sdstring.size()); - - S32 width = sdres[0]; - S32 height = sdres[1]; - - LLSnapshotLivePreview * previewp = static_cast<LLSnapshotLivePreview *>(mPreviewHandle.get()); - if (previewp && combobox->getCurrentIndex() >= 0) - { - S32 original_width = 0 , original_height = 0 ; - previewp->getSize(original_width, original_height) ; - - if (width == 0 || height == 0) - { - // take resolution from current window size - lldebugs << "Setting preview res from window: " << gViewerWindow->getWindowWidthRaw() << "x" << gViewerWindow->getWindowHeightRaw() << llendl; - previewp->setSize(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw()); - } - else - { - // use the resolution from the selected pre-canned drop-down choice - lldebugs << "Setting preview res selected from combo: " << width << "x" << height << llendl; - previewp->setSize(width, height); - } - - checkAspectRatio(width); - - previewp->getSize(width, height); - - if(original_width != width || original_height != height) - { - previewp->setSize(width, height); - - // hide old preview as the aspect ratio could be wrong - lldebugs << "updating thumbnail" << llendl; - - previewp->updateSnapshot(FALSE, TRUE); - if(do_update) - { - lldebugs << "Will update controls" << llendl; - updateControls(); - setNeedRefresh(true); - } - } - - } -} - -void LLSocialPhotoPanel::setNeedRefresh(bool need) -{ - mRefreshLabel->setVisible(need); - mNeedRefresh = need; -} - -void LLSocialPhotoPanel::checkAspectRatio(S32 index) -{ - LLSnapshotLivePreview *previewp = getPreviewView() ; - - BOOL keep_aspect = FALSE; - - if (0 == index) // current window size - { - keep_aspect = TRUE; - } - else // predefined resolution - { - keep_aspect = FALSE; - } - - if (previewp) - { - previewp->mKeepAspectRatio = keep_aspect; - } -} - -LLSnapshotLivePreview* LLSocialPhotoPanel::getPreviewView() -{ - LLSnapshotLivePreview* previewp = (LLSnapshotLivePreview*)mPreviewHandle.get(); - return previewp; -} - -void LLSocialPhotoPanel::updateControls() -{ - LLSnapshotLivePreview* previewp = getPreviewView(); - BOOL got_bytes = previewp && previewp->getDataSize() > 0; - BOOL got_snap = previewp && previewp->getSnapshotUpToDate(); - LLSnapshotLivePreview::ESnapshotType shot_type = previewp->getSnapshotType(); - - // *TODO: Separate maximum size for Web images from postcards - lldebugs << "Is snapshot up-to-date? " << got_snap << llendl; - - LLLocale locale(LLLocale::USER_LOCALE); - std::string bytes_string; - if (got_snap) - { - LLResMgr::getInstance()->getIntegerString(bytes_string, (previewp->getDataSize()) >> 10 ); - } - - //getChild<LLUICtrl>("file_size_label")->setTextArg("[SIZE]", got_snap ? bytes_string : getString("unknown")); - getChild<LLUICtrl>("file_size_label")->setTextArg("[SIZE]", got_snap ? bytes_string : "unknown"); - getChild<LLUICtrl>("file_size_label")->setColor( - shot_type == LLSnapshotLivePreview::SNAPSHOT_POSTCARD - && got_bytes - && previewp->getDataSize() > MAX_POSTCARD_DATASIZE ? LLUIColor(LLColor4::red) : LLUIColorTable::instance().getColor( "LabelTextColor" )); - - LLComboBox* combo = getChild<LLComboBox>("resolution_combobox"); - LLFloaterSocial* instance = LLFloaterReg::findTypedInstance<LLFloaterSocial>("social"); - updateResolution(combo, instance, FALSE); -} - -void LLSocialPhotoPanel::onVisibilityChange(const LLSD& new_visibility) -{ - bool visible = new_visibility.asBoolean(); - if (visible && !mPreviewHandle.get()) - { - LLRect full_screen_rect = getRootView()->getRect(); - LLSnapshotLivePreview::Params p; - p.rect(full_screen_rect); - LLSnapshotLivePreview* previewp = new LLSnapshotLivePreview(p); - mPreviewHandle = previewp->getHandle(); - - previewp->setSnapshotType(previewp->SNAPSHOT_WEB); - previewp->setSnapshotFormat(LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG); - //previewp->setSnapshotQuality(98); - previewp->setThumbnailPlaceholderRect(getThumbnailPlaceholderRect()); + mCaptionTextBox = getChild<LLUICtrl>("caption"); + mLocationCheckbox = getChild<LLUICtrl>("add_location_cb"); + mPostButton = getChild<LLUICtrl>("post_btn"); - updateControls(); - } + return LLPanel::postBuild(); } void LLSocialPhotoPanel::draw() @@ -313,7 +168,7 @@ void LLSocialPhotoPanel::draw() if(previewp && previewp->getThumbnailImage()) { bool working = false; //impl.getStatus() == Impl::STATUS_WORKING; - const LLRect& thumbnail_rect = getThumbnailPlaceholderRect(); + const LLRect& thumbnail_rect = mThumbnailPlaceholder->getRect(); const S32 thumbnail_w = previewp->getThumbnailWidth(); const S32 thumbnail_h = previewp->getThumbnailHeight(); @@ -325,8 +180,7 @@ void LLSocialPhotoPanel::draw() S32 offset_x = thumbnail_rect.mLeft + local_offset_x; S32 offset_y = thumbnail_rect.mBottom + local_offset_y; - LLUICtrl * snapshot_panel = getChild<LLUICtrl>("snapshot_panel"); - snapshot_panel->localPointToOtherView(offset_x, offset_y, &offset_x, &offset_y, gFloaterView->getParentFloater(this)); + mSnapshotPanel->localPointToOtherView(offset_x, offset_y, &offset_x, &offset_y, getParentByType<LLFloater>()); gGL.matrixMode(LLRender::MM_MODELVIEW); // Apply floater transparency to the texture unless the floater is focused. @@ -373,20 +227,57 @@ void LLSocialPhotoPanel::draw() gGL.pushUIMatrix(); S32 x_pos; S32 y_pos; - snapshot_panel->localPointToOtherView(thumbnail_rect.mLeft, thumbnail_rect.mBottom, &x_pos, &y_pos, gFloaterView->getParentFloater(this)); - + mSnapshotPanel->localPointToOtherView(thumbnail_rect.mLeft, thumbnail_rect.mBottom, &x_pos, &y_pos, getParentByType<LLFloater>()); + LLUI::translate((F32) x_pos, (F32) y_pos); mThumbnailPlaceholder->draw(); gGL.popUIMatrix(); } - mPostButton->setEnabled(LLFacebookConnect::instance().isConnected()); + mPostButton->setEnabled(LLFacebookConnect::instance().isConnected()); +} + +LLSnapshotLivePreview* LLSocialPhotoPanel::getPreviewView() +{ + LLSnapshotLivePreview* previewp = (LLSnapshotLivePreview*)mPreviewHandle.get(); + return previewp; +} + +void LLSocialPhotoPanel::onVisibilityChange(const LLSD& new_visibility) +{ + bool visible = new_visibility.asBoolean(); + if (visible && !mPreviewHandle.get()) + { + LLRect full_screen_rect = getRootView()->getRect(); + LLSnapshotLivePreview::Params p; + p.rect(full_screen_rect); + LLSnapshotLivePreview* previewp = new LLSnapshotLivePreview(p); + mPreviewHandle = previewp->getHandle(); + + previewp->setSnapshotType(previewp->SNAPSHOT_WEB); + previewp->setSnapshotFormat(LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG); + //previewp->setSnapshotQuality(98); + previewp->setThumbnailPlaceholderRect(mThumbnailPlaceholder->getRect()); + + updateControls(); + } +} + +void LLSocialPhotoPanel::onClickNewSnapshot() +{ + LLSnapshotLivePreview* previewp = getPreviewView(); + if (previewp) + { + //setStatus(Impl::STATUS_READY); + lldebugs << "updating snapshot" << llendl; + previewp->updateSnapshot(TRUE); + } } void LLSocialPhotoPanel::onSend() { - std::string caption = getChild<LLUICtrl>("caption")->getValue().asString(); - bool add_location = getChild<LLUICtrl>("add_location_cb")->getValue().asBoolean(); + std::string caption = mCaptionTextBox->getValue().asString(); + bool add_location = mLocationCheckbox->getValue().asBoolean(); if (add_location) { @@ -399,7 +290,6 @@ void LLSocialPhotoPanel::onSend() } LLSnapshotLivePreview* previewp = getPreviewView(); - LLFacebookConnect::instance().sharePhoto(previewp->getFormattedImage(), caption); updateControls(); @@ -411,6 +301,122 @@ void LLSocialPhotoPanel::onSend() } } +void LLSocialPhotoPanel::updateControls() +{ + LLSnapshotLivePreview* previewp = getPreviewView(); + BOOL got_bytes = previewp && previewp->getDataSize() > 0; + BOOL got_snap = previewp && previewp->getSnapshotUpToDate(); + LLSnapshotLivePreview::ESnapshotType shot_type = previewp->getSnapshotType(); + + // *TODO: Separate maximum size for Web images from postcards + lldebugs << "Is snapshot up-to-date? " << got_snap << llendl; + + LLLocale locale(LLLocale::USER_LOCALE); + std::string bytes_string; + if (got_snap) + { + LLResMgr::getInstance()->getIntegerString(bytes_string, (previewp->getDataSize()) >> 10 ); + } + + //getChild<LLUICtrl>("file_size_label")->setTextArg("[SIZE]", got_snap ? bytes_string : getString("unknown")); <---uses localized string + getChild<LLUICtrl>("file_size_label")->setTextArg("[SIZE]", got_snap ? bytes_string : "unknown"); + getChild<LLUICtrl>("file_size_label")->setColor( + shot_type == LLSnapshotLivePreview::SNAPSHOT_POSTCARD + && got_bytes + && previewp->getDataSize() > MAX_POSTCARD_DATASIZE ? LLUIColor(LLColor4::red) : LLUIColorTable::instance().getColor( "LabelTextColor" )); + + updateResolution(FALSE); +} + +void LLSocialPhotoPanel::updateResolution(BOOL do_update) +{ + LLComboBox* combobox = static_cast<LLComboBox *>(mResolutionComboBox); + + std::string sdstring = combobox->getSelectedValue(); + LLSD sdres; + std::stringstream sstream(sdstring); + LLSDSerialize::fromNotation(sdres, sstream, sdstring.size()); + + S32 width = sdres[0]; + S32 height = sdres[1]; + + LLSnapshotLivePreview * previewp = static_cast<LLSnapshotLivePreview *>(mPreviewHandle.get()); + if (previewp && combobox->getCurrentIndex() >= 0) + { + S32 original_width = 0 , original_height = 0 ; + previewp->getSize(original_width, original_height) ; + + if (width == 0 || height == 0) + { + // take resolution from current window size + lldebugs << "Setting preview res from window: " << gViewerWindow->getWindowWidthRaw() << "x" << gViewerWindow->getWindowHeightRaw() << llendl; + previewp->setSize(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw()); + } + else + { + // use the resolution from the selected pre-canned drop-down choice + lldebugs << "Setting preview res selected from combo: " << width << "x" << height << llendl; + previewp->setSize(width, height); + } + + checkAspectRatio(width); + + previewp->getSize(width, height); + + if(original_width != width || original_height != height) + { + previewp->setSize(width, height); + + // hide old preview as the aspect ratio could be wrong + lldebugs << "updating thumbnail" << llendl; + + previewp->updateSnapshot(FALSE, TRUE); + if(do_update) + { + lldebugs << "Will update controls" << llendl; + updateControls(); + setNeedRefresh(true); + } + } + + } +} + +void LLSocialPhotoPanel::checkAspectRatio(S32 index) +{ + LLSnapshotLivePreview *previewp = getPreviewView() ; + + BOOL keep_aspect = FALSE; + + if (0 == index) // current window size + { + keep_aspect = TRUE; + } + else // predefined resolution + { + keep_aspect = FALSE; + } + + if (previewp) + { + previewp->mKeepAspectRatio = keep_aspect; + } +} + +void LLSocialPhotoPanel::setNeedRefresh(bool need) +{ + mRefreshLabel->setVisible(need); + mNeedRefresh = need; +} + +LLUICtrl* LLSocialPhotoPanel::getRefreshBtn() +{ + return mRefreshBtn; +} + +//////////////////////// +//LLSocialCheckinPanel// +//////////////////////// LLSocialCheckinPanel::LLSocialCheckinPanel() : mMapUrl(""), @@ -501,6 +507,9 @@ void LLSocialCheckinPanel::onSend() } } +//////////////////////// +//LLFloaterSocial/////// +//////////////////////// LLFloaterSocial::LLFloaterSocial(const LLSD& key) : LLFloater(key), mSocialPhotoPanel(NULL) @@ -522,15 +531,9 @@ BOOL LLFloaterSocial::postBuild() return LLFloater::postBuild(); } -/*virtual*/ -void LLFloaterSocial::draw() -{ - LLFloater::draw(); -} - void LLFloaterSocial::onOpen(const LLSD& key) { - LLSnapshotLivePreview* preview = static_cast<LLSnapshotLivePreview *>(mSocialPhotoPanel->mPreviewHandle.get()); + LLSnapshotLivePreview* preview = mSocialPhotoPanel->getPreviewView(); if(preview) { lldebugs << "opened, updating snapshot" << llendl; @@ -541,14 +544,13 @@ void LLFloaterSocial::onOpen(const LLSD& key) // static void LLFloaterSocial::preUpdate() { - // FIXME: duplicated code LLFloaterSocial* instance = LLFloaterReg::findTypedInstance<LLFloaterSocial>("social"); if (instance) { - // Disable the send/post/save buttons until snapshot is ready. + //Will set file size text to 'unknown' instance->mSocialPhotoPanel->updateControls(); - // Force hiding the "Refresh to save" hint because we know we've just started refresh. + //Hides the refresh text instance->mSocialPhotoPanel->setNeedRefresh(false); } } @@ -556,21 +558,22 @@ void LLFloaterSocial::preUpdate() // static void LLFloaterSocial::postUpdate() { - // FIXME: duplicated code LLFloaterSocial* instance = LLFloaterReg::findTypedInstance<LLFloaterSocial>("social"); if (instance) { - // Enable the send/post/save buttons. + //Will set the file size text instance->mSocialPhotoPanel->updateControls(); - // We've just done refresh. + //Hides the refresh text instance->mSocialPhotoPanel->setNeedRefresh(false); // The refresh button is initially hidden. We show it after the first update, - // i.e. when preview appears. - if (!instance->mSocialPhotoPanel->mRefreshBtn->getVisible()) + // i.e. after snapshot is taken + LLUICtrl * refresh_button = instance->mSocialPhotoPanel->getRefreshBtn(); + + if (!refresh_button->getVisible()) { - instance->mSocialPhotoPanel->mRefreshBtn->setVisible(true); + refresh_button->setVisible(true); } } diff --git a/indra/newview/llfloatersocial.h b/indra/newview/llfloatersocial.h index 6675a990f4..95ba688430 100644 --- a/indra/newview/llfloatersocial.h +++ b/indra/newview/llfloatersocial.h @@ -50,37 +50,40 @@ private: class LLSocialPhotoPanel : public LLPanel { - public: +public: LLSocialPhotoPanel(); ~LLSocialPhotoPanel(); BOOL postBuild(); void draw(); - void onSend(); - const LLRect& getThumbnailPlaceholderRect() { return mThumbnailPlaceholder->getRect(); } - void onResolutionComboCommit(); + LLSnapshotLivePreview* getPreviewView(); + void onVisibilityChange(const LLSD& new_visibility); void onClickNewSnapshot(); + void onSend(); - LLHandle<LLView> mPreviewHandle; - - void updateResolution(LLUICtrl* ctrl, void* data, BOOL do_update = TRUE); - void setNeedRefresh(bool need); + void updateControls(); + void updateResolution(BOOL do_update); void checkAspectRatio(S32 index); - LLSnapshotLivePreview* getPreviewView(); + void setNeedRefresh(bool need); + LLUICtrl* getRefreshBtn(); - void updateControls(); - void onVisibilityChange(const LLSD& new_visibility); +private: + + LLHandle<LLView> mPreviewHandle; + LLUICtrl * mSnapshotPanel; LLUICtrl * mResolutionComboBox; - LLUICtrl *mRefreshBtn, *mRefreshLabel; - LLUICtrl *mSucceessLblPanel, *mFailureLblPanel; - LLUICtrl* mThumbnailPlaceholder; + LLUICtrl * mRefreshBtn; + LLUICtrl * mRefreshLabel; + LLUICtrl * mSucceessLblPanel; + LLUICtrl * mFailureLblPanel; + LLUICtrl * mThumbnailPlaceholder; + LLUICtrl * mCaptionTextBox; + LLUICtrl * mLocationCheckbox; + LLUICtrl * mPostButton; bool mNeedRefresh; - -private: - LLUICtrl* mPostButton; }; class LLSocialCheckinPanel : public LLPanel @@ -108,8 +111,6 @@ public: BOOL postBuild(); void onCancel(); void onOpen(const LLSD& key); - /*virtual*/ void draw(); - static void preUpdate(); static void postUpdate(); |