tagdialog.cpp
来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 1,499 行 · 第 1/4 页
CPP
1,499 行
// (c) 2004 Mark Kretschmann <markey@web.de>// (c) 2004 Pierpaolo Di Panfilo <pippo_dp@libero.it>// (c) 2005-2006 Alexandre Pereira de Oliveira <aleprj@gmail.com>// See COPYING file for licensing information.#include "amarok.h"#include "debug.h"#include "contextbrowser.h"#include "collectionbrowser.h"#include "collectiondb.h"#include "coverfetcher.h"#include "metabundle.h"#include "playlist.h"#include "playlistitem.h"#include "statusbar.h" //for status messages#include "tagdialog.h"#include "tagguesser.h"#include "tagguesserconfigdialog.h"#include "trackpickerdialog.h"#include <taglib/tfile.h> //TagLib::File::isWritable#include <qdom.h>#include <qfile.h>#include <qheader.h>#include <qlabel.h>#include <qlayout.h>#include <qpair.h>#include <qpushbutton.h>#include <qtooltip.h>#include <qvbox.h>#include <qcheckbox.h>#include <kapplication.h>#include <kcombobox.h>#include <kcursor.h>#include <kglobal.h>#include <khtmlview.h>#include <kiconloader.h>#include <ktabwidget.h>#include <ktextedit.h>#include <klineedit.h>#include <kmessagebox.h>#include <knuminput.h>#include <krun.h>#include <kstandarddirs.h>class TagDialogWriter : public ThreadManager::Job{public: TagDialogWriter( const QMap<QString, MetaBundle> tagsToChange ); bool doJob(); void completeJob();private: QValueList<bool> m_failed; QValueList<MetaBundle> m_tags; bool m_updateView; int m_successCount; int m_failCount; QStringList m_failedURLs;};TagDialog::TagDialog( const KURL& url, QWidget* parent ) : TagDialogBase( parent ) , m_bundle( url, true ) , m_playlistItem( 0 ) , m_currentCover( 0 ){ init();}TagDialog::TagDialog( const KURL::List list, QWidget* parent ) : TagDialogBase( parent ) , m_bundle() , m_playlistItem( 0 ) , m_urlList( list ) , m_currentCover( 0 ){ init();}TagDialog::TagDialog( const MetaBundle& mb, PlaylistItem* item, QWidget* parent ) : TagDialogBase( parent ) , m_bundle( mb ) , m_playlistItem( item ) , m_currentCover( 0 ){ init();}TagDialog::~TagDialog(){ Amarok::config( "TagDialog" )->writeEntry( "CurrentTab", kTabWidget->currentPageIndex() );}voidTagDialog::setTab( int id ){ kTabWidget->setCurrentPage( id );}////////////////////////////////////////////////////////////////////////////////// PRIVATE SLOTS////////////////////////////////////////////////////////////////////////////////voidTagDialog::cancelPressed() //SLOT{ QApplication::restoreOverrideCursor(); // restore the cursor before closing the dialog reject();}voidTagDialog::accept() //SLOT{ pushButton_ok->setEnabled( false ); //visual feedback saveTags(); QDialog::accept();}inline voidTagDialog::openPressed() //SLOT{ Amarok::invokeBrowser( m_path );}inline voidTagDialog::previousTrack(){ if( m_playlistItem ) { if( !m_playlistItem->itemAbove() ) return; storeTags(); m_playlistItem = static_cast<PlaylistItem *>( m_playlistItem->itemAbove() ); loadTags( m_playlistItem->url() ); } else { storeTags( *m_currentURL ); if( m_currentURL != m_urlList.begin() ) --m_currentURL; loadTags( *m_currentURL ); enableItems(); } readTags();}inline voidTagDialog::nextTrack(){ if( m_playlistItem ) { if( !m_playlistItem->itemBelow() ) return; storeTags(); m_playlistItem = static_cast<PlaylistItem *>( m_playlistItem->itemBelow() ); loadTags( m_playlistItem->url() ); } else { storeTags( *m_currentURL ); KURL::List::iterator next = m_currentURL; ++next; if( next != m_urlList.end() ) ++m_currentURL; loadTags( *m_currentURL ); enableItems(); } readTags();}inline voidTagDialog::perTrack(){ m_perTrack = !m_perTrack; if( m_perTrack ) { // just switched to per track mode applyToAllTracks(); setSingleTrackMode(); loadTags( *m_currentURL ); readTags(); } else { storeTags( *m_currentURL ); setMultipleTracksMode(); readMultipleTracks(); } enableItems();}voidTagDialog::enableItems(){ checkBox_perTrack->setChecked( m_perTrack ); pushButton_previous->setEnabled( m_perTrack && m_currentURL != m_urlList.begin() ); KURL::List::ConstIterator next = m_currentURL; ++next; pushButton_next->setEnabled( m_perTrack && next != m_urlList.end()); if( m_urlList.count() == 1 ) { checkBox_perTrack->setEnabled( false ); } else { checkBox_perTrack->setEnabled( true ); }}inline voidTagDialog::checkModified() //SLOT{ pushButton_ok->setEnabled( hasChanged() || storedTags.count() > 0 || storedScores.count() > 0 || storedLyrics.count() > 0 || storedRatings.count() > 0 || newLabels.count() > 0 );}voidTagDialog::loadCover( const QString &artist, const QString &album ){ if ( m_bundle.artist() != artist || m_bundle.album()!=album ) return; // draw the album cover on the dialog QString cover = CollectionDB::instance()->albumImage( m_bundle ); if( m_currentCover != cover ) { pixmap_cover->setPixmap( QPixmap( cover, "PNG" ) ); m_currentCover = cover; } pixmap_cover->setInformation( m_bundle.artist(), m_bundle.album() ); const int s = AmarokConfig::coverPreviewSize(); pixmap_cover->setMinimumSize( s, s ); pixmap_cover->setMaximumSize( s, s );}voidTagDialog::setFileNameSchemes() //SLOT{ TagGuesserConfigDialog* dialog = new TagGuesserConfigDialog(this, "child"); dialog->exec();}voidTagDialog::guessFromFilename() //SLOT{ TagGuesser guesser( m_bundle.url().path() ); if( !guesser.title().isNull() ) kLineEdit_title->setText( guesser.title() ); if( !guesser.artist().isNull() ) kComboBox_artist->setCurrentText( guesser.artist() ); if( !guesser.album().isNull() ) kComboBox_album->setCurrentText( guesser.album() ); if( !guesser.track().isNull() ) kIntSpinBox_track->setValue( guesser.track().toInt() ); if( !guesser.comment().isNull() ) kTextEdit_comment->setText( guesser.comment() ); if( !guesser.year().isNull() ) kIntSpinBox_year->setValue( guesser.year().toInt() ); if( !guesser.composer().isNull() ) kComboBox_composer->setCurrentText( guesser.composer() ); if( !guesser.genre().isNull() ) kComboBox_genre->setCurrentText( guesser.genre() );}voidTagDialog::musicbrainzQuery() //SLOT{#if HAVE_TUNEPIMP kdDebug() << k_funcinfo << endl; m_mbTrack = m_bundle.url(); KTRMLookup* ktrm = new KTRMLookup( m_mbTrack.path(), true ); connect( ktrm, SIGNAL( sigResult( KTRMResultList, QString ) ), SLOT( queryDone( KTRMResultList, QString ) ) ); connect( pushButton_cancel, SIGNAL( clicked() ), ktrm, SLOT( deleteLater() ) ); pushButton_musicbrainz->setEnabled( false ); pushButton_musicbrainz->setText( i18n( "Generating audio fingerprint..." ) ); QApplication::setOverrideCursor( KCursor::workingCursor() );#endif}voidTagDialog::queryDone( KTRMResultList results, QString error ) //SLOT{#if HAVE_TUNEPIMP if ( !error.isEmpty() ) { KMessageBox::sorry( this, i18n( "Tunepimp (MusicBrainz tagging library) returned the following error: \"%1\"." ).arg(error) ); } else { if ( !results.isEmpty() ) { TrackPickerDialog* t = new TrackPickerDialog( m_mbTrack.filename(), results, this ); t->show(); connect( t, SIGNAL( finished() ), SLOT( resetMusicbrainz() ) ); // clear m_mbTrack } else { KMessageBox::sorry( this, i18n( "The track was not found in the MusicBrainz database." ) ); resetMusicbrainz(); // clear m_mbTrack } } QApplication::restoreOverrideCursor(); pushButton_musicbrainz->setEnabled( true ); pushButton_musicbrainz->setText( m_buttonMbText );#else Q_UNUSED(results); Q_UNUSED(error);#endif}voidTagDialog::fillSelected( KTRMResult selected ) //SLOT{#if HAVE_TUNEPIMP kdDebug() << k_funcinfo << endl; if ( m_bundle.url() == m_mbTrack ) { if ( !selected.title().isEmpty() ) kLineEdit_title->setText( selected.title() ); if ( !selected.artist().isEmpty() ) kComboBox_artist->setCurrentText( selected.artist() ); if ( !selected.album().isEmpty() ) kComboBox_album->setCurrentText( selected.album() ); if ( selected.track() != 0 ) kIntSpinBox_track->setValue( selected.track() ); if ( selected.year() != 0 ) kIntSpinBox_year->setValue( selected.year() ); } else { MetaBundle mb; mb.setPath( m_mbTrack.path() ); if ( !selected.title().isEmpty() ) mb.setTitle( selected.title() ); if ( !selected.artist().isEmpty() ) mb.setArtist( selected.artist() ); if ( !selected.album().isEmpty() ) mb.setAlbum( selected.album() ); if ( selected.track() != 0 ) mb.setTrack( selected.track() ); if ( selected.year() != 0 ) mb.setYear( selected.year() ); storedTags.replace( m_mbTrack.path(), mb ); }#else Q_UNUSED(selected);#endif}void TagDialog::resetMusicbrainz() //SLOT{#if HAVE_TUNEPIMP m_mbTrack = "";#endif}////////////////////////////////////////////////////////////////////////////////// PRIVATE////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?