Bug 393464 - Re-landing tag-search so search-in-folders (bug 384228) and related work could get the same sort of love. patch by dietrich, r=sspitzer, a=mconnor.

git-svn-id: svn://10.0.0.236/trunk@236045 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mozilla.mano%sent.com 2007-09-15 19:53:44 +00:00
parent 81587d6b25
commit 10ae818f9b
4 changed files with 62 additions and 2 deletions

View File

@ -91,3 +91,9 @@ interface nsITaggingService : nsISupports
*/
readonly attribute nsIVariant allTags;
};
%{C++
#define TAGGING_SERVICE_CID "@mozilla.org/browser/tagging-service;1"
%}

View File

@ -69,6 +69,9 @@
#include "prtime.h"
#include "prprf.h"
#include "nsEscape.h"
#include "nsITaggingService.h"
#include "nsIVariant.h"
#include "nsVariant.h"
#include "mozIStorageService.h"
#include "mozIStorageConnection.h"
@ -4096,6 +4099,45 @@ nsNavHistory::GroupByHost(nsNavHistoryQueryResultNode *aResultNode,
return NS_OK;
}
PRBool
nsNavHistory::URIHasTag(nsIURI* aURI, const nsAString& aTag)
{
nsresult rv;
nsCOMPtr<nsITaggingService> tagService =
do_GetService(TAGGING_SERVICE_CID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIVariant> tagsV;
rv = tagService->GetTagsForURI(aURI, getter_AddRefs(tagsV));
NS_ENSURE_SUCCESS(rv, rv);
// confirm that type is array, and has elements
// (data type is different for empty array)
PRUint16 dataType;
tagsV->GetDataType(&dataType);
if (dataType != nsIDataType::VTYPE_ARRAY)
return PR_FALSE;
// get tags as array
PRUint16 type;
nsIID iid;
PRUint32 count;
PRUnichar** tags;
rv = tagsV->GetAsArray(&type, &iid, &count, (void**)&tags);
NS_ENSURE_SUCCESS(rv, rv);
for (PRUint32 i = 0; i < count; i++) {
nsAutoString tag(tags[i]);
PRInt32 position = Compare(tag, aTag, nsCaseInsensitiveStringComparator());
if (position == 0) {
nsMemory::Free(tags);
return PR_TRUE;
}
}
nsMemory::Free(tags);
return PR_FALSE;
}
// nsNavHistory::FilterResultSet
//
@ -4161,6 +4203,7 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aParentNode,
if (terms.Count() == 0) {
allTermsFound = PR_TRUE;
} else {
for (PRInt32 termIndex = 0; termIndex < terms.Count(); termIndex ++) {
PRBool termFound = PR_FALSE;
// title and URL
@ -4170,6 +4213,7 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aParentNode,
CaseInsensitiveFindInReadable(*terms[termIndex],
NS_ConvertUTF8toUTF16(aSet[nodeIndex]->mURI))))
termFound = PR_TRUE;
// searchable annotations
/*if (! termFound) {
for (PRInt32 annotIndex = 0; annotIndex < curAnnotations.Count(); annotIndex ++) {
@ -4178,7 +4222,16 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aParentNode,
termFound = PR_TRUE;
}
}*/
if (! termFound) {
// search tags
if (!termFound) {
nsCOMPtr<nsIURI> itemURI;
rv = NS_NewURI(getter_AddRefs(itemURI), aSet[nodeIndex]->mURI);
NS_ENSURE_SUCCESS(rv, rv);
termFound = URIHasTag(itemURI, *terms[termIndex]);
}
if (!termFound) {
allTermsFound = PR_FALSE;
break;
}

View File

@ -511,6 +511,8 @@ protected:
nsCOMArray<nsNavHistoryResultNode>* aDest,
PRBool aIsDomain);
PRBool URIHasTag(nsIURI* aURI, const nsAString& aTag);
nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode,
const nsCOMArray<nsNavHistoryResultNode>& aSet,
nsCOMArray<nsNavHistoryResultNode>* aFiltered,

View File

@ -63,7 +63,6 @@ var root = bmsvc.bookmarksRoot;
// main
function run_test() {
return true;
// test searching for tagged bookmarks
// test folder