]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.cpp
i18n: Fix in the popup menu
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.cpp
index 9eba5910d3ec0f436e8dfdf6fabe88c10bb0f76c..fd45e755a2cae961b51b46a2d75499cc9060e460 100644 (file)
 #endif
 
 #include "qt4.hpp"
+#include "dialogs_provider.hpp"
 #include "components/playlist/playlist_model.hpp"
 #include "dialogs/mediainfo.hpp"
+#include "dialogs/playlist.hpp"
 #include <vlc_intf_strings.h>
 
 #include "pixmaps/types/type_unknown.xpm"
@@ -131,7 +133,7 @@ QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
     QByteArray encodedData;
     QDataStream stream( &encodedData, QIODevice::WriteOnly );
 
-    foreach( QModelIndex index, indexes ) {
+    foreach( const QModelIndex &index, indexes ) {
         if( index.isValid() && index.column() == 0 )
             stream << itemId( index );
     }
@@ -148,11 +150,11 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
         if( action == Qt::IgnoreAction )
             return true;
 
-        PLItem *targetItem;
-        if( target.isValid() )
-            targetItem = static_cast<PLItem*>( target.internalPointer() );
-        else
-            targetItem = rootItem;
+        if( !target.isValid() )
+            /* We don't want to move on an invalid position */
+            return true;
+
+        PLItem *targetItem = static_cast<PLItem*>( target.internalPointer() );
 
         QByteArray encodedData = data->data( "vlc/playlist-item-id" );
         QDataStream stream( &encodedData, QIODevice::ReadOnly );
@@ -190,7 +192,8 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                 }
                 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 );
+                // Move the item to the element after i
+                playlist_TreeMove( p_playlist, p_src, p_parent, i + 1 );
                 newParentItem = parentItem;
             }
             else
@@ -200,25 +203,10 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                 i = 0;
                 newParentItem = targetItem;
             }
-            /* Remove from source */
-            PLItem *srcItem = FindById( rootItem, p_src->i_id );
-            // We dropped on the source selector. Ask the dialog to forward
-            // to the main view
-            if( !srcItem )
-            {
-                emit shouldRemove( p_src->i_id );
-            }
-            else
-                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;
         }
+        /*TODO: That's not a good idea to rebuild the playlist */
+        rebuild();
     }
     return true;
 }
@@ -396,6 +384,34 @@ int PLModel::rowCount( const QModelIndex &parent ) const
     return parentItem->childCount();
 }
 
+QStringList PLModel::selectedURIs()
+{
+    QStringList lst;
+    for( int i = 0; i < current_selection.size(); i++ )
+    {
+        PL_LOCK;
+        PLItem *item = static_cast<PLItem*>
+                    (current_selection[i].internalPointer());
+        if( !item )
+            continue;
+
+        input_item_t *p_item = NULL;
+        if( !p_item )
+            continue;
+
+        char *psz = input_item_GetURI( p_item );
+        if( !psz )
+            continue;
+        else
+        {
+            lst.append( QString( psz ) );
+            free( psz );
+        }
+        PL_UNLOCK;
+    }
+    return lst;
+}
+
 /************************* General playlist status ***********************/
 
 bool PLModel::hasRandom()
@@ -569,6 +585,7 @@ void PLModel::rebuild()
 
 void PLModel::rebuild( playlist_item_t *p_root )
 {
+    playlist_item_t* p_item;
     /* Remove callbacks before locking to avoid deadlocks */
     delCallbacks();
     /* Invalidate cache */
@@ -595,13 +612,13 @@ void PLModel::rebuild( playlist_item_t *p_root )
     assert( rootItem );
     /* Recreate from root */
     UpdateNodeChildren( rootItem );
-    if( p_playlist->status.p_item )
+    if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
     {
         PLItem *currentItem = FindByInput( rootItem,
-                                     p_playlist->status.p_item->p_input->i_id );
+                                           p_item->p_input->i_id );
         if( currentItem )
         {
-            UpdateTreeItem( p_playlist->status.p_item, currentItem,
+            UpdateTreeItem( p_item, currentItem,
                             true, false );
         }
     }
@@ -651,7 +668,7 @@ void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
     if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
                                  p_item->p_parent->i_id != rootItem->i_id )
         return;
-    item->update( p_item, p_item == p_playlist->status.p_item );
+    item->update( p_item, p_item == playlist_CurrentPlayingItem( p_playlist ) );
     if( signal )
         emit dataChanged( index( item, 0 ) , index( item, 1 ) );
 }
@@ -718,37 +735,18 @@ void PLModel::sort( int column, Qt::SortOrder order )
     int i_index = -1;
     int i_flag = 0;
 
-    // FIXME: Disable sorting on startup by ignoring
-    // first call of sorting caused by showing dialog
-    // see: standardpanel.cpp:65
-    static bool b_first_time = true;
-    if( b_first_time )
+    int i_column = 1;
+    for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
     {
-        b_first_time = false;
-        return;
+        if( ( shownFlags() & i_column ) )
+            i_index++;
+        if( column == i_index )
+        {
+            i_flag = i_column;
+            goto next;
+        }
     }
 
-#define CHECK_COLUMN( meta )                        \
-{                                                   \
-    if( ( shownFlags() & meta ) )                   \
-        i_index++;                                  \
-    if( column == i_index )                         \
-    {                                               \
-        i_flag = meta;                              \
-        goto next;                                  \
-    }                                               \
-}
-
-    CHECK_COLUMN( COLUMN_NUMBER );
-    CHECK_COLUMN( COLUMN_TITLE );
-    CHECK_COLUMN( COLUMN_DURATION );
-    CHECK_COLUMN( COLUMN_ARTIST );
-    CHECK_COLUMN( COLUMN_GENRE );
-    CHECK_COLUMN( COLUMN_ALBUM );
-    CHECK_COLUMN( COLUMN_TRACK_NUMBER );
-    CHECK_COLUMN( COLUMN_DESCRIPTION );
-
-#undef CHECK_COLUMN
 
 next:
     PL_LOCK;
@@ -762,7 +760,6 @@ next:
                                         i_column_sorting( i_flag ),
                                         order == Qt::AscendingOrder ?
                                             ORDER_NORMAL : ORDER_REVERSE );
-            p_playlist->b_reset_currently_playing = true;
         }
     }
     PL_UNLOCK;
@@ -799,21 +796,21 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
         PL_UNLOCK;
         current_selection = list;
         QMenu *menu = new QMenu;
-        menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
-        menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
+        menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
+        menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
         menu->addSeparator();
-        menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
-        menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
+        menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
+        menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
         menu->addSeparator();
-        menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
+        menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
         if( p_item->i_children > -1 )
         {
             menu->addSeparator();
-            menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
-            menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
+            menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
+            menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
         }
         menu->addSeparator();
-        menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
+        menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
         menu->popup( point );
     }
     else
@@ -843,6 +840,7 @@ void PLModel::viewchanged( int meta )
         {
             beginRemoveColumns( parent, index, index+1 );
             rootItem->i_showflags &= ~( meta );
+            getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
             rootItem->updateColumnHeaders();
             endRemoveColumns();
         }
@@ -851,6 +849,7 @@ void PLModel::viewchanged( int meta )
             /* Adding columns */
             beginInsertColumns( parent, index, index+1 );
             rootItem->i_showflags |= meta;
+            getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
             rootItem->updateColumnHeaders();
             endInsertColumns();
         }
@@ -862,6 +861,7 @@ void PLModel::popupDel()
 {
     doDelete( current_selection );
 }
+
 void PLModel::popupPlay()
 {
     PL_LOCK;
@@ -882,18 +882,25 @@ void PLModel::popupInfo()
     if( p_item )
     {
         MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
+        mid->setParent( PlaylistDialog::getInstance( p_intf ),
+                        Qt::Dialog );
         mid->show();
     }
 }
 
 void PLModel::popupStream()
 {
-     msg_Err( p_playlist, "Stream not implemented" );
+    QStringList mrls = selectedURIs();
+    if( !mrls.isEmpty() )
+        THEDP->streamingDialog( NULL, mrls[0], false );
+
 }
 
 void PLModel::popupSave()
 {
-     msg_Err( p_playlist, "Save not implemented" );
+    QStringList mrls = selectedURIs();
+    if( !mrls.isEmpty() )
+        THEDP->streamingDialog( NULL, mrls[0], true );
 }
 
 #include <QUrl>
@@ -910,9 +917,19 @@ void PLModel::popupExplore()
        char *psz_meta = input_item_GetURI( p_input );
        if( psz_meta )
        {
-           /* FIXME add a MRLSplit like function */
-           QFileInfo info( qfu( psz_meta ) );
-           QDesktopServices::openUrl( QUrl::fromLocalFile( info.absolutePath() ) );
+           const char *psz_access;
+           const char *psz_demux;
+           char  *psz_path;
+           input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
+
+           if( EMPTY_STR( psz_access ) ||
+               !strncasecmp( psz_access, "file", 4 ) ||
+               !strncasecmp( psz_access, "dire", 4 ) )
+           {
+               QFileInfo info( qfu( psz_meta ) );
+               QDesktopServices::openUrl(
+                               QUrl::fromLocalFile( info.absolutePath() ) );
+           }
            free( psz_meta );
        }
     }
@@ -926,7 +943,7 @@ static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
 {
     PLModel *p_model = (PLModel *) param;
     PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }
 
@@ -935,9 +952,9 @@ static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
 {
     PLModel *p_model = (PLModel *) param;
     PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     event = new PLEvent( ItemUpdate_Type, nval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }
 
@@ -946,7 +963,7 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
 {
     PLModel *p_model = (PLModel *) param;
     PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }
 
@@ -955,7 +972,7 @@ static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
 {
     PLModel *p_model = (PLModel *) param;
     PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }
 
@@ -966,8 +983,8 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
     playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
     memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
 
-    PLEvent *event = new PLEvent(  p_add );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    PLEvent *event = new PLEvent( p_add );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }