1 /***************************************************************************
2 kde_interface.cpp - description
4 begin : Sun Mar 25 2001
5 copyright : (C) 2001 by andres
7 ***************************************************************************/
10 #include "kde_interface.h"
13 #include "kde_slider.h"
14 #include "kde_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/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 slotStatusMsg( i18n( "Opening file..." ) );
140 KURL url=KFileDialog::getOpenURL( QString::null,
141 i18n( "*|All files" ), this, i18n( "Open File..." ) );
145 fileOpenRecent->addURL( url );
146 intf_PlaylistAdd( p_intf->p_vlc->p_playlist, PLAYLIST_END, url.path() );
149 slotStatusMsg( i18n( "Ready." ) );
152 void KInterface::slotFileOpenRecent(const KURL& url)
154 slotStatusMsg(i18n("Opening file..."));
155 slotStatusMsg(i18n("Ready."));
158 void KInterface::slotFileClose()
160 slotStatusMsg(i18n("Closing file..."));
164 slotStatusMsg(i18n("Ready."));
167 void KInterface::slotFileQuit()
169 slotStatusMsg(i18n("Exiting..."));
170 p_intf->p_sys->p_app->quit();
171 slotStatusMsg(i18n("Ready."));
174 void KInterface::slotViewToolBar()
176 slotStatusMsg(i18n("Toggling toolbar..."));
177 ///////////////////////////////////////////////////////////////////
178 // turn Toolbar on or off
179 if(!viewToolBar->isChecked())
181 toolBar("mainToolBar")->hide();
185 toolBar("mainToolBar")->show();
188 slotStatusMsg(i18n("Ready."));
191 void KInterface::slotViewStatusBar()
193 slotStatusMsg(i18n("Toggle the statusbar..."));
194 ///////////////////////////////////////////////////////////////////
195 //turn Statusbar on or off
196 if(!viewStatusBar->isChecked())
205 slotStatusMsg(i18n("Ready."));
208 void KInterface::slotShowPreferences()
211 KPreferences(this->p_intf, "main", this, "preferences");
214 void KInterface::slotStatusMsg(const QString &text)
216 ///////////////////////////////////////////////////////////////////
217 // change status message permanently
218 statusBar()->clear();
219 statusBar()->changeItem(text, ID_STATUS_MSG);
222 void KInterface::slotManage()
224 vlc_mutex_lock( &p_intf->change_lock );
226 /* If the "display popup" flag has changed */
227 if( p_intf->b_menu_change )
229 fTitleMenu->popup( ( QCursor::pos() ) );
230 p_intf->b_menu_change = 0;
233 /* Update language/chapter menus after user request */
235 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL && p_intf->p_sys->p_window != NULL &&
236 p_intf->p_sys->b_menus_update )
238 // GnomeSetupMenu( p_intf );
242 /* Manage the slider */
243 #define p_area p_intf->p_vlc->p_input_bank->pp_input[0]->stream.p_selected_area
244 if( (p_intf->p_vlc->p_input_bank->pp_input[0] != NULL) && (p_area->i_size != 0 ))
246 fSlider->setValue( ( 10000. * p_area->i_tell ) / p_area->i_size );
250 /* Manage core vlc functions through the callback */
251 p_intf->pf_manage(p_intf);
253 if( p_intf->p_vlc->b_die )
255 p_intf->p_sys->p_app->quit();
258 vlc_mutex_unlock( &p_intf->change_lock );
261 void KInterface::slotSliderMoved( int position )
263 // XXX is this locking really useful ?
264 vlc_mutex_lock( &p_intf->change_lock );
266 off_t i_seek = ( position * p_intf->p_vlc->p_input_bank->pp_input[0]->stream.p_selected_area->i_size ) / 10000;
267 input_Seek( p_intf->p_vlc->p_input_bank->pp_input[0]->p_this, i_seek, INPUT_SEEK_SET );
269 vlc_mutex_unlock( &p_intf->change_lock );
272 void KInterface::slotSliderChanged( int position )
274 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
276 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
278 vlc_mutex_lock( &p_intf->p_vlc->p_input_bank->pp_input[0]->stream.stream_lock );
280 #define p_area p_intf->p_vlc->p_input_bank->pp_input[0]->stream.p_selected_area
281 statusBar()->changeItem( input_OffsetToTime( p_intf->p_vlc->p_input_bank->pp_input[0], psz_time, ( p_area->i_size * position ) / 10000 ), ID_DATE );
284 vlc_mutex_unlock( &p_intf->p_vlc->p_input_bank->pp_input[0]->stream.stream_lock );
288 void KInterface::slotOpenDisk()
290 int r = fDiskDialog->exec();
295 source += fDiskDialog->type();
297 source += fDiskDialog->device();
300 source += fDiskDialog->title();
302 source += fDiskDialog->chapter();
304 // add it to playlist
305 intf_PlaylistAdd( p_intf->p_vlc->p_playlist, PLAYLIST_END, source.latin1() );
307 // Select added item and switch to disk interface
308 intf_PlaylistJumpto( p_intf->p_vlc->p_playlist, p_intf->p_vlc->p_playlist->i_size-2 );
309 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
311 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
316 void KInterface::slotOpenStream()
318 int r = fNetDialog->exec();
323 source += fNetDialog->protocol();
325 source += fNetDialog->server();
327 source += QString().setNum( fNetDialog->port() );
329 // add it to playlist
330 intf_PlaylistAdd( p_intf->p_vlc->p_playlist, PLAYLIST_END, source.latin1() );
331 intf_PlaylistJumpto( p_intf->p_vlc->p_playlist, p_intf->p_vlc->p_playlist->i_size-2 );
333 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
335 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
340 void KInterface::slotPlay()
342 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
344 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
348 void KInterface::slotPause()
350 if ( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
352 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0], INPUT_STATUS_PAUSE );
356 void KInterface::slotStop()
358 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
360 /* end playing item */
361 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
363 /* update playlist */
364 vlc_mutex_lock( &p_intf->p_vlc->p_playlist->change_lock );
366 p_intf->p_vlc->p_playlist->i_index--;
367 p_intf->p_vlc->p_playlist->b_stopped = 1;
369 vlc_mutex_unlock( &p_intf->p_vlc->p_playlist->change_lock );
373 void KInterface::slotBackward()
375 msg_Err( p_intf, "KInterface::slotBackward() - Unimplemented" );
378 void KInterface::slotPrev()
380 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
382 /* FIXME: temporary hack */
383 intf_PlaylistPrev( p_intf->p_vlc->p_playlist );
384 intf_PlaylistPrev( p_intf->p_vlc->p_playlist );
385 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
389 void KInterface::slotNext()
391 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
393 /* FIXME: temporary hack */
394 p_intf->p_vlc->p_input_bank->pp_input[0]->b_eof = 1;
398 void KInterface::slotSlow()
400 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
402 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0], INPUT_STATUS_SLOWER );
406 void KInterface::slotFast()
408 if( p_intf->p_vlc->p_input_bank->pp_input[0] != NULL )
410 input_SetStatus( p_intf->p_vlc->p_input_bank->pp_input[0], INPUT_STATUS_FASTER );
414 void KInterface::dragEnterEvent( QDragEnterEvent *event )
416 event->accept( QUriDrag::canDecode( event ) );
419 void KInterface::dropEvent( QDropEvent *event )
423 if ( KURLDrag::decode( event, urlList ) ) {
424 for ( KURL::List::ConstIterator i = urlList.begin(); i != urlList.end(); i++ )
426 // XXX add a private function to add a KURL with checking
427 // actually a whole class for core abstraction would be neat
428 if( !(*i).isEmpty() )
430 fileOpenRecent->addURL( *i );
431 intf_PlaylistAdd( p_intf->p_vlc->p_playlist, PLAYLIST_END, (*i).path() );