summaryrefslogtreecommitdiffstats
path: root/src/app/stateChange.cpp
blob: efa93896920c2cac9d303597a5d262c90d266c0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright 2004 Max Howell ([email protected])
// See COPYING file for licensing information

#include "actions.h"
#include "adjustSizeButton.h"
#include "../debug.h"
#include "mainWindow.h"
#include <tdeconfig.h>
#include <tdeglobal.h>
#include "../mxcl.library.h"
#include <tqapplication.h>
#include <tqevent.h>
#include <tqlabel.h>
#include <tqpopupmenu.h>
#include <tqslider.h>
#include "theStream.h"
#include "videoSettings.h" //FIXME unfortunate
#include "xineEngine.h"
#include "volumeAction.h"


//TODO do in Sconstruct
#define QT_FATAL_ASSERT


//TODO make the XineEngine into xine::Stream and then make singleton and add functions like Stream::hasVideo() etc.
//TODO make convenience function to get fullscreen state


namespace Codeine {


void
MainWindow::engineStateChanged( Engine::State state )
{
   Q_ASSERT( state != Engine::Uninitialised );

   KURL const &url = TheStream::url();
   bool const isFullScreen = toggleAction("fullscreen")->isChecked();
   TQWidget *const toolbar = reinterpret_cast<TQWidget*>(toolBar());

   Debug::Block block( state == Engine::Empty
         ? "State: Empty" : state == Engine::Loaded
         ? "State: Loaded" : state == Engine::Playing
         ? "State: Playing" : state == Engine::Paused
         ? "State: Paused" : state == Engine::TrackEnded
         ? "State: TrackEnded" : "State: Unknown" );


   /// update actions
   {
      using namespace Engine;

      #define enableIf( name, criteria ) action( name )->setEnabled( state & criteria );
      enableIf( "stop", (Playing | Paused) );
      enableIf( "fullscreen", (Playing | Paused) );
      enableIf( "reset_zoom", ~Empty && !isFullScreen );
      enableIf( "information", ~Empty );
      enableIf( "video_settings", (Playing | Paused) );
      enableIf( "volume", (Playing | Paused) );
      #undef enableIf

      toggleAction( "play" )->setChecked( state == Playing );

      //FIXME bad design to do this way
      m_volumeAction->sliderMoved( engine()->volume() );
   }


   /// update VideoSettingsDialog instance
   VideoSettingsDialog::stateChanged( this, state );


   /// update menus
   {
      using namespace Engine;

      // the toolbar play button is always enabled, but the menu item
      // is disabled if we are empty, this looks more sensible
      TQPopupMenu * const file_menu = menu( "file" );
      TQPopupMenu * const settings_menu = menu( "settings" );
      const int play_id = file_menu->idAt( 2 );
      file_menu->setItemEnabled( play_id, state != Empty );

      // menus are clearer when handled differently to toolbars
      // KDE has a shit special action for this, but it stupidly changes
      // the toolbar icon too.
      // TODO do this from the playAction since we do it in context menu too
      const KGuiItem item = (state == Playing) ? KGuiItem( i18n("&Pause"), "media-playback-pause" ) : KGuiItem( i18n("&Play"), "media-playback-start" );
      file_menu->changeItem( play_id, item.iconSet(), item.text() );
      file_menu->setItemChecked( play_id, false );

      settings_menu->setItemEnabled( AspectRatioMenuItemId, state & (Playing | Paused) && TheStream::hasVideo() );

      // set correct aspect ratio
      if( state == Loaded )
         static_cast<TQPopupMenu*>(child( "aspect_ratio_menu" ))->setItemChecked( TheStream::aspectRatio(), true );
   }


   /// update statusBar
   {
      using namespace Engine;
      m_analyzer->setShown( state & (Playing | Paused) && TheStream::hasAudio() );
      m_timeLabel->setShown( state & (Playing | Paused) );
   }


   /// update position slider
   switch( state )
   {
      case Engine::Empty:
         m_positionSlider->setEnabled( false );
         break;
      case Engine::Loaded:
      case Engine::TrackEnded:
         m_positionSlider->setValue( 0 );
         // NO BREAK!
      case Engine::Playing:
      case Engine::Paused:
         m_positionSlider->setEnabled( TheStream::canSeek() );
         break;
      default:
         break;
   }


   /// update recent files list if necessary
   if( state == Engine::Loaded ) {
      // update recently played list

      #ifndef NO_SKIP_PR0N
      // ;-)
      const TQString url_string = url.url();
      if( !(url_string.contains( "porn", false ) || url_string.contains( "pr0n", false )) )
      #endif
         if( url.protocol() != "dvd" && url.protocol() != "vcd" ) {
            TDEConfig *config = Codeine::config( "General" );
            const TQString prettyUrl = url.prettyURL();

            TQStringList urls = config->readPathListEntry( "Recent Urls" );
            urls.remove( prettyUrl );
            config->writePathEntry( "Recent Urls", urls << prettyUrl );
         }

      if( TheStream::hasVideo() && !isFullScreen )
         new AdjustSizeButton( reinterpret_cast<TQWidget*>(videoWindow()) );
   }


   /// set titles
   switch( state )
   {
      case Engine::Empty:
         m_titleLabel->setText( i18n("No media loaded") );
         break;
      case Engine::Paused:
         m_titleLabel->setText( i18n("Paused") );
         break;
      case Engine::Loaded:
      case Engine::Playing:
      case Engine::TrackEnded:
         m_titleLabel->setText( TheStream::prettyTitle() );
         break;
      default:
         break;
   }


   /// set toolbar states
   TQWidget *dvd_button = (TQWidget*)toolBar()->child( "toolbutton_toggle_dvd_menu" );
   if (dvd_button)
      dvd_button->setShown( state != Engine::Empty && url.protocol() == "dvd" );

   if( isFullScreen && !toolbar->hasMouse() ) {
      switch( state ) {
      case Engine::TrackEnded:
         toolbar->show();

         if( videoWindow()->isActiveWindow() ) {
            //FIXME dual-screen this seems to still show
            TQContextMenuEvent e( TQContextMenuEvent::Other, TQPoint(), TQt::MetaButton );
            TQApplication::sendEvent( videoWindow(), &e );
         }
         break;
      case Engine::Empty:
      case Engine::Loaded:
      case Engine::Paused:
         toolBar()->show();
         break;
      case Engine::Playing:
         toolBar()->hide();
         break;
      default:
         break;
      }
   }
}

}