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"
18 #include <kfiledialog.h>
20 #include <kstdaction.h>
24 #include <qdragobject.h>
27 #define ID_STATUS_MSG 1
29 #define ID_STREAM_SOURCE 3
31 KInterface::KInterface( intf_thread_t *p_intf, QWidget *parent,
32 const char *name ) : KMainWindow(parent,name)
36 this->p_intf = p_intf;
38 fDiskDialog = new KDiskDialog( this );
39 fNetDialog = new KNetDialog( this );
40 fTitleMenu = new KTitleMenu( p_intf, this );
42 fSlider = new KVLCSlider( QSlider::Horizontal, this );
43 connect( fSlider, SIGNAL( userChanged( int ) ), this, SLOT( slotSliderMoved( int ) ) );
44 connect( fSlider, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderChanged( int ) ) );
45 setCentralWidget(fSlider);
47 fTimer = new QTimer( this );
48 connect( fTimer, SIGNAL( timeout() ), this, SLOT( slotManage() ) );
53 ///////////////////////////////////////////////////////////////////
54 // call inits to invoke all other construction parts
55 // XXX could we move this up ?
59 // add certain calls to the popup menu
60 fileOpen->plug( fTitleMenu );
61 fileOpenRecent->plug( fTitleMenu );
62 diskOpen->plug( fTitleMenu );
63 streamOpen->plug( fTitleMenu );
64 play->plug( fTitleMenu );
65 pause->plug( fTitleMenu );
66 slow->plug( fTitleMenu );
67 fast->plug( fTitleMenu );
68 fileClose->plug( fTitleMenu );
69 fileQuit->plug( fTitleMenu );
72 KInterface::~KInterface()
77 void KInterface::initActions()
79 fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection());
80 fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection());
81 fileClose = KStdAction::close(this, SLOT(slotFileClose()), actionCollection());
82 fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
83 viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), actionCollection());
84 viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), actionCollection());
86 diskOpen = new KAction( i18n( "Open &Disk" ), 0, 0, this, SLOT( slotOpenDisk() ), actionCollection(), "open_disk" );
87 streamOpen = new KAction( i18n( "Open &Stream" ), 0, 0, this, SLOT( slotOpenStream() ), actionCollection(), "open_stream" );
88 backward = new KAction( i18n( "&Backward" ), 0, 0, this, SLOT( slotBackward() ), actionCollection(), "backward" );
89 stop = new KAction( i18n( "&Stop" ), 0, 0, this, SLOT( slotStop() ), actionCollection(), "stop" );
90 play = new KAction( i18n( "&Play" ), 0, 0, this, SLOT( slotPlay() ), actionCollection(), "play" );
91 pause = new KAction( i18n( "P&ause" ), 0, 0, this, SLOT( slotPause() ), actionCollection(), "pause" );
92 slow = new KAction( i18n( "&Slow" ), 0, 0, this, SLOT( slotSlow() ), actionCollection(), "slow" );
93 fast = new KAction( i18n( "Fas&t" ), 0, 0, this, SLOT( slotFast() ), actionCollection(), "fast" );
94 prev = new KAction( i18n( "Prev" ), 0, 0, this, SLOT( slotPrev() ), actionCollection(), "prev" );
95 next = new KAction( i18n( "Next" ), 0, 0, this, SLOT( slotNext() ), actionCollection(), "next" );
97 fileOpen->setStatusText(i18n("Opens an existing document"));
98 fileOpenRecent->setStatusText(i18n("Opens a recently used file"));
99 fileClose->setStatusText(i18n("Closes the actual document"));
100 fileQuit->setStatusText(i18n("Quits the application"));
101 viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
102 viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));
104 diskOpen->setStatusText( i18n( "Opens a disk") );
105 streamOpen->setStatusText( i18n( "Opens a network stream" ) );
106 backward->setStatusText( i18n( "Backward" ) );
107 stop->setStatusText( i18n( "Stops playback" ) );
108 play->setStatusText( i18n( "Starts playback" ) );
109 pause->setStatusText( i18n( "Pauses playback" ) );
110 slow->setStatusText( i18n( "Slow" ) );
111 fast->setStatusText( i18n( "Fast" ) );
112 prev->setStatusText( i18n( "Prev" ) );
113 next->setStatusText( i18n( "Next" ) );
114 // use the absolute path to your ktestui.rc file for testing purpose in createGUI();
116 createGUI("plugins/kde/kde_ui.rc");
119 void KInterface::initStatusBar()
121 ///////////////////////////////////////////////////////////////////
123 // TODO: add your own items you need for displaying current application status.
124 statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG, 1, false);
125 statusBar()->setItemAlignment( ID_STATUS_MSG, AlignLeft | AlignVCenter );
126 statusBar()->insertItem( "0:00:00", ID_DATE, 0, true );
129 /////////////////////////////////////////////////////////////////////
130 // SLOT IMPLEMENTATION
131 /////////////////////////////////////////////////////////////////////
133 void KInterface::slotFileOpen()
135 slotStatusMsg( i18n( "Opening file..." ) );
136 KURL url=KFileDialog::getOpenURL( QString::null,
137 i18n( "*|All files" ), this, i18n( "Open File..." ) );
141 fileOpenRecent->addURL( url );
142 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, url.path() );
145 slotStatusMsg( i18n( "Ready." ) );
148 void KInterface::slotFileOpenRecent(const KURL& url)
150 slotStatusMsg(i18n("Opening file..."));
151 slotStatusMsg(i18n("Ready."));
154 void KInterface::slotFileClose()
156 slotStatusMsg(i18n("Closing file..."));
160 slotStatusMsg(i18n("Ready."));
163 void KInterface::slotFileQuit()
165 slotStatusMsg(i18n("Exiting..."));
166 p_intf->p_sys->p_app->quit();
167 slotStatusMsg(i18n("Ready."));
170 void KInterface::slotViewToolBar()
172 slotStatusMsg(i18n("Toggling toolbar..."));
173 ///////////////////////////////////////////////////////////////////
174 // turn Toolbar on or off
175 if(!viewToolBar->isChecked())
177 toolBar("mainToolBar")->hide();
181 toolBar("mainToolBar")->show();
184 slotStatusMsg(i18n("Ready."));
187 void KInterface::slotViewStatusBar()
189 slotStatusMsg(i18n("Toggle the statusbar..."));
190 ///////////////////////////////////////////////////////////////////
191 //turn Statusbar on or off
192 if(!viewStatusBar->isChecked())
201 slotStatusMsg(i18n("Ready."));
204 void KInterface::slotStatusMsg(const QString &text)
206 ///////////////////////////////////////////////////////////////////
207 // change status message permanently
208 statusBar()->clear();
209 statusBar()->changeItem(text, ID_STATUS_MSG);
212 void KInterface::slotManage()
214 vlc_mutex_lock( &p_intf->change_lock );
216 /* If the "display popup" flag has changed */
217 if( p_intf->b_menu_change )
219 fTitleMenu->popup( ( QCursor::pos() ) );
220 p_intf->b_menu_change = 0;
223 /* Update language/chapter menus after user request */
225 if( fInterface->p_input != NULL && p_intf->p_sys->p_window != NULL &&
226 p_intf->p_sys->b_menus_update )
228 // GnomeSetupMenu( p_intf );
232 /* Manage the slider */
233 if( p_intf->p_input != NULL )
235 #define p_area p_intf->p_input->stream.p_selected_area
236 fSlider->setValue( ( 100 * p_area->i_tell ) / p_area->i_size );
240 /* Manage core vlc functions through the callback */
241 p_intf->pf_manage(p_intf);
245 p_intf->p_sys->p_app->quit();
248 vlc_mutex_unlock( &p_intf->change_lock );
251 void KInterface::slotSliderMoved( int position )
253 // XXX is this locking really useful ?
254 vlc_mutex_lock( &p_intf->change_lock );
256 off_t i_seek = ( position * p_intf->p_input->stream.p_selected_area->i_size ) / 100;
257 input_Seek( p_intf->p_input, i_seek );
259 vlc_mutex_unlock( &p_intf->change_lock );
262 void KInterface::slotSliderChanged( int position )
264 if( p_intf->p_input != NULL )
266 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
268 vlc_mutex_lock( &p_intf->p_input->stream.stream_lock );
270 #define p_area p_intf->p_input->stream.p_selected_area
271 statusBar()->changeItem( input_OffsetToTime( p_intf->p_input, psz_time, ( p_area->i_size * position ) / 100 ), ID_DATE );
274 vlc_mutex_unlock( &p_intf->p_input->stream.stream_lock );
278 void KInterface::slotOpenDisk()
280 int r = fDiskDialog->exec();
285 source += fDiskDialog->type();
287 source += fDiskDialog->device();
289 // Select title and chapter
290 main_PutIntVariable( INPUT_TITLE_VAR, fDiskDialog->title() );
291 main_PutIntVariable( INPUT_CHAPTER_VAR, fDiskDialog->chapter() );
293 // add it to playlist
294 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, source.latin1() );
296 // Select added item and switch to disk interface
297 intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
298 if( p_intf->p_input != NULL )
300 p_intf->p_input->b_eof = 1;
305 void KInterface::slotOpenStream()
307 int r = fNetDialog->exec();
312 source += fNetDialog->protocol();
314 source += fNetDialog->server();
316 source += QString().setNum( fNetDialog->port() );
318 // add it to playlist
319 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, source.latin1() );
320 intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
322 if( p_intf->p_input != NULL )
324 p_intf->p_input->b_eof = 1;
329 void KInterface::slotPlay()
331 if( p_intf->p_input != NULL )
333 input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
337 void KInterface::slotPause()
339 if ( p_intf->p_input != NULL )
341 input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
345 void KInterface::slotStop()
347 if( p_intf->p_input != NULL )
349 /* end playing item */
350 p_intf->p_input->b_eof = 1;
352 /* update playlist */
353 vlc_mutex_lock( &p_main->p_playlist->change_lock );
355 p_main->p_playlist->i_index--;
356 p_main->p_playlist->b_stopped = 1;
358 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
362 void KInterface::slotBackward()
364 intf_ErrMsg( "KInterface::slotBackward() - Unimplemented" );
367 void KInterface::slotPrev()
369 if( p_intf->p_input != NULL )
371 /* FIXME: temporary hack */
372 intf_PlaylistPrev( p_main->p_playlist );
373 intf_PlaylistPrev( p_main->p_playlist );
374 p_intf->p_input->b_eof = 1;
378 void KInterface::slotNext()
380 if( p_intf->p_input != NULL )
382 /* FIXME: temporary hack */
383 p_intf->p_input->b_eof = 1;
387 void KInterface::slotSlow()
389 if( p_intf->p_input != NULL )
391 input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
395 void KInterface::slotFast()
397 if( p_intf->p_input != NULL )
399 input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
403 void KInterface::dragEnterEvent( QDragEnterEvent *event )
405 event->accept( QUriDrag::canDecode( event ) );
408 void KInterface::dropEvent( QDropEvent *event )
412 if ( KURLDrag::decode( event, urlList ) ) {
413 for ( KURL::List::ConstIterator i = urlList.begin(); i != urlList.end(); i++ )
415 // XXX add a private function to add a KURL with checking
416 // actually a whole class for core abstraction would be neat
417 if( !(*i).isEmpty() )
419 fileOpenRecent->addURL( *i );
420 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (*i).path() );