]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Qt: Menus: Don't repeat context for playlist view modes
[vlc] / modules / gui / qt4 / main_interface.cpp
index 72e05caa22a35736f16bee875f2d4b5885afdcc1..2f2ca1a28ef7de2fca10be73a27d4f454f80c6a9 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * main_interface.cpp : Main interface
  ****************************************************************************
- * Copyright (C) 2006-2010 VideoLAN and AUTHORS
+ * Copyright (C) 2006-2011 VideoLAN and AUTHORS
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
@@ -41,6 +41,7 @@
 #include "components/controller.hpp"            // controllers
 #include "components/playlist/playlist.hpp"     // plWidget
 #include "dialogs/firstrun.hpp"                 // First Run
+#include "dialogs/playlist.hpp"                 // PlaylistDialog
 
 #include "menus.hpp"                            // Menu creation
 #include "recents.hpp"                          // RecentItems when DnD
 #include <QUrl>
 #include <QSize>
 #include <QDate>
+#include <QMimeData>
 
 #include <QMenu>
 #include <QMenuBar>
 #include <QStatusBar>
 #include <QLabel>
 #include <QStackedWidget>
+#include <QFileInfo>
 
 #include <vlc_keys.h>                       /* Wheel event */
 #include <vlc_vout_display.h>               /* vout_thread_t and VOUT_ events */
@@ -68,6 +71,14 @@ static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
                         vlc_value_t old_val, vlc_value_t new_val, void *param );
 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param );
+static int IntfBossCB( vlc_object_t *p_this, const char *psz_variable,
+                       vlc_value_t old_val, vlc_value_t new_val, void *param );
+static int IntfRaiseMainCB( vlc_object_t *p_this, const char *psz_variable,
+                           vlc_value_t old_val, vlc_value_t new_val,
+                           void *param );
+
+const QEvent::Type MainInterface::ToolbarsNeedRebuild =
+        (QEvent::Type)QEvent::registerEventType();
 
 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 {
@@ -76,9 +87,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     videoWidget          = NULL;
     playlistWidget       = NULL;
     stackCentralOldWidget= NULL;
-#ifndef HAVE_MAEMO
     sysTray              = NULL;
-#endif
     fullscreenControls   = NULL;
     cryptedLabel         = NULL;
     controls             = NULL;
@@ -87,7 +96,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     b_hideAfterCreation  = false; // --qt-start-minimized
     playlistVisible      = false;
     input_name           = "";
-
+    b_interfaceFullScreen= false;
+    b_hasPausedWhenMinimized = false;
+    i_kc_offset          = false;
 
     /* Ask for Privacy */
     FirstRun::CheckAndRun( this, p_intf );
@@ -116,11 +127,13 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     b_minimalView = var_InheritBool( p_intf, "qt-minimal-view" );
 
     /* Do we want anoying popups or not */
-    b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" );
+    i_notificationSetting = var_InheritInteger( p_intf, "qt-notification" );
+
+    /* */
+    b_pauseOnMinimize = var_InheritBool( p_intf, "qt-pause-minimized" );
 
     /* Set the other interface settings */
     settings = getSettings();
-    settings->beginGroup( "MainWindow" );
 
 #ifdef WIN32
     /* Volume keys */
@@ -128,15 +141,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 #endif
 
     /* */
-    b_plDocked = getSettings()->value( "pl-dock-status", true ).toBool();
-
-    settings->endGroup( );
+    b_plDocked = getSettings()->value( "MainWindow/pl-dock-status", true ).toBool();
 
-    /**************
-     * Status Bar *
-     **************/
-    createStatusBar();
-    statusBar()->setVisible( getSettings()->value( "status-bar-visible", false ).toBool() );
 
     /**************************
      *  UI and Widgets design
@@ -146,15 +152,17 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /************
      * Menu Bar *
      ************/
-    QVLCMenu::createMenuBar( this, p_intf );
+    VLCMenuBar::createMenuBar( this, p_intf );
     CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
              this, destroyPopupMenu() );
 
     createMainWidget( settings );
-    /*********************************
-     * Create the Systray Management *
-     *********************************/
-    initSystray();
+
+    /**************
+     * Status Bar *
+     **************/
+    createStatusBar();
+    setStatusBarVisibility( getSettings()->value( "MainWindow/status-bar-visible", false ).toBool() );
 
     /********************
      * Input Manager    *
@@ -164,12 +172,18 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 #ifdef WIN32
     himl = NULL;
     p_taskbl = NULL;
-    taskbar_wmsg = RegisterWindowMessage("TaskbarButtonCreated");
+    taskbar_wmsg = RegisterWindowMessage(TEXT("TaskbarButtonCreated"));
 #endif
 
-    /************************************************************
-     * Connect the input manager to the GUI elements it manages *
-     ************************************************************/
+    /*********************************
+     * Create the Systray Management *
+     *********************************/
+    initSystray();
+
+    /*************************************************************
+     * Connect the input manager to the GUI elements it manages  *
+     * Beware initSystray did some connects on input manager too *
+     *************************************************************/
     /**
      * Connects on nameChanged()
      * Those connects are different because options can impeach them to trigger.
@@ -177,38 +191,16 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Main Interface statusbar */
     CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
              this, setName( const QString& ) );
