1 /***************************************************************************
2 interface.cpp - description
4 begin : Sun Mar 25 2001
5 copyright : (C) 2001 by andres
7 ***************************************************************************/
10 #include "interface.h"
14 #include "preferences.h"
19 #include <kfiledialog.h>
21 #include <kstdaction.h>
25 #include <qdragobject.h>
29 #define ID_STATUS_MSG 1
31 #define ID_STREAM_SOURCE 3
33 KInterface::KInterface( intf_thread_t *p_intf, QWidget *parent,
34 const char *name ) : KMainWindow(parent,name)
38 this->p_intf = p_intf;
40 fDiskDialog = new KDiskDialog( this );
41 fNetDialog = new KNetDialog( this );
42 fTitleMenu = new KTitleMenu( p_intf, this );
44 fSlider = new KVLCSlider( QSlider::Horizontal, this );
45 fSlider->setMaxValue(10000);
46 connect( fSlider, SIGNAL( userChanged( int ) ), this, SLOT( slotSliderMoved( int ) ) );
47 connect( fSlider, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderChanged( int ) ) );
48 setCentralWidget(fSlider);
50 fTimer = new QTimer( this );
51 connect( fTimer, SIGNAL( timeout() ), this, SLOT( slotManage() ) );
56 ///////////////////////////////////////////////////////////////////
57 // call inits to invoke all other construction parts
58 // XXX could we move this up ?
62 // add certain calls to the popup menu
63 fileOpen->plug( fTitleMenu );
64 fileOpenRecent->plug( fTitleMenu );
65 diskOpen->plug( fTitleMenu );
66 streamOpen->plug( fTitleMenu );
67 play->plug( fTitleMenu );
68 pause->plug( fTitleMenu );
69 slow->plug( fTitleMenu );
70 fast->plug( fTitleMenu );
71 fileClose->plug( fTitleMenu );
72 fileQuit->plug( fTitleMenu );
75 KInterface::~KInterface()
80 void KInterface::initActions()
82 fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection());
83 fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection());
84 fileClose = KStdAction::close(this, SLOT(slotFileClose()), actionCollection());
85 preferences = KStdAction::preferences(this, SLOT(slotShowPreferences()), actionCollection());
86 fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
87 viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), actionCollection());
88 viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), actionCollection());
90 diskOpen = new KAction( i18n( "Open &Disk" ), 0, 0, this, SLOT( slotOpenDisk() ), actionCollection(), "open_disk" );
91 streamOpen = new KAction( i18n( "Open &Stream" ), 0, 0, this, SLOT( slotOpenStream() ), actionCollection(), "open_stream" );
92 backward = new KAction( i18n( "&Backward" ), 0, 0, this, SLOT( slotBackward() ), actionCollection(), "backward" );
93 stop = new KAction( i18n( "&Stop" ), 0, 0, this, SLOT( slotStop() ), actionCollection(), "stop" );
94 play = new KAction( i18n( "&Play" ), 0, 0, this, SLOT( slotPlay() ), actionCollection(), "play" );
95 pause = new KAction( i18n( "P&ause" ), 0, 0, this, SLOT( slotPause() ), actionCollection(), "pause" );
96 slow = new KAction( i18n( "&Slow" ), 0, 0, this, SLOT( slotSlow() ), actionCollection(), "slow" );
97 fast = new KAction( i18n( "Fas&t" ), 0, 0, this, SLOT( slotFast() ), actionCollection(), "fast" );
98 prev = new KAction( i18n( "Prev" ), 0, 0, this, SLOT( slotPrev() ), actionCollection(), "prev" );
99 next = new KAction( i18n( "Next" ), 0, 0, this, SLOT( slotNext() ), actionCollection(), "next" );
101 fileOpen->setStatusText(i18n("Opens an existing document"));
102 fileOpenRecent->setStatusText(i18n("Opens a recently used file"));
103 fileClose->setStatusText(i18n("Closes the actual document"));
104 fileQuit->setStatusText(i18n("Quits the application"));
105 viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
106 viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));
108 diskOpen->setStatusText( i18n( "Opens a disk") );
109 streamOpen->setStatusText( i18n( "Opens a network stream" ) );
110 backward->setStatusText( i18n( "Backward" ) );
111 stop->setStatusText( i18n( "Stops playback" ) );
112 play->setStatusText( i18n( "Starts playback" ) );
113 pause->setStatusText( i18n( "Pauses playback" ) );
114 slow->setStatusText( i18n( "Slow" ) );
115 fast->setStatusText( i18n( "Fast" ) );
116 prev->setStatusText( i18n( "Prev" ) );
117 next->setStatusText( i18n( "Next" ) );
118 // use the absolute path to your ktestui.rc file for testing purpose in createGUI();
120 createGUI("plugins/kde/ui.rc");
123 void KInterface::initStatusBar()
125 ///////////////////////////////////////////////////////////////////
127 // TODO: add your own items you need for displaying current application status.
128 statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG, 1, false);
129 statusBar()->setItemAlignment( ID_STATUS_MSG, AlignLeft | AlignVCenter );
130 statusBar()->insertItem( "0:00:00", ID_DATE, 0, true );
133 /////////////////////////////////////////////////////////////////////
134 // SLOT IMPLEMENTATION
135 /////////////////////////////////////////////////////////////////////
137 void KInterface::slotFileOpen()
139 playlist_t *p_playlist;
141 slotStatusMsg( i18n( "Opening file..." ) );
142 KURL url=KFileDialog::getOpenURL( QString::null,
143 i18n( "*|All files" ), this, i18n( "Open File..." ) );
147 p_playlist = (playlist_t *)
148 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
151 fileOpenRecent->addURL( url );
152 playlist_Add( p_playlist, url.path(),
153 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
154 vlc_object_release( p_playlist );
158 slotStatusMsg( i18n( "Ready." ) );
161 void KInterface::slotFileOpenRecent(const KURL& url)
163 slotStatusMsg(i18n("Opening file..."));
164 slotStatusMsg(i18n("Ready."));
167 void KInterface::slotFileClose()
169 slotStatusMsg(i18n("Closing file..."));
173 slotStatusMsg(i18n("Ready."));
176 void KInterface::slotFileQuit()
178 slotStatusMsg(i18n("Exiting..."));
179 p_intf->p_vlc->b_die = VLC_TRUE;
180 slotStatusMsg(i18n("Ready."));
183 void KInterface::slotViewToolBar()
185 slotStatusMsg(i18n("Toggling toolbar..."));
186 ///////////////////////////////////////////////////////////////////
187 // turn Toolbar on or off
188 if(!viewToolBar->isChecked())
190 toolBar("mainToolBar")->hide();
194 toolBar("mainToolBar")->show();
197 slotStatusMsg(i18n("Ready."));
200 void KInterface::slotViewStatusBar()
202 slotStatusMsg(i18n("Toggle the statusbar..."));
203 ///////////////////////////////////////////////////////////////////
204 //turn Statusbar on or off
205 if(!viewStatusBar->isChecked())
214 slotStatusMsg(i18n("Ready."));
217 void KInterface::slotShowPreferences()
220 KPreferences(this->p_intf, "main", this, "preferences");
223 void KInterface::slotStatusMsg(const QString &text)
225 ///////////////////////////////////////////////////////////////////
226 // change status message permanently
227 statusBar()->clear();
228 statusBar()->changeItem(text, ID_STATUS_MSG);
231 void KInterface::slotManage()
233 vlc_mutex_lock( &p_intf->change_lock );
235 /* Update the input */
236 if( p_intf->p_sys->p_input == NULL )
238 p_intf->p_sys->p_input = (input_thread_t *)
239 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
241 else if( p_intf->p_sys->p_input->b_dead )
243 vlc_object_release( p_intf->p_sys->p_input );
244 p_intf->p_sys->p_input = NULL;
247 /* If the "display popup" flag has changed */
248 if( p_intf->b_menu_change )
250 fTitleMenu->popup( ( QCursor::pos() ) );
251 p_intf->b_menu_change = 0;
254 /* Update language/chapter menus after user request */
256 if( p_intf->p_sys->p_input != NULL && p_intf->p_sys->p_window != NULL &&
257 p_intf->p_sys->b_menus_update )
259 // GnomeSetupMenu( p_intf );
263 /* Manage the slider */
264 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
265 if( p_intf->p_sys->p_input && p_area->i_size )
267 fSlider->setValue( ( 10000. * p_area->i_tell ) / p_area->i_size );
273 p_intf->p_sys->p_app->quit();
276 vlc_mutex_unlock( &p_intf->change_lock );
279 void KInterface::slotSliderMoved( int position )
281 if( p_intf->p_sys->p_input )
283 // XXX is this locking really useful ?
284 vlc_mutex_lock( &p_intf->change_lock );
286 off_t i_seek = ( position * p_intf->p_sys->p_input->stream.p_selected_area->i_size ) / 10000;
287 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
289 vlc_mutex_unlock( &p_intf->change_lock );
293 void KInterface::slotSliderChanged( int position )
295 if( p_intf->p_sys->p_input != NULL )
297 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
299 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
301 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
302 statusBar()->changeItem( input_OffsetToTime( p_intf->p_sys->p_input, psz_time, ( p_area->i_size * position ) / 10000 ), ID_DATE );
305 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
309 void KInterface::slotOpenDisk()
311 playlist_t *p_playlist;
312 int r = fDiskDialog->exec();
317 source += fDiskDialog->type();
319 source += fDiskDialog->device();
322 source += fDiskDialog->title();
324 source += fDiskDialog->chapter();
326 p_playlist = (playlist_t *)
327 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
330 // add it to playlist
331 playlist_Add( p_playlist, source.latin1(),
332 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
333 vlc_object_release( p_playlist );
338 void KInterface::slotOpenStream()
340 playlist_t *p_playlist;
341 int r = fNetDialog->exec();
346 source += fNetDialog->protocol();
348 source += fNetDialog->server();
350 source += QString().setNum( fNetDialog->port() );
352 p_playlist = (playlist_t *)
353 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
356 // add it to playlist
357 playlist_Add( p_playlist, source.latin1(),
358 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
359 vlc_object_release( p_playlist );
364 void KInterface::slotPlay()
366 if( p_intf->p_sys->p_input )
368 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
372 void KInterface::slotPause()
374 if ( p_intf->p_sys->p_input )
376 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
380 void KInterface::slotStop()
382 playlist_t *p_playlist = (playlist_t *)
383 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
386 playlist_Stop( p_playlist );
387 vlc_object_release( p_playlist );
391 void KInterface::slotBackward()
393 msg_Err( p_intf, "KInterface::slotBackward() - Unimplemented" );
396 void KInterface::slotPrev()
398 playlist_t *p_playlist = (playlist_t *)
399 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
402 playlist_Prev( p_playlist );
403 vlc_object_release( p_playlist );
407 void KInterface::slotNext()
409 playlist_t *p_playlist = (playlist_t *)
410 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
413 playlist_Next( p_playlist );
414 vlc_object_release( p_playlist );
418 void KInterface::slotSlow()
420 if( p_intf->p_sys->p_input != NULL )
422 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
426 void KInterface::slotFast()
428 if( p_intf->p_sys->p_input != NULL )
430 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
434 void KInterface::dragEnterEvent( QDragEnterEvent *event )
436 event->accept( QUriDrag::canDecode( event ) );
439 void KInterface::dropEvent( QDropEvent *event )
443 playlist_t *p_playlist = (playlist_t *)
444 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
445 if( p_playlist == NULL )
450 if ( KURLDrag::decode( event, urlList ) )
452 for ( KURL::List::ConstIterator i = urlList.begin(); i != urlList.end(); i++ )
454 // XXX add a private function to add a KURL with checking
455 // actually a whole class for core abstraction would be neat
456 if( !(*i).isEmpty() )
458 fileOpenRecent->addURL( *i );
459 playlist_Add( p_playlist, (*i).path(),
460 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
465 vlc_object_release( p_playlist );