#include <QPushButton>
#include <QStatusBar>
#include <QKeyEvent>
+#include <QUrl>
#include <assert.h>
#include <vlc_keys.h>
settings = new QSettings( "VideoLAN", "VLC" );
settings->beginGroup( "MainWindow" );
+ setAcceptDrops(true);
+
need_components_update = false;
bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
embeddedPlaylistWasActive = videoIsActive = false;
p_intf->b_interaction = VLC_TRUE;
}
+void MainInterface::dropEvent(QDropEvent *event)
+{
+ const QMimeData *mimeData = event->mimeData();
+
+ /* D&D of a subtitles file, add it on the fly */
+ if( mimeData->urls().size() == 1 )
+ {
+ if( THEMIM->getIM()->hasInput() )
+ {
+ if( input_AddSubtitles( THEMIM->getInput(),
+ qtu( mimeData->urls()[0].toString() ),
+ VLC_TRUE ) )
+ {
+ event->acceptProposedAction();
+ return;
+ }
+ }
+ }
+ bool first = true;
+ foreach( QUrl url, mimeData->urls() ) {
+ QString s = url.toString();
+ if( s.length() > 0 ) {
+ playlist_PlaylistAdd( THEPL, qtu(s), NULL,
+ PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
+ PLAYLIST_END );
+ first = false;
+ }
+ }
+ event->acceptProposedAction();
+}
+void MainInterface::dragEnterEvent(QDragEnterEvent *event)
+{
+ event->acceptProposedAction();
+}
+void MainInterface::dragMoveEvent(QDragMoveEvent *event)
+{
+ event->acceptProposedAction();
+}
+void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
+{
+ event->accept();
+}
+
+
+
MainInterface::~MainInterface()
{
settings->setValue( "playlist-embedded", playlistEmbeddedFlag );
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#define PLI_NAME( p ) p ? p->p_input->psz_name : "null"
#include <assert.h>
#include <QIcon>
assert( model );
if( signal )
model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
- children.append( item );
+ children.insert( i_pos, item );
if( signal )
model->endInsertRows();
}
delete rootItem;
}
+Qt::DropActions PLModel::supportedDropActions() const
+{
+ return Qt::CopyAction;
+}
+
+Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
+{
+ Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
+ if( index.isValid() )
+ return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
+ else
+ return Qt::ItemIsDropEnabled | defaultFlags;
+}
+
+QStringList PLModel::mimeTypes() const
+{
+ QStringList types;
+ types << "vlc/playlist-item-id";
+ return types;
+}
+
+QMimeData *PLModel::mimeData(const QModelIndexList &indexes) const
+{
+ QMimeData *mimeData = new QMimeData();
+ QByteArray encodedData;
+ QDataStream stream(&encodedData, QIODevice::WriteOnly);
+
+ foreach (QModelIndex index, indexes) {
+ if (index.isValid() && index.column() == 0 )
+ stream << itemId(index);
+ }
+ mimeData->setData("vlc/playlist-item-id", encodedData);
+ return mimeData;
+}
+
+bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &target)
+{
+ if ( data->hasFormat("vlc/playlist-item-id") )
+ {
+ if (action == Qt::IgnoreAction)
+ return true;
+
+ PLItem *targetItem;
+ if( target.isValid() )
+ targetItem = static_cast<PLItem*>( target.internalPointer() );
+ else
+ targetItem = rootItem;
+
+ QByteArray encodedData = data->data("vlc/playlist-item-id");
+ QDataStream stream(&encodedData, QIODevice::ReadOnly);
+
+ PLItem *newParentItem;
+ while (!stream.atEnd())
+ {
+ int i;
+ int srcId;
+ stream >> srcId;
+
+ PL_LOCK;
+ playlist_item_t *p_target =
+ playlist_ItemGetById( p_playlist, targetItem->i_id );
+ playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId );
+
+ if( !p_target || !p_src )
+ {
+ PL_UNLOCK;
+ return false;
+ }
+
+ if( p_target->i_children == -1 ) /* A leaf */
+ {
+ PLItem *parentItem = targetItem->parent();
+ assert( parentItem );
+ playlist_item_t *p_parent =
+ playlist_ItemGetById( p_playlist, parentItem->i_id );
+ if( !p_parent )
+ {
+ PL_UNLOCK;
+ return false;
+ }
+ for( i = 0 ; i< p_parent->i_children ; i++ )
+ if( p_parent->pp_children[i] == p_target ) break;
+ playlist_TreeMove( p_playlist, p_src, p_parent, i );
+ newParentItem = parentItem;
+ }
+ else
+ {
+ /* \todo: if we drop on a top-level node, use copy instead ? */
+ playlist_TreeMove( p_playlist, p_src, p_target, 0 );
+ i = 0;
+ newParentItem = targetItem;
+ }
+ /* Remove from source */
+ PLItem *srcItem = FindByInput( rootItem, p_src->p_input->i_id );
+ srcItem->remove( srcItem );
+ /* Display at new destination */
+ PLItem *newItem = new PLItem( p_src, newParentItem, this );
+ newParentItem->insertChild( newItem, i, true );
+ UpdateTreeItem( p_src, newItem, true );
+ if( p_src->i_children != -1 )
+ UpdateNodeChildren( newItem );
+ PL_UNLOCK;
+ }
+ }
+ return true;
+ }
+
+
void PLModel::addCallbacks()
{
/* Some global changes happened -> Rebuild all */
/****************** Base model mandatory implementations *****************/
QVariant PLModel::data(const QModelIndex &index, int role) const
{
- assert( index.isValid() );
+ if(!index.isValid() ) return QVariant();
PLItem *item = static_cast<PLItem*>(index.internalPointer());
if( role == Qt::DisplayRole )
{
return static_cast<PLItem*>(index.internalPointer())->i_id;
}
-Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
-{
- if( !index.isValid() ) return Qt::ItemIsEnabled;
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-}
-
QVariant PLModel::headerData( int section, Qt::Orientation orientation,
int role) const
{
{
int type = event->type();
if( type != ItemUpdate_Type && type != ItemAppend_Type &&
- type != ItemDelete_Type )
+ type != ItemDelete_Type && type != PLUpdate_Type )
return;
PLEvent *ple = static_cast<PLEvent *>(event);
ProcessInputItemUpdate( ple->i_id );
else if( type == ItemAppend_Type )
ProcessItemAppend( ple->p_add );
- else
+ else if( type == ItemDelete_Type )
ProcessItemRemoval( ple->i_id );
+ else
+ rebuild();
}
/**** Events processing ****/
case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
case 1: i_mode = SORT_ARTIST;break;
case 2: i_mode = SORT_DURATION; break;
+ default: i_mode = SORT_TITLE_NODES_FIRST; break;
}
if( p_root )
playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
vlc_value_t oval, vlc_value_t nval, void *param )
{
PLModel *p_model = (PLModel *) param;
-// p_model->b_need_update = VLC_TRUE;
+ PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
+ QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
return VLC_SUCCESS;
}