]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
New recently played menu.
[vlc] / modules / gui / qt4 / main_interface.cpp
index aa8e0a0e7f355ae3a177d20512893facf843c3e2..dd29bc6bdc6c6881a38d30e5363247f5923a6af6 100644 (file)
 #include "util/customwidgets.hpp"
 #include "dialogs_provider.hpp"
 #include "components/interface_widgets.hpp"
+#include "components/controller.hpp"
 #include "components/playlist/playlist.hpp"
 #include "dialogs/extended.hpp"
 #include "dialogs/playlist.hpp"
 #include "menus.hpp"
+#include "recents.hpp"
 
 #include <QMenuBar>
 #include <QCloseEvent>
@@ -131,9 +133,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
      * Menu Bar and Status Bar
      **************************/
     QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
+    
     /* StatusBar Creation */
     createStatusBar();
 
+    /* Recents menu updates */
+    CONNECT( RecentsMRL::getInstance( p_intf ), updated(), this, updateRecentsMenu() ); 
 
     /********************
      * Input Manager    *
@@ -146,8 +151,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Connect the input manager to the GUI elements it manages */
 
     /* It is also connected to the control->slider, see the ControlsWidget */
-    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
-             this, setDisplayPosition( float, int, int ) );
     /* Change the SpeedRate in the Status */
     CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
 
@@ -187,11 +190,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* END CONNECTS ON IM */
 
 
-    /** OnTimeOut **/
-    /* TODO Remove this function, but so far, there is no choice because there
-       is no intf-should-die variable #1365 */
-    ON_TIMEOUT( updateOnTimer() );
-
     /************
      * Callbacks
      ************/
@@ -215,13 +213,14 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     CONNECT( this, askUpdate(), this, doComponentsUpdate() );
 
     /* Size and placement of interface */
+    settings->beginGroup( "MainWindow" );
     QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
 
-
-    /* Playlist */
-    if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
+    bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
     settings->endGroup();
 
+    /* Playlist */
+    if( b_visible ) togglePlaylist();
 
     /* Final sizing and showing */
     setMinimumWidth( __MAX( controls->sizeHint().width(),
@@ -233,9 +232,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     if( i_visualmode == QT_MINIMAL_MODE )
         toggleMinimalView();
 
-    /* Update the geometry TODO: is it useful ?*/
+    /* Update the geometry : It is useful if you switch between
+       qt-display-modes ?*/
     updateGeometry();
-    //    resize( sizeHint() );
+    resize( sizeHint() );
 
     /*****************************************************
      * End everything by creating the Systray Management *
@@ -247,22 +247,27 @@ MainInterface::~MainInterface()
 {
     msg_Dbg( p_intf, "Destroying the main interface" );
 
+    if( videoIsActive ) videoWidget->hide();
+
     if( playlistWidget )
-        playlistWidget->savingSettings();
+    {
+        if( !isDocked() )
+            QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
+
+        delete playlistWidget;
+    }
 
     settings->beginGroup( "MainWindow" );
 
-    // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
+    settings->setValue( "pl-dock-status", (int)i_pl_dock );
     settings->setValue( "playlist-visible", (int)playlistVisible );
     settings->setValue( "adv-controls",
                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
 
-    if( !videoIsActive )
-        QVLCTools::saveWidgetPosition(settings, this);
-
     if( bgWidget )
         settings->setValue( "backgroundSize", bgWidget->size() );
 
+    QVLCTools::saveWidgetPosition(settings, this);
     settings->endGroup();
 
     var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
@@ -286,11 +291,7 @@ inline void MainInterface::createStatusBar()
      *  Status Bar  *
      ****************/
     /* Widgets Creation*/
-    b_remainingTime = false;
-    timeLabel = new TimeLabel;
-    timeLabel->setText( " --:--/--:-- " );
-    timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
-    timeLabel->setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
+    timeLabel = new TimeLabel( p_intf );
     nameLabel = new QLabel;
     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
                                       | Qt::TextSelectableByKeyboard );
@@ -313,9 +314,7 @@ inline void MainInterface::createStatusBar()
        - double clicking opens the goto time dialog
        - right-clicking and clicking just toggle between remaining and
          elapsed time.*/
-    CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
     CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
-    CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
 
     /* Speed Label behaviour:
        - right click gives the vertical speed slider */
@@ -374,23 +373,11 @@ void MainInterface::handleMainUi( QSettings *settings )
     mainLayout->setMargin( 0 );
 
     /* Create the CONTROLS Widget */
-    bool b_shiny = config_GetInt( p_intf, "qt-blingbling" );
-    controls = new ControlsWidget( p_intf, this,
-                   settings->value( "adv-controls", false ).toBool(),
-                   b_shiny );
+    controls = new ControlsWidget( p_intf,
+                   settings->value( "adv-controls", false ).toBool() );
     CONNECT( controls, advancedControlsToggled( bool ),
              this, doComponentsUpdate() );
 
-    /* Create the FULLSCREEN CONTROLS Widget */
-    if( config_GetInt( p_intf, "qt-fs-controller" ) )
-    {
-        fullscreenControls = new FullscreenControllerWidget( p_intf, this,
-                settings->value( "adv-controls", false ).toBool(),
-                b_shiny );
-        CONNECT( fullscreenControls, advancedControlsToggled( bool ),
-                this, doComponentsUpdate() );
-    }
-
     /* Add the controls Widget to the main Widget */
     mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
 
@@ -433,6 +420,16 @@ void MainInterface::handleMainUi( QSettings *settings )
 
     /* Finish the sizing */
     main->updateGeometry();
+
+    getSettings()->endGroup();
+#ifdef WIN32
+    if ( depth() > 8 )
+#endif
+    /* Create the FULLSCREEN CONTROLS Widget */
+    if( config_GetInt( p_intf, "qt-fs-controller" ) )
+    {
+        fullscreenControls = new FullscreenControllerWidget( p_intf );
+    }
 }
 
 inline void MainInterface::askForPrivacy()
