📄 mediabrowser.cpp
字号:
case INVISIBLEROOT: case STALEROOT: case STALE: case ORPHANEDROOT: return false; case UNKNOWN: case TRACK: case ORPHANED: case INVISIBLE: case PODCASTITEM: case DIRECTORY: return true; } return false;}longMediaItem::size() const{ if( !isFileBacked() ) return 0; if( bundle() ) return bundle()->filesize(); return 0;}voidMediaItem::setType( Type type ){ m_type=type; setDragEnabled(true); setDropEnabled(false); switch(m_type) { case UNKNOWN: setPixmap(0, *s_pixUnknown); break; case INVISIBLE: case TRACK: setPixmap(0, *s_pixFile); break; case PLAYLISTITEM: setPixmap(0, *s_pixTrack); setDropEnabled(true); break; case ARTIST: setPixmap(0, *s_pixArtist); break; case ALBUM: setPixmap(0, *s_pixAlbum); break; case PODCASTSROOT: setPixmap(0, *s_pixRootItem); break; case PODCASTITEM: case PODCASTCHANNEL: setPixmap(0, *s_pixPodcast); break; case PLAYLIST: setPixmap(0, *s_pixPlaylist); setDropEnabled(true); break; case PLAYLISTSROOT: setPixmap(0, *s_pixRootItem); setDropEnabled( true ); break; case INVISIBLEROOT: setPixmap(0, *s_pixInvisible); break; case STALEROOT: case STALE: setPixmap(0, *s_pixStale); break; case ORPHANEDROOT: case ORPHANED: setPixmap(0, *s_pixOrphaned); break; case DIRECTORY: setExpandable( true ); setDropEnabled( true ); setPixmap(0, *s_pixDirectory); break; }}voidMediaItem::setFailed( bool failed ){ if( failed ) { m_flags &= ~MediaItem::Transferring; m_flags |= MediaItem::Failed; setPixmap(0, *MediaItem::s_pixTransferFailed); } else { m_flags &= ~MediaItem::Failed; if( m_type == PODCASTITEM ) setPixmap(0, *s_pixPodcast); else if( m_type == PLAYLIST ) setPixmap(0, *s_pixPlaylist); else setPixmap(0, QPixmap() ); }}MediaItem *MediaItem::lastChild() const{ QListViewItem *last = 0; for( QListViewItem *it = firstChild(); it; it = it->nextSibling() ) { last = it; } return dynamic_cast<MediaItem *>(last);}boolMediaItem::isLeafItem() const{ switch(type()) { case UNKNOWN: return false; case INVISIBLE: case TRACK: case PODCASTITEM: case PLAYLISTITEM: case STALE: case ORPHANED: return true; case ARTIST: case ALBUM: case PODCASTSROOT: case PODCASTCHANNEL: case PLAYLISTSROOT: case PLAYLIST: case INVISIBLEROOT: case STALEROOT: case ORPHANEDROOT: case DIRECTORY: return false; } return false;}MediaItem *MediaItem::findItem( const QString &key, const MediaItem *after ) const{ MediaItem *it = 0; if( after ) it = dynamic_cast<MediaItem *>( after->nextSibling() ); else it = dynamic_cast<MediaItem *>( firstChild() ); for( ; it; it = dynamic_cast<MediaItem *>(it->nextSibling())) { if(key == it->text(0)) return it; if(key.isEmpty() && it->text(0).isEmpty()) return it; } return 0;}intMediaItem::compare( QListViewItem *i, int col, bool ascending ) const{ MediaItem *item = dynamic_cast<MediaItem *>(i); if(item && col==0 && item->m_order != m_order) return m_order-item->m_order; else if( item && item->type() == MediaItem::ARTIST ) { QString key1 = key( col, ascending ); if( key1.startsWith( "the ", false ) ) key1 = key1.mid( 4 ); QString key2 = i->key( col, ascending ); if( key2.startsWith( "the ", false ) ) key2 = key2.mid( 4 ); return key1.localeAwareCompare( key2 ); } return KListViewItem::compare(i, col, ascending);}class MediaItemTip : public QToolTip{ public: MediaItemTip( QListView *listview ) : QToolTip( listview->viewport() ) , m_view( listview ) {} virtual ~MediaItemTip() {} protected: virtual void maybeTip( const QPoint &p ) { MediaItem *i = dynamic_cast<MediaItem *>(m_view->itemAt( m_view->viewportToContents( p ) ) ); if( !i ) return; QString text; switch( i->type() ) { case MediaItem::TRACK: { const MetaBundle *b = i->bundle(); if( b ) { if( b->track() ) text = QString( "%1 - %2 (%3)" ) .arg( QString::number(b->track()), b->title(), b->prettyLength() ); if( !b->genre().isEmpty() ) { if( !text.isEmpty() ) text += "<br>"; text += QString( "<i>Genre: %1</i>" ) .arg( b->genre() ); } } } break; case MediaItem::PLAYLISTSROOT: text = i18n( "Drag items here to create new playlist" ); break; case MediaItem::PLAYLIST: text = i18n( "Drag items here to append to this playlist" ); break; case MediaItem::PLAYLISTITEM: text = i18n( "Drag items here to insert before this item" ); break; case MediaItem::INVISIBLEROOT: case MediaItem::INVISIBLE: text = i18n( "Not visible on media device" ); break; case MediaItem::STALEROOT: case MediaItem::STALE: text = i18n( "In device database, but file is missing" ); break; case MediaItem::ORPHANEDROOT: case MediaItem::ORPHANED: text = i18n( "File on device, but not in device database" ); break; default: break; } if( !text.isEmpty() && !text.isNull() ) tip( m_view->itemRect( i ), text ); } QListView *m_view;};MediaView::MediaView( QWidget* parent, MediaDevice *device ) : KListView( parent ) , m_parent( parent ) , m_device( device ){ hide(); setSelectionMode( QListView::Extended ); setItemsMovable( false ); setShowSortIndicator( true ); setFullWidth( true ); setRootIsDecorated( true ); setDragEnabled( true ); setDropVisualizer( true ); //the visualizer (a line marker) is drawn when dragging over tracks setDropHighlighter( true ); //and the highligther (a focus rect) is drawn when dragging over playlists setDropVisualizerWidth( 3 ); setAcceptDrops( true ); header()->hide(); addColumn( i18n( "Remote Media" ) ); KActionCollection* ac = new KActionCollection( this ); KStdAction::selectAll( this, SLOT( selectAll() ), ac, "mediabrowser_select_all" ); connect( this, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), this, SLOT( rmbPressed( QListViewItem*, const QPoint&, int ) ) ); connect( this, SIGNAL( itemRenamed( QListViewItem* ) ), this, SLOT( renameItem( QListViewItem* ) ) ); connect( this, SIGNAL( expanded( QListViewItem* ) ), this, SLOT( slotExpand( QListViewItem* ) ) ); connect( this, SIGNAL( returnPressed( QListViewItem* ) ), this, SLOT( invokeItem( QListViewItem* ) ) ); connect( this, SIGNAL( doubleClicked( QListViewItem*, const QPoint&, int ) ), this, SLOT( invokeItem( QListViewItem*, const QPoint &, int ) ) ); m_toolTip = new MediaItemTip( this );}voidMediaView::keyPressEvent( QKeyEvent *e ){ if( e->key() == Key_Delete ) m_device->deleteFromDevice(); else KListView::keyPressEvent( e );}voidMediaView::invokeItem( QListViewItem* i, const QPoint& point, int column ) //SLOT{ if( column == -1 ) return; QPoint p = mapFromGlobal( point ); if ( p.x() > header()->sectionPos( header()->mapToIndex( 0 ) ) + treeStepSize() * ( i->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() || p.x() < header()->sectionPos( header()->mapToIndex( 0 ) ) ) invokeItem( i );}voidMediaView::invokeItem( QListViewItem *i ){ MediaItem *item = dynamic_cast<MediaItem *>( i ); if( !item ) return; KURL::List urls = nodeBuildDragList( item ); Playlist::instance()->insertMedia( urls, Playlist::DefaultOptions );}voidMediaView::renameItem( QListViewItem *item ){ m_device->renameItem( item );}voidMediaView::slotExpand( QListViewItem *item ){ m_device->expandItem( item );}MediaView::~MediaView(){ delete m_toolTip;}QDragObject *MediaView::dragObject(){ KURL::List urls = nodeBuildDragList( 0 ); KMultipleDrag *md = new KMultipleDrag( viewport() ); md->addDragObject( KListView::dragObject() ); KURLDrag* ud = new KURLDrag( urls, viewport() ); md->addDragObject( ud ); md->setPixmap( CollectionDB::createDragPixmap( urls ), QPoint( CollectionDB::DRAGPIXMAP_OFFSET_X, CollectionDB::DRAGPIXMAP_OFFSET_Y ) ); return md;}KURL::ListMediaView::nodeBuildDragList( MediaItem* item, int flags ){ KURL::List items; MediaItem* fi; if ( !item ) { fi = static_cast<MediaItem*>(firstChild()); } else fi = item; while ( fi ) { if( fi->isVisible() ) { if ( fi->isSelected() || !(flags & OnlySelected ) ) { if( fi->isLeafItem() || fi->type() == MediaItem::DIRECTORY ) items += fi->url(); else { if(fi->childCount() ) items += nodeBuildDragList( static_cast<MediaItem*>(fi->firstChild()), None ); } } else { if ( fi->childCount() ) items += nodeBuildDragList( static_cast<MediaItem*>(fi->firstChild()), OnlySelected ); } } fi = static_cast<MediaItem*>(fi->nextSibling()); } return items;}intMediaView::getSelectedLeaves( MediaItem *parent, QPtrList<MediaItem> *list, int flags ){ int numFiles = 0; if( !list ) list = new QPtrList<MediaItem>; MediaItem *it; if( !parent ) it = dynamic_cast<MediaItem *>(firstChild()); else it = dynamic_cast<MediaItem *>(parent->firstChild()); for( ; it; it = dynamic_cast<MediaItem*>(it->nextSibling())) { if( it->isVisible() ) { if( it->childCount() && !( it->type() == MediaItem::DIRECTORY && it->isSelected() ) ) { int f = flags; if( it->isSelected() ) f &= ~OnlySelected; numFiles += getSelectedLeaves(it, list, f ); } if( it->isSelected() || !(flags & OnlySelected) ) { if( it->type() == MediaItem::TRACK || it->type() == MediaItem::DIRECTORY || it->type() == MediaItem::PODCASTITEM || it->type() == MediaItem::PLAYLISTITEM|| it->type() == MediaItem::INVISIBLE || it->type() == MediaItem::ORPHANED ) { if( flags & OnlyPlayed ) { if( it->played() > 0 ) numFiles++; } else numFiles++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -