コード例 #1
0
K3bDataItem* K3bDirItem::takeDataItem( K3bDataItem* item )
{
  int x = m_children.findRef( item );
  if( x > -1 ) {
    K3bDataItem* item = m_children.take();
    updateSize( item, true );
    if( item->isDir() )
      updateFiles( -1*((K3bDirItem*)item)->numFiles(), -1*((K3bDirItem*)item)->numDirs()-1 );
    else
      updateFiles( -1, 0 );

    item->m_parentDir = 0;

    // inform the doc
    if( doc() )
      doc()->itemRemovedFromDir( this, item );

    if( item->isFile() ) {
      // restore the item imported from an old session
      if( static_cast<K3bFileItem*>(item)->replaceItemFromOldSession() )
	addDataItem( static_cast<K3bFileItem*>(item)->replaceItemFromOldSession() );
    }

    return item;
  }
  else
    return 0;
}
コード例 #2
0
K3bDataItem* K3bDirItem::findByPath( const QString& p )
{
  if( p.isEmpty() || p == "/" )
    return this;

  QString path = p;
  if( path.startsWith("/") )
    path = path.mid(1);
  int pos = path.find( "/" );
  if( pos < 0 )
    return find( path );
  else {
    // do it recursivly
    K3bDataItem* item = find( path.left(pos) );
    if( item && item->isDir() )
      return ((K3bDirItem*)item)->findByPath( path.mid( pos+1 ) );
    else
      return 0;
  }
}
コード例 #3
0
bool K3bIsoImager::writeJolietHideFile()
{
  delete m_jolietHideFile;
  m_jolietHideFile = new KTempFile();
  m_jolietHideFile->setAutoDelete(true);

  if( QTextStream* t = m_jolietHideFile->textStream() ) {

    K3bDataItem* item = m_doc->root();
    while( item ) {
      if( item->hideOnRockRidge() ) {
	if( !item->isDir() )  // hiding directories does not work (all dirs point to the dummy-dir but we could introduce a second hidden dummy dir)
	  *t << escapeGraftPoint( item->localPath() ) << endl;
      }
      item = item->nextSibling();
    }

    m_jolietHideFile->close();
    return true;
  }
  else
    return false;
}
コード例 #4
0
bool K3bDirItem::mkdir( const QString& dirPath )
{
  //
  // An absolut path always starts at the root item
  //
  if( dirPath[0] == '/' ) {
    if( parent() )
      return parent()->mkdir( dirPath );
    else
      return mkdir( dirPath.mid( 1 ) );
  }

  if( findByPath( dirPath ) )
    return false;

  QString restPath;
  QString dirName;
  int pos = dirPath.find( '/' );
  if( pos == -1 ) {
    dirName = dirPath;
  }
  else {
    dirName = dirPath.left( pos );
    restPath = dirPath.mid( pos+1 );
  }

  K3bDataItem* dir = find( dirName );
  if( !dir )
    dir = new K3bDirItem( dirName, doc(), this );
  else if( !dir->isDir() )
    return false;

  if( !restPath.isEmpty() )
    return static_cast<K3bDirItem*>(dir)->mkdir( restPath );

  return true;
}
コード例 #5
0
bool K3bIsoImager::writeSortWeightFile()
{
  delete m_sortWeightFile;
  m_sortWeightFile = new KTempFile();
  m_sortWeightFile->setAutoDelete(true);

  if( QTextStream* t = m_sortWeightFile->textStream() ) {
    //
    // We need to write the local path in combination with the sort weight
    // mkisofs will take care of multiple entries for one local file and always
    // use the highest weight
    //
    K3bDataItem* item = m_doc->root();
    while( (item = item->nextSibling()) ) {  // we skip the root here
      if( item->sortWeight() != 0 ) {
	if( m_doc->bootImages().containsRef( dynamic_cast<K3bBootItem*>(item) ) ) { // boot-image-backup-hack
	  *t << escapeGraftPoint( static_cast<K3bBootItem*>(item)->tempPath() ) << " " << item->sortWeight() << endl;
	}
	else if( item->isDir() ) {
	  //
	  // Since we use dummy dirs for all directories in the filesystem and mkisofs uses the local path
	  // for sorting we need to create a different dummy dir for every sort weight value.
	  //
	  *t << escapeGraftPoint( dummyDir( static_cast<K3bDirItem*>(item) ) ) << " " << item->sortWeight() << endl;
	}
	else
	  *t << escapeGraftPoint( item->localPath() ) << " " << item->sortWeight() << endl;
      }
    }

    m_sortWeightFile->close();
    return true;
  }
  else
    return false;
}
コード例 #6
0
void K3bDataUrlAddingDialog::slotCopyMoveItems()
{
  if( m_bCanceled )
    return;

  //
  // Pop first item from the item list
  //
  K3bDataItem* item = m_items.first().first;
  K3bDirItem* dir = m_items.first().second;
  m_items.remove( m_items.begin() );

  ++m_filesHandled;
  m_infoLabel->setText( item->k3bPath() );
  if( m_totalFiles == 0 )
    m_counterLabel->setText( QString("(%1)").arg(m_filesHandled) );
  else
    m_counterLabel->setText( QString("(%1/%2)").arg(m_filesHandled).arg(m_totalFiles) );


  if( dir == item->parent() ) {
    kdDebug() << "(K3bDataUrlAddingDialog) trying to move an item into its own parent dir." << endl;
  }
  else if( dir == item ) {
    kdDebug() << "(K3bDataUrlAddingDialog) trying to move an item into itselft." << endl;
  }
  else {
    //
    // Let's see if an item with that name alredy exists
    //
    if( K3bDataItem* oldItem = dir->find( item->k3bName() ) ) {
      //
      // reuse an existing dir: move all child items into the old dir
      //
      if( oldItem->isDir() && item->isDir() ) {
	const QPtrList<K3bDataItem>& cl = dynamic_cast<K3bDirItem*>( item )->children();
	for( QPtrListIterator<K3bDataItem> it( cl ); *it; ++it )
	  m_items.append( qMakePair( *it, dynamic_cast<K3bDirItem*>( oldItem ) ) );

	// FIXME: we need to remove the old dir item
      }

      //
      // we cannot replace files in the old session with dirs and vice versa (I think)
      // files are handled in K3bFileItem constructor and dirs handled above
      //
      else if( oldItem->isFromOldSession() &&
	       item->isDir() != oldItem->isDir() ) {
	QString newName;
	if( getNewName( newName, dir, newName ) ) {
	  if( m_copyItems )
	    item = item->copy();
	  item->setK3bName( newName );
	  dir->addDataItem( item );
	}
      }

      else if( m_bExistingItemsReplaceAll ) {
	//
	// if we replace an item from an old session K3bDirItem::addDataItem takes care
	// of replacing the item
	//
	if( !oldItem->isFromOldSession() )
	  delete oldItem;
	if( m_copyItems )
	  item = item->copy();
	dir->addDataItem( item );
      }

      else if( !m_bExistingItemsIgnoreAll ) {
	switch( K3bMultiChoiceDialog::choose( i18n("File already exists"),
					      i18n("<p>File <em>%1</em> already exists in "
						   "project folder <em>%2</em>.")
					      .arg( item->k3bName() )
					      .arg("/" + dir->k3bPath()),
					      QMessageBox::Warning,
					      this,
					      0,
					      6,
					      KGuiItem( i18n("Replace"),
							QString::null,
							i18n("Replace the existing file") ),
					      KGuiItem( i18n("Replace All"),
							QString::null,
							i18n("Always replace existing files") ),
					      KGuiItem( i18n("Ignore"),
							QString::null,
							i18n("Keep the existing file") ),
					      KGuiItem( i18n("Ignore All"),
							QString::null,
							i18n("Always keep the existing file") ),
					      KGuiItem( i18n("Rename"),
							QString::null,
							i18n("Rename the new file") ),
					      KStdGuiItem::cancel() ) ) {
	case 2: // replace all
	  m_bExistingItemsReplaceAll = true;
	  // fallthrough
	case 1: // replace
	  //
	  // if we replace an item from an old session K3bDirItem::addDataItem takes care
	  // of replacing the item
	  //
	  if( !oldItem->isFromOldSession() )
	    delete oldItem;
	  if( m_copyItems )
	    item = item->copy();
	  dir->addDataItem( item );
	  break;
	case 4: // ignore all
	  m_bExistingItemsIgnoreAll = true;
	  // fallthrough
	case 3: // ignore
	  // do nothing
	  break;
	case 5: {// rename
	  QString newName;
	  if( getNewName( newName, dir, newName ) ) {
	    if( m_copyItems )
	      item = item->copy();
	    item->setK3bName( newName );
	    dir->addDataItem( item );
	  }
	  break;
	}
	case 6: // cancel
	  slotCancel();
	  return;
	}
      }
    }

    //
    // No old item with the same name
    //
    else {
      if( m_copyItems )
	item = item->copy();
      dir->addDataItem( item );
    }
  }

  if( m_items.isEmpty() ) {
    m_dirSizeJob->cancel();
    accept();
  }
  else {
    updateProgress();
    QTimer::singleShot( 0, this, SLOT(slotCopyMoveItems()) );
  }
}
コード例 #7
0
int K3bIsoImager::writePathSpecForDir( K3bDirItem* dirItem, QTextStream& stream )
{
  if( !m_noDeepDirectoryRelocation && dirItem->depth() > 7 ) {
    kdDebug() << "(K3bIsoImager) found directory depth > 7. Enabling no deep directory relocation." << endl;
    m_noDeepDirectoryRelocation = true;
  }

  // now create the graft points
  int num = 0;
  for( QPtrListIterator<K3bDataItem> it( dirItem->children() ); it.current(); ++it ) {
    K3bDataItem* item = it.current();
    bool writeItem = item->writeToCd();

    if( item->isSymLink() ) {
      if( d->usedLinkHandling == Private::DISCARD_ALL ||
	  ( d->usedLinkHandling == Private::DISCARD_BROKEN &&
	    !item->isValid() ) )
	writeItem = false;

      else if( d->usedLinkHandling == Private::FOLLOW ) {
	QFileInfo f( K3b::resolveLink( item->localPath() ) );
	if( !f.exists() ) {
	  emit infoMessage( i18n("Could not follow link %1 to non-existing file %2. Skipping...")
			    .arg(item->k3bName())
			    .arg(f.filePath()), WARNING );
	  writeItem = false;
	}
	else if( f.isDir() ) {
	  emit infoMessage( i18n("Ignoring link %1 to folder %2. K3b is unable to follow links to folders.")
			    .arg(item->k3bName())
			    .arg(f.filePath()), WARNING );
	  writeItem = false;
	}
      }
    }
    else if( item->isFile() ) {
      QFileInfo f( item->localPath() );
      if( !f.exists() ) {
	emit infoMessage( i18n("Could not find file %1. Skipping...").arg(item->localPath()), WARNING );
	writeItem = false;
      }
      else if( !f.isReadable() ) {
	emit infoMessage( i18n("Could not read file %1. Skipping...").arg(item->localPath()), WARNING );
	writeItem = false;
      }
    }

    if( writeItem ) {
      num++;

      // some versions of mkisofs seem to have a bug that prevents to use filenames
      // that contain one or more backslashes
      if( item->writtenPath().contains("\\") )
	m_containsFilesWithMultibleBackslashes = true;


      if( item->isDir() ) {
	stream << escapeGraftPoint( item->writtenPath() )
	       << "="
	       << escapeGraftPoint( dummyDir( static_cast<K3bDirItem*>(item) ) ) << "\n";

	int x = writePathSpecForDir( dynamic_cast<K3bDirItem*>(item), stream );
	if( x >= 0 )
	  num += x;
	else
	  return -1;
      }
      else {
	writePathSpecForFile( static_cast<K3bFileItem*>(item), stream );
      }
    }
  }

  return num;
}