aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpaneldirfind.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llpaneldirfind.cpp')
-rw-r--r--linden/indra/newview/llpaneldirfind.cpp361
1 files changed, 344 insertions, 17 deletions
diff --git a/linden/indra/newview/llpaneldirfind.cpp b/linden/indra/newview/llpaneldirfind.cpp
index 73643bf..50bdc9e 100644
--- a/linden/indra/newview/llpaneldirfind.cpp
+++ b/linden/indra/newview/llpaneldirfind.cpp
@@ -1,6 +1,6 @@
1/** 1/**
2 * @file llpaneldirfind.cpp 2 * @file llpaneldirfind.cpp
3 * @brief The "Find All" panel in the Find directory. 3 * @brief The "All" panel in the Search directory.
4 * 4 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$ 5 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 * 6 *
@@ -44,29 +44,356 @@
44#include "llagent.h" 44#include "llagent.h"
45#include "llbutton.h" 45#include "llbutton.h"
46#include "llcheckboxctrl.h" 46#include "llcheckboxctrl.h"
47#include "lllineeditor.h"
47#include "llcombobox.h" 48#include "llcombobox.h"
48#include "llviewercontrol.h" 49#include "llviewercontrol.h"
49#include "lllineeditor.h"
50#include "llmenucommands.h" 50#include "llmenucommands.h"
51#include "llmenugl.h" 51#include "llmenugl.h"
52#include "llscrolllistctrl.h"
53#include "lltextbox.h" 52#include "lltextbox.h"
54#include "lluiconstants.h" 53#include "lluiconstants.h"
55#include "llviewerimagelist.h" 54#include "llviewerimagelist.h"
56#include "llviewermessage.h" 55#include "llviewermessage.h"
57#include "llfloateravatarinfo.h" 56#include "llfloateravatarinfo.h"
58#include "lldir.h" 57#include "lldir.h"
58#include "llviewercontrol.h"
59#include "llviewerregion.h" // for region name for search urls
59#include "llvieweruictrlfactory.h" 60#include "llvieweruictrlfactory.h"
60#include "llfloaterdirectory.h" 61#include "llfloaterdirectory.h"
61#include "llpaneldirbrowser.h" 62#include "llpaneldirbrowser.h"
62 63
63LLPanelDirFind::LLPanelDirFind(const std::string& name, LLFloaterDirectory* floater) 64#include <boost/tokenizer.hpp>
65
66//---------------------------------------------------------------------------
67// LLPanelDirFindAll - Google search appliance based search
68//---------------------------------------------------------------------------
69
70class LLPanelDirFindAll
71: public LLPanelDirBrowser,
72 public LLWebBrowserCtrlObserver
73{
74public:
75 LLPanelDirFindAll(const std::string& name, LLFloaterDirectory* floater);
76 /*virtual*/ ~LLPanelDirFindAll();
77
78 /*virtual*/ BOOL postBuild();
79 /*virtual*/ void draw();
80
81 void search(const std::string& search_text);
82 void focus();
83 void navigateToDefaultPage();
84
85private:
86 static void onClickBack( void* data );
87 static void onClickForward( void* data );
88 static void onClickHome( void* data );
89 static void onClickSearch( void* data );
90 static void onCommitSearch(LLUICtrl*, void* data);
91 static void onKeystrokeSearchEditor(LLLineEditor* line, void* data);
92
93 /*virtual*/ void onNavigateBegin( const EventType& eventIn );
94 /*virtual*/ void onNavigateComplete( const EventType& eventIn );
95 // Used to update progress indicator
96
97private:
98#if LL_LIBXUL_ENABLED
99 LLWebBrowserCtrl* mWebBrowser;
100#endif // LL_LIBXUL_ENABLED
101};
102
103
104LLPanelDirFindAll::LLPanelDirFindAll(const std::string& name, LLFloaterDirectory* floater)
105: LLPanelDirBrowser(name, floater)
106#if LL_LIBXUL_ENABLED
107 ,mWebBrowser(NULL)
108#endif // LL_LIBXUL_ENABLED
109{
110 mMinSearchChars = 3;
111}
112
113BOOL LLPanelDirFindAll::postBuild()
114{
115 LLPanelDirBrowser::postBuild();
116
117 childSetAction("back_btn", onClickBack, this);
118 childSetAction("home_btn", onClickHome, this);
119 childSetAction("forward_btn", onClickForward, this);
120 childSetCommitCallback("search_editor", onCommitSearch, this);
121 childSetAction("search_btn", onClickSearch, this);
122
123 if (gAgent.isTeen())
124 {
125 childSetVisible("mature_check", false);
126 }
127
128 // we don't record the last search query (yet) so search text will be empty -> disable search
129 childDisable("search_btn");
130
131 childSetKeystrokeCallback("search_editor", onKeystrokeSearchEditor, this);
132
133#if LL_LIBXUL_ENABLED
134 mWebBrowser = LLViewerUICtrlFactory::getWebBrowserByName(this, "find_browser");
135 if (mWebBrowser)
136 {
137 // new pages appear in same window as the results page now
138 mWebBrowser->setOpenInInternalBrowser( false );
139 mWebBrowser->setOpenInExternalBrowser( false );
140
141 // Track updates for progress display.
142 mWebBrowser->addObserver(this);
143
144 navigateToDefaultPage();
145 }
146#endif // LL_LIBXUL_ENABLED
147
148 return TRUE;
149}
150
151LLPanelDirFindAll::~LLPanelDirFindAll()
152{
153#if LL_LIBXUL_ENABLED
154 if (mWebBrowser) mWebBrowser->remObserver(this);
155#endif // LL_LIBXUL_ENABLED
156}
157
158// virtual
159void LLPanelDirFindAll::draw()
160{
161 // enable/disable buttons depending on state
162#if LL_LIBXUL_ENABLED
163 if ( mWebBrowser )
164 {
165 bool enable_back = mWebBrowser->canNavigateBack();
166 childSetEnabled( "back_btn", enable_back );
167
168 bool enable_forward = mWebBrowser->canNavigateForward();
169 childSetEnabled( "forward_btn", enable_forward );
170 }
171#endif // LL_LIBXUL_ENABLED
172
173 LLPanelDirBrowser::draw();
174}
175
176void LLPanelDirFindAll::search(const std::string& search_text)
177{
178 if (!search_text.empty())
179 {
180 // Replace spaces with "+" for use by Google search appliance
181 // Yes, this actually works for double-spaces
182 // " foo bar" becomes "+foo++bar" and works fine. JC
183 std::string query = search_text;
184 std::string::iterator it = query.begin();
185 for ( ; it != query.end(); ++it )
186 {
187 if ( std::isspace( *it ) )
188 {
189 *it = '+';
190 }
191 }
192
193 std::string url = gSavedSettings.getString("SearchQueryURL");
194 std::string substring = "[QUERY]";
195 url.replace(url.find(substring), substring.length(), query);
196
197 // replace the collection name with the one selected from the combo box
198 std::string selected_collection = childGetValue( "Category" ).asString();
199 substring = "[COLLECTION]";
200 url.replace(url.find(substring), substring.length(), selected_collection);
201
202 // if the mature checkbox is unchecked, modify query to remove
203 // terms with given phrase from the result set
204 substring = "[MATURE]";
205 if ( childGetValue( "mature_check" ).asBoolean() == false )
206 {
207 url.replace(url.find(substring), substring.length(), "N");
208 }
209 else
210 {
211 url.replace(url.find(substring), substring.length(), "Y");
212 }
213
214 substring = "[TEEN]";
215 const char* teen = (gAgent.isTeen() ? "Y" : "N");
216 url.replace(url.find(substring), substring.length(), teen);
217
218 // Include region and x/y position, not for the GSA, but
219 // just to get logs on the web server for search_proxy.php
220 // showing where people were standing when they searched.
221 std::string region_name;
222 LLViewerRegion* region = gAgent.getRegion();
223 if (region)
224 {
225 region_name = region->getName();
226 }
227 // take care of spaces in names
228 region_name = LLURI::escape(region_name);
229 substring = "[REGION]";
230 url.replace(url.find(substring), substring.length(), region_name);
231
232 LLVector3 pos_region = gAgent.getPositionAgent();
233 std::string x = llformat("%.0f", pos_region.mV[VX]);
234 substring = "[X]";
235 url.replace(url.find(substring), substring.length(), x);
236 std::string y = llformat("%.0f", pos_region.mV[VY]);
237 substring = "[Y]";
238 url.replace(url.find(substring), substring.length(), y);
239 std::string z = llformat("%.0f", pos_region.mV[VZ]);
240 substring = "[Z]";
241 url.replace(url.find(substring), substring.length(), z);
242
243 llinfos << "url " << url << llendl;
244
245#if LL_LIBXUL_ENABLED
246 if (mWebBrowser)
247 {
248 mWebBrowser->navigateTo(url);
249 }
250#endif // LL_LIBXUL_ENABLED
251 }
252 else
253 {
254 // empty search text
255 navigateToDefaultPage();
256 }
257
258 childSetText("search_editor", search_text);
259}
260
261void LLPanelDirFindAll::focus()
262{
263 childSetFocus("search_editor");
264}
265
266void LLPanelDirFindAll::navigateToDefaultPage()
267{
268 std::string start_url = gSavedSettings.getString("SearchDefaultURL");
269
270 std::string substring = "[MATURE]";
271 if ( childGetValue( "mature_check" ).asBoolean() == false )
272 {
273 start_url.replace( start_url.find( substring ), substring.length(), "N" );
274 }
275 else
276 {
277 start_url.replace( start_url.find( substring ), substring.length(), "Y" );
278 }
279 llinfos << "SEARCH> browsing to default url: " << start_url << llendl;
280
281#if LL_LIBXUL_ENABLED
282 if (mWebBrowser)
283 {
284 mWebBrowser->navigateTo( start_url );
285 }
286#endif //LL_LIBXUL_ENABLED
287}
288
289// static - only enable search if there is at least 1 character
290void LLPanelDirFindAll::onKeystrokeSearchEditor(LLLineEditor* line, void* data)
291{
292 LLPanelDirBrowser *self = (LLPanelDirBrowser*)data;
293 if (line->getLength() > 0 )
294 {
295 self->childEnable("search_btn");
296 }
297 else
298 {
299 self->childDisable("search_btn");
300 }
301}
302
303// static
304void LLPanelDirFindAll::onClickBack( void* data )
305{
306#if LL_LIBXUL_ENABLED
307 LLPanelDirFindAll* self = ( LLPanelDirFindAll* )data;
308 if ( self->mWebBrowser )
309 {
310 self->mWebBrowser->navigateBack();
311 }
312#endif // LL_LIBXUL_ENABLED
313}
314
315// static
316void LLPanelDirFindAll::onClickForward( void* data )
317{
318#if LL_LIBXUL_ENABLED
319 LLPanelDirFindAll* self = ( LLPanelDirFindAll* )data;
320 if ( self->mWebBrowser )
321 {
322 self->mWebBrowser->navigateForward();
323 }
324#endif // LL_LIBXUL_ENABLED
325}
326
327// static
328void LLPanelDirFindAll::onClickHome( void* data )
329{
330#if LL_LIBXUL_ENABLED
331 LLPanelDirFindAll* self = ( LLPanelDirFindAll* )data;
332 if ( self->mWebBrowser )
333 {
334 self->mWebBrowser->navigateHome();
335 }
336#endif // LL_LIBXUL_ENABLED
337}
338
339// static
340void LLPanelDirFindAll::onCommitSearch(LLUICtrl*, void* data)
341{
342 onClickSearch(data);
343}
344
345// static
346void LLPanelDirFindAll::onClickSearch(void* data)
347{
348 LLPanelDirFindAll* self = ( LLPanelDirFindAll* )data;
349 LLString search_text = self->childGetText("search_editor");
350 self->search(search_text);
351}
352
353void LLPanelDirFindAll::onNavigateBegin( const EventType& eventIn )
354{
355 childSetText("status_text", childGetText("loading_text"));
356}
357
358void LLPanelDirFindAll::onNavigateComplete( const EventType& eventIn )
359{
360 childSetText("status_text", childGetText("done_text"));
361}
362
363//---------------------------------------------------------------------------
364// LLPanelDirFindAllInterface
365//---------------------------------------------------------------------------
366
367// static
368LLPanelDirFindAll* LLPanelDirFindAllInterface::create(LLFloaterDirectory* floater)
369{
370 return new LLPanelDirFindAll("find_all_panel", floater);
371}
372
373// static
374void LLPanelDirFindAllInterface::search(LLPanelDirFindAll* panel,
375 const std::string& search_text)
376{
377 panel->search(search_text);
378}
379
380// static
381void LLPanelDirFindAllInterface::focus(LLPanelDirFindAll* panel)
382{
383 panel->focus();
384}
385
386//---------------------------------------------------------------------------
387// LLPanelDirFindAllOld - deprecated if new Google search works out. JC
388//---------------------------------------------------------------------------
389
390LLPanelDirFindAllOld::LLPanelDirFindAllOld(const std::string& name, LLFloaterDirectory* floater)
64 : LLPanelDirBrowser(name, floater) 391 : LLPanelDirBrowser(name, floater)
65{ 392{
66 mMinSearchChars = 3; 393 mMinSearchChars = 3;
67} 394}
68 395
69BOOL LLPanelDirFind::postBuild() 396BOOL LLPanelDirFindAllOld::postBuild()
70{ 397{
71 LLPanelDirBrowser::postBuild(); 398 LLPanelDirBrowser::postBuild();
72 399
@@ -79,32 +406,32 @@ BOOL LLPanelDirFind::postBuild()
79 return TRUE; 406 return TRUE;
80} 407}
81 408
409LLPanelDirFindAllOld::~LLPanelDirFindAllOld()
410{
411 // Children all cleaned up by default view destructor.
412}
413
82// virtual 414// virtual
83void LLPanelDirFind::draw() 415void LLPanelDirFindAllOld::draw()
84{ 416{
85 // You only have a choice if you are mature 417 // You only have a choice if you are mature
86 childSetVisible("incmature", gAgent.mAccess >= SIM_ACCESS_MATURE); 418 childSetVisible("incmature", !gAgent.isTeen());
87 childSetValue("incmature", gSavedSettings.getBOOL("ShowMatureFindAll")); 419 childSetValue("incmature", gSavedSettings.getBOOL("ShowMatureFindAll"));
88 420
89 LLPanelDirBrowser::draw(); 421 LLPanelDirBrowser::draw();
90} 422}
91 423
92LLPanelDirFind::~LLPanelDirFind()
93{
94 // Children all cleaned up by default view destructor.
95}
96
97// static 424// static
98void LLPanelDirFind::onCommitScope(LLUICtrl* ctrl, void* data) 425void LLPanelDirFindAllOld::onCommitScope(LLUICtrl* ctrl, void* data)
99{ 426{
100 LLPanelDirFind* self = (LLPanelDirFind*)data; 427 LLPanelDirFindAllOld* self = (LLPanelDirFindAllOld*)data;
101 self->setFocus(TRUE); 428 self->setFocus(TRUE);
102} 429}
103 430
104// static 431// static
105void LLPanelDirFind::onClickSearch(void *userdata) 432void LLPanelDirFindAllOld::onClickSearch(void *userdata)
106{ 433{
107 LLPanelDirFind *self = (LLPanelDirFind *)userdata; 434 LLPanelDirFindAllOld *self = (LLPanelDirFindAllOld *)userdata;
108 435
109 if (self->childGetValue("name").asString().length() < self->mMinSearchChars) 436 if (self->childGetValue("name").asString().length() < self->mMinSearchChars)
110 { 437 {
@@ -121,7 +448,7 @@ void LLPanelDirFind::onClickSearch(void *userdata)
121 scope |= DFQ_GROUPS; // groups 448 scope |= DFQ_GROUPS; // groups
122 449
123 BOOL filter_mature = (!gSavedSettings.getBOOL("ShowMatureFindAll") || 450 BOOL filter_mature = (!gSavedSettings.getBOOL("ShowMatureFindAll") ||
124 gAgent.mAccess <= SIM_ACCESS_PG || 451 gAgent.isTeen() ||
125 !self->childGetValue("incmature").asBoolean() ); 452 !self->childGetValue("incmature").asBoolean() );
126 453
127 if ( filter_mature ) 454 if ( filter_mature )