-    /* and systray */
-#ifndef HAVE_MAEMO
-    if( sysTray )
-    {
-        CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
-                 this, updateSystrayTooltipName( const QString& ) );
-    }
-#endif
     /* and title of the Main Interface*/
     if( var_InheritBool( p_intf, "qt-name-in-title" ) )
     {
         CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
                  this, setVLCWindowsTitle( const QString& ) );
     }
-
-    /**
-     * CONNECTS on PLAY_STATUS
-     **/
-    /* Status on the systray */
-#ifndef HAVE_MAEMO
-    if( sysTray )
-    {
-        CONNECT( THEMIM->getIM(), playingStatusChanged( int ),
-                 this, updateSystrayTooltipStatus( int ) );
-    }
-#endif
-
     /* END CONNECTS ON IM */
 
     /* VideoWidget connects for asynchronous calls */
     b_videoFullScreen = false;
-    b_videoOnTop = false;
     connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
              this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
              Qt::BlockingQueuedConnection );
@@ -224,40 +216,42 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
             CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
                      this, setVideoSize( unsigned int, unsigned int ) );
             CONNECT( videoWidget, sizeChanged( int, int ),
-                     this, resizeStack( int,  int ) );
+                     this, videoSizeChanged( int,  int ) );
         }
         CONNECT( this, askVideoSetFullScreen( bool ),
                  this, setVideoFullScreen( bool ) );
     }
 
-    CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
+    CONNECT( THEDP, toolBarConfUpdated(), this, toolBarConfUpdated() );
+    installEventFilter( this );
 
     CONNECT( this, askToQuit(), THEDP, quit() );
 
+    CONNECT( this, askBoss(), this, setBoss() );
+    CONNECT( this, askRaise(), this, setRaise() );
+
     /** END of CONNECTS**/
 
 
     /************
      * Callbacks
      ************/
-    var_AddCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
+    var_AddCallback( p_intf->p_libvlc, "intf-toggle-fscontrol", IntfShowCB, p_intf );
+    var_AddCallback( p_intf->p_libvlc, "intf-boss", IntfBossCB, p_intf );
+    var_AddCallback( p_intf->p_libvlc, "intf-show", IntfRaiseMainCB, p_intf );
 
     /* Register callback for the intf-popupmenu variable */
     var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
 
-    /* Playlist */
-    int i_plVis = settings->value( "MainWindow/playlist-visible", false ).toBool();
 
-    if( i_plVis ) togglePlaylist();
+    /* Final Sizing, restoration and placement of the interface */
+    if( settings->value( "MainWindow/playlist-visible", false ).toBool() )
+        togglePlaylist();
 
-    /**** FINAL SIZING and placement of interface */
-    settings->beginGroup( "MainWindow" );
-    QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
-    settings->endGroup();
+    QVLCTools::restoreWidgetPosition( settings, this, QSize(600, 420) );
 
     b_interfaceFullScreen = isFullScreen();
 
-    /* Final sizing and showing */
     setVisible( !b_hideAfterCreation );
 
     computeMinimumSize();
@@ -265,8 +259,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Switch to minimal view if needed, must be called after the show() */
     if( b_minimalView )
         toggleMinimalView( true );
-
-    b_hasPausedWhenMinimized = false;
 }
 
 MainInterface::~MainInterface()
@@ -282,7 +274,7 @@ MainInterface::~MainInterface()
     if( himl )
         ImageList_Destroy( himl );
     if(p_taskbl)
-        p_taskbl->vt->Release(p_taskbl);
+        p_taskbl->Release();
     CoUninitialize();
 #endif
 
@@ -296,36 +288,31 @@ MainInterface::~MainInterface()
     delete fullscreenControls;
 
     /* Save states */
-    settings->beginGroup( "MainWindow" );
 
+    settings->beginGroup("MainWindow");
     settings->setValue( "pl-dock-status", b_plDocked );
+
     /* Save playlist state */
