summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterurlentry.cpp
diff options
context:
space:
mode:
authorJosh Bell <josh@lindenlab.com>2008-02-14 01:45:59 +0000
committerJosh Bell <josh@lindenlab.com>2008-02-14 01:45:59 +0000
commit98fd90ddd6595f2ee7e626c14117f51def621ec5 (patch)
tree9a9caf8bffa53b753fe850f445bd133195e9bb03 /indra/newview/llfloaterurlentry.cpp
parent89d938efe371645756240da72f4c359c36985060 (diff)
svn merge -r 79730:79944 svn+ssh://svn.lindenlab.com/svn/linden/branches/parcel_media/sl-parcelmedia-6 --> release
QAR-275 Parcel Media Sam made me do it.
Diffstat (limited to 'indra/newview/llfloaterurlentry.cpp')
-rw-r--r--indra/newview/llfloaterurlentry.cpp268
1 files changed, 268 insertions, 0 deletions
diff --git a/indra/newview/llfloaterurlentry.cpp b/indra/newview/llfloaterurlentry.cpp
new file mode 100644
index 0000000000..1ad9e0577c
--- /dev/null
+++ b/indra/newview/llfloaterurlentry.cpp
@@ -0,0 +1,268 @@
+/**
+ * @file llfloaterurlentry.cpp
+ * @brief LLFloaterURLEntry class implementation
+ *
+ * Copyright (c) 2002-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llfloaterurlentry.h"
+
+#include "llpanellandmedia.h"
+
+// project includes
+#include "llcombobox.h"
+#include "llurlhistory.h"
+#include "llvieweruictrlfactory.h"
+#include "llwindow.h"
+#include "llviewerwindow.h"
+
+static LLFloaterURLEntry* sInstance = NULL;
+
+// Move this to its own file.
+// helper class that tries to download a URL from a web site and calls a method
+// on the Panel Land Media and to discover the MIME type
+class LLMediaTypeResponder : public LLHTTPClient::Responder
+{
+public:
+ LLMediaTypeResponder( LLViewHandle parent ) :
+ mParent( parent )
+ {}
+
+ LLViewHandle mParent;
+
+
+ virtual void completedHeader(U32 status, const std::string& reason, const LLSD& content)
+ {
+ std::string media_type = content["content-type"].asString();
+ std::string::size_type idx1 = media_type.find_first_of(";");
+ std::string mime_type = media_type.substr(0, idx1);
+ completeAny(status, mime_type);
+ }
+
+ virtual void error( U32 status, const std::string& reason )
+ {
+ completeAny(status, "none/none");
+ }
+
+ void completeAny(U32 status, const std::string& mime_type)
+ {
+ LLFloaterURLEntry* floater_url_entry =
+ (LLFloaterURLEntry*)LLFloater::getFloaterByHandle(mParent);
+ if ( floater_url_entry )
+ floater_url_entry->headerFetchComplete( status, mime_type );
+ }
+};
+
+//-----------------------------------------------------------------------------
+// LLFloaterURLEntry()
+//-----------------------------------------------------------------------------
+LLFloaterURLEntry::LLFloaterURLEntry(LLViewHandle parent)
+ :
+ LLFloater(),
+ mPanelLandMediaHandle(parent)
+{
+ gUICtrlFactory->buildFloater(this, "floater_url_entry.xml");
+
+ mMediaURLEdit = LLUICtrlFactory::getComboBoxByName(this, "media_entry");
+
+ // Cancel button
+ childSetAction("cancel_btn", onBtnCancel, this);
+
+ // Cancel button
+ childSetAction("clear_btn", onBtnClear, this);
+
+ // clear media list button
+ LLSD parcel_history = LLURLHistory::getURLHistory("parcel");
+ bool enable_clear_button = parcel_history.size() > 0 ? true : false;
+ childSetEnabled( "clear_btn", enable_clear_button );
+
+ // OK button
+ childSetAction("ok_btn", onBtnOK, this);
+
+ setDefaultBtn("ok_btn");
+ buildURLHistory();
+
+ sInstance = this;
+}
+
+//-----------------------------------------------------------------------------
+// ~LLFloaterURLEntry()
+//-----------------------------------------------------------------------------
+LLFloaterURLEntry::~LLFloaterURLEntry()
+{
+ sInstance = NULL;
+}
+
+void LLFloaterURLEntry::buildURLHistory()
+{
+ LLCtrlListInterface* url_list = childGetListInterface("media_entry");
+ if (url_list)
+ {
+ url_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
+ }
+
+ // Get all of the entries in the "parcel" collection
+ LLSD parcel_history = LLURLHistory::getURLHistory("parcel");
+
+ LLSD::array_iterator iter_history =
+ parcel_history.beginArray();
+ LLSD::array_iterator end_history =
+ parcel_history.endArray();
+ for(; iter_history != end_history; ++iter_history)
+ {
+ url_list->addSimpleElement((*iter_history).asString());
+ }
+}
+
+void LLFloaterURLEntry::headerFetchComplete(U32 status, const std::string& mime_type)
+{
+ LLPanelLandMedia* panel_media = (LLPanelLandMedia*)LLPanel::getPanelByHandle(mPanelLandMediaHandle);
+ if (panel_media)
+ {
+ // status is ignored for now -- error = "none/none"
+ panel_media->setMediaType(mime_type);
+ panel_media->setMediaURL(mMediaURLEdit->getValue().asString());
+ }
+ // Decrement the cursor
+ getWindow()->decBusyCount();
+ childSetVisible("loading_label", false);
+ close();
+}
+
+// static
+LLViewHandle LLFloaterURLEntry::show(LLViewHandle parent)
+{
+ if (sInstance)
+ {
+ sInstance->open();
+ }
+ else
+ {
+ sInstance = new LLFloaterURLEntry(parent);
+ }
+ sInstance->updateFromLandMediaPanel();
+ return sInstance->getHandle();
+}
+
+void LLFloaterURLEntry::updateFromLandMediaPanel()
+{
+ LLPanelLandMedia* panel_media = (LLPanelLandMedia*)LLPanel::getPanelByHandle(mPanelLandMediaHandle);
+ if (panel_media)
+ {
+ std::string media_url = panel_media->getMediaURL();
+ addURLToCombobox(media_url);
+ }
+}
+
+bool LLFloaterURLEntry::addURLToCombobox(const std::string& media_url)
+{
+ if(! mMediaURLEdit->setSimple( media_url ) && ! media_url.empty())
+ {
+ mMediaURLEdit->add( media_url );
+ mMediaURLEdit->setSimple( media_url );
+ return true;
+ }
+
+ // URL was not added for whatever reason (either it was empty or already existed)
+ return false;
+}
+
+// static
+//-----------------------------------------------------------------------------
+// onBtnOK()
+//-----------------------------------------------------------------------------
+void LLFloaterURLEntry::onBtnOK( void* userdata )
+{
+ LLFloaterURLEntry *self =(LLFloaterURLEntry *)userdata;
+
+ std::string media_url = self->mMediaURLEdit->getValue().asString();
+ self->mMediaURLEdit->remove(media_url);
+ LLURLHistory::removeURL("parcel", media_url);
+ if(self->addURLToCombobox(media_url))
+ {
+ // Add this url to the parcel collection
+ LLURLHistory::addURL("parcel", media_url);
+ }
+
+ // leading whitespace causes problems with the MIME-type detection so strip it
+ LLString::trim( media_url );
+
+ // First check the URL scheme
+ LLURI url(media_url);
+ std::string scheme = url.scheme();
+
+ // We assume that an empty scheme is an http url, as this is how we will treat it.
+ if(scheme == "")
+ {
+ scheme = "http";
+ }
+
+ // Discover the MIME type only for "http" scheme.
+ if(scheme == "http")
+ {
+ LLHTTPClient::getHeaderOnly( media_url,
+ new LLMediaTypeResponder(self->getHandle()));
+ }
+ else
+ {
+ self->headerFetchComplete(0, scheme);
+ }
+
+ // Grey the buttons until we get the header response
+ self->childSetEnabled("ok_btn", false);
+ self->childSetEnabled("cancel_btn", false);
+ self->childSetEnabled("media_entry", false);
+
+ // show progress bar here?
+ getWindow()->incBusyCount();
+ self->childSetVisible("loading_label", true);
+}
+
+// static
+//-----------------------------------------------------------------------------
+// onBtnCancel()
+//-----------------------------------------------------------------------------
+void LLFloaterURLEntry::onBtnCancel( void* userdata )
+{
+ LLFloaterURLEntry *self =(LLFloaterURLEntry *)userdata;
+ self->close();
+}
+
+// static
+//-----------------------------------------------------------------------------
+// onBtnClear()
+//-----------------------------------------------------------------------------
+void LLFloaterURLEntry::onBtnClear( void* userdata )
+{
+ gViewerWindow->alertXml( "ConfirmClearMediaUrlList", callback_clear_url_list, userdata );
+}
+
+void LLFloaterURLEntry::callback_clear_url_list(S32 option, void* userdata)
+{
+ if ( option == 0 ) // YES
+ {
+ LLFloaterURLEntry *self =(LLFloaterURLEntry *)userdata;
+
+ if ( self )
+ {
+ // clear saved list
+ LLCtrlListInterface* url_list = self->childGetListInterface("media_entry");
+ if ( url_list )
+ {
+ url_list->operateOnAll( LLCtrlListInterface::OP_DELETE );
+ }
+
+ // clear current contents of combo box
+ self->mMediaURLEdit->clear();
+
+ // clear stored version of list
+ LLURLHistory::clear("parcel");
+
+ // cleared the list so disable Clear button
+ self->childSetEnabled( "clear_btn", false );
+ }
+ }
+}