]> git.sesse.net Git - vlc/commitdiff
Qt: allow loop/repeat button to be in a toolbar (part 2)
authorJean-Baptiste Kempf <jb@videolan.org>
Sun, 29 Nov 2009 22:16:16 +0000 (23:16 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 4 Dec 2009 06:21:39 +0000 (07:21 +0100)
Action and states consistency

modules/gui/qt4/components/controller.cpp
modules/gui/qt4/components/controller_widget.cpp
modules/gui/qt4/components/controller_widget.hpp
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/input_manager.hpp

index 4c5ffc061c13b8b2329d3c9c5bec35bdd06685ec..0f688bef6bc8963dba44b05bb59ada3e1d1e767f 100644 (file)
@@ -372,6 +372,10 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
         setupButton( loopButton );
         loopButton->setToolTip( qtr( "Click to toggle between loop one, loop all" ) );
         loopButton->setCheckable( true );
+        loopButton->updateIcons( NORMAL );
+        CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateIcons( int ) );
+        CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
+        widget = loopButton;
         }
         break;
     default:
index c7746acfc44c0525a9c455a952ba8cdae238b128..aa377bacdd6f19baefab36ac29b66644092b82f0 100644 (file)
@@ -235,22 +235,9 @@ void AtoB_Button::setIcons( bool timeA, bool timeB )
     }
 }
 
-void LoopButton::update()
+void LoopButton::updateIcons( int value )
 {
-/*    if( model->hasRepeat() )
-    {
-        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
-        repeatButton->setChecked( true );
-    }
-    else if( model->hasLoop() )
-    {
-        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
-        repeatButton->setChecked( true );
-    }
-    else
-    {
-        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
-        repeatButton->setChecked( false );
-    }*/
-    //BUTTONACT( repeatButton, toggleRepeat() );
+    setChecked( value != NORMAL );
+    setIcon( ( value == REPEAT_ALL ) ? QIcon( ":/buttons/playlist/repeat_all" )
+                                     : QIcon( ":/buttons/playlist/repeat_one" ) );
 }
index 092730be1b6c0cd34ec09fe53c63d59cfa71e9ad..9714c0561676493187b3395e7335c078079b1f5b 100644 (file)
@@ -56,8 +56,8 @@ private slots:
 class LoopButton : public QToolButton
 {
     Q_OBJECT
-private slots:
-    void update();
+public slots:
+    void updateIcons( int );
 };
 
 class AtoB_Button : public QToolButton
index 7f65ff0d5578f119108f117c19bacd15317f2f44..177b0b1af50bcf4185f26466fd15c12d02bce8f8 100644 (file)
@@ -48,6 +48,10 @@ static int VolumeChanged( vlc_object_t *, const char *,
 
 static int RandomChanged( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
+static int LoopChanged( vlc_object_t *, const char *,
+                        vlc_value_t, vlc_value_t, void * );
+static int RepeatChanged( vlc_object_t *, const char *,
+                        vlc_value_t, vlc_value_t, void * );
 
 
 static int InputEvent( vlc_object_t *, const char *,
@@ -893,6 +897,8 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
     var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
     var_AddCallback( THEPL, "random", RandomChanged, this );
+    var_AddCallback( THEPL, "repeat", RepeatChanged, this );
+    var_AddCallback( THEPL, "loop", LoopChanged, this );
 
     var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
 
@@ -932,6 +938,10 @@ MainInputManager::~MainInputManager()
     var_DelCallback( THEPL, "item-current", PLItemChanged, this );
     var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
     var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
+    var_DelCallback( THEPL, "random", RandomChanged, this );
+    var_DelCallback( THEPL, "repeat", RepeatChanged, this );
+    var_DelCallback( THEPL, "loop", LoopChanged, this );
+
 }
 
 vout_thread_t* MainInputManager::getVout()
@@ -967,6 +977,10 @@ void MainInputManager::customEvent( QEvent *event )
     case RandomChanged_Type:
         emit randomChanged( var_GetBool( THEPL, "random" ) );
         return;
+    case LoopChanged_Type:
+    case RepeatChanged_Type:
+        notifyRepeatLoop();
+        return;
     default:
         if( type != ItemChanged_Type ) return;
     }
@@ -1042,6 +1056,28 @@ void MainInputManager::toggleRandom()
     var_ToggleBool( THEPL, "random" );
 }
 
+void MainInputManager::notifyRepeatLoop()
+{
+    int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ONE
+              + var_GetBool( THEPL, "repeat" ) * REPEAT_ALL;
+
+    emit repeatLoopChanged( i_value );
+}
+
+void MainInputManager::loopRepeatLoopStatus()
+{
+    /* Toggle Normal -> Loop -> Repeat -> Normal ... */
+    if( var_GetBool( THEPL, "repeat" ) )
+        var_SetBool( THEPL, "repeat", false );
+    else if( var_GetBool( THEPL, "loop" ) )
+    {
+        var_SetBool( THEPL, "loop", false );
+        var_SetBool( THEPL, "repeat", true );
+    }
+    else
+        var_SetBool( THEPL, "loop", true );
+}
+
 void MainInputManager::activatePlayQuit( bool b_exit )
 {
     var_SetBool( THEPL, "play-and-exit", b_exit );
@@ -1097,3 +1133,24 @@ static int RandomChanged
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
+
+/* Probably could be merged with next callback */
+static int LoopChanged
+( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
+{
+    MainInputManager *mim = static_cast<MainInputManager*>(data);
+
+    IMEvent *event = new IMEvent( LoopChanged_Type );
+    QApplication::postEvent( mim, event );
+    return VLC_SUCCESS;
+}
+
+static int RepeatChanged
+( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
+{
+    MainInputManager *mim = static_cast<MainInputManager*>(data);
+
+    IMEvent *event = new IMEvent( RepeatChanged_Type );
+    QApplication::postEvent( mim, event );
+    return VLC_SUCCESS;
+}
index 98f5c1d86d197dca959615320737eab835b007d0..03a7f358eb825c5df4b9882800f432f05ae2421e 100644 (file)
@@ -58,6 +58,8 @@ enum {
     RecordingEvent_Type,
     ProgramChanged_Type,
     RandomChanged_Type,
+    LoopChanged_Type,
+    RepeatChanged_Type,
 /*    SignalChanged_Type, */
 
     FullscreenControlToggle_Type = QEvent::User + IMEventType + 20,
@@ -66,6 +68,11 @@ enum {
     FullscreenControlPlanHide_Type,
 };
 
+enum { NORMAL,    /* loop: 0, repeat: 0 */
+       REPEAT_ONE,/* loop: 1, repeat: 0 */
+       REPEAT_ALL,/* loop: 0, repeat: 1 */
+};
+
 class IMEvent : public QEvent
 {
 friend class InputManager;
@@ -257,6 +264,7 @@ private:
     input_thread_t          *p_input;
     intf_thread_t           *p_intf;
 
+    void notifyRepeatLoop();
 public slots:
     void togglePlayPause();
     void toggleRandom();
@@ -265,12 +273,15 @@ public slots:
     void prev();
     void activatePlayQuit( bool );
 
+    void loopRepeatLoopStatus();
+
 signals:
     void inputChanged( input_thread_t * );
     void volumeChanged();
     void playlistItemAppended( int itemId, int parentId );
     void playlistItemRemoved( int itemId );
     void randomChanged( bool );
+    void repeatLoopChanged( int );
 };
 
 #endif