-    if( playlistWidget )
-        settings->setValue( "playlist-visible", playlistVisible );
+    settings->setValue( "playlist-visible", playlistVisible );
 
     settings->setValue( "adv-controls",
                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
-    settings->setValue( "status-bar-visible", statusBar()->isVisible() );
+    settings->setValue( "status-bar-visible", b_statusbarVisible );
 
     /* Save the stackCentralW sizes */
     settings->setValue( "bgSize", stackWidgetsSizes[bgWidget] );
     settings->setValue( "playlistSize", stackWidgetsSizes[playlistWidget] );
+    settings->endGroup();
 
     /* Save this size */
     QVLCTools::saveWidgetPosition(settings, this);
 
-    settings->endGroup();
-
-    /* Save undocked playlist size */
-    if( playlistWidget && !isPlDocked() )
-        QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
-
-    delete playlistWidget;
-
     delete statusBar();
 
     /* Unregister callbacks */
-    var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
+    var_DelCallback( p_intf->p_libvlc, "intf-boss", IntfBossCB, p_intf );
+    var_DelCallback( p_intf->p_libvlc, "intf-show", IntfRaiseMainCB, p_intf );
+    var_DelCallback( p_intf->p_libvlc, "intf-toggle-fscontrol", IntfShowCB, p_intf );
     var_DelCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
 
     p_intf->p_sys->p_mi = NULL;
@@ -347,12 +334,14 @@ void MainInterface::recreateToolbars()
 {
     bool b_adv = getControlsVisibilityStatus() & CONTROLS_ADVANCED;
 
-    settings->beginGroup( "MainWindow" );
     delete controls;
     delete inputC;
 
     controls = new ControlsWidget( p_intf, b_adv, this );
     inputC = new InputControlsWidget( p_intf, this );
+    mainLayout->insertWidget( 2, inputC );
+    mainLayout->insertWidget( settings->value( "MainWindow/ToolbarPos", 0 ).toInt() ? 0: 3,
+                              controls );
 
     if( fullscreenControls )
     {
@@ -360,14 +349,27 @@ void MainInterface::recreateToolbars()
         fullscreenControls = new FullscreenControllerWidget( p_intf, this );
         CONNECT( fullscreenControls, keyPressed( QKeyEvent * ),
                  this, handleKeyPress( QKeyEvent * ) );
+        THEMIM->requestVoutUpdate();
     }
-    mainLayout->insertWidget( 2, inputC );
-    mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
-                              controls );
-    settings->endGroup();
+
+    setMinimalView( b_minimalView );
 }
 
-void MainInterface::createMainWidget( QSettings *settings )
+void MainInterface::reloadPrefs()
+{
+    i_notificationSetting = var_InheritInteger( p_intf, "qt-notification" );
+    b_pauseOnMinimize = var_InheritBool( p_intf, "qt-pause-minimized" );
+#ifdef WIN32
+    p_intf->p_sys->disable_volume_keys = var_InheritBool( p_intf, "qt-disable-volume-keys" );
+#endif
+    if( !var_InheritBool( p_intf, "qt-fs-controller" ) && fullscreenControls )
+    {
+        delete fullscreenControls;
+        fullscreenControls = NULL;
+    }
+}
+
+void MainInterface::createMainWidget( QSettings *creationSettings )
 {
     /* Create the main Widget and the mainLayout */
     QWidget *main = new QWidget;
@@ -380,7 +382,15 @@ void MainInterface::createMainWidget( QSettings *settings )
     stackCentralW = new QVLCStackedWidget( main );
 
     /* Bg Cone */
-    bgWidget = new BackgroundWidget( p_intf );
+    if ( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY
+         && var_InheritBool( p_intf, "qt-icon-change" ) )
+    {
+        bgWidget = new EasterEggBackgroundWidget( p_intf );
+        CONNECT( this, kc_pressed(), bgWidget, animate() );
+    }
+    else
+        bgWidget = new BackgroundWidget( p_intf );
+
     stackCentralW->addWidget( bgWidget );
     if ( !var_InheritBool( p_intf, "qt-bgcone" ) )
         bgWidget->setWithArt( false );
@@ -396,19 +406,20 @@ void MainInterface::createMainWidget( QSettings *settings )
     }
     mainLayout->insertWidget( 1, stackCentralW );
 
-    settings->beginGroup( "MainWindow" );
-    stackWidgetsSizes[bgWidget] = settings->value( "bgSize", QSize( 400, 0 ) ).toSize();
+    stackWidgetsSizes[bgWidget] =
+        creationSettings->value( "MainWindow/bgSize", QSize( 600, 0 ) ).toSize();
     /* Resize even if no-auto-resize, because we are at creation */
     resizeStack( stackWidgetsSizes[bgWidget].width(), stackWidgetsSizes[bgWidget].height() );
 
     /* Create the CONTROLS Widget */
     controls = new ControlsWidget( p_intf,
-                   settings->value( "adv-controls", false ).toBool(), this );
+        creationSettings->value( "MainWindow/adv-controls", false ).toBool(), this );
     inputC = new InputControlsWidget( p_intf, this );
 
     mainLayout->insertWidget( 2, inputC );
-    mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
-                              controls );
+    mainLayout->insertWidget(
+        creationSettings->value( "MainWindow/ToolbarPos", 0 ).toInt() ? 0: 3,
+        controls );
 
     /* Visualisation, disabled for now, they SUCK */
     #if 0
@@ -417,7 +428,6 @@ void MainInterface::createMainWidget( QSettings *settings )
     visualSelector->hide();
     #endif
 
-    settings->endGroup();
 
     /* Enable the popup menu in the MI */
     main->setContextMenuPolicy( Qt::CustomContextMenu );
@@ -436,7 +446,6 @@ void MainInterface::createMainWidget( QSettings *settings )
 
 inline void MainInterface::initSystray()
 {
-#ifndef HAVE_MAEMO
     bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
     bool b_systrayWanted = var_InheritBool( p_intf, "qt-system-tray" );
 
@@ -453,7 +462,6 @@ inline void MainInterface::initSystray()
 
     if( b_systrayAvailable && b_systrayWanted )
         createSystray();
-#endif
 }
 
 inline void MainInterface::createStatusBar()