@@ -472,13 +469,13 @@ int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
     QLabel *text = new QLabel( qtr(
         "<p>The <i>VideoLAN Team</i> doesn't like when an application goes "
         "online without authorization.</p>\n "
-        "<p><i>VLC media player</i> can request limited information on "
-        "the Internet, especially to get CD covers or to know "
-        "if updates are available.</p>\n"
+        "<p><i>VLC media player</i> can retreive limited information from "
+        "the Internet in order to get CD covers or to check "
+        "for available updates.</p>\n"
         "<p><i>VLC media player</i> <b>DOES NOT</b> send or collect <b>ANY</b> "
         "information, even anonymously, about your usage.</p>\n"
-        "<p>Therefore please check the following options, the default being "
-        "almost no access on the web.</p>\n") );
+        "<p>Therefore please select from the following options, the default being "
+        "almost no access to the web.</p>\n") );
     text->setWordWrap( true );
     text->setTextFormat( Qt::RichText );
 
@@ -577,8 +574,6 @@ void MainInterface::toggleFSC()
    QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
 }
 
-
-//FIXME remove me at the end...
 void MainInterface::debug()
 {
 #ifndef NDEBUG
@@ -586,11 +581,9 @@ void MainInterface::debug()
     msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
     if( videoWidget && videoWidget->isVisible() )
     {
-        //    sleep( 10 );
         msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
         msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
     }
-    adjustSize();
 #endif
 }
 
@@ -674,6 +667,8 @@ void MainInterface::releaseVideoSlot( void *p_win )
         bgWidget->show();
     }
 
+    videoIsActive = false;
+
     /* Try to resize, except when you are in Fullscreen mode */
     if( !isFullScreen() ) doComponentsUpdate();
 }
