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

void KDirTree::refresh ( KFileInfo subtree = 0 ) [slot]

Refresh a subtree, i.e. read its contents from disk again.

The old subtree will be deleted and rebuilt from scratch, i.e. all pointers to elements within this subtree will become invalid (a subtreeDeleted() signal will be emitted to notify about that fact).

When 0 is passed, the entire tree will be refreshed, i.e. from the root element on.

This may sound stupid, but the parent must be told to unlink its child from the children list. The child cannot simply do this by itself in its destructor since at this point important parts of the object may already be destroyed, e.g., the virtual table - i.e. virtual methods won't work any more.

I just found that out the hard way by several hours of debugging. ;-}

Definition at line 167 of file kdirtree.cpp.

References addJob(), childAddedNotify(), childDeleted(), KDirStat::KDirInfo::deletingChild(), deletingChild(), finished(), KDirStat::KDirInfo::insertChild(), KDirStat::KFileInfo::isDir(), KDirStat::KFileInfo::isInSubtree(), KDirStat::KFileInfo::parent(), selectItem(), KDirStat::KFileInfo::setExcluded(), startingReading(), startReading(), KDirStat::KioDirReadJob::stat(), KDirStat::KLocalDirReadJob::stat(), and KDirStat::KFileInfo::url().

Referenced by KDirStat::KCleanup::execute(), KDirStat::KDirTreeView::refreshAll(), and KDirStat::KDirTreeView::refreshSelected().

{
    if ( ! _root )
      return;

    if ( ! subtree || ! subtree->parent() )     // Refresh all (from root)
    {
      startReading( fixedUrl( _root->url() ) );
    }
    else    // Refresh subtree
    {
      // Save some values from the old subtree.

      KUrl url          = subtree->url();
      KDirInfo * parent = subtree->parent();


      // Select nothing if the current selection is to be deleted

      if ( _selection && _selection->isInSubtree( subtree ) )
          selectItem( 0 );


      // Clear any old "excluded" status

      subtree->setExcluded( false );

      
      // Get rid of the old subtree.

      emit deletingChild( subtree );

      // kdDebug() << "Deleting subtree " << subtree << endl;

      /**
       * This may sound stupid, but the parent must be told to unlink its
       * child from the children list. The child cannot simply do this by
       * itself in its destructor since at this point important parts of the
       * object may already be destroyed, e.g., the virtual table -
       * i.e. virtual methods won't work any more.
       *
       * I just found that out the hard way by several hours of debugging. ;-}
       **/
      parent->deletingChild( subtree );
      delete subtree;
      emit childDeleted();

      _isBusy = true;
      emit startingReading();
      
      // Create new subtree root.

      subtree = ( _readMethod == KDirReadLocal ) ?
          KLocalDirReadJob::stat( url, this, parent ) : KioDirReadJob::stat( url, this, parent );

      // kdDebug() << "New subtree: " << subtree << endl;

      if ( subtree )
      {
          // Insert new subtree root into the tree hierarchy.

          parent->insertChild( subtree );
          childAddedNotify( subtree );

          if ( subtree->isDir() )
          {
            // Prepare reading this subtree's contents.

            KDirInfo *dir = (KDirInfo *) subtree;

            if ( _readMethod == KDirReadLocal )
                addJob( new KLocalDirReadJob( this, dir ) );
            else
                addJob( new KioDirReadJob( this, dir ) );
          }
          else
          {
            _isBusy = false;
            emit finished();
          }
      }
    }
}

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