void OrganizeCollectionDialog::slotUpdatePreview() { DEBUG_BLOCK; QString formatString = buildFormatString(); m_trackOrganizer->setAsciiOnly( m_optionsWidget->asciiOnly() ); m_trackOrganizer->setFolderPrefix( ui->folderCombo->currentText() ); m_trackOrganizer->setFormatString( formatString ); m_trackOrganizer->setTargetFileExtension( m_targetFileExtension ); m_trackOrganizer->setPostfixThe( m_optionsWidget->postfixThe() ); m_trackOrganizer->setReplaceSpaces( m_optionsWidget->replaceSpaces() ); m_trackOrganizer->setReplace( m_optionsWidget->regexpText(), m_optionsWidget->replaceText() ); m_trackOrganizer->setVfatSafe( m_optionsWidget->vfatCompatible() ); //empty the table, not only it's contents ui->previewTableWidget->setRowCount( 0 ); m_trackOrganizer->resetTrackOffset(); m_conflict = false; setCursor( Qt::BusyCursor ); previewNextBatch(); }
void OrganizeCollectionDialog::previewNextBatch() //private slot { const int batchSize = 10; QMap<Meta::TrackPtr, QString> dests = m_trackOrganizer->getDestinations( batchSize ); QMapIterator<Meta::TrackPtr, QString> it( dests ); while( it.hasNext() ) { it.next(); Meta::TrackPtr track = it.key(); QString originalPath = track->prettyUrl(); QString newPath = it.value(); int newRow = ui->previewTableWidget->rowCount(); ui->previewTableWidget->insertRow( newRow ); //new path preview in the 1st column QPalette p = ui->previewTableWidget->palette(); QTableWidgetItem *item = new QTableWidgetItem( newPath ); KColorScheme::adjustBackground( p, KColorScheme::NegativeBackground ); if( QFileInfo( newPath ).exists() ) { item->setBackgroundColor( p.color( QPalette::Base ) ); m_conflict = true; } ui->previewTableWidget->setItem( newRow, 0, item ); //original in the second column item = new QTableWidgetItem( originalPath ); ui->previewTableWidget->setItem( newRow, 1, item ); } if( m_conflict ) { if( ui->overwriteCheck->isChecked() ) ui->conflictLabel->setText( i18n( "There is a filename conflict, existing files will be overwritten." ) ); else ui->conflictLabel->setText( i18n( "There is a filename conflict, existing files will not be changed." ) ); } else ui->conflictLabel->setText(""); // we clear the text instead of hiding it to retain the layout spacing //non-blocking way of updating the preview table. if( dests.count() == batchSize ) QTimer::singleShot( 10, this, SLOT(previewNextBatch()) ); else unsetCursor(); // finished }
void OrganizeCollectionDialog::previewNextBatch() { const int batchSize = 100; QPalette negativePalette = ui->previewTableWidget->palette(); KColorScheme::adjustBackground( negativePalette, KColorScheme::NegativeBackground ); int processed = 0; while( !m_originals.isEmpty() && !m_previews.isEmpty() ) { QString originalPath = m_originals.takeFirst(); QString newPath = m_previews.takeFirst(); int newRow = ui->previewTableWidget->rowCount(); ui->previewTableWidget->insertRow( newRow ); // new path preview in the 1st column QTableWidgetItem *item = new QTableWidgetItem( newPath ); if( QFileInfo( m_previewPrefix + newPath ).exists() ) { item->setBackgroundColor( negativePalette.color( QPalette::Base ) ); m_conflict = true; } ui->previewTableWidget->setItem( newRow, 0, item ); //original in the second column item = new QTableWidgetItem( originalPath ); ui->previewTableWidget->setItem( newRow, 1, item ); processed++; if( processed >= batchSize ) { // yield some room to the other events in the main loop QTimer::singleShot( 0, this, SLOT(previewNextBatch()) ); return; } } // finished unsetCursor(); ui->previewTableWidget->setSortingEnabled( true ); slotOverwriteModeChanged(); // in fact, m_conflict may have changed }
void OrganizeCollectionDialog::processPreviewPaths() { QStringList originals; QStringList previews; QStringList commonOriginalPrefix; // common initial directories QStringList commonPreviewPrefix; // common initial directories QMap<Meta::TrackPtr, QString> destinations = m_trackOrganizer->getDestinations(); for( auto it = destinations.constBegin(); it != destinations.constEnd(); ++it ) { originals << it.key()->prettyUrl(); previews << it.value(); QStringList originalPrefix = originals.last().split( '/' ); originalPrefix.removeLast(); // we never include file name in the common prefix QStringList previewPrefix = previews.last().split( '/' ); previewPrefix.removeLast(); if( it == destinations.constBegin() ) { commonOriginalPrefix = originalPrefix; commonPreviewPrefix = previewPrefix; } else { int commonLength = 0; while( commonOriginalPrefix.size() > commonLength && originalPrefix.size() > commonLength && commonOriginalPrefix[ commonLength ] == originalPrefix[ commonLength ] ) { commonLength++; } commonOriginalPrefix = commonOriginalPrefix.mid( 0, commonLength ); commonLength = 0; while( commonPreviewPrefix.size() > commonLength && previewPrefix.size() > commonLength && commonPreviewPrefix[ commonLength ] == previewPrefix[ commonLength ] ) { commonLength++; } commonPreviewPrefix = commonPreviewPrefix.mid( 0, commonLength ); } } QString originalPrefix = commonOriginalPrefix.isEmpty() ? QString() : commonOriginalPrefix.join( "/" ) + '/'; m_previewPrefix = commonPreviewPrefix.isEmpty() ? QString() : commonPreviewPrefix.join( "/" ) + '/'; ui->previewTableWidget->horizontalHeaderItem( 1 )->setText( i18n( "Original: %1", originalPrefix ) ); ui->previewTableWidget->horizontalHeaderItem( 0 )->setText( i18n( "Preview: %1", m_previewPrefix ) ); m_originals.clear(); m_originals.reserve( originals.size() ); m_previews.clear(); m_previews.reserve( previews.size() ); for( int i = 0; i < qMin( originals.size(), previews.size() ); i++ ) { m_originals << originals.at( i ).mid( originalPrefix.length() ); m_previews << previews.at( i ).mid( m_previewPrefix.length() ); } QTimer::singleShot( 0, this, SLOT(previewNextBatch()) ); }