📄 contextbrowser.cpp
字号:
{ newMetaData = true; const QString timeString = KGlobal::locale()->formatTime( QTime::currentTime() ).replace(" ", " "); // don't break over lines m_metadataHistory.prepend( QString( "<td valign='top'>" + timeString + " </td><td align='left'>" + escapeHTML( bundle.prettyTitle() ) + "</td>" ) ); } if ( currentPage() == m_contextTab && ( bundle.url() != m_currentURL || newMetaData || !trackChanged ) ) showCurrentTrack(); else if ( currentPage() == m_lyricsTab ) { EngineController::engine()->isStream() ? lyricsRefresh() : // can't call showLyrics() because the url hasn't changed showLyrics() ; } else if ( CollectionDB::instance()->isEmpty() || !CollectionDB::instance()->isValid() ) showCurrentTrack(); if (trackChanged) { m_cuefile->clear(); if (bundle.url().isLocalFile()) { /** The cue file that is provided with the media might have different name than the * media file itself, hence simply cutting the media extension and adding ".cue" * is not always enough to find the matching cue file. In such cases we have * to search for all the cue files in the directory and have a look inside them for * the matching FILE="" stanza. However the FILE="" stanza does not always * point at the corresponding media file (e.g. it is quite often set to the misleading * FILE="audio.wav" WAV). Therfore we also have to check blindly if there is a cue * file having the same name as the media file played, as described above. */ // look for the cue file that matches the media file played first QString path = bundle.url().path(); QString cueFile = path.left( path.findRev('.') ) + ".cue"; m_cuefile->setCueFileName( cueFile ); if( m_cuefile->load( bundle.length() ) ) debug() << "[CUEFILE]: " << cueFile << " - Shoot blindly, found and loaded. " << endl; // if unlucky, let's have a look inside cue files, if any else { debug() << "[CUEFILE]: " << cueFile << " - Shoot blindly and missed, searching for other cue files." << endl; bool foundCueFile = false; QDir dir ( bundle.directory() ); dir.setFilter( QDir::Files ) ; dir.setNameFilter( "*.cue *.CUE" ) ; QStringList cueFilesList = dir.entryList(); if ( !cueFilesList.empty() ) for ( QStringList::Iterator it = cueFilesList.begin(); it != cueFilesList.end() && !foundCueFile; ++it ) { QFile file ( dir.filePath(*it) ); if( file.open( IO_ReadOnly ) ) { debug() << "[CUEFILE]: " << *it << " - Opened, looking for the matching FILE stanza." << endl; QTextStream stream( &file ); QString line; while ( !stream.atEnd() && !foundCueFile) { line = stream.readLine().simplifyWhiteSpace(); if( line.startsWith( "file", false ) ) { line = line.mid( 5 ).remove( '"' ); if ( line.contains( bundle.filename(), false ) ) { cueFile = dir.filePath(*it); foundCueFile = true; m_cuefile->setCueFileName( cueFile ); if( m_cuefile->load( bundle.length() ) ) debug() << "[CUEFILE]: " << cueFile << " - Looked inside cue files, found and loaded proper one" << endl; } } } file.close(); } } if ( !foundCueFile ) debug() << "[CUEFILE]: - Didn't find any matching cue file." << endl; } } }}void ContextBrowser::engineStateChanged( Engine::State state, Engine::State oldState ){ DEBUG_BLOCK if( state != Engine::Paused /*pause*/ && oldState != Engine::Paused /*resume*/ || state == Engine::Empty ) { // Pause shouldn't clear everything (but stop should, even when paused) m_dirtyCurrentTrackPage = true; m_dirtyLyricsPage = true; m_wikiJob = 0; //let's forget previous wiki-fetching jobs } switch( state ) { case Engine::Empty: m_metadataHistory.clear(); if ( currentPage() == m_contextTab || currentPage() == m_lyricsTab ) { showCurrentTrack(); } blockSignals( true ); setTabEnabled( m_lyricsTab, false ); if ( currentPage() != m_wikiTab ) { setTabEnabled( m_wikiTab, false ); m_dirtyWikiPage = true; } else // current tab is wikitab, disable some buttons. { m_wikiToolBar->setItemEnabled( WIKI_ARTIST, false ); m_wikiToolBar->setItemEnabled( WIKI_ALBUM, false ); m_wikiToolBar->setItemEnabled( WIKI_TITLE, false ); } blockSignals( false ); break; case Engine::Playing: if ( oldState != Engine::Paused ) m_metadataHistory.clear(); blockSignals( true ); setTabEnabled( m_lyricsTab, true ); setTabEnabled( m_wikiTab, true ); m_wikiToolBar->setItemEnabled( WIKI_ARTIST, true ); m_wikiToolBar->setItemEnabled( WIKI_ALBUM, true ); m_wikiToolBar->setItemEnabled( WIKI_TITLE, true ); blockSignals( false ); break; default: ; }}void ContextBrowser::saveHtmlData(){ QFile exportedDocument( Amarok::saveLocation() + "contextbrowser.html" ); if ( !exportedDocument.open( IO_WriteOnly ) ) warning() << "Failed to open file " << exportedDocument.name() << " write-only" << endl; else { QTextStream stream( &exportedDocument ); stream.setEncoding( QTextStream::UnicodeUTF8 ); stream << m_HTMLSource // the pure html data.. .replace( "<html>", QString( "<html><head><style type=\"text/css\">" "%1</style></head>" ) .arg( HTMLView::loadStyleSheet() ) ); // and the // stylesheet // code exportedDocument.close(); }}void ContextBrowser::paletteChange( const QPalette& /* pal */ ){// KTabWidget::paletteChange( pal ); HTMLView::paletteChange(); reloadStyleSheet();}void ContextBrowser::reloadStyleSheet(){ m_currentTrackPage->setUserStyleSheet( HTMLView::loadStyleSheet() ); m_lyricsPage->setUserStyleSheet( HTMLView::loadStyleSheet() ); m_wikiPage->setUserStyleSheet( HTMLView::loadStyleSheet() );}//////////////////////////////////////////////////////////////////////////////////////////// PROTECTED SLOTS////////////////////////////////////////////////////////////////////////////////////////////parts of this function from ktabwidget.cpp, copyright (C) 2003 Zack Rusin and Stephan Binner//fucking setCurrentTab() isn't virtual so we have to override this instead =(void ContextBrowser::wheelDelta( int delta ){ if ( count() < 2 || delta == 0 ) return; int index = currentPageIndex(), start = index; do { if( delta < 0 ) index = (index + 1) % count(); else { index = index - 1; if( index < 0 ) index = count() - 1; } if( index == start ) // full circle, none enabled return; } while( !isTabEnabled( page( index ) ) ); setCurrentPage( index );}//////////////////////////////////////////////////////////////////////////////////////////// PRIVATE SLOTS//////////////////////////////////////////////////////////////////////////////////////////void ContextBrowser::tabChanged( QWidget *page ){DEBUG_FUNC_INFO setFocusProxy( page ); //so focus is given to a sensible widget when the tab is opened if ( page == m_contextTab ) showCurrentTrack(); else if ( page == m_lyricsTab ) showLyrics(); else if ( page == m_wikiTab ) showWikipedia();}void ContextBrowser::slotContextMenu( const QString& urlString, const QPoint& point ){ enum { APPEND, ASNEXT, MAKE, MEDIA_DEVICE, INFO, TITLE, RELATED, SUGGEST, FAVES, FRESHPODCASTS, NEWALBUMS, FAVALBUMS, LABELS }; debug() << "url string: " << urlString << endl; if( urlString.startsWith( "musicbrainz" ) || urlString.startsWith( "externalurl" ) || urlString.startsWith( "show:suggest" ) || urlString.startsWith( "http" ) || urlString.startsWith( "wikipedia" ) || urlString.startsWith( "seek" ) || urlString.startsWith( "ggartist" ) || urlString.startsWith( "artistback" ) || urlString.startsWith( "current" ) || urlString.startsWith( "lastfm" ) || urlString.startsWith( "showlabel" ) || urlString.startsWith( "show:editLabels" ) || currentPage() != m_contextTab ) return; KURL url( urlString ); KPopupMenu menu; KURL::List urls( url ); QString artist, album, track; // track unused here Amarok::albumArtistTrackFromUrl( url.path(), artist, album, track ); if( urlString.isEmpty() ) { debug() << "url string empty. loaded?" << EngineController::engine()->loaded() << endl; if( EngineController::engine()->loaded() ) { menu.setCheckable( true ); menu.insertItem( i18n("Show Labels"), LABELS ); menu.insertItem( i18n("Show Related Artists"), RELATED ); menu.insertItem( i18n("Show Suggested Songs"), SUGGEST ); menu.insertItem( i18n("Show Favorite Tracks"), FAVES ); menu.setItemChecked( RELATED, m_showRelated ); menu.setItemChecked( SUGGEST, m_showSuggested ); menu.setItemChecked( FAVES, m_showFaves ); menu.setItemChecked( LABELS, m_showLabels ); } else { // the home info page menu.setCheckable( true ); menu.insertItem( i18n("Show Fresh Podcasts"), FRESHPODCASTS ); menu.insertItem( i18n("Show Newest Albums"), NEWALBUMS ); menu.insertItem( i18n("Show Favorite Albums"), FAVALBUMS ); menu.setItemChecked( FRESHPODCASTS, m_showFreshPodcasts ); menu.setItemChecked( NEWALBUMS, m_showNewestAlbums ); menu.setItemChecked( FAVALBUMS, m_showFavoriteAlbums ); } } else if( url.protocol() == "fetchcover" ) { Amarok::coverContextMenu( this, point, artist, album ); return; } else if( url.protocol() == "stream" ) { url = KURL::fromPathOrURL( url.url().replace( QRegExp( "^stream:" ), "http:" ) ); urls = KURL::List( url ); menu.insertTitle( i18n("Podcast"), TITLE ); menu.insertItem( SmallIconSet( Amarok::icon( "files" ) ), i18n( "&Load" ), MAKE ); menu.insertItem( SmallIconSet( Amarok::icon( "add_playlist" ) ), i18n( "&Append to Playlist" ), APPEND ); menu.insertItem( SmallIconSet( Amarok::icon( "queue_track" ) ), i18n( "&Queue Podcast" ), ASNEXT ); //menu.insertSeparator(); //menu.insertItem( SmallIconSet( "down" ), i18n( "&Download" ), DOWNLOAD ); } else if( url.protocol() == "file" || url.protocol() == "artist" || url.protocol() == "album" || url.protocol() == "compilation" || url.protocol() == "albumdisc" || url.protocol() == "compilationdisc") { //TODO it would be handy and more usable to have this menu under the cover one too menu.insertTitle( i18n("Track"), TITLE ); menu.insertItem( SmallIconSet( Amarok::icon( "files" ) ), i18n( "&Load" ), MAKE ); menu.insertItem( SmallIconSet( Amarok::icon( "add_playlist" ) ), i18n( "&Append to Playlist" ), APPEND ); menu.insertItem( SmallIconSet( Amarok::icon( "queue_track" ) ), i18n( "&Queue Track" ), ASNEXT ); if( MediaBrowser::isAvailable() ) menu.insertItem( SmallIconSet( Amarok::icon( "device" ) ), i18n( "&Transfer to Media Device" ), MEDIA_DEVICE ); menu.insertSeparator(); menu.insertItem( SmallIconSet( Amarok::icon( "info" ) ), i18n( "Edit Track &Information..." ), INFO ); if ( url.protocol() == "artist" ) { urls = expandURL( url ); menu.changeTitle( TITLE, i18n("Artist") ); menu.changeItem( INFO, i18n("Edit Artist &Information..." ) ); menu.changeItem( ASNEXT, i18n("&Queue Artist's Songs") );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -