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

void KCacheReader::addItem (  ) [protected]

Use _fields to add one item to _tree.

Definition at line 271 of file kdirtreecache.cpp.

References KDirStat::KDirTree::childAddedNotify(), error(), KDirStat::KExcludeRules::excludeRules(), field(), fieldsCount(), KDirStat::KDirInfo::finalizeLocal(), KDirStat::KDirInfo::insertChild(), KDirStat::KDirTree::locate(), KDirStat::KFileInfo::locate(), KDirStat::KDirTree::root(), KDirStat::KDirTree::sendFinalizeLocal(), KDirStat::KDirInfo::setExcluded(), KDirStat::KDirInfo::setReadState(), KDirStat::KDirTree::setRoot(), and KDirStat::KFileInfo::url().

Referenced by read().

{
    if ( fieldsCount() < 4 )
    {
      _ok = false;
      emit error();
      return;
    }

    int n = 0;
    char * type         = field( n++ );
    char * raw_path     = field( n++ );
    char * size_str     = field( n++ );
    char * mtime_str    = field( n++ );
    char * blocks_str   = 0;
    char * links_str    = 0;

    while ( fieldsCount() > n+1 )
    {
      char * keyword    = field( n++ );
      char * val_str    = field( n++ );

      if ( strcasecmp( keyword, "blocks:" ) == 0 ) blocks_str = val_str;
      if ( strcasecmp( keyword, "links:"  ) == 0 ) links_str  = val_str;
    }


    // Type

    mode_t mode = S_IFREG;

    if      ( strcasecmp( type, "F"        ) == 0 )   mode = S_IFREG;
    else if ( strcasecmp( type, "D"        ) == 0 )   mode = S_IFDIR;
    else if ( strcasecmp( type, "L"        ) == 0 )   mode = S_IFLNK;
    else if ( strcasecmp( type, "BlockDev" ) == 0 )   mode = S_IFBLK;
    else if ( strcasecmp( type, "CharDev"  ) == 0 )   mode = S_IFCHR;
    else if ( strcasecmp( type, "FIFO"     ) == 0 )   mode = S_IFIFO;
    else if ( strcasecmp( type, "Socket"   ) == 0 )   mode = S_IFSOCK;


    // Path

    if ( *raw_path == '/' )
      _lastDir = 0;



    // Size

    char * end = 0;
    KFileSize size = strtoll( size_str, &end, 10 );

    if ( end )
    {
      switch ( *end )
      {
          case 'K':     size *= KB; break;
          case 'M':     size *= MB; break;
          case 'G':     size *= GB; break;
          default: break;
      }
    }


    // MTime

    time_t mtime = strtol( mtime_str, 0, 0 );


    // Blocks

    KFileSize blocks = blocks_str ? strtoll( blocks_str, 0, 10 ) : -1;


    // Links

    int links = links_str ? atoi( links_str ) : 1;


    //
    // Create a new item
    //

    char * raw_name = raw_path;

    if ( *raw_path == '/' && _tree->root() )
    {
      // Split raw_path in path + name

      raw_name = strrchr( raw_path, '/' );

      if ( raw_name )
          *raw_name++ = 0;    // Overwrite the last '/' with 0 byte - split string there
      else              // No '/' found
          raw_name = raw_path;
    }

    QString path = KUrl::decode_string( QString::fromLatin1( raw_path ) );
    QString name = KUrl::decode_string( QString::fromLatin1( raw_name ) );

    if ( _lastExcludedDir )
    {
      if ( path.startsWith( _lastExcludedDirUrl ) )
      {
          // kdDebug() << "Excluding " << path << "/" << name << endl;
          return;
      }
    }

    // Find parent in tree
    
    KDirInfo * parent = _lastDir;

    if ( ! parent && _tree->root() )
    {
      // Try the easy way first - the starting point of this cache

      if ( _toplevel )
          parent = dynamic_cast<KDirInfo *> ( _toplevel->locate( path ) );


      // Fallback: Search the entire tree

      if ( ! parent )
          parent = dynamic_cast<KDirInfo *> ( _tree->locate( path ) );


      if ( ! parent )   // Still nothing?
      {
#if 0
          kdError() << _fileName << ":" << _lineNo << ": "
                  << "Could not locate parent " << path << endl;
#endif

          return; // Ignore this cache line completely
      }
    }

    if ( strcasecmp( type, "D" ) == 0 )
    {
      // kdDebug() << "Creating KDirInfo  for " << name << endl;
      KDirInfo * dir = new KDirInfo( _tree, parent, name,
                               mode, size, mtime );
      dir->setReadState( KDirCached );
      _lastDir = dir;

      if ( parent )
          parent->insertChild( dir );

      if ( ! _tree->root() )
      {
          _tree->setRoot( dir );
          _toplevel = dir;
      }

      if ( ! _toplevel )
          _toplevel = dir;

      _tree->childAddedNotify( dir );

      if ( dir != _toplevel )
      {
          if ( KExcludeRules::excludeRules()->match( dir->url() ) )
          {
            // kdDebug() << "Excluding " << name << endl;
            dir->setExcluded();
            dir->setReadState( KDirOnRequestOnly );
            _tree->sendFinalizeLocal( dir );
            dir->finalizeLocal();

            _lastExcludedDir        = dir;
            _lastExcludedDirUrl     = _lastExcludedDir->url();
            _lastDir          = 0;
          }
      }
    }
    else
    {
      if ( parent )
      {
          // kdDebug() << "Creating KFileInfo for " << parent->debugUrl() << "/" << name << endl;

          KFileInfo * item = new KFileInfo( _tree, parent, name,
                                    mode, size, mtime,
                                    blocks, links );
          parent->insertChild( item );
          _tree->childAddedNotify( item );
      }
      else
      {
          kdError() << _fileName << ":" << _lineNo << ": "
                  << "No parent for item " << name << endl;
      }
    }
}

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