llfloaterhtmlhelp.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloaterhtmlhelp.h"
00035 
00036 #include "llparcel.h"
00037 #include "lluictrlfactory.h"
00038 #include "llwebbrowserctrl.h"
00039 #include "llviewerwindow.h"
00040 #include "llviewercontrol.h"
00041 #include "llviewerparcelmgr.h"
00042 #include "llweb.h"
00043 #include "llui.h"
00044 #include "roles_constants.h"
00045 
00046 #include "llurlhistory.h"
00047 #include "llwebbrowserctrl.h"
00048 #include "llviewermedia.h"
00049 #include "llviewerparcelmedia.h"
00050 #include "llcombobox.h"
00051 
00052 
00053 LLFloaterMediaBrowser::LLFloaterMediaBrowser(const LLSD& media_data)
00054 {
00055         LLUICtrlFactory::getInstance()->buildFloater(this, "floater_media_browser.xml");
00056 }
00057 
00058 void LLFloaterMediaBrowser::draw()
00059 {
00060         childSetEnabled("go", !mAddressCombo->getValue().asString().empty());
00061         LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
00062         if(parcel)
00063         {
00064                 childSetVisible("parcel_owner_controls", LLViewerParcelMgr::isParcelModifiableByAgent(parcel, GP_LAND_CHANGE_MEDIA));
00065                 childSetEnabled("assign", !mAddressCombo->getValue().asString().empty());
00066         }
00067         LLFloater::draw();
00068 }
00069 
00070 BOOL LLFloaterMediaBrowser::postBuild()
00071 {
00072         mBrowser = getChild<LLWebBrowserCtrl>("browser");
00073         mBrowser->addObserver(this);
00074 
00075         mAddressCombo = getChild<LLComboBox>("address");
00076         mAddressCombo->setCommitCallback(onEnterAddress);
00077         mAddressCombo->setCallbackUserData(this);
00078 
00079         childSetAction("back", onClickBack, this);
00080         childSetAction("forward", onClickForward, this);
00081         childSetAction("reload", onClickRefresh, this);
00082         childSetAction("go", onClickGo, this);
00083         childSetAction("close", onClickClose, this);
00084         childSetAction("open_browser", onClickOpenWebBrowser, this);
00085         childSetAction("assign", onClickAssign, this);
00086 
00087         buildURLHistory();
00088         return TRUE;
00089 }
00090 
00091 void LLFloaterMediaBrowser::buildURLHistory()
00092 {
00093         LLCtrlListInterface* url_list = childGetListInterface("address");
00094         if (url_list)
00095         {
00096                 url_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
00097         }
00098 
00099         // Get all of the entries in the "parcel" collection
00100         LLSD parcel_history = LLURLHistory::getURLHistory("browser");
00101 
00102         LLSD::array_iterator iter_history =
00103                 parcel_history.beginArray();
00104         LLSD::array_iterator end_history =
00105                 parcel_history.endArray();
00106         for(; iter_history != end_history; ++iter_history)
00107         {
00108                 std::string url = (*iter_history).asString();
00109                 if(! url.empty())
00110                         url_list->addSimpleElement(url);
00111         }
00112 }
00113 
00114 void LLFloaterMediaBrowser::onClose(bool app_quitting)
00115 {
00116         //setVisible(FALSE);
00117         destroy();
00118 }
00119 
00120 void LLFloaterMediaBrowser::onLocationChange( const EventType& eventIn )
00121 {
00122         // hitting the refresh button will navigate to same URL, so don't add to address history
00123         mCurrentURL = eventIn.getStringValue();
00124         std::string::size_type string_start = mCurrentURL.find("://");
00125         LLString truncated_url;
00126         if ((string_start == std::string::npos) || (1)) // NOTE: this conditional is forced true to disable truncation DEV-9834
00127         {
00128                 truncated_url = mCurrentURL;
00129         }
00130         else
00131         {
00132                 truncated_url = mCurrentURL.substr(string_start + 3);
00133         }
00134         // redirects will navigate momentarily to about:blank, don't add to history
00135         if (truncated_url != "about:blank")
00136         {
00137                 mAddressCombo->remove(truncated_url);
00138                 mAddressCombo->add(truncated_url, ADD_SORTED);
00139                 mAddressCombo->selectByValue(truncated_url);
00140 
00141                 // Serialize url history
00142                 LLURLHistory::removeURL("browser", truncated_url);
00143                 LLURLHistory::addURL("browser", truncated_url);
00144         }
00145         childSetEnabled("back", mBrowser->canNavigateBack());
00146         childSetEnabled("forward", mBrowser->canNavigateForward());
00147         childSetEnabled("reload", TRUE);
00148 }
00149 
00150 LLFloaterMediaBrowser* LLFloaterMediaBrowser::showInstance(const LLSD& media_url)
00151 {
00152         LLFloaterMediaBrowser* floaterp = LLUISingleton<LLFloaterMediaBrowser, VisibilityPolicy<LLFloater> >::showInstance(media_url);
00153 
00154         floaterp->openMedia(media_url.asString());
00155         return floaterp;
00156 }
00157 
00158 //static 
00159 void LLFloaterMediaBrowser::onEnterAddress(LLUICtrl* ctrl, void* user_data)
00160 {
00161         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00162         self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
00163 }
00164 
00165 //static 
00166 void LLFloaterMediaBrowser::onClickRefresh(void* user_data)
00167 {
00168         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00169 
00170         self->mAddressCombo->remove(0);
00171         self->mBrowser->navigateTo(self->mCurrentURL);
00172 }
00173 
00174 //static 
00175 void LLFloaterMediaBrowser::onClickForward(void* user_data)
00176 {
00177         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00178 
00179         self->mBrowser->navigateForward();
00180 }
00181 
00182 //static 
00183 void LLFloaterMediaBrowser::onClickBack(void* user_data)
00184 {
00185         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00186 
00187         self->mBrowser->navigateBack();
00188 }
00189 
00190 //static 
00191 void LLFloaterMediaBrowser::onClickGo(void* user_data)
00192 {
00193         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00194 
00195         self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
00196 }
00197 
00198 //static 
00199 void LLFloaterMediaBrowser::onClickClose(void* user_data)
00200 {
00201         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00202 
00203         self->close();
00204 }
00205 
00206 //static 
00207 void LLFloaterMediaBrowser::onClickOpenWebBrowser(void* user_data)
00208 {
00209         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00210 
00211         std::string url = self->mCurrentURL.empty() ? 
00212                 self->mBrowser->getHomePageUrl() :
00213                 self->mCurrentURL;
00214         LLWeb::loadURLExternal(url);
00215 }
00216 
00217 void LLFloaterMediaBrowser::onClickAssign(void* user_data)
00218 {
00219         LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
00220 
00221         LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
00222         if (!parcel)
00223         {
00224                 return;
00225         }
00226         std::string media_url = self->mAddressCombo->getValue().asString();
00227         LLString::trim(media_url);
00228 
00229         parcel->setMediaURL(media_url.c_str());
00230         parcel->setMediaType("text/html");
00231 
00232         // Send current parcel data upstream to server 
00233         LLViewerParcelMgr::getInstance()->sendParcelPropertiesUpdate( parcel, true );
00234         // now check for video
00235         LLViewerParcelMedia::update( parcel );
00236 
00237 
00238 }
00239 
00240 void LLFloaterMediaBrowser::openMedia(const std::string& media_url)
00241 {
00242         mBrowser->setHomePageUrl(media_url);
00243         mBrowser->navigateTo(media_url);
00244 }
00245 
00246 LLViewerHtmlHelp gViewerHtmlHelp;
00247 
00248 class LLFloaterHtmlHelp :
00249         public LLFloater,
00250         public LLWebBrowserCtrlObserver
00251 {
00252 public:
00253         LLFloaterHtmlHelp(std::string start_url, std::string title);
00254         virtual ~LLFloaterHtmlHelp();
00255         
00256         virtual void onClose( bool app_quitting );
00257         virtual void draw();
00258         
00259         static void show(std::string url, std::string title);
00260         static void onClickBack( void* data );
00261         static void onClickHome( void* data );
00262         static void onClickForward( void* data );
00263         static void onClickClose( void* data );
00264         
00265         // browser observer impls
00266         virtual void onStatusTextChange( const EventType& eventIn );
00267         virtual void onLocationChange( const EventType& eventIn );
00268         
00269         // used for some stats logging - will be removed at some point
00270         static BOOL sFloaterOpened;
00271 
00272         static void onClickF1HelpLoadURL(S32 option, void* userdata);
00273 
00274 protected:
00275         LLWebBrowserCtrl* mWebBrowser;
00276         static LLFloaterHtmlHelp* sInstance;
00277         LLButton* mBackButton;
00278         LLButton* mForwardButton;
00279         LLButton* mCloseButton;
00280         LLTextBox* mStatusText;
00281         LLString mStatusTextContents;
00282         LLString mCurrentUrl;
00283 };
00284 
00285 LLFloaterHtmlHelp* LLFloaterHtmlHelp::sInstance = 0;
00286 
00287 BOOL LLFloaterHtmlHelp::sFloaterOpened = FALSE;
00288 
00290 //
00291 LLFloaterHtmlHelp::LLFloaterHtmlHelp(std::string start_url, std::string title)
00292 :       LLFloater( "HTML Help" ),
00293         mWebBrowser( 0 ),
00294         mStatusTextContents( "" ),
00295         mCurrentUrl( "" )
00296 {
00297         sInstance = this;
00298                 
00299         // create floater from its XML definition
00300         LLUICtrlFactory::getInstance()->buildFloater( this, "floater_html_help.xml" );
00301                 
00302         childSetAction("back_btn", onClickBack, this);
00303         childSetAction("home_btn", onClickHome, this);
00304         childSetAction("forward_btn", onClickForward, this);
00305         
00306         if (!title.empty())
00307         {
00308                 setTitle(title);
00309         }
00310 
00311         mWebBrowser = getChild<LLWebBrowserCtrl>("html_help_browser" );
00312         if ( mWebBrowser )
00313         {
00314                 // observe browser control events
00315                 mWebBrowser->addObserver( this );
00316 
00317                 if (start_url != "")
00318                 {
00319                         mWebBrowser->navigateTo( start_url );
00320                 }
00321                 else
00322                 {
00323                         // if the last page we were at before the client was closed is valid, go there and
00324                         // override what is in the XML file
00325                         // (not when the window was closed - it's only ever hidden - not closed)
00326                         LLString lastPageUrl = gSavedSettings.getString( "HtmlHelpLastPage" );
00327                         if ( lastPageUrl != "" )
00328                         {
00329                                 mWebBrowser->navigateTo( lastPageUrl );
00330                         };
00331                 }
00332         };
00333 }
00334 
00336 //
00337 LLFloaterHtmlHelp::~LLFloaterHtmlHelp()
00338 {
00339         // stop observing browser events
00340         if ( mWebBrowser )
00341         {
00342                 mWebBrowser->remObserver( this );
00343         };
00344 
00345         // save position of floater
00346         gSavedSettings.setRect( "HtmlHelpRect", getRect() );
00347 
00348         // save the location we were at when SL closed 
00349         gSavedSettings.setString( "HtmlHelpLastPage", mCurrentUrl );
00350 
00351         sInstance = 0;
00352 }
00353 
00355 // virtual 
00356 void LLFloaterHtmlHelp::draw()
00357 {
00358         // enable/disable buttons depending on state
00359         if ( mWebBrowser )
00360         {
00361                 bool enable_back = mWebBrowser->canNavigateBack();      
00362                 childSetEnabled( "back_btn", enable_back );
00363 
00364                 bool enable_forward = mWebBrowser->canNavigateForward();        
00365                 childSetEnabled( "forward_btn", enable_forward );
00366         };
00367 
00368         LLFloater::draw();
00369 }
00370 
00372 //
00373 void LLFloaterHtmlHelp::show(std::string url, std::string title)
00374 {
00375     gViewerWindow->alertXml("ClickOpenF1Help", onClickF1HelpLoadURL, (void*) NULL);
00376 
00377         // switching this out for the moment - will come back later
00378         // want it still to be compiled so not using comments of #if 0
00379         if ( false )
00380         {
00381                 sFloaterOpened = true;
00382 
00383                 if ( sInstance )
00384                 {
00385                         if (sInstance->mWebBrowser)
00386                         {
00387                                 sInstance->mWebBrowser->navigateTo(url);
00388                         }
00389                         sInstance->setVisibleAndFrontmost();
00390                         return;
00391                 }
00392 
00393                 LLFloaterHtmlHelp* self = new LLFloaterHtmlHelp(url, title);
00394 
00395                 // reposition floater from saved settings
00396                 LLRect rect = gSavedSettings.getRect( "HtmlHelpRect" );
00397                 self->reshape( rect.getWidth(), rect.getHeight(), FALSE );
00398                 self->setRect( rect );
00399         };
00400 }
00401 
00402 // static 
00403 void LLFloaterHtmlHelp::onClickF1HelpLoadURL(S32 option, void* userdata)
00404 {
00405         if (option == 0)
00406         {
00407                 // choose HELP url based on selected language - default to english language support page
00408                 LLString lang = LLUI::sConfigGroup->getString("Language");
00409 
00410                 // this sucks but there isn't a way to grab an arbitrary string from an XML file
00411                 // (using llcontroldef strings causes problems if string don't exist)
00412                 LLString help_url( "http://secondlife.com/support" );
00413                 if ( lang == "ja" )
00414                         help_url = "http://help.secondlife.com/jp";
00415                 else
00416                 if ( lang == "ko" )
00417                         help_url = "http://help.secondlife.com/kr";
00418                 else
00419                 if ( lang == "pt" )
00420                         help_url = "http://help.secondlife.com/pt";
00421                 else
00422                 if ( lang == "de" )
00423                         help_url = "http://de.secondlife.com/support";
00424                 else
00425                 if ( lang == "es" )
00426                         help_url = "http://secondlife.com/app/support/index_es.html";
00427                 else
00428                 if ( lang == "fr" )
00429                         help_url = "http://secondlife.com/app/support/index_fr.html";
00430                 else
00431                 if ( lang == "zh" )
00432                         help_url = "http://secondlife.com/app/support/index_zh.html";           
00433 
00434                 LLWeb::loadURL( help_url );
00435         };
00436 }
00437 
00439 //
00440 void LLFloaterHtmlHelp::onClose( bool app_quitting )
00441 {
00442         setVisible( false );
00443 }
00444 
00446 //
00447 void LLFloaterHtmlHelp::onClickClose( void* data )
00448 {
00449         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00450 
00451         self->setVisible( false );
00452 }
00453 
00455 //
00456 void LLFloaterHtmlHelp::onClickBack( void* data )
00457 {
00458         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00459         if ( self )
00460         {
00461                 if ( self->mWebBrowser )
00462                 {
00463                         self->mWebBrowser->navigateBack();
00464                 };
00465         };
00466 }
00467 
00469 //
00470 void LLFloaterHtmlHelp::onClickHome( void* data )
00471 {
00472         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00473         if ( self )
00474         {
00475                 // get the home page URL (which can differ from the start URL) from XML and go there
00476                 LLWebBrowserCtrl* web_browser = self->getChild<LLWebBrowserCtrl>("html_help_browser" );
00477                 if ( web_browser )
00478                 {
00479                         web_browser->navigateHome();
00480                 };
00481         };
00482 }
00483 
00485 // 
00486 void LLFloaterHtmlHelp::onClickForward( void* data )
00487 {
00488         LLFloaterHtmlHelp* self = ( LLFloaterHtmlHelp* )data;
00489         if ( self )
00490         {
00491                 if ( self->mWebBrowser )
00492                 {
00493                         self->mWebBrowser->navigateForward();
00494                 };
00495         };
00496 }
00497 
00499 //
00500 void LLFloaterHtmlHelp::onStatusTextChange( const EventType& eventIn )
00501 {
00502         mStatusTextContents = LLString( eventIn.getStringValue() );
00503 
00504         childSetText("status_text", mStatusTextContents);
00505 }
00506 
00508 //
00509 void LLFloaterHtmlHelp::onLocationChange( const EventType& eventIn )
00510 {
00511         llinfos << "MOZ> Location changed to " << eventIn.getStringValue() << llendl;
00512         mCurrentUrl = LLString( eventIn.getStringValue() );
00513 }
00514 
00516 //
00517 LLViewerHtmlHelp::LLViewerHtmlHelp()
00518 {
00519         LLUI::setHtmlHelp(this);
00520 }
00521 
00522 LLViewerHtmlHelp::~LLViewerHtmlHelp()
00523 {
00524         LLUI::setHtmlHelp(NULL);
00525 }
00526 
00527 void LLViewerHtmlHelp::show()
00528 {
00529         LLFloaterHtmlHelp::show("", "");
00530 }
00531 
00532 void LLViewerHtmlHelp::show(std::string url)
00533 {
00534         std::string title;      // empty
00535         LLFloaterHtmlHelp::show(url, title);
00536 }

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