Add a dropdown to choose searchengine when in basic mode in

the search sidebar panel.

b  = 86483
r  = matt
sr = alecf
This commit is contained in:
sgehani%netscape.com 2007-09-06 21:58:13 +00:00
Родитель 5d0748fadb
Коммит eceb4b6f2c
2 изменённых файлов: 160 добавлений и 140 удалений

Просмотреть файл

@ -334,8 +334,9 @@ nsIRDFResource *InternetSearchDataSource::kNC_Title;
nsIRDFResource *InternetSearchDataSource::kNC_Data; nsIRDFResource *InternetSearchDataSource::kNC_Data;
nsIRDFResource *InternetSearchDataSource::kNC_Name; nsIRDFResource *InternetSearchDataSource::kNC_Name;
nsIRDFResource *InternetSearchDataSource::kNC_Description; nsIRDFResource *InternetSearchDataSource::kNC_Description;
nsIRDFResource *InternetSearchDataSource::kNC_actionButton; nsIRDFResource *InternetSearchDataSource::kNC_Version;
nsIRDFResource *InternetSearchDataSource::kNC_actionBar; nsIRDFResource *InternetSearchDataSource::kNC_actionButton;
nsIRDFResource *InternetSearchDataSource::kNC_actionBar;
nsIRDFResource *InternetSearchDataSource::kNC_LastText; nsIRDFResource *InternetSearchDataSource::kNC_LastText;
nsIRDFResource *InternetSearchDataSource::kNC_URL; nsIRDFResource *InternetSearchDataSource::kNC_URL;
nsIRDFResource *InternetSearchDataSource::kRDF_InstanceOf; nsIRDFResource *InternetSearchDataSource::kRDF_InstanceOf;
@ -400,8 +401,9 @@ InternetSearchDataSource::InternetSearchDataSource(void)
gRDFService->GetResource(NC_NAMESPACE_URI "data", &kNC_Data); gRDFService->GetResource(NC_NAMESPACE_URI "data", &kNC_Data);
gRDFService->GetResource(NC_NAMESPACE_URI "Name", &kNC_Name); gRDFService->GetResource(NC_NAMESPACE_URI "Name", &kNC_Name);
gRDFService->GetResource(NC_NAMESPACE_URI "Description", &kNC_Description); gRDFService->GetResource(NC_NAMESPACE_URI "Description", &kNC_Description);
gRDFService->GetResource(NC_NAMESPACE_URI "actionButton", &kNC_actionButton); gRDFService->GetResource(NC_NAMESPACE_URI "Version", &kNC_Version);
gRDFService->GetResource(NC_NAMESPACE_URI "actionBar", &kNC_actionBar); gRDFService->GetResource(NC_NAMESPACE_URI "actionButton", &kNC_actionButton);
gRDFService->GetResource(NC_NAMESPACE_URI "actionBar", &kNC_actionBar);
gRDFService->GetResource(NC_NAMESPACE_URI "LastText", &kNC_LastText); gRDFService->GetResource(NC_NAMESPACE_URI "LastText", &kNC_LastText);
gRDFService->GetResource(NC_NAMESPACE_URI "URL", &kNC_URL); gRDFService->GetResource(NC_NAMESPACE_URI "URL", &kNC_URL);
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf); gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf);
@ -464,8 +466,9 @@ InternetSearchDataSource::~InternetSearchDataSource (void)
NS_IF_RELEASE(kNC_Data); NS_IF_RELEASE(kNC_Data);
NS_IF_RELEASE(kNC_Name); NS_IF_RELEASE(kNC_Name);
NS_IF_RELEASE(kNC_Description); NS_IF_RELEASE(kNC_Description);
NS_IF_RELEASE(kNC_actionButton); NS_IF_RELEASE(kNC_Version);
NS_IF_RELEASE(kNC_actionBar); NS_IF_RELEASE(kNC_actionButton);
NS_IF_RELEASE(kNC_actionBar);
NS_IF_RELEASE(kNC_LastText); NS_IF_RELEASE(kNC_LastText);
NS_IF_RELEASE(kNC_URL); NS_IF_RELEASE(kNC_URL);
NS_IF_RELEASE(kRDF_InstanceOf); NS_IF_RELEASE(kRDF_InstanceOf);
@ -3123,29 +3126,39 @@ InternetSearchDataSource::updateDataHintsInGraph(nsIRDFResource *engine, const P
} }
} }
// save/update version of search engine (if specified)
nsAutoString buttonValue; nsAutoString versionValue;
if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionButton", buttonValue))) if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "version", versionValue)))
{ {
nsCOMPtr<nsIRDFLiteral> descLiteral; nsCOMPtr<nsIRDFLiteral> versionLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(buttonValue.GetUnicode(), if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(versionValue.GetUnicode(),
getter_AddRefs(descLiteral)))) getter_AddRefs(versionLiteral))))
{ {
rv = updateAtom(mInner, engine, kNC_actionButton, descLiteral, nsnull); rv = updateAtom(mInner, engine, kNC_Version, versionLiteral, nsnull);
} }
} }
nsAutoString buttonValue;
if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionButton", buttonValue)))
{
nsCOMPtr<nsIRDFLiteral> buttonLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(buttonValue.GetUnicode(),
getter_AddRefs(buttonLiteral))))
{
rv = updateAtom(mInner, engine, kNC_actionButton, buttonLiteral, nsnull);
}
}
nsAutoString barValue; nsAutoString barValue;
if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionBar", barValue))) if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionBar", barValue)))
{ {
nsCOMPtr<nsIRDFLiteral> descLiteral; nsCOMPtr<nsIRDFLiteral> barLiteral;
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(barValue.GetUnicode(), if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(barValue.GetUnicode(),
getter_AddRefs(descLiteral)))) getter_AddRefs(barLiteral))))
{ {
rv = updateAtom(mInner, engine, kNC_actionBar, descLiteral, nsnull); rv = updateAtom(mInner, engine, kNC_actionBar, barLiteral, nsnull);
} }
} }
PRBool updatePrivateFiles = PR_FALSE; PRBool updatePrivateFiles = PR_FALSE;
@ -5049,8 +5062,14 @@ InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRD
nsAutoString site(hrefStr); nsAutoString site(hrefStr);
#ifdef DEBUG_SEARCH_OUTPUT #ifdef DEBUG_SEARCH_OUTPUT
printf("HREF: '%s'\n", href); char *hrefCStr = hrefStr.ToNewCString();
if (hrefCStr)
{
printf("HREF: '%s'\n", hrefCStr);
nsCRT::free(hrefCStr);
hrefCStr = nsnull;
}
#endif #endif
nsCOMPtr<nsIRDFResource> res; nsCOMPtr<nsIRDFResource> res;

Просмотреть файл

@ -39,135 +39,136 @@
class InternetSearchDataSource : public nsIInternetSearchService, class InternetSearchDataSource : public nsIInternetSearchService,
public nsIRDFDataSource, public nsIRDFDataSource,
public nsIStreamListener, public nsIStreamListener,
public nsIObserver, public nsIObserver,
public nsSupportsWeakReference public nsSupportsWeakReference
{ {
private: private:
static PRInt32 gRefCnt; static PRInt32 gRefCnt;
static PRBool mEngineListBuilt; static PRBool mEngineListBuilt;
// pseudo-constants // pseudo-constants
static nsIRDFResource *kNC_SearchResult; static nsIRDFResource *kNC_SearchResult;
static nsIRDFResource *kNC_SearchEngineRoot; static nsIRDFResource *kNC_SearchEngineRoot;
static nsIRDFResource *kNC_LastSearchRoot; static nsIRDFResource *kNC_LastSearchRoot;
static nsIRDFResource *kNC_LastSearchMode; static nsIRDFResource *kNC_LastSearchMode;
static nsIRDFResource *kNC_SearchCategoryRoot; static nsIRDFResource *kNC_SearchCategoryRoot;
static nsIRDFResource *kNC_SearchResultsSitesRoot; static nsIRDFResource *kNC_SearchResultsSitesRoot;
static nsIRDFResource *kNC_FilterSearchURLsRoot; static nsIRDFResource *kNC_FilterSearchURLsRoot;
static nsIRDFResource *kNC_FilterSearchSitesRoot; static nsIRDFResource *kNC_FilterSearchSitesRoot;
static nsIRDFResource *kNC_SearchType; static nsIRDFResource *kNC_SearchType;
static nsIRDFResource *kNC_Ref; static nsIRDFResource *kNC_Ref;
static nsIRDFResource *kNC_Child; static nsIRDFResource *kNC_Child;
static nsIRDFResource *kNC_Title; static nsIRDFResource *kNC_Title;
static nsIRDFResource *kNC_Data; static nsIRDFResource *kNC_Data;
static nsIRDFResource *kNC_Name; static nsIRDFResource *kNC_Name;
static nsIRDFResource *kNC_Description; static nsIRDFResource *kNC_Description;
static nsIRDFResource *kNC_actionButton; static nsIRDFResource *kNC_Version;
static nsIRDFResource *kNC_actionBar; static nsIRDFResource *kNC_actionButton;
static nsIRDFResource *kNC_LastText; static nsIRDFResource *kNC_actionBar;
static nsIRDFResource *kNC_URL; static nsIRDFResource *kNC_LastText;
static nsIRDFResource *kRDF_InstanceOf; static nsIRDFResource *kNC_URL;
static nsIRDFResource *kRDF_type; static nsIRDFResource *kRDF_InstanceOf;
static nsIRDFResource *kNC_loading; static nsIRDFResource *kRDF_type;
static nsIRDFResource *kNC_HTML; static nsIRDFResource *kNC_loading;
static nsIRDFResource *kNC_Icon; static nsIRDFResource *kNC_HTML;
static nsIRDFResource *kNC_StatusIcon; static nsIRDFResource *kNC_Icon;
static nsIRDFResource *kNC_Banner; static nsIRDFResource *kNC_StatusIcon;
static nsIRDFResource *kNC_Site; static nsIRDFResource *kNC_Banner;
static nsIRDFResource *kNC_Relevance; static nsIRDFResource *kNC_Site;
static nsIRDFResource *kNC_Date; static nsIRDFResource *kNC_Relevance;
static nsIRDFResource *kNC_RelevanceSort; static nsIRDFResource *kNC_Date;
static nsIRDFResource *kNC_PageRank; static nsIRDFResource *kNC_RelevanceSort;
static nsIRDFResource *kNC_Engine; static nsIRDFResource *kNC_PageRank;
static nsIRDFResource *kNC_Price; static nsIRDFResource *kNC_Engine;
static nsIRDFResource *kNC_PriceSort; static nsIRDFResource *kNC_Price;
static nsIRDFResource *kNC_Availability; static nsIRDFResource *kNC_PriceSort;
static nsIRDFResource *kNC_BookmarkSeparator; static nsIRDFResource *kNC_Availability;
static nsIRDFResource *kNC_Update; static nsIRDFResource *kNC_BookmarkSeparator;
static nsIRDFResource *kNC_UpdateIcon; static nsIRDFResource *kNC_Update;
static nsIRDFResource *kNC_UpdateCheckDays; static nsIRDFResource *kNC_UpdateIcon;
static nsIRDFResource *kWEB_LastPingDate; static nsIRDFResource *kNC_UpdateCheckDays;
static nsIRDFResource *kWEB_LastPingModDate; static nsIRDFResource *kWEB_LastPingDate;
static nsIRDFResource *kWEB_LastPingContentLen; static nsIRDFResource *kWEB_LastPingModDate;
static nsIRDFResource *kWEB_LastPingContentLen;
static nsIRDFResource *kNC_SearchCommand_AddToBookmarks; static nsIRDFResource *kNC_SearchCommand_AddToBookmarks;
static nsIRDFResource *kNC_SearchCommand_FilterResult; static nsIRDFResource *kNC_SearchCommand_FilterResult;
static nsIRDFResource *kNC_SearchCommand_FilterSite; static nsIRDFResource *kNC_SearchCommand_FilterSite;
static nsIRDFResource *kNC_SearchCommand_ClearFilters; static nsIRDFResource *kNC_SearchCommand_ClearFilters;
static nsIRDFLiteral *kTrueLiteral; static nsIRDFLiteral *kTrueLiteral;
protected: protected:
static nsIRDFDataSource *mInner; static nsIRDFDataSource *mInner;
static nsCOMPtr<nsIRDFDataSource> mLocalstore; static nsCOMPtr<nsIRDFDataSource> mLocalstore;
static nsCOMPtr<nsISupportsArray> mUpdateArray; static nsCOMPtr<nsISupportsArray> mUpdateArray;
nsCOMPtr<nsITimer> mTimer; nsCOMPtr<nsITimer> mTimer;
static nsCOMPtr<nsILoadGroup> mBackgroundLoadGroup; static nsCOMPtr<nsILoadGroup> mBackgroundLoadGroup;
static nsCOMPtr<nsILoadGroup> mLoadGroup; static nsCOMPtr<nsILoadGroup> mLoadGroup;
static nsCOMPtr<nsIRDFDataSource> categoryDataSource; static nsCOMPtr<nsIRDFDataSource> categoryDataSource;
static nsCOMPtr<nsIPref> prefs; static nsCOMPtr<nsIPref> prefs;
PRBool busySchedule; PRBool busySchedule;
nsCOMPtr<nsIRDFResource> busyResource; nsCOMPtr<nsIRDFResource> busyResource;
nsString mQueryEncodingStr; nsString mQueryEncodingStr;
friend int PR_CALLBACK searchModePrefCallback(const char *pref, void *aClosure); friend int PR_CALLBACK searchModePrefCallback(const char *pref, void *aClosure);
// helper methods // helper methods
nsresult GetSearchEngineToPing(nsIRDFResource **theResource, nsCString &updateURL); nsresult GetSearchEngineToPing(nsIRDFResource **theResource, nsCString &updateURL);
PRBool isEngineURI(nsIRDFResource* aResource); PRBool isEngineURI(nsIRDFResource* aResource);
PRBool isSearchURI(nsIRDFResource* aResource); PRBool isSearchURI(nsIRDFResource* aResource);
PRBool isSearchCategoryURI(nsIRDFResource* aResource); PRBool isSearchCategoryURI(nsIRDFResource* aResource);
PRBool isSearchCategoryEngineURI(nsIRDFResource* aResource); PRBool isSearchCategoryEngineURI(nsIRDFResource* aResource);
PRBool isSearchCategoryEngineBasenameURI(nsIRDFNode *aResource); PRBool isSearchCategoryEngineBasenameURI(nsIRDFNode *aResource);
PRBool isSearchCommand(nsIRDFResource* aResource); PRBool isSearchCommand(nsIRDFResource* aResource);
nsresult resolveSearchCategoryEngineURI(nsIRDFResource *source, nsIRDFResource **trueEngine); nsresult resolveSearchCategoryEngineURI(nsIRDFResource *source, nsIRDFResource **trueEngine);
nsresult BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest); nsresult BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest);
nsresult FindData(nsIRDFResource *engine, nsIRDFLiteral **data); nsresult FindData(nsIRDFResource *engine, nsIRDFLiteral **data);
nsresult updateDataHintsInGraph(nsIRDFResource *engine, const PRUnichar *data); nsresult updateDataHintsInGraph(nsIRDFResource *engine, const PRUnichar *data);
nsresult updateAtom(nsIRDFDataSource *db, nsIRDFResource *src, nsIRDFResource *prop, nsIRDFNode *newValue, PRBool *dirtyFlag); nsresult updateAtom(nsIRDFDataSource *db, nsIRDFResource *src, nsIRDFResource *prop, nsIRDFNode *newValue, PRBool *dirtyFlag);
nsresult validateEngine(nsIRDFResource *engine); nsresult validateEngine(nsIRDFResource *engine);
nsresult DoSearch(nsIRDFResource *source, nsIRDFResource *engine, const nsString &fullURL, const nsString &text); nsresult DoSearch(nsIRDFResource *source, nsIRDFResource *engine, const nsString &fullURL, const nsString &text);
nsresult MapEncoding(const nsString &numericEncoding, nsString &stringEncoding); nsresult MapEncoding(const nsString &numericEncoding, nsString &stringEncoding);
nsresult SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool checkMacFileType); nsresult SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool checkMacFileType);
nsresult GetSearchEngineList(nsIFile *spec, PRBool checkMacFileType); nsresult GetSearchEngineList(nsIFile *spec, PRBool checkMacFileType);
nsresult GetCategoryList(); nsresult GetCategoryList();
nsresult GetSearchFolder(nsIFile **spec); nsresult GetSearchFolder(nsIFile **spec);
nsresult ReadFileContents(const nsFileSpec &baseFilename, nsString & sourceContents); nsresult ReadFileContents(const nsFileSpec &baseFilename, nsString & sourceContents);
nsresult GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value); nsresult GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value);
nsresult GetNumInterpretSections(const PRUnichar *data, PRUint32 &numInterpretSections); nsresult GetNumInterpretSections(const PRUnichar *data, PRUint32 &numInterpretSections);
nsresult GetInputs(const PRUnichar *data, nsString &userVar, const nsString &text, nsString &input); nsresult GetInputs(const PRUnichar *data, nsString &userVar, const nsString &text, nsString &input);
nsresult GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult); nsresult GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
nsresult validateEngineNow(nsIRDFResource *engine); nsresult validateEngineNow(nsIRDFResource *engine);
nsresult webSearchFinalize(nsIChannel *channel, nsIInternetSearchContext *context); nsresult webSearchFinalize(nsIChannel *channel, nsIInternetSearchContext *context);
nsresult ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const PRUnichar *htmlPage); nsresult ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const PRUnichar *htmlPage);
nsresult SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes); nsresult SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes);
nsresult ConvertEntities(nsString &str, PRBool removeHTMLFlag = PR_TRUE, PRBool removeCRLFsFlag = PR_TRUE, PRBool trimWhiteSpaceFlag = PR_TRUE); nsresult ConvertEntities(nsString &str, PRBool removeHTMLFlag = PR_TRUE, PRBool removeCRLFsFlag = PR_TRUE, PRBool trimWhiteSpaceFlag = PR_TRUE);
nsresult saveContents(nsIChannel* channel, nsIInternetSearchContext *context, PRUint32 contextType); nsresult saveContents(nsIChannel* channel, nsIInternetSearchContext *context, PRUint32 contextType);
char * getSearchURI(nsIRDFResource *src); char * getSearchURI(nsIRDFResource *src);
nsresult addToBookmarks(nsIRDFResource *src); nsresult addToBookmarks(nsIRDFResource *src);
nsresult filterResult(nsIRDFResource *src); nsresult filterResult(nsIRDFResource *src);
nsresult filterSite(nsIRDFResource *src); nsresult filterSite(nsIRDFResource *src);
nsresult clearFilters(void); nsresult clearFilters(void);
PRBool isSearchResultFiltered(const nsString &href); PRBool isSearchResultFiltered(const nsString &href);
static void FireTimer(nsITimer* aTimer, void* aClosure); static void FireTimer(nsITimer* aTimer, void* aClosure);
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIINTERNETSEARCHSERVICE NS_DECL_NSIINTERNETSEARCHSERVICE
NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIRDFDATASOURCE NS_DECL_NSIRDFDATASOURCE
NS_DECL_NSIOBSERVER NS_DECL_NSIOBSERVER
InternetSearchDataSource(void); InternetSearchDataSource(void);
virtual ~InternetSearchDataSource(void); virtual ~InternetSearchDataSource(void);
NS_METHOD Init(); NS_METHOD Init();
NS_METHOD DeferredInit(); NS_METHOD DeferredInit();
}; };
#endif // nsinternetsearchdatasource__h____ #endif // nsinternetsearchdatasource__h____