void KMSearch::start()
{
  //close all referenced folders
  QList<QPointer<KMFolder> >::Iterator fit;
  for ( fit = mOpenedFolders.begin(); fit != mOpenedFolders.end(); ++fit ) {
    if ( !(*fit) ) {
      continue;
    }
    (*fit)->close( "kmsearch" );
  }
  mOpenedFolders.clear();
  mFolders.clear();

  if ( running() ) {
    return;
  }

  if ( !mSearchPattern ) {
    emit finished( true );
    return;
  }

  mFoundCount = 0;
  mSearchCount = 0;
  mRunning = true;

  mFolders.append( mRoot );
  if ( recursive() ) {
    //Append all descendants to folders
    KMFolder *folder;
    for ( int i = 0; i < mFolders.size(); i++ ) {
      folder = mFolders[i];
      KMFolderDir *dir = 0;
      if ( folder ) {
        dir = folder->child();
      } else {
        dir = &kmkernel->folderMgr()->dir();
      }
      if ( !dir ) {
        continue;
      }

      QListIterator<KMFolderNode*> it( *dir );
      while ( it.hasNext() ) {
        KMFolderNode *node = it.next();
        if ( !node->isDir() ) {
          KMFolder* kmf = dynamic_cast<KMFolder*>( node );
          if ( kmf ) {
            mFolders.append( kmf );
          }
        }
      }
    }
  }

  mRemainingFolders = mFolders.count();
  mLastFolder.clear();
  mProcessNextBatchTimer->start( 0 );
}
void CopyFolderJob::slotCopyNextChild( bool success )
{
  if ( mNextChildFolder )
    mNextChildFolder->close( "copyfolder" ); // refcount
  // previous sibling failed
  if ( !success ) {
    kDebug() << "Failed to copy one subfolder, let's not continue:" << mNewFolder->prettyUrl();
    rollback();
    emit folderCopyComplete( false );
    deleteLater();
  }

  //Attempt to find the next child folder which is not a directory
  KMFolderNode* node = 0;
  bool folderFound = false;
  if ( mHasChildFolders )
    for ( ; mChildFolderNodeIterator != mStorage->folder()->child()->end();
          ++mChildFolderNodeIterator ) {
      node = *mChildFolderNodeIterator;
      if ( !node->isDir() ) {
        folderFound = true;
        break;
      }
    }

  if ( folderFound ) {
    mNextChildFolder = static_cast<KMFolder*>(node);
    ++mChildFolderNodeIterator;
  } else {
    // no more children, we are done
    emit folderCopyComplete( true );
    deleteLater();
    return;
  }

  KMFolderDir * const dir = mNewFolder->createChildFolder();
  if ( !dir ) {
    kDebug() << "Failed to create subfolders of:" << mNewFolder->prettyUrl();
    emit folderCopyComplete( false );
    deleteLater();
    return;
  }
  // let it do its thing and report back when we are ready to do the next sibling
  mNextChildFolder->open( "copyfolder" ); // refcount
  FolderJob* job = new CopyFolderJob( mNextChildFolder->storage(), dir);
  connect( job, SIGNAL( folderCopyComplete( bool ) ),
           this, SLOT( slotCopyNextChild( bool ) ) );
  job->start();
}
Beispiel #3
0
KMFolder* Utils::findStandardResourceFolder( KMFolderDir* folderParentDir,
                                             KMail::FolderContentsType contentsType,
                                             const QStringList &attributes )
{
  QMap<int, QString> typeMap;
  typeMap.insert( KMail::ContentsTypeCalendar, "IPF.Appointment" );
  typeMap.insert( KMail::ContentsTypeContact, "IPF.Contact" );
  typeMap.insert( KMail::ContentsTypeNote, "IPF.StickyNote" );
  typeMap.insert( KMail::ContentsTypeTask, "IPF.Task" );

  if ( !typeMap.contains( contentsType ) )
    return 0;

  for ( uint i = 0; i < attributes.count(); ++i ) {
    FolderAttributeParser parser( attributes[ i ] );
    if ( parser.folderClass() == typeMap[ contentsType ] ) {
      KMFolderNode* node = folderParentDir->hasNamedFolder( parser.folderName() );
      if ( node && !node->isDir() )
        return static_cast<KMFolder*>( node );
    }
  }

  return 0;
}