[vlc-devel] [RFC 20/82] qt: remove legacy playlist model and view
Pierre Lamot
pierre at videolabs.io
Fri Feb 1 14:01:24 CET 2019
---
modules/gui/qt/Makefile.am | 20 -
.../gui/qt/components/playlist/playlist.cpp | 411 ------
.../gui/qt/components/playlist/playlist.hpp | 129 --
.../qt/components/playlist/playlist_item.cpp | 153 ---
.../qt/components/playlist/playlist_item.hpp | 97 --
.../qt/components/playlist/playlist_model.cpp | 1115 -----------------
.../qt/components/playlist/playlist_model.hpp | 182 ---
.../gui/qt/components/playlist/selector.cpp | 636 ----------
.../gui/qt/components/playlist/selector.hpp | 160 ---
modules/gui/qt/components/playlist/sorting.h | 138 --
.../qt/components/playlist/standardpanel.cpp | 842 -------------
.../qt/components/playlist/standardpanel.hpp | 147 ---
modules/gui/qt/components/playlist/views.cpp | 591 ---------
modules/gui/qt/components/playlist/views.hpp | 151 ---
.../gui/qt/components/playlist/vlc_model.cpp | 214 ----
.../gui/qt/components/playlist/vlc_model.hpp | 164 ---
modules/gui/qt/dialogs/playlist.cpp | 97 --
modules/gui/qt/dialogs/playlist.hpp | 63 -
18 files changed, 5310 deletions(-)
delete mode 100644 modules/gui/qt/components/playlist/playlist.cpp
delete mode 100644 modules/gui/qt/components/playlist/playlist.hpp
delete mode 100644 modules/gui/qt/components/playlist/playlist_item.cpp
delete mode 100644 modules/gui/qt/components/playlist/playlist_item.hpp
delete mode 100644 modules/gui/qt/components/playlist/playlist_model.cpp
delete mode 100644 modules/gui/qt/components/playlist/playlist_model.hpp
delete mode 100644 modules/gui/qt/components/playlist/selector.cpp
delete mode 100644 modules/gui/qt/components/playlist/selector.hpp
delete mode 100644 modules/gui/qt/components/playlist/sorting.h
delete mode 100644 modules/gui/qt/components/playlist/standardpanel.cpp
delete mode 100644 modules/gui/qt/components/playlist/standardpanel.hpp
delete mode 100644 modules/gui/qt/components/playlist/views.cpp
delete mode 100644 modules/gui/qt/components/playlist/views.hpp
delete mode 100644 modules/gui/qt/components/playlist/vlc_model.cpp
delete mode 100644 modules/gui/qt/components/playlist/vlc_model.hpp
delete mode 100644 modules/gui/qt/dialogs/playlist.cpp
delete mode 100644 modules/gui/qt/dialogs/playlist.hpp
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index ec1ccc86d4..c80da69165 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -56,7 +56,6 @@ libqt_plugin_la_SOURCES = \
gui/qt/adapters/seekpoints.cpp gui/qt/adapters/seekpoints.hpp \
gui/qt/adapters/chromaprint.cpp gui/qt/adapters/chromaprint.hpp \
gui/qt/adapters/variables.cpp gui/qt/adapters/variables.hpp \
- gui/qt/dialogs/playlist.cpp gui/qt/dialogs/playlist.hpp \
gui/qt/dialogs/bookmarks.cpp gui/qt/dialogs/bookmarks.hpp \
gui/qt/dialogs/preferences.cpp gui/qt/dialogs/preferences.hpp \
gui/qt/dialogs/mediainfo.cpp gui/qt/dialogs/mediainfo.hpp \
@@ -108,21 +107,8 @@ libqt_plugin_la_SOURCES = \
gui/qt/components/epg/EPGView.cpp gui/qt/components/epg/EPGView.hpp \
gui/qt/components/epg/EPGWidget.cpp \
gui/qt/components/epg/EPGWidget.hpp \
- gui/qt/components/playlist/views.cpp \
- gui/qt/components/playlist/views.hpp \
- gui/qt/components/playlist/vlc_model.cpp \
- gui/qt/components/playlist/vlc_model.hpp \
- gui/qt/components/playlist/playlist_model.cpp \
- gui/qt/components/playlist/playlist_model.hpp \
gui/qt/components/playlist/playlist_item.cpp \
gui/qt/components/playlist/playlist_item.hpp \
- gui/qt/components/playlist/standardpanel.cpp \
- gui/qt/components/playlist/standardpanel.hpp \
- gui/qt/components/playlist/playlist.cpp \
- gui/qt/components/playlist/playlist.hpp \
- gui/qt/components/playlist/selector.cpp \
- gui/qt/components/playlist/selector.hpp \
- gui/qt/components/playlist/sorting.h \
gui/qt/components/sout/profile_selector.cpp \
gui/qt/components/sout/profile_selector.hpp \
gui/qt/components/sout/sout_widgets.cpp \
@@ -188,7 +174,6 @@ nodist_libqt_plugin_la_SOURCES = \
gui/qt/adapters/seekpoints.moc.cpp \
gui/qt/adapters/chromaprint.moc.cpp \
gui/qt/adapters/variables.moc.cpp \
- gui/qt/dialogs/playlist.moc.cpp \
gui/qt/dialogs/bookmarks.moc.cpp \
gui/qt/dialogs/mediainfo.moc.cpp \
gui/qt/dialogs/extended.moc.cpp \
@@ -225,12 +210,7 @@ nodist_libqt_plugin_la_SOURCES = \
gui/qt/components/epg/EPGRuler.moc.cpp \
gui/qt/components/epg/EPGView.moc.cpp \
gui/qt/components/epg/EPGWidget.moc.cpp \
- gui/qt/components/playlist/views.moc.cpp \
- gui/qt/components/playlist/vlc_model.moc.cpp \
gui/qt/components/playlist/playlist_model.moc.cpp \
- gui/qt/components/playlist/playlist.moc.cpp \
- gui/qt/components/playlist/standardpanel.moc.cpp \
- gui/qt/components/playlist/selector.moc.cpp \
gui/qt/components/sout/profile_selector.moc.cpp \
gui/qt/components/sout/sout_widgets.moc.cpp \
gui/qt/util/animators.moc.cpp \
diff --git a/modules/gui/qt/components/playlist/playlist.cpp b/modules/gui/qt/components/playlist/playlist.cpp
deleted file mode 100644
index 4a7275fd4b..0000000000
--- a/modules/gui/qt/components/playlist/playlist.cpp
+++ /dev/null
@@ -1,411 +0,0 @@
-/*****************************************************************************
- * playlist.cpp : Custom widgets for the playlist
- ****************************************************************************
- * Copyright © 2007-2010 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Jean-Baptiste Kempf <jb at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * ( at your option ) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "components/playlist/playlist.hpp"
-#include "components/playlist/standardpanel.hpp" /* MainView */
-#include "components/playlist/selector.hpp" /* PLSelector */
-#include "components/playlist/playlist_model.hpp" /* PLModel */
-#include "components/interface_widgets.hpp" /* CoverArtLabel */
-
-#include "util/searchlineedit.hpp"
-
-#include "input_manager.hpp" /* art signal */
-#include "main_interface.hpp" /* DropEvent TODO remove this*/
-
-#include <QMenu>
-#include <QSignalMapper>
-#include <QSlider>
-#include <QStackedWidget>
-
-/**********************************************************************
- * Playlist Widget. The embedded playlist
- **********************************************************************/
-
-PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
- : QWidget( _par ), p_intf ( _p_i )
-{
-
- setContentsMargins( 0, 3, 0, 3 );
-
- QGridLayout *layout = new QGridLayout( this );
- layout->setMargin( 0 ); layout->setSpacing( 0 );
-
- /*******************
- * Left *
- *******************/
- /* We use a QSplitter for the left part */
- leftSplitter = new QSplitter( Qt::Vertical, this );
-
- /* Source Selector */
- selector = new PLSelector( this, p_intf );
- leftSplitter->addWidget( selector );
-
- /* Create a Container for the Art Label
- in order to have a beautiful resizing for the selector above it */
- artContainer = new QStackedWidget;
-
- /* Art label */
- CoverArtLabel *art = new CoverArtLabel( artContainer, p_intf );
- art->setToolTip( qtr( "Double click to get media information" ) );
- artContainer->addWidget( art );
-
- CONNECT( THEMIM->getIM(), artChanged( QString ),
- art, showArtUpdate( const QString& ) );
- CONNECT( THEMIM->getIM(), artChanged( input_item_t * ),
- art, showArtUpdate( input_item_t * ) );
-
- leftSplitter->addWidget( artContainer );
-
- /*******************
- * Right *
- *******************/
- /* Initialisation of the playlist */
- playlist_t * p_playlist = THEPL;
- PL_LOCK;
- playlist_item_t *p_root = p_playlist->p_playing;
- PL_UNLOCK;
-
- setMinimumWidth( 400 );
-
- PLModel *model = PLModel::getPLModel( p_intf );
-
- mainView = new StandardPLPanel( this, p_intf, p_root, selector, model );
-
- QHBoxLayout *topbarLayout = new QHBoxLayout();
- topbarLayout->setSpacing( 10 );
- layout->addLayout( topbarLayout, 0, 0 );
-
- /* Location Bar */
- locationBar = new LocationBar( model );
- locationBar->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
- topbarLayout->addWidget( locationBar );
- CONNECT( locationBar, invoked( const QModelIndex & ),
- mainView, browseInto( const QModelIndex & ) );
-
- /* Button to switch views */
- QToolButton *viewButton = new QToolButton( this );
- viewButton->setIcon( style()->standardIcon( QStyle::SP_FileDialogDetailedView ) );
- viewButton->setToolTip( qtr("Change playlistview") );
- topbarLayout->addWidget( viewButton );
-
- viewButton->setMenu( StandardPLPanel::viewSelectionMenu( mainView ));
- CONNECT( viewButton, clicked(), mainView, cycleViews() );
-
- /* Search */
- searchEdit = new SearchLineEdit( this );
- searchEdit->setMaximumWidth( 250 );
- searchEdit->setMinimumWidth( 80 );
- searchEdit->setToolTip( qtr("Search the playlist") );
- topbarLayout->addWidget( searchEdit );
- CONNECT( searchEdit, textChanged( const QString& ),
- mainView, search( const QString& ) );
- CONNECT( searchEdit, searchDelayedChanged( const QString& ),
- mainView, searchDelayed( const QString & ) );
-
- CONNECT( mainView, viewChanged( const QModelIndex& ),
- this, changeView( const QModelIndex &) );
-
- /* Connect the activation of the selector to a redefining of the PL */
- DCONNECT( selector, categoryActivated( playlist_item_t *, bool ),
- mainView, setRootItem( playlist_item_t *, bool ) );
- mainView->setRootItem( p_root, false );
- CONNECT( selector, SDCategorySelected(bool), mainView, setWaiting(bool) );
-
- /* */
- split = new QSplitter( this );
-
- /* Add the two sides of the QSplitter */
- split->addWidget( leftSplitter );
- split->addWidget( mainView );
-
- QList<int> sizeList;
- sizeList << 180 << 420 ;
- split->setSizes( sizeList );
- split->setStretchFactor( 0, 0 );
- split->setStretchFactor( 1, 3 );
- split->setCollapsible( 1, false );
- leftSplitter->setMaximumWidth( 250 );
-
- /* In case we want to keep the splitter information */
- // components shall never write there setting to a fixed location, may infer
- // with other uses of the same component...
- getSettings()->beginGroup("Playlist");
- split->restoreState( getSettings()->value("splitterSizes").toByteArray());
- leftSplitter->restoreState( getSettings()->value("leftSplitterGeometry").toByteArray() );
- getSettings()->endGroup();
-
- layout->addWidget( split, 1, 0, 1, -1 );
-
- setAcceptDrops( true );
- setWindowTitle( qtr( "Playlist" ) );
- setWindowRole( "vlc-playlist" );
- setWindowIcon( QApplication::windowIcon() );
-}
-
-PlaylistWidget::~PlaylistWidget()
-{
- getSettings()->beginGroup("Playlist");
- getSettings()->setValue( "splitterSizes", split->saveState() );
- getSettings()->setValue( "leftSplitterGeometry", leftSplitter->saveState() );
- getSettings()->endGroup();
- msg_Dbg( p_intf, "Playlist Destroyed" );
-}
-
-void PlaylistWidget::dropEvent( QDropEvent *event )
-{
- if( selector->getCurrentItemCategory() != IS_PL ) return;
-
- if( p_intf->p_sys->p_mi )
- p_intf->p_sys->p_mi->dropEventPlay( event, false );
-}
-void PlaylistWidget::dragEnterEvent( QDragEnterEvent *event )
-{
- event->acceptProposedAction();
-}
-
-void PlaylistWidget::closeEvent( QCloseEvent *event )
-{
- if( THEDP->isDying() )
- {
- p_intf->p_sys->p_mi->playlistVisible = true;
- event->accept();
- }
- else
- {
- p_intf->p_sys->p_mi->playlistVisible = false;
- hide();
- event->ignore();
- }
-}
-
-void PlaylistWidget::forceHide()
-{
- leftSplitter->hide();
- mainView->hide();
- updateGeometry();
-}
-
-void PlaylistWidget::forceShow()
-{
- leftSplitter->show();
- mainView->show();
- updateGeometry();
-}
-
-void PlaylistWidget::changeView( const QModelIndex& index )
-{
- locationBar->setIndex( index );
-}
-
-void PlaylistWidget::setSearchFieldFocus()
-{
- searchEdit->setFocus();
-}
-
-#include <QSignalMapper>
-#include <QMenu>
-#include <QPainter>
-LocationBar::LocationBar( VLCModel *m )
-{
- setModel( m );
- mapper = new QSignalMapper( this );
- CONNECT( mapper, mapped( int ), this, invoke( int ) );
-
- btnMore = new LocationButton( "...", false, true, this );
- menuMore = new QMenu( this );
- btnMore->setMenu( menuMore );
-}
-
-void LocationBar::setIndex( const QModelIndex &index )
-{
- qDeleteAll( buttons );
- buttons.clear();
- qDeleteAll( actions );
- actions.clear();
-
- QModelIndex i = index;
- bool first = true;
-
- while( true )
- {
- QString text = model->getTitle( i );
-
- QAbstractButton *btn = new LocationButton( text, first, !first, this );
- btn->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
- buttons.append( btn );
-
- QAction *action = new QAction( text, this );
- actions.append( action );
- CONNECT( btn, clicked(), action, trigger() );
-
- mapper->setMapping( action, model->itemId( i ) );
- CONNECT( action, triggered(), mapper, map() );
-
- first = false;
-
- if( i.isValid() ) i = i.parent();
- else break;
- }
-
- QString prefix;
- for( int a = actions.count() - 1; a >= 0 ; a-- )
- {
- actions[a]->setText( prefix + actions[a]->text() );
- prefix += QString(" ");
- }
-
- if( isVisible() ) layOut( size() );
-}
-
-void LocationBar::setRootIndex()
-{
- setIndex( QModelIndex() );
-}
-
-void LocationBar::invoke( int i_id )
-{
- QModelIndex index = model->indexByPLID( i_id, 0 );
- emit invoked ( index );
-}
-
-void LocationBar::layOut( const QSize& size )
-{
- menuMore->clear();
- widths.clear();
-
- int count = buttons.count();
- int totalWidth = 0;
- for( int i = 0; i < count; i++ )
- {
- int w = buttons[i]->sizeHint().width();
- widths.append( w );
- totalWidth += w;
- if( totalWidth > size.width() ) break;
- }
-
- int x = 0;
- int shown = widths.count();
-
- if( totalWidth > size.width() && count > 1 )
- {
- QSize sz = btnMore->sizeHint();
- btnMore->setGeometry( 0, 0, sz.width(), size.height() );
- btnMore->show();
- x = sz.width();
- totalWidth += x;
- }
- else
- {
- btnMore->hide();
- }
- for( int i = count - 1; i >= 0; i-- )
- {
- if( totalWidth <= size.width() || i == 0)
- {
- buttons[i]->setGeometry( x, 0, qMin( size.width() - x, widths[i] ), size.height() );
- buttons[i]->show();
- x += widths[i];
- totalWidth -= widths[i];
- }
- else
- {
- menuMore->addAction( actions[i] );
- buttons[i]->hide();
- if( i < shown ) totalWidth -= widths[i];
- }
- }
-}
-
-void LocationBar::resizeEvent ( QResizeEvent * event )
-{
- layOut( event->size() );
-}
-
-QSize LocationBar::sizeHint() const
-{
- return btnMore->sizeHint();
-}
-
-LocationButton::LocationButton( const QString &text, bool bold,
- bool arrow, QWidget * parent )
- : QPushButton( parent ), b_arrow( arrow )
-{
- QFont font;
- font.setBold( bold );
- setFont( font );
- setText( text );
-}
-
-#define PADDING 4
-
-void LocationButton::paintEvent ( QPaintEvent * )
-{
- QStyleOptionButton option;
- option.initFrom( this );
- option.state |= QStyle::State_Enabled;
- QPainter p( this );
-
- if( underMouse() )
- {
- p.save();
- p.setRenderHint( QPainter::Antialiasing, true );
- QColor c = palette().color( QPalette::Highlight );
- p.setPen( c );
- p.setBrush( c.lighter( 150 ) );
- p.setOpacity( 0.2 );
- p.drawRoundedRect( option.rect.adjusted( 0, 2, 0, -2 ), 5, 5 );
- p.restore();
- }
-
- QRect r = option.rect.adjusted( PADDING, 0, -PADDING - (b_arrow ? 10 : 0), 0 );
-
- QString str( text() );
- /* This check is absurd, but either it is not done properly inside elidedText(),
- or boundingRect() is wrong */
- if( r.width() < fontMetrics().size(Qt::TextHideMnemonic, text()).width() )
- str = fontMetrics().elidedText( text(), Qt::ElideRight, r.width(), Qt::TextHideMnemonic );
- p.drawText( r, Qt::AlignVCenter | Qt::AlignLeft | Qt::TextHideMnemonic , str );
-
- if( b_arrow )
- {
- option.rect.setWidth( 10 );
- option.rect.moveRight( rect().right() );
- style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p );
- }
-}
-
-QSize LocationButton::sizeHint() const
-{
- QSize s( fontMetrics().size( Qt::TextHideMnemonic, text() ) );
- /* Add two pixels to width: font metrics are buggy, if you pass text through elidation
- with exactly the width of its bounding rect, sometimes it still elides */
- s.setWidth( s.width() + ( 2 * PADDING ) + ( b_arrow ? 10 : 0 ) + 2 );
- s.setHeight( s.height() + 2 * PADDING );
- return s;
-}
-
-#undef PADDING
diff --git a/modules/gui/qt/components/playlist/playlist.hpp b/modules/gui/qt/components/playlist/playlist.hpp
deleted file mode 100644
index 94924395a1..0000000000
--- a/modules/gui/qt/components/playlist/playlist.hpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*****************************************************************************
- * playlist.hpp : Playlist Widgets
- ****************************************************************************
- * Copyright (C) 2006-2009 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Jean-Baptiste Kempf <jb at videolan.org>
- * Rafaël Carré <funman at videolanorg>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_PLAYLIST_HPP_
-#define VLC_QT_PLAYLIST_HPP_
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "qt.hpp"
-
-//#include <vlc_playlist_legacy.h>
-
-#include <QSplitter>
-
-#include <QPushButton>
-#include <QSplitterHandle>
-#include <QMouseEvent>
-
-class StandardPLPanel;
-class LocationBar;
-class QSignalMapper;
-class SearchLineEdit;
-class QModelIndex;
-class QStackedWidget;
-class PLSelector;
-
-class PlaylistWidget : public QWidget
-{
- Q_OBJECT
-public:
- virtual ~PlaylistWidget();
-
- void forceHide();
- void forceShow();
- void setSearchFieldFocus();
- QStackedWidget *artContainer;
- StandardPLPanel *mainView;
-
-private:
- QSplitter *leftSplitter;
- QSplitter *split;
-
- PLSelector *selector;
-
- LocationBar *locationBar;
- SearchLineEdit *searchEdit;
-
- intf_thread_t *p_intf;
-
-protected:
- PlaylistWidget( intf_thread_t *_p_i, QWidget * );
- void dropEvent( QDropEvent *) Q_DECL_OVERRIDE;
- void dragEnterEvent( QDragEnterEvent * ) Q_DECL_OVERRIDE;
- void closeEvent( QCloseEvent * ) Q_DECL_OVERRIDE;
-private slots:
- void changeView( const QModelIndex& index );
-
- friend class PlaylistDialog;
-};
-
-class LocationButton : public QPushButton
-{
-public:
- LocationButton( const QString &, bool bold, bool arrow, QWidget * parent = NULL );
- QSize sizeHint() const Q_DECL_OVERRIDE;
-protected:
- void paintEvent ( QPaintEvent * event ) Q_DECL_OVERRIDE;
-private:
- bool b_arrow;
-};
-
-class VLCModel;
-
-class LocationBar : public QWidget
-{
- Q_OBJECT
-public:
- LocationBar( VLCModel * );
- void setIndex( const QModelIndex & );
- void setModel( VLCModel * _model ) { model = _model; };
- QSize sizeHint() const Q_DECL_OVERRIDE;
-protected:
- void resizeEvent ( QResizeEvent * event ) Q_DECL_OVERRIDE;
-
-private:
- void layOut( const QSize& size );
-
- VLCModel *model;
- QSignalMapper *mapper;
- QWidgetList buttons;
- QList<QAction*> actions;
- LocationButton *btnMore;
- QMenu *menuMore;
- QList<int> widths;
-
-public slots:
- void setRootIndex();
-private slots:
- void invoke( int i_item_id );
-
-signals:
- void invoked( const QModelIndex & );
-};
-
-
-#endif
diff --git a/modules/gui/qt/components/playlist/playlist_item.cpp b/modules/gui/qt/components/playlist/playlist_item.cpp
deleted file mode 100644
index 6ebd9d3bfd..0000000000
--- a/modules/gui/qt/components/playlist/playlist_item.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*****************************************************************************
- * playlist_item.cpp : Manage playlist item
- ****************************************************************************
- * Copyright © 2006-2011 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Jean-Baptiste Kempf <jb at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <assert.h>
-
-#include "qt.hpp"
-#include "playlist_item.hpp"
-#include <vlc_input_item.h>
-
-/*************************************************************************
- * Playlist item implementation
- *************************************************************************/
-
-void AbstractPLItem::clearChildren()
-{
- qDeleteAll( children );
- children.clear();
-}
-
-void AbstractPLItem::removeChild( AbstractPLItem *item )
-{
- children.removeOne( item );
- delete item;
-}
-
-/*
- Playlist item is just a wrapper, an abstraction of the playlist_item
- in order to be managed by PLModel
-
- PLItem have a parent, and id and a input Id
-*/
-
-void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent )
-{
- parentItem = parent; /* Can be NULL, but only for the rootItem */
- i_playlist_id = _playlist_item->i_id; /* Playlist item specific id */
- p_input = _playlist_item->p_input;
- i_flags = _playlist_item->i_flags;
- input_item_Hold( p_input );
-}
-
-/*
- Constructors
- Call the above function init
- */
-PLItem::PLItem( playlist_item_t *p_item, PLItem *parent )
-{
- init( p_item, parent );
-}
-
-PLItem::PLItem( playlist_item_t * p_item )
-{
- init( p_item, NULL );
-}
-
-PLItem::~PLItem()
-{
- input_item_Release( p_input );
- qDeleteAll( children );
- children.clear();
-}
-
-int PLItem::id() const
-{
- return i_playlist_id;
-}
-
-void PLItem::takeChildAt( int index )
-{
- AbstractPLItem *child = children[index];
- child->parentItem = NULL;
- children.removeAt( index );
-}
-
-/* This function is used to get one's parent's row number in the model */
-int PLItem::row()
-{
- if( parentItem )
- return parentItem->indexOf( this );
- return 0;
-}
-
-bool PLItem::operator< ( AbstractPLItem& other )
-{
- AbstractPLItem *item1 = this;
- while( item1->parentItem )
- {
- AbstractPLItem *item2 = &other;
- while( item2->parentItem )
- {
- if( item1 == item2->parentItem ) return true;
- if( item2 == item1->parentItem ) return false;
- if( item1->parentItem == item2->parentItem )
- return item1->parentItem->indexOf( item1 ) <
- item1->parentItem->indexOf( item2 );
- item2 = item2->parentItem;
- }
- item1 = item1->parentItem;
- }
- return false;
-}
-
-QString PLItem::getURI() const
-{
- QString uri;
- vlc_mutex_lock( &p_input->lock );
- uri = QString( p_input->psz_uri );
- vlc_mutex_unlock( &p_input->lock );
- return uri;
-}
-
-QString PLItem::getTitle() const
-{
- QString title;
- char *fb_name = input_item_GetTitle( p_input );
- if( EMPTY_STR( fb_name ) )
- {
- free( fb_name );
- fb_name = input_item_GetName( p_input );
- }
- title = qfu(fb_name);
- free(fb_name);
- return title;
-}
-
-bool PLItem::readOnly() const
-{
- return i_flags & PLAYLIST_RO_FLAG;
-}
diff --git a/modules/gui/qt/components/playlist/playlist_item.hpp b/modules/gui/qt/components/playlist/playlist_item.hpp
deleted file mode 100644
index 62387786d8..0000000000
--- a/modules/gui/qt/components/playlist/playlist_item.hpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*****************************************************************************
- * playlist_item.hpp : Item for a playlist tree
- ****************************************************************************
- * Copyright (C) 2006-2011 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_PLAYLIST_ITEM_HPP_
-#define VLC_QT_PLAYLIST_ITEM_HPP_
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "qt.hpp"
-
-#include <QList>
-#include <QString>
-
-class AbstractPLItem
-{
- friend class PLItem; /* super ugly glue stuff */
- friend class MLItem;
- friend class VLCModel;
- friend class PLModel;
- friend class MLModel;
-
-public:
- virtual ~AbstractPLItem() {}
-
-protected:
- virtual int id( ) const = 0;
- int childCount() const { return children.count(); }
- int indexOf( AbstractPLItem *item ) const { return children.indexOf( item ); };
- int lastIndexOf( AbstractPLItem *item ) const { return children.lastIndexOf( item ); };
- AbstractPLItem *parent() { return parentItem; }
- virtual input_item_t *inputItem() = 0;
- void insertChild( AbstractPLItem *item, int pos = -1 ) { children.insert( pos, item ); }
- void appendChild( AbstractPLItem *item ) { insertChild( item, children.count() ); } ;
- virtual AbstractPLItem *child( int id ) const = 0;
- void removeChild( AbstractPLItem *item );
- void clearChildren();
- virtual QString getURI() const = 0;
- virtual QString getTitle() const = 0;
- virtual bool readOnly() const = 0;
-
- QList<AbstractPLItem *> children;
- AbstractPLItem *parentItem;
-};
-
-class PLItem : public AbstractPLItem
-{
- friend class PLModel;
-
-public:
- virtual ~PLItem();
- bool hasSameParent( PLItem *other ) { return parent() == other->parent(); }
- bool operator< ( AbstractPLItem& );
-
-private:
- /* AbstractPLItem */
- int id() const Q_DECL_OVERRIDE;
- input_item_t *inputItem() Q_DECL_OVERRIDE { return p_input; }
- AbstractPLItem *child( int id ) const Q_DECL_OVERRIDE { return children.value( id ); };
- virtual QString getURI() const Q_DECL_OVERRIDE;
- virtual QString getTitle() const Q_DECL_OVERRIDE;
- virtual bool readOnly() const Q_DECL_OVERRIDE;
-
- /* Local */
- PLItem( playlist_item_t *, PLItem *parent );
- int row();
- void takeChildAt( int );
-
- PLItem( playlist_item_t * );
- void init( playlist_item_t *, PLItem * );
- int i_playlist_id;
- int i_flags;
- input_item_t *p_input;
-};
-
-#endif
-
diff --git a/modules/gui/qt/components/playlist/playlist_model.cpp b/modules/gui/qt/components/playlist/playlist_model.cpp
deleted file mode 100644
index 38d4677760..0000000000
--- a/modules/gui/qt/components/playlist/playlist_model.cpp
+++ /dev/null
@@ -1,1115 +0,0 @@
-/*****************************************************************************
- * playlist_model.cpp : Manage playlist model
- ****************************************************************************
- * Copyright (C) 2006-2011 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Ilkka Ollakkka <ileoo (at) videolan dot org>
- * Jakob Leben <jleben at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "qt.hpp"
-#include "components/playlist/playlist_model.hpp"
-#include "input_manager.hpp" /* THEMIM */
-#include "util/qt_dirs.hpp"
-#include "recents.hpp" /* Open:: */
-
-#include <vlc_intf_strings.h> /* I_DIR */
-#include <vlc_url.h>
-
-#include "sorting.h"
-
-#include <assert.h>
-#include <QFont>
-#include <QAction>
-#include <QStack>
-
-/*************************************************************************
- * Playlist model implementation
- *************************************************************************/
-
-PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
- intf_thread_t *_p_intf, /* main Qt p_intf */
- playlist_item_t * p_root,
- QObject *parent ) /* Basic Qt parent */
- : VLCModel( _p_intf, parent )
-{
- p_playlist = _p_playlist;
-
- rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
- latestSearch = QString();
-
- rebuild( p_root );
- DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
- this, processInputItemUpdate( input_item_t *) );
- DCONNECT( THEMIM, inputChanged( bool ),
- this, processInputItemUpdate( ) );
- CONNECT( THEMIM, playlistItemAppended( int, int ),
- this, processItemAppend( int, int ) );
- CONNECT( THEMIM, playlistItemRemoved( int ),
- this, processItemRemoval( int ) );
-}
-
-PLModel::~PLModel()
-{
- delete rootItem;
-}
-
-Qt::DropActions PLModel::supportedDropActions() const
-{
- return Qt::CopyAction | Qt::MoveAction;
-}
-
-Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
-{
- Qt::ItemFlags flags = QAbstractItemModel::flags( index );
-
- const PLItem *item = index.isValid() ? getItem( index ) : rootItem;
-
- if( canEdit() )
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- playlist_item_t *plItem =
- playlist_ItemGetById( p_playlist, item->i_playlist_id );
-
- if ( plItem && ( plItem->i_children > -1 ) )
- flags |= Qt::ItemIsDropEnabled;
- }
- flags |= Qt::ItemIsDragEnabled;
-
- return flags;
-}
-
-QStringList PLModel::mimeTypes() const
-{
- QStringList types;
- types << "vlc/qt-input-items";
- return types;
-}
-
-bool modelIndexLessThen( const QModelIndex &i1, const QModelIndex &i2 )
-{
- if( !i1.isValid() || !i2.isValid() ) return false;
- PLItem *item1 = static_cast<PLItem*>( i1.internalPointer() );
- PLItem *item2 = static_cast<PLItem*>( i2.internalPointer() );
- if( item1->hasSameParent( item2 ) ) return i1.row() < i2.row();
- else return *item1 < *item2;
-}
-
-QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
-{
- PlMimeData *plMimeData = new PlMimeData();
- QModelIndexList list;
-
- foreach( const QModelIndex &index, indexes ) {
- if( index.isValid() && index.column() == 0 )
- list.append(index);
- }
-
- qSort(list.begin(), list.end(), modelIndexLessThen);
-
- AbstractPLItem *item = NULL;
- foreach( const QModelIndex &index, list ) {
- if( item )
- {
- AbstractPLItem *testee = getItem( index );
- while( testee->parent() )
- {
- if( testee->parent() == item ||
- testee->parent() == item->parent() ) break;
- testee = testee->parent();
- }
- if( testee->parent() == item ) continue;
- item = getItem( index );
- }
- else
- item = getItem( index );
-
- plMimeData->appendItem( static_cast<PLItem*>(item)->inputItem() );
- }
-
- return plMimeData;
-}
-
-/* Drop operation */
-bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
- int row, int, const QModelIndex &parent )
-{
- bool copy = action == Qt::CopyAction;
- if( !copy && action != Qt::MoveAction )
- return true;
-
- const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
- if( plMimeData )
- {
- if( copy )
- dropAppendCopy( plMimeData, getItem( parent ), row );
- else
- dropMove( plMimeData, getItem( parent ), row );
- }
- return true;
-}
-
-void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target, int pos )
-{
- vlc_playlist_locker pl_lock ( THEPL );
-
- playlist_item_t *p_parent =
- playlist_ItemGetByInput( p_playlist, target->inputItem() );
- if( !p_parent ) return;
-
- if( pos == -1 ) pos = PLAYLIST_END;
-
- QList<input_item_t*> inputItems = plMimeData->inputItems();
-
- foreach( input_item_t* p_input, inputItems )
- {
- playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
- if( !p_item ) continue;
- pos = playlist_NodeAddCopy( p_playlist, p_item, p_parent, pos );
- }
-}
-
-void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
-{
- QList<input_item_t*> inputItems = plMimeData->inputItems();
- QList<PLItem*> model_items;
- playlist_item_t **pp_items;
- pp_items = (playlist_item_t **)
- calloc( inputItems.count(), sizeof( playlist_item_t* ) );
- if ( !pp_items ) return;
-
- int model_pos;
-
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- playlist_item_t *p_parent =
- playlist_ItemGetByInput( p_playlist, target->inputItem() );
-
- if( !p_parent || row > p_parent->i_children )
- {
- free( pp_items );
- return;
- }
-
- int new_pos = model_pos = row == -1 ? p_parent->i_children : row;
- int i = 0;
-
- foreach( input_item_t *p_input, inputItems )
- {
- playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
- if( !p_item ) continue;
-
- PLItem *item = findByInputLocked( rootItem, p_input );
- if( !item ) continue;
-
- /* Better not try to move a node into itself.
- Abort the whole operation in that case,
- because it is ambiguous. */
- AbstractPLItem *climber = target;
- while( climber )
- {
- if( climber == item )
- {
- free( pp_items );
- return;
- }
- climber = climber->parent();
- }
-
- if( item->parent() == target &&
- target->children.indexOf( item ) < new_pos )
- model_pos--;
-
- model_items.append( item );
- pp_items[i] = p_item;
- i++;
- }
-
- if( model_items.isEmpty() )
- {
- free( pp_items );
- return;
- }
-
- playlist_TreeMoveMany( p_playlist, i, pp_items, p_parent, new_pos );
- }
-
- foreach( PLItem *item, model_items )
- takeItem( item );
-
- insertChildren( target, model_items, model_pos );
- free( pp_items );
-}
-
-void PLModel::activateItem( const QModelIndex &index )
-{
- assert( index.isValid() );
- const PLItem *item = getItem( index );
- assert( item );
-
- vlc_playlist_locker pl_lock( THEPL );
-
- playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_playlist_id );
- activateItem( p_item );
-}
-
-/* Convenient overloaded private version of activateItem
- * Must be entered with PL lock */
-void PLModel::activateItem( playlist_item_t *p_item )
-{
- if( !p_item ) return;
- playlist_item_t *p_parent = p_item;
- while( p_parent )
- {
- if( p_parent->i_id == rootItem->id() ) break;
- p_parent = p_parent->p_parent;
- }
- if( p_parent )
- playlist_ViewPlay( p_playlist, p_parent, p_item );
-}
-
-/****************** Base model mandatory implementations *****************/
-QVariant PLModel::data( const QModelIndex &index, const int role ) const
-{
- if( !index.isValid() )
- return QVariant();
-
- switch( role )
- {
-
- case Qt::FontRole:
- return customFont;
-
- case Qt::DisplayRole:
- {
- PLItem *item = getItem( index );
- int metadata = columnToMeta( index.column() );
- if( metadata == COLUMN_END )
- return QVariant();
-
- QString returninfo;
- if( metadata == COLUMN_NUMBER )
- {
- returninfo = QString::number( index.row() + 1 );
- }
- else if( metadata == COLUMN_COVER )
- {
- QString artUrl;
- artUrl = InputManager::decodeArtURL( item->inputItem() );
- if( artUrl.isEmpty() )
- {
- for( int i = 0; i < item->childCount(); i++ )
- {
- artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
- if( !artUrl.isEmpty() )
- break;
- }
- }
- return artUrl;
- }
- else
- {
- char *psz = psz_column_meta( item->inputItem(), metadata );
- returninfo = qfu( psz );
- free( psz );
- }
-
- return QVariant( returninfo );
- }
-
- case Qt::DecorationRole:
- {
- switch( columnToMeta(index.column()) )
- {
- case COLUMN_TITLE:
- {
- PLItem *item = getItem( index );
- /* Used to segfault here because i_type wasn't always initialized */
- enum input_item_type_e idx = item->inputItem()->i_type;
- if( item->inputItem()->b_net && item->inputItem()->i_type == ITEM_TYPE_FILE )
- idx = ITEM_TYPE_STREAM;
- return QVariant( icons[idx] );
- }
- case COLUMN_COVER:
- /* !warn: changes tree item line height. Otherwise, override
- * delegate's sizehint */
- return getArtPixmap( index, QSize(16,16) );
- default:
- break;
- }
- break;
- }
-
- case Qt::BackgroundRole:
- if( isCurrent( index ) )
- return QVariant( QBrush( Qt::gray ) );
- break;
-
- case CURRENT_ITEM_ROLE:
- return QVariant( isCurrent( index ) );
-
- case CURRENT_ITEM_CHILD_ROLE:
- return QVariant( isParent( index, currentIndex() ) );
-
- case LEAF_NODE_ROLE:
- return QVariant( isLeaf( index ) );
-
- default:
- break;
- }
-
- return QVariant();
-}
-
-bool PLModel::setData( const QModelIndex &index, const QVariant & value, int role )
-{
- switch( role )
- {
- case Qt::FontRole:
- customFont = value.value<QFont>();
- return true;
- default:
- return VLCModel::setData( index, value, role );
- }
-}
-
-/* Seek from current index toward the top and see if index is one of parent nodes */
-bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
-{
- if( !index.isValid() )
- return false;
-
- if( index == current )
- return true;
-
- if( !current.isValid() || !current.parent().isValid() )
- return false;
-
- return isParent( index, current.parent() );
-}
-
-bool PLModel::isLeaf( const QModelIndex &index ) const
-{
- bool b_isLeaf = false;
-
- vlc_playlist_locker pl_lock ( THEPL );
-
- playlist_item_t *plItem =
- playlist_ItemGetById( p_playlist, itemId( index ) );
-
- if( plItem )
- b_isLeaf = plItem->i_children == -1;
-
- return b_isLeaf;
-}
-
-PLItem* PLModel::getItem( const QModelIndex & index ) const
-{
- PLItem *item = static_cast<PLItem *>( VLCModel::getItem( index ) );
- if ( item == NULL ) item = rootItem;
- return item;
-}
-
-QModelIndex PLModel::index( const int row, const int column, const QModelIndex &parent )
- const
-{
- PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
-
- PLItem *childItem = static_cast<PLItem*>(parentItem->child( row ));
- if( childItem )
- return createIndex( row, column, childItem );
- else
- return QModelIndex();
-}
-
-QModelIndex PLModel::indexByPLID( const int i_plid, const int c ) const
-{
- return index( findByPLId( rootItem, i_plid ), c );
-}
-
-QModelIndex PLModel::indexByInputItem( const input_item_t *item, const int c ) const
-{
- return index( findByInput( rootItem, item ), c );
-}
-
-QModelIndex PLModel::rootIndex() const
-{
- return index( findByPLId( rootItem, rootItem->id() ), 0 );
-}
-
-bool PLModel::isTree() const
-{
- return ( ( rootItem && rootItem->id() != p_playlist->p_playing->i_id )
- || var_InheritBool( p_intf, "playlist-tree" ) );
-}
-
-/* Return the index of a given item */
-QModelIndex PLModel::index( PLItem *item, int column ) const
-{
- if( !item ) return QModelIndex();
- AbstractPLItem *parent = item->parent();
- if( parent )
- return createIndex( parent->lastIndexOf( item ),
- column, item );
- return QModelIndex();
-}
-
-QModelIndex PLModel::currentIndex() const
-{
- input_thread_t *p_input_thread = THEMIM->getInput();
- if( !p_input_thread ) return QModelIndex();
- PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread ) );
- return index( item, 0 );
-}
-
-QModelIndex PLModel::parent( const QModelIndex &index ) const
-{
- if( !index.isValid() ) return QModelIndex();
-
- PLItem *childItem = getItem( index );
- if( !childItem )
- {
- msg_Err( p_playlist, "Item not found" );
- return QModelIndex();
- }
-
- PLItem *parentItem = static_cast<PLItem*>(childItem->parent());
- if( !parentItem || parentItem == rootItem ) return QModelIndex();
- if( !parentItem->parent() )
- {
- msg_Err( p_playlist, "No parent found, trying row 0. Please report this" );
- return createIndex( 0, 0, parentItem );
- }
- return createIndex(parentItem->row(), 0, parentItem);
-}
-
-int PLModel::rowCount( const QModelIndex &parent ) const
-{
- PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
- return parentItem->childCount();
-}
-
-/************************* Lookups *****************************/
-PLItem *PLModel::findByPLId( PLItem *root, int i_id ) const
-{
- if( !root ) return NULL;
-
- if( root->id() == i_id )
- return root;
-
- /* traverse the tree (in depth first) iteratively to avoid stack overflow */
-
- struct RemainingChildren {
- QList<AbstractPLItem *>::const_iterator next;
- QList<AbstractPLItem *>::const_iterator end;
- };
-
- QStack<RemainingChildren> stack;
- if( root->childCount() )
- stack.push( {root->children.cbegin(), root->children.cend()} );
-
- while ( !stack.isEmpty() )
- {
- RemainingChildren &remainingChildren = stack.top();
-
- PLItem *item = static_cast<PLItem *>( *remainingChildren.next );
- if( item->id() == i_id )
- return item;
-
- if( ++remainingChildren.next == remainingChildren.end )
- /* there are no more children at this depth level */
- stack.pop();
-
- if( item->childCount() )
- stack.push( {item->children.cbegin(), item->children.cend()} );
- }
- return NULL;
-}
-
-PLItem *PLModel::findByInput( PLItem *root, const input_item_t *input ) const
-{
- int i_id;
- {
- playlist_item_t *item;
-
- vlc_playlist_locker pl_lock ( THEPL );
- item = playlist_ItemGetByInput( THEPL, input );
- if( item == NULL )
- return NULL;
- i_id = item->i_id;
- }
- return findByPLId( root, i_id );
-}
-
-PLItem *PLModel::findByInputLocked( PLItem *root, const input_item_t *input ) const
-{
- PL_ASSERT_LOCKED;
-
- playlist_item_t* item = playlist_ItemGetByInput( THEPL, input );
- if( item == NULL )
- return NULL;
- return findByPLId( root, item->i_id );
-}
-
-PLModel::pl_nodetype PLModel::getPLRootType() const
-{
- vlc_playlist_locker pl_lock ( THEPL );
-
- /* can't rely on rootitem as it depends on view / rebuild() */
- AbstractPLItem *plitem = rootItem;
- while( plitem->parent() )plitem = plitem->parent();
-
- if( plitem->id() == p_playlist->p_playing->i_id )
- return ROOTTYPE_CURRENT_PLAYING;
-
- return ROOTTYPE_OTHER;
-}
-
-bool PLModel::canEdit() const
-{
- return ( getPLRootType() != ROOTTYPE_OTHER );
-}
-
-/************************* Updates handling *****************************/
-
-/**** Events processing ****/
-void PLModel::processInputItemUpdate( )
-{
- input_thread_t *p_input = THEMIM->getInput();
- if( !p_input ) return;
-
- PLItem *item = findByInput( rootItem, input_GetItem( p_input ) );
- if( item ) emit currentIndexChanged( index( item, 0 ) );
-
- processInputItemUpdate( input_GetItem( p_input ) );
-}
-
-void PLModel::processInputItemUpdate( input_item_t *p_item )
-{
- if( !p_item ) return;
- PLItem *item = findByInput( rootItem, p_item );
- if( item )
- updateTreeItem( item );
-}
-
-void PLModel::processItemRemoval( int i_pl_itemid )
-{
- if( i_pl_itemid <= 0 ) return;
- removeItem( findByPLId( rootItem, i_pl_itemid ) );
-}
-
-void PLModel::processItemAppend( int i_pl_itemid, int i_pl_itemidparent )
-{
- playlist_item_t *p_item = NULL;
- PLItem *newItem = NULL;
- int pos;
-
- /* Find the Parent */
- PLItem *nodeParentItem = findByPLId( rootItem, i_pl_itemidparent );
- if( !nodeParentItem ) return;
-
- /* Search for an already matching children */
- foreach( AbstractPLItem *existing, nodeParentItem->children )
- if( existing->id() == i_pl_itemid ) return;
-
- /* Find the child */
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- p_item = playlist_ItemGetById( p_playlist, i_pl_itemid );
- if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
- return;
-
- for( pos = p_item->p_parent->i_children - 1; pos >= 0; pos-- )
- if( p_item->p_parent->pp_children[pos] == p_item ) break;
-
- newItem = new PLItem( p_item, nodeParentItem );
- }
-
- /* We insert the newItem (children) inside the parent */
- beginInsertRows( index( nodeParentItem, 0 ), pos, pos );
- nodeParentItem->insertChild( newItem, pos );
- endInsertRows();
- if ( newItem->inputItem() == THEMIM->currentInputItem() )
- emit currentIndexChanged( index( newItem, 0 ) );
-
- if( latestSearch.isEmpty() ) return;
- filter( latestSearch, index( rootItem, 0), false /*FIXME*/ );
-}
-
-void PLModel::rebuild( playlist_item_t *p_root )
-{
- beginResetModel();
-
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- if( rootItem ) rootItem->clearChildren();
- if( p_root ) // Can be NULL
- {
- if ( rootItem ) delete rootItem;
- rootItem = new PLItem( p_root );
- }
- assert( rootItem );
- /* Recreate from root */
- updateChildren( rootItem );
- }
-
- /* And signal the view */
- endResetModel();
- if( p_root ) emit rootIndexChanged();
-}
-
-void PLModel::takeItem( PLItem *item )
-{
- assert( item );
- PLItem *parent = static_cast<PLItem*>(item->parent());
- assert( parent );
- int i_index = parent->indexOf( item );
-
- beginRemoveRows( index( parent, 0 ), i_index, i_index );
- parent->takeChildAt( i_index );
- endRemoveRows();
-}
-
-void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
-{
- assert( node );
- int count = items.count();
- if( !count ) return;
- beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
- for( int i = 0; i < count; i++ )
- {
- node->children.insert( i_pos + i, items[i] );
- items[i]->parentItem = node;
- }
- endInsertRows();
-}
-
-void PLModel::removeItem( PLItem *item )
-{
- if( !item ) return;
-
- if( item->parent() ) {
- int i = item->parent()->indexOf( item );
- beginRemoveRows( index( static_cast<PLItem*>(item->parent()), 0), i, i );
- item->parent()->children.removeAt(i);
- delete item;
- endRemoveRows();
- }
- else delete item;
-
- if(item == rootItem)
- {
- rootItem = NULL;
- rebuild( p_playlist->p_playing );
- }
-}
-
-/* This function must be entered WITH the playlist lock */
-void PLModel::updateChildren( PLItem *root )
-{
- playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->id() );
- updateChildren( p_node, root );
-}
-
-/* This function must be entered WITH the playlist lock */
-void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
-{
- for( int i = 0; i < p_node->i_children ; i++ )
- {
- if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
- PLItem *newItem = new PLItem( p_node->pp_children[i], root );
- root->appendChild( newItem );
- if( p_node->pp_children[i]->i_children != -1 )
- updateChildren( p_node->pp_children[i], newItem );
- }
-}
-
-/* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
-void PLModel::updateTreeItem( PLItem *item )
-{
- if( !item ) return;
- emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) - 1 ) );
-}
-
-/************************* Actions ******************************/
-
-/**
- * Deletion, don't delete items childrens if item is going to be
- * delete allready, so we remove childrens from selection-list.
- */
-void PLModel::doDelete( QModelIndexList selected )
-{
- if( !canEdit() ) return;
-
- while( !selected.isEmpty() )
- {
- QModelIndex index = selected[0];
- selected.removeAt( 0 );
-
- if( index.column() != 0 ) continue;
-
- PLItem *item = getItem( index );
- if( item->childCount() )
- recurseDelete( item->children, &selected );
-
- PL_LOCK;
- playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
- item->id() );
- if( p_root != NULL )
- playlist_NodeDelete( p_playlist, p_root );
- PL_UNLOCK;
-
- if( p_root != NULL )
- removeItem( item );
- }
-}
-
-void PLModel::recurseDelete( QList<AbstractPLItem*> children, QModelIndexList *fullList )
-{
- for( int i = children.count() - 1; i >= 0 ; i-- )
- {
- PLItem *item = static_cast<PLItem *>(children[i]);
- if( item->childCount() )
- recurseDelete( item->children, fullList );
- fullList->removeAll( index( item, 0 ) );
- }
-}
-
-/******* Volume III: Sorting and searching ********/
-void PLModel::sort( const int column, Qt::SortOrder order )
-{
- sort( QModelIndex(), indexByPLID( rootItem->id(), 0 ) , column, order );
-}
-
-void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column, Qt::SortOrder order )
-{
- msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
-
- int meta = columnToMeta( column );
- if( meta == COLUMN_END || meta == COLUMN_COVER ) return;
-
- PLItem *item = ( rootIndex.isValid() ) ? getItem( rootIndex )
- : rootItem;
- if( !item ) return;
-
- input_item_t* p_caller_item = caller.isValid()
- ? static_cast<AbstractPLItem*>( caller.internalPointer() )->inputItem()
- : NULL;
-
- int i_root_id = item->id();
-
- QModelIndex qIndex = index( item, 0 );
- int count = item->childCount();
- if( count )
- {
- beginRemoveRows( qIndex, 0, count - 1 );
- item->clearChildren();
- endRemoveRows( );
- }
-
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
- i_root_id );
- if( p_root )
- {
- playlist_RecursiveNodeSort( p_playlist, p_root,
- i_column_sorting( meta ),
- order == Qt::AscendingOrder ?
- ORDER_NORMAL : ORDER_REVERSE );
- }
-
- if( count )
- {
- beginInsertRows( qIndex, 0, count - 1 );
- updateChildren( item );
- endInsertRows( );
- }
- }
-
- /* if we have popup item, try to make sure that you keep that item visible */
- if( p_caller_item )
- {
- QModelIndex idx = indexByInputItem( p_caller_item, 0 );
-
- emit currentIndexChanged( idx );
- }
- else if( currentIndex().isValid() )
- emit currentIndexChanged( currentIndex() );
-}
-
-void PLModel::filter( const QString& search_text, const QModelIndex & idx, bool b_recursive )
-{
- latestSearch = search_text;
-
- /** \todo Fire the search with a small delay ? */
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
- itemId( idx ) );
- assert( p_root );
- playlist_LiveSearchUpdate( p_playlist, p_root, qtu( search_text ),
- b_recursive );
- if( idx.isValid() )
- {
- PLItem *searchRoot = getItem( idx );
-
- beginRemoveRows( idx, 0, searchRoot->childCount() - 1 );
- searchRoot->clearChildren();
- endRemoveRows();
-
- beginInsertRows( idx, 0, searchRoot->childCount() - 1 );
- updateChildren( searchRoot ); // The PL_LOCK is needed here
- endInsertRows();
-
- return;
- }
- }
-
- rebuild();
-}
-
-void PLModel::removeAll()
-{
- if( rowCount() < 1 ) return;
-
- QModelIndexList l;
- for( int i = 0; i < rowCount(); i++)
- {
- QModelIndex indexrecord = index( i, 0, QModelIndex() );
- l.append( indexrecord );
- }
- doDelete(l);
-}
-
-void PLModel::createNode( QModelIndex index, QString name )
-{
- if( name.isEmpty() )
- return;
-
- vlc_playlist_locker pl_lock ( THEPL );
-
- index = index.parent();
- if ( !index.isValid() ) index = rootIndex();
- playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
- if( p_item )
- playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0 );
-}
-
-void PLModel::renameNode( QModelIndex index, QString name )
-{
- if( name.isEmpty() || !index.isValid() ) return;
-
- vlc_playlist_locker pl_lock ( THEPL );
-
- if ( !index.isValid() ) index = rootIndex();
- input_item_t* p_input = this->getInputItem( index );
- input_item_SetName( p_input, qtu( name ) );
- playlist_t *p_playlist = THEPL;
- input_item_WriteMeta( VLC_OBJECT(p_playlist), p_input );
-}
-
-bool PLModel::action( QAction *action, const QModelIndexList &indexes )
-{
- QModelIndex index;
- actionsContainerType a = action->data().value<actionsContainerType>();
-
- switch ( a.action )
- {
-
- case ACTION_PLAY:
- if ( !indexes.empty() && indexes.first().isValid() )
- {
- if( isCurrent( indexes.first() ) )
- playlist_Resume(THEPL);
- else
- activateItem( indexes.first() );
- return true;
- }
- break;
-
- case ACTION_PAUSE:
- if ( !indexes.empty() && indexes.first().isValid() )
- {
- playlist_Pause(THEPL);
- return true;
- }
- break;
-
- case ACTION_ADDTOPLAYLIST:
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- foreach( const QModelIndex ¤tIndex, indexes )
- {
- playlist_item_t *p_item = playlist_ItemGetById( THEPL, itemId( currentIndex ) );
- if( !p_item ) continue;
-
- playlist_NodeAddCopy( THEPL, p_item,
- THEPL->p_playing,
- PLAYLIST_END );
- }
- return true;
- }
-
- case ACTION_REMOVE:
- doDelete( indexes );
- return true;
-
- case ACTION_SORT:
- if ( !indexes.empty() )
- index = indexes.first();
-
- sort( index, rootIndex(),
- a.column > 0 ? a.column - 1 : -a.column - 1,
- a.column > 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
- return true;
-
- case ACTION_CLEAR:
- removeAll();
- return true;
-
- case ACTION_ENQUEUEFILE:
- foreach( const QString &uri, a.uris )
- Open::openMRL( p_intf, uri.toLatin1().constData(),
- false );
- return true;
-
- case ACTION_ENQUEUEDIR:
- if( a.uris.isEmpty() ) break;
-
- Open::openMRL( p_intf, a.uris.first().toLatin1().constData(),
- false );
-
- return true;
-
- case ACTION_ENQUEUEGENERIC:
- foreach( const QString &uri, a.uris )
- {
- QStringList options = a.options.split( " :" );
- Open::openMRLwithOptions( p_intf, uri, &options, false );
- }
- return true;
-
- default:
- break;
- }
- return false;
-}
-
-bool PLModel::isSupportedAction( actions action, const QModelIndex &index ) const
-{
- AbstractPLItem const* item = VLCModel::getItem( index );
-
- switch ( action )
- {
- case ACTION_ADDTOPLAYLIST:
- /* Only if we are not already in Current Playing */
- return getPLRootType() != ROOTTYPE_CURRENT_PLAYING;
- case ACTION_SORT:
- return rowCount();
- case ACTION_PLAY:
- {
- if( !item )
- return false;
-
- {
- vlc_playlist_locker pl_lock ( THEPL );
-
- if( playlist_Status( THEPL ) != PLAYLIST_RUNNING )
- return true;
- }
-
- return !isCurrent( index );
- }
- case ACTION_PAUSE:
- {
- if( !isCurrent( index ) )
- return false;
-
- vlc_playlist_locker pl_lock ( THEPL );
-
- return playlist_Status( THEPL ) == PLAYLIST_RUNNING;
- }
- case ACTION_STREAM:
- case ACTION_SAVE:
- case ACTION_INFO:
- return item;
- case ACTION_REMOVE:
- return item && !item->readOnly();
- case ACTION_EXPLORE:
- {
- if( !item )
- return false;
-
- char* psz_path = vlc_uri2path( qtu( item->getURI() ) );
- free( psz_path );
- return psz_path != NULL;
- }
- case ACTION_CREATENODE:
- return canEdit() && isTree() && ( !item || !item->readOnly() );
- case ACTION_RENAMENODE:
- return item && !isLeaf( index ) && !item->readOnly();
- case ACTION_CLEAR:
- return canEdit() && rowCount();
- case ACTION_ENQUEUEFILE:
- case ACTION_ENQUEUEDIR:
- case ACTION_ENQUEUEGENERIC:
- return canEdit();
- case ACTION_SAVETOPLAYLIST:
- return getPLRootType() == ROOTTYPE_CURRENT_PLAYING && rowCount();
- default:
- return false;
- }
- return false;
-}
-
-/******************* Drag and Drop helper class ******************/
-PlMimeData::~PlMimeData()
-{
- foreach( input_item_t *p_item, _inputItems )
- input_item_Release( p_item );
-}
-
-void PlMimeData::appendItem( input_item_t *p_item )
-{
- input_item_Hold( p_item );
- _inputItems.append( p_item );
-}
-
-QList<input_item_t*> PlMimeData::inputItems() const
-{
- return _inputItems;
-}
-
-QStringList PlMimeData::formats () const
-{
- QStringList fmts;
- fmts << "vlc/qt-input-items";
- return fmts;
-}
diff --git a/modules/gui/qt/components/playlist/playlist_model.hpp b/modules/gui/qt/components/playlist/playlist_model.hpp
deleted file mode 100644
index 6a0e510de5..0000000000
--- a/modules/gui/qt/components/playlist/playlist_model.hpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/*****************************************************************************
- * playlist_model.hpp : Model for a playlist tree
- ****************************************************************************
- * Copyright (C) 2006-2011 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Jakob Leben <jleben at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_PLAYLIST_MODEL_HPP
-#define VLC_QT_PLAYLIST_MODEL_HPP
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_input.h>
-#include <vlc_playlist_legacy.h>
-#include "vlc_model.hpp"
-#include "playlist_item.hpp"
-
-#include <QObject>
-#include <QEvent>
-#include <QSignalMapper>
-#include <QMimeData>
-#include <QAbstractItemModel>
-#include <QVariant>
-#include <QModelIndex>
-#include <QAction>
-
-class PLItem;
-class PlMimeData;
-
-class PLModel : public VLCModel
-{
- Q_OBJECT
-
-public:
- PLModel( playlist_t *, intf_thread_t *,
- playlist_item_t *, QObject *parent = 0 );
- virtual ~PLModel();
-
- /* Qt main PLModel */
- static PLModel* getPLModel( intf_thread_t *p_intf )
- {
- if(!p_intf->p_sys->pl_model )
- {
- playlist_Lock( THEPL );
- playlist_item_t *p_root = THEPL->p_playing;
- playlist_Unlock( THEPL );
- p_intf->p_sys->pl_model = new PLModel( THEPL, p_intf, p_root, NULL );
- }
-
- return p_intf->p_sys->pl_model;
- }
-
- /*** QAbstractItemModel subclassing ***/
-
- /* Data structure */
- QVariant data( const QModelIndex &index, const int role ) const Q_DECL_OVERRIDE;
- bool setData( const QModelIndex &index, const QVariant & value, int role = Qt::EditRole ) Q_DECL_OVERRIDE;
- int rowCount( const QModelIndex &parent = QModelIndex() ) const Q_DECL_OVERRIDE;
- Qt::ItemFlags flags( const QModelIndex &index ) const Q_DECL_OVERRIDE;
- QModelIndex index( const int r, const int c, const QModelIndex &parent ) const Q_DECL_OVERRIDE;
- QModelIndex parent( const QModelIndex &index ) const Q_DECL_OVERRIDE;
-
- /* Drag and Drop */
- Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
- QMimeData* mimeData( const QModelIndexList &indexes ) const Q_DECL_OVERRIDE;
- virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action,
- int row, int column, const QModelIndex &target ) Q_DECL_OVERRIDE;
- QStringList mimeTypes() const Q_DECL_OVERRIDE;
-
- /* Sort */
- void sort( const int column, Qt::SortOrder order = Qt::AscendingOrder ) Q_DECL_OVERRIDE;
-
- /*** VLCModelSubInterface subclassing ***/
- virtual void rebuild( playlist_item_t * p = NULL ) Q_DECL_OVERRIDE;
- virtual void doDelete( QModelIndexList selected ) Q_DECL_OVERRIDE;
- virtual void createNode( QModelIndex index, QString name ) Q_DECL_OVERRIDE;
- virtual void renameNode( QModelIndex index, QString name ) Q_DECL_OVERRIDE;
- virtual void removeAll() Q_DECL_OVERRIDE;
-
- /* Lookups */
- virtual QModelIndex rootIndex() const Q_DECL_OVERRIDE;
- virtual void filter( const QString& search_text, const QModelIndex & root, bool b_recursive ) Q_DECL_OVERRIDE;
- virtual QModelIndex currentIndex() const Q_DECL_OVERRIDE;
- virtual QModelIndex indexByPLID( const int i_plid, const int c ) const Q_DECL_OVERRIDE;
- virtual QModelIndex indexByInputItem( const input_item_t *, const int c ) const Q_DECL_OVERRIDE;
- virtual bool isTree() const Q_DECL_OVERRIDE;
- virtual bool canEdit() const Q_DECL_OVERRIDE;
- virtual bool action( QAction *action, const QModelIndexList &indexes ) Q_DECL_OVERRIDE;
- virtual bool isSupportedAction( actions action, const QModelIndex & ) const Q_DECL_OVERRIDE;
-
-protected:
- /* VLCModel subclassing */
- virtual bool isParent( const QModelIndex &index, const QModelIndex ¤t) const Q_DECL_OVERRIDE;
- virtual bool isLeaf( const QModelIndex &index ) const Q_DECL_OVERRIDE;
- virtual PLItem *getItem( const QModelIndex & index ) const Q_DECL_OVERRIDE;
-
-private:
- /* General */
- PLItem *rootItem;
-
- playlist_t *p_playlist;
-
- /* Custom model private methods */
- /* Lookups */
- QModelIndex index( PLItem *, const int c ) const;
-
- /* Shallow actions (do not affect core playlist) */
- void updateTreeItem( PLItem * );
- void removeItem ( PLItem * );
- void recurseDelete( QList<AbstractPLItem*> children, QModelIndexList *fullList );
- void takeItem( PLItem * ); //will not delete item
- void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
- /* ...of which the following will not update the views */
- void updateChildren( PLItem * );
- void updateChildren( playlist_item_t *, PLItem * );
-
- /* Deep actions (affect core playlist) */
- void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
- void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
-
- /* */
- void sort( QModelIndex caller, QModelIndex rootIndex, const int column, Qt::SortOrder order );
-
- /* Lookups */
- PLItem *findByPLId( PLItem *, int i_plitemid ) const;
- PLItem *findByInput( PLItem *, const input_item_t * ) const;
- PLItem *findByInputLocked( PLItem *, const input_item_t * ) const;
- enum pl_nodetype
- {
- ROOTTYPE_CURRENT_PLAYING,
- ROOTTYPE_OTHER
- };
- pl_nodetype getPLRootType() const;
-
- /* */
- QString latestSearch;
- QFont customFont;
-
-private slots:
- void processInputItemUpdate( input_item_t *);
- void processInputItemUpdate();
- void processItemRemoval( int i_pl_itemid );
- void processItemAppend( int i_pl_itemid, int i_pl_itemidparent );
- void activateItem( playlist_item_t *p_item );
- virtual void activateItem( const QModelIndex &index ) Q_DECL_OVERRIDE;
-};
-
-class PlMimeData : public QMimeData
-{
- Q_OBJECT
-
-public:
- PlMimeData() {}
- virtual ~PlMimeData();
- void appendItem( input_item_t *p_item );
- QList<input_item_t*> inputItems() const;
- QStringList formats () const;
-
-private:
- QList<input_item_t*> _inputItems;
- QMimeData *_mimeData;
-};
-
-#endif
diff --git a/modules/gui/qt/components/playlist/selector.cpp b/modules/gui/qt/components/playlist/selector.cpp
deleted file mode 100644
index e80b6c40fe..0000000000
--- a/modules/gui/qt/components/playlist/selector.cpp
+++ /dev/null
@@ -1,636 +0,0 @@
-/*****************************************************************************
- * selector.cpp : Playlist source selector
- ****************************************************************************
- * Copyright (C) 2006-2009 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Jean-Baptiste Kempf
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "qt.hpp"
-#include "components/playlist/selector.hpp"
-#include "playlist_model.hpp" /* plMimeData */
-#include "input_manager.hpp" /* MainInputManager, for podcast */
-
-#include <QApplication>
-#include <QInputDialog>
-#include <QMessageBox>
-#include <QMimeData>
-#include <QDragMoveEvent>
-#include <QTreeWidgetItem>
-#include <QHBoxLayout>
-#include <QPainter>
-#include <QPalette>
-#include <QScrollBar>
-#include <QResource>
-#include <assert.h>
-
-#include <vlc_playlist_legacy.h>
-#include <vlc_services_discovery.h>
-
-void SelectorActionButton::paintEvent( QPaintEvent *event )
-{
- QPainter p( this );
- QColor color = palette().color( QPalette::HighlightedText );
- color.setAlpha( 80 );
- if( underMouse() )
- p.fillRect( rect(), color );
- p.setPen( color );
- int frame = style()->pixelMetric( QStyle::PM_DefaultFrameWidth, 0, this );
- p.drawLine( rect().topLeft() + QPoint( 0, frame ),
- rect().bottomLeft() - QPoint( 0, frame ) );
- QFramelessButton::paintEvent( event );
-}
-
-PLSelItem::PLSelItem ( QTreeWidgetItem *i, const QString& text )
- : qitem(i), lblAction( NULL)
-{
- layout = new QHBoxLayout( this );
- layout->setContentsMargins(0,0,0,0);
- layout->addSpacing( 3 );
-
- lbl = new QElidingLabel( text );
- layout->addWidget(lbl, 1);
-
- int height = qMax( 22, fontMetrics().height() + 8 );
- setMinimumHeight( height );
-}
-
-void PLSelItem::addAction( ItemAction act, const QString& tooltip )
-{
- if( lblAction ) return; //might change later
-
- QIcon icon;
-
- switch( act )
- {
- case ADD_ACTION:
- icon = QIcon( ":/buttons/playlist/playlist_add.svg" ); break;
- case RM_ACTION:
- icon = QIcon( ":/buttons/playlist/playlist_remove.svg" ); break;
- default:
- return;
- }
-
- lblAction = new SelectorActionButton();
- lblAction->setIcon( icon );
- int icon_size = fontMetrics().height();
- lblAction->setIconSize( QSize( icon_size, icon_size ) );
- lblAction->setMinimumWidth( lblAction->sizeHint().width() + icon_size );
-
- if( !tooltip.isEmpty() ) lblAction->setToolTip( tooltip );
-
- layout->addWidget( lblAction, 0 );
- lblAction->hide();
-
- CONNECT( lblAction, clicked(), this, triggerAction() );
-}
-
-
-PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
- : QTreeWidget( p ), p_intf(_p_intf)
-{
- /* Properties */
- setFrameStyle( QFrame::NoFrame );
- setAttribute( Qt::WA_MacShowFocusRect, false );
- viewport()->setAutoFillBackground( false );
- setIconSize( QSize( 24,24 ) );
- setIndentation( 12 );
- setHeaderHidden( true );
- setRootIsDecorated( true );
- setAlternatingRowColors( false );
-
- /* drops */
- viewport()->setAcceptDrops(true);
- setDropIndicatorShown(true);
- invisibleRootItem()->setFlags( invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled );
-
- setMinimumHeight( 120 );
-
- /* Podcasts */
- podcastsParent = NULL;
- podcastsParentId = -1;
-
- /* Podcast connects */
- CONNECT( THEMIM, playlistItemAppended( int, int ),
- this, plItemAdded( int, int ) );
- CONNECT( THEMIM, playlistItemRemoved( int ),
- this, plItemRemoved( int ) );
- DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
- this, inputItemUpdate( input_item_t * ) );
-
- createItems();
-
- setRootIsDecorated( false );
- setIndentation( 5 );
- /* Expand at least to show level 2 */
- for ( int i = 0; i < topLevelItemCount(); i++ )
- expandItem( topLevelItem( i ) );
-
- /***
- * We need to react to both clicks and activation (enter-key) here.
- * We use curItem to avoid rebuilding twice.
- * See QStyle::SH_ItemView_ActivateItemOnSingleClick
- ***/
- curItem = NULL;
- CONNECT( this, itemActivated( QTreeWidgetItem *, int ),
- this, setSource( QTreeWidgetItem *) );
- CONNECT( this, itemClicked( QTreeWidgetItem *, int ),
- this, setSource( QTreeWidgetItem *) );
-}
-
-PLSelector::~PLSelector()
-{
- if( podcastsParent )
- {
- int c = podcastsParent->childCount();
- for( int i = 0; i < c; i++ )
- {
- QTreeWidgetItem *item = podcastsParent->child(i);
- input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
- input_item_Release( p_input );
- }
- }
-}
-
-PLSelItem * putSDData( PLSelItem* item, const char* name, const char* longname )
-{
- item->treeItem()->setData( 0, NAME_ROLE, qfu( name ) );
- item->treeItem()->setData( 0, LONGNAME_ROLE, qfu( longname ) );
- return item;
-}
-
-PLSelItem * putPLData( PLSelItem* item, playlist_item_t* plItem )
-{
- item->treeItem()->setData( 0, PL_ITEM_ROLE, QVariant::fromValue( plItem ) );
-/* item->setData( 0, PL_ITEM_ID_ROLE, plItem->i_id );
- item->setData( 0, IN_ITEM_ROLE, QVariant::fromValue( (void*) plItem->p_input ) ); );*/
- return item;
-}
-
-/*
- * Reads and updates the playlist's duration as [xx:xx] after the label in the tree
- * item - the treeview item to get the duration for
- * prefix - the string to use before the time (should be the category name)
- */
-void PLSelector::updateTotalDuration( PLSelItem* item, const char* prefix )
-{
- /* Getting the playlist */
- QVariant playlistVariant = item->treeItem()->data( 0, PL_ITEM_ROLE );
- playlist_item_t* node = playlistVariant.value<playlist_item_t*>();
-
- /* Get the duration of the playlist item */
- playlist_Lock( THEPL );
- vlc_tick_t mt_duration = playlist_GetNodeDuration( node );
- playlist_Unlock( THEPL );
-
- /* Formatting time */
- QString qs_timeLabel( prefix );
-
- int i_seconds = SEC_FROM_VLC_TICK(mt_duration);
- int i_minutes = i_seconds / 60;
- i_seconds = i_seconds % 60;
- if( i_minutes >= 60 )
- {
- int i_hours = i_minutes / 60;
- i_minutes = i_minutes % 60;
- qs_timeLabel += QString(" [%1:%2:%3]").arg( i_hours ).arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );
- }
- else
- qs_timeLabel += QString( " [%1:%2]").arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );
-
- item->setText( qs_timeLabel );
-}
-
-void PLSelector::createItems()
-{
- /* PL */
- playlistItem = putPLData( addItem( PL_ITEM_TYPE, N_("Playlist"), true ),
- THEPL->p_playing );
- playlistItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PL ) );
- playlistItem->treeItem()->setData( 0, Qt::DecorationRole, QIcon( ":/sidebar/playlist.svg" ) );
- setCurrentItem( playlistItem->treeItem() );
-
- /* SD nodes */
- QTreeWidgetItem *mycomp = addItem( CATEGORY_TYPE, N_("My Computer"), false, true )->treeItem();
- QTreeWidgetItem *devices = addItem( CATEGORY_TYPE, N_("Devices"), false, true )->treeItem();
- QTreeWidgetItem *lan = addItem( CATEGORY_TYPE, N_("Local Network"), false, true )->treeItem();
- QTreeWidgetItem *internet = addItem( CATEGORY_TYPE, N_("Internet"), false, true )->treeItem();
-
-#define NOT_SELECTABLE(w) w->setFlags( w->flags() ^ Qt::ItemIsSelectable );
- NOT_SELECTABLE( mycomp );
- NOT_SELECTABLE( devices );
- NOT_SELECTABLE( lan );
- NOT_SELECTABLE( internet );
-#undef NOT_SELECTABLE
-
- /* SD subnodes */
- char **ppsz_longnames;
- int *p_categories;
- char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames, &p_categories );
- if( !ppsz_names )
- return;
-
- char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
- int *p_category = p_categories;
- for( ; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++ )
- {
- //msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );
-
- PLSelItem *selItem;
- QIcon icon;
- QString name( *ppsz_name );
- switch( *p_category )
- {
- case SD_CAT_INTERNET:
- {
- selItem = addItem( SD_TYPE, *ppsz_longname, false, false, internet );
- if( name.startsWith( "podcast" ) )
- {
- selItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
- selItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
- CONNECT( selItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
- podcastsParent = selItem->treeItem();
- icon = QIcon( ":/sidebar/podcast.svg" );
- }
- else if ( name.startsWith( "lua{" ) )
- {
- int i_head = name.indexOf( "sd='" ) + 4;
- int i_tail = name.indexOf( '\'', i_head );
- QString iconname = QString( ":/sidebar/sd/%1.svg" ).arg( name.mid( i_head, i_tail - i_head ) );
- QResource resource( iconname );
- if ( !resource.isValid() )
- icon = QIcon( ":/sidebar/network.svg" );
- else
- icon = QIcon( iconname );
- }
- }
- break;
- case SD_CAT_DEVICES:
- name = name.mid( 0, name.indexOf( '{' ) );
- selItem = addItem( SD_TYPE, *ppsz_longname, false, false, devices );
- if ( name == "xcb_apps" )
- icon = QIcon( ":/sidebar/screen.svg" );
- else if ( name == "mtp" )
- icon = QIcon( ":/sidebar/mtp.svg" );
- else if ( name == "disc" )
- icon = QIcon( ":/sidebar/disc.svg" );
- else
- icon = QIcon( ":/sidebar/capture.svg" );
- break;
- case SD_CAT_LAN:
- selItem = addItem( SD_TYPE, *ppsz_longname, false, false, lan );
- icon = QIcon( ":/sidebar/lan.svg" );
- break;
- case SD_CAT_MYCOMPUTER:
- name = name.mid( 0, name.indexOf( '{' ) );
- selItem = addItem( SD_TYPE, *ppsz_longname, false, false, mycomp );
- if ( name == "video_dir" )
- icon = QIcon( ":/sidebar/movie.svg" );
- else if ( name == "audio_dir" )
- icon = QIcon( ":/sidebar/music.svg" );
- else if ( name == "picture_dir" )
- icon = QIcon( ":/sidebar/pictures.svg" );
- else
- icon = QIcon( ":/sidebar/movie.svg" );
- break;
- default:
- selItem = addItem( SD_TYPE, *ppsz_longname );
- }
-
- selItem->treeItem()->setData( 0, SD_CATEGORY_ROLE, *p_category );
- putSDData( selItem, *ppsz_name, *ppsz_longname );
- if ( ! icon.isNull() )
- selItem->treeItem()->setData( 0, Qt::DecorationRole, icon );
-
- free( *ppsz_name );
- free( *ppsz_longname );
- }
- free( ppsz_names );
- free( ppsz_longnames );
- free( p_categories );
-
- if( mycomp->childCount() == 0 ) delete mycomp;
- if( devices->childCount() == 0 ) delete devices;
- if( lan->childCount() == 0 ) delete lan;
- if( internet->childCount() == 0 ) delete internet;
-}
-
-void PLSelector::setSource( QTreeWidgetItem *item )
-{
- if( !item || item == curItem )
- return;
-
- bool b_ok;
- int i_type = item->data( 0, TYPE_ROLE ).toInt( &b_ok );
- if( !b_ok || i_type == CATEGORY_TYPE )
- return;
-
- bool sd_loaded;
- if( i_type == SD_TYPE )
- {
- QString qs = item->data( 0, NAME_ROLE ).toString();
- sd_loaded = playlist_IsServicesDiscoveryLoaded( THEPL, qtu( qs ) );
- if( !sd_loaded )
- {
- if ( playlist_ServicesDiscoveryAdd( THEPL, qtu( qs ) ) != VLC_SUCCESS )
- return ;
-
- services_discovery_descriptor_t test;
-
- if ( playlist_ServicesDiscoveryControl( THEPL, qtu( qs ),
- SD_CMD_DESCRIPTOR, &test ) == VLC_SUCCESS )
- {
- item->setData( 0, CAP_SEARCH_ROLE, (test.i_capabilities & SD_CAP_SEARCH) );
- }
- }
- }
-
- curItem = item;
-
- /* */
- playlist_Lock( THEPL );
- playlist_item_t *pl_item = NULL;
-
- /* Special case for podcast */
- // FIXME: simplify
- if( i_type == SD_TYPE )
- {
- /* Find the right item for the SD */
- /* FIXME: searching by name - what could possibly go wrong? */
- pl_item = playlist_ChildSearchName( &(THEPL->root),
- vlc_gettext(qtu(item->data(0, LONGNAME_ROLE).toString())) );
-
- /* Podcasts */
- if( item->data( 0, SPECIAL_ROLE ).toInt() == IS_PODCAST )
- {
- if( pl_item && !sd_loaded )
- {
- podcastsParentId = pl_item->i_id;
- for( int i=0; i < pl_item->i_children; i++ )
- addPodcastItem( pl_item->pp_children[i] );
- }
- pl_item = NULL; //to prevent activating it
- }
- }
- else
- pl_item = item->data( 0, PL_ITEM_ROLE ).value<playlist_item_t*>();
-
- playlist_Unlock( THEPL );
-
- /* */
- if( pl_item )
- {
- emit categoryActivated( pl_item, false );
- int i_cat = item->data( 0, SD_CATEGORY_ROLE ).toInt();
- emit SDCategorySelected( i_cat == SD_CAT_INTERNET
- || i_cat == SD_CAT_LAN );
- }
-}
-
-PLSelItem * PLSelector::addItem (
- SelectorItemType type, const char* str, bool drop, bool bold,
- QTreeWidgetItem* parentItem )
-{
- QTreeWidgetItem *item = parentItem ?
- new QTreeWidgetItem( parentItem ) : new QTreeWidgetItem( this );
-
- PLSelItem *selItem = new PLSelItem( item, qtr( str ) );
- if ( bold ) selItem->setStyleSheet( "font-weight: bold;" );
- setItemWidget( item, 0, selItem );
- item->setData( 0, TYPE_ROLE, (int)type );
- if( !drop ) item->setFlags( item->flags() & ~Qt::ItemIsDropEnabled );
-
- return selItem;
-}
-
-PLSelItem *PLSelector::addPodcastItem( playlist_item_t *p_item )
-{
- input_item_Hold( p_item->p_input );
-
- char *psz_name = input_item_GetName( p_item->p_input );
- PLSelItem *item = addItem( PL_ITEM_TYPE, psz_name, false, false, podcastsParent );
- free( psz_name );
-
- item->addAction( RM_ACTION, qtr( "Remove this podcast subscription" ) );
- item->treeItem()->setData( 0, PL_ITEM_ROLE, QVariant::fromValue( p_item ) );
- item->treeItem()->setData( 0, PL_ITEM_ID_ROLE, QVariant(p_item->i_id) );
- item->treeItem()->setData( 0, IN_ITEM_ROLE, QVariant::fromValue( p_item->p_input ) );
- CONNECT( item, action( PLSelItem* ), this, podcastRemove( PLSelItem* ) );
- return item;
-}
-
-QStringList PLSelector::mimeTypes() const
-{
- QStringList types;
- types << "vlc/qt-input-items";
- return types;
-}
-
-bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int,
- const QMimeData * data, Qt::DropAction )
-{
- if( !parent ) return false;
-
- QVariant type = parent->data( 0, TYPE_ROLE );
- if( type == QVariant() ) return false;
-
- int i_truth = parent->data( 0, SPECIAL_ROLE ).toInt();
- if( i_truth != IS_PL ) return false;
-
- const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
- if( !plMimeData ) return false;
-
- QList<input_item_t*> inputItems = plMimeData->inputItems();
-
- playlist_Lock( THEPL );
-
- foreach( input_item_t *p_input, inputItems )
- {
- playlist_item_t *p_item = playlist_ItemGetByInput( THEPL, p_input );
- if( !p_item ) continue;
-
- playlist_NodeAddCopy( THEPL, p_item, THEPL->p_playing, PLAYLIST_END );
- }
-
- playlist_Unlock( THEPL );
-
- return true;
-}
-
-void PLSelector::dragMoveEvent ( QDragMoveEvent * event )
-{
- event->setDropAction( Qt::CopyAction );
- QAbstractItemView::dragMoveEvent( event );
-}
-
-void PLSelector::plItemAdded( int item, int parent )
-{
- updateTotalDuration(playlistItem, "Playlist");
- if( parent != podcastsParentId || podcastsParent == NULL ) return;
-
- playlist_Lock( THEPL );
-
- playlist_item_t *p_item = playlist_ItemGetById( THEPL, item );
- if( !p_item ) {
- playlist_Unlock( THEPL );
- return;
- }
-
- int c = podcastsParent->childCount();
- for( int i = 0; i < c; i++ )
- {
- QTreeWidgetItem *podItem = podcastsParent->child(i);
- if( podItem->data( 0, PL_ITEM_ID_ROLE ).toInt() == item )
- {
- //msg_Dbg( p_intf, "Podcast already in: (%d) %s", item, p_item->p_input->psz_uri);
- playlist_Unlock( THEPL );
- return;
- }
- }
-
- //msg_Dbg( p_intf, "Adding podcast: (%d) %s", item, p_item->p_input->psz_uri );
- addPodcastItem( p_item );
-
- playlist_Unlock( THEPL );
-
- podcastsParent->setExpanded( true );
-}
-
-void PLSelector::plItemRemoved( int id )
-{
- updateTotalDuration(playlistItem, "Playlist");
- if( !podcastsParent ) return;
-
- int c = podcastsParent->childCount();
- for( int i = 0; i < c; i++ )
- {
- QTreeWidgetItem *item = podcastsParent->child(i);
- if( item->data( 0, PL_ITEM_ID_ROLE ).toInt() == id )
- {
- input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
- //msg_Dbg( p_intf, "Removing podcast: (%d) %s", id, p_input->psz_uri );
- input_item_Release( p_input );
- delete item;
- return;
- }
- }
-}
-
-void PLSelector::inputItemUpdate( input_item_t *arg )
-{
- updateTotalDuration(playlistItem, "Playlist");
-
- if( podcastsParent == NULL )
- return;
-
- int c = podcastsParent->childCount();
- for( int i = 0; i < c; i++ )
- {
- QTreeWidgetItem *item = podcastsParent->child(i);
- input_item_t *p_input = item->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
- if( p_input == arg )
- {
- PLSelItem *si = itemWidget( item );
- char *psz_name = input_item_GetName( p_input );
- si->setText( qfu( psz_name ) );
- free( psz_name );
- return;
- }
- }
-}
-
-void PLSelector::podcastAdd( PLSelItem * )
-{
- assert( podcastsParent );
-
- bool ok;
- QString url = QInputDialog::getText( this, qtr( "Subscribe" ),
- qtr( "Enter URL of the podcast to subscribe to:" ),
- QLineEdit::Normal, QString(), &ok );
- if( !ok || url.isEmpty() ) return;
-
- setSource( podcastsParent ); //to load the SD in case it's not loaded
-
- QString request("ADD:");
- request += url.trimmed();
- var_SetString( THEPL, "podcast-request", qtu( request ) );
-}
-
-void PLSelector::podcastRemove( PLSelItem* item )
-{
- QString question ( qtr( "Do you really want to unsubscribe from %1?" ) );
- question = question.arg( item->text() );
- QMessageBox::StandardButton res =
- QMessageBox::question( this, qtr( "Unsubscribe" ), question,
- QMessageBox::Yes | QMessageBox::No,
- QMessageBox::No );
- if( res == QMessageBox::No ) return;
-
- input_item_t *input = item->treeItem()->data( 0, IN_ITEM_ROLE ).value<input_item_t*>();
- if( !input ) return;
-
- QString request("RM:");
- char *psz_uri = input_item_GetURI( input );
- request += qfu( psz_uri );
- var_SetString( THEPL, "podcast-request", qtu( request ) );
- free( psz_uri );
-}
-
-PLSelItem * PLSelector::itemWidget( QTreeWidgetItem *item )
-{
- return ( static_cast<PLSelItem*>( QTreeWidget::itemWidget( item, 0 ) ) );
-}
-
-void PLSelector::drawBranches ( QPainter * painter, const QRect & rect, const QModelIndex & index ) const
-{
- if( !model()->hasChildren( index ) ) return;
- QStyleOption option;
- option.initFrom( this );
- option.rect = rect.adjusted( rect.width() - indentation(), 0, 0, 0 );
- style()->drawPrimitive( isExpanded( index ) ?
- QStyle::PE_IndicatorArrowDown :
- QStyle::PE_IndicatorArrowRight, &option, painter );
-}
-
-void PLSelector::getCurrentItemInfos( int* type, bool* can_delay_search, QString *string)
-{
- *type = currentItem()->data( 0, TYPE_ROLE ).toInt();
- *string = currentItem()->data( 0, NAME_ROLE ).toString();
- *can_delay_search = currentItem()->data( 0, CAP_SEARCH_ROLE ).toBool();
-}
-
-int PLSelector::getCurrentItemCategory()
-{
- return currentItem()->data( 0, SPECIAL_ROLE ).toInt();
-}
-
-void PLSelector::wheelEvent( QWheelEvent *e )
-{
- if( verticalScrollBar()->isVisible() && (
- (verticalScrollBar()->value() != verticalScrollBar()->minimum() && e->delta() >= 0 ) ||
- (verticalScrollBar()->value() != verticalScrollBar()->maximum() && e->delta() < 0 )
- ) )
- QApplication::sendEvent(verticalScrollBar(), e);
-
- // Accept this event in order to prevent unwanted volume up/down changes
- e->accept();
-}
diff --git a/modules/gui/qt/components/playlist/selector.hpp b/modules/gui/qt/components/playlist/selector.hpp
deleted file mode 100644
index 4ccf98ebe8..0000000000
--- a/modules/gui/qt/components/playlist/selector.hpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*****************************************************************************
- * selector.hpp : Playlist source selector
- ****************************************************************************
- * Copyright (C) 2000-2009 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Jean-Baptiste Kempf
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_SELECTOR_HPP_
-#define VLC_QT_SELECTOR_HPP_
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "qt.hpp"
-#include "util/customwidgets.hpp" /* QFramelessButton */
-
-#include <QTreeWidget>
-
-class QHBoxLayout;
-class QPainter;
-class QTreeWidgetItem;
-class QLabel;
-
-enum SelectorItemType {
- CATEGORY_TYPE,
- SD_TYPE,
- PL_ITEM_TYPE,
- SQL_ML_TYPE,
-};
-
-enum SpecialData {
- IS_PODCAST = 1,
- IS_PL,
-};
-
-enum {
- TYPE_ROLE = Qt::UserRole + 1,
- NAME_ROLE, //QString
- LONGNAME_ROLE, //QString
- PL_ITEM_ROLE, //playlist_item_t*
- PL_ITEM_ID_ROLE, //playlist_item_t->i_id
- IN_ITEM_ROLE, //input_item_t->i_id
- SPECIAL_ROLE, //SpecialData
- CAP_SEARCH_ROLE,
- SD_CATEGORY_ROLE,
-};
-
-enum ItemAction {
- ADD_ACTION,
- RM_ACTION
-};
-
-
-class SelectorActionButton : public QFramelessButton
-{
-protected:
- void paintEvent( QPaintEvent * ) Q_DECL_OVERRIDE;
-};
-
-class PLSelItem : public QWidget
-{
- Q_OBJECT
-public:
- PLSelItem( QTreeWidgetItem*, const QString& );
-
- void setText( const QString& text ) { lbl->setText( text ); }
- QString text() const { return lbl->text(); }
-
- void addAction( ItemAction, const QString& toolTip = 0 );
- QTreeWidgetItem *treeItem() { return qitem; }
-
-public slots:
- void showAction() { if( lblAction ) lblAction->show(); }
- void hideAction() { if( lblAction ) lblAction->hide(); }
-
-private slots:
- void triggerAction() { emit action( this ); }
-
-signals:
- void action( PLSelItem* );
-
-private:
- inline void enterEvent( QEvent* ){ showAction(); }
- inline void leaveEvent( QEvent* ){ hideAction(); }
-
- QTreeWidgetItem* qitem;
- QFramelessButton* lblAction;
- QLabel* lbl;
- QHBoxLayout* layout;
-};
-
-#include <vlc_input_item.h>
-
-Q_DECLARE_METATYPE( playlist_item_t *);
-Q_DECLARE_METATYPE( input_item_t *);
-class PLSelector: public QTreeWidget
-{
- Q_OBJECT
-public:
- PLSelector( QWidget *p, intf_thread_t *_p_intf );
- virtual ~PLSelector();
-
- void getCurrentItemInfos( int *type, bool *delayedSearch, QString *name );
- int getCurrentItemCategory();
-
-protected:
- void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const Q_DECL_OVERRIDE;
- void dragMoveEvent ( QDragMoveEvent * event ) Q_DECL_OVERRIDE;
- bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction ) Q_DECL_OVERRIDE;
- QStringList mimeTypes () const Q_DECL_OVERRIDE;
- void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
-
-private:
- void createItems();
- PLSelItem * addItem ( SelectorItemType type, const char* str,
- bool drop = false, bool bold = false, QTreeWidgetItem* parentItem = 0 );
- PLSelItem * addPodcastItem( playlist_item_t *p_item );
-
- PLSelItem* playlistItem;
-
- void updateTotalDuration(PLSelItem*, const char*);
-
- inline PLSelItem * itemWidget( QTreeWidgetItem * );
-
- intf_thread_t *p_intf;
- QTreeWidgetItem *podcastsParent;
- int podcastsParentId;
- QTreeWidgetItem *curItem;
-
-private slots:
- void setSource( QTreeWidgetItem *item );
- void plItemAdded( int, int );
- void plItemRemoved( int );
- void inputItemUpdate( input_item_t * );
- void podcastAdd( PLSelItem* );
- void podcastRemove( PLSelItem* );
-
-signals:
- void categoryActivated( playlist_item_t *, bool );
- void SDCategorySelected( bool );
-};
-
-#endif
diff --git a/modules/gui/qt/components/playlist/sorting.h b/modules/gui/qt/components/playlist/sorting.h
deleted file mode 100644
index 07ac2250cf..0000000000
--- a/modules/gui/qt/components/playlist/sorting.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*****************************************************************************
- * sorting.h : commun sorting & column display code
- ****************************************************************************
- * Copyright © 2008 the VideoLAN team and AUTHORS
- *
- * Authors: Rafaël Carré <funman at videolanorg>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_SORTING_H_
-#define VLC_QT_SORTING_H_
-
-#include <vlc_media_library.h>
-#include <vlc_input_item.h>
-
-/* You can use these numbers with | and & to determine what you want to show */
-enum
-{
- COLUMN_TITLE = 0x0001,
- COLUMN_DURATION = 0x0002,
- COLUMN_ARTIST = 0x0004,
- COLUMN_GENRE = 0x0008,
- COLUMN_ALBUM = 0x0010,
- COLUMN_TRACK_NUMBER = 0x0020,
- COLUMN_DESCRIPTION = 0x0040,
- COLUMN_URI = 0x0080,
- COLUMN_NUMBER = 0x0100,
- COLUMN_RATING = 0x0200,
- COLUMN_COVER = 0x0400,
- COLUMN_DISC_NUMBER = 0x0800,
- COLUMN_DATE = 0x1000,
-
- /* Add new entries here and update the COLUMN_END value*/
-
- COLUMN_END = 0x2000
-};
-
-#define COLUMN_DEFAULT (COLUMN_TITLE|COLUMN_DURATION|COLUMN_ALBUM)
-
-/* Return the title of a column */
-static inline const char * psz_column_title( uint32_t i_column )
-{
- switch( i_column )
- {
- case COLUMN_NUMBER: return _("ID");
- case COLUMN_TITLE: return VLC_META_TITLE;
- case COLUMN_DURATION: return _("Duration");
- case COLUMN_ARTIST: return VLC_META_ARTIST;
- case COLUMN_GENRE: return VLC_META_GENRE;
- case COLUMN_ALBUM: return VLC_META_ALBUM;
- case COLUMN_TRACK_NUMBER: return VLC_META_TRACK_NUMBER;
- case COLUMN_DESCRIPTION: return VLC_META_DESCRIPTION;
- case COLUMN_URI: return _("URI");
- case COLUMN_RATING: return VLC_META_RATING;
- case COLUMN_COVER: return _("Cover");
- case COLUMN_DISC_NUMBER: return VLC_META_DISCNUMBER;
- case COLUMN_DATE: return VLC_META_DATE;
- default: abort();
- }
-}
-
-/* Return the meta data associated with an item for a column
- * Returned value has to be freed */
-static inline char * psz_column_meta( input_item_t *p_item, uint32_t i_column )
-{
- int i_duration;
- char psz_duration[MSTRTIME_MAX_SIZE];
- switch( i_column )
- {
- case COLUMN_NUMBER:
- return NULL;
- case COLUMN_TITLE:
- return input_item_GetTitleFbName( p_item );
- case COLUMN_DURATION:
- i_duration = SEC_FROM_VLC_TICK( input_item_GetDuration( p_item ) );
- if( i_duration == 0 ) return NULL;
- secstotimestr( psz_duration, i_duration );
- return strdup( psz_duration );
- case COLUMN_ARTIST:
- return input_item_GetArtist( p_item );
- case COLUMN_GENRE:
- return input_item_GetGenre( p_item );
- case COLUMN_ALBUM:
- return input_item_GetAlbum( p_item );
- case COLUMN_TRACK_NUMBER:
- return input_item_GetTrackNum( p_item );
- case COLUMN_DESCRIPTION:
- return input_item_GetDescription( p_item );
- case COLUMN_URI:
- return input_item_GetURI( p_item );
- case COLUMN_RATING:
- return input_item_GetRating( p_item );
- case COLUMN_COVER:
- return input_item_GetArtworkURL( p_item );
- case COLUMN_DISC_NUMBER:
- return input_item_GetDiscNumber( p_item );
- case COLUMN_DATE:
- return input_item_GetDate( p_item );
- default:
- abort();
- }
-}
-
-/* Return the playlist sorting mode for a given column */
-static inline int i_column_sorting( uint32_t i_column )
-{
- switch( i_column )
- {
- case COLUMN_NUMBER: return SORT_ID;
- case COLUMN_TITLE: return SORT_TITLE_NODES_FIRST;
- case COLUMN_DURATION: return SORT_DURATION;
- case COLUMN_ARTIST: return SORT_ARTIST;
- case COLUMN_GENRE: return SORT_GENRE;
- case COLUMN_ALBUM: return SORT_ALBUM;
- case COLUMN_TRACK_NUMBER: return SORT_TRACK_NUMBER;
- case COLUMN_DESCRIPTION: return SORT_DESCRIPTION;
- case COLUMN_URI: return SORT_URI;
- case COLUMN_RATING: return SORT_RATING;
- case COLUMN_DISC_NUMBER: return SORT_DISC_NUMBER;
- case COLUMN_DATE: return SORT_DATE;
- default: abort();
- }
-}
-
-#endif
diff --git a/modules/gui/qt/components/playlist/standardpanel.cpp b/modules/gui/qt/components/playlist/standardpanel.cpp
deleted file mode 100644
index 1ac31e7182..0000000000
--- a/modules/gui/qt/components/playlist/standardpanel.cpp
+++ /dev/null
@@ -1,842 +0,0 @@
-/*****************************************************************************
- * standardpanel.cpp : The "standard" playlist panel : just a treeview
- ****************************************************************************
- * Copyright © 2000-2010 VideoLAN
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- * Jean-Baptiste Kempf <jb at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "components/playlist/standardpanel.hpp"
-
-#include "components/playlist/vlc_model.hpp" /* VLCModel */
-#include "components/playlist/playlist_model.hpp" /* PLModel */
-#include "components/playlist/views.hpp" /* 3 views */
-#include "components/playlist/selector.hpp" /* PLSelector */
-#include "util/animators.hpp" /* PixmapAnimator */
-#include "menus.hpp" /* Popup */
-#include "input_manager.hpp" /* THEMIM */
-#include "dialogs_provider.hpp" /* THEDP */
-#include "recents.hpp" /* RecentMRL */
-#include "dialogs/playlist.hpp" /* Playlist Dialog */
-#include "dialogs/mediainfo.hpp" /* MediaInfoDialog */
-#include "util/qt_dirs.hpp"
-#include "util/imagehelper.hpp"
-
-#include <vlc_services_discovery.h> /* SD_CMD_SEARCH */
-#include <vlc_intf_strings.h> /* POP_ */
-
-#define SPINNER_SIZE 32
-#define I_NEW_DIR \
- I_DIR_OR_FOLDER( N_("Create Directory"), N_( "Create Folder" ) )
-#define I_NEW_DIR_NAME \
- I_DIR_OR_FOLDER( N_( "Enter name for new directory:" ), \
- N_( "Enter name for new folder:" ) )
-
-#define I_RENAME_DIR \
- I_DIR_OR_FOLDER( N_("Rename Directory"), N_( "Rename Folder" ) )
-#define I_RENAME_DIR_NAME \
- I_DIR_OR_FOLDER( N_( "Enter a new name for the directory:" ), \
- N_( "Enter a new name for the folder:" ) )
-
-#include <QHeaderView>
-#include <QMenu>
-#include <QKeyEvent>
-#include <QWheelEvent>
-#include <QStackedLayout>
-#include <QSignalMapper>
-#include <QSettings>
-#include <QStylePainter>
-#include <QInputDialog>
-#include <QDesktopServices>
-#include <QUrl>
-#include <QFont>
-
-#include <assert.h>
-
-#define DROPZONE_SIZE 112
-
-/* local helper */
-inline QModelIndex popupIndex( QAbstractItemView *view );
-
-StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
- intf_thread_t *_p_intf,
- playlist_item_t *p_root,
- PLSelector *_p_selector,
- VLCModel *_p_model )
- : QWidget( _parent ),
- model( _p_model ),
- p_intf( _p_intf ),
- p_selector( _p_selector )
-{
- viewStack = new QStackedLayout( this );
- viewStack->setSpacing( 0 ); viewStack->setMargin( 0 );
- setMinimumWidth( 300 );
-
- iconView = NULL;
- treeView = NULL;
- listView = NULL;
- picFlowView = NULL;
-
- currentRootIndexPLId = -1;
- lastActivatedPLItemId = -1;
-
- QList<QString> frames;
- frames << ":/util/wait1.svg";
- frames << ":/util/wait2.svg";
- frames << ":/util/wait3.svg";
- frames << ":/util/wait4.svg";
- spinnerAnimation = new PixmapAnimator( this, frames, SPINNER_SIZE, SPINNER_SIZE );
- CONNECT( spinnerAnimation, pixmapReady( const QPixmap & ), this, updateViewport() );
-
- /* Saved Settings */
- int i_savedViewMode = getSettings()->value( "Playlist/view-mode", TREE_VIEW ).toInt();
-
- QFont font = QApplication::font();
- font.setPointSize( font.pointSize() + getSettings()->value( "Playlist/zoom", 0 ).toInt() );
- model->setData( QModelIndex(), font, Qt::FontRole );
-
- showView( i_savedViewMode );
-
- DCONNECT( THEMIM, leafBecameParent( int ),
- this, browseInto( int ) );
-
- CONNECT( model, currentIndexChanged( const QModelIndex& ),
- this, handleExpansion( const QModelIndex& ) );
- CONNECT( model, rootIndexChanged(), this, browseInto() );
-
- setRootItem( p_root, false );
-}
-
-StandardPLPanel::~StandardPLPanel()
-{
- getSettings()->beginGroup("Playlist");
- if( treeView )
- getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
- getSettings()->setValue( "view-mode", currentViewIndex() );
- getSettings()->setValue( "zoom",
- model->data( QModelIndex(), Qt::FontRole ).value<QFont>().pointSize()
- - QApplication::font().pointSize() );
- getSettings()->endGroup();
-}
-
-/* Unused anymore, but might be useful, like in right-click menu */
-void StandardPLPanel::gotoPlayingItem()
-{
- currentView->scrollTo( model->currentIndex() );
-}
-
-void StandardPLPanel::handleExpansion( const QModelIndex& index )
-{
- assert( currentView );
- if( currentRootIndexPLId != -1 && currentRootIndexPLId != model->itemId( index.parent() ) )
- browseInto( index.parent() );
- currentView->scrollTo( index );
-}
-
-void StandardPLPanel::popupPlView( const QPoint &point )
-{
- QPoint globalPoint = currentView->viewport()->mapToGlobal( point );
- QModelIndex index = currentView->indexAt( point );
- if ( !index.isValid() )
- {
- currentView->clearSelection();
- }
- else if ( ! currentView->selectionModel()->selectedIndexes().contains( index ) )
- {
- currentView->selectionModel()->select( index, QItemSelectionModel::Select );
- }
-
- if( !popup( globalPoint ) ) THEDP->setPopupMenu();
-}
-
-/*********** Popup *********/
-bool StandardPLPanel::popup( const QPoint &point )
-{
- QModelIndex index = popupIndex( currentView ); /* index for menu logic only. Do not store.*/
- VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
-
-#define ADD_MENU_ENTRY( icon, title, act ) \
- if ( model->isSupportedAction( act, index ) )\
- {\
- action = menu.addAction( icon, title ); \
- container.action = act; \
- action->setData( QVariant::fromValue( container ) );\
- }
-
- /* */
- QMenu menu;
- QAction *action;
- VLCModelSubInterface::actionsContainerType container;
-
- /* Play/Stream/Info static actions */
-
- ADD_MENU_ENTRY( QIcon( ":/toolbar/play_b.svg" ), qtr(I_POP_PLAY),
- VLCModelSubInterface::ACTION_PLAY )
-
- ADD_MENU_ENTRY( QIcon( ":/toolbar/pause_b.svg" ), qtr("Pause"),
- VLCModelSubInterface::ACTION_PAUSE )
-
- ADD_MENU_ENTRY( QIcon( ":/menu/stream.svg" ), qtr(I_POP_STREAM),
- VLCModelSubInterface::ACTION_STREAM )
-
- ADD_MENU_ENTRY( QIcon(), qtr(I_POP_SAVE),
- VLCModelSubInterface::ACTION_SAVE );
-
- ADD_MENU_ENTRY( QIcon( ":/menu/info.svg" ), qtr(I_POP_INFO),
- VLCModelSubInterface::ACTION_INFO );
-
- menu.addSeparator();
-
- ADD_MENU_ENTRY( QIcon( ":/type/folder-grey.svg" ), qtr(I_POP_EXPLORE),
- VLCModelSubInterface::ACTION_EXPLORE );
-
- QIcon addIcon( ":/buttons/playlist/playlist_add.svg" );
-
- ADD_MENU_ENTRY( addIcon, qtr(I_POP_NEWFOLDER),
- VLCModelSubInterface::ACTION_CREATENODE )
-
- ADD_MENU_ENTRY( QIcon(), qtr(I_POP_RENAMEFOLDER),
- VLCModelSubInterface::ACTION_RENAMENODE )
-
- menu.addSeparator();
- /* In PL or ML, allow to add a file/folder */
- ADD_MENU_ENTRY( addIcon, qtr(I_PL_ADDF),
- VLCModelSubInterface::ACTION_ENQUEUEFILE )
-
- ADD_MENU_ENTRY( addIcon, qtr(I_PL_ADDDIR),
- VLCModelSubInterface::ACTION_ENQUEUEDIR )
-
- ADD_MENU_ENTRY( addIcon, qtr(I_OP_ADVOP),
- VLCModelSubInterface::ACTION_ENQUEUEGENERIC )
-
- ADD_MENU_ENTRY( QIcon(), qtr(I_PL_ADDPL),
- VLCModelSubInterface::ACTION_ADDTOPLAYLIST );
-
- menu.addSeparator();
- ADD_MENU_ENTRY( QIcon(), qtr( I_PL_SAVE ),
- VLCModelSubInterface::ACTION_SAVETOPLAYLIST );
-
- menu.addSeparator();
-
- /* Item removal */
-
- ADD_MENU_ENTRY( QIcon( ":/buttons/playlist/playlist_remove.svg" ), qtr(I_POP_DEL),
- VLCModelSubInterface::ACTION_REMOVE );
-
- ADD_MENU_ENTRY( QIcon( ":/toolbar/clear.svg" ), qtr("Clear the playlist"),
- VLCModelSubInterface::ACTION_CLEAR );
-
- menu.addSeparator();
-
- /* Playlist sorting */
- if ( model->isSupportedAction( VLCModelSubInterface::ACTION_SORT, index ) )
- {
- QMenu *sortingMenu = new QMenu( qtr( "Sort by" ), &menu );
- /* Choose what columns to show in sorting menu, not sure if this should be configurable*/
- QList<int> sortingColumns;
- sortingColumns << COLUMN_TITLE << COLUMN_ARTIST << COLUMN_ALBUM << COLUMN_TRACK_NUMBER << COLUMN_URI << COLUMN_DISC_NUMBER;
- container.action = VLCModelSubInterface::ACTION_SORT;
- foreach( int Column, sortingColumns )
- {
- action = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Ascending") );
- container.column = model->columnFromMeta(Column) + 1;
- action->setData( QVariant::fromValue( container ) );
-
- action = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Descending") );
- container.column = -1 * (model->columnFromMeta(Column)+1);
- action->setData( QVariant::fromValue( container ) );
- }
- menu.addMenu( sortingMenu );
- }
-
- /* Zoom */
- QMenu *zoomMenu = new QMenu( qtr( "Display size" ), &menu );
- zoomMenu->addAction( qtr( "Increase" ), this, SLOT( increaseZoom() ) );
- zoomMenu->addAction( qtr( "Decrease" ), this, SLOT( decreaseZoom() ) );
- menu.addMenu( zoomMenu );
-
- CONNECT( &menu, triggered( QAction * ), this, popupAction( QAction * ) );
-
- menu.addMenu( StandardPLPanel::viewSelectionMenu( this ) );
-
- /* Display and forward the result */
- if( !menu.isEmpty() )
- {
- menu.exec( point ); return true;
- }
- else return false;
-
-#undef ADD_MENU_ENTRY
-}
-
-void StandardPLPanel::popupAction( QAction *action )
-{
- VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
- VLCModelSubInterface::actionsContainerType a =
- action->data().value<VLCModelSubInterface::actionsContainerType>();
- QModelIndexList list = currentView->selectionModel()->selectedRows();
- QModelIndex index = popupIndex( currentView );
- char *path = NULL;
- OpenDialog *dialog;
- QString temp;
- QStringList uris;
- bool ok;
-
- /* first try to complete actions requiring missing parameters thru UI dialogs */
- switch( a.action )
- {
- case VLCModelSubInterface::ACTION_INFO:
- /* locally handled only */
- if( index.isValid() )
- {
- input_item_t* p_input = model->getInputItem( index );
- MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
- mid->setParent( PlaylistDialog::getInstance( p_intf ),
- Qt::Dialog );
- mid->show();
- }
- break;
-
- case VLCModelSubInterface::ACTION_EXPLORE:
- /* locally handled only */
- temp = model->getURI( index );
- if( ! temp.isEmpty() ) path = vlc_uri2path( temp.toLatin1().constData() );
- if( path == NULL ) return;
- QDesktopServices::openUrl(
- QUrl::fromLocalFile( QFileInfo( qfu( path ) ).absolutePath() ) );
- free( path );
- break;
-
- case VLCModelSubInterface::ACTION_STREAM:
- /* locally handled only */
- temp = model->getURI( index );
- if ( ! temp.isEmpty() )
- {
- QStringList tempList;
- tempList.append(temp);
- THEDP->streamingDialog( NULL, tempList, false );
- }
- break;
-
- case VLCModelSubInterface::ACTION_SAVE:
- /* locally handled only */
- temp = model->getURI( index );
- if ( ! temp.isEmpty() )
- {
- QStringList tempList;
- tempList.append(temp);
- THEDP->streamingDialog( NULL, tempList );
- }
- break;
-
- case VLCModelSubInterface::ACTION_CREATENODE:
- temp = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
- qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
- QLineEdit::Normal, QString(), &ok);
- if ( !ok ) return;
- model->createNode( index, temp );
- break;
-
- case VLCModelSubInterface::ACTION_RENAMENODE:
- temp = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
- qtr( I_RENAME_DIR ), qtr( I_RENAME_DIR_NAME ),
- QLineEdit::Normal, model->getTitle( index ), &ok);
- if ( !ok ) return;
- model->renameNode( index, temp );
- break;
-
- case VLCModelSubInterface::ACTION_ENQUEUEFILE:
- uris = THEDP->showSimpleOpen();
- if ( uris.isEmpty() ) return;
- uris.sort();
- a.uris = uris;
- action->setData( QVariant::fromValue( a ) );
- model->action( action, list );
- break;
-
- case VLCModelSubInterface::ACTION_ENQUEUEDIR:
- temp = DialogsProvider::getDirectoryDialog( p_intf );
- if ( temp.isEmpty() ) return;
- a.uris << temp;
- action->setData( QVariant::fromValue( a ) );
- model->action( action, list );
- break;
-
- case VLCModelSubInterface::ACTION_ENQUEUEGENERIC:
- dialog = OpenDialog::getInstance( this, p_intf, false, SELECT, true );
- dialog->showTab( OPEN_FILE_TAB );
- dialog->exec(); /* make it modal */
- a.uris = dialog->getMRLs();
- a.options = dialog->getOptions();
- if ( a.uris.isEmpty() ) return;
- action->setData( QVariant::fromValue( a ) );
- model->action( action, list );
- break;
-
- case VLCModelSubInterface::ACTION_SAVETOPLAYLIST:
- THEDP->savePlayingToPlaylist();
- break;
- default:
- model->action( action, list );
- }
-}
-
-QMenu* StandardPLPanel::viewSelectionMenu( StandardPLPanel *panel )
-{
- QMenu *viewMenu = new QMenu( qtr( "Playlist View Mode" ), panel );
- QSignalMapper *viewSelectionMapper = new QSignalMapper( viewMenu );
- CONNECT( viewSelectionMapper, mapped( int ), panel, showView( int ) );
-
- QActionGroup *viewGroup = new QActionGroup( viewMenu );
-# define MAX_VIEW StandardPLPanel::VIEW_COUNT
- for( int i = 0; i < MAX_VIEW; i++ )
- {
- QAction *action = viewMenu->addAction( viewNames[i] );
- action->setCheckable( true );
- viewGroup->addAction( action );
- viewSelectionMapper->setMapping( action, i );
- CONNECT( action, triggered(), viewSelectionMapper, map() );
- if( panel->currentViewIndex() == i )
- action->setChecked( true );
- }
- return viewMenu;
-}
-
-inline QModelIndex popupIndex( QAbstractItemView *view )
-{
- QModelIndexList list = view->selectionModel()->selectedIndexes();
- if ( list.isEmpty() )
- return QModelIndex();
- else
- return list.first();
-}
-
-void StandardPLPanel::popupSelectColumn( QPoint )
-{
- QMenu menu;
- assert( treeView );
-
- /* We do not offer the option to hide index 0 column, or
- * QTreeView will behave weird */
- for( int i = 1 << 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
- {
- QAction* option = menu.addAction( qfu( psz_column_title( i ) ) );
- option->setCheckable( true );
- option->setChecked( !treeView->isColumnHidden( j ) );
- selectColumnsSigMapper->setMapping( option, j );
- CONNECT( option, triggered(), selectColumnsSigMapper, map() );
- }
- menu.exec( QCursor::pos() );
-}
-
-void StandardPLPanel::toggleColumnShown( int i )
-{
- treeView->setColumnHidden( i, !treeView->isColumnHidden( i ) );
-}
-
-/* Search in the playlist */
-void StandardPLPanel::search( const QString& searchText )
-{
- int type;
- QString name;
- bool can_search;
- p_selector->getCurrentItemInfos( &type, &can_search, &name );
-
- if( type != SD_TYPE || !can_search )
- {
- bool flat = ( currentView == iconView ||
- currentView == listView ||
- currentView == picFlowView );
- model->filter( searchText,
- flat ? currentView->rootIndex() : QModelIndex(),
- !flat );
- }
-}
-
-void StandardPLPanel::searchDelayed( const QString& searchText )
-{
- int type;
- QString name;
- bool can_search;
- p_selector->getCurrentItemInfos( &type, &can_search, &name );
-
- if( type == SD_TYPE && can_search )
- {
- if( !name.isEmpty() && !searchText.isEmpty() )
- playlist_ServicesDiscoveryControl( THEPL, qtu( name ), SD_CMD_SEARCH,
- qtu( searchText ) );
- }
-}
-
-/* Set the root of the new Playlist */
-/* This activated by the selector selection */
-void StandardPLPanel::setRootItem( playlist_item_t *p_item, bool b )
-{
- Q_UNUSED( b );
- model->rebuild( p_item );
-}
-
-void StandardPLPanel::browseInto( const QModelIndex &index )
-{
- if( currentView == iconView || currentView == listView || currentView == picFlowView )
- {
-
- currentView->setRootIndex( index );
-
- /* When going toward root in LocationBar, scroll to the item
- that was previously as root */
- QModelIndex newIndex = model->indexByPLID(currentRootIndexPLId,0);
- while( newIndex.isValid() && (newIndex.parent() != index) )
- newIndex = newIndex.parent();
- if( newIndex.isValid() )
- currentView->scrollTo( newIndex );
-
- /* Store new rootindexid*/
- currentRootIndexPLId = model->itemId( index );
-
- model->ensureArtRequested( index );
- }
-
- emit viewChanged( index );
-}
-
-void StandardPLPanel::browseInto()
-{
- browseInto( (currentRootIndexPLId != -1 && currentView != treeView) ?
- model->indexByPLID( currentRootIndexPLId, 0 ) :
- QModelIndex() );
-}
-
-void StandardPLPanel::wheelEvent( QWheelEvent *e )
-{
- if( e->modifiers() & Qt::ControlModifier ) {
- int numSteps = e->delta() / 8 / 15;
- if( numSteps > 0)
- increaseZoom();
- else if( numSteps < 0)
- decreaseZoom();
- }
- // Accept this event in order to prevent unwanted volume up/down changes
- e->accept();
-}
-
-bool StandardPLPanel::eventFilter ( QObject *obj, QEvent * event )
-{
- if (event->type() == QEvent::KeyPress)
- {
- QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
- if( keyEvent->key() == Qt::Key_Delete ||
- keyEvent->key() == Qt::Key_Backspace )
- {
- deleteSelection();
- return true;
- }
- }
- else if ( event->type() == QEvent::Paint )
- {/* Warn! Don't filter events from anything else than views ! */
- if ( model->rowCount() == 0 && p_selector->getCurrentItemCategory() == PL_ITEM_TYPE )
- {
- QWidget *viewport = qobject_cast<QWidget *>( obj );
- QStylePainter painter( viewport );
-
- QPixmap dropzone = ImageHelper::loadSvgToPixmap(":/dropzone.svg", DROPZONE_SIZE, DROPZONE_SIZE);
- QRect rect = viewport->geometry();
-#if HAS_QT56
- qreal scale = dropzone.devicePixelRatio();
- QSize size = rect.size() / 2 - dropzone.size() / (2 * scale);
-#else
- QSize size = rect.size() / 2 - dropzone.size() / 2;
-#endif
- rect.adjust( 0, size.height(), 0 , 0 );
- painter.drawItemPixmap( rect, Qt::AlignHCenter, dropzone );
- /* now select the zone just below the drop zone and let Qt center
- the text by itself */
-#if HAS_QT56
- rect.adjust( 0, dropzone.height() / scale + 10, 0, 0 );
-#else
- rect.adjust( 0, dropzone.height() + 10, 0, 0 );
-#endif
- rect.setRight( viewport->geometry().width() );
- rect.setLeft( 0 );
- painter.drawItemText( rect,
- Qt::AlignHCenter,
- palette(),
- true,
- qtr("Playlist is currently empty.\n"
- "Drop a file here or select a "
- "media source from the left."),
- QPalette::Text );
- }
- else if ( spinnerAnimation->state() == PixmapAnimator::Running )
- {
- if ( currentView->model()->rowCount() )
- spinnerAnimation->stop(); /* Trick until SD emits events */
- else
- {
- QWidget *viewport = qobject_cast<QWidget *>( obj );
- QStylePainter painter( viewport );
- const QPixmap& spinner = spinnerAnimation->getPixmap();
- QPoint point = viewport->geometry().center();
- point -= QPoint( spinner.width() / 2, spinner.height() / 2 );
- painter.drawPixmap( point, spinner );
- }
- }
- }
- return false;
-}
-
-void StandardPLPanel::deleteSelection()
-{
- QModelIndexList list = currentView->selectionModel()->selectedIndexes();
- model->doDelete( list );
-}
-
-void StandardPLPanel::createIconView()
-{
- iconView = new PlIconView( model, this );
- iconView->setContextMenuPolicy( Qt::CustomContextMenu );
- CONNECT( iconView, customContextMenuRequested( const QPoint & ),
- this, popupPlView( const QPoint & ) );
- CONNECT( iconView, activated( const QModelIndex & ),
- this, activate( const QModelIndex & ) );
- iconView->installEventFilter( this );
- iconView->viewport()->installEventFilter( this );
- viewStack->addWidget( iconView );
-}
-
-void StandardPLPanel::createListView()
-{
- listView = new PlListView( model, this );
- listView->setContextMenuPolicy( Qt::CustomContextMenu );
- CONNECT( listView, customContextMenuRequested( const QPoint & ),
- this, popupPlView( const QPoint & ) );
- CONNECT( listView, activated( const QModelIndex & ),
- this, activate( const QModelIndex & ) );
- listView->installEventFilter( this );
- listView->viewport()->installEventFilter( this );
- viewStack->addWidget( listView );
-}
-
-void StandardPLPanel::createCoverView()
-{
- picFlowView = new PicFlowView( model, this );
- picFlowView->setContextMenuPolicy( Qt::CustomContextMenu );
- CONNECT( picFlowView, customContextMenuRequested( const QPoint & ),
- this, popupPlView( const QPoint & ) );
- CONNECT( picFlowView, activated( const QModelIndex & ),
- this, activate( const QModelIndex & ) );
- viewStack->addWidget( picFlowView );
- picFlowView->installEventFilter( this );
-}
-
-void StandardPLPanel::createTreeView()
-{
- /* Create and configure the QTreeView */
- treeView = new PlTreeView( model, this );
-
- /* setModel after setSortingEnabled(true), or the model will sort immediately! */
-
- /* Connections for the TreeView */
- CONNECT( treeView, activated( const QModelIndex& ),
- this, activate( const QModelIndex& ) );
- CONNECT( treeView->header(), customContextMenuRequested( const QPoint & ),
- this, popupSelectColumn( QPoint ) );
- CONNECT( treeView, customContextMenuRequested( const QPoint & ),
- this, popupPlView( const QPoint & ) );
- treeView->installEventFilter( this );
- treeView->viewport()->installEventFilter( this );
-
- /* SignalMapper for columns */
- selectColumnsSigMapper = new QSignalMapper( this );
- CONNECT( selectColumnsSigMapper, mapped( int ),
- this, toggleColumnShown( int ) );
-
- viewStack->addWidget( treeView );
-}
-
-void StandardPLPanel::updateZoom( int i )
-{
- QVariant fontdata = model->data( QModelIndex(), Qt::FontRole );
- QFont font = fontdata.value<QFont>();
- font.setPointSize( font.pointSize() + i );
- if ( font.pointSize() < 5 - QApplication::font().pointSize() ) return;
- if ( font.pointSize() > 3 + QApplication::font().pointSize() ) return;
- model->setData( QModelIndex(), font, Qt::FontRole );
-}
-
-void StandardPLPanel::showView( int i_view )
-{
- bool b_treeViewCreated = false;
-
- switch( i_view )
- {
- case ICON_VIEW:
- {
- if( iconView == NULL )
- createIconView();
- currentView = iconView;
- break;
- }
- case LIST_VIEW:
- {
- if( listView == NULL )
- createListView();
- currentView = listView;
- break;
- }
- case PICTUREFLOW_VIEW:
- {
- if( picFlowView == NULL )
- createCoverView();
- currentView = picFlowView;
- break;
- }
- default:
- case TREE_VIEW:
- {
- if( treeView == NULL )
- {
- createTreeView();
- b_treeViewCreated = true;
- }
- currentView = treeView;
- break;
- }
- }
-
- currentView->setModel( model );
-
- /* Restoring the header Columns must come after changeModel */
- if( b_treeViewCreated )
- {
- assert( treeView );
- if( getSettings()->contains( "Playlist/headerStateV2" ) )
- {
- treeView->header()->restoreState(getSettings()
- ->value( "Playlist/headerStateV2" ).toByteArray() );
- /* if there is allready stuff in playlist, we don't sort it and we reset
- sorting */
- if( model->rowCount() )
- {
- treeView->header()->setSortIndicator( -1 , Qt::AscendingOrder );
- }
- }
- else
- {
- for( int m = 1, c = 0; m != COLUMN_END; m <<= 1, c++ )
- {
- treeView->setColumnHidden( c, !( m & COLUMN_DEFAULT ) );
- if( m == COLUMN_TITLE ) treeView->header()->resizeSection( c, 200 );
- else if( m == COLUMN_DURATION ) treeView->header()->resizeSection( c, 80 );
- }
- }
- }
-
- viewStack->setCurrentWidget( currentView );
- browseInto();
- gotoPlayingItem();
-}
-
-void StandardPLPanel::setWaiting( bool b )
-{
- if ( b )
- {
- spinnerAnimation->setLoopCount( 20 ); /* Trick until SD emits an event */
- spinnerAnimation->start();
- }
- else
- spinnerAnimation->stop();
-}
-
-void StandardPLPanel::updateViewport()
-{
- /* A single update on parent widget won't work */
- currentView->viewport()->repaint();
-}
-
-int StandardPLPanel::currentViewIndex() const
-{
- if( currentView == treeView )
- return TREE_VIEW;
- else if( currentView == iconView )
- return ICON_VIEW;
- else if( currentView == listView )
- return LIST_VIEW;
- else
- return PICTUREFLOW_VIEW;
-}
-
-void StandardPLPanel::cycleViews()
-{
- if( currentView == iconView )
- showView( TREE_VIEW );
- else if( currentView == treeView )
- showView( LIST_VIEW );
- else if( currentView == listView )
-#ifndef NDEBUG
- showView( PICTUREFLOW_VIEW );
- else if( currentView == picFlowView )
-#endif
- showView( ICON_VIEW );
- else
- vlc_assert_unreachable();
-}
-
-void StandardPLPanel::activate( const QModelIndex &index )
-{
- if( currentView->model() == model )
- {
- /* If we are not a leaf node */
- if( !index.data( VLCModelSubInterface::LEAF_NODE_ROLE ).toBool() )
- {
- if( currentView != treeView )
- browseInto( index );
- }
- else
- {
- playlist_Lock( THEPL );
- playlist_item_t *p_item = playlist_ItemGetById( THEPL, model->itemId( index ) );
- if ( p_item )
- {
- p_item->i_flags |= PLAYLIST_SUBITEM_STOP_FLAG;
- lastActivatedPLItemId = p_item->i_id;
- }
- playlist_Unlock( THEPL );
- if ( p_item && index.isValid() )
- model->activateItem( index );
- }
- }
-}
-
-void StandardPLPanel::browseInto( int i_pl_item_id )
-{
- if( i_pl_item_id != lastActivatedPLItemId ) return;
-
- QModelIndex index = model->indexByPLID( i_pl_item_id, 0 );
-
- if( currentView == treeView )
- treeView->setExpanded( index, true );
- else
- browseInto( index );
-
- lastActivatedPLItemId = -1;
-}
diff --git a/modules/gui/qt/components/playlist/standardpanel.hpp b/modules/gui/qt/components/playlist/standardpanel.hpp
deleted file mode 100644
index 51b6b48bbd..0000000000
--- a/modules/gui/qt/components/playlist/standardpanel.hpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/*****************************************************************************
- * standardpanel.hpp : Panels for the playlist
- ****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_STANDARDPANEL_HPP_
-#define VLC_QT_STANDARDPANEL_HPP_
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "qt.hpp"
-#include "components/playlist/playlist.hpp"
-#include "components/playlist/vlc_model.hpp"
-
-#include <QWidget>
-#include <QModelIndexList>
-
-#include <vlc_playlist_legacy.h> /* playlist_item_t */
-
-class QSignalMapper;
-class QWheelEvent;
-class QStackedLayout;
-class QModelIndex;
-
-class QAbstractItemView;
-class QTreeView;
-class PlIconView;
-class PlListView;
-class PicFlowView;
-
-class PLSelector;
-class PlaylistWidget;
-class PixmapAnimator;
-
-class StandardPLPanel: public QWidget
-{
- Q_OBJECT
-
-public:
- StandardPLPanel( PlaylistWidget *, intf_thread_t *,
- playlist_item_t *, PLSelector *, VLCModel * );
- virtual ~StandardPLPanel();
-
- enum { ICON_VIEW = 0,
- TREE_VIEW ,
- LIST_VIEW,
- PICTUREFLOW_VIEW,
- VIEW_COUNT };
-
- int currentViewIndex() const;
-
- static QMenu *viewSelectionMenu(StandardPLPanel *obj);
-
-protected:
- VLCModel *model;
- void wheelEvent( QWheelEvent *e ) Q_DECL_OVERRIDE;
- bool popup( const QPoint &point );
-
-private:
- intf_thread_t *p_intf;
-
- PLSelector *p_selector;
-
- QTreeView *treeView;
- PlIconView *iconView;
- PlListView *listView;
- PicFlowView *picFlowView;
-
- QAbstractItemView *currentView;
-
- QStackedLayout *viewStack;
-
- QSignalMapper *selectColumnsSigMapper;
-
- int lastActivatedPLItemId;
- int currentRootIndexPLId;
-
- void createTreeView();
- void createIconView();
- void createListView();
- void createCoverView();
- void updateZoom( int i_zoom );
- virtual bool eventFilter ( QObject * watched, QEvent * event ) Q_DECL_OVERRIDE;
-
- /* Wait spinner */
- PixmapAnimator *spinnerAnimation;
-
-public slots:
- void setRootItem( playlist_item_t *, bool );
- void browseInto( const QModelIndex& );
- void showView( int );
- void setWaiting( bool ); /* spinner */
-
-private slots:
- void deleteSelection();
- void handleExpansion( const QModelIndex& );
- void activate( const QModelIndex & );
-
- void browseInto();
- void browseInto( int );
-
- void gotoPlayingItem();
-
- void search( const QString& searchText );
- void searchDelayed( const QString& searchText );
-
- void popupPlView( const QPoint & );
- void popupSelectColumn( QPoint );
- void popupAction( QAction * );
- void increaseZoom() { updateZoom( 1 ); };
- void decreaseZoom() { updateZoom( -1 ); };
- void toggleColumnShown( int );
-
- void cycleViews();
- void updateViewport(); /* spinner */
-
-signals:
- void viewChanged( const QModelIndex& );
-};
-
-
-static const QString viewNames[ StandardPLPanel::VIEW_COUNT ]
- = { qtr( "Icons" ),
- qtr( "Detailed List" ),
- qtr( "List" ),
- qtr( "PictureFlow") };
-
-#endif
diff --git a/modules/gui/qt/components/playlist/views.cpp b/modules/gui/qt/components/playlist/views.cpp
deleted file mode 100644
index 7a7aabd954..0000000000
--- a/modules/gui/qt/components/playlist/views.cpp
+++ /dev/null
@@ -1,591 +0,0 @@
-/*****************************************************************************
- * views.cpp : Views for the Playlist
- ****************************************************************************
- * Copyright © 2010 the VideoLAN team
- *
- * Authors: Jean-Baptiste Kempf <jb at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#include "components/playlist/views.hpp"
-#include "components/playlist/vlc_model.hpp" /* VLCModel */
-#include "components/playlist/sorting.h" /* Columns List */
-#include "input_manager.hpp" /* THEMIM */
-
-#include <QPainter>
-#include <QRect>
-#include <QStyleOptionViewItem>
-#include <QFontMetrics>
-#include <QDrag>
-#include <QDragMoveEvent>
-#include <QMetaType>
-#include <QHeaderView>
-#include <QSvgRenderer>
-
-#include <assert.h>
-
-/* ICON_SCALER comes currently from harrison-stetson method, so good value */
-#define ICON_SCALER 16
-#define ART_RADIUS 5
-#define SPACER 5
-
-void AbstractPlViewItemDelegate::paintBackground(
- QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
-{
- /* FIXME: This does not indicate item selection in all QStyles, so for the time being we
- have to draw it ourselves, to ensure visible effect of selection on all platforms */
- /* QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &option,
- painter ); */
-
- painter->save();
- QRect r = option.rect.adjusted( 0, 0, -1, -1 );
- if( option.state & QStyle::State_Selected )
- {
- painter->setBrush( option.palette.color( QPalette::Highlight ) );
- painter->setPen( option.palette.color( QPalette::Highlight ).darker( 150 ) );
- painter->drawRect( r );
- }
- else if( index.data( VLCModel::CURRENT_ITEM_ROLE ).toBool() )
- {
- painter->setBrush( QBrush( Qt::lightGray ) );
- painter->setPen( QColor( Qt::darkGray ) );
- painter->drawRect( r );
- }
- if( option.state & QStyle::State_MouseOver )
- { /* requires WA_hover on viewport */
- painter->setOpacity( 0.5 );
- painter->setPen( Qt::NoPen );
- painter->setBrush( option.palette.color( QPalette::Highlight ).lighter( 150 ) );
- painter->drawRect( option.rect );
- }
- painter->restore();
-}
-
-void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
-{
- QString title = VLCModel::getMeta( index, COLUMN_TITLE );
- QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
-
- QFont font( index.data( Qt::FontRole ).value<QFont>() );
- font.setBold( index.data( VLCModel::CURRENT_ITEM_ROLE ).toBool() );
- painter->setFont( font );
- QFontMetrics fm = painter->fontMetrics();
-
- int averagewidth = fm.averageCharWidth();
- QSize rectSize = option.rect.size();
- int art_width = averagewidth * ICON_SCALER;
- int art_height = averagewidth * ICON_SCALER;
-
- QPixmap artPix = VLCModel::getArtPixmap( index, QSize( art_width, art_height) );
-
- paintBackground( painter, option, index );
-
- painter->save();
-
- QRect artRect( option.rect.x() + ( rectSize.width() - artPix.width() ) / 2,
- option.rect.y() - averagewidth*3 + ( rectSize.height() - artPix.height() ) / 2,
- artPix.width(), artPix.height() );
-
- // Draw the drop shadow
- painter->save();
- painter->setOpacity( 0.7 );
- painter->setBrush( QBrush( Qt::darkGray ) );
- painter->setPen( Qt::NoPen );
- painter->drawRoundedRect( artRect.adjusted( 0, 0, 2, 2 ), ART_RADIUS, ART_RADIUS );
- painter->restore();
-
- // Draw the art pixmap
- QPainterPath artRectPath;
- artRectPath.addRoundedRect( artRect, ART_RADIUS, ART_RADIUS );
- painter->setClipPath( artRectPath );
- painter->drawPixmap( artRect, artPix );
- painter->setClipping( false );
-
- if( option.state & QStyle::State_Selected )
- painter->setPen( option.palette.color( QPalette::HighlightedText ) );
-
-
- //Draw children indicator
- if( !index.data( VLCModel::LEAF_NODE_ROLE ).toBool() )
- {
- QRect r( option.rect );
- r.setSize( QSize( 25, 25 ) );
- r.translate( 5, 5 );
- if( index.data( VLCModel::CURRENT_ITEM_CHILD_ROLE ).toBool() )
- {
- painter->setOpacity( 0.75 );
- QPainterPath nodeRectPath;
- nodeRectPath.addRoundedRect( r, 4, 4 );
- painter->fillPath( nodeRectPath, option.palette.color( QPalette::Highlight ) );
- painter->setOpacity( 1.0 );
- }
- QSvgRenderer renderer( QString(":/type/node.svg") );
- renderer.render(painter, r);
- }
-
- // Draw title
- font.setItalic( true );
-
- QRect textRect;
- textRect.setRect( option.rect.x() , artRect.bottom() + fm.height()/2, option.rect.width(), fm.height() );
-
- painter->drawText( textRect,
- fm.elidedText( title, Qt::ElideRight, textRect.width() ),
- QTextOption( Qt::AlignCenter ) );
-
- // Draw artist
- painter->setPen( painter->pen().color().lighter( 150 ) );
- font.setItalic( false );
- painter->setFont( font );
- fm = painter->fontMetrics();
-
- textRect.moveTop( textRect.bottom() + 1 );
-
- painter->drawText( textRect,
- fm.elidedText( artist, Qt::ElideRight, textRect.width() ),
- QTextOption( Qt::AlignCenter ) );
-
- painter->restore();
-}
-
-QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QModelIndex & index ) const
-{
- QFont f( index.data( Qt::FontRole ).value<QFont>() );
- f.setBold( true );
- QFontMetrics fm( f );
- int textHeight = fm.height();
- int averagewidth = fm.averageCharWidth();
- QSize sz ( averagewidth * ICON_SCALER + 4 * SPACER,
- averagewidth * ICON_SCALER + 4 * SPACER + 2 * textHeight + 1 );
- return sz;
-}
-
-
-#define LISTVIEW_ART_SIZE 45
-
-void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
-{
- QString title = VLCModel::getMeta( index, COLUMN_TITLE );
- QString duration = VLCModel::getMeta( index, COLUMN_DURATION );
- if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration );
-
- QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
- QString album = VLCModel::getMeta( index, COLUMN_ALBUM );
- QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER );
- QString artistAlbum = artist;
- if( !album.isEmpty() )
- {
- if( !artist.isEmpty() ) artistAlbum += ": ";
- artistAlbum += album;
- if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum );
- }
-
- QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );
-
- //Draw selection rectangle and current playing item indication
- paintBackground( painter, option, index );
-
- QRect artRect( artPix.rect() );
- artRect.moveCenter( QPoint( artRect.center().x() + 3,
- option.rect.center().y() ) );
- //Draw album art
- painter->drawPixmap( artRect, artPix );
-
- //Start drawing text
- painter->save();
-
- if( option.state & QStyle::State_Selected )
- painter->setPen( option.palette.color( QPalette::HighlightedText ) );
-
- QTextOption textOpt( Qt::AlignVCenter | Qt::AlignLeft );
- textOpt.setWrapMode( QTextOption::NoWrap );
-
- QFont f( index.data( Qt::FontRole ).value<QFont>() );
-
- //Draw title info
- f.setItalic( true );
- f.setBold( index.data( VLCModel::CURRENT_ITEM_ROLE ).toBool() );
- painter->setFont( f );
- QFontMetrics fm( painter->fontMetrics() );
-
- QRect textRect = option.rect.adjusted( LISTVIEW_ART_SIZE + 10, 0, -10, 0 );
- if( !artistAlbum.isEmpty() )
- {
- textRect.setHeight( fm.height() );
- textRect.moveBottom( option.rect.center().y() - 2 );
- }
-
- //Draw children indicator
- if( !index.data( VLCModel::LEAF_NODE_ROLE ).toBool() )
- {
- qreal pixsize = fm.height();
- QSvgRenderer renderer( QString( ":/type/node.svg" ) );
- renderer.render(painter, QRect(
- textRect.x(), textRect.center().y() - pixsize / 2,
- pixsize, pixsize ) );
- textRect.setLeft( textRect.x() + pixsize + 5 );
- }
-
- painter->drawText( textRect,
- fm.elidedText( title, Qt::ElideRight, textRect.width() ),
- textOpt );
-
- // Draw artist and album info
- if( !artistAlbum.isEmpty() )
- {
- f.setItalic( false );
- painter->setFont( f );
- fm = painter->fontMetrics();
-
- textRect.moveTop( textRect.bottom() + 4 );
- textRect.setLeft( textRect.x() + 20 );
-
- painter->drawText( textRect,
- fm.elidedText( artistAlbum, Qt::ElideRight, textRect.width() ),
- textOpt );
- }
-
- painter->restore();
-}
-
-QSize PlListViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QModelIndex & ) const
-{
- QFont f;
- f.setBold( true );
- QFontMetrics fm( f );
- int height = qMax( LISTVIEW_ART_SIZE, 2 * fm.height() + 4 ) + 6;
- return QSize( 0, height );
-}
-
-
-void PlTreeViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
-{
- if ( index.data( VLCModel::CURRENT_ITEM_ROLE ).toBool() )
- {
- QStyleOptionViewItem myoptions = option;
- myoptions.font.setBold( true );
- AbstractPlViewItemDelegate::paint( painter, myoptions, index );
- }
- else
- {
- AbstractPlViewItemDelegate::paint( painter, option, index );
- }
-}
-
-void CellPixmapDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
-{
- QPixmap pixmap = index.data( Qt::DecorationRole ).value<QPixmap>();
- painter->drawPixmap( option.rect.topLeft(),
- pixmap.scaled( option.rect.size(), Qt::KeepAspectRatio ) );
-}
-
-static inline void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & supportedActions )
-{
- QDrag *drag = new QDrag( view );
- drag->setPixmap( QPixmap( ":/noart64.png" ) );
- drag->setMimeData( view->model()->mimeData(
- view->selectionModel()->selectedIndexes() ) );
- drag->exec( supportedActions );
-}
-
-static void plViewDragMoveEvent( QAbstractItemView *, QDragMoveEvent * event )
-{
- if( event->keyboardModifiers() & Qt::ControlModifier &&
- event->possibleActions() & Qt::CopyAction )
- event->setDropAction( Qt::CopyAction );
- else event->acceptProposedAction();
-}
-
-PlIconView::PlIconView( QAbstractItemModel *, QWidget *parent ) : QListView( parent )
-{
- PlIconViewItemDelegate *delegate = new PlIconViewItemDelegate( this );
-
- setViewMode( QListView::IconMode );
- setMovement( QListView::Static );
- setResizeMode( QListView::Adjust );
- setWrapping( true );
- setUniformItemSizes( true );
- setSelectionMode( QAbstractItemView::ExtendedSelection );
- setSelectionBehavior( QAbstractItemView::SelectRows );
- setDragEnabled(true);
- setAttribute( Qt::WA_MacShowFocusRect, false );
- viewport()->setAttribute( Qt::WA_Hover );
- /* dropping in QListView::IconMode does not seem to work */
- //setAcceptDrops( true );
- //setDropIndicatorShown(true);
-
- setItemDelegate( delegate );
-}
-
-void PlIconView::startDrag ( Qt::DropActions supportedActions )
-{
- plViewStartDrag( this, supportedActions );
-}
-
-void PlIconView::dragMoveEvent ( QDragMoveEvent * event )
-{
- plViewDragMoveEvent( this, event );
- QAbstractItemView::dragMoveEvent( event );
-}
-
-bool PlIconView::viewportEvent ( QEvent * event )
-{
- if ( event->type() == QEvent::ToolTip )
- {
- event->ignore();
- return true;
- }
- else if ( event->type() == QEvent::Wheel )
- {
- QWheelEvent *wEvent = static_cast<QWheelEvent *>(event);
- if( wEvent->modifiers() & Qt::ControlModifier ) {
- event->ignore();
- return true;
- }
- }
- return QAbstractItemView::viewportEvent( event );
-}
-
-PlListView::PlListView( QAbstractItemModel *, QWidget *parent ) : QListView( parent )
-{
- setViewMode( QListView::ListMode );
- setUniformItemSizes( true );
- setSelectionMode( QAbstractItemView::ExtendedSelection );
- setSelectionBehavior( QAbstractItemView::SelectRows );
- setAlternatingRowColors( true );
- setDragEnabled(true);
- setAcceptDrops( true );
- setDropIndicatorShown(true);
-
- PlListViewItemDelegate *delegate = new PlListViewItemDelegate( this );
- setItemDelegate( delegate );
- setAttribute( Qt::WA_MacShowFocusRect, false );
- viewport()->setAttribute( Qt::WA_Hover );
-}
-
-void PlListView::startDrag ( Qt::DropActions supportedActions )
-{
- plViewStartDrag( this, supportedActions );
-}
-
-void PlListView::dragMoveEvent ( QDragMoveEvent * event )
-{
- plViewDragMoveEvent( this, event );
- QAbstractItemView::dragMoveEvent( event );
-}
-
-void PlListView::keyPressEvent( QKeyEvent *event )
-{
- //If the space key is pressed, override the standard list behaviour to allow pausing
- //to proceed.
- if ( event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_Space )
- QWidget::keyPressEvent( event );
- //Otherwise, just do as usual.
- else
- QListView::keyPressEvent( event );
-}
-
-bool PlListView::viewportEvent ( QEvent * event )
-{
- if ( event->type() == QEvent::ToolTip )
- {
- event->ignore();
- return true;
- }
- else if ( event->type() == QEvent::Wheel )
- {
- QWheelEvent *wEvent = static_cast<QWheelEvent *>(event);
- if( wEvent->modifiers() & Qt::ControlModifier ) {
- event->ignore();
- return true;
- }
- }
- return QAbstractItemView::viewportEvent( event );
-}
-
-PlTreeView::PlTreeView( QAbstractItemModel *, QWidget *parent ) : QTreeView( parent )
-{
- setItemDelegate( new PlTreeViewItemDelegate( this ) );
- setItemDelegateForColumn( VLCModel::metaToColumn(COLUMN_COVER),
- new CellPixmapDelegate( this ) );
- setIconSize( QSize( 20, 20 ) );
- setAlternatingRowColors( true );
- setAnimated( true );
- setUniformRowHeights( true );
- setSortingEnabled( true );
- setAttribute( Qt::WA_MacShowFocusRect, false );
- viewport()->setAttribute( Qt::WA_Hover );
- header()->setSortIndicator( -1 , Qt::AscendingOrder );
- header()->setSortIndicatorShown( true );
- header()->setSectionsClickable( true );
- header()->setContextMenuPolicy( Qt::CustomContextMenu );
-
- setSelectionBehavior( QAbstractItemView::SelectRows );
- setSelectionMode( QAbstractItemView::ExtendedSelection );
- setDragEnabled( true );
- setAcceptDrops( true );
- setDropIndicatorShown( true );
- setContextMenuPolicy( Qt::CustomContextMenu );
-}
-
-void PlTreeView::setModel( QAbstractItemModel * model )
-{
- QTreeView::setModel( model );
- VLCModel *m = static_cast<VLCModel*>(model);
- CONNECT( this, expanded( const QModelIndex & ),
- m, ensureArtRequested( const QModelIndex & ) );
-}
-
-void PlTreeView::startDrag ( Qt::DropActions supportedActions )
-{
- plViewStartDrag( this, supportedActions );
-}
-
-void PlTreeView::dragMoveEvent ( QDragMoveEvent * event )
-{
- plViewDragMoveEvent( this, event );
- QAbstractItemView::dragMoveEvent( event );
-}
-
-void PlTreeView::keyPressEvent( QKeyEvent *event )
-{
- //If the space key is pressed, override the standard list behaviour to allow pausing
- //to proceed.
- if ( event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_Space )
- QWidget::keyPressEvent( event );
- //Otherwise, just do as usual.
- else
- QTreeView::keyPressEvent( event );
-}
-
-#include <QHBoxLayout>
-PicFlowView::PicFlowView( QAbstractItemModel *p_model, QWidget *parent ) : QAbstractItemView( parent )
-{
- QHBoxLayout *layout = new QHBoxLayout( this );
- layout->setMargin( 0 );
- picFlow = new PictureFlow( this, p_model );
- picFlow->setContextMenuPolicy( Qt::CustomContextMenu );
- connect( picFlow, SIGNAL(customContextMenuRequested( const QPoint & )),
- this, SIGNAL(customContextMenuRequested( const QPoint & )) );
- layout->addWidget( picFlow );
- picFlow->setSlideSize(QSize( 4*LISTVIEW_ART_SIZE, 3*LISTVIEW_ART_SIZE) );
- setSelectionMode( QAbstractItemView::SingleSelection );
-}
-
-void PicFlowView::setModel( QAbstractItemModel *model )
-{
- QAbstractItemView::setModel( model );
- picFlow->setModel( model );
-}
-
-int PicFlowView::horizontalOffset() const
-{
- return 0;
-}
-
-int PicFlowView::verticalOffset() const
-{
- return 0;
-}
-
-QRect PicFlowView::visualRect(const QModelIndex & ) const
-{
- return QRect( QPoint(0,0), picFlow->slideSize() );
-}
-
-void PicFlowView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint)
-{
- int currentIndex = picFlow->centerIndex();
- if( qAbs( currentIndex - index.row()) > 20 )
- {
- /* offset is offset from target index toward currentIndex */
- int offset = -19;
- if( index.row() > currentIndex )
- offset = 19;
- picFlow->setCenterIndex( index.row() + offset );
- picFlow->showSlide( index.row() );
- }
- else
- picFlow->showSlide( index.row() );
-}
-
-QModelIndex PicFlowView::indexAt(const QPoint &) const
-{
- return QModelIndex();
- // No idea, PictureFlow doesn't provide anything to help this
-}
-
-QModelIndex PicFlowView::moveCursor(QAbstractItemView::CursorAction, Qt::KeyboardModifiers)
-{
- return QModelIndex();
-}
-
-bool PicFlowView::isIndexHidden(const QModelIndex &index) const
-{
- int currentIndex = picFlow->centerIndex();
- if( index.row()-5 <= currentIndex &&
- index.row()+5 >= currentIndex )
- return false;
- else
- return true;
-}
-
-QRegion PicFlowView::visualRegionForSelection(const QItemSelection &) const
-{
- return QRect();
-}
-
-void PicFlowView::setSelection(const QRect &, QFlags<QItemSelectionModel::SelectionFlag>)
-{
- // No selection possible
-}
-
-void PicFlowView::dataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight )
-{
- int currentIndex = picFlow->centerIndex();
- for(int i = topLeft.row(); i<=bottomRight.row(); i++ )
- {
- if( i-5 <= currentIndex &&
- i+5 >= currentIndex )
- {
- picFlow->render();
- return;
- }
- }
-}
-
-void PicFlowView::playItem( int i_item )
-{
- emit activated( model()->index(i_item, 0) );
-}
-
-bool PicFlowView::viewportEvent ( QEvent * event )
-{
- if ( event->type() == QEvent::ToolTip )
- {
- event->ignore();
- return true;
- }
- else if ( event->type() == QEvent::Wheel )
- {
- QWheelEvent *wEvent = static_cast<QWheelEvent *>(event);
- if( wEvent->modifiers() & Qt::ControlModifier ) {
- event->ignore();
- return true;
- }
- }
- return QAbstractItemView::viewportEvent( event );
-}
diff --git a/modules/gui/qt/components/playlist/views.hpp b/modules/gui/qt/components/playlist/views.hpp
deleted file mode 100644
index 04d16f655c..0000000000
--- a/modules/gui/qt/components/playlist/views.hpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*****************************************************************************
- * views.hpp : Icon view for the Playlist
- ****************************************************************************
- * Copyright © 2010 the VideoLAN team
- *
- * Authors: Jean-Baptiste Kempf <jb at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_VIEWS_HPP_
-#define VLC_QT_VIEWS_HPP_
-
-#include <QStyledItemDelegate>
-#include <QListView>
-#include <QTreeView>
-#include <QAbstractItemView>
-#include "util/pictureflow.hpp"
-
-class QPainter;
-
-class AbstractPlViewItemDelegate : public QStyledItemDelegate
-{
- Q_OBJECT
-
-public:
- AbstractPlViewItemDelegate( QWidget * parent = 0 ) : QStyledItemDelegate(parent) {}
- void paintBackground( QPainter *, const QStyleOptionViewItem &, const QModelIndex & ) const;
-};
-
-class PlIconViewItemDelegate : public AbstractPlViewItemDelegate
-{
- Q_OBJECT
-
-public:
- PlIconViewItemDelegate(QWidget *parent = 0) : AbstractPlViewItemDelegate( parent ) {}
- void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const Q_DECL_OVERRIDE;
- QSize sizeHint ( const QStyleOptionViewItem & option = QStyleOptionViewItem(),
- const QModelIndex & index = QModelIndex() ) const Q_DECL_OVERRIDE;
-};
-
-class PlListViewItemDelegate : public AbstractPlViewItemDelegate
-{
- Q_OBJECT
-
-public:
- PlListViewItemDelegate(QWidget *parent = 0) : AbstractPlViewItemDelegate(parent) {}
-
- void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const Q_DECL_OVERRIDE;
- QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const Q_DECL_OVERRIDE;
-};
-
-class PlTreeViewItemDelegate : public AbstractPlViewItemDelegate
-{
- Q_OBJECT
-
-public:
- PlTreeViewItemDelegate(QWidget *parent = 0) : AbstractPlViewItemDelegate(parent) {}
-
- void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const Q_DECL_OVERRIDE;
-};
-
-class CellPixmapDelegate : public QStyledItemDelegate
-{
- Q_OBJECT
-
-public:
- CellPixmapDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
- void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const Q_DECL_OVERRIDE;
-};
-
-class PlIconView : public QListView
-{
- Q_OBJECT
-
-public:
- PlIconView( QAbstractItemModel *model, QWidget *parent = 0 );
-protected:
- void startDrag ( Qt::DropActions supportedActions ) Q_DECL_OVERRIDE;
- void dragMoveEvent ( QDragMoveEvent * event ) Q_DECL_OVERRIDE;
- bool viewportEvent ( QEvent * ) Q_DECL_OVERRIDE;
-};
-
-class PlListView : public QListView
-{
- Q_OBJECT
-
-public:
- PlListView( QAbstractItemModel *model, QWidget *parent = 0 );
-protected:
- void startDrag ( Qt::DropActions supportedActions ) Q_DECL_OVERRIDE;
- void dragMoveEvent ( QDragMoveEvent * event ) Q_DECL_OVERRIDE;
- void keyPressEvent( QKeyEvent *event ) Q_DECL_OVERRIDE;
- bool viewportEvent ( QEvent * ) Q_DECL_OVERRIDE;
-};
-
-class PlTreeView : public QTreeView
-{
- Q_OBJECT
-
-public:
- PlTreeView( QAbstractItemModel *, QWidget *parent = 0 );
-protected:
- void startDrag ( Qt::DropActions supportedActions ) Q_DECL_OVERRIDE;
- void dragMoveEvent ( QDragMoveEvent * event ) Q_DECL_OVERRIDE;
- void keyPressEvent( QKeyEvent *event ) Q_DECL_OVERRIDE;
- void setModel( QAbstractItemModel * ) Q_DECL_OVERRIDE;
-};
-
-class PicFlowView : public QAbstractItemView
-{
- Q_OBJECT
-public:
- PicFlowView( QAbstractItemModel *model, QWidget *parent = 0 );
-
- QRect visualRect(const QModelIndex&) const Q_DECL_OVERRIDE;
- void scrollTo(const QModelIndex&, QAbstractItemView::ScrollHint) Q_DECL_OVERRIDE;
- QModelIndex indexAt(const QPoint&) const Q_DECL_OVERRIDE;
- void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE;
-
-protected:
- int horizontalOffset() const Q_DECL_OVERRIDE;
- int verticalOffset() const Q_DECL_OVERRIDE;
- QModelIndex moveCursor(QAbstractItemView::CursorAction, Qt::KeyboardModifiers) Q_DECL_OVERRIDE;
- bool isIndexHidden(const QModelIndex&) const Q_DECL_OVERRIDE;
- QRegion visualRegionForSelection(const QItemSelection&) const Q_DECL_OVERRIDE;
- void setSelection(const QRect&, QFlags<QItemSelectionModel::SelectionFlag>) Q_DECL_OVERRIDE;
- bool viewportEvent ( QEvent * ) Q_DECL_OVERRIDE;
-
-private:
- PictureFlow *picFlow;
-
-public slots:
- void dataChanged( const QModelIndex &, const QModelIndex &);
-private slots:
- void playItem( int );
-};
-
-#endif
diff --git a/modules/gui/qt/components/playlist/vlc_model.cpp b/modules/gui/qt/components/playlist/vlc_model.cpp
deleted file mode 100644
index c723535485..0000000000
--- a/modules/gui/qt/components/playlist/vlc_model.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/*****************************************************************************
- * vlc_model.cpp : base for playlist and ml model
- ****************************************************************************
- * Copyright (C) 2010 the VideoLAN team and AUTHORS
- *
- * Authors: Srikanth Raju <srikiraju#gmail#com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#include "vlc_model.hpp"
-#include "input_manager.hpp" /* THEMIM */
-#include "pixmaps/types/type_unknown.xpm"
-
-#include <QImageReader>
-
-VLCModelSubInterface::VLCModelSubInterface()
-{
-}
-
-VLCModelSubInterface::~VLCModelSubInterface()
-{
-}
-
-int VLCModelSubInterface::columnFromMeta( int meta_col )
-{
- int meta = 1, column = 0;
-
- while( meta != meta_col && meta != COLUMN_END )
- {
- meta <<= 1;
- column++;
- }
-
- return column;
-}
-
-VLCModel::VLCModel( intf_thread_t *_p_intf, QObject *parent )
- : QAbstractItemModel( parent ), VLCModelSubInterface(), p_intf(_p_intf)
-{
- /* Icons initialization */
-#define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( x )
- ADD_ICON( UNKNOWN , QPixmap( type_unknown_xpm ) );
- ADD_ICON( FILE, ":/type/file.svg" );
- ADD_ICON( DIRECTORY, ":/type/directory.svg" );
- ADD_ICON( DISC, ":/type/disc.svg" );
- ADD_ICON( CARD, ":/type/capture-card.svg" );
- ADD_ICON( STREAM, ":/type/stream.svg" );
- ADD_ICON( PLAYLIST, ":/type/playlist.svg" );
- ADD_ICON( NODE, ":/type/node.svg" );
-#undef ADD_ICON
-}
-
-VLCModel::~VLCModel()
-{
-
-}
-
-QString VLCModel::getMeta( const QModelIndex & index, int meta )
-{
- return index.model()->index( index.row(), columnFromMeta( meta ), index.parent() ).
- data().toString();
-}
-
-QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size )
-{
- QString artUrl = index.sibling( index.row(),
- VLCModel::columnFromMeta(COLUMN_COVER) ).data().toString();
- QPixmap artPix;
-
- QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
-
- if( !QPixmapCache::find( key, artPix ))
- {
- if( artUrl.isEmpty() == false )
- {
- QImageReader reader( artUrl );
- reader.setDecideFormatFromContent( true );
- artPix = QPixmap::fromImageReader( &reader ).scaled( size );
- if ( artPix.isNull() == false )
- {
- QPixmapCache::insert( key, artPix );
- return artPix;
- }
- }
- key = QString("noart%1%2").arg(size.width()).arg(size.height());
- if( !QPixmapCache::find( key, artPix ) )
- {
- artPix = QPixmap( ":/noart" ).scaled( size,
- Qt::KeepAspectRatio,
- Qt::SmoothTransformation );
- QPixmapCache::insert( key, artPix );
- }
- }
- return artPix;
-}
-
-QVariant VLCModel::headerData( int section, Qt::Orientation orientation,
- int role ) const
-{
- if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
- return QVariant();
-
- int meta_col = columnToMeta( section );
-
- if( meta_col == COLUMN_END ) return QVariant();
-
- return QVariant( qfu( psz_column_title( meta_col ) ) );
-}
-
-int VLCModel::columnToMeta( int _column )
-{
- int meta = 1, column = 0;
-
- while( column != _column && meta != COLUMN_END )
- {
- meta <<= 1;
- column++;
- }
-
- return meta;
-}
-
-int VLCModel::metaToColumn( int _meta )
-{
- int meta = 1, column = 0;
-
- while( meta != COLUMN_END )
- {
- if ( meta & _meta )
- break;
- meta <<= 1;
- column++;
- }
-
- return column;
-}
-
-int VLCModel::itemId( const QModelIndex &index ) const
-{
- AbstractPLItem *item = getItem( index );
- if ( !item ) return -1;
- return item->id();
-}
-
-AbstractPLItem *VLCModel::getItem( const QModelIndex &index ) const
-{
- if( index.isValid() )
- return static_cast<AbstractPLItem*>( index.internalPointer() );
- else return NULL;
-}
-
-QString VLCModel::getURI( const QModelIndex &index ) const
-{
- AbstractPLItem *item = getItem( index );
- if ( !item ) return QString();
- return item->getURI();
-}
-
-input_item_t * VLCModel::getInputItem( const QModelIndex &index ) const
-{
- AbstractPLItem *item = getItem( index );
- if ( !item ) return NULL;
- return item->inputItem();
-}
-
-QString VLCModel::getTitle( const QModelIndex &index ) const
-{
- AbstractPLItem *item = getItem( index );
- if ( !item ) return QString();
- return item->getTitle();
-}
-
-bool VLCModel::isCurrent( const QModelIndex &index ) const
-{
- AbstractPLItem *item = getItem( index );
- if ( !item ) return false;
- return item->inputItem() == THEMIM->currentInputItem();
-}
-
-int VLCModel::columnCount( const QModelIndex & ) const
-{
- return columnFromMeta( COLUMN_END );
-}
-
-void VLCModel::ensureArtRequested( const QModelIndex &index )
-{
- if ( index.isValid() && hasChildren( index ) )
- {
- bool b_access = var_InheritBool( THEPL, "metadata-network-access" );
- if ( !b_access ) return;
- int nbnodes = rowCount( index );
- QModelIndex child;
- for( int row = 0 ; row < nbnodes ; row++ )
- {
- child = index.child( row, COLUMN_COVER );
- if ( child.isValid() && child.data().toString().isEmpty() )
- THEMIM->getIM()->requestArtUpdate( getInputItem( child ), false );
- }
- }
-}
-
diff --git a/modules/gui/qt/components/playlist/vlc_model.hpp b/modules/gui/qt/components/playlist/vlc_model.hpp
deleted file mode 100644
index 80dc7080df..0000000000
--- a/modules/gui/qt/components/playlist/vlc_model.hpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/*****************************************************************************
- * vlc_model.hpp : base for playlist and ml model
- ****************************************************************************
- * Copyright (C) 2010 the VideoLAN team and AUTHORS
- *
- * Authors: Srikanth Raju <srikiraju#gmail#com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef VLC_QT_VLC_MODEL_HPP_
-#define VLC_QT_VLC_MODEL_HPP_
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "qt.hpp"
-#include "sorting.h"
-
-#include "playlist_item.hpp"
-
-#include <vlc_input.h>
-
-#include <QModelIndex>
-#include <QPixmapCache>
-#include <QSize>
-#include <QObject>
-#include <QAbstractItemModel>
-#include <QIcon>
-
-class QAction;
-
-/* Provides non Q_Object interface for Models.
- This allows multiple inheritance on already QAbstractModel based
- Qobjects like Q*ProxyModel.
- Signals being a Q_Object property, they need to be redirected
- using a QObject based class member.
-*/
-class VLCModelSubInterface
-{
-public:
- VLCModelSubInterface();
- virtual ~VLCModelSubInterface();
- enum nodeRole
- {
- CURRENT_ITEM_ROLE = Qt::UserRole,
- CURRENT_ITEM_CHILD_ROLE,
- LEAF_NODE_ROLE, /* FIXME: same as index().child() ? */
- };
- virtual void rebuild( playlist_item_t * p = NULL ) = 0;
- virtual void doDelete( QModelIndexList ) = 0;
- virtual void createNode( QModelIndex, QString ) = 0;
- virtual void renameNode( QModelIndex, QString ) = 0;
- virtual void removeAll() = 0;
-
- virtual QModelIndex rootIndex() const = 0;
- virtual void filter( const QString& search_text, const QModelIndex & root, bool b_recursive ) = 0;
- virtual QModelIndex currentIndex() const = 0;
- virtual QModelIndex indexByPLID( const int i_plid, const int c ) const = 0;
- virtual QModelIndex indexByInputItem( const input_item_t *, const int c ) const = 0;
- virtual int itemId( const QModelIndex & ) const = 0;
- virtual bool isTree() const = 0;
- virtual bool canEdit() const = 0;
- virtual QString getURI( const QModelIndex &index ) const = 0;
- virtual input_item_t *getInputItem( const QModelIndex & ) const = 0;
- virtual QString getTitle( const QModelIndex &index ) const = 0;
- enum actions
- {
- ACTION_PLAY = 1,
- ACTION_PAUSE,
- ACTION_STREAM,
- ACTION_SAVE,
- ACTION_INFO,
- ACTION_ADDTOPLAYLIST,
- ACTION_REMOVE,
- ACTION_SORT,
- ACTION_EXPLORE,
- ACTION_CREATENODE,
- ACTION_RENAMENODE,
- ACTION_CLEAR,
- ACTION_ENQUEUEFILE,
- ACTION_ENQUEUEDIR,
- ACTION_ENQUEUEGENERIC,
- ACTION_SAVETOPLAYLIST
- };
- struct actionsContainerType
- {
- actions action;
- int column; /* for sorting */
- QStringList uris; /* for enqueuing */
- QString options;
- };
- virtual bool action( QAction *, const QModelIndexList & ) = 0;
- virtual bool isSupportedAction( actions action, const QModelIndex & ) const = 0;
- static int columnFromMeta( int meta_col );
-
- virtual void activateItem( const QModelIndex &index ) = 0;
- virtual void ensureArtRequested( const QModelIndex &index ) = 0;
-};
-
-/* Abstract VLC Model ; Base for custom models.
- Only implements methods sharing the same code that would be
- implemented in subclasses.
- Any custom method here must be only used in implemented methods.
-*/
-class VLCModel : public QAbstractItemModel, public VLCModelSubInterface
-{
- Q_OBJECT
-public:
- VLCModel( intf_thread_t *_p_intf, QObject *parent = 0 );
- virtual ~VLCModel();
-
- /*** QAbstractItemModel subclassing ***/
- int columnCount( const QModelIndex &parent = QModelIndex() ) const Q_DECL_OVERRIDE;
- QVariant headerData( int, Qt::Orientation, int ) const Q_DECL_OVERRIDE;
-
- /*** VLCModelSubInterface subclassing ***/
- int itemId( const QModelIndex & ) const Q_DECL_OVERRIDE;
- QString getURI( const QModelIndex &index ) const Q_DECL_OVERRIDE;
- input_item_t *getInputItem( const QModelIndex & ) const Q_DECL_OVERRIDE;
- QString getTitle( const QModelIndex &index ) const Q_DECL_OVERRIDE;
-
- /* Custom */
- static int columnToMeta( int _column );
- static int metaToColumn( int meta );
- static QString getMeta( const QModelIndex & index, int meta );
- static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
-
-public slots:
- /* slots handlers */
- void ensureArtRequested( const QModelIndex &index ) Q_DECL_OVERRIDE;
-
-signals:
- void currentIndexChanged( const QModelIndex& );
- void rootIndexChanged();
-
-protected:
- /* Custom methods / helpers */
- virtual bool isCurrent( const QModelIndex &index ) const;
- virtual bool isParent( const QModelIndex &index, const QModelIndex ¤t ) const = 0;
- virtual bool isLeaf( const QModelIndex &index ) const = 0;
- virtual AbstractPLItem *getItem( const QModelIndex & index ) const;
-
- QIcon icons[ITEM_TYPE_NUMBER];
-
- intf_thread_t *p_intf;
-};
-
-Q_DECLARE_METATYPE(VLCModelSubInterface::actionsContainerType)
-
-#endif
diff --git a/modules/gui/qt/dialogs/playlist.cpp b/modules/gui/qt/dialogs/playlist.cpp
deleted file mode 100644
index 7346f0cb1c..0000000000
--- a/modules/gui/qt/dialogs/playlist.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*****************************************************************************
- * playlist.cpp : Playlist dialog
- ****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- ******************************************************************************/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "dialogs/playlist.hpp"
-
-#include "components/playlist/playlist.hpp"
-
-#include "util/qt_dirs.hpp"
-
-#include <QMimeData>
-#include <QHBoxLayout>
-
-PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf )
- : QVLCMW( _p_intf )
-{
- setWindowTitle( qtr( "Playlist" ) );
- setWindowRole( "vlc-playlist" );
- setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
-
- playlistWidget = new PlaylistWidget( p_intf, this );
- setCentralWidget( playlistWidget );
-
- readSettings( "playlistdialog", QSize( 600,700 ) );
-}
-
-PlaylistWidget *PlaylistDialog::exportPlaylistWidget()
-{
- Q_ASSERT( playlistWidget );
- PlaylistWidget *widget = playlistWidget;
- layout()->removeWidget( playlistWidget );
- playlistWidget = NULL;
- return widget;
-}
-
-void PlaylistDialog::importPlaylistWidget( PlaylistWidget *widget )
-{
- Q_ASSERT( !playlistWidget );
- playlistWidget = widget;
- setCentralWidget( playlistWidget );
- playlistWidget->show();
-}
-
-bool PlaylistDialog::hasPlaylistWidget()
-{
- return ( !! playlistWidget );
-}
-
-void PlaylistDialog::hideEvent( QHideEvent * event )
-{
- QWidget::hideEvent( event );
- emit visibilityChanged( false );
-}
-
-PlaylistDialog::~PlaylistDialog()
-{
- writeSettings( "playlistdialog" );
-}
-
-void PlaylistDialog::dropEvent( QDropEvent *event )
-{
- playlistWidget->dropEvent(event);
-}
-void PlaylistDialog::dragEnterEvent( QDragEnterEvent *event )
-{
- event->acceptProposedAction();
-}
-void PlaylistDialog::dragMoveEvent( QDragMoveEvent *event )
-{
- event->acceptProposedAction();
-}
-void PlaylistDialog::dragLeaveEvent( QDragLeaveEvent *event )
-{
- event->accept();
-}
-
diff --git a/modules/gui/qt/dialogs/playlist.hpp b/modules/gui/qt/dialogs/playlist.hpp
deleted file mode 100644
index ca7cdd20db..0000000000
--- a/modules/gui/qt/dialogs/playlist.hpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*****************************************************************************
- * playlist.hpp: Playlist dialog
- ****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
- *
- * Authors: Clément Stenac <zorglub at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifndef QVLC_PLAYLIST_DIALOG_H_
-#define QVLC_PLAYLIST_DIALOG_H_ 1
-
-#include "util/qvlcframe.hpp"
-#include "components/playlist/playlist.hpp"
-#include "util/singleton.hpp"
-
-#include <QModelIndex>
-
-class QHideEvent;
-
-class PlaylistDialog : public QVLCMW, public Singleton<PlaylistDialog>
-{
- Q_OBJECT
-
-public:
- PlaylistWidget *exportPlaylistWidget( );
- void importPlaylistWidget( PlaylistWidget * );
- bool hasPlaylistWidget();
-
-protected:
- void hideEvent( QHideEvent * ) Q_DECL_OVERRIDE;
-
-private:
- PlaylistWidget *playlistWidget;
- PlaylistDialog( intf_thread_t * );
- virtual ~PlaylistDialog();
-
- virtual void dropEvent( QDropEvent *) Q_DECL_OVERRIDE;
- virtual void dragEnterEvent( QDragEnterEvent * ) Q_DECL_OVERRIDE;
- virtual void dragMoveEvent( QDragMoveEvent * ) Q_DECL_OVERRIDE;
- virtual void dragLeaveEvent( QDragLeaveEvent * ) Q_DECL_OVERRIDE;
-
- friend class Singleton<PlaylistDialog>;
-
-signals:
- void visibilityChanged( bool );
-};
-
-
-#endif
--
2.19.1
More information about the vlc-devel
mailing list