@@ -465,7 +473,7 @@ inline void MainInterface::createStatusBar()
     QStatusBar *statusBarr = statusBar();
 
     TimeLabel *timeLabel = new TimeLabel( p_intf );
-    nameLabel = new QLabel( this );
+    nameLabel = new ClickableQLabel();
     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
                                       | Qt::TextSelectableByKeyboard );
     SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
@@ -486,11 +494,12 @@ inline void MainInterface::createStatusBar()
     statusBarr->addPermanentWidget( speedLabel, 0 );
     statusBarr->addPermanentWidget( timeLabel, 0 );
 
+    CONNECT( nameLabel, doubleClicked(), THEDP, epgDialog() );
     /* timeLabel behaviour:
        - double clicking opens the goto time dialog
        - right-clicking and clicking just toggle between remaining and
          elapsed time.*/
-    CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
+    CONNECT( timeLabel, doubleClicked(), THEDP, gotoTimeDialog() );
 
     CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
              this, showCryptedLabel( bool ) );
@@ -530,38 +539,90 @@ inline void MainInterface::restoreStackOldWidget()
 
 inline void MainInterface::showTab( QWidget *widget )
 {
+    if ( !widget ) widget = bgWidget; /* trying to restore a null oldwidget */
 #ifdef DEBUG_INTF
-    msg_Warn( p_intf, "Old stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
+    if ( stackCentralOldWidget )
+        msg_Dbg( p_intf, "Old stackCentralOldWidget %s at index %i",
+                 stackCentralOldWidget->metaObject()->className(),
+                 stackCentralW->indexOf( stackCentralOldWidget ) );
+    msg_Dbg( p_intf, "ShowTab request for %s", widget->metaObject()->className() );
 #endif
+    /* fixing when the playlist has been undocked after being hidden.
+       restoreStackOldWidget() is called when video stops but
+       stackCentralOldWidget would still be pointing to playlist */
+    if ( widget == playlistWidget && !isPlDocked() )
+        widget = bgWidget;
 
     stackCentralOldWidget = stackCentralW->currentWidget();
     stackWidgetsSizes[stackCentralOldWidget] = stackCentralW->size();
 
+    /* If we are playing video, embedded */
+    if( videoWidget && THEMIM->getIM()->hasVideo() )
+    {
+        /* Video -> Playlist */
+        if( videoWidget == stackCentralOldWidget && widget == playlistWidget )
+        {
+            stackCentralW->removeWidget( videoWidget );
+            videoWidget->show(); videoWidget->raise();
+        }
+
+        /* Playlist -> Video */
+        if( playlistWidget == stackCentralOldWidget && widget == videoWidget )
+        {
+            playlistWidget->artContainer->removeWidget( videoWidget );
+            videoWidget->show(); videoWidget->raise();
+            stackCentralW->addWidget( videoWidget );
+        }
+
+        /* Embedded playlist -> Non-embedded playlist */
+        if( bgWidget == stackCentralOldWidget && widget == videoWidget )
+        {
+            /* In rare case when video is started before the interface */
+            if( playlistWidget != NULL )
+                playlistWidget->artContainer->removeWidget( videoWidget );
+            videoWidget->show(); videoWidget->raise();
+            stackCentralW->addWidget( videoWidget );
+            stackCentralW->setCurrentWidget( videoWidget );
+        }
+    }
+
     stackCentralW->setCurrentWidget( widget );
     if( b_autoresize )
         resizeStack( stackWidgetsSizes[widget].width(), stackWidgetsSizes[widget].height() );
 
 #ifdef DEBUG_INTF
-    msg_Warn( p_intf, "State change %i",  stackCentralW->currentIndex() );
-    msg_Warn( p_intf, "New stackCentralOldWidget %i", stackCentralW->indexOf( stackCentralOldWidget ) );
+    msg_Dbg( p_intf, "Stack state changed to %s, index %i",
+              stackCentralW->currentWidget()->metaObject()->className(),
+              stackCentralW->currentIndex() );
+    msg_Dbg( p_intf, "New stackCentralOldWidget %s at index %i",
+              stackCentralOldWidget->metaObject()->className(),
+              stackCentralW->indexOf( stackCentralOldWidget ) );
 #endif
+
+    /* This part is done later, to account for the new pl size */
+    if( videoWidget && THEMIM->getIM()->hasVideo() &&
+        videoWidget == stackCentralOldWidget && widget == playlistWidget )
+    {
+        playlistWidget->artContainer->addWidget( videoWidget );
+        playlistWidget->artContainer->setCurrentWidget( videoWidget );
+    }
 }
 
 void MainInterface::destroyPopupMenu()
 {
-    QVLCMenu::PopupMenu( p_intf, false );
+    VLCMenuBar::PopupMenu( p_intf, false );
 }
 
-void MainInterface::popupMenu( const QPoint &p )
+void MainInterface::popupMenu( const QPoint & )
 {
-    QVLCMenu::PopupMenu( p_intf, true );
+    VLCMenuBar::PopupMenu( p_intf, true );
 }
 
 void MainInterface::toggleFSC()
 {
    if( !fullscreenControls ) return;
 
-   IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
+   IMEvent *eShow = new IMEvent( IMEvent::FullscreenControlToggle );
    QApplication::postEvent( fullscreenControls, eShow );
 }
 
@@ -592,6 +653,10 @@ WId MainInterface::getVideo( int *pi_x, int *pi_y,
 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
                                   unsigned *pi_width, unsigned *pi_height )
 {
+    /* Hidden or minimized, activate */
+    if( isHidden() || isMinimized() )
+        toggleUpdateSystrayMenu();
+
     /* Request the videoWidget */
     WId ret = videoWidget->request( pi_x, pi_y,
                                     pi_width, pi_height, !b_autoresize );
@@ -626,6 +691,12 @@ void MainInterface::releaseVideoSlot( void )
 
     if( stackCentralW->currentWidget() == videoWidget )
         restoreStackOldWidget();
+    else if( playlistWidget &&
+             playlistWidget->artContainer->currentWidget() == videoWidget )
+    {
+        playlistWidget->artContainer->setCurrentIndex( 0 );
+        stackCentralW->addWidget( videoWidget );
+    }
 
     /* We don't want to have a blank video to popup */
     stackCentralOldWidget = bgWidget;
@@ -637,6 +708,12 @@ void MainInterface::setVideoSize( unsigned int w, unsigned int h )
         videoWidget->SetSizing( w, h );
 }
 
+void MainInterface::videoSizeChanged( int w, int h )
+{
+    if( !playlistWidget || playlistWidget->artContainer->currentWidget() != videoWidget )
+        resizeStack( w, h );
+}
+
 void MainInterface::setVideoFullScreen( bool fs )
 {
     b_videoFullScreen = fs;
@@ -658,6 +735,14 @@ void MainInterface::setVideoFullScreen( bool fs )
             msg_Dbg( p_intf, "Moving video to correct screen");
             move( QPoint( screenres.x(), screenres.y() ) );
         }
+
+        /* */
+        if( playlistWidget != NULL && playlistWidget->artContainer->currentWidget() == videoWidget )
+        {
+            showTab( videoWidget );
+        }
+
+        /* */
         setMinimalView( true );
         setInterfaceFullScreen( true );
     }
@@ -675,16 +760,14 @@ void MainInterface::setVideoFullScreen( bool fs )
  * Emit askVideoOnTop() to invoke this from other thread. */
 void MainInterface::setVideoOnTop( bool on_top )
 {
-    b_videoOnTop = on_top;
-
     Qt::WindowFlags oldflags = windowFlags(), newflags;
 
-    if( b_videoOnTop )
+    if( on_top )
         newflags = oldflags | Qt::WindowStaysOnTopHint;
     else
         newflags = oldflags & ~Qt::WindowStaysOnTopHint;
+    if( newflags != oldflags && !b_videoFullScreen )
 
-    if( newflags != oldflags )
     {
         setWindowFlags( newflags );
         show(); /* necessary to apply window flags */
@@ -733,39 +816,31 @@ int MainInterface::controlVideo( int i_query, va_list args )
  **/
 void MainInterface::createPlaylist()
 {
-    playlistWidget = new PlaylistWidget( p_intf, this );
+    PlaylistDialog *dialog = PlaylistDialog::getInstance( p_intf );
 
     if( b_plDocked )
     {
+        playlistWidget = dialog->exportPlaylistWidget();
         stackCentralW->addWidget( playlistWidget );
-        stackWidgetsSizes[playlistWidget] = settings->value( "playlistSize", QSize( 500, 250 ) ).toSize();
-    }
-    else
-    {
-#ifdef WIN32
-        playlistWidget->setParent( NULL );
-#endif
-        playlistWidget->setWindowFlags( Qt::Window );
-
-        /* This will restore the geometry but will not work for position,
-           because of parenting */
-        QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
-                playlistWidget, QSize( 600, 300 ) );
+        stackWidgetsSizes[playlistWidget] = settings->value( "playlistSize", QSize( 600, 300 ) ).toSize();
     }
+    CONNECT( dialog, visibilityChanged(bool), this, setPlaylistVisibility(bool) );
 }
 
 void MainInterface::togglePlaylist()
 {
-    if( !playlistWidget )
-    {
-        createPlaylist();
-    }
+    if( !playlistWidget ) createPlaylist();
 
+    PlaylistDialog *dialog = PlaylistDialog::getInstance( p_intf );
     if( b_plDocked )
     {
+        if ( dialog->hasPlaylistWidget() )
+            playlistWidget = dialog->exportPlaylistWidget();
         /* Playlist is not visible, show it */
         if( stackCentralW->currentWidget() != playlistWidget )
         {
+            if( stackCentralW->indexOf( playlistWidget ) == -1 )
+                stackCentralW->addWidget( playlistWidget );
             showTab( playlistWidget );
         }
         else /* Hide it! */
@@ -776,43 +851,52 @@ void MainInterface::togglePlaylist()
     }
     else
     {
-#ifdef WIN32
-        playlistWidget->setParent( NULL );
-#endif
-        playlistWidget->setWindowFlags( Qt::Window );
         playlistVisible = !playlistVisible;
-        playlistWidget->setVisible( playlistVisible );
+        if ( ! dialog->hasPlaylistWidget() )
+            dialog->importPlaylistWidget( playlistWidget );
+        if ( playlistVisible )
+            dialog->show();
+        else
+            dialog->hide();
     }
     debug();
 }
 
+const Qt::Key MainInterface::kc[10] =
+{
+    Qt::Key_Up, Qt::Key_Up,
+    Qt::Key_Down, Qt::Key_Down,
+    Qt::Key_Left, Qt::Key_Right, Qt::Key_Left, Qt::Key_Right,
+    Qt::Key_B, Qt::Key_A
+};
+
 void MainInterface::dockPlaylist( bool p_docked )
 {
     if( b_plDocked == p_docked ) return;
+    /* some extra check */
+    if ( b_plDocked && !playlistWidget ) createPlaylist();
+
     b_plDocked = p_docked;
+    PlaylistDialog *dialog = PlaylistDialog::getInstance( p_intf );
 
-    if( !playlistWidget ) return; /* Playlist wasn't created yet */
-    if( !p_docked )
+    if( !p_docked ) /* Previously docked */
     {
+        playlistVisible = playlistWidget->isVisible();
         stackCentralW->removeWidget( playlistWidget );
-#ifdef WIN32
-        playlistWidget->setParent( NULL );
-#endif
-        playlistWidget->setWindowFlags( Qt::Window );
-        QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
-                playlistWidget, QSize( 600, 300 ) );
-        playlistWidget->show();
+        dialog->importPlaylistWidget( playlistWidget );
+        if ( playlistVisible ) dialog->show();
         restoreStackOldWidget();
     }
-    else
+    else /* Previously undocked */
     {
-        QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
-        playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here
-        // It would be logical that QStackWidget::addWidget reset the flags...
+        playlistVisible = dialog->isVisible();
+        dialog->hide();
+        playlistWidget = dialog->exportPlaylistWidget();
         stackCentralW->addWidget( playlistWidget );
-        showTab( playlistWidget );
+
+        /* If playlist is invisible don't show it */
+        if( playlistVisible ) showTab( playlistWidget );
     }
-    playlistVisible = true;
 }
 
 /*
@@ -823,7 +907,7 @@ void MainInterface::setMinimalView( bool b_minimal )
 {
     menuBar()->setVisible( !b_minimal );
     controls->setVisible( !b_minimal );
-    statusBar()->setVisible( !b_minimal );
+    statusBar()->setVisible( !b_minimal && b_statusbarVisible );
     inputC->setVisible( !b_minimal );
 }
 
@@ -866,12 +950,27 @@ int MainInterface::getControlsVisibilityStatus()
 {
     if( !controls ) return 0;
     return( (controls->isVisible() ? CONTROLS_VISIBLE : CONTROLS_HIDDEN )
-                + CONTROLS_ADVANCED * controls->b_advancedVisible );
+            + CONTROLS_ADVANCED * controls->b_advancedVisible );
+}
+
+StandardPLPanel *MainInterface::getPlaylistView()
+{
+    if( !playlistWidget ) return NULL;
+    else return playlistWidget->mainView;
 }
 
 void MainInterface::setStatusBarVisibility( bool b_visible )
 {
     statusBar()->setVisible( b_visible );
+    b_statusbarVisible = b_visible;
+    if( controls ) controls->setGripVisible( !b_statusbarVisible );
+}
+
+
+void MainInterface::setPlaylistVisibility( bool b_visible )
+{
+    if ( !isPlDocked() )
+        playlistVisible = b_visible;
 }
 
 #if 0
@@ -946,7 +1045,6 @@ void MainInterface::showBuffering( float f_cache )
 /*****************************************************************************
  * Systray Icon and Systray Menu
  *****************************************************************************/