@@ -722,53 +717,51 @@ int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
  **/
 void MainInterface::togglePlaylist()
 {
-    THEDP->playlistDialog();
-#if 0
     /* CREATION
     If no playlist exist, then create one and attach it to the DockPL*/
     if( !playlistWidget )
     {
-        playlistWidget = new PlaylistWidget( p_intf, settings, dockPL );
+        playlistWidget = new PlaylistWidget( p_intf );
 
-        /* Add it to the parent DockWidget */
-        dockPL->setWidget( playlistWidget );
+        i_pl_dock = PL_UNDOCKED;
+/*        i_pl_dock = (pl_dock_e)getSettings()
+                         ->value( "pl-dock-status", PL_UNDOCKED ).toInt(); */
 
-        /* Add the dock to the main Interface */
-        addDockWidget( Qt::BottomDockWidgetArea, dockPL );
+        if( i_pl_dock == PL_UNDOCKED )
+        {
+            playlistWidget->setWindowFlags( Qt::Window );
 
-        /* Make the playlist floating is requested. Default is not. */
-        settings->beginGroup( "MainWindow" );
-        if( settings->value( "playlist-floats", 1 ).toInt() )
+            /* This will restore the geometry but will not work for position,
+               because of parenting */
+            QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
+                    playlistWidget, QSize( 600, 300 ) );
+        }
+        else
         {
-            msg_Dbg( p_intf, "we don't want the playlist inside");
-            dockPL->setFloating( true );
+            mainLayout->insertWidget( 4, playlistWidget );
         }
-        settings->endGroup();
-        settings->beginGroup( "playlist" );
-        dockPL->move( settings->value( "pos", QPoint( 0,0 ) ).toPoint() );
-        QSize newSize = settings->value( "size", QSize( 400, 300 ) ).toSize();
-        if( newSize.isValid() )
-            dockPL->resize( newSize );
-        settings->endGroup();
-
-        dockPL->show();
         playlistVisible = true;
+
+        playlistWidget->show();
     }
     else
     {
     /* toggle the visibility of the playlist */
-       TOGGLEV( dockPL );
-       resize( sizeHint() );
+       TOGGLEV( playlistWidget );
        playlistVisible = !playlistVisible;
+       //doComponentsUpdate(); //resize( sizeHint() );
     }
-    #endif
 }
 
 /* Function called from the menu to undock the playlist */
 void MainInterface::undockPlaylist()
 {
 //    dockPL->setFloating( true );
-    adjustSize();
+//    adjustSize();
+}
+
+void MainInterface::dockPlaylist( pl_dock_e i_pos )
+{
 }
 
 void MainInterface::toggleMinimalView()
@@ -795,18 +788,29 @@ void MainInterface::toggleMinimalView()
 
 /* Video widget cannot do this synchronously as it runs in another thread */
 /* Well, could it, actually ? Probably dangerous ... */
+
+/* This function is called:
+   - toggling of minimal View
+   - through askUpdate() by Vout thread request video and resize video (zoom)
+   - Advanced buttons toggled
+ */
 void MainInterface::doComponentsUpdate()
 {
     msg_Dbg( p_intf, "Updating the geometry" );
-    //    resize( sizeHint() );
-    adjustSize();
+    /* Here we resize to sizeHint() and not adjustsize because we want
+       the videoWidget to be exactly the correctSize */
+    resize( sizeHint() );
+    //    adjustSize()  ;
+#ifndef NDEBUG
+    debug();
+#endif
 }
 
 /* toggling advanced controls buttons */
 void MainInterface::toggleAdvanced()
 {
     controls->toggleAdvanced();
-    if( fullscreenControls ) fullscreenControls->toggleAdvanced();
+//    if( fullscreenControls ) fullscreenControls->toggleAdvanced();
 }
 
 /* Get the visibility status of the controls (hidden or not, advanced or not) */
@@ -841,27 +845,6 @@ void MainInterface::visual()
 /************************************************************************
  * Other stuff
  ************************************************************************/
