llpaneldirfind.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llpaneldirfind.h"
00035 
00036 // linden library includes
00037 #include "llclassifiedflags.h"
00038 #include "llfontgl.h"
00039 #include "llparcel.h"
00040 #include "llqueryflags.h"
00041 #include "message.h"
00042 
00043 // viewer project includes
00044 #include "llagent.h"
00045 #include "llbutton.h"
00046 #include "llcheckboxctrl.h"
00047 #include "lllineeditor.h"
00048 #include "llcombobox.h"
00049 #include "llviewercontrol.h"
00050 #include "llmenucommands.h"
00051 #include "llmenugl.h"
00052 #include "lltextbox.h"
00053 #include "lluiconstants.h"
00054 #include "llviewerimagelist.h"
00055 #include "llviewermessage.h"
00056 #include "llfloateravatarinfo.h"
00057 #include "lldir.h"
00058 #include "llviewercontrol.h"
00059 #include "llviewerregion.h"             // for region name for search urls
00060 #include "lluictrlfactory.h"
00061 #include "llfloaterdirectory.h"
00062 #include "llpaneldirbrowser.h"
00063 
00064 #include <boost/tokenizer.hpp>
00065 
00066 //---------------------------------------------------------------------------
00067 // LLPanelDirFindAll - Google search appliance based search
00068 //---------------------------------------------------------------------------
00069 
00070 class LLPanelDirFindAll
00071 :       public LLPanelDirFind
00072 {
00073 public:
00074         LLPanelDirFindAll(const std::string& name, LLFloaterDirectory* floater);
00075 
00076         /*Virtual*/ void search(const std::string& search_text);
00077 };
00078 
00079 LLPanelDirFindAll::LLPanelDirFindAll(const std::string& name, LLFloaterDirectory* floater)
00080 :       LLPanelDirFind(name, floater, "find_browser")
00081 {
00082 }
00083 
00084 //---------------------------------------------------------------------------
00085 // LLPanelDirFind - Base class for all browser-based search tabs
00086 //---------------------------------------------------------------------------
00087 
00088 LLPanelDirFind::LLPanelDirFind(const std::string& name, LLFloaterDirectory* floater, const std::string& browser_name)
00089 :       LLPanelDirBrowser(name, floater),
00090         mWebBrowser(NULL),
00091         mBrowserName(browser_name)
00092 {
00093 }
00094 
00095 BOOL LLPanelDirFind::postBuild()
00096 {
00097         LLPanelDirBrowser::postBuild();
00098 
00099         childSetAction("back_btn", onClickBack, this);
00100         childSetAction("home_btn", onClickHome, this);
00101         childSetAction("forward_btn", onClickForward, this);
00102         childSetCommitCallback("search_editor", onCommitSearch, this);
00103         childSetAction("search_btn", onClickSearch, this);
00104 
00105         if (gAgent.isTeen())
00106         {
00107                 // Showcase tab does not have mature checkbox
00108                 if (hasChild("mature_check"))
00109                 {
00110                         childSetVisible("mature_check", false);
00111                         childSetValue("mature_check", false);
00112                 }
00113         }
00114 
00115         mWebBrowser = getChild<LLWebBrowserCtrl>(mBrowserName);
00116         if (mWebBrowser)
00117         {
00118                 // new pages appear in same window as the results page now
00119                 mWebBrowser->setOpenInInternalBrowser( false );
00120                 mWebBrowser->setOpenInExternalBrowser( false ); 
00121 
00122                 // need to handle secondlife:///app/ URLs for direct teleports
00123                 mWebBrowser->setOpenAppSLURLs( true );
00124 
00125                 // redirect 404 pages from S3 somewhere else
00126                 mWebBrowser->set404RedirectUrl( getString("redirect_404_url") );
00127 
00128                 // Track updates for progress display.
00129                 mWebBrowser->addObserver(this);
00130 
00131                 navigateToDefaultPage();
00132         }
00133 
00134         return TRUE;
00135 }
00136 
00137 LLPanelDirFind::~LLPanelDirFind()
00138 {
00139         if (mWebBrowser) 
00140                 mWebBrowser->remObserver(this);
00141 }
00142 
00143 // virtual
00144 void LLPanelDirFind::draw()
00145 {
00146         // enable/disable buttons depending on state
00147         if ( mWebBrowser )
00148         {
00149                 bool enable_back = mWebBrowser->canNavigateBack();      
00150                 childSetEnabled( "back_btn", enable_back );
00151 
00152                 bool enable_forward = mWebBrowser->canNavigateForward();        
00153                 childSetEnabled( "forward_btn", enable_forward );
00154         }
00155 
00156         LLPanelDirBrowser::draw();
00157 }
00158 
00159 // When we show any browser-based view, we want to hide all
00160 // the right-side XUI detail panels.
00161 // virtual
00162 void LLPanelDirFind::onVisibilityChange(BOOL new_visibility)
00163 {
00164         if (new_visibility)
00165         {
00166                 mFloaterDirectory->hideAllDetailPanels();
00167         }
00168         LLPanel::onVisibilityChange(new_visibility);
00169 }
00170 
00171 void LLPanelDirFindAll::search(const std::string& search_text)
00172 {
00173         if (!search_text.empty())
00174         {
00175                 bool mature = childGetValue( "mature_check" ).asBoolean();
00176                 std::string selected_collection = childGetValue( "Category" ).asString();
00177                 std::string url = buildSearchURL(search_text, selected_collection, mature);
00178                 if (mWebBrowser)
00179                 {
00180                         mWebBrowser->navigateTo(url);
00181                 }
00182         }
00183         else
00184         {
00185                 // empty search text
00186                 navigateToDefaultPage();
00187         }
00188 
00189         childSetText("search_editor", search_text);
00190 }
00191 
00192 void LLPanelDirFind::focus()
00193 {
00194         childSetFocus("search_editor");
00195 }
00196 
00197 void LLPanelDirFind::navigateToDefaultPage()
00198 {
00199         std::string start_url = getString("default_search_page");
00200         bool mature = childGetValue( "mature_check" ).asBoolean();
00201         start_url += getSearchURLSuffix( mature );
00202 
00203         llinfos << "default url: "  << start_url << llendl;
00204 
00205         if (mWebBrowser)
00206         {
00207                 mWebBrowser->navigateTo( start_url );
00208         }
00209 }
00210 // static
00211 std::string LLPanelDirFind::buildSearchURL(const std::string& search_text, const std::string& collection, bool mature_in)
00212 {
00213         std::string url = gSavedSettings.getString("SearchURLDefault");
00214         if (!search_text.empty())
00215         {
00216                 // Replace spaces with "+" for use by Google search appliance
00217                 // Yes, this actually works for double-spaces
00218                 // " foo  bar" becomes "+foo++bar" and works fine. JC
00219                 std::string search_text_with_plus = search_text;
00220                 std::string::iterator it = search_text_with_plus.begin();
00221                 for ( ; it != search_text_with_plus.end(); ++it )
00222                 {
00223                         if ( std::isspace( *it ) )
00224                         {
00225                                 *it = '+';
00226                         }
00227                 }
00228 
00229                 // Our own special set of allowed chars (RFC1738 http://www.ietf.org/rfc/rfc1738.txt)
00230                 // Note that "+" is one of them, so we can do "+" addition first.
00231                 const char* allowed =   
00232                         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
00233                         "0123456789"
00234                         "-._~$+!*'()";
00235                 std::string query = LLURI::escape(search_text_with_plus, allowed);
00236 
00237                 url = gSavedSettings.getString("SearchURLQuery");
00238                 std::string substring = "[QUERY]";
00239                 url.replace(url.find(substring), substring.length(), query);
00240 
00241                 // replace the collection name with the one selected from the combo box
00242                 // std::string selected_collection = childGetValue( "Category" ).asString();
00243                 substring = "[COLLECTION]";
00244                 url.replace(url.find(substring), substring.length(), collection);
00245 
00246                 llinfos << "url " << url << llendl;
00247         }
00248         url += getSearchURLSuffix( mature_in );
00249         return url;
00250 }
00251 // static
00252 std::string LLPanelDirFind::getSearchURLSuffix(bool mature_in)
00253 {
00254         bool mature = mature_in;
00255         // Teens never get mature results.  Explicitly override because 
00256         // Lindens/testers have multiple accounts and shared settings sometimes 
00257         // result in teen=Y and mature=Y simultaneously.  JC
00258         if (gAgent.isTeen())
00259         {
00260                 mature = false;
00261         }
00262 
00263         std::string url = gSavedSettings.getString("SearchURLSuffix2");
00264 
00265         // if the mature checkbox is unchecked, modify query to remove 
00266         // terms with given phrase from the result set
00267         std::string substring = "[MATURE]";
00268         const char* mature_flag = (mature ? "Y" : "N");
00269         url.replace(url.find(substring), substring.length(), mature_flag);
00270 
00271         substring = "[TEEN]";
00272         const char* teen_flag = (gAgent.isTeen() ? "Y" : "N");
00273         url.replace(url.find(substring), substring.length(), teen_flag);
00274 
00275         // Include region and x/y position, not for the GSA, but
00276         // just to get logs on the web server for search_proxy.php
00277         // showing where people were standing when they searched.
00278         std::string region_name;
00279         LLViewerRegion* region = gAgent.getRegion();
00280         if (region)
00281         {
00282                 region_name = region->getName();
00283         }
00284         // take care of spaces in names
00285         region_name = LLURI::escape(region_name);
00286         substring = "[REGION]";
00287         url.replace(url.find(substring), substring.length(), region_name);
00288 
00289         LLVector3 pos_region = gAgent.getPositionAgent();
00290 
00291         std::string x = llformat("%.0f", pos_region.mV[VX]);
00292         substring = "[X]";
00293         url.replace(url.find(substring), substring.length(), x);
00294         std::string y = llformat("%.0f", pos_region.mV[VY]);
00295         substring = "[Y]";
00296         url.replace(url.find(substring), substring.length(), y);
00297         std::string z = llformat("%.0f", pos_region.mV[VZ]);
00298         substring = "[Z]";
00299         url.replace(url.find(substring), substring.length(), z);
00300 
00301         LLUUID session_id = gAgent.getSessionID();
00302         std::string session_string = session_id.getString();
00303         substring = "[SESSION]";
00304         url.replace(url.find(substring), substring.length(), session_string);
00305 
00306         // set the currently selected lanaguage by asking the pref setting
00307         std::string language_string = LLUI::sConfigGroup->getString( "Language" );
00308         if ( language_string == "default" ) 
00309         {
00310                 // if "default system language" setting used, ask again
00311                 // (we can't do this directly since it can vary if you install
00312                 // under one language and select a different one using prefs)
00313                 language_string = gSavedSettings.getString( "SystemLanguage" );
00314         }
00315         std::string language_tag = "[LANG]";
00316         url.replace( url.find( language_tag ), language_tag.length(), language_string );
00317 
00318         return url;
00319 }
00320 
00321 
00322 // static
00323 void LLPanelDirFind::onClickBack( void* data )
00324 {
00325         LLPanelDirFind* self = ( LLPanelDirFind* )data;
00326         if ( self->mWebBrowser )
00327         {
00328                 self->mWebBrowser->navigateBack();
00329         }
00330 }
00331 
00332 // static
00333 void LLPanelDirFind::onClickForward( void* data )
00334 {
00335         LLPanelDirFind* self = ( LLPanelDirFind* )data;
00336         if ( self->mWebBrowser )
00337         {
00338                 self->mWebBrowser->navigateForward();
00339         }
00340 }
00341 
00342 // static
00343 void LLPanelDirFind::onClickHome( void* data )
00344 {
00345         LLPanelDirFind* self = ( LLPanelDirFind* )data;
00346         if ( self->mWebBrowser )
00347         {
00348                 self->mWebBrowser->navigateHome();
00349         }
00350 }
00351 
00352 // static
00353 void LLPanelDirFind::onCommitSearch(LLUICtrl*, void* data)
00354 {
00355         onClickSearch(data);
00356 }
00357 
00358 // static
00359 void LLPanelDirFind::onClickSearch(void* data)
00360 {
00361         LLPanelDirFind* self = ( LLPanelDirFind* )data;
00362         LLString search_text = self->childGetText("search_editor");
00363         self->search(search_text);
00364 
00365         LLFloaterDirectory::sNewSearchCount++;
00366 }
00367 
00368 void LLPanelDirFind::onNavigateBegin( const EventType& eventIn )
00369 {
00370         childSetText("status_text", getString("loading_text"));
00371 }
00372 
00373 void LLPanelDirFind::onNavigateComplete( const EventType& eventIn )
00374 {
00375         childSetText("status_text", getString("done_text"));
00376 }
00377 
00378 void LLPanelDirFind::onLocationChange( const EventType& eventIn )
00379 {
00380         llinfos << eventIn.getStringValue() << llendl;
00381 }
00382 
00383 //---------------------------------------------------------------------------
00384 // LLPanelDirFindAllInterface
00385 //---------------------------------------------------------------------------
00386 
00387 // static
00388 LLPanelDirFindAll* LLPanelDirFindAllInterface::create(LLFloaterDirectory* floater)
00389 {
00390         return new LLPanelDirFindAll("find_all_panel", floater);
00391 }
00392 
00393 // static
00394 void LLPanelDirFindAllInterface::search(LLPanelDirFindAll* panel,
00395                                                                                 const std::string& search_text)
00396 {
00397         panel->search(search_text);
00398 }
00399 
00400 // static
00401 void LLPanelDirFindAllInterface::focus(LLPanelDirFindAll* panel)
00402 {
00403         panel->focus();
00404 }
00405 

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