aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloatertos.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llfloatertos.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llfloatertos.cpp')
-rw-r--r--linden/indra/newview/llfloatertos.cpp304
1 files changed, 304 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloatertos.cpp b/linden/indra/newview/llfloatertos.cpp
new file mode 100644
index 0000000..35b4531
--- /dev/null
+++ b/linden/indra/newview/llfloatertos.cpp
@@ -0,0 +1,304 @@
1/**
2 * @file llfloatertos.cpp
3 * @brief Terms of Service Agreement dialog
4 *
5 * Copyright (c) 2003-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llfloatertos.h"
31
32#include "llbutton.h"
33#include "llradiogroup.h"
34#include "llvfile.h"
35#include "lltextbox.h"
36#include "llviewertexteditor.h"
37#include "viewer.h"
38#include "llstartup.h"
39#include "message.h"
40#include "llagent.h"
41#include "llvieweruictrlfactory.h"
42#include "llviewerwindow.h"
43#include "llviewerstats.h"
44#include "llui.h"
45#include "llhttpclient.h"
46#include "llradiogroup.h"
47
48// static
49LLFloaterTOS* LLFloaterTOS::sInstance = NULL;
50
51// static
52LLFloaterTOS* LLFloaterTOS::show(ETOSType type, const std::string & message)
53{
54 if( !LLFloaterTOS::sInstance )
55 {
56 LLFloaterTOS::sInstance = new LLFloaterTOS(type, message);
57 }
58
59 if (type == TOS_TOS)
60 {
61 gUICtrlFactory->buildFloater(LLFloaterTOS::sInstance, "floater_tos.xml");
62 }
63 else
64 {
65 gUICtrlFactory->buildFloater(LLFloaterTOS::sInstance, "floater_critical.xml");
66 }
67
68 return LLFloaterTOS::sInstance;
69}
70
71
72LLFloaterTOS::LLFloaterTOS(ETOSType type, const std::string & message)
73: LLModalDialog( " ", 100, 100 ),
74 mType(type),
75 mMessage(message),
76 mWebBrowserWindowId( 0 ),
77 mLoadCompleteCount( 0 )
78{
79}
80
81// helper class that trys to download a URL from a web site and calls a method
82// on parent class indicating if the web server is working or not
83class LLIamHere : public LLHTTPClient::Responder
84{
85 private:
86 LLIamHere( LLFloaterTOS* parent ) :
87 mParent( parent )
88 {}
89
90 LLFloaterTOS* mParent;
91
92 public:
93
94 static boost::intrusive_ptr< LLIamHere > build( LLFloaterTOS* parent )
95 {
96 return boost::intrusive_ptr< LLIamHere >( new LLIamHere( parent ) );
97 };
98
99 virtual void setParent( LLFloaterTOS* parentIn )
100 {
101 mParent = parentIn;
102 };
103
104 virtual void result( const LLSD& content )
105 {
106 if ( mParent )
107 mParent->setSiteIsAlive( true );
108 };
109
110 virtual void error( U32 status, const std::string& reason )
111 {
112 if ( mParent )
113 mParent->setSiteIsAlive( false );
114 };
115};
116
117// this is global and not a class member to keep crud out of the header file
118namespace {
119 boost::intrusive_ptr< LLIamHere > gResponsePtr = 0;
120};
121
122BOOL LLFloaterTOS::postBuild()
123{
124 childSetAction("Continue", onContinue, this);
125 childSetAction("Cancel", onCancel, this);
126 childSetCommitCallback("tos_agreement", updateAgree, this);
127
128 // this displays the critical message
129 if ( mType != TOS_TOS )
130 {
131 LLTextEditor *Editor = LLUICtrlFactory::getTextEditorByName(this, "tos_text");
132 if (Editor)
133 {
134 Editor->setHandleEditKeysDirectly( TRUE );
135 Editor->setEnabled( FALSE );
136 Editor->setReadOnlyFgColor(LLColor4::white);
137 Editor->setWordWrap(TRUE);
138 Editor->setFocus(TRUE);
139 }
140 childSetValue("tos_text", LLSD(mMessage));
141 };
142
143 // this displays the critical message
144 if ( mType != TOS_TOS )
145 {
146 LLTextEditor *Editor = LLUICtrlFactory::getTextEditorByName(this, "tos_text");
147 if (Editor)
148 {
149 Editor->setHandleEditKeysDirectly( TRUE );
150 Editor->setEnabled( FALSE );
151 Editor->setReadOnlyFgColor(LLColor4::white);
152 Editor->setWordWrap(TRUE);
153 Editor->setFocus(TRUE);
154 }
155 childSetValue("tos_text", LLSD(mMessage));
156 };
157
158 #if LL_LIBXUL_ENABLED
159 // disable Agree to TOS radio button until the page has fully loaded
160 LLRadioGroup* tos_agreement = LLUICtrlFactory::getRadioGroupByName(this, "tos_agreement");
161 if ( tos_agreement )
162 {
163 tos_agreement->setEnabled( false );
164 };
165
166 LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(this, "tos_html");
167 if ( web_browser )
168 {
169 // start to observe it so we see navigate complete events
170 if ( web_browser )
171 {
172 web_browser->addObserver( this );
173 };
174
175 gResponsePtr = LLIamHere::build( this );
176 LLHTTPClient::get( childGetValue( "real_url" ).asString(), gResponsePtr );
177 };
178 #else
179 LLTextEditor *Editor = LLUICtrlFactory::getTextEditorByName(this, "tos_text");
180 if (Editor)
181 {
182 Editor->setHandleEditKeysDirectly( TRUE );
183 Editor->setEnabled( FALSE );
184 Editor->setReadOnlyFgColor(LLColor4::white);
185 Editor->setWordWrap(TRUE);
186 Editor->setFocus(TRUE);
187 }
188 childSetValue("tos_text", LLSD(mMessage));
189 #endif
190 return TRUE;
191}
192
193void LLFloaterTOS::setSiteIsAlive( bool alive )
194{
195 // only do this for TOS pages
196 if ( mType == TOS_TOS )
197 {
198#if LL_LIBXUL_ENABLED
199 LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(this, "tos_html");
200 // if the contents of the site was retrieved
201 if ( alive )
202 {
203 if ( web_browser )
204 {
205 // navigate to the "real" page
206 web_browser->navigateTo( childGetValue( "real_url" ).asString() );
207 };
208 }
209 else
210 {
211 // normally this is set when navigation to TOS page navigation completes (so you can't accept before TOS loads)
212 // but if the page is unavailable, we need to do this now
213 LLRadioGroup* tos_agreement = LLUICtrlFactory::getRadioGroupByName(this, "tos_agreement");
214 if ( tos_agreement )
215 {
216 tos_agreement->setEnabled( true );
217 };
218
219 if ( web_browser )
220 {
221 // hide browser control (revealing default text message)
222 web_browser->setVisible( FALSE );
223 };
224 };
225#endif // LL_LIBXUL_ENABLED
226 };
227}
228
229LLFloaterTOS::~LLFloaterTOS()
230{
231#if LL_LIBXUL_ENABLED
232 // stop obsaerving events
233 LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(this, "tos_html");
234 if ( web_browser )
235 {
236 web_browser->addObserver( this );
237 };
238#endif // LL_LIBXUL_ENABLED
239
240 // tell the responder we're not here anymore
241 if ( gResponsePtr )
242 gResponsePtr->setParent( 0 );
243
244 LLFloaterTOS::sInstance = NULL;
245}
246
247// virtual
248void LLFloaterTOS::draw()
249{
250 // draw children
251 LLModalDialog::draw();
252}
253
254// static
255void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata )
256{
257 LLFloaterTOS* self = (LLFloaterTOS*) userdata;
258 std::string agree = self->childGetValue("tos_agreement").asString();
259 self->childSetEnabled("Continue", (agree == "radio_agree") );
260}
261
262// static
263void LLFloaterTOS::onContinue( void* userdata )
264{
265 LLFloaterTOS* self = (LLFloaterTOS*) userdata;
266 llinfos << "User agrees with TOS." << llendl;
267 if (self->mType == TOS_TOS)
268 {
269 gAcceptTOS = TRUE;
270 }
271 else
272 {
273 gAcceptCriticalMessage = TRUE;
274 }
275 gStartupState++;
276 self->close(); // destroys this object
277}
278
279// static
280void LLFloaterTOS::onCancel( void* userdata )
281{
282 LLFloaterTOS* self = (LLFloaterTOS*) userdata;
283 llinfos << "User disagrees with TOS." << llendl;
284 gViewerWindow->alertXml("MustAgreeToLogIn", login_alert_done);
285 gStartupState = STATE_LOGIN_SHOW;
286 self->mLoadCompleteCount = 0; // reset counter for next time we come to TOS
287 self->close(); // destroys this object
288}
289
290//virtual
291void LLFloaterTOS::onNavigateComplete( const EventType& eventIn )
292{
293 // skip past the loading screen navigate complete
294 if ( ++mLoadCompleteCount == 2 )
295 {
296 llinfos << "NAVIGATE COMPLETE" << llendl;
297 // enable Agree to TOS radio button now that page has loaded
298 LLRadioGroup* tos_agreement = LLUICtrlFactory::getRadioGroupByName(this, "tos_agreement");
299 if ( tos_agreement )
300 {
301 tos_agreement->setEnabled( true );
302 };
303 };
304}