aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterurlentry.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llfloaterurlentry.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/llfloaterurlentry.cpp')
-rw-r--r--linden/indra/newview/llfloaterurlentry.cpp293
1 files changed, 293 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterurlentry.cpp b/linden/indra/newview/llfloaterurlentry.cpp
new file mode 100644
index 0000000..b2cc37f
--- /dev/null
+++ b/linden/indra/newview/llfloaterurlentry.cpp
@@ -0,0 +1,293 @@
1/**
2 * @file llfloaterurlentry.cpp
3 * @brief LLFloaterURLEntry class implementation
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "llviewerprecompiledheaders.h"
33
34#include "llfloaterurlentry.h"
35
36#include "llpanellandmedia.h"
37
38// project includes
39#include "llcombobox.h"
40#include "llurlhistory.h"
41#include "llvieweruictrlfactory.h"
42#include "llwindow.h"
43#include "llviewerwindow.h"
44
45static LLFloaterURLEntry* sInstance = NULL;
46
47// Move this to its own file.
48// helper class that tries to download a URL from a web site and calls a method
49// on the Panel Land Media and to discover the MIME type
50class LLMediaTypeResponder : public LLHTTPClient::Responder
51{
52public:
53 LLMediaTypeResponder( const LLHandle<LLFloater> parent ) :
54 mParent( parent )
55 {}
56
57 LLHandle<LLFloater> mParent;
58
59
60 virtual void completedHeader(U32 status, const std::string& reason, const LLSD& content)
61 {
62 std::string media_type = content["content-type"].asString();
63 std::string::size_type idx1 = media_type.find_first_of(";");
64 std::string mime_type = media_type.substr(0, idx1);
65 completeAny(status, mime_type);
66 }
67
68 virtual void error( U32 status, const std::string& reason )
69 {
70 completeAny(status, "none/none");
71 }
72
73 void completeAny(U32 status, const std::string& mime_type)
74 {
75 // Set empty type to none/none. Empty string is reserved for legacy parcels
76 // which have no mime type set.
77 std::string resolved_mime_type = ! mime_type.empty() ? mime_type : "none/none";
78 LLFloaterURLEntry* floater_url_entry = (LLFloaterURLEntry*)mParent.get();
79 if ( floater_url_entry )
80 floater_url_entry->headerFetchComplete( status, resolved_mime_type );
81 }
82};
83
84//-----------------------------------------------------------------------------
85// LLFloaterURLEntry()
86//-----------------------------------------------------------------------------
87LLFloaterURLEntry::LLFloaterURLEntry(LLHandle<LLPanel> parent)
88 :
89 LLFloater(),
90 mPanelLandMediaHandle(parent)
91{
92 gUICtrlFactory->buildFloater(this, "floater_url_entry.xml");
93
94 mMediaURLEdit = LLUICtrlFactory::getComboBoxByName(this, "media_entry");
95
96 // Cancel button
97 childSetAction("cancel_btn", onBtnCancel, this);
98
99 // Cancel button
100 childSetAction("clear_btn", onBtnClear, this);
101
102 // clear media list button
103 LLSD parcel_history = LLURLHistory::getURLHistory("parcel");
104 bool enable_clear_button = parcel_history.size() > 0 ? true : false;
105 childSetEnabled( "clear_btn", enable_clear_button );
106
107 // OK button
108 childSetAction("ok_btn", onBtnOK, this);
109
110 setDefaultBtn("ok_btn");
111 buildURLHistory();
112
113 sInstance = this;
114}
115
116//-----------------------------------------------------------------------------
117// ~LLFloaterURLEntry()
118//-----------------------------------------------------------------------------
119LLFloaterURLEntry::~LLFloaterURLEntry()
120{
121 sInstance = NULL;
122}
123
124void LLFloaterURLEntry::buildURLHistory()
125{
126 LLCtrlListInterface* url_list = childGetListInterface("media_entry");
127 if (url_list)
128 {
129 url_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
130 }
131
132 // Get all of the entries in the "parcel" collection
133 LLSD parcel_history = LLURLHistory::getURLHistory("parcel");
134
135 LLSD::array_iterator iter_history =
136 parcel_history.beginArray();
137 LLSD::array_iterator end_history =
138 parcel_history.endArray();
139 for(; iter_history != end_history; ++iter_history)
140 {
141 url_list->addSimpleElement((*iter_history).asString());
142 }
143}
144
145void LLFloaterURLEntry::headerFetchComplete(U32 status, const std::string& mime_type)
146{
147 LLPanelLandMedia* panel_media = (LLPanelLandMedia*)mPanelLandMediaHandle.get();
148 if (panel_media)
149 {
150 // status is ignored for now -- error = "none/none"
151 panel_media->setMediaType(mime_type);
152 panel_media->setMediaURL(mMediaURLEdit->getValue().asString());
153 }
154 // Decrement the cursor
155 getWindow()->decBusyCount();
156 childSetVisible("loading_label", false);
157 close();
158}
159
160// static
161LLHandle<LLFloater> LLFloaterURLEntry::show(LLHandle<LLPanel> parent)
162{
163 if (sInstance)
164 {
165 sInstance->open();
166 }
167 else
168 {
169 sInstance = new LLFloaterURLEntry(parent);
170 }
171 sInstance->updateFromLandMediaPanel();
172 return sInstance->getHandle();
173}
174
175void LLFloaterURLEntry::updateFromLandMediaPanel()
176{
177 LLPanelLandMedia* panel_media = (LLPanelLandMedia*)mPanelLandMediaHandle.get();
178 if (panel_media)
179 {
180 std::string media_url = panel_media->getMediaURL();
181 addURLToCombobox(media_url);
182 }
183}
184
185bool LLFloaterURLEntry::addURLToCombobox(const std::string& media_url)
186{
187 if(! mMediaURLEdit->setSimple( media_url ) && ! media_url.empty())
188 {
189 mMediaURLEdit->add( media_url );
190 mMediaURLEdit->setSimple( media_url );
191 return true;
192 }
193
194 // URL was not added for whatever reason (either it was empty or already existed)
195 return false;
196}
197
198// static
199//-----------------------------------------------------------------------------
200// onBtnOK()
201//-----------------------------------------------------------------------------
202void LLFloaterURLEntry::onBtnOK( void* userdata )
203{
204 LLFloaterURLEntry *self =(LLFloaterURLEntry *)userdata;
205
206 std::string media_url = self->mMediaURLEdit->getValue().asString();
207 self->mMediaURLEdit->remove(media_url);
208 LLURLHistory::removeURL("parcel", media_url);
209 if(self->addURLToCombobox(media_url))
210 {
211 // Add this url to the parcel collection
212 LLURLHistory::addURL("parcel", media_url);
213 }
214
215 // leading whitespace causes problems with the MIME-type detection so strip it
216 LLString::trim( media_url );
217
218 // First check the URL scheme
219 LLURI url(media_url);
220 std::string scheme = url.scheme();
221
222 // We assume that an empty scheme is an http url, as this is how we will treat it.
223 if(scheme == "")
224 {
225 scheme = "http";
226 }
227
228 // Discover the MIME type only for "http" scheme.
229 if(scheme == "http")
230 {
231 LLHTTPClient::getHeaderOnly( media_url,
232 new LLMediaTypeResponder(self->getHandle()));
233 }
234 else
235 {
236 self->headerFetchComplete(0, scheme);
237 }
238
239 // Grey the buttons until we get the header response
240 self->childSetEnabled("ok_btn", false);
241 self->childSetEnabled("cancel_btn", false);
242 self->childSetEnabled("media_entry", false);
243
244 // show progress bar here?
245 getWindow()->incBusyCount();
246 self->childSetVisible("loading_label", true);
247}
248
249// static
250//-----------------------------------------------------------------------------
251// onBtnCancel()
252//-----------------------------------------------------------------------------
253void LLFloaterURLEntry::onBtnCancel( void* userdata )
254{
255 LLFloaterURLEntry *self =(LLFloaterURLEntry *)userdata;
256 self->close();
257}
258
259// static
260//-----------------------------------------------------------------------------
261// onBtnClear()
262//-----------------------------------------------------------------------------
263void LLFloaterURLEntry::onBtnClear( void* userdata )
264{
265 gViewerWindow->alertXml( "ConfirmClearMediaUrlList", callback_clear_url_list, userdata );
266}
267
268void LLFloaterURLEntry::callback_clear_url_list(S32 option, void* userdata)
269{
270 if ( option == 0 ) // YES
271 {
272 LLFloaterURLEntry *self =(LLFloaterURLEntry *)userdata;
273
274 if ( self )
275 {
276 // clear saved list
277 LLCtrlListInterface* url_list = self->childGetListInterface("media_entry");
278 if ( url_list )
279 {
280 url_list->operateOnAll( LLCtrlListInterface::OP_DELETE );
281 }
282
283 // clear current contents of combo box
284 self->mMediaURLEdit->clear();
285
286 // clear stored version of list
287 LLURLHistory::clear("parcel");
288
289 // cleared the list so disable Clear button
290 self->childSetEnabled( "clear_btn", false );
291 }
292 }
293}