1
1
/* *
2
2
* @file llfloatersearch.cpp
3
- * @author Martin Reddy
4
- * @brief Search floater - uses an embedded web browser control
3
+ * @brief Floater for Search (update 2025, preload)
5
4
*
6
- * $LicenseInfo:firstyear=2009 &license=viewerlgpl$
5
+ * $LicenseInfo:firstyear=2011 &license=viewerlgpl$
7
6
* Second Life Viewer Source Code
8
- * Copyright (C) 2010 , Linden Research, Inc.
7
+ * Copyright (C) 2011 , Linden Research, Inc.
9
8
*
10
9
* This library is free software; you can redistribute it and/or
11
10
* modify it under the terms of the GNU Lesser General Public
27
26
28
27
#include " llviewerprecompiledheaders.h"
29
28
29
+ #include " llfloatersearch.h"
30
+
31
+ #include " llagent.h"
30
32
#include " llcommandhandler.h"
31
33
#include " llfloaterreg.h"
32
- #include " llfloatersearch.h"
33
- #include " llhttpconstants.h"
34
34
#include " llmediactrl.h"
35
- #include " llnotificationsutil.h"
36
- #include " lllogininstance.h"
37
- #include " lluri.h"
38
- #include " llagent.h"
39
- #include " llui.h"
35
+ #include " lluictrlfactory.h"
40
36
#include " llviewercontrol.h"
41
37
#include " llweb.h"
42
38
43
39
// support secondlife:///app/search/{CATEGORY}/{QUERY} SLapps
44
- class LLSearchHandler : public LLCommandHandler
45
- {
46
- public:
47
- // requires trusted browser to trigger
48
- LLSearchHandler () : LLCommandHandler(" search" , UNTRUSTED_CLICK_ONLY) { }
49
- bool handle (const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web)
50
- {
51
- const size_t parts = tokens.size ();
52
-
53
- // get the (optional) category for the search
54
- std::string collection;
55
- if (parts > 0 )
56
- {
57
- collection = tokens[0 ].asString ();
40
+ class LLSearchHandler : public LLCommandHandler {
41
+ public:
42
+ // requires trusted browser to trigger
43
+ LLSearchHandler () : LLCommandHandler(" search" , UNTRUSTED_CLICK_ONLY) { }
44
+ bool handle (const LLSD& tokens, const LLSD& query_map, const std::string& grid, LLMediaCtrl* web) {
45
+ const size_t parts = tokens.size ();
46
+
47
+ // open the search floater and perform the requested search
48
+ LLFloaterReg::showInstance (" search" , tokens);
49
+ return true ;
58
50
}
59
-
60
- // get the (optional) search string
61
- std::string search_text;
62
- if (parts > 1 )
63
- {
64
- search_text = tokens[1 ].asString ();
65
- }
66
-
67
- // create the LLSD arguments for the search floater
68
- LLFloaterSearch::Params p;
69
- p.search .collection = collection;
70
- p.search .query = LLURI::unescape (search_text);
71
-
72
- // open the search floater and perform the requested search
73
- LLFloaterReg::showInstance (" search" , p);
74
- return true ;
75
- }
76
51
};
77
52
LLSearchHandler gSearchHandler ;
78
53
79
- LLFloaterSearch::SearchQuery::SearchQuery ()
80
- : category(" category" , " " ),
81
- collection(" collection" , " " ),
82
- query(" query" )
83
- {}
84
-
85
- LLFloaterSearch::LLFloaterSearch (const Params& key) :
86
- LLFloaterWebContent(key),
87
- mSearchGodLevel(0 )
54
+ LLFloaterSearch::LLFloaterSearch (const LLSD& key)
55
+ : LLFloater(key)
88
56
{
89
- // declare a map that transforms a category name into
90
- // the URL suffix that is used to search that category
91
-
92
57
mSearchType .insert (" standard" );
93
58
mSearchType .insert (" land" );
94
59
mSearchType .insert (" classified" );
@@ -100,76 +65,61 @@ LLFloaterSearch::LLFloaterSearch(const Params& key) :
100
65
mCollectionType .insert (" people" );
101
66
}
102
67
103
- bool LLFloaterSearch::postBuild ()
68
+ LLFloaterSearch::~LLFloaterSearch ()
104
69
{
105
- LLFloaterWebContent::postBuild ();
106
- mWebBrowser ->addObserver (this );
107
-
108
- return true ;
109
70
}
110
71
111
- void LLFloaterSearch::onOpen (const LLSD& key )
72
+ void LLFloaterSearch::onOpen (const LLSD& tokens )
112
73
{
113
- Params p (key);
114
- p.trusted_content = true ;
115
- p.allow_address_entry = false ;
116
-
117
- LLFloaterWebContent::onOpen (p);
118
- mWebBrowser ->setFocus (true );
119
- search (p.search );
74
+ initiateSearch (tokens);
120
75
}
121
76
122
- void LLFloaterSearch::onClose ( bool app_quitting )
77
+ void LLFloaterSearch::initiateSearch ( const LLSD& tokens )
123
78
{
124
- LLFloaterWebContent::onClose (app_quitting);
125
- // tear down the web view so we don't show the previous search
126
- // result when the floater is opened next time
127
- destroy ();
128
- }
79
+ std::string url = gSavedSettings .getString (" SearchURL" );
129
80
130
- void LLFloaterSearch::godLevelChanged (U8 godlevel)
131
- {
132
- // search results can change based upon god level - if the user
133
- // changes god level, then give them a warning (we don't refresh
134
- // the search as this might undo any page navigation or
135
- // AJAX-driven changes since the last search).
81
+ LLSD subs;
136
82
137
- // FIXME: set status bar text
83
+ // Setting this substitution here results in a full set of collections being
84
+ // substituted into the final URL using the logic from the original search.
85
+ subs[" TYPE" ] = " standard" ;
138
86
139
- // getChildView("refresh_search")->setVisible( (godlevel != mSearchGodLevel));
140
- }
87
+ const size_t parts = tokens.size ();
141
88
142
- void LLFloaterSearch::search ( const SearchQuery &p)
143
- {
144
- if (! mWebBrowser || !p. validateBlock () )
89
+ // get the (optional) category for the search
90
+ std::string collection;
91
+ if (parts > 0 )
145
92
{
146
- return ;
93
+ collection = tokens[ 0 ]. asString () ;
147
94
}
148
95
149
- // reset the god level warning as we're sending the latest state
150
- getChildView (" refresh_search" )->setVisible (false );
151
- mSearchGodLevel = gAgent .getGodLevel ();
96
+ // get the (optional) search string
97
+ std::string search_text;
98
+ if (parts > 1 )
99
+ {
100
+ search_text = tokens[1 ].asString ();
101
+ }
152
102
153
- // work out the subdir to use based on the requested category
154
- LLSD subs;
155
- if (mSearchType .find (p.category ) != mSearchType .end ())
103
+ // TODO: where does category get set? I cannot find a reference to
104
+ // it in internal docs - might be conflated with values in mSearchType
105
+ std::string category;
106
+ if (mSearchType .find (category) != mSearchType .end ())
156
107
{
157
- subs[" TYPE" ] = p. category ;
108
+ subs[" TYPE" ] = category;
158
109
}
159
110
else
160
111
{
161
112
subs[" TYPE" ] = " standard" ;
162
113
}
163
114
164
- // add the search query string
165
- subs[" QUERY" ] = LLURI::escape (p.query );
115
+ subs[" QUERY" ] = LLURI::escape (search_text);
166
116
167
117
subs[" COLLECTION" ] = " " ;
168
118
if (subs[" TYPE" ] == " standard" )
169
119
{
170
- if (mCollectionType .find (p. collection ) != mCollectionType .end ())
120
+ if (mCollectionType .find (collection) != mCollectionType .end ())
171
121
{
172
- subs[" COLLECTION" ] = " &collection_chosen=" + std::string (p. collection );
122
+ subs[" COLLECTION" ] = " &collection_chosen=" + std::string (collection);
173
123
}
174
124
else
175
125
{
@@ -182,30 +132,41 @@ void LLFloaterSearch::search(const SearchQuery &p)
182
132
}
183
133
}
184
134
185
- // add the user's preferred maturity (can be changed via prefs)
186
- std::string maturity;
135
+ // Default to PG
136
+ std::string maturity = " g " ;
187
137
if (gAgent .prefersAdult ())
188
138
{
189
- maturity = " gma" ; // PG,Mature,Adult
139
+ // PG,Mature,Adult
140
+ maturity = " gma" ;
190
141
}
191
142
else if (gAgent .prefersMature ())
192
143
{
193
- maturity = " gm" ; // PG,Mature
194
- }
195
- else
196
- {
197
- maturity = " g" ; // PG
144
+ // PG,Mature
145
+ maturity = " gm" ;
198
146
}
199
147
subs[" MATURITY" ] = maturity;
200
148
201
- // add the user's god status
149
+ // God status
202
150
subs[" GODLIKE" ] = gAgent .isGodlike () ? " 1" : " 0" ;
203
151
204
- // get the search URL and expand all of the substitutions
205
- // (also adds things like [LANGUAGE], [VERSION], [OS], etc.)
206
- std::string url = gSavedSettings .getString (" SearchURL" );
152
+ // This call expands a set of generic substitutions like language, viewer version
153
+ // etc. and then also does the same with the list of subs passed in.
207
154
url = LLWeb::expandURLSubstitutions (url, subs);
208
155
209
- // and load the URL in the web view
210
- mWebBrowser ->navigateTo (url, HTTP_CONTENT_TEXT_HTML);
156
+ // Naviation to the calculated URL - we know it's HTML so we can
157
+ // tell the media system not to bother with the MIME type check.
158
+ LLMediaCtrl* search_browser = findChild<LLMediaCtrl>(" search_contents" );
159
+ search_browser->navigateTo (url, HTTP_CONTENT_TEXT_HTML);
160
+ }
161
+
162
+ bool LLFloaterSearch::postBuild ()
163
+ {
164
+ enableResizeCtrls (true , true , false );
165
+
166
+ // This call is actioned by the preload code in llViewerWindow
167
+ // that creates the search floater during the login process
168
+ // using a generic search with no query
169
+ initiateSearch (LLSD ());
170
+
171
+ return true ;
211
172
}
0 commit comments