tagdialog.cpp
来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 1,499 行 · 第 1/4 页
CPP
1,499 行
// Don't enable button if a query is in progress already (or if the file isn't local) pushButton_musicbrainz->setEnabled( m_bundle.url().isLocalFile() && m_mbTrack.isEmpty() );#else pushButton_musicbrainz->setEnabled( false );#endif if( m_playlistItem ) { pushButton_previous->setEnabled( m_playlistItem->itemAbove() ); pushButton_next->setEnabled( m_playlistItem->itemBelow() ); }}voidTagDialog::setMultipleTracksMode(){ kTabWidget->setTabEnabled( summaryTab, false ); kTabWidget->setTabEnabled( lyricsTab, false ); kComboBox_artist->setCurrentText( "" ); kComboBox_album->setCurrentText( "" ); kComboBox_genre->setCurrentText( "" ); kComboBox_composer->setCurrentText( "" ); kLineEdit_title->setText( "" ); kTextEdit_comment->setText( "" ); kIntSpinBox_track->setValue( kIntSpinBox_track->minValue() ); kIntSpinBox_discNumber->setValue( kIntSpinBox_discNumber->minValue() ); kIntSpinBox_year->setValue( kIntSpinBox_year->minValue() ); kIntSpinBox_score->setValue( kIntSpinBox_score->minValue() ); kComboBox_rating->setCurrentItem( 0 ); kLineEdit_title->setEnabled( false ); kIntSpinBox_track->setEnabled( false ); pushButton_musicbrainz->hide(); pushButton_guessTags->hide(); pushButton_setFilenameSchemes->hide(); locationLabel->hide(); kLineEdit_location->hide(); pushButton_open->hide(); pixmap_cover->hide();}voidTagDialog::setSingleTrackMode(){ kTabWidget->setTabEnabled( summaryTab, true ); kTabWidget->setTabEnabled( lyricsTab, true ); kLineEdit_title->setEnabled( true ); kIntSpinBox_track->setEnabled( true ); pushButton_musicbrainz->show(); pushButton_guessTags->show(); pushButton_setFilenameSchemes->show(); locationLabel->show(); kLineEdit_location->show(); pushButton_open->show(); pixmap_cover->show();}voidTagDialog::readMultipleTracks(){ setCaption( kapp->makeStdCaption( i18n("1 Track", "Information for %n Tracks", m_urlList.count()) ) ); //Check which fields are the same for all selected tracks const KURL::List::ConstIterator end = m_urlList.end(); KURL::List::ConstIterator it = m_urlList.begin(); m_bundle = MetaBundle(); MetaBundle first = bundleForURL( *it ); bool artist=true, album=true, genre=true, comment=true, year=true, score=true, rating=true, composer=true, discNumber=true; int songCount=0, ratingCount=0, ratingSum=0, scoreCount=0; float scoreSum = 0.f; for ( ; it != end; ++it ) { MetaBundle mb = bundleForURL( *it ); songCount++; if ( mb.rating() ) { ratingCount++; ratingSum+=mb.rating(); } if ( mb.score() > 0.f ) { scoreCount++; scoreSum+=mb.score(); } if( !mb.url().isLocalFile() ) { // If we have a non local file, don't even lose more time comparing artist = album = genre = comment = year = false; score = rating = composer = discNumber = false; continue; } if ( artist && mb.artist()!=first.artist() ) artist=false; if ( album && mb.album()!=first.album() ) album=false; if ( genre && mb.genre()!=first.genre() ) genre=false; if ( comment && mb.comment()!=first.comment() ) comment=false; if ( year && mb.year()!=first.year() ) year=false; if ( composer && mb.composer()!=first.composer() ) composer=false; if ( discNumber && mb.discNumber()!=first.discNumber() ) discNumber=false; if ( score && mb.score()!=first.score() ) score = false; if ( rating && mb.rating()!=first.rating() ) rating = false; } // Set them in the dialog and in m_bundle ( so we don't break hasChanged() ) if (artist) { m_bundle.setArtist( first.artist() ); kComboBox_artist->setCurrentText( first.artist() ); } if (album) { m_bundle.setAlbum( first.album() ); kComboBox_album->setCurrentText( first.album() ); } if (genre) { m_bundle.setGenre( first.genre() ); kComboBox_genre->setCurrentText( first.genre() ); } if (comment) { m_bundle.setComment( first.comment() ); kTextEdit_comment->setText( first.comment() ); } if (composer) { m_bundle.setComposer( first.composer() ); kComboBox_composer->setCurrentText( first.composer() ); } if (year) { m_bundle.setYear( first.year() ); kIntSpinBox_year->setValue( first.year() ); } if (discNumber) { m_bundle.setDiscNumber( first.discNumber() ); kIntSpinBox_discNumber->setValue( first.discNumber() ); } if (score) { m_bundle.setScore( first.score() ); kIntSpinBox_score->setValue( static_cast<int>( first.score() ) ); } if (rating) { m_bundle.setRating( first.rating() ); kComboBox_rating->setCurrentItem( first.rating() ); } m_currentURL = m_urlList.begin(); trackArtistAlbumLabel2->setText( i18n( "Editing 1 file", "Editing %n files", songCount ) ); const QString body = i18n( "<tr><td>Label:</td><td><b>Value</b></td></tr>", "<tr><td><nobr>%1:</nobr></td><td><b>%2</b></td></tr>" ); QString statisticsText = "<table>"; if( AmarokConfig::useRatings() ) { statisticsText += body.arg( i18n( "Rated Songs" ) , QString::number( ratingCount ) ); if ( ratingCount ) statisticsText += body.arg( i18n( "Average Rating" ) , QString::number( (float)ratingSum / (float)ratingCount/2.0, 'f', 1 ) ); } if( AmarokConfig::useRatings() ) { statisticsText += body.arg( i18n( "Scored Songs" ) , QString::number( scoreCount ) ); if ( scoreCount ) statisticsText += body.arg( i18n( "Average Score" ) , QString::number( scoreSum / scoreCount, 'f', 1 ) ); } statisticsText += "</table>"; statisticsLabel->setText( statisticsText ); QStringList commonLabels = getCommonLabels(); QString text; foreach ( commonLabels ) { if ( !text.isEmpty() ) text.append( ", " ); text.append( *it ); } kTextEdit_selectedLabels->setText( text ); m_commaSeparatedLabels = text; // This will reset a wrongly enabled Ok button checkModified();}QStringListTagDialog::getCommonLabels(){ DEBUG_BLOCK QMap<QString, int> counterMap; const KURL::List::ConstIterator end = m_urlList.end(); KURL::List::ConstIterator iter = m_urlList.begin(); for(; iter != end; ++iter ) { QStringList labels = labelsForURL( *iter ); foreach( labels ) { if ( counterMap.contains( *it ) ) counterMap[ *it ] = counterMap[ *it ] +1; else counterMap[ *it ] = 1; } } int n = m_urlList.count(); QStringList result; QMap<QString, int>::ConstIterator counterEnd( counterMap.end() ); for(QMap<QString, int>::ConstIterator it = counterMap.begin(); it != counterEnd; ++it ) { if ( it.data() == n ) result.append( it.key() ); } return result;}inline boolequalString( const QString &a, const QString &b ){ return (a.isEmpty() && b.isEmpty()) ? true : a == b;}boolTagDialog::hasChanged(){ return changes();}intTagDialog::changes(){ int result=TagDialog::NOCHANGE; bool modified = false; modified |= !equalString( kComboBox_artist->lineEdit()->text(), m_bundle.artist() ); modified |= !equalString( kComboBox_album->lineEdit()->text(), m_bundle.album() ); modified |= !equalString( kComboBox_genre->lineEdit()->text(), m_bundle.genre() ); modified |= kIntSpinBox_year->value() != m_bundle.year(); modified |= kIntSpinBox_discNumber->value() != m_bundle.discNumber(); modified |= !equalString( kComboBox_composer->lineEdit()->text(), m_bundle.composer() ); modified |= !equalString( kTextEdit_comment->text(), m_bundle.comment() ); if (!m_urlList.count() || m_perTrack) { //ignore these on MultipleTracksMode modified |= !equalString( kLineEdit_title->text(), m_bundle.title() ); modified |= kIntSpinBox_track->value() != m_bundle.track(); } if (modified) result |= TagDialog::TAGSCHANGED; if (kIntSpinBox_score->value() != m_bundle.score()) result |= TagDialog::SCORECHANGED; if (kComboBox_rating->currentItem() != ( m_bundle.rating() ) ) result |= TagDialog::RATINGCHANGED; if (!m_urlList.count() || m_perTrack) { //ignore these on MultipleTracksMode if ( !equalString( kTextEdit_lyrics->text(), m_lyrics ) ) result |= TagDialog::LYRICSCHANGED; } if ( !equalString( kTextEdit_selectedLabels->text(), m_commaSeparatedLabels ) ) result |= TagDialog::LABELSCHANGED; return result;}voidTagDialog::storeTags(){ storeTags( m_bundle.url() );}voidTagDialog::storeTags( const KURL &kurl ){ int result = changes(); QString url = kurl.path(); if( result & TagDialog::TAGSCHANGED ) { MetaBundle mb( m_bundle ); mb.setTitle( kLineEdit_title->text() ); mb.setComposer( kComboBox_composer->currentText() ); mb.setArtist( kComboBox_artist->currentText() ); mb.setAlbum( kComboBox_album->currentText() ); mb.setComment( kTextEdit_comment->text() ); mb.setGenre( kComboBox_genre->currentText() ); mb.setTrack( kIntSpinBox_track->value() ); mb.setYear( kIntSpinBox_year->value() ); mb.setDiscNumber( kIntSpinBox_discNumber->value() ); mb.setLength( m_bundle.length() ); mb.setBitrate( m_bundle.bitrate() ); mb.setSampleRate( m_bundle.sampleRate() ); storedTags.replace( url, mb ); } if( result & TagDialog::SCORECHANGED ) storedScores.replace( url, kIntSpinBox_score->value() ); if( result & TagDialog::RATINGCHANGED ) storedRatings.replace( url, kComboBox_rating->currentItem() ); if( result & TagDialog::LYRICSCHANGED ) { if ( kTextEdit_lyrics->text().isEmpty() ) storedLyrics.replace( url, QString::null ); else { QDomDocument doc; QDomElement e = doc.createElement( "lyrics" ); e.setAttribute( "artist", kComboBox_artist->currentText() ); e.setAttribute( "title", kLineEdit_title->text() ); QDomText t = doc.createTextNode( kTextEdit_lyrics->text() ); e.appendChild( t ); doc.appendChild( e ); storedLyrics.replace( url, doc.toString() ); } } if( result & TagDialog::LABELSCHANGED ) { generateDeltaForLabelList( labelListFromText( kTextEdit_selectedLabels->text() ) ); QStringList tmpLabels; if ( newLabels.find( url ) != newLabels.end() ) tmpLabels = newLabels[ url ]; else tmpLabels = originalLabels[ url ]; //apply delta foreach( m_removedLabels ) { tmpLabels.remove( *it ); } foreach( m_addedLabels ) { if( tmpLabels.find( *it ) == tmpLabels.end() ) tmpLabels.append( *it ); } newLabels.replace( url, tmpLabels ); }}voidTagDialog::storeTags( const KURL &url, int changes, const MetaBundle &mb ){ if ( changes & TagDialog::TAGSCHANGED ) storedTags.replace( url.path(), mb ); if ( changes & TagDialog::SCORECHANGED ) storedScores.replace( url.path(), mb.score() ); if ( changes & TagDialog::RATINGCHANGED ) storedRatings.replace( url.path(), mb.rating() );}voidTagDialog::storeLabels( const KURL &url, const QStringList &labels ){ newLabels.replace( url.path(), labels );}voidTagDialog::loadTags( const KURL &url ){ m_bundle = bundleForURL( url ); loadLyrics( url ); loadLabels( url );}voidTagDialog::loadLyrics( const KURL &url ){ QString xml = lyricsForURL(url.path() );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?