-void MainInterface::setDisplayPosition( float pos, int time, int length )
-{
-    char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
-    secstotimestr( psz_length, length );
-    secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
-                                                           : time );
-
-    QString timestr;
-    timestr.sprintf( "%s/%s", psz_time,
-                            ( !length && time ) ? "--:--" : psz_length );
-
-    /* Add a minus to remaining time*/
-    if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
-    else timeLabel->setText( " "+timestr+" " );
-}
-
-void MainInterface::toggleTimeDisplay()
-{
-    b_remainingTime = !b_remainingTime;
-}
-
 void MainInterface::setName( QString name )
 {
     input_name = name; /* store it for the QSystray use */
@@ -875,16 +858,6 @@ void MainInterface::setStatus( int status )
 {
     msg_Dbg( p_intf, "Updating the stream status: %i", status );
 
-    /* Forward the status to the controls to toggle Play/Pause */
-    controls->setStatus( status );
-    controls->updateInput();
-
-    if( fullscreenControls )
-    {
-        fullscreenControls->setStatus( status );
-        fullscreenControls->updateInput();
-    }
-
     speedControl->setEnable( THEMIM->getIM()->hasInput() );
 
     /* And in the systray for the menu */
@@ -902,16 +875,6 @@ void MainInterface::setRate( int rate )
     speedControl->updateControls( rate );
 }
 
-void MainInterface::updateOnTimer()
-{
-    /* No event for dying */
-    if( intf_ShouldDie( p_intf ) )
-    {
-        QApplication::closeAllWindows();
-        QApplication::quit();
-    }
-}
-
 /*****************************************************************************
  * Systray Icon and Systray Menu
  *****************************************************************************/
@@ -1054,6 +1017,11 @@ void MainInterface::updateSystrayTooltipStatus( int i_status )
  * D&D Events
  ************************************************************************/
 void MainInterface::dropEvent(QDropEvent *event)
+{
+    dropEventPlay( event, true );
+}
+
+void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
 {
      const QMimeData *mimeData = event->mimeData();
 
@@ -1063,7 +1031,8 @@ void MainInterface::dropEvent(QDropEvent *event)
         if( THEMIM->getIM()->hasInput() )
         {
             if( input_AddSubtitles( THEMIM->getInput(),
-                                    qtu( mimeData->urls()[0].toString() ),
+                                    qtu( toNativeSeparators(
+                                         mimeData->urls()[0].toLocalFile() ) ),
                                     true ) )
             {
                 event->acceptProposedAction();
@@ -1071,15 +1040,17 @@ void MainInterface::dropEvent(QDropEvent *event)
             }
         }
      }
-     bool first = true;
+     bool first = b_play;
      foreach( QUrl url, mimeData->urls() )
      {
-        QString s = url.toLocalFile();
+        QString s = toNativeSeparators( url.toLocalFile() );
+
         if( s.length() > 0 ) {
             playlist_Add( THEPL, qtu(s), NULL,
-                          PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
+                          PLAYLIST_APPEND | (first ? PLAYLIST_GO: 0),
                           PLAYLIST_END, true, false );
             first = false;
+            RecentsMRL::getInstance( p_intf )->addRecent( s );
         }
      }
      event->acceptProposedAction();
@@ -1126,7 +1097,7 @@ void MainInterface::customEvent( QEvent *event )
 
 void MainInterface::keyPressEvent( QKeyEvent *e )
 {
-    if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() & Qt::Key_H )
+    if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
           && menuBar()->isHidden() )
     {
         toggleMinimalView();
@@ -1159,7 +1130,10 @@ void MainInterface::closeEvent( QCloseEvent *e )
 void MainInterface::toggleFullScreen( void )
 {
     if( isFullScreen() )
+    {
         showNormal();
+        emit askUpdate(); // Needed if video was launched after the F11
+    }
     else
         showFullScreen();
 }
@@ -1209,3 +1183,12 @@ static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
     /* Show event */
      return VLC_SUCCESS;
 }
+
+/*****************************************************************************
+ * updateRecentsMenu: event called by RecentsMRL
+ *****************************************************************************/
+
+void MainInterface::updateRecentsMenu()
+{
+    QVLCMenu::updateRecents( p_intf );
+}