-#ifndef HAVE_MAEMO
 /**
  * Create a SystemTray icon and a menu that would go with it.
  * Connects to a click handler on the icon.
@@ -964,11 +1062,18 @@ void MainInterface::createSystray()
     systrayMenu = new QMenu( qtr( "VLC media player" ), this );
     systrayMenu->setIcon( iconVLC );
 
-    QVLCMenu::updateSystrayMenu( this, p_intf, true );
+    VLCMenuBar::updateSystrayMenu( this, p_intf, true );
     sysTray->show();
 
     CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
-            this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
+             this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
+
+    /* Connects on nameChanged() */
+    CONNECT( THEMIM->getIM(), nameChanged( const QString& ),
+             this, updateSystrayTooltipName( const QString& ) );
+    /* Connect PLAY_STATUS on the systray */
+    CONNECT( THEMIM->getIM(), playingStatusChanged( int ),
+             this, updateSystrayTooltipStatus( int ) );
 }
 
 /**
@@ -1016,9 +1121,11 @@ void MainInterface::toggleUpdateSystrayMenu()
         hide();
 #endif
     }
-    QVLCMenu::updateSystrayMenu( this, p_intf );
+    if( sysTray )
+        VLCMenuBar::updateSystrayMenu( this, p_intf );
 }
 
+/* First Item of the systray menu */
 void MainInterface::showUpdateSystrayMenu()
 {
     if( isHidden() )
@@ -1027,15 +1134,17 @@ void MainInterface::showUpdateSystrayMenu()
         showNormal();
     activateWindow();
 
-    QVLCMenu::updateSystrayMenu( this, p_intf );
+    VLCMenuBar::updateSystrayMenu( this, p_intf );
 }
 
