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>
28 #include <kstatusbar.h>
30 #define ID_STATUS_MSG 1
32 #define ID_STREAM_SOURCE 3
34 KInterface::KInterface( intf_thread_t *p_intf, QWidget *parent,
35 const char *name ) : KMainWindow(parent,name)
39 this->p_intf = p_intf;
41 fDiskDialog = new KDiskDialog( this );
42 fNetDialog = new KNetDialog( this );
43 fTitleMenu = new KTitleMenu( p_intf, this );
45 fSlider = new KVLCSlider( QSlider::Horizontal, this );
46 fSlider->setMaxValue(10000);
47 connect( fSlider, SIGNAL( userChanged( int ) ), this, SLOT( slotSliderMoved( int ) ) );
48 connect( fSlider, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderChanged( int ) ) );
49 setCentralWidget(fSlider);
51 fTimer = new QTimer( this );
52 connect( fTimer, SIGNAL( timeout() ), this, SLOT( slotManage() ) );
57 ///////////////////////////////////////////////////////////////////
58 // call inits to invoke all other construction parts
59 // XXX could we move this up ?
63 // add certain calls to the popup menu
64 fileOpen->plug( fTitleMenu );
65 fileOpenRecent->plug( fTitleMenu );
66 diskOpen->plug( fTitleMenu );
67 streamOpen->plug( fTitleMenu );
68 play->plug( fTitleMenu );
69 pause->plug( fTitleMenu );
70 slow->plug( fTitleMenu );
71 fast->plug( fTitleMenu );
72 fileClose->plug( fTitleMenu );
73 fileQuit->plug( fTitleMenu );
76 KInterface::~KInterface()
81 void KInterface::initActions()
83 fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection());
84 fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection());
85 fileClose = KStdAction::close(this, SLOT(slotFileClose()), actionCollection());
86 preferences = KStdAction::preferences(this, SLOT(slotShowPreferences()), actionCollection());
87 fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
88 viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), actionCollection());
89 viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), actionCollection());
91 diskOpen = new KAction( i18n( "Open &Disk" ), 0, 0, this, SLOT( slotOpenDisk() ), actionCollection(), "open_disk" );
92 streamOpen = new KAction( i18n( "Open &Stream" ), 0, 0, this, SLOT( slotOpenStream() ), actionCollection(), "open_stream" );
93 backward = new KAction( i18n( "&Backward" ), 0, 0, this, SLOT( slotBackward() ), actionCollection(), "backward" );
94 stop = new KAction( i18n( "&Stop" ), 0, 0, this, SLOT( slotStop() ), actionCollection(), "stop" );
95 play = new KAction( i18n( "&Play" ), 0, 0, this, SLOT( slotPlay() ), actionCollection(), "play" );
96 pause = new KAction( i18n( "P&ause" ), 0, 0, this, SLOT( slotPause() ), actionCollection(), "pause" );
97 slow = new KAction( i18n( "&Slow" ), 0, 0, this, SLOT( slotSlow() ), actionCollection(), "slow" );
98 fast = new KAction( i18n( "Fas&t" ), 0, 0, this, SLOT( slotFast() ), actionCollection(), "fast" );
99 prev = new KAction( i18n( "Prev" ), 0, 0, this, SLOT( slotPrev() ), actionCollection(), "prev" );
100 next = new KAction( i18n( "Next" ), 0, 0, this, SLOT( slotNext() ), actionCollection(), "next" );
102 fileOpen->setStatusText(i18n("Opens an existing document"));
103 fileOpenRecent->setStatusText(i18n("Opens a recently used file"));
104 fileClose->setStatusText(i18n("Closes the actual document"));
105 fileQuit->setStatusText(i18n("Quits the application"));
106 viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
107 viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));
109 diskOpen->setStatusText( i18n( "Opens a disk") );
110 streamOpen->setStatusText( i18n( "Opens a network stream" ) );
111 backward->setStatusText( i18n( "Backward" ) );
112 stop->setStatusText( i18n( "Stops playback" ) );
113 play->setStatusText( i18n( "Starts playback" ) );
114 pause->setStatusText( i18n( "Pauses playback" ) );
115 slow->setStatusText( i18n( "Slow" ) );
116 fast->setStatusText( i18n( "Fast" ) );
117 prev->setStatusText( i18n( "Prev" ) );
118 next->setStatusText( i18n( "Next" ) );
119 // use the absolute path to your ktestui.rc file for testing purpose in createGUI();
121 createGUI( DATA_PATH "/vlc_kde_ui.rc" );
124 void KInterface::initStatusBar()
126 ///////////////////////////////////////////////////////////////////
128 // TODO: add your own items you need for displaying current application status.
129 statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG, 1, false);
130 statusBar()->setItemAlignment( ID_STATUS_MSG, AlignLeft | AlignVCenter );
131 statusBar()->insertItem( "0:00:00", ID_DATE, 0, true );
134 /////////////////////////////////////////////////////////////////////
135 // SLOT IMPLEMENTATION
136 /////////////////////////////////////////////////////////////////////
138 void KInterface::slotFileOpen()
140 playlist_t *p_playlist;
142 slotStatusMsg( i18n( "Opening file..." ) );
143 KURL url=KFileDialog::getOpenURL( QString::null,
144 i18n( "*|All files" ), this, i18n( "Open File..." ) );
148 p_playlist = (playlist_t *)
149 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
152 fileOpenRecent->addURL( url );
153 playlist_Add( p_playlist, url.path(),
154 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
155 vlc_object_release( p_playlist );
159 slotStatusMsg( i18n( "Ready." ) );
162 void KInterface::slotFileOpenRecent(const KURL& url)
164 slotStatusMsg(i18n("Opening file..."));
165 slotStatusMsg(i18n("Ready."));
168 void KInterface::slotFileClose()
170 slotStatusMsg(i18n("Closing file..."));
174 slotStatusMsg(i18n("Ready."));
177 void KInterface::slotFileQuit()
179 slotStatusMsg(i18n("Exiting..."));
180 p_intf->p_vlc->b_die = VLC_TRUE;
181 slotStatusMsg(i18n("Ready."));
184 void KInterface::slotViewToolBar()
186 slotStatusMsg(i18n("Toggling toolbar..."));
187 ///////////////////////////////////////////////////////////////////
188 // turn Toolbar on or off
189 if(!viewToolBar->isChecked())
191 toolBar("mainToolBar")->hide();
195 toolBar("mainToolBar")->show();
198 slotStatusMsg(i18n("Ready."));
201 void KInterface::slotViewStatusBar()
203 slotStatusMsg(i18n("Toggle the statusbar..."));
204 ///////////////////////////////////////////////////////////////////
205 //turn Statusbar on or off
206 if(!viewStatusBar->isChecked())
215 slotStatusMsg(i18n("Ready."));
218 void KInterface::slotShowPreferences()
221 KPreferences(this->p_intf, "main", this, "preferences");
224 void KInterface::slotStatusMsg(const QString &text)
226 ///////////////////////////////////////////////////////////////////
227 // change status message permanently
228 statusBar()->clear();
229 statusBar()->changeItem(text, ID_STATUS_MSG);
232 void KInterface::slotManage()
234 vlc_mutex_lock( &p_intf->change_lock );
236 /* Update the input */
237 if( p_intf->p_sys->p_input == NULL )
239 p_intf->p_sys->p_input = (input_thread_t *)
240 vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
242 else if( p_intf->p_sys->p_input->b_dead )
244 vlc_object_release( p_intf->p_sys->p_input );
245 p_intf->p_sys->p_input = NULL;
248 /* If the "display popup" flag has changed */
249 if( p_intf->b_menu_change )
251 fTitleMenu->popup( ( QCursor::pos() ) );
252 p_intf->b_menu_change = 0;
255 /* Update language/chapter menus after user request */
257 if( p_intf->p_sys->p_input != NULL && p_intf->p_sys->p_window != NULL &&
258 p_intf->p_sys->b_menus_update )
260 // GnomeSetupMenu( p_intf );
264 /* Manage the slider */
265 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
266 if( p_intf->p_sys->p_input && p_area->i_size )
268 fSlider->setValue( ( 10000. * p_area->i_tell ) / p_area->i_size );
274 p_intf->p_sys->p_app->quit();
277 vlc_mutex_unlock( &p_intf->change_lock );
280 void KInterface::slotSliderMoved( int position )
282 if( p_intf->p_sys->p_input )
284 // XXX is this locking really useful ?
285 vlc_mutex_lock( &p_intf->change_lock );
287 off_t i_seek = ( position * p_intf->p_sys->p_input->stream.p_selected_area->i_size ) / 10000;
288 input_Seek( p_intf->p_sys->p_input, i_seek, INPUT_SEEK_SET );
290 vlc_mutex_unlock( &p_intf->change_lock );
294 void KInterface::slotSliderChanged( int position )
296 if( p_intf->p_sys->p_input != NULL )
298 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
300 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
302 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
303 statusBar()->changeItem( input_OffsetToTime( p_intf->p_sys->p_input, psz_time, ( p_area->i_size * position ) / 10000 ), ID_DATE );
306 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
310 void KInterface::slotOpenDisk()
312 playlist_t *p_playlist;
313 int r = fDiskDialog->exec();
318 source += fDiskDialog->type();
320 source += fDiskDialog->device();
323 source += fDiskDialog->title();
325 source += fDiskDialog->chapter();
327 p_playlist = (playlist_t *)
328 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
331 // add it to playlist
332 playlist_Add( p_playlist, source.latin1(),
333 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
334 vlc_object_release( p_playlist );
339 void KInterface::slotOpenStream()
341 playlist_t *p_playlist;
342 int r = fNetDialog->exec();
347 source += fNetDialog->protocol();
349 source += fNetDialog->server();
351 source += QString().setNum( fNetDialog->port() );
353 p_playlist = (playlist_t *)
354 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
357 // add it to playlist
358 playlist_Add( p_playlist, source.latin1(),
359 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
360 vlc_object_release( p_playlist );
365 void KInterface::slotPlay()
367 if( p_intf->p_sys->p_input )
369 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
373 void KInterface::slotPause()
375 if ( p_intf->p_sys->p_input )
377 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
381 void KInterface::slotStop()
383 playlist_t *p_playlist = (playlist_t *)
384 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
387 playlist_Stop( p_playlist );
388 vlc_object_release( p_playlist );
392 void KInterface::slotBackward()
394 msg_Err( p_intf, "KInterface::slotBackward() - Unimplemented" );
397 void KInterface::slotPrev()
399 playlist_t *p_playlist = (playlist_t *)
400 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
403 playlist_Prev( p_playlist );
404 vlc_object_release( p_playlist );
408 void KInterface::slotNext()
410 playlist_t *p_playlist = (playlist_t *)
411 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
414 playlist_Next( p_playlist );
415 vlc_object_release( p_playlist );
419 void KInterface::slotSlow()
421 if( p_intf->p_sys->p_input != NULL )
423 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
427 void KInterface::slotFast()
429 if( p_intf->p_sys->p_input != NULL )
431 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
435 void KInterface::dragEnterEvent( QDragEnterEvent *event )
437 event->accept( QUriDrag::canDecode( event ) );
440 void KInterface::dropEvent( QDropEvent *event )
444 playlist_t *p_playlist = (playlist_t *)
445 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
446 if( p_playlist == NULL )
451 if ( KURLDrag::decode( event, urlList ) )
453 for ( KURL::List::ConstIterator i = urlList.begin(); i != urlList.end(); i++ )
455 // XXX add a private function to add a KURL with checking
456 // actually a whole class for core abstraction would be neat
457 if( !(*i).isEmpty() )
459 fileOpenRecent->addURL( *i );
460 playlist_Add( p_playlist, (*i).path(),
461 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
466 vlc_object_release( p_playlist );