collectionbrowser.cpp
来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 1,829 行 · 第 1/5 页
CPP
1,829 行
}}voidCollectionView::scanStarted() // SLOT{ Amarok::actionCollection()->action("update_collection")->setEnabled( false );}voidCollectionView::scanDone( bool changed ) //SLOT{ if( changed ) { renderView(true); } Amarok::actionCollection()->action("update_collection")->setEnabled( true );}voidCollectionView::slotEnsureSelectedItemVisible() //SLOT{ //Scroll to make sure the first selected item is visible //Find the first selected item QListViewItem *r=0; for ( QListViewItem *i = firstChild(); i && !r; i=i->nextSibling() ) { if ( i->isSelected() ) r = i; for ( QListViewItem *j = i->firstChild(); j && !r; j=j->nextSibling() ) { if ( j->isSelected() ) r = j; for ( QListViewItem *k = j->firstChild(); k && !r; k=k->nextSibling() ) { if ( k->isSelected() ) r = k; } } } if ( r ) { //We've found the selected item. Now let's refocus on it. //An elaborate agorithm to try to make as much as possible of the vicinity visible //It looks better if things end up consistently in one place. //So, scroll to the end so that we come at items from the bottom. if ( lastChild() ) ensureItemVisible( lastChild() ); //Create a reverse list of parents, grandparents etc. //Later we try to make the grandparents in view, then their children etc. //This means that the selected item has the most priority as it is done last. QValueStack<QListViewItem*> parents; while ( r ) { parents.push( r ); r = r->parent(); } while ( !parents.isEmpty() ) { //We would prefer the next item to be visible. if ( parents.top()->nextSibling() ) ensureItemVisible( parents.top()->nextSibling() ); //It's even more important the actual item is visible than the next one. ensureItemVisible( parents.top() ); parents.pop(); } }}voidCollectionView::slotExpand( QListViewItem* item ) //SLOT{ if ( !item || !item->isExpandable() ) return; int category = 0; QStringList values; QueryBuilder qb; bool c = false; bool SortbyTrackFirst = false; //Sort by track number first if album is in one of the categories, otherwise by track name first if ( m_cat1 == IdAlbum || m_cat2 == IdAlbum || m_cat3 == IdAlbum ) SortbyTrackFirst = true; // initialization for year - album mode QString tmptext; int VisYearAlbum = -1; int VisLabel = -1; int q_cat1=m_cat1; int q_cat2=m_cat2; int q_cat3=m_cat3; if( m_cat1 == IdVisYearAlbum || m_cat2 == IdVisYearAlbum || m_cat3 == IdVisYearAlbum ) { SortbyTrackFirst = true; if( m_cat1 == IdVisYearAlbum ) { VisYearAlbum = 1; q_cat1 = IdAlbum; } if( m_cat2 == IdVisYearAlbum ) { VisYearAlbum = 2; q_cat2 = IdAlbum; } if( m_cat3 == IdVisYearAlbum ) { VisYearAlbum = 3; q_cat3 = IdAlbum; } } if( m_cat1 == IdLabel || m_cat2 == IdLabel || m_cat3 == IdLabel ) { if( m_cat1 == IdLabel ) VisLabel = 1; if( m_cat2 == IdLabel ) VisLabel = 2; if ( m_cat3 == IdLabel ) VisLabel = 3; } if ( translateTimeFilter( timeFilter() ) > 0 ) qb.addFilter( QueryBuilder::tabSong, QueryBuilder::valCreateDate, QString().setNum( QDateTime::currentDateTime().toTime_t() - translateTimeFilter( timeFilter() ) ), QueryBuilder::modeGreater ); QString itemText; bool isUnknown; if ( dynamic_cast<CollectionItem*>( item ) ) { itemText = static_cast<CollectionItem*>( item )->getSQLText( 0 ); } else { debug() << "slotExpand in CollectionView of a non-CollectionItem" << endl; itemText = item->text( 0 ); } switch ( item->depth() ) { case 0: tmptext = itemText; isUnknown = tmptext.isEmpty(); if ( !static_cast<CollectionItem*>( item )->isSampler() ) { if ( m_cat1 == IdArtist ) qb.setOptions( QueryBuilder::optNoCompilations ); if( VisYearAlbum == 1 ) { tmptext = item->text( 0 ); QString year = tmptext.left( tmptext.find( i18n(" - ") ) ); yearAlbumCalc( year, tmptext ); qb.addMatch( QueryBuilder::tabYear, year, false, true ); if ( isUnknown ) tmptext = ""; } qb.addMatch( q_cat1, tmptext, false, true ); } else { qb.setOptions( QueryBuilder::optOnlyCompilations ); c = true; } if ( m_cat2 == QueryBuilder::tabSong ) { qb.addReturnValue( q_cat2, QueryBuilder::valTitle, true ); qb.addReturnValue( q_cat2, QueryBuilder::valURL ); if ( c ) qb.addReturnValue( QueryBuilder::tabArtist, QueryBuilder::valName, true ); if ( SortbyTrackFirst ) { qb.sortBy( q_cat2, QueryBuilder::valDiscNumber ); qb.sortBy( q_cat2, QueryBuilder::valTrack ); } if ( c ) qb.sortBy( QueryBuilder::tabArtist, QueryBuilder::valName ); qb.sortBy( q_cat2, QueryBuilder::valTitle ); if ( !SortbyTrackFirst ) { qb.sortBy( q_cat2, QueryBuilder::valDiscNumber ); qb.sortBy( q_cat2, QueryBuilder::valTrack ); } qb.sortBy( q_cat2, QueryBuilder::valURL ); } else { c = false; qb.addReturnValue( q_cat2, QueryBuilder::valName, true ); if( VisYearAlbum == 2 ) { qb.addReturnValue( QueryBuilder::tabYear, QueryBuilder::valName, true ); qb.sortBy( QueryBuilder::tabYear, QueryBuilder::valName ); } qb.sortBy( q_cat2, QueryBuilder::valName ); } category = m_cat2; break; case 1: tmptext = dynamic_cast<CollectionItem*>( item->parent() ) ? static_cast<CollectionItem*>( item->parent() )->getSQLText( 0 ) : item->parent()->text( 0 ); isUnknown = tmptext.isEmpty(); if( !static_cast<CollectionItem*>( item->parent() )->isSampler() ) { if ( m_cat1 == IdArtist ) qb.setOptions( QueryBuilder::optNoCompilations ); if( VisYearAlbum == 1 ) { tmptext = item->parent()->text( 0 ); QString year = tmptext.left( tmptext.find( i18n(" - ") ) ); yearAlbumCalc( year, tmptext ); qb.addMatch( QueryBuilder::tabYear, year, false, true ); if ( isUnknown ) tmptext = ""; } qb.addMatch( q_cat1, tmptext, false, true ); } else { qb.setOptions( QueryBuilder::optOnlyCompilations ); c = true; } tmptext = itemText; isUnknown = tmptext.isEmpty(); if( VisYearAlbum == 2 ) { tmptext = item->text( 0 ); QString year = tmptext.left( tmptext.find( i18n(" - ") ) ); yearAlbumCalc( year, tmptext ); qb.addMatch( QueryBuilder::tabYear, year, false, true ); if ( isUnknown ) tmptext = ""; } qb.addMatch( q_cat2, tmptext, false, true ); if( m_cat3 == QueryBuilder::tabSong ) { qb.addReturnValue( q_cat3, QueryBuilder::valTitle, true ); qb.addReturnValue( q_cat3, QueryBuilder::valURL ); if ( c ) qb.addReturnValue( QueryBuilder::tabArtist, QueryBuilder::valName, true ); if ( SortbyTrackFirst ) { qb.sortBy( q_cat3, QueryBuilder::valDiscNumber ); qb.sortBy( q_cat3, QueryBuilder::valTrack ); } if ( c ) qb.sortBy( QueryBuilder::tabArtist, QueryBuilder::valName ); qb.sortBy( q_cat3, QueryBuilder::valTitle ); if ( !SortbyTrackFirst ) { qb.sortBy( q_cat3, QueryBuilder::valDiscNumber ); qb.sortBy( q_cat3, QueryBuilder::valTrack ); } qb.sortBy( q_cat3, QueryBuilder::valURL ); } else { c = false; qb.addReturnValue( q_cat3, QueryBuilder::valName, true ); if( VisYearAlbum == 3 ) { qb.addReturnValue( QueryBuilder::tabYear, QueryBuilder::valName ); qb.sortBy( QueryBuilder::tabYear, QueryBuilder::valName ); } qb.sortBy( q_cat3, QueryBuilder::valName ); } category = m_cat3; break; case 2: tmptext = dynamic_cast<CollectionItem*> ( item->parent()->parent() ) ? static_cast<CollectionItem*>( item->parent()->parent() )->getSQLText( 0 ) : item->parent()->parent()->text( 0 ); isUnknown = tmptext.isEmpty(); if ( !static_cast<CollectionItem*>( item->parent()->parent() )->isSampler() ) { if ( m_cat1 == IdArtist ) qb.setOptions( QueryBuilder::optNoCompilations ); if( VisYearAlbum == 1 ) { tmptext = item->parent()->parent()->text( 0 ); QString year = tmptext.left( tmptext.find( i18n(" - ") ) ); yearAlbumCalc( year, tmptext ); qb.addMatch( QueryBuilder::tabYear, year, false, true ); if ( isUnknown ) tmptext = ""; } qb.addMatch( q_cat1, tmptext, false, true ); } else { qb.setOptions( QueryBuilder::optOnlyCompilations ); c = true; } tmptext = dynamic_cast<CollectionItem*>( item->parent() ) ? static_cast<CollectionItem*>( item->parent() )->getSQLText( 0 ) : item->parent()->text( 0 ); isUnknown = tmptext.isEmpty(); if( VisYearAlbum == 2 ) { tmptext = item->parent()->text( 0 ); QString year = tmptext.left( tmptext.find( i18n(" - ") ) ); yearAlbumCalc( year, tmptext ); qb.addMatch( QueryBuilder::tabYear, year, false, true ); if ( isUnknown ) tmptext = ""; } qb.addMatch( q_cat2, tmptext, false, true ); tmptext = itemText; isUnknown = tmptext.isEmpty(); if( VisYearAlbum == 3 ) { tmptext = item->text( 0 ); QString year = tmptext.left( tmptext.find( i18n(" - ") ) ); yearAlbumCalc( year, tmptext ); qb.addMatch( QueryBuilder::tabYear, year, false, true ); if ( isUnknown ) tmptext = ""; } qb.addMatch( q_cat3, tmptext, false, true ); qb.addReturnValue( QueryBuilder::tabSong, QueryBuilder::valTitle, true ); qb.addReturnValue( QueryBuilder::tabSong, QueryBuilder::valURL ); if( c ) qb.addReturnValue( QueryBuilder::tabArtist, QueryBuilder::valName, true ); if ( SortbyTrackFirst ) { qb.sortBy( QueryBuilder::tabSong, QueryBuilder::valDiscNumber ); qb.sortBy( QueryBuilder::tabSong, QueryBuilder::valTrack ); } if ( c ) qb.sortBy( QueryBuilder::tabArtist, QueryBuilder::valName ); qb.sortBy( QueryBuilder::tabSong, QueryBuilder::valTitle ); if ( !SortbyTrackFirst ) { qb.sortBy( QueryBuilder::tabSong, QueryBuilder::valDiscNumber ); qb.sortBy( QueryBuilder::tabSong, QueryBuilder::valTrack ); } qb.sortBy( QueryBuilder::tabSong, QueryBuilder::valURL ); category = IdNone; break; } qb.setGoogleFilter( q_cat1 | q_cat2 | q_cat3 | QueryBuilder::tabSong, m_filter );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?