llfloatertos.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloatertos.h"
00035 
00036 #include "llbutton.h"
00037 #include "llradiogroup.h"
00038 #include "llvfile.h"
00039 #include "lltextbox.h"
00040 #include "llviewertexteditor.h"
00041 #include "llappviewer.h"
00042 #include "llstartup.h"
00043 #include "message.h"
00044 #include "llagent.h"
00045 #include "lluictrlfactory.h"
00046 #include "llviewerwindow.h"
00047 #include "llviewerstats.h"
00048 #include "llui.h"
00049 #include "llhttpclient.h"
00050 #include "llradiogroup.h"
00051 
00052 // static 
00053 LLFloaterTOS* LLFloaterTOS::sInstance = NULL;
00054 
00055 // static
00056 LLFloaterTOS* LLFloaterTOS::show(ETOSType type, const std::string & message)
00057 {
00058         if( !LLFloaterTOS::sInstance )
00059         {
00060                 LLFloaterTOS::sInstance = new LLFloaterTOS(type, message);
00061         }
00062 
00063         if (type == TOS_TOS)
00064         {
00065                 LLUICtrlFactory::getInstance()->buildFloater(LLFloaterTOS::sInstance, "floater_tos.xml");
00066         }
00067         else
00068         {
00069                 LLUICtrlFactory::getInstance()->buildFloater(LLFloaterTOS::sInstance, "floater_critical.xml");
00070         }
00071 
00072         return LLFloaterTOS::sInstance;
00073 }
00074 
00075 
00076 LLFloaterTOS::LLFloaterTOS(ETOSType type, const std::string & message)
00077 :       LLModalDialog( " ", 100, 100 ),
00078         mType(type),
00079         mMessage(message),
00080         mWebBrowserWindowId( 0 ),
00081         mLoadCompleteCount( 0 )
00082 {
00083 }
00084 
00085 // helper class that trys to download a URL from a web site and calls a method 
00086 // on parent class indicating if the web server is working or not
00087 class LLIamHere : public LLHTTPClient::Responder
00088 {
00089         private:
00090                 LLIamHere( LLFloaterTOS* parent ) :
00091                    mParent( parent )
00092                 {}
00093 
00094                 LLFloaterTOS* mParent;
00095 
00096         public:
00097 
00098                 static boost::intrusive_ptr< LLIamHere > build( LLFloaterTOS* parent )
00099                 {
00100                         return boost::intrusive_ptr< LLIamHere >( new LLIamHere( parent ) );
00101                 };
00102                 
00103                 virtual void  setParent( LLFloaterTOS* parentIn )
00104                 {
00105                         mParent = parentIn;
00106                 };
00107                 
00108                 virtual void result( const LLSD& content )
00109                 {
00110                         if ( mParent )
00111                                 mParent->setSiteIsAlive( true );
00112                 };
00113 
00114                 virtual void error( U32 status, const std::string& reason )
00115                 {
00116                         if ( mParent )
00117                                 mParent->setSiteIsAlive( false );
00118                 };
00119 };
00120 
00121 // this is global and not a class member to keep crud out of the header file
00122 namespace {
00123         boost::intrusive_ptr< LLIamHere > gResponsePtr = 0;
00124 };
00125 
00126 BOOL LLFloaterTOS::postBuild()
00127 {       
00128         childSetAction("Continue", onContinue, this);
00129         childSetAction("Cancel", onCancel, this);
00130         childSetCommitCallback("tos_agreement", updateAgree, this);
00131 
00132         if ( mType != TOS_TOS )
00133         {
00134                 // this displays the critical message
00135                 LLTextEditor *Editor = getChild<LLTextEditor>("tos_text");
00136                 if (Editor)
00137                 {
00138                         Editor->setHandleEditKeysDirectly( TRUE );
00139                         Editor->setEnabled( FALSE );
00140                         Editor->setReadOnlyFgColor(LLColor4::white);
00141                         Editor->setWordWrap(TRUE);
00142                         Editor->setFocus(TRUE);
00143                 }
00144                 childSetValue("tos_text", LLSD(mMessage));
00145                 return TRUE;
00146         }
00147 
00148         // disable Agree to TOS radio button until the page has fully loaded
00149         LLRadioGroup* tos_agreement = getChild<LLRadioGroup>("tos_agreement");
00150         if ( tos_agreement )
00151         {
00152                 tos_agreement->setEnabled( false );
00153         };
00154 
00155         // hide the SL text widget if we're displaying TOS with using a browser widget.
00156         LLTextEditor *editor = getChild<LLTextEditor>("tos_text");
00157         if ( editor )
00158         {
00159                 editor->setVisible( FALSE );
00160         };
00161 
00162         LLWebBrowserCtrl* web_browser = getChild<LLWebBrowserCtrl>("tos_html");
00163         if ( web_browser )
00164         {
00165                 // start to observe it so we see navigate complete events
00166                 if ( web_browser )
00167                 {
00168                         web_browser->addObserver( this );
00169                 };
00170 
00171                 gResponsePtr = LLIamHere::build( this );
00172                 LLHTTPClient::get( getString( "real_url" ), gResponsePtr );
00173         };
00174 
00175         return TRUE;
00176 }
00177 
00178 void LLFloaterTOS::setSiteIsAlive( bool alive )
00179 {
00180         // only do this for TOS pages
00181         if ( mType == TOS_TOS )
00182         {
00183                 LLWebBrowserCtrl* web_browser = getChild<LLWebBrowserCtrl>("tos_html");
00184                 // if the contents of the site was retrieved
00185                 if ( alive )
00186                 {
00187                         if ( web_browser )
00188                         {
00189                                 // navigate to the "real" page 
00190                                 web_browser->navigateTo( getString( "real_url" ) );
00191                         };
00192                 }
00193                 else
00194                 {
00195                         // normally this is set when navigation to TOS page navigation completes (so you can't accept before TOS loads)
00196                         // but if the page is unavailable, we need to do this now
00197                         LLRadioGroup* tos_agreement = getChild<LLRadioGroup>("tos_agreement");
00198                         if ( tos_agreement )
00199                         {
00200                                 tos_agreement->setEnabled( true );
00201                         };
00202 
00203                         if ( web_browser )
00204                         {
00205                                 // hide browser control (revealing default text message)
00206                                 web_browser->setVisible( FALSE );
00207                         };
00208                 };
00209         };
00210 }
00211 
00212 LLFloaterTOS::~LLFloaterTOS()
00213 {
00214         // stop obsaerving events
00215         LLWebBrowserCtrl* web_browser = getChild<LLWebBrowserCtrl>("tos_html");
00216         if ( web_browser )
00217         {
00218                 web_browser->addObserver( this );               
00219         };
00220 
00221         // tell the responder we're not here anymore
00222         if ( gResponsePtr )
00223                 gResponsePtr->setParent( 0 );
00224 
00225         LLFloaterTOS::sInstance = NULL;
00226 }
00227 
00228 // virtual
00229 void LLFloaterTOS::draw()
00230 {
00231         // draw children
00232         LLModalDialog::draw();
00233 }
00234 
00235 // static
00236 void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata )
00237 {
00238         LLFloaterTOS* self = (LLFloaterTOS*) userdata;
00239         std::string agree = self->childGetValue("tos_agreement").asString();
00240         self->childSetEnabled("Continue", (agree == "radio_agree") );
00241 }
00242 
00243 // static
00244 void LLFloaterTOS::onContinue( void* userdata )
00245 {
00246         LLFloaterTOS* self = (LLFloaterTOS*) userdata;
00247         llinfos << "User agrees with TOS." << llendl;
00248         if (self->mType == TOS_TOS)
00249         {
00250                 gAcceptTOS = TRUE;
00251         }
00252         else
00253         {
00254                 gAcceptCriticalMessage = TRUE;
00255         }
00256 
00257         // Testing TOS dialog
00258         #if ! LL_RELEASE_FOR_DOWNLOAD           
00259         if ( LLStartUp::getStartupState() == STATE_LOGIN_WAIT )
00260         {
00261                 LLStartUp::setStartupState( STATE_LOGIN_SHOW );
00262         }
00263         else 
00264         #endif
00265 
00266         LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT );                    // Go back and finish authentication
00267         self->close(); // destroys this object
00268 }
00269 
00270 // static
00271 void LLFloaterTOS::onCancel( void* userdata )
00272 {
00273         LLFloaterTOS* self = (LLFloaterTOS*) userdata;
00274         llinfos << "User disagrees with TOS." << llendl;
00275         gViewerWindow->alertXml("MustAgreeToLogIn", login_alert_done);
00276         LLStartUp::setStartupState( STATE_LOGIN_SHOW );
00277         self->mLoadCompleteCount = 0;  // reset counter for next time we come to TOS
00278         self->close(); // destroys this object
00279 }
00280 
00281 //virtual 
00282 void LLFloaterTOS::onNavigateComplete( const EventType& eventIn )
00283 {
00284         // skip past the loading screen navigate complete
00285         if ( ++mLoadCompleteCount == 2 )
00286         {
00287                 llinfos << "NAVIGATE COMPLETE" << llendl;
00288                 // enable Agree to TOS radio button now that page has loaded
00289                 LLRadioGroup* tos_agreement = getChild<LLRadioGroup>("tos_agreement");
00290                 if ( tos_agreement )
00291                 {
00292                         tos_agreement->setEnabled( true );
00293                 };
00294         };
00295 }

Generated on Fri May 16 08:33:32 2008 for SecondLife by  doxygen 1.5.5