Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
inFileSearch Class Reference

#include <inFileSearch.h>

Inheritance diagram for inFileSearch:
Inheritance graph
[legend]
Collaboration diagram for inFileSearch:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_INISEARCHPROCESS
NS_DECL_INIFILESEARCH 
inFileSearch ()
virtual ~inFileSearch ()
unsigned long getDirectoryDepth (in nsIFile aDir)
nsISupportsArray getSubDirectories (in nsIFile aDir)
nsIFile getFileResultAt (in long aIndex)
void searchSync ()
void searchAsync (in inISearchObserver aObserver)
void searchStop ()
boolean searchStep ()
AString getStringResultAt (in long aIndex)
long getIntResultAt (in long aIndex)
unsigned long getUIntResultAt (in long aIndex)

Public Attributes

attribute wstring basePath
attribute boolean returnRelativePaths
attribute wstring filenameCriteria
attribute wstring textCriteria
attribute nsIFile searchPath
attribute boolean searchRecursive
readonly attribute unsigned long directoriesSearched
readonly attribute nsIFile currentDirectory
readonly attribute boolean isActive
readonly attribute long resultCount
attribute boolean holdResults

Protected Member Functions

nsresult InitSearch ()
nsresult KillSearch (PRInt16 aResult)
nsresult SearchDirectory (nsIFile *aDir, PRBool aIsSync)
nsresult PrepareResult (nsIFile *aFile, PRBool aIsSync)
nsresult InitSearchLoop ()
nsresult InitSubDirectoryStack ()
PRBool GetNextSubDirectory (nsIFile **aDir)
nsresult PushSubDirectoryOnStack (nsIFile *aDir)
already_AddRefed< nsIFileGetNextDirectory (nsISimpleEnumerator *aEnum)
PRBool MatchFile (nsIFile *aFile)
nsresult MakePathRelative (nsAString &aPath)
nsresult CountDirectoryDepth (nsIFile *aDir, PRUint32 *aDepth)

Static Protected Member Functions

static PRBool MatchPattern (PRUnichar *aPattern, PRUnichar *aString)
static PRBool AdvanceWildcard (PRUnichar **aString, PRUnichar *aNextChar)

Protected Attributes

nsCOMPtr< inISearchObservermObserver
nsCOMArray< nsIFilemResults
nsCOMArray< nsISimpleEnumeratormDirStack
nsCOMPtr< nsIFilemLastResult
nsCOMPtr< nsIFilemSearchPath
inSearchLoopmSearchLoop
nsAutoStringmBasePath
nsAutoStringmTextCriteria
PRUnichar ** mFilenameCriteria
PRUint32 mDirsSearched
PRUint32 mFilenameCriteriaCount
PRInt32 mResultCount
PRBool mIsActive
PRBool mHoldResults
PRBool mReturnRelativePaths
PRBool mSearchRecursive

Detailed Description

Definition at line 51 of file inFileSearch.h.


Constructor & Destructor Documentation

Definition at line 61 of file inFileSearch.cpp.

{
  delete mSearchLoop;
  delete mTextCriteria;
}

Member Function Documentation

PRBool inFileSearch::AdvanceWildcard ( PRUnichar **  aString,
PRUnichar aNextChar 
) [static, protected]

Definition at line 585 of file inFileSearch.cpp.

{
  PRUnichar* stringPtr = *aString;

  while (1) {
    if (*stringPtr == *aNextChar) {
      // we have found the next char after the wildcard, so return with success
      *aString = stringPtr;
      return PR_TRUE;
    } else if (*stringPtr == 0)
      return PR_FALSE;
    ++stringPtr;
  }
}

Here is the caller graph for this function:

nsresult inFileSearch::CountDirectoryDepth ( nsIFile aDir,
PRUint32 aDepth 
) [protected]

Definition at line 623 of file inFileSearch.cpp.

{
  ++(*aDepth);

  nsISimpleEnumerator* entries;
  aDir->GetDirectoryEntries(&entries);

  PRBool hasMoreElements;
  PRBool isDirectory;
  nsCOMPtr<nsIFile> entry;

  entries->HasMoreElements(&hasMoreElements);
  while (hasMoreElements) {
    entries->GetNext(getter_AddRefs(entry));
    entries->HasMoreElements(&hasMoreElements);

    entry->IsDirectory(&isDirectory);
    if (isDirectory) {
      CountDirectoryDepth(entry, aDepth);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

unsigned long inIFileSearch::getDirectoryDepth ( in nsIFile  aDir) [inherited]
nsIFile inIFileSearch::getFileResultAt ( in long  aIndex) [inherited]
long inISearchProcess::getIntResultAt ( in long  aIndex) [inherited]

Definition at line 513 of file inFileSearch.cpp.

{
  nsCOMPtr<nsIFile> file;
  nsCOMPtr<nsISupports> supports;
  PRBool isDir;
  PRBool hasMoreElements;

  while (PR_TRUE) {
    aEnum->HasMoreElements(&hasMoreElements);
    if (!hasMoreElements) 
      break;
    aEnum->GetNext(getter_AddRefs(supports));
    file = do_QueryInterface(supports);
    file->IsDirectory(&isDir);
    if (isDir)
      break;
  } 

  nsIFile* f = file.get();
  NS_IF_ADDREF(f);

  return isDir ? f : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 475 of file inFileSearch.cpp.

{
  // get the enumerator on top of the stack
  nsCOMPtr<nsISimpleEnumerator> nextDirs;
  while (PR_TRUE) {
    PRInt32 count = mDirStack.Count();
    // the stack is empty, so our search must be complete
    if (count == 0) return PR_FALSE;

    // get the next directory enumerator on the stack
    nextDirs = mDirStack[count-1];

    // get the next directory from the enumerator
    *aDir = GetNextDirectory(nextDirs).get();
  
    if (*aDir)  {
      // this enumerator is ready to rock, so let's move on
      return PR_TRUE;
    }

    // enumerator is done, so pop it off the stack
    mDirStack.RemoveObjectAt(count-1);
  } 

  
  return PR_TRUE;
}

Here is the call graph for this function:

AString inISearchProcess::getStringResultAt ( in long  aIndex) [inherited]
unsigned long inISearchProcess::getUIntResultAt ( in long  aIndex) [inherited]

Definition at line 379 of file inFileSearch.cpp.

Here is the call graph for this function:

Definition at line 454 of file inFileSearch.cpp.

Here is the call graph for this function:

Definition at line 467 of file inFileSearch.cpp.

{
  mDirStack.Clear();

  return NS_OK;
}

Here is the call graph for this function:

nsresult inFileSearch::KillSearch ( PRInt16  aResult) [protected]

Definition at line 390 of file inFileSearch.cpp.

{
  mIsActive = PR_TRUE;
  mObserver->OnSearchEnd(this, aResult);

  return NS_OK;
}
nsresult inFileSearch::MakePathRelative ( nsAString &  aPath) [protected]

Definition at line 604 of file inFileSearch.cpp.

{

  // get an nsAutoString version of the search path
  nsAutoString searchPath;
  mSearchPath->GetPath(searchPath);

  nsAutoString result;
  PRUint32 len = searchPath.Length();
  if (Substring(aPath, 0, len) == searchPath) {
    result = Substring(aPath, len+1, aPath.Length() - len - 1);
    result.ReplaceChar('\\', '/');
  }
  aPath = result;

  return NS_OK;
}

Here is the call graph for this function:

PRBool inFileSearch::MatchFile ( nsIFile aFile) [protected]

Definition at line 541 of file inFileSearch.cpp.

{
  nsAutoString fileName;
  aFile->GetLeafName(fileName);

  PRUnichar* fileNameUnicode = ToNewUnicode(fileName);
  
  PRBool match;

  for (PRUint32 i = 0; i < mFilenameCriteriaCount; ++i) {
    match = MatchPattern(mFilenameCriteria[i], fileNameUnicode);
    if (match) return PR_TRUE;
  }

  // XXX are we leaking fileNameUnicode?
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool inFileSearch::MatchPattern ( PRUnichar aPattern,
PRUnichar aString 
) [static, protected]

Definition at line 560 of file inFileSearch.cpp.

{
  PRInt32 index = 0;
  PRBool matching = PR_TRUE;
  char wildcard = '*';
  
  PRUnichar* patternPtr = aPattern;
  PRUnichar* stringPtr = aString;

  while (matching && *patternPtr && *stringPtr) {
    if (*patternPtr == wildcard) {
      matching = AdvanceWildcard(&stringPtr, patternPtr+1);
    } else {
      matching = *patternPtr == *stringPtr;
      ++stringPtr;
    }
    if (!matching) return PR_FALSE;
    ++patternPtr;
    ++index;
  }

  return matching;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult inFileSearch::PrepareResult ( nsIFile aFile,
PRBool  aIsSync 
) [protected]

Definition at line 438 of file inFileSearch.cpp.

{
  if (aIsSync || mHoldResults) {
    mResults.AppendObject(aFile);
  }

  if (!aIsSync) {
    ++mResultCount;
    mLastResult = aFile;
    mObserver->OnSearchResult(this);
  } 

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 504 of file inFileSearch.cpp.

{
  nsCOMPtr<nsISimpleEnumerator> entries;
  aDir->GetDirectoryEntries(getter_AddRefs(entries));
  mDirStack.AppendObject(entries);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult inFileSearch::SearchDirectory ( nsIFile aDir,
PRBool  aIsSync 
) [protected]

Definition at line 399 of file inFileSearch.cpp.

{
  ++mDirsSearched;

  // recurse through subdirectories
  nsISimpleEnumerator* entries;
  aDir->GetDirectoryEntries(&entries);

  if (!aIsSync) {
    // store this directory for next step in async search
    PushSubDirectoryOnStack(aDir);
  }
  
  PRBool hasMoreElements;
  PRBool isDirectory;
  nsCOMPtr<nsIFile> entry;

  entries->HasMoreElements(&hasMoreElements);
  while (hasMoreElements) {
    entries->GetNext(getter_AddRefs(entry));
    entries->HasMoreElements(&hasMoreElements);

    entry->IsDirectory(&isDirectory);
    if (isDirectory && aIsSync) {
      // this is a directory, so search it now (only if synchronous)
      if (aIsSync) 
        SearchDirectory(entry, aIsSync);
    } else {
      // this is a file, so see if it matches
      if (MatchFile(entry)) {
        PrepareResult(entry, aIsSync);
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

attribute wstring inIFileSearch::basePath [inherited]

Definition at line 46 of file inIFileSearch.idl.

Definition at line 62 of file inIFileSearch.idl.

readonly attribute unsigned long inIFileSearch::directoriesSearched [inherited]

Definition at line 61 of file inIFileSearch.idl.

Definition at line 55 of file inIFileSearch.idl.

Definition at line 59 of file inISearchProcess.idl.

Definition at line 49 of file inISearchProcess.idl.

Definition at line 68 of file inFileSearch.h.

Definition at line 71 of file inFileSearch.h.

Definition at line 64 of file inFileSearch.h.

Definition at line 70 of file inFileSearch.h.

Definition at line 72 of file inFileSearch.h.

Definition at line 75 of file inFileSearch.h.

Definition at line 74 of file inFileSearch.h.

Definition at line 65 of file inFileSearch.h.

Definition at line 62 of file inFileSearch.h.

Definition at line 73 of file inFileSearch.h.

Definition at line 63 of file inFileSearch.h.

Definition at line 76 of file inFileSearch.h.

Definition at line 67 of file inFileSearch.h.

Definition at line 66 of file inFileSearch.h.

Definition at line 77 of file inFileSearch.h.

Definition at line 69 of file inFileSearch.h.

Definition at line 52 of file inISearchProcess.idl.

Definition at line 49 of file inIFileSearch.idl.

Definition at line 57 of file inIFileSearch.idl.

Definition at line 58 of file inIFileSearch.idl.

Definition at line 56 of file inIFileSearch.idl.


The documentation for this class was generated from the following files: