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 "viewer.h"
00042 #include "llstartup.h"
00043 #include "message.h"
00044 #include "llagent.h"
00045 #include "llvieweruictrlfactory.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                 gUICtrlFactory->buildFloater(LLFloaterTOS::sInstance, "floater_tos.xml");
00066         }
00067         else
00068         {
00069                 gUICtrlFactory->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 = LLUICtrlFactory::getTextEditorByName(this, "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 #if LL_LIBXUL_ENABLED
00149         // disable Agree to TOS radio button until the page has fully loaded
00150         LLRadioGroup* tos_agreement = LLUICtrlFactory::getRadioGroupByName(this, "tos_agreement");
00151         if ( tos_agreement )
00152         {
00153                 tos_agreement->setEnabled( false );
00154         };
00155 
00156         // hide the SL text widget if we're displaying TOS with using a browser widget.
00157         LLTextEditor *editor = LLUICtrlFactory::getTextEditorByName(this, "tos_text");
00158         if ( editor )
00159         {
00160                 editor->setVisible( FALSE );
00161         };
00162 
00163         LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(this, "tos_html");
00164         if ( web_browser )
00165         {
00166                 // start to observe it so we see navigate complete events
00167                 if ( web_browser )
00168                 {
00169                         web_browser->addObserver( this );
00170                 };
00171 
00172                 gResponsePtr = LLIamHere::build( this );
00173                 LLHTTPClient::get( childGetValue( "real_url" ).asString(), gResponsePtr );
00174         };
00175 #else
00176         LLTextEditor *Editor = LLUICtrlFactory::getTextEditorByName(this, "tos_text");
00177         if (Editor)
00178         {
00179                 Editor->setHandleEditKeysDirectly( TRUE );
00180                 Editor->setEnabled( FALSE );
00181                 Editor->setReadOnlyFgColor(LLColor4::white);
00182                 Editor->setWordWrap(TRUE);
00183                 Editor->setFocus(TRUE);
00184         }
00185         childSetValue("tos_text", LLSD(mMessage));      
00186 #endif
00187 
00188         return TRUE;
00189 }
00190 
00191 void LLFloaterTOS::setSiteIsAlive( bool alive )
00192 {
00193         // only do this for TOS pages
00194         if ( mType == TOS_TOS )
00195         {
00196 #if LL_LIBXUL_ENABLED
00197                 LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(this, "tos_html");
00198                 // if the contents of the site was retrieved
00199                 if ( alive )
00200                 {
00201                         if ( web_browser )
00202                         {
00203                                 // navigate to the "real" page 
00204                                 web_browser->navigateTo( childGetValue( "real_url" ).asString() );
00205                         };
00206                 }
00207                 else
00208                 {
00209                         // normally this is set when navigation to TOS page navigation completes (so you can't accept before TOS loads)
00210                         // but if the page is unavailable, we need to do this now
00211                         LLRadioGroup* tos_agreement = LLUICtrlFactory::getRadioGroupByName(this, "tos_agreement");
00212                         if ( tos_agreement )
00213                         {
00214                                 tos_agreement->setEnabled( true );
00215                         };
00216 
00217                         if ( web_browser )
00218                         {
00219                                 // hide browser control (revealing default text message)
00220                                 web_browser->setVisible( FALSE );
00221                         };
00222                 };
00223 #endif // LL_LIBXUL_ENABLED
00224         };
00225 }
00226 
00227 LLFloaterTOS::~LLFloaterTOS()
00228 {
00229 #if LL_LIBXUL_ENABLED
00230         // stop obsaerving events
00231         LLWebBrowserCtrl* web_browser = LLUICtrlFactory::getWebBrowserCtrlByName(this, "tos_html");
00232         if ( web_browser )
00233         {
00234                 web_browser->addObserver( this );               
00235         };
00236 #endif // LL_LIBXUL_ENABLED
00237 
00238         // tell the responder we're not here anymore
00239         if ( gResponsePtr )
00240                 gResponsePtr->setParent( 0 );
00241 
00242         LLFloaterTOS::sInstance = NULL;
00243 }
00244 
00245 // virtual
00246 void LLFloaterTOS::draw()
00247 {
00248         // draw children
00249         LLModalDialog::draw();
00250 }
00251 
00252 // static
00253 void LLFloaterTOS::updateAgree(LLUICtrl*, void* userdata )
00254 {
00255         LLFloaterTOS* self = (LLFloaterTOS*) userdata;
00256         std::string agree = self->childGetValue("tos_agreement").asString();
00257         self->childSetEnabled("Continue", (agree == "radio_agree") );
00258 }
00259 
00260 // static
00261 void LLFloaterTOS::onContinue( void* userdata )
00262 {
00263         LLFloaterTOS* self = (LLFloaterTOS*) userdata;
00264         llinfos << "User agrees with TOS." << llendl;
00265         if (self->mType == TOS_TOS)
00266         {
00267                 gAcceptTOS = TRUE;
00268         }
00269         else
00270         {
00271                 gAcceptCriticalMessage = TRUE;
00272         }
00273 
00274         // Testing TOS dialog
00275         #if ! LL_RELEASE_FOR_DOWNLOAD           
00276         if ( LLStartUp::getStartupState() == STATE_LOGIN_WAIT )
00277         {
00278                 LLStartUp::setStartupState( STATE_LOGIN_SHOW );
00279         }
00280         else 
00281         #endif
00282 
00283         LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT );                    // Go back and finish authentication
00284         self->close(); // destroys this object
00285 }
00286 
00287 // static
00288 void LLFloaterTOS::onCancel( void* userdata )
00289 {
00290         LLFloaterTOS* self = (LLFloaterTOS*) userdata;
00291         llinfos << "User disagrees with TOS." << llendl;
00292         gViewerWindow->alertXml("MustAgreeToLogIn", login_alert_done);
00293         LLStartUp::setStartupState( STATE_LOGIN_SHOW );
00294         self->mLoadCompleteCount = 0;  // reset counter for next time we come to TOS
00295         self->close(); // destroys this object
00296 }
00297 
00298 //virtual 
00299 void LLFloaterTOS::onNavigateComplete( const EventType& eventIn )
00300 {
00301         // skip past the loading screen navigate complete
00302         if ( ++mLoadCompleteCount == 2 )
00303         {
00304                 llinfos << "NAVIGATE COMPLETE" << llendl;
00305                 // enable Agree to TOS radio button now that page has loaded
00306                 LLRadioGroup* tos_agreement = LLUICtrlFactory::getRadioGroupByName(this, "tos_agreement");
00307                 if ( tos_agreement )
00308                 {
00309                         tos_agreement->setEnabled( true );
00310                 };
00311         };
00312 }

Generated on Thu Jul 1 06:08:36 2010 for Second Life Viewer by  doxygen 1.4.7