2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* Copyright (c) 1994,1995,1996 FUJITSU LIMITED */
24 /* All Rights Reserved */
27 * $TOG: SearchMgr.C /main/17 1998/04/17 11:37:13 mgreess $
29 * Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
30 * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
31 * States. Use of a copyright notice is precautionary only and does not
32 * imply publication or disclosure.
34 * This software contains confidential information and trade secrets of HaL
35 * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
36 * without the prior express written permission of HaL Computer Systems, Inc.
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject to
40 * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
41 * Technical Data and Computer Software clause at DFARS 252.227-7013.
42 * HaL Computer Systems, Inc.
43 * 1315 Dell Avenue, Campbell, CA 95008
49 #include "Registration.hh"
56 #define C_WindowSystem
65 #define C_SearchHistoryListView
69 #define C_SearchResultsMgr
71 #define C_SearchScopeMgr
77 #include "Managers/CatMgr.hh"
81 LONG_LIVED_CC(SearchMgr,search_mgr)
83 // Reconfigure search engine
84 class SeReconfigure : public UAS_Receiver<UAS_CollectionRetrievedMsg >,
85 public UAS_Receiver<UAS_LibraryDestroyedMsg>
91 void receive (UAS_CollectionRetrievedMsg &message, void *client_data);
92 void receive (UAS_LibraryDestroyedMsg &message, void *client_data);
95 SeReconfigure::SeReconfigure()
97 UAS_Collection::request((UAS_Receiver<UAS_CollectionRetrievedMsg> *)
99 UAS_Common::request ((UAS_Receiver<UAS_LibraryDestroyedMsg> *)this);
102 // infolib was added to system, need to reinit search engine
104 SeReconfigure::receive (UAS_CollectionRetrievedMsg &message, void *client_data)
106 ON_DEBUG (printf ("Received UAS_CollectionRetrievedMsg message!\n"));
107 UAS_Pointer<UAS_Common> root(message.fCol->root());
108 search_mgr().add_root(root);
111 // infolib was removed from system, need to reinit search engine
113 SeReconfigure::receive (UAS_LibraryDestroyedMsg &message, void *client_data)
115 ON_DEBUG (printf ("Received UAS_LibraryDestroyedMsg message!\n"));
116 search_mgr().remove_root(message.fLib);
119 static SeReconfigure se_reconfigure;
123 // /////////////////////////////////////////////////////////////////
125 // /////////////////////////////////////////////////////////////////
127 SearchMgr::SearchMgr()
128 : f_search_engine(NULL),
129 f_query_editor (NULL),
130 f_search_history_list (pref_mgr().get_int (PrefMgr::SearchHistSize)),
131 f_search_history_list_view (NULL),
132 f_search_section ("")
137 // /////////////////////////////////////////////////////////////////
139 // /////////////////////////////////////////////////////////////////
144 UAS_List<UAS_String> rootLocs = UAS_Common::rootLocators ();
147 for (i = 0; i < rootLocs.length(); i ++) {
148 UAS_Pointer<UAS_Common> theDoc =
149 UAS_Common::create(*(UAS_String*)rootLocs[i]);
150 UAS_Pointer<UAS_Collection> theCol = (UAS_Collection *)
151 ((UAS_Common *) theDoc);
152 theDoc = theCol->root();
153 f_roots.insert_item (theDoc);
157 setStatus (eSuccess);
160 SearchMgr::~SearchMgr()
162 while (f_search_history_list.length () > 0)
163 f_search_history_list.remove_first();
167 SearchMgr::search_engine () {
168 if (f_search_engine == 0) {
169 if (f_roots.length() > 0)
170 f_search_engine = f_roots[0]->search_engine();
172 throw (CASTEXCEPT Exception());
174 return *(UAS_SearchEngine*)f_search_engine;
178 // /////////////////////////////////////////////////////////////////
179 // history_entry_activate - user says display something from hist
180 // /////////////////////////////////////////////////////////////////
183 SearchMgr::history_entry_activate (FolioObject *, u_int,
184 void *notify_data, void *)
187 u_int which_item = (int) notify_data;
189 ResultID *rid = (ResultID *) f_search_history_list[which_item];
192 if (rid->ndocs() > 0)
193 search_results_mgr().display (rid);
195 display_message (NO_HITS);
199 // /////////////////////////////////////////////////////////////////
200 // search_history_list_view
201 // /////////////////////////////////////////////////////////////////
204 SearchMgr::search_history_list_view()
206 if (f_search_history_list_view == NULL)
208 f_search_history_list_view =
209 new SearchHistoryListView (&f_search_history_list, "search_history");
210 f_search_history_list_view->AddDependent
211 ((notify_handler_t) &SearchMgr::history_entry_activate,
212 ListView::ENTRY_ACTIVATE);
215 return (*f_search_history_list_view);
218 // /////////////////////////////////////////////////////////////////
220 // /////////////////////////////////////////////////////////////////
223 SearchMgr::display_editor()
225 if (f_query_editor == NULL)
226 f_query_editor = new QueryEditor(search_engine());
228 f_query_editor->display();
231 // /////////////////////////////////////////////////////////////////
232 // search - invoke search engine on raw query and display results
233 // /////////////////////////////////////////////////////////////////
236 SearchMgr::parse_and_search (char *query, UAS_SearchScope *scope) {
238 // SWM -- code lifted from old SearchQuery object. If no scope
239 // is passed, pass "current section" if f_search_section is set,
240 // otherwise, pass "information library"
243 xList<UAS_SearchScope *> &scope_list = search_scope_mgr().scope_list();
244 List_Iterator<UAS_SearchScope *> s (scope_list);
245 if (!f_search_section.length())
250 // Hand off to search engine.
251 UAS_Pointer<UAS_SearchResults> tmp_results;
252 ResultID *search_results = 0;
253 if (f_search_section.length()) {
254 scope->search_zones().section ((char*)f_search_section);
258 tmp_results = search_engine().search (query, *scope);
260 catch (UAS_Exception&, e)
262 message_mgr().error_dialog ((char*)e->message());
271 if (tmp_results == 0) {
272 display_message(BAD_QUERY);
275 if (tmp_results->num_docs() > 0) {
276 search_results = new ResultID (tmp_results);
277 f_search_history_list.append (*search_results);
279 if (!f_search_section.length()) {
280 search_results_mgr().display (search_results);
283 if (f_search_section.length() ||
284 pref_mgr().get_boolean (PrefMgr::DisplayFirstHit))
286 UAS_Pointer<UAS_List<UAS_SearchResultsEntry> > tmpPtr =
287 tmp_results->create_results(0, 1);
289 UAS_List<UAS_SearchResultsEntry> * tmpTmpPtr =
290 (UAS_List<UAS_SearchResultsEntry>*)tmpPtr;
292 UAS_List<UAS_SearchResultsEntry> tmp3Ptr =
295 UAS_Pointer<UAS_SearchResultsEntry> tmp4Ptr = tmp3Ptr[0];
297 f_current_hits = tmp4Ptr->create_matches();
298 UAS_String target = tmp4Ptr->id();
299 UAS_Pointer<UAS_Common> doc_ptr = UAS_Common::create (target);
302 } else if (tmp_results->num_docs() == 0) {
303 display_message(NO_HITS);
309 SearchMgr::display_message (SearchMessageType msg, int)
315 message_mgr().info_dialog (
316 (char*)UAS_String(CATGETS(Set_Messages, 40, "File a Bug")));
319 message_mgr().warning_dialog (
320 (char*)UAS_String(CATGETS(Set_Messages, 41, "File a Bug")));
325 UAS_Pointer<UAS_List<UAS_TextRun> >
326 SearchMgr::current_hits()
328 UAS_Pointer<UAS_List<UAS_TextRun> > rval = NULL;
329 if (f_search_section) {
330 rval = f_current_hits;
331 f_current_hits = NULL; // f_current_hits is volatile
337 SearchMgr::add_root(UAS_Pointer<UAS_Common>& root)
340 for (i = 0; i < f_roots.length(); i++) {
341 if (f_roots[i] == root)
344 if (i < f_roots.length())
347 f_roots.insert_item(root);
349 f_search_engine = NULL;
353 SearchMgr::remove_root(UAS_Pointer<UAS_Common>& root)
356 for (i = 0; i < f_roots.length(); i++) {
357 if (f_roots[i] == root)
360 if (i == f_roots.length())
363 f_roots.remove_item(i);
365 f_search_engine = NULL;