Copyright © 2004-2008 Opera Software ASA. All rights reserved.
This file is part of the Opera web browser. It may not be distributed
under any circumstances.
$Id$
The searchmanager module contains functionality for storing and loading URLs to different searchengines and given a search query produce an URL to that searchengine with that query. It also supports giving each searchengine a nickname. For example the string "g foo" could become "http://www.google.com/search?client=opera&rls=en&q=foo&sourceid=opera&num=10&ie=utf-8&oe=utf-8".
The searchengines are stored in the file search.ini. Format for a searchengine is:
[Google] ID=1 Version=0 Deleted=0 Is Separator=0 GUID= Name ID=17171 Name= Description ID=0 Description= URL=http://www.google.com/search?q=%s&sourceid=opera&num=%i&ie=utf-8&oe=utf-8 Key=g Is post=0 Post Query= Type=1 Icon URL= Encoding=utf-8where
%s in the URL value means that the search query should be placed there and %i means that the preferred number of answers per page should be placed there. This number is controlled by the preference PrefsCollectionCore::PreferredNumberOfHits.
Find search string if you want to search for "foobar" on google (post_query will be empty if google search is not using POST) :
//Find search element by key ('g' for Google). Can also be done by ID or URL
SearchElement* search_element = g_search_manager->GetSearchByKey(UNI_L("g"));
if (search_element)
{
OpString search_query;
OpString post_query;
if (OpStatus::IsSuccess(search_element->MakeSearchString(search_query, post_query, UNI_L("foobar"))))
{
...
}
}
For detailed information on how to use the style module in Opera and the module's public API, please refer to the API documentation.
The code is supposed to meet all requirements from platform teams, while being simple to use. Just initialize it with the read-only opera-provided search.ini, and a writable file for user-defined searches in case user-defined searches are module.import'ed. When it is initialized, you can query, iterate, add, remove and modify searches, as well as giving URL to an OpenSearch (www.opensearch.org) XML file the user wants to add (it will be downloaded and added async, sending a message to the global messagehandler when done). You can force a writing of the user-defined search.ini (if not, it will be done at shutdown, if needed). Everything else is pretty much handled for you.