+/* First Item of the systray menu */
 void MainInterface::hideUpdateSystrayMenu()
 {
     hide();
-    QVLCMenu::updateSystrayMenu( this, p_intf );
+    VLCMenuBar::updateSystrayMenu( this, p_intf );
 }
 
+/* Click on systray Icon */
 void MainInterface::handleSystrayClick(
                                     QSystemTrayIcon::ActivationReason reason )
 {
@@ -1044,7 +1153,7 @@ void MainInterface::handleSystrayClick(
         case QSystemTrayIcon::Trigger:
         case QSystemTrayIcon::DoubleClick:
 #ifdef Q_WS_MAC
-            QVLCMenu::updateSystrayMenu( this, p_intf );
+            VLCMenuBar::updateSystrayMenu( this, p_intf );
 #else
             toggleUpdateSystrayMenu();
 #endif
@@ -1072,14 +1181,15 @@ void MainInterface::updateSystrayTooltipName( const QString& name )
     else
     {
         sysTray->setToolTip( name );
-        if( b_notificationEnabled && ( isHidden() || isMinimized() ) )
+        if( ( i_notificationSetting == NOTIFICATION_ALWAYS ) ||
+            ( i_notificationSetting == NOTIFICATION_MINIMIZED && (isMinimized() || isHidden()) ) )
         {
             sysTray->showMessage( qtr( "VLC media player" ), name,
                     QSystemTrayIcon::NoIcon, 3000 );
         }
     }
 
-    QVLCMenu::updateSystrayMenu( this, p_intf );
+    VLCMenuBar::updateSystrayMenu( this, p_intf );
 }
 
 /**
@@ -1100,9 +1210,8 @@ void MainInterface::updateSystrayTooltipStatus( int i_status )
         sysTray->setToolTip( qtr( "VLC media player" ) );
         break;
     }
-    QVLCMenu::updateSystrayMenu( this, p_intf );
+    VLCMenuBar::updateSystrayMenu( this, p_intf );
 }
-#endif
 
 void MainInterface::changeEvent(QEvent *event)
 {
@@ -1117,9 +1226,8 @@ void MainInterface::changeEvent(QEvent *event)
             b_hasPausedWhenMinimized = false;
 
             if( THEMIM->getIM()->playingStatus() == PLAYING_S &&
-                THEMIM->getIM()->hasVideo() &&
-                !THEMIM->getIM()->hasVisualisation() &&
-                var_InheritBool( p_intf, "qt-pause-minimized" ) )
+                THEMIM->getIM()->hasVideo() && !THEMIM->getIM()->hasVisualisation() &&
+                b_pauseOnMinimize )
             {
                 b_hasPausedWhenMinimized = true;
                 THEMIM->pause();
@@ -1145,9 +1253,18 @@ void MainInterface::dropEvent(QDropEvent *event)
     dropEventPlay( event, true );
 }
 
-void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
+/**
+ * dropEventPlay
+ *
+ * Event called if something is dropped onto a VLC window
+ * \param event the event in question
+ * \param b_play whether to play the file immediately
+ * \param b_playlist true to add to playlist, false to add to media library
+ * \return nothing
+ */
+void MainInterface::dropEventPlay( QDropEvent *event, bool b_play, bool b_playlist )
 {
-    if( event->possibleActions() & Qt::CopyAction )
+    if( event->possibleActions() & ( Qt::CopyAction | Qt::MoveAction | Qt::LinkAction ) )
        event->setDropAction( Qt::CopyAction );
     else
         return;
@@ -1155,7 +1272,7 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
     const QMimeData *mimeData = event->mimeData();
 
     /* D&D of a subtitles file, add it on the fly */
-    if( mimeData->urls().size() == 1 && THEMIM->getIM()->hasInput() )
+    if( mimeData->urls().count() == 1 && THEMIM->getIM()->hasInput() )
     {
         if( !input_AddSubtitle( THEMIM->getInput(),
                  qtu( toNativeSeparators( mimeData->urls()[0].toLocalFile() ) ),
@@ -1172,11 +1289,29 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
         if( url.isValid() )
         {
             QString mrl = toURI( url.toEncoded().constData() );
-            playlist_Add( THEPL, qtu(mrl), NULL,
+            QFileInfo info( url.toLocalFile() );
+            if( info.exists() && info.isSymLink() )
+            {
+                QString target = info.symLinkTarget();
+                QUrl url;
+                if( QFile::exists( target ) )
+                {
+                    url = QUrl::fromLocalFile( target );
+                }
+                else
+                {
+                    url.setUrl( target );
+                }
+                mrl = toURI( url.toEncoded().constData() );
+            }
+            if( mrl.length() > 0 )
+            {
+                playlist_Add( THEPL, qtu(mrl), NULL,
                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
-                          PLAYLIST_END, true, pl_Unlocked );
-            first = false;
-            RecentsMRL::getInstance( p_intf )->addRecent( url.toString() );
+                          PLAYLIST_END, b_playlist, pl_Unlocked );
+                first = false;
+                RecentsMRL::getInstance( p_intf )->addRecent( mrl );
+            }
         }
     }
 
@@ -1189,7 +1324,7 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
         QString mrl = toURI( mimeData->text() );
         playlist_Add( THEPL, qtu(mrl), NULL,
                       PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
-                      PLAYLIST_END, true, pl_Unlocked );
+                      PLAYLIST_END, b_playlist, pl_Unlocked );
     }
     event->accept();
 }
@@ -1212,11 +1347,24 @@ void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
 void MainInterface::keyPressEvent( QKeyEvent *e )
 {
     handleKeyPress( e );
+
+    /* easter eggs sequence handling */
+    if ( e->key() == kc[ i_kc_offset ] )
+        i_kc_offset++;
+    else
+        i_kc_offset = 0;
+
+    if ( i_kc_offset == (sizeof( kc ) / sizeof( Qt::Key )) )
+    {
+        i_kc_offset = 0;
+        emit kc_pressed();
+    }
 }
 
 void MainInterface::handleKeyPress( QKeyEvent *e )
 {
-    if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H ) )
+    if( ( ( e->modifiers() & Qt::ControlModifier ) && ( e->key() == Qt::Key_H ) ) ||
+        ( b_minimalView && !b_videoFullScreen && e->key() == Qt::Key_Escape ) )
     {
         toggleMinimalView( !b_minimalView );
         e->accept();
@@ -1241,9 +1389,26 @@ void MainInterface::wheelEvent( QWheelEvent *e )
 
 void MainInterface::closeEvent( QCloseEvent *e )
 {
-    e->ignore();      /* Do not quit */
 //  hide();
     emit askToQuit(); /* ask THEDP to quit, so we have a unique method */
+    /* Accept session quit. Otherwise we break the desktop mamager. */
+    e->accept();
+}
+
+bool MainInterface::eventFilter( QObject *obj, QEvent *event )
+{
+    if ( event->type() == MainInterface::ToolbarsNeedRebuild ) {
+        event->accept();
+        recreateToolbars();
+        return true;
+    } else {
+        return QObject::eventFilter( obj, event );
+    }
+}
+
+void MainInterface::toolBarConfUpdated()
+{
+    QApplication::postEvent( this, new QEvent( MainInterface::ToolbarsNeedRebuild ) );
 }
 
 void MainInterface::setInterfaceFullScreen( bool fs )
@@ -1261,6 +1426,33 @@ void MainInterface::toggleInterfaceFullScreen()
     emit fullscreenInterfaceToggled( b_interfaceFullScreen );
 }
 
+void MainInterface::emitBoss()
+{
+    emit askBoss();
+}
+void MainInterface::setBoss()
+{
+    THEMIM->pause();
+    if( sysTray )
+    {
+        hide();
+    }
+    else
+    {
+        showMinimized();
+    }
+}
+
+void MainInterface::emitRaise()
+{
+    emit askRaise();
+}
+void MainInterface::setRaise()
+{
+    activateWindow();
+    raise();
+}
+
 /*****************************************************************************
  * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
  *  We don't show the menu directly here because we don't want the
@@ -1269,6 +1461,8 @@ void MainInterface::toggleInterfaceFullScreen()
 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
                         vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_variable ); VLC_UNUSED( old_val );
+
     intf_thread_t *p_intf = (intf_thread_t *)param;
 
     if( p_intf->pf_show_dialog )
@@ -1281,14 +1475,47 @@ static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
 }
 
 /*****************************************************************************
- * IntfShowCB: callback triggered by the intf-show libvlc variable.
+ * IntfShowCB: callback triggered by the intf-toggle-fscontrol libvlc variable.
  *****************************************************************************/
 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_variable ); VLC_UNUSED( old_val );
+    VLC_UNUSED( new_val );
+
     intf_thread_t *p_intf = (intf_thread_t *)param;
     p_intf->p_sys->p_mi->toggleFSC();
 
     /* Show event */
      return VLC_SUCCESS;
 }
+
+/*****************************************************************************
+ * IntfRaiseMainCB: callback triggered by the intf-show-main libvlc variable.
+ *****************************************************************************/
+static int IntfRaiseMainCB( vlc_object_t *p_this, const char *psz_variable,
+                       vlc_value_t old_val, vlc_value_t new_val, void *param )
+{
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_variable ); VLC_UNUSED( old_val );
+    VLC_UNUSED( new_val );
+
+    intf_thread_t *p_intf = (intf_thread_t *)param;
+    p_intf->p_sys->p_mi->emitRaise();
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * IntfBossCB: callback triggered by the intf-boss libvlc variable.
+ *****************************************************************************/
+static int IntfBossCB( vlc_object_t *p_this, const char *psz_variable,
+                       vlc_value_t old_val, vlc_value_t new_val, void *param )
+{
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_variable ); VLC_UNUSED( old_val );
+    VLC_UNUSED( new_val );
+
+    intf_thread_t *p_intf = (intf_thread_t *)param;
+    p_intf->p_sys->p_mi->emitBoss();
+
+    return VLC_SUCCESS;
+}