Commit 9449cc33 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: PLModel: move out Info & Prompt Dialogs references from Model

parent b08027f1
......@@ -36,7 +36,6 @@
#include <QMimeData>
#include "ml_item.hpp"
#include "ml_model.hpp"
#include "dialogs/mediainfo.hpp"
#include "dialogs/playlist.hpp"
#include "components/playlist/sorting.h"
#include "dialogs_provider.hpp"
......@@ -259,6 +258,11 @@ int MLModel::itemId( const QModelIndex &index ) const
return getItem( index )->id();
}
input_item_t * MLModel::getInputItem( const QModelIndex &index ) const
{
return getItem( index )->inputItem();
}
QVariant MLModel::data( const QModelIndex &index, const int role ) const
{
if( index.isValid() )
......@@ -511,11 +515,9 @@ QString MLModel::getURI( const QModelIndex &index ) const
void MLModel::actionSlot( QAction *action )
{
char *uri = NULL, *path = NULL;
QString name;
QStringList mrls;
QModelIndex index;
bool ok;
playlist_item_t *p_item;
actionsContainerType a = action->data().value<actionsContainerType>();
......@@ -529,35 +531,6 @@ void MLModel::actionSlot( QAction *action )
case actionsContainerType::ACTION_ADDTOPLAYLIST:
break;
case actionsContainerType::ACTION_INFO:
if( a.indexes.first().isValid() )
{
input_item_t* p_input = getItem( a.indexes.first() )->inputItem();
MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
mid->setParent( PlaylistDialog::getInstance( p_intf ),
Qt::Dialog );
mid->show();
}
break;
case actionsContainerType::ACTION_STREAM:
mrls = selectedURIs( & a.indexes );
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0], false );
break;
case actionsContainerType::ACTION_EXPLORE:
break;
case actionsContainerType::ACTION_SAVE:
mrls = selectedURIs( & a.indexes );
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0] );
break;
case actionsContainerType::ACTION_ADDNODE:
break;
case actionsContainerType::ACTION_REMOVE:
doDelete( a.indexes );
break;
......
......@@ -56,6 +56,7 @@ public:
virtual ~MLModel();
virtual int itemId( const QModelIndex & ) const;
virtual input_item_t *getInputItem( const QModelIndex &index ) const;
QVariant data( const QModelIndex &idx, const int role = Qt::DisplayRole ) const;
bool setData( const QModelIndex &idx, const QVariant &value,
......
......@@ -31,8 +31,6 @@
#include "components/playlist/playlist_model.hpp"
#include "dialogs_provider.hpp" /* THEDP */
#include "input_manager.hpp" /* THEMIM */
#include "dialogs/mediainfo.hpp" /* MediaInfo Dialog */
#include "dialogs/playlist.hpp" /* Playlist Dialog */
#include <vlc_intf_strings.h> /* I_DIR */
......@@ -42,20 +40,8 @@
#include <assert.h>
#include <QIcon>
#include <QFont>
#include <QMenu>
#include <QUrl>
#include <QFileInfo>
#include <QDesktopServices>
#include <QInputDialog>
#include <QSignalMapper>
#include <QTimer>
#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:" ) )
QIcon PLModel::icons[ITEM_TYPE_NUMBER];
/*************************************************************************
......@@ -470,6 +456,11 @@ int PLModel::itemId( const QModelIndex &index ) const
return getItem( index )->id();
}
input_item_t * PLModel::getInputItem( const QModelIndex &index ) const
{
return getItem( index )->inputItem();
}
QString PLModel::getURI( const QModelIndex &index ) const
{
QString uri;
......@@ -1094,14 +1085,25 @@ void PLModel::ensureArtRequested( const QModelIndex &index )
}
}
void PLModel::createNode( QModelIndex index, QString name )
{
if( name.isEmpty() || !index.isValid() ) return;
PL_LOCK;
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, NULL );
PL_UNLOCK;
}
void PLModel::actionSlot( QAction *action )
{
char *uri = NULL, *path = NULL;
QString name;
QStringList mrls;
QModelIndex index;
bool ok;
playlist_item_t *p_item;
actionsContainerType a = action->data().value<actionsContainerType>();
switch ( a.action )
......@@ -1134,72 +1136,6 @@ void PLModel::actionSlot( QAction *action )
PL_UNLOCK;
break;
case actionsContainerType::ACTION_INFO:
PL_LOCK;
if( a.indexes.first().isValid() )
{
input_item_t* p_input = getItem( a.indexes.first() )->inputItem();
vlc_gc_incref( p_input );
PL_UNLOCK;
MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
vlc_gc_decref( p_input );
mid->setParent( PlaylistDialog::getInstance( p_intf ),
Qt::Dialog );
mid->show();
} else
PL_UNLOCK;
break;
case actionsContainerType::ACTION_STREAM:
mrls = selectedURIs( & a.indexes );
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0], false );
break;
case actionsContainerType::ACTION_EXPLORE:
PL_LOCK;
if( a.indexes.first().isValid() )
{
input_item_t *p_input = getItem( a.indexes.first() )->inputItem();
uri = input_item_GetURI( p_input );
}
PL_UNLOCK;
if( uri != NULL )
{
path = make_path( uri );
free( uri );
}
if( path == NULL )
return;
QDesktopServices::openUrl(
QUrl::fromLocalFile( QFileInfo( qfu( path ) ).absolutePath() ) );
free( path );
break;
case actionsContainerType::ACTION_SAVE:
mrls = selectedURIs( & a.indexes );
if( !mrls.isEmpty() )
THEDP->streamingDialog( NULL, mrls[0] );
break;
case actionsContainerType::ACTION_ADDNODE:
name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
QLineEdit::Normal, QString(), &ok);
if( !ok || name.isEmpty() || !a.indexes.first().isValid() ) return;
PL_LOCK;
index = a.indexes.first().parent();
if ( !index.isValid() ) index = rootIndex();
p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
if( p_item )
playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
PL_UNLOCK;
break;
case actionsContainerType::ACTION_REMOVE:
doDelete( a.indexes );
break;
......
......@@ -102,6 +102,7 @@ public:
virtual bool canEdit() const;
virtual QModelIndex currentIndex() const;
int itemId( const QModelIndex &index ) const;
virtual input_item_t *getInputItem( const QModelIndex & ) const;
virtual QString getURI( const QModelIndex &index ) const;
QString getTitle( const QModelIndex &index ) const;
virtual bool isCurrentItem( const QModelIndex &index, playLocation where ) const;
......@@ -111,6 +112,7 @@ public:
void rebuild( playlist_item_t * p = NULL );
virtual void doDelete( QModelIndexList selected );
virtual void createNode( QModelIndex index, QString name );
signals:
void currentIndexChanged( const QModelIndex& );
......
......@@ -36,10 +36,18 @@
#include "menus.hpp" /* Popup */
#include "input_manager.hpp" /* THEMIM */
#include "dialogs_provider.hpp" /* THEDP */
#include "dialogs/playlist.hpp" /* Playlist Dialog */
#include "dialogs/mediainfo.hpp" /* MediaInfoDialog */
#include <vlc_services_discovery.h> /* SD_CMD_SEARCH */
#include <vlc_intf_strings.h> /* POP_ */
#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:" ) )
#include <QHeaderView>
#include <QMenu>
#include <QKeyEvent>
......@@ -48,6 +56,9 @@
#include <QSignalMapper>
#include <QSettings>
#include <QStylePainter>
#include <QInputDialog>
#include <QDesktopServices>
#include <QUrl>
#include <assert.h>
......@@ -129,6 +140,7 @@ bool StandardPLPanel::popup( const QModelIndex & index, const QPoint &point, con
VLCModel *model = qobject_cast<VLCModel*>(currentView->model());
QModelIndexList callerAsList;
callerAsList << ( index.isValid() ? index : QModelIndex() );
popupIndex = index; /* suitable for modal only */
#define ADD_MENU_ENTRY( icon, title, act, data ) \
action = menu.addAction( icon, title ); \
......@@ -147,22 +159,20 @@ bool StandardPLPanel::popup( const QModelIndex & index, const QPoint &point, con
ADD_MENU_ENTRY( QIcon( ":/menu/play" ), qtr(I_POP_PLAY),
container.ACTION_PLAY, callerAsList );
ADD_MENU_ENTRY( QIcon( ":/menu/stream" ), qtr(I_POP_STREAM),
container.ACTION_STREAM, selectionlist );
menu.addAction( QIcon( ":/menu/stream" ), qtr(I_POP_STREAM),
this, SLOT( popupStream() ) );
ADD_MENU_ENTRY( QIcon(), qtr(I_POP_SAVE),
container.ACTION_SAVE, selectionlist );
menu.addAction( QIcon(), qtr(I_POP_SAVE),
this, SLOT( popupSave() ) );
ADD_MENU_ENTRY( QIcon( ":/menu/info" ), qtr(I_POP_INFO),
container.ACTION_INFO, callerAsList );
menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO),
this, SLOT( popupInfoDialog() ) );
menu.addSeparator();
if( model->getURI( index ).startsWith( "file://" ) )
{
ADD_MENU_ENTRY( QIcon( ":/type/folder-grey" ), qtr(I_POP_EXPLORE),
container.ACTION_EXPLORE, callerAsList );
}
menu.addAction( QIcon( ":/type/folder-grey" ), qtr(I_POP_EXPLORE),
this, SLOT( popupExplore() ) );
}
/* In PL or ML, allow to add a file/folder */
......@@ -171,10 +181,8 @@ bool StandardPLPanel::popup( const QModelIndex & index, const QPoint &point, con
QIcon addIcon( ":/buttons/playlist/playlist_add" );
if( model->isTree() )
{
ADD_MENU_ENTRY( addIcon, qtr(I_POP_NEWFOLDER),
container.ACTION_ADDNODE, callerAsList );
}
menu.addAction( addIcon, qtr(I_POP_NEWFOLDER),
this, SLOT( popupPromptAndCreateNode() ) );
menu.addSeparator();
if( model->isCurrentItem( model->rootIndex(), PLModel::IN_PLAYLIST ) )
......@@ -271,6 +279,63 @@ void StandardPLPanel::popupSelectColumn( QPoint )
menu.exec( QCursor::pos() );
}
void StandardPLPanel::popupPromptAndCreateNode()
{
bool ok;
QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
QLineEdit::Normal, QString(), &ok);
if ( !ok ) return;
qobject_cast<VLCModel *>(currentView->model())->createNode( popupIndex, name );
}
void StandardPLPanel::popupInfoDialog()
{
if( popupIndex.isValid() )
{
VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
input_item_t* p_input = model->getInputItem( popupIndex );
MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
mid->setParent( PlaylistDialog::getInstance( p_intf ),
Qt::Dialog );
mid->show();
}
}
void StandardPLPanel::popupExplore()
{
VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
QString uri = model->getURI( popupIndex );
char *path = NULL;
if( ! uri.isEmpty() )
path = make_path( uri.toStdString().c_str() );
if( path == NULL )
return;
QDesktopServices::openUrl(
QUrl::fromLocalFile( QFileInfo( qfu( path ) ).absolutePath() ) );
free( path );
}
void StandardPLPanel::popupStream()
{
VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
QString uri = model->getURI( popupIndex );
if ( ! uri.isEmpty() )
THEDP->streamingDialog( NULL, uri, false );
}
void StandardPLPanel::popupSave()
{
VLCModel *model = qobject_cast<VLCModel *>(currentView->model());
QString uri = model->getURI( popupIndex );
if ( ! uri.isEmpty() )
THEDP->streamingDialog( NULL, uri );
}
void StandardPLPanel::toggleColumnShown( int i )
{
treeView->setColumnHidden( i, !treeView->isColumnHidden( i ) );
......
......@@ -103,6 +103,9 @@ private:
void changeModel ( bool b_ml );
bool eventFilter ( QObject * watched, QEvent * event );
/* for popup */
QModelIndex popupIndex; /* FIXME: don't store here, pass as Action param */
public slots:
void setRootItem( playlist_item_t *, bool );
void browseInto( const QModelIndex& );
......@@ -122,6 +125,11 @@ private slots:
void popupPlView( const QPoint & );
void popupSelectColumn( QPoint );
void popupPromptAndCreateNode();
void popupInfoDialog();
void popupExplore();
void popupStream();
void popupSave();
void toggleColumnShown( int );
void showView( int );
......
......@@ -51,6 +51,7 @@ public:
VLCModel( intf_thread_t *_p_intf, QObject *parent = 0 );
virtual int itemId( const QModelIndex & ) const = 0;
virtual input_item_t *getInputItem( const QModelIndex & ) const = 0;
virtual QModelIndex currentIndex() const = 0;
virtual void doDelete( QModelIndexList ) = 0;
virtual ~VLCModel();
......@@ -73,12 +74,7 @@ public:
enum
{
ACTION_PLAY = 1,
ACTION_INFO,
ACTION_STREAM,
ACTION_SAVE,
ACTION_EXPLORE,
ACTION_ADDTOPLAYLIST,
ACTION_ADDNODE,
ACTION_REMOVE,
ACTION_SORT
} action;
......@@ -112,6 +108,8 @@ public:
return column;
}
virtual void createNode( QModelIndex, QString ) {};
public slots:
virtual void activateItem( const QModelIndex &index ) = 0;
virtual void actionSlot( QAction *action ) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment