Logo Search packages:      
Sourcecode: k4dirstat version File versions  Download package

KFileInfo * KFileInfo::locate ( QString  url,
bool  findDotEntries = false 
) [virtual]

Locate a child somewhere in this subtree whose URL (i.e. complete path) matches the URL passed. Returns 0 if there is no such child.

Notice: This is a very expensive operation since the entire subtree is searched recursively.

Derived classes might or might not wish to overwrite this method; it's only advisable to do so if a derived class comes up with a different method than brute-force search all children.

'findDotEntries' specifies if locating "dot entries" (".../<Files>") is desired.

Definition at line 327 of file kfileinfo.cpp.

References dotEntry(), firstChild(), isDotEntry(), locate(), and next().

Referenced by KDirStat::KCacheReader::addItem(), locate(), and KDirStat::KDirTree::locate().

{
    if ( ! url.startsWith( _name ) )
      return 0;
    else                            // URL starts with this node's name
    {
      url.remove( 0, _name.length() );    // Remove leading name of this node

      if ( url.length() == 0 )            // Nothing left?
          return this;              // Hey! That's us!

      if ( url.startsWith( "/" ) )        // If the next thing a path delimiter,
          url.remove( 0, 1 );             // remove that leading delimiter.
      else                          // No path delimiter at the beginning
      {
          if ( _name.right(1) != "/" &&   // and this is not the root directory
             ! isDotEntry() )       // or a dot entry:
            return 0;               // This can't be any of our children.
      }


      // Search all children

      KFileInfo *child = firstChild();

      while ( child )
      {
          KFileInfo *foundChild = child->locate( url, findDotEntries );

          if ( foundChild )
            return foundChild;
          else
            child = child->next();
      }


      // Special case: The dot entry is requested.

      if ( findDotEntries && dotEntry() && url == "<Files>" )
          return dotEntry();

      // Search the dot entry if there is one - but only if there is no more
      // path delimiter left in the URL. The dot entry contains files only,
      // and their names may not contain the path delimiter, nor can they
      // have children. This check is not strictly necessary, but it may
      // speed up things a bit if we don't search the non-directory children
      // if the rest of the URL consists of several pathname components.

      if ( dotEntry() &&
           url.find ( "/" ) < 0 )   // No (more) "/" in this URL
      {
          return dotEntry()->locate( url, findDotEntries );
      }
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index