]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs_provider.cpp
sout: chromecast: handle tcp close messages
[vlc] / modules / gui / qt4 / dialogs_provider.cpp
index 6905c4257a2d915e325a752eff211f177f8f5c33..7c3cf165c958182a302536924c458fd7081c1ffb 100644 (file)
@@ -34,6 +34,7 @@
 #include "menus.hpp"
 #include "recents.hpp"
 #include "util/qt_dirs.hpp"
+#include "util/customwidgets.hpp" /* VLCKeyToString() */
 #include "main_interface.hpp"
 
 /* The dialogs */
 DialogsProvider* DialogsProvider::instance = NULL;
 
 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
-                                  QObject( NULL ), p_intf( _p_intf )
+                                  QObject( NULL ), p_intf( _p_intf ),
+                                  popupMenu( NULL ),
+                                  videoPopupMenu( NULL ),
+                                  audioPopupMenu( NULL ),
+                                  miscPopupMenu( NULL )
 {
     b_isDying = false;
 
@@ -91,22 +96,22 @@ DialogsProvider::~DialogsProvider()
     PlaylistDialog::killInstance();
     MediaInfoDialog::killInstance();
     MessagesDialog::killInstance();
-    ExtendedDialog::killInstance();
     BookmarksDialog::killInstance();
     HelpDialog::killInstance();
 #ifdef UPDATE_CHECK
     UpdateDialog::killInstance();
 #endif
     PluginDialog::killInstance();
+    EpgDialog::killInstance();
 
     delete menusMapper;
     delete menusUpdateMapper;
     delete SDMapper;
 
-    QVLCMenu::PopupMenu( p_intf, false );
-    QVLCMenu::AudioPopupMenu( p_intf, false );
-    QVLCMenu::VideoPopupMenu( p_intf, false );
-    QVLCMenu::MiscPopupMenu( p_intf, false );
+    delete popupMenu;
+    delete videoPopupMenu;
+    delete audioPopupMenu;
+    delete miscPopupMenu;
 }
 
 void DialogsProvider::quit()
@@ -117,7 +122,7 @@ void DialogsProvider::quit()
 
 void DialogsProvider::customEvent( QEvent *event )
 {
-    if( event->type() == (int)DialogEvent_Type )
+    if( event->type() == DialogEvent::DialogEvent_Type )
     {
         DialogEvent *de = static_cast<DialogEvent*>(event);
         switch( de->i_dialog )
@@ -148,18 +153,44 @@ void DialogsProvider::customEvent( QEvent *event )
            bookmarksDialog(); break;
         case INTF_DIALOG_EXTENDED:
            extendedDialog(); break;
+        case INTF_DIALOG_SENDKEY:
+           sendKey( de->i_arg ); break;
 #ifdef ENABLE_VLM
         case INTF_DIALOG_VLM:
            vlmDialog(); break;
 #endif
         case INTF_DIALOG_POPUPMENU:
-           QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete popupMenu; popupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               popupMenu = VLCMenuBar::PopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_AUDIOPOPUPMENU:
-           QVLCMenu::AudioPopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete audioPopupMenu; audioPopupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               audioPopupMenu = VLCMenuBar::AudioPopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_VIDEOPOPUPMENU:
-           QVLCMenu::VideoPopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete videoPopupMenu; videoPopupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               videoPopupMenu = VLCMenuBar::VideoPopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_MISCPOPUPMENU:
-           QVLCMenu::MiscPopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete miscPopupMenu; miscPopupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               miscPopupMenu = VLCMenuBar::MiscPopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_WIZARD:
         case INTF_DIALOG_STREAMWIZARD:
             openAndStreamingDialogs(); break;
@@ -178,6 +209,9 @@ void DialogsProvider::customEvent( QEvent *event )
 /****************************************************************************
  * Individual simple dialogs
  ****************************************************************************/
+const QEvent::Type DialogEvent::DialogEvent_Type =
+        (QEvent::Type)QEvent::registerEventType();
+
 void DialogsProvider::playlistDialog()
 {
     PlaylistDialog::getInstance( p_intf )->toggleVisible();
@@ -191,20 +225,24 @@ void DialogsProvider::prefsDialog()
 
 void DialogsProvider::extendedDialog()
 {
-    if( !ExtendedDialog::getInstance( p_intf )->isVisible() || /* Hidden */
-        ExtendedDialog::getInstance( p_intf )->currentTab() != 0 )  /* wrong tab */
-        ExtendedDialog::getInstance( p_intf )->showTab( 0 );
+    ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
+
+    if( !extDialog->isVisible() || /* Hidden */
+        extDialog->currentTab() != 0 )  /* wrong tab */
+        extDialog->showTab( 0 );
     else
-        ExtendedDialog::getInstance( p_intf )->hide();
+        extDialog->hide();
 }
 
 void DialogsProvider::synchroDialog()
 {
-    if( !ExtendedDialog::getInstance( p_intf )->isVisible() || /* Hidden */
-        ExtendedDialog::getInstance( p_intf )->currentTab() != 2 )  /* wrong tab */
-        ExtendedDialog::getInstance( p_intf )->showTab( 2 );
+    ExtendedDialog *extDialog = ExtendedDialog::getInstance(p_intf );
+
+    if( !extDialog->isVisible() || /* Hidden */
+        extDialog->currentTab() != 2 )  /* wrong tab */
+        extDialog->showTab( 2 );
     else
-        ExtendedDialog::getInstance( p_intf )->hide();
+        extDialog->hide();
 }
 
 void DialogsProvider::messagesDialog()
@@ -243,12 +281,12 @@ void DialogsProvider::aboutDialog()
 
 void DialogsProvider::mediaInfoDialog()
 {
-    MediaInfoDialog::getInstance( p_intf )->showTab( 0 );
+    MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::META_PANEL );
 }
 
 void DialogsProvider::mediaCodecDialog()
 {
-    MediaInfoDialog::getInstance( p_intf )->showTab( 2 );
+    MediaInfoDialog::getInstance( p_intf )->showTab( MediaInfoDialog::INFO_PANEL );
 }
 
 void DialogsProvider::bookmarksDialog()
@@ -278,6 +316,18 @@ void DialogsProvider::epgDialog()
     EpgDialog::getInstance( p_intf )->toggleVisible();
 }
 
+void DialogsProvider::setPopupMenu()
+{
+    delete popupMenu;
+    popupMenu = VLCMenuBar::PopupMenu( p_intf, true );
+}
+
+void DialogsProvider::destroyPopupMenu()
+{
+    delete popupMenu;
+    popupMenu = NULL;
+}
+
 /* Generic open file */
 void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
 {
@@ -303,7 +353,8 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
     /* Save */
     if( p_arg->b_save )
     {
-        QString file = QFileDialog::getSaveFileName( NULL, p_arg->psz_title,
+        QString file = QFileDialog::getSaveFileName( NULL,
+                                        qfu( p_arg->psz_title ),
                                         p_intf->p_sys->filepath, extensions );
         if( !file.isEmpty() )
         {
@@ -317,7 +368,7 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
     else /* non-save mode */
     {
         QStringList files = QFileDialog::getOpenFileNames( NULL,
-                p_arg->psz_title, p_intf->p_sys->filepath,
+                qfu( p_arg->psz_title ), p_intf->p_sys->filepath,
                 extensions );
         p_arg->i_results = files.count();
         p_arg->psz_results = (char **)malloc( p_arg->i_results * sizeof( char * ) );
@@ -325,7 +376,7 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg )
         foreach( const QString &file, files )
             p_arg->psz_results[i++] = strdup( qtu( toNativeSepNoSlash( file ) ) );
         if(i == 0)
-            p_intf->p_sys->filepath = QString::fromAscii("");
+            p_intf->p_sys->filepath = QString::fromLatin1("");
         else
             p_intf->p_sys->filepath = qfu( p_arg->psz_results[i-1] );
     }
@@ -398,21 +449,21 @@ QStringList DialogsProvider::showSimpleOpen( const QString& help,
 {
     QString fileTypes = "";
     if( filters & EXT_FILTER_MEDIA ) {
-        ADD_FILTER_MEDIA( fileTypes );
+        ADD_EXT_FILTER( fileTypes, EXTENSIONS_MEDIA );
     }
     if( filters & EXT_FILTER_VIDEO ) {
-        ADD_FILTER_VIDEO( fileTypes );
+        ADD_EXT_FILTER( fileTypes, EXTENSIONS_VIDEO );
     }
     if( filters & EXT_FILTER_AUDIO ) {
-        ADD_FILTER_AUDIO( fileTypes );
+        ADD_EXT_FILTER( fileTypes, EXTENSIONS_AUDIO );
     }
     if( filters & EXT_FILTER_PLAYLIST ) {
-        ADD_FILTER_PLAYLIST( fileTypes );
+        ADD_EXT_FILTER( fileTypes, EXTENSIONS_PLAYLIST );
     }
     if( filters & EXT_FILTER_SUBTITLE ) {
-        ADD_FILTER_SUBTITLE( fileTypes );
+        ADD_EXT_FILTER( fileTypes, EXTENSIONS_SUBTITLE );
     }
-    ADD_FILTER_ALL( fileTypes );
+    ADD_EXT_FILTER( fileTypes, EXTENSIONS_ALL );
     fileTypes.replace( ";*", " *");
 
     QStringList files = QFileDialog::getOpenFileNames( NULL,
@@ -433,16 +484,14 @@ QStringList DialogsProvider::showSimpleOpen( const QString& help,
 void DialogsProvider::addFromSimple( bool pl, bool go)
 {
     QStringList files = DialogsProvider::showSimpleOpen();
-    int mode = go ? PLAYLIST_GO : PLAYLIST_PREPARSE;
 
+    bool first = go;
     files.sort();
     foreach( const QString &file, files )
     {
         QString url = toURI( toNativeSeparators( file ) );
-        playlist_Add( THEPL, qtu( url ), NULL, PLAYLIST_APPEND | mode,
-                      PLAYLIST_END, pl, pl_Unlocked );
-        RecentsMRL::getInstance( p_intf )->addRecent( url );
-        mode = PLAYLIST_PREPARSE;
+        Open::openMRL( p_intf, url, first, pl);
+        first = false;
     }
 }
 
@@ -451,16 +500,6 @@ void DialogsProvider::simpleOpenDialog()
     addFromSimple( true, true ); /* Playlist and Go */
 }
 
-void DialogsProvider::simplePLAppendDialog()
-{
-    addFromSimple( true, false );
-}
-
-void DialogsProvider::simpleMLAppendDialog()
-{
-    addFromSimple( false, false );
-}
-
 /* Url & Clipboard */
 /**
  * Open a MRL.
@@ -468,21 +507,24 @@ void DialogsProvider::simpleMLAppendDialog()
  **/
 void DialogsProvider::openUrlDialog()
 {
-    OpenUrlDialog *oud = new OpenUrlDialog( p_intf );
-    if( oud->exec() == QDialog::Accepted )
+    OpenUrlDialog oud( p_intf );
+    if( oud.exec() != QDialog::Accepted )
+        return;
+
+    QString url = oud.url();
+    if( url.isEmpty() )
+        return;
+
+    if( !url.contains( qfu( "://" ) ) )
     {
-        QString url = oud->url();
-        if( !url.isEmpty() )
-        {
-            playlist_Add( THEPL, qtu( url ),
-                          NULL, !oud->shouldEnqueue() ?
-                                  ( PLAYLIST_APPEND | PLAYLIST_GO )
-                                : ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
-                          PLAYLIST_END, true, false );
-            RecentsMRL::getInstance( p_intf )->addRecent( url );
-        }
+        char *uri = vlc_path2uri( qtu( url ), NULL );
+        if( uri == NULL )
+            return;
+        url = qfu(uri);
+        free( uri );
     }
-    delete oud;
+
+    Open::openMRL( p_intf, qtu(url), !oud.shouldEnqueue() );
 }
 
 /* Directory */
@@ -493,31 +535,39 @@ void DialogsProvider::openUrlDialog()
  **/
 static void openDirectory( intf_thread_t *p_intf, bool pl, bool go )
 {
-    QString dir = QFileDialog::getExistingDirectory( NULL, qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
+    QString uri = DialogsProvider::getDirectoryDialog( p_intf );
+    if( !uri.isEmpty() )
+        Open::openMRL( p_intf, uri, go, pl );
+}
 
-    if( dir.isEmpty() )
-        return;
+QString DialogsProvider::getDirectoryDialog( intf_thread_t *p_intf )
+{
+    QString dir = QFileDialog::getExistingDirectory( NULL,
+            qtr( I_OP_DIR_WINTITLE ), p_intf->p_sys->filepath );
+
+    if( dir.isEmpty() ) return QString();
+
+    p_intf->p_sys->filepath = dir;
 
     const char *scheme = "directory";
-    if( dir.endsWith( "/VIDEO_TS", Qt::CaseInsensitive ) )
+    if( dir.endsWith( DIR_SEP "VIDEO_TS", Qt::CaseInsensitive ) )
         scheme = "dvd";
+    else if( dir.endsWith( DIR_SEP "BDMV", Qt::CaseInsensitive ) )
+    {
+        scheme = "bluray";
+        dir.remove( "BDMV" );
+    }
 
-    char *uri = make_URI( qtu( toNativeSeparators( dir ) ), scheme );
+    char *uri = vlc_path2uri( qtu( toNativeSeparators( dir ) ), scheme );
     if( unlikely(uri == NULL) )
-        return;
-
-    RecentsMRL::getInstance( p_intf )->addRecent( qfu(uri) );
+        return QString();
 
-    input_item_t *p_input = input_item_New( uri, NULL );
+    dir = qfu( uri );
     free( uri );
-    if( unlikely( p_input == NULL ) )
-        return;
 
-    /* FIXME: playlist_AddInput() can fail */
-    playlist_AddInput( THEPL, p_input,
-                       go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
-                       PLAYLIST_END, pl, pl_Unlocked );
-    vlc_gc_decref( p_input );
+    RecentsMRL::getInstance( p_intf )->addRecent( dir );
+
+    return dir;
 }
 
 void DialogsProvider::PLOpenDir()
@@ -530,11 +580,6 @@ void DialogsProvider::PLAppendDir()
     openDirectory( p_intf, true, false );
 }
 
-void DialogsProvider::MLAppendDir()
-{
-    openDirectory( p_intf, false , false );
-}
-
 /****************
  * Playlist     *
  ****************/
@@ -548,7 +593,7 @@ void DialogsProvider::openAPlaylist()
     }
 }
 
-void DialogsProvider::saveAPlaylist()
+void DialogsProvider::saveAPlaylist(playlist_t *p_playlist, playlist_item_t *p_node)
 {
     static const struct
     {
@@ -576,20 +621,67 @@ void DialogsProvider::saveAPlaylist()
 
     QString selected;
     QString file = QFileDialog::getSaveFileName( NULL,
-                                  qtr( "Save playlist as..." ),
-                                  p_intf->p_sys->filepath, filters.join( ";;" ),
-                                  &selected );
+                                                 qtr( "Save playlist as..." ),
+                                                 p_intf->p_sys->filepath, filters.join( ";;" ),
+                                                 &selected );
+    const char *psz_selected_module = NULL;
+    const char *psz_last_playlist_ext = NULL;
+
     if( file.isEmpty() )
         return;
 
+    /* First test if the file extension is set, and different to selected filter */
     for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
-        if( selected == qfu( vlc_gettext( types[i].filter_name ) ) + " (*." + qfu( types[i].filter_patterns ) + ")" )
+    {
+        if ( file.endsWith( QString( "." ) + qfu( types[i].filter_patterns ) ) )
         {
-            playlist_Export( THEPL, qtu( toNativeSeparators( file ) ),
-                             THEPL->p_playing, types[i].module );
-            getSettings()->setValue( "last-playlist-ext", types[i].filter_patterns );
+            psz_selected_module = types[i].module;
+            psz_last_playlist_ext = types[i].filter_patterns;
             break;
         }
+    }
+
+    /* otherwise apply the selected extension */
+    if ( !psz_last_playlist_ext )
+    {
+        for( size_t i = 0; i < sizeof (types) / sizeof (types[0]); i++)
+        {
+            if ( selected.startsWith( qfu( vlc_gettext( types[i].filter_name ) ) ) )
+            {
+                psz_selected_module = types[i].module;
+                psz_last_playlist_ext = types[i].filter_patterns;
+                /* Fix file extension */
+                file = file.append( QString( "." ) + qfu( psz_last_playlist_ext ) );
+                break;
+            }
+        }
+    }
+
+    if ( psz_selected_module )
+    {
+        playlist_Export( p_playlist, qtu( toNativeSeparators( file ) ),
+                         p_node, psz_selected_module );
+        getSettings()->setValue( "last-playlist-ext", psz_last_playlist_ext );
+    }
+}
+
+void DialogsProvider::savePlayingToPlaylist()
+{
+    saveAPlaylist(THEPL, THEPL->p_playing);
+}
+
+void DialogsProvider::saveRecentsToPlaylist()
+{
+    playlist_item_t *p_node_recents = RecentsMRL::getInstance(p_intf)->toPlaylist(0);
+
+    if (p_node_recents == NULL)
+    {
+        msg_Warn(p_intf, "cannot create playlist from recents");
+        return;
+    }
+
+    saveAPlaylist(THEPL, p_node_recents);
+    playlist_NodeDelete(THEPL, p_node_recents, true, false);
 }
 
 /****************************************************************************
@@ -637,29 +729,7 @@ void DialogsProvider::streamingDialog( QWidget *parent,
     {
         options += soutoption.split( " :");
 
-        /* Create Input */
-        input_item_t *p_input;
-        p_input = input_item_New( qtu( mrl ), _("Streaming") );
-
-        /* Add normal Options */
-        for( int j = 0; j < options.count(); j++ )
-        {
-            QString qs = colon_unescape( options[j] );
-            if( !qs.isEmpty() )
-            {
-                input_item_AddOption( p_input, qtu( qs ),
-                        VLC_INPUT_OPTION_TRUSTED );
-                msg_Dbg( p_intf, "Adding option: %s", qtu( qs ) );
-            }
-        }
-
-        /* Switch between enqueuing and starting the item */
-        /* FIXME: playlist_AddInput() can fail */
-        playlist_AddInput( THEPL, p_input,
-                PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true, pl_Unlocked );
-        vlc_gc_decref( p_input );
-
-        RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+        Open::openMRLwithOptions( p_intf, mrl, &options, true, true, _("Streaming") );
     }
 }
 
@@ -702,8 +772,8 @@ void DialogsProvider::loadSubtitlesFile()
     free( path2 );
     foreach( const QString &qsFile, qsl )
     {
-        if( input_AddSubtitle( p_input, qtu( toNativeSeparators( qsFile ) ),
-                    true ) )
+        if( input_AddSubtitleOSD( p_input, qtu( toNativeSeparators( qsFile ) ),
+                    true, true ) )
             msg_Warn( p_intf, "unable to load subtitles from '%s'",
                       qtu( qsFile ) );
     }
@@ -716,7 +786,7 @@ void DialogsProvider::loadSubtitlesFile()
 
 void DialogsProvider::menuAction( QObject *data )
 {
-    QVLCMenu::DoAction( data );
+    VLCMenuBar::DoAction( data );
 }
 
 void DialogsProvider::menuUpdateAction( QObject *data )
@@ -734,12 +804,32 @@ void DialogsProvider::SDMenuAction( const QString& data )
         playlist_ServicesDiscoveryRemove( THEPL, qtu( data ) );
 }
 
-/**
- * Play the MRL contained in the Recently played menu.
- **/
-void DialogsProvider::playMRL( const QString &mrl )
-{
-    playlist_Add( THEPL, qtu(mrl), NULL,
-           PLAYLIST_APPEND | PLAYLIST_GO , PLAYLIST_END, true, false );
-    RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+void DialogsProvider::sendKey( int key )
+{
+     // translate from a vlc keycode into a Qt sequence
+     QKeySequence kseq0( VLCKeyToString( key, true ) );
+
+     if( popupMenu == NULL )
+     {
+         // make sure at least a non visible popupmenu is available
+         popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
+         if( unlikely( popupMenu == NULL ) )
+             return;
+     }
+
+     // test against key accelerators from the popupmenu
+     QList<QAction*> actions = popupMenu->findChildren<QAction*>();
+     for( int i = 0; i < actions.size(); i++ )
+     {
+         QAction* action = actions.at(i);
+         QKeySequence kseq = action->shortcut();
+         if( kseq == kseq0 )
+         {
+             action->trigger();
+             return;
+         }
+     }
+
+     // forward key to vlc core when not a key accelerator
+     var_SetInteger( p_intf->p_libvlc, "key-pressed", key );
 }