File: kinterfacemain.cpp

package info (click to toggle)
vlc 0.2.92-8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 7,076 kB
  • ctags: 7,147
  • sloc: ansic: 62,829; cpp: 5,824; sh: 2,469; xml: 2,351; makefile: 1,291; python: 503; perl: 19
file content (401 lines) | stat: -rw-r--r-- 11,654 bytes parent folder | download
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/***************************************************************************
                          kinterfacemain.cpp  -  description
                             -------------------
    begin                : Sun Mar 25 2001
    copyright            : (C) 2001 by andres
    email                : dae@chez.com
 ***************************************************************************/

#include "kdiskdialog.h"
#include "kinterfacemain.h"
#include "knetdialog.h"
#include "ktitlemenu.h"
#include "kvlcslider.h"

#include <iostream>

#include <kaction.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kstdaction.h>
#include <kurl.h>
#include <kurldrag.h>
#include <qcursor.h>
#include <qdragobject.h>
#include <qtimer.h>

#define ID_STATUS_MSG			1
#define ID_DATE							2
#define ID_STREAM_SOURCE	3

KInterfaceMain::KInterfaceMain( intf_thread_t *p_intf, QWidget *parent,
		const char *name ) : KMainWindow(parent,name)
{
	setAcceptDrops(true);

	fInterfaceThread = p_intf;

	fDiskDialog = new KDiskDialog( this );
	fNetDialog = new KNetDialog( this );
	fTitleMenu = new KTitleMenu( fInterfaceThread, this );

	fSlider = new KVLCSlider( QSlider::Horizontal, this );
	connect( fSlider, SIGNAL( userChanged( int ) ), this, SLOT( slotSliderMoved( int ) ) );
	connect( fSlider, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderChanged( int ) ) );
   setCentralWidget(fSlider);

	fTimer = new QTimer( this );
	connect( fTimer, SIGNAL( timeout() ), this, SLOT( slotManage() ) );
	fTimer->start( 100 );

	resize( 400, 30 );

  ///////////////////////////////////////////////////////////////////
  // call inits to invoke all other construction parts
	// XXX could we move this up ?
  initStatusBar();
  initActions();

	// add certain calls to the popup menu
	fileOpen->plug( fTitleMenu );
	fileOpenRecent->plug( fTitleMenu );
	diskOpen->plug( fTitleMenu );
	streamOpen->plug( fTitleMenu );
	play->plug( fTitleMenu );
	pause->plug( fTitleMenu );
	slow->plug( fTitleMenu );
	fast->plug( fTitleMenu );
	fileClose->plug( fTitleMenu );
	fileQuit->plug( fTitleMenu );
}

KInterfaceMain::~KInterfaceMain()
{
}

void KInterfaceMain::initActions()
{
	fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection());
	fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection());
	fileClose = KStdAction::close(this, SLOT(slotFileClose()), actionCollection());
	fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection());
	viewToolBar = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), actionCollection());
	viewStatusBar = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), actionCollection());

	diskOpen = new KAction( i18n( "Open &Disk" ), 0, 0, this, SLOT( slotOpenDisk() ), actionCollection(), "open_disk" );
	streamOpen = new KAction( i18n( "Open &Stream" ), 0, 0, this, SLOT( slotOpenStream() ), actionCollection(), "open_stream" );
	play = new KAction( i18n( "&Play" ), 0, 0, this, SLOT( slotPlay() ), actionCollection(), "play" );
	pause = new KAction( i18n( "P&ause" ), 0, 0, this, SLOT( slotPause() ), actionCollection(), "pause" );
	stop = new KAction( i18n( "&Stop" ), 0, 0, this, SLOT( slotStop() ), actionCollection(), "stop" );
	backward = new KAction( i18n( "&Backward" ), 0, 0, this, SLOT( slotBackward() ), actionCollection(), "backward" );
	forward = new KAction( i18n( "&Forward" ), 0, 0, this, SLOT( slotForward() ), actionCollection(), "forward" );
	slow = new KAction( i18n( "&Slow" ), 0, 0, this, SLOT( slotSlow() ), actionCollection(), "slow" );
	fast = new KAction( i18n( "Fas&t" ), 0, 0, this, SLOT( slotFast() ), actionCollection(), "fast" );

	fileOpen->setStatusText(i18n("Opens an existing document"));
	fileOpenRecent->setStatusText(i18n("Opens a recently used file"));
	fileClose->setStatusText(i18n("Closes the actual document"));
	fileQuit->setStatusText(i18n("Quits the application"));
	viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
	viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));

	diskOpen->setStatusText( i18n( "Opens a disk") );
	streamOpen->setStatusText( i18n( "Opens a network stream" ) );
	play->setStatusText( i18n( "Starts playback" ) );
	pause->setStatusText( i18n( "Pauses playback" ) );
	stop->setStatusText( i18n( "Stops playback" ) );
	backward->setStatusText( i18n( "Backward" ) );
	forward->setStatusText( i18n( "Forward" ) );
	slow->setStatusText( i18n( "Slow" ) );
	fast->setStatusText( i18n( "Fast" ) );
	// use the absolute path to your ktestui.rc file for testing purpose in createGUI();

	createGUI("plugins/kde/kvlcui.rc");
}

void KInterfaceMain::initStatusBar()
{
  ///////////////////////////////////////////////////////////////////
  // STATUSBAR
  // TODO: add your own items you need for displaying current application status.
	statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG, 1, false);
	statusBar()->setItemAlignment( ID_STATUS_MSG, AlignLeft | AlignVCenter );
	statusBar()->insertItem( "0:00:00", ID_DATE, 0, true );
}

/////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATION
/////////////////////////////////////////////////////////////////////

void KInterfaceMain::slotFileOpen()
{
	slotStatusMsg( i18n( "Opening file..." ) );
	KURL url=KFileDialog::getOpenURL( QString::null,
			i18n( "*|All files" ), this, i18n( "Open File..." ) );

	if( !url.isEmpty() )
	{
		fileOpenRecent->addURL( url );
		intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, url.path() );
	}

	slotStatusMsg( i18n( "Ready." ) );
}

void KInterfaceMain::slotFileOpenRecent(const KURL& url)
{
  slotStatusMsg(i18n("Opening file..."));
  slotStatusMsg(i18n("Ready."));
}

void KInterfaceMain::slotFileClose()
{
  slotStatusMsg(i18n("Closing file..."));
	
  close();

  slotStatusMsg(i18n("Ready."));
}

void KInterfaceMain::slotFileQuit()
{
	slotStatusMsg(i18n("Exiting..."));
	slotStatusMsg(i18n("Ready."));
}

void KInterfaceMain::slotViewToolBar()
{
  slotStatusMsg(i18n("Toggling toolbar..."));
  ///////////////////////////////////////////////////////////////////
  // turn Toolbar on or off
  if(!viewToolBar->isChecked())
  {
    toolBar("mainToolBar")->hide();
  }
  else
  {
    toolBar("mainToolBar")->show();
  }		

  slotStatusMsg(i18n("Ready."));
}

void KInterfaceMain::slotViewStatusBar()
{
  slotStatusMsg(i18n("Toggle the statusbar..."));
  ///////////////////////////////////////////////////////////////////
  //turn Statusbar on or off
  if(!viewStatusBar->isChecked())
  {
    statusBar()->hide();
  }
  else
  {
    statusBar()->show();
  }

  slotStatusMsg(i18n("Ready."));
}

void KInterfaceMain::slotStatusMsg(const QString &text)
{
  ///////////////////////////////////////////////////////////////////
  // change status message permanently
  statusBar()->clear();
  statusBar()->changeItem(text, ID_STATUS_MSG);
}

void KInterfaceMain::slotManage()
{
	vlc_mutex_lock( &fInterfaceThread->change_lock );

    /* If the "display popup" flag has changed */
	if( fInterfaceThread->b_menu_change )
	{
		fTitleMenu->popup( ( QCursor::pos() ) );
		fInterfaceThread->b_menu_change = 0;
	}

    /* Update language/chapter menus after user request */
//    if( fInterface->p_input != NULL && p_intf->p_sys->p_window != NULL &&
//        p_intf->p_sys->b_menus_update )
//    {
////        GnomeSetupMenu( p_intf );
//    }

    /* Manage the slider */
	if( fInterfaceThread->p_input != NULL )
	{
#define p_area fInterfaceThread->p_input->stream.p_selected_area
		fSlider->setValue( ( 100 * p_area->i_tell ) / p_area->i_size );
#undef p_area
    }

	/* Manage core vlc functions through the callback */
	fInterfaceThread->pf_manage(fInterfaceThread);

	if( fInterfaceThread->b_die )
	{
		cerr << "we shoud die\n";
	}

	vlc_mutex_unlock( &fInterfaceThread->change_lock );
}

void KInterfaceMain::slotSliderMoved( int position )
{
// XXX is this locking really useful ?
	vlc_mutex_lock( &fInterfaceThread->change_lock );

	off_t i_seek = ( position * fInterfaceThread->p_input->stream.p_selected_area->i_size ) / 100;
	input_Seek( fInterfaceThread->p_input, i_seek );

	vlc_mutex_unlock( &fInterfaceThread->change_lock );
}

void KInterfaceMain::slotSliderChanged( int position )
{
		if( fInterfaceThread->p_input != NULL )
		{
		char psz_time[ OFFSETTOTIME_MAX_SIZE ];

		vlc_mutex_lock( &fInterfaceThread->p_input->stream.stream_lock );

#define p_area fInterfaceThread->p_input->stream.p_selected_area
		statusBar()->changeItem( input_OffsetToTime( fInterfaceThread->p_input, psz_time, ( p_area->i_size * position ) / 100 ), ID_DATE );
#undef p_area

        vlc_mutex_unlock( &fInterfaceThread->p_input->stream.stream_lock );
     }
}

void KInterfaceMain::slotOpenDisk()
{
	int r = fDiskDialog->exec();
	if ( r )
	{
		// Build source name
		QString source;
		source += fDiskDialog->type();
		source += ':';
		source += fDiskDialog->device();

		// Select title and chapter
		main_PutIntVariable( INPUT_TITLE_VAR, fDiskDialog->title() );
		main_PutIntVariable( INPUT_CHAPTER_VAR, fDiskDialog->chapter() );

		// add it to playlist
		intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, source.latin1() );

		// Select added item and switch to disk interface
		intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );
		if( fInterfaceThread->p_input != NULL )
		{
			fInterfaceThread->p_input->b_eof = 1;
		}
	}
}

void KInterfaceMain::slotOpenStream()
{
	int r = fNetDialog->exec();
	if ( r )
	{
		// Build source name
		QString source;
		source += fNetDialog->protocol();
		source += "://";
		source += fNetDialog->server();
		source += ":";
		source += QString().setNum( fNetDialog->port() );

		// add it to playlist
		intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, source.latin1() );
		intf_PlaylistJumpto( p_main->p_playlist, p_main->p_playlist->i_size-2 );

		if( fInterfaceThread->p_input != NULL )
		{
			fInterfaceThread->p_input->b_eof = 1;
		}
	}
}

void KInterfaceMain::slotPlay()
{
	if( fInterfaceThread->p_input != NULL )
	{
		input_SetStatus( fInterfaceThread->p_input, INPUT_STATUS_PLAY );
	}
}

void KInterfaceMain::slotPause()
{
	if ( fInterfaceThread->p_input != NULL )
	{
		input_SetStatus( fInterfaceThread->p_input, INPUT_STATUS_PAUSE );
	}
}

void KInterfaceMain::slotStop()
{
	cerr << "KInterfaceMain::slotStop() - Unimplemented\n";
}

void KInterfaceMain::slotBackward()
{
    if( fInterfaceThread->p_input != NULL )
    {
        /* FIXME: temporary hack */
        intf_PlaylistPrev( p_main->p_playlist );
        intf_PlaylistPrev( p_main->p_playlist );
        fInterfaceThread->p_input->b_eof = 1;
    }
}

void KInterfaceMain::slotForward()
{
	if( fInterfaceThread->p_input != NULL )
	{
		/* FIXME: temporary hack */
		fInterfaceThread->p_input->b_eof = 1;
	}
}

void KInterfaceMain::slotSlow()
{
	if( fInterfaceThread->p_input != NULL )
	{
		input_SetStatus( fInterfaceThread->p_input, INPUT_STATUS_SLOWER );
	}
}

void KInterfaceMain::slotFast()
{
	if( fInterfaceThread->p_input != NULL )
	{
		input_SetStatus( fInterfaceThread->p_input, INPUT_STATUS_FASTER );
	}
}

void KInterfaceMain::dragEnterEvent( QDragEnterEvent *event )
{
	event->accept( QUriDrag::canDecode( event ) );
}

void KInterfaceMain::dropEvent( QDropEvent *event )
{
	KURL::List urlList;

	if ( KURLDrag::decode( event, urlList ) ) {
		for ( KURL::List::ConstIterator i = urlList.begin(); i != urlList.end(); i++ )
		{
			// XXX add a private function to add a KURL with checking
			// actually a whole class for core abstraction would be neat
			if( !(*i).isEmpty() )
			{
				fileOpenRecent->addURL( *i );
				intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (*i).path() );
			}
		}
	}
}