From 39912d87d5982a40d5fd3633da12568d160b67c7 Mon Sep 17 00:00:00 2001 From: mio Date: Sun, 6 Oct 2024 10:41:24 +1000 Subject: Fix channel selection menus disappearing When adding/removing an action to/from the toolbar, the aspect ratio, audio channel, and subtitle channel menus would disappear from the parent settings menu. My understanding is that this happened because nothing was keeping those menus present (plugged?) when other actions were plugged/unplugged. This changes it so "Aspect Ratio", "Subtitles", and "Audio Channels" each are a TDESelectAction that is dynamically filled with items. This way, each popup menu is still present after other actions being plugged/unplugged. Resolves: TDE/codeine#24 Signed-off-by: mio (cherry picked from commit f460840a5e1c4e6cc262177f2b60cebfe469d393) --- src/app/mainWindow.cpp | 138 ++++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 64 deletions(-) (limited to 'src/app/mainWindow.cpp') diff --git a/src/app/mainWindow.cpp b/src/app/mainWindow.cpp index 159d84c..9409d85 100644 --- a/src/app/mainWindow.cpp +++ b/src/app/mainWindow.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include //::stateChanged() #include //ctor #include //because XMLGUI is poorly designed @@ -48,6 +47,9 @@ extern "C" } #endif +constexpr auto kAspectSelectActionName = "aspect_ratio_select"; +constexpr auto kAudioSelectActionName = "audio_channels_select"; +constexpr auto kSubtitleSelectActionName = "subtitle_channels_select"; namespace Codeine { @@ -116,27 +118,27 @@ MainWindow::MainWindow() } { - TQPopupMenu *menu = nullptr; - TQPopupMenu *settings = static_cast(factory()->container( "settings", this )); - int id = SubtitleChannelsMenuItemId, index = 0; - - #define make_menu( name, text ) \ - menu = new TQPopupMenu( this, name ); \ - menu->setCheckable( true ); \ - connect( menu, TQ_SIGNAL(activated( int )), engine(), TQ_SLOT(setStreamParameter( int )) ); \ - connect( menu, TQ_SIGNAL(aboutToShow()), TQ_SLOT(aboutToShowMenu()) ); \ - settings->insertItem( text, menu, id, index ); \ - settings->setItemEnabled( id, false ); \ - id++, index++; - - make_menu( "subtitle_channels_menu", i18n( "&Subtitles" ) ); - make_menu( "audio_channels_menu", i18n( "A&udio Channels" ) ); - make_menu( "aspect_ratio_menu", i18n( "Aspect &Ratio" ) ); - #undef make_menu - - Codeine::insertAspectRatioMenuItems( menu ); //so we don't have to include xine.h here - - settings->insertSeparator( index ); + /* Disable aspect/channel menus until the stream has loaded; + * Make sure they have the same default item selected. */ + TQStringList defaultItems("&Determine Automatically"); + if (const auto aspectAction = dynamic_cast(action(kAspectSelectActionName))) + { + aspectAction->setToolTip(i18n("Aspect Ratio")); + insertAspectRatioMenuItems(aspectAction); + aspectAction->setEnabled(false); + } + if (const auto audioChannelAction = dynamic_cast(action(kAudioSelectActionName))) + { + audioChannelAction->setToolTip(i18n("Audio Channels")); + audioChannelAction->setItems(defaultItems); + audioChannelAction->setEnabled(false); + } + if (const auto subChannelAction = dynamic_cast(action(kSubtitleSelectActionName))) + { + subChannelAction->setToolTip(i18n("Subtitles")); + subChannelAction->setItems(defaultItems); + subChannelAction->setEnabled(false); + } } TQObjectList *list = toolBar()->queryList( "TDEToolBarButton" ); @@ -171,10 +173,14 @@ MainWindow::init() connect( engine(), TQ_SIGNAL(statusMessage( const TQString& )), this, TQ_SLOT(engineMessage( const TQString& )) ); connect( engine(), TQ_SIGNAL(stateChanged( Engine::State )), this, TQ_SLOT(engineStateChanged( Engine::State )) ); - connect( engine(), TQ_SIGNAL(channelsChanged( const TQStringList& )), this, TQ_SLOT(setChannels( const TQStringList& )) ); connect( engine(), TQ_SIGNAL(titleChanged( const TQString& )), m_titleLabel, TQ_SLOT(setText( const TQString& )) ); connect( m_positionSlider, TQ_SIGNAL(valueChanged( int )), this, TQ_SLOT(showTime( int )) ); + connect(engine(), TQ_SIGNAL(audioChannelsChanged(const TQStringList &)), + this, TQ_SLOT(setAudioChannels(const TQStringList &))); + connect(engine(), TQ_SIGNAL(subtitleChannelsChanged(const TQStringList &)), + this, TQ_SLOT(setSubtitleChannels(const TQStringList &))); + if( !engine()->init() ) { KMessageBox::error( this, i18n( "xine could not be successfully initialised. " PRETTY_NAME " will now exit. " @@ -266,6 +272,15 @@ MainWindow::setupActions() (new KWidgetAction( m_positionSlider, i18n("Position Slider"), nullptr, nullptr, nullptr, ac, "position_slider" ))->setAutoSized( true ); + const auto audioSelectAction = new TDESelectAction(i18n("A&udio Channels"), 0, ac, kAudioSelectActionName); + connect(audioSelectAction, TQ_SIGNAL(activated(int)), engine(), TQ_SLOT(setStreamParameter(int))); + + const auto subSelectAction = new TDESelectAction(i18n("&Subtitles"), 0, ac, kSubtitleSelectActionName); + connect(subSelectAction, TQ_SIGNAL(activated(int)), engine(), TQ_SLOT(setStreamParameter(int))); + + const auto aspectSelectAction = new TDESelectAction(i18n("Aspect &Ratio"), 0, ac, kAspectSelectActionName); + connect(aspectSelectAction, TQ_SIGNAL(activated(int)), engine(), TQ_SLOT(setStreamParameter(int))); + m_volumeAction = new VolumeAction( toolBar(), ac ); } @@ -594,54 +609,49 @@ MainWindow::streamInformation() } void -MainWindow::setChannels( const TQStringList &channels ) +MainWindow::setAudioChannels(const TQStringList &channels) const { DEBUG_FUNC_INFO - //TODO -1 = auto - - TQStringList::ConstIterator it = channels.begin(); - - TQPopupMenu *menu = (TQPopupMenu*)child( (*it).latin1() ); - menu->clear(); - - menu->insertItem( i18n("&Determine Automatically"), 1 ); - menu->insertSeparator(); - - //the id is crucial, since the slot this menu is connected to requires - //that information to set the correct channel - //NOTE we subtract 2 in xineEngine because TQMenuData doesn't allow negative id - int id = 2; - ++it; - for( TQStringList::ConstIterator const end = channels.end(); it != end; ++it, ++id ) - menu->insertItem( *it, id ); + /* Xine uses -1 and -2 to indicate that a channel should be determined automatically or + * turned off. TDESelectAction inserts items starting from index 0, so we add 2 to the + * channel returned from TheStream to match. */ - menu->insertSeparator(); - menu->insertItem( i18n("&Off"), 0 ); - - id = channels.first() == "subtitle_channels_menu" ? SubtitleChannelsMenuItemId : AudioChannelsMenuItemId; - MainWindow::menu( "settings" )->setItemEnabled( id, channels.count() > 1 ); + if (const auto audioSelection = dynamic_cast(action(kAudioSelectActionName))) + { + TQStringList audioChannels(channels); + audioChannels.prepend("&Determine Automatically"); + audioChannels.prepend("&Off"); + audioSelection->setItems(audioChannels); + audioSelection->popupMenu()->insertSeparator(2); + audioSelection->setCurrentItem(TheStream::audioChannel() + 2); + audioSelection->setEnabled(channels.count()); + } + else + { + Debug::error() << "Failed to update the audio channels (selection menu not found)" << endl; + } } void -MainWindow::aboutToShowMenu() +MainWindow::setSubtitleChannels(const TQStringList &channels) const { - TQPopupMenu *menu = (TQPopupMenu*)sender(); - TQCString name( sender() ? sender()->name() : nullptr ); - - // uncheck all items first - for( uint x = 0; x < menu->count(); ++x ) - menu->setItemChecked( menu->idAt( x ), false ); - - int id; - if( name == "subtitle_channels_menu" ) - id = TheStream::subtitleChannel() + 2; - else if( name == "audio_channels_menu" ) - id = TheStream::audioChannel() + 2; - else - id = TheStream::aspectRatio(); + DEBUG_FUNC_INFO - menu->setItemChecked( id, true ); + if (const auto subSelection = dynamic_cast(action(kSubtitleSelectActionName))) + { + TQStringList subChannels(channels); + subChannels.prepend("&Determine Automatically"); + subChannels.prepend("&Off"); + subSelection->setItems(subChannels); + subSelection->popupMenu()->insertSeparator(2); + subSelection->setCurrentItem(TheStream::subtitleChannel() + 2); + subSelection->setEnabled(channels.count()); + } + else + { + Debug::error() << "Failed to update the subtitle channels (selection menu not found)" << endl; + } } void @@ -682,10 +692,10 @@ MainWindow::keyPressEvent( TQKeyEvent *e ) } TQPopupMenu* -MainWindow::menu( const char *name ) +MainWindow::menu( const TQString& name ) { // KXMLGUI is "really good". - return static_cast(factory()->container( name, this )); + return dynamic_cast(factory()->container( name, this )); } -- cgit v1.2.3