@ -11,6 +11,7 @@
# include <kcursor.h>
# include <tdefiledialog.h> //::open()
# include <tdeglobalsettings.h> //::timerEvent()
# include <tdepopupmenu.h>
# include <tdeio/netaccess.h>
# include <ksqueezedtextlabel.h>
# include <kstatusbar.h>
@ -18,16 +19,17 @@
# include <kurldrag.h>
# include <twin.h>
# include <tqcstring.h>
# include <tqdesktopwidget.h>
# include <tqevent.h> //::stateChanged()
# include <tqlayout.h> //ctor
# include <tqpopupmenu.h> //because XMLGUI is poorly designed
# include <tqobjectlist.h>
# include <tqwidgetstack.h>
# include "../debug.h"
# include "../mxcl.library.h"
# include "actions.h"
# include "analyzer.h"
# include "audioView.h"
# include "codeineConfig.h"
# include "extern.h" //dialog creation function definitions
# include "fullScreenAction.h"
@ -48,12 +50,15 @@ extern "C"
}
# endif
constexpr auto kAspectSelectActionName = " aspect_ratio_select " ;
constexpr auto kAudioSelectActionName = " audio_channels_select " ;
constexpr auto kSubtitleSelectActionName = " subtitle_channels_select " ;
namespace Codeine {
/// @see codeine.h
TQWidget * mainWindow ( ) { return ka pp- > mainWidget ( ) ; }
TQWidget * mainWindow ( ) { return tdeA pp- > mainWidget ( ) ; }
MainWindow : : MainWindow ( )
@ -66,10 +71,21 @@ MainWindow::MainWindow()
clearWFlags ( WDestructiveClose ) ; //we are allocated on the stack
kapp - > setMainWidget ( this ) ;
tdeApp - > setMainWidget ( this ) ;
m_widgetStack = new TQWidgetStack ( this , " m_widgetStack " ) ;
new VideoWindow ( this ) ;
setCentralWidget ( videoWindow ( ) ) ;
m_audioView = new AudioView ( this , " m_audioView " ) ;
// videoWindow() will be the initial widget.
// m_audioView is raised when no video track is present.
m_widgetStack - > addWidget ( videoWindow ( ) ) ;
m_widgetStack - > addWidget ( m_audioView ) ;
setCentralWidget ( m_widgetStack ) ;
setFocusProxy ( videoWindow ( ) ) ; // essential! See VideoWindow::event(), TQEvent::FocusOut
// these have no affect beccause "KDE Knows Best" FFS
@ -93,6 +109,9 @@ MainWindow::MainWindow()
setStandardToolBarMenuEnabled ( false ) ; //bah to setupGUI()!
toolBar ( ) - > show ( ) ; //it's possible it would be hidden, but we don't want that as no UI way to show it!
m_showAnalyzer = config ( " MainWindow " ) - > readBoolEntry ( " showAnalyzer " , true ) ;
m_analyzer - > setShown ( m_showAnalyzer ) ;
// only show dvd button when playing a dvd
{
struct KdeIsTehSuck : public TQObject
@ -116,26 +135,27 @@ MainWindow::MainWindow()
}
{
TQPopupMenu * menu = 0 , * settings = static_cast < TQPopupMenu * > ( factory ( ) - > container ( " settings " , this ) ) ;
int id = SubtitleChannelsMenuItemId , index = 0 ;
# define make_menu( name, text ) \
menu = new TQPopupMenu ( this , name ) ; \
menu - > setCheckable ( true ) ; \
connect ( menu , SIGNAL ( activated ( int ) ) , engine ( ) , SLOT ( setStreamParameter ( int ) ) ) ; \
connect ( menu , SIGNAL ( aboutToShow ( ) ) , 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 < TDESelectAction * > ( action ( kAspectSelectActionName ) ) )
{
aspectAction - > setToolTip ( i18n ( " Aspect Ratio " ) ) ;
insertAspectRatioMenuItems ( aspectAction ) ;
aspectAction - > setEnabled ( false ) ;
}
if ( const auto audioChannelAction = dynamic_cast < TDESelectAction * > ( action ( kAudioSelectActionName ) ) )
{
audioChannelAction - > setToolTip ( i18n ( " Audio Channels " ) ) ;
audioChannelAction - > setItems ( defaultItems ) ;
audioChannelAction - > setEnabled ( false ) ;
}
if ( const auto subChannelAction = dynamic_cast < TDESelectAction * > ( action ( kSubtitleSelectActionName ) ) )
{
subChannelAction - > setToolTip ( i18n ( " Subtitles " ) ) ;
subChannelAction - > setItems ( defaultItems ) ;
subChannelAction - > setEnabled ( false ) ;
}
}
TQObjectList * list = toolBar ( ) - > queryList ( " TDEToolBarButton " ) ;
@ -153,13 +173,13 @@ MainWindow::MainWindow()
KXMLGUIClient : : stateChanged ( " empty " ) ;
TDECmdLineArgs * args = TDECmdLineArgs : : parsedArgs ( ) ;
if ( args - > count ( ) | | args - > isSet ( " play-dvd " ) | | ka pp- > isRestored ( ) )
if ( args - > count ( ) | | args - > isSet ( " play-dvd " ) | | tdeA pp- > isRestored ( ) )
//we need to resize the window, so we can't show the window yet
init ( ) ;
else {
//"faster" startup
//TODO if we have a size stored for this video, do the "faster" route
TQTimer : : singleShot ( 0 , this , SLOT( init ( ) ) ) ;
TQTimer : : singleShot ( 0 , this , TQ_ SLOT( init ( ) ) ) ;
TQApplication : : setOverrideCursor ( KCursor : : waitCursor ( ) ) ; }
}
@ -168,11 +188,15 @@ MainWindow::init()
{
DEBUG_BLOCK
connect ( engine ( ) , SIGNAL ( statusMessage ( const TQString & ) ) , this , SLOT ( engineMessage ( const TQString & ) ) ) ;
connect ( engine ( ) , SIGNAL ( stateChanged ( Engine : : State ) ) , this , SLOT ( engineStateChanged ( Engine : : State ) ) ) ;
connect ( engine ( ) , SIGNAL ( channelsChanged ( const TQStringList & ) ) , this , SLOT ( setChannels ( const TQStringList & ) ) ) ;
connect ( engine ( ) , SIGNAL ( titleChanged ( const TQString & ) ) , m_titleLabel , SLOT ( setText ( const TQString & ) ) ) ;
connect ( m_positionSlider , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( showTime ( int ) ) ) ;
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 ( 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 (
@ -183,12 +207,12 @@ MainWindow::init()
//would be dangerous for these to65535 happen before the videoWindow() is initialised
setAcceptDrops ( true ) ;
connect ( m_positionSlider , SIGNAL( sliderReleased ( uint ) ) , engine ( ) , SLOT( seek ( uint ) ) ) ;
connect ( statusBar ( ) , SIGNAL( messageChanged ( const TQString & ) ) , engine ( ) , SLOT( showOSD ( const TQString & ) ) ) ;
connect ( m_positionSlider , TQ_ SIGNAL( sliderReleased ( uint ) ) , engine ( ) , TQ_ SLOT( seek ( uint ) ) ) ;
connect ( statusBar ( ) , TQ_ SIGNAL( messageChanged ( const TQString & ) ) , engine ( ) , TQ_ SLOT( showOSD ( const TQString & ) ) ) ;
TQApplication : : restoreOverrideCursor ( ) ;
if ( ! ka pp- > isRestored ( ) ) {
if ( ! tdeA pp- > isRestored ( ) ) {
TDECmdLineArgs & args = * TDECmdLineArgs : : parsedArgs ( ) ;
if ( args . isSet ( " play-dvd " ) )
open ( " dvd:/ " ) ;
@ -221,6 +245,9 @@ MainWindow::~MainWindow()
bool
MainWindow : : queryExit ( )
{
config ( " MainWindow " ) - > writeEntry ( " showAnalyzer " , m_showAnalyzer ) ;
config ( " MainWindow " ) - > sync ( ) ;
if ( toggleAction ( " fullscreen " ) - > isChecked ( ) ) {
// there seems to be no other way to stop TDEMainWindow
// saving the window state without any controls
@ -246,26 +273,35 @@ MainWindow::setupActions()
TDEActionCollection * const ac = actionCollection ( ) ;
KStdAction : : quit ( kapp , SLOT ( quit ( ) ) , ac ) ;
KStdAction : : open ( this , SLOT ( playMedia ( ) ) , ac , " play_media " ) - > setText ( i18n ( " Play &Media... " ) ) ;
connect ( new FullScreenAction ( this , ac ) , SIGNAL ( toggled ( bool ) ) , SLOT ( fullScreenToggled ( bool ) ) ) ;
KStdAction : : quit ( tdeApp , TQ_SLOT ( quit ( ) ) , ac ) ;
KStdAction : : open ( this , TQ_SLOT ( playMedia ( ) ) , ac , " play_media " ) - > setText ( i18n ( " Play &Media... " ) ) ;
connect ( new FullScreenAction ( this , ac ) , TQ_SIGNAL ( toggled ( bool ) ) , TQ_SLOT ( fullScreenToggled ( bool ) ) ) ;
new PlayAction ( this , TQ_SLOT ( play ( ) ) , ac ) ;
new TDEAction ( i18n ( " Stop " ) , " media-playback-stop " , Key_S , engine ( ) , TQ_SLOT ( stop ( ) ) , ac , " stop " ) ;
new TDEToggleAction ( i18n ( " Record " ) , " player_record " , CTRL + Key_R , engine ( ) , TQ_SLOT ( record ( ) ) , ac , " record " ) ;
new TDEAction ( i18n ( " Reset Video Scale " ) , " viewmag1 " , Key_Equal , videoWindow ( ) , TQ_SLOT ( resetZoom ( ) ) , ac , " reset_zoom " ) ;
new TDEAction ( i18n ( " Media Information " ) , " messagebox_info " , Key_I , this , TQ_SLOT ( streamInformation ( ) ) , ac , " information " ) ;
new TDEAction ( i18n ( " Menu Toggle " ) , " media-optical-dvd-unmounted " , Key_R , engine ( ) , TQ_SLOT ( toggleDVDMenu ( ) ) , ac , " toggle_dvd_menu " ) ;
new TDEAction ( i18n ( " &Capture Frame " ) , " frame_image " , Key_C , this , TQ_SLOT ( captureFrame ( ) ) , ac , " capture_frame " ) ;
new PlayAction ( this , SLOT ( play ( ) ) , ac ) ;
new TDEAction ( i18n ( " Stop " ) , " media-playback-stop " , Key_S , engine ( ) , SLOT ( stop ( ) ) , ac , " stop " ) ;
new TDEAction( i18n ( " Video Settings... " ) , " configure " , Key_V , this , TQ_SLOT ( configure ( ) ) , ac , " video_settings " ) ;
new TDEAction ( i18n ( " Configure xine..." ) , " configure " , 0 , this , TQ_SLOT ( configure ( ) ) , ac , " xine_settings " ) ;
new TDEToggleAction ( i18n ( " Record " ) , " player_record " , CTRL + Key_R , engine ( ) , SLOT ( record ( ) ) , ac , " record " ) ;
( new KWidgetAction ( m_positionSlider , i18n ( " Position Slider " ) , nullptr , nullptr , nullptr , ac , " position_slider " ) ) - > setAutoSized ( true ) ;
new TDEAction ( i18n ( " Reset Video Scale " ) , " viewmag1 " , Key_Equal , videoWindow ( ) , SLOT ( resetZoom ( ) ) , ac , " reset_zoom " ) ;
new TDEAction ( i18n ( " Media Information " ) , " messagebox_info " , Key_I , this , SLOT ( streamInformation ( ) ) , ac , " information " ) ;
new TDEAction ( i18n ( " Menu Toggle " ) , " media-optical-dvd-unmounted " , Key_R , engine ( ) , SLOT ( toggleDVDMenu ( ) ) , ac , " media-optical-dvd-unmounted " ) ;
new TDEAction ( i18n ( " &Capture Frame " ) , " frame_image " , Key_C , this , SLOT ( captureFrame ( ) ) , ac , " capture_frame " ) ;
const auto audioSelectAction = new TDESelectAction ( i18n ( " A&udio Channels " ) , 0 , ac , kAudioSelectActionName ) ;
connect ( audioSelectAction , TQ_SIGNAL ( activated ( int ) ) , engine ( ) , TQ_SLOT ( setStreamParameter ( int ) ) ) ;
new TDEAction ( i18n ( " Video Settings... " ) , " configure " , Key_V , this , SLOT ( configure ( ) ) , ac , " video_settings " ) ;
new TDEAction ( i18n ( " Configure xine... " ) , " configure " , 0 , this , SLOT ( configure ( ) ) , ac , " xine_settings " ) ;
const auto subSelectAction = new TDESelectAction ( i18n ( " &Subtitles " ) , 0 , ac , kSubtitleSelectActionName ) ;
connect ( subSelectAction , TQ_SIGNAL ( activated ( int ) ) , engine ( ) , TQ_SLOT ( setStreamParameter ( int ) ) ) ;
( new KWidgetAction ( m_positionSlider , i18n ( " Position Slider " ) , 0 , 0 , 0 , ac , " position_slider " ) ) - > setAutoSized ( true ) ;
const auto aspectSelectAction = new TDESelectAction ( i18n ( " Aspect &Ratio " ) , 0 , ac , kAspectSelectActionName ) ;
connect ( aspectSelectAction , TQ_SIGNAL ( activated ( int ) ) , engine ( ) , TQ_SLOT ( setStreamParameter ( int ) ) ) ;
new VolumeAction( toolBar ( ) , ac ) ;
m_volumeAction = new VolumeAction( toolBar ( ) , ac ) ;
}
void
@ -282,6 +318,24 @@ MainWindow::readProperties( TDEConfig *config )
engine ( ) - > play ( config - > readNumEntry ( " time " ) ) ;
}
void
MainWindow : : contextMenuEvent ( TQContextMenuEvent * ev )
{
TQRect statusBarRect ( mapTo ( this , statusBar ( ) - > pos ( ) ) , statusBar ( ) - > size ( ) ) ;
if ( statusBarRect . contains ( ev - > pos ( ) ) & & TheStream : : hasVideo ( ) )
{
ev - > accept ( ) ;
TDEPopupMenu menu ;
menu . setCheckable ( true ) ;
int id = menu . insertItem ( i18n ( " Show Analyzer " ) , this , TQ_SLOT ( toggleAnalyzer ( ) ) ) ;
menu . setItemChecked ( id , m_analyzer - > isVisible ( ) ) ;
menu . exec ( ev - > globalPos ( ) ) ;
}
}
void
MainWindow : : timerEvent ( TQTimerEvent * )
{
@ -331,6 +385,13 @@ MainWindow::showTime( int pos )
m_timeLabel - > setText ( time ) ;
}
void
MainWindow : : toggleAnalyzer ( )
{
m_showAnalyzer = ! m_showAnalyzer ;
m_analyzer - > setShown ( m_showAnalyzer ) ;
}
void
MainWindow : : engineMessage ( const TQString & message )
{
@ -381,7 +442,7 @@ MainWindow::load( const KURL &url )
if ( url . protocol ( ) = = " media " ) {
# define UDS_LOCAL_PATH (72 | TDEIO::UDS_STRING)
TDEIO : : UDSEntry e ;
if ( ! TDEIO : : NetAccess : : stat ( url , e , 0 ) )
if ( ! TDEIO : : NetAccess : : stat ( url , e , nullptr ) )
MessageBox : : sorry ( " There was an internal error with the media slave... " ) ;
else {
TDEIO : : UDSEntry : : ConstIterator end = e . end ( ) ;
@ -507,7 +568,6 @@ show_toolbar:
//we aren't managed by mainWindow when at FullScreen
videoWindow ( ) - > move ( 0 , 0 ) ;
videoWindow ( ) - > resize ( ( ( TQWidget * ) o ) - > size ( ) ) ;
videoWindow ( ) - > lower ( ) ;
}
if ( o = = m_toolbar )
@ -564,14 +624,12 @@ MainWindow::fullScreenToggled( bool isFullScreen )
statusBar ( ) - > setHidden ( isFullScreen ) ;
setMouseTracking ( isFullScreen ) ; /// @see mouseMoveEvent()
m_widgetStack - > setMouseTracking ( isFullScreen ) ;
if ( isFullScreen )
s_handler = new FullScreenToolBarHandler ( this ) ;
else
delete s_handler ;
// prevent videoWindow() moving around when mouse moves
setCentralWidget ( isFullScreen ? 0 : videoWindow ( ) ) ;
}
void
@ -593,54 +651,49 @@ MainWindow::streamInformation()
}
void
MainWindow : : set Channels( const TQStringList & channels )
MainWindow : : set Audio Channels( const TQStringList & channels ) const
{
DEBUG_FUNC_INFO
//TODO -1 = auto
TQStringList : : ConstIterator it = channels . begin ( ) ;
TQPopupMenu * menu = ( TQPopupMenu * ) child ( ( * it ) . latin1 ( ) ) ;
menu - > clear ( ) ;
/* 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 - > 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 ) ;
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 < TDESelectAction * > ( 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 ( ) : 0 ) ;
// 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 < TDESelectAction * > ( 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
@ -681,10 +734,10 @@ MainWindow::keyPressEvent( TQKeyEvent *e )
}
TQPopupMenu *
MainWindow : : menu ( const char * name )
MainWindow : : menu ( const TQString & name )
{
// KXMLGUI is "really good".
return stat ic_cast< TQPopupMenu * > ( factory ( ) - > container ( name , this ) ) ;
return dynam ic_cast< TQPopupMenu * > ( factory ( ) - > container ( name , this ) ) ;
}
@ -692,7 +745,7 @@ MainWindow::menu( const char *name )
TDEActionCollection *
actionCollection ( )
{
return static_cast < MainWindow * > ( ka pp- > mainWidget ( ) ) - > actionCollection ( ) ;
return static_cast < MainWindow * > ( tdeA pp- > mainWidget ( ) ) - > actionCollection ( ) ;
}
/// Convenience class for other classes that need access to the actions
@ -701,17 +754,23 @@ action( const char *name )
{
# define QT_FATAL_ASSERT
MainWindow * mainWindow = 0 ;
TDEActionCollection * actionCollection = 0 ;
TDEAction * action = 0 ;
MainWindow * mainWindow = nullptr ;
TDEActionCollection * actionCollection = nullptr ;
TDEAction * action = nullptr ;
if ( mainWindow = ( MainWindow * ) kapp - > mainWidget ( ) )
if ( actionCollection = mainWindow - > actionCollection ( ) )
action = actionCollection - > action ( name ) ;
mainWindow = dynamic_cast < MainWindow * > ( tdeApp - > mainWidget ( ) ) ;
if ( mainWindow )
{
actionCollection = mainWindow - > actionCollection ( ) ;
if ( actionCollection )
{
action = actionCollection - > action ( name ) ;
}
}
Q_ASSERT ( mainWindow ) ;
Q_ASSERT ( actionCollection ) ;
Q_ASSERT ( action ) ;
Q_ASSERT ( mainWindow ) ;
Q_ASSERT ( actionCollection ) ;
Q_ASSERT ( action ) ;
return action ;
}