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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
/*
*
* $Id: k3bvideocdview.cpp 619556 2007-01-03 17:38:12Z trueg $
* Copyright (C) 2003 Christian Kvasny <[email protected]>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file "COPYING" for the exact licensing terms.
*/
// kde includes
#include <tdeaction.h>
#include <kcutlabel.h>
#include <kdebug.h>
#include <kdialogbase.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <kstandarddirs.h>
#include <kstdaction.h>
// qt includes
#include <tqfont.h>
#include <tqframe.h>
#include <tqheader.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqcursor.h>
#include <tqapplication.h>
// k3b includes
#include "k3bvideocdview.h"
#include "k3bvideocdrippingdialog.h"
#include <k3bdevice.h>
#include <k3bmsf.h>
#include <k3btoc.h>
#include <k3bcore.h>
#include <k3blistview.h>
#include <k3bstdguiitems.h>
#include <k3btoolbox.h>
class K3bVideoCdView::VideoTrackViewItem : public TQListViewItem
{
public:
VideoTrackViewItem( TQListViewItem* parent, TQListViewItem* after )
: TQListViewItem( parent, after )
{
setSelectable( false );
}
VideoTrackViewItem( TQListView* parent, TQListViewItem* after )
: TQListViewItem( parent, after )
{
setSelectable( false );
}
VideoTrackViewItem( TQListViewItem* parent,
const TQString& name,
const TQString& id,
int _trackNumber,
const K3b::Msf& length )
: TQListViewItem( parent )
{
setText( 0, TQString( "%1. %2" ).arg( _trackNumber ).arg( id ) );
setText( 1, name );
if ( length > 0 ) {
setText( 2, length.toString() );
setText( 3, TDEIO::convertSize( length.mode2Form2Bytes() ) );
}
trackNumber = _trackNumber;
setSelectable( false );
}
int trackNumber;
void updateData( const K3bVideoCdInfoResultEntry& resultEntry )
{
setText( 0, TQString( "%1. %2" ).arg( trackNumber ).arg( resultEntry.id ) );
setText( 1, resultEntry.name );
}
};
class K3bVideoCdView::VideoTrackViewCheckItem : public TQCheckListItem
{
public:
VideoTrackViewCheckItem( TQListViewItem* parent,
const TQString& desc )
: TQCheckListItem( parent,
TQString(),
TQCheckListItem::CheckBox )
{
setText( 0, desc );
setOn( true );
}
VideoTrackViewCheckItem( TQListView* parent,
const TQString& desc )
: TQCheckListItem( parent,
TQString(),
TQCheckListItem::CheckBox )
{
setText( 0, desc );
setOn( true );
}
VideoTrackViewCheckItem( VideoTrackViewCheckItem* parent,
const TQString& desc )
: TQCheckListItem( parent,
TQString(),
TQCheckListItem::CheckBox )
{
setText( 0, desc );
setOn( true );
}
void updateData( const K3b::Msf& length, bool form2 = false )
{
setText( 2, length.toString() );
if ( form2 )
setText( 3, TDEIO::convertSize( length.mode2Form2Bytes() ) );
else
setText( 3, TDEIO::convertSize( length.mode2Form1Bytes() ) );
}
};
K3bVideoCdView::K3bVideoCdView( TQWidget* parent, const char *name )
: K3bMediaContentsView( true,
K3bMedium::CONTENT_VIDEO_CD,
K3bDevice::MEDIA_CD_ALL,
K3bDevice::STATE_INCOMPLETE|K3bDevice::STATE_COMPLETE,
parent, name )
{
TQGridLayout * mainGrid = new TQGridLayout( mainWidget() );
// toolbox
// ----------------------------------------------------------------------------------
TQHBoxLayout* toolBoxLayout = new TQHBoxLayout( 0, 0, 0, "toolBoxLayout" );
m_toolBox = new K3bToolBox( mainWidget() );
toolBoxLayout->addWidget( m_toolBox );
TQSpacerItem* spacer = new TQSpacerItem( 10, 10, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
toolBoxLayout->addItem( spacer );
m_labelLength = new TQLabel( mainWidget() );
m_labelLength->setAlignment( int( TQLabel::AlignVCenter | TQLabel::AlignRight ) );
toolBoxLayout->addWidget( m_labelLength );
// the track view
// ----------------------------------------------------------------------------------
m_trackView = new K3bListView( mainWidget() );
m_trackView->setFullWidth( true );
m_trackView->setAllColumnsShowFocus( true );
m_trackView->setSelectionMode( TQListView::Single );
m_trackView->setDragEnabled( true );
m_trackView->addColumn( i18n( "Item Name" ) );
m_trackView->addColumn( i18n( "Extracted Name" ) );
m_trackView->addColumn( i18n( "Length" ) );
m_trackView->addColumn( i18n( "Size" ) );
m_trackView->header() ->setClickEnabled( false );
m_trackView->setItemsRenameable( false );
m_trackView->setRootIsDecorated( true );
connect( m_trackView, TQ_SIGNAL( contextMenu( TDEListView*, TQListViewItem*, const TQPoint& ) ),
this, TQ_SLOT( slotContextMenu( TDEListView*, TQListViewItem*, const TQPoint& ) ) );
connect( m_trackView, TQ_SIGNAL( selectionChanged( TQListViewItem* ) ),
this, TQ_SLOT( slotTrackSelectionChanged( TQListViewItem* ) ) );
connect( m_trackView, TQ_SIGNAL( clicked( TQListViewItem* ) ),
this, TQ_SLOT( slotStateChanged( TQListViewItem* ) ) );
connect( m_trackView, TQ_SIGNAL( spacePressed( TQListViewItem* ) ),
this, TQ_SLOT( slotStateChanged( TQListViewItem* ) ) );
mainGrid->addLayout( toolBoxLayout, 0, 0 );
mainGrid->addWidget( m_trackView, 1, 0 );
initActions();
slotTrackSelectionChanged( 0 );
m_videocdinfo = 0L;
m_videooptions = new K3bVideoCdRippingOptions();
m_contentList.clear();
}
K3bVideoCdView::~K3bVideoCdView()
{
delete m_videocdinfo;
delete m_videooptions;
}
void K3bVideoCdView::reloadMedium()
{
m_toc = medium().toc();
m_trackView->clear();
m_trackView->setEnabled( false );
m_toolBox->setEnabled( false );
TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) );
m_contentList.append( new VideoTrackViewCheckItem( m_trackView, i18n("Video CD MPEG tracks") ) );
m_contentList.append( new VideoTrackViewCheckItem( m_trackView, i18n("Video CD DATA track" ) ) );
( ( VideoTrackViewCheckItem* ) m_contentList[ 0 ] ) ->setOpen( true );
// create a listviewItem for every video track
int index = 0;
m_videocddatasize = 0;
m_videocdmpegsize = 0;
K3b::Msf sequenceSize;
for ( K3bDevice::Toc::const_iterator it = m_toc.begin();
it != m_toc.end(); ++it ) {
if ( index > 0 ) {
K3b::Msf length( ( *it ).length() );
sequenceSize += length;
m_videocdmpegsize += length.mode2Form2Bytes();
( void ) new VideoTrackViewItem( ( VideoTrackViewCheckItem* ) m_contentList[ 0 ], i18n( "Sequence-%1" ).arg( index ), "", index, length );
} else {
K3b::Msf length( ( *it ).length() );
m_videocddatasize += length.mode2Form1Bytes();
( ( VideoTrackViewCheckItem* ) m_contentList[ 1 ] ) ->updateData( length );
( void ) new VideoTrackViewCheckItem( ( VideoTrackViewCheckItem* ) m_contentList[ 1 ], i18n( "Files" ) );
( void ) new VideoTrackViewCheckItem( ( VideoTrackViewCheckItem* ) m_contentList[ 1 ], i18n( "Segments" ) );
}
index++;
}
( ( VideoTrackViewCheckItem* ) m_contentList[ 0 ] ) ->updateData( sequenceSize, true );
m_videooptions ->setVideoCdSource( device()->devicename() );
m_videocdinfo = new K3bVideoCdInfo( this );
m_videocdinfo->info( device()->devicename() );
connect( m_videocdinfo, TQ_SIGNAL( infoFinished( bool ) ),
this, TQ_SLOT( slotVideoCdInfoFinished( bool ) ) );
}
void K3bVideoCdView::slotVideoCdInfoFinished( bool success )
{
if ( success ) {
m_videocdinfoResult = m_videocdinfo->result();
updateDisplay();
}
m_trackView->setEnabled( true );
m_toolBox->setEnabled( true );
TQApplication::restoreOverrideCursor();
}
void K3bVideoCdView::updateDisplay()
{
// update the listview
VideoTrackViewItem * item = ( VideoTrackViewItem* ) m_contentList[ 0 ] ->firstChild();
int index = 0;
while ( item ) {
item->updateData( m_videocdinfoResult.entry( index, K3bVideoCdInfoResult::SEQUENCE ) );
item = ( VideoTrackViewItem* ) item->nextSibling();
index++;
}
VideoTrackViewCheckItem* check_item = ( VideoTrackViewCheckItem* ) m_contentList[ 1 ] ->firstChild();
while ( check_item ) {
if ( check_item->key( 0, false ).compare( i18n( "Files" ) ) == 0 ) {
if ( domTree.setContent( m_videocdinfoResult.xmlData ) ) {
TQDomElement root = domTree.documentElement();
TQDomNode node;
node = root.firstChild();
while ( !node.isNull() ) {
if ( node.isElement() && node.nodeName() == "filesystem" ) {
TQDomElement body = node.toElement();
buildTree( check_item, body );
break;
}
node = node.nextSibling();
}
}
} else {
for ( index = 0; index < m_videocdinfoResult.foundEntries( K3bVideoCdInfoResult::SEGMENT ); index++ ) {
( void ) new VideoTrackViewItem( check_item, m_videocdinfoResult.entry( index, K3bVideoCdInfoResult::SEGMENT ).name, m_videocdinfoResult.entry( index, K3bVideoCdInfoResult::SEGMENT ).id , index + 1, 0 );
}
}
check_item = ( VideoTrackViewCheckItem* ) check_item->nextSibling();
}
if ( !m_videocdinfoResult.volumeId.isEmpty() ) {
TQString description = m_videocdinfoResult.volumeId + " (" + m_videocdinfoResult.type + " " + m_videocdinfoResult.version + ")" ;
setTitle( description );
m_videooptions ->setVideoCdDescription( description );
}
else
setTitle( i18n( "Video CD" ) );
m_labelLength->setText( i18n( "1 track (%1)", "%n tracks (%1)", m_toc.count() ).arg( K3b::Msf( m_toc.length() ).toString() ) );
}
void K3bVideoCdView::initActions()
{
m_actionCollection = new TDEActionCollection( this );
TDEAction* actionSelectAll = KStdAction::selectAll( this, TQ_SLOT( slotSelectAll() ),
m_actionCollection, "select_all" );
TDEAction* actionDeselectAll = KStdAction::deselect( this, TQ_SLOT( slotDeselectAll() ),
m_actionCollection, "deselect_all" );
actionDeselectAll->setText( i18n( "Dese&lect All" ) );
TDEAction* actionSelect = new TDEAction( i18n( "Select Track" ), 0, 0, this,
TQ_SLOT( slotSelect() ), actionCollection(),
"select_track" );
TDEAction* actionDeselect = new TDEAction( i18n( "Deselect Track" ), 0, 0, this,
TQ_SLOT( slotDeselect() ), actionCollection(),
"deselect_track" );
TDEAction* actionStartRip = new TDEAction( i18n( "Start Ripping" ), "system-run", 0, this,
TQ_SLOT( startRip() ), actionCollection(), "start_rip" );
// TODO: set the actions tooltips and whatsthis infos
// setup the popup menu
m_popupMenu = new TDEActionMenu( actionCollection(), "popup_menu" );
TDEAction* separator = new TDEActionSeparator( actionCollection(), "separator" );
m_popupMenu->insert( actionSelect );
m_popupMenu->insert( actionDeselect );
m_popupMenu->insert( actionSelectAll );
m_popupMenu->insert( actionDeselectAll );
m_popupMenu->insert( separator );
m_popupMenu->insert( actionStartRip );
// setup the toolbox
m_toolBox->addButton( actionStartRip, true );
}
void K3bVideoCdView::slotContextMenu( TDEListView*, TQListViewItem*, const TQPoint& p )
{
m_popupMenu->popup( p );
}
void K3bVideoCdView::slotTrackSelectionChanged( TQListViewItem* item )
{
actionCollection() ->action( "select_track" ) ->setEnabled( item != 0 );
actionCollection() ->action( "deselect_track" ) ->setEnabled( item != 0 );
}
void K3bVideoCdView::slotStateChanged( TQListViewItem* item )
{
/* > QT 3.1
if ( !item == 0 && item ->isSelectable() ) {
if ( ( ( VideoTrackViewCheckItem* ) item) ->state() == TQCheckListItem::On)
slotSelect();
else if ( ( ( VideoTrackViewCheckItem* ) item) ->state() == TQCheckListItem::Off)
slotDeselect();
}
*/
if ( !item == 0 && item ->isSelectable() ) {
if ( ( ( VideoTrackViewCheckItem* ) item) ->isOn() )
slotSelect();
else
slotDeselect();
}
}
void K3bVideoCdView::startRip()
{
int selectedItems = 0;
for ( TQListViewItemIterator it( m_trackView ); it.current(); ++it ) {
if ( it.current() ->isSelectable() ) {
if ( ( ( ( VideoTrackViewCheckItem* ) it.current()) ->key( 0, false ).compare( i18n("Video CD MPEG tracks" ) ) == 0 ) && ( ( VideoTrackViewCheckItem* ) it.current() ) ->isOn() ) {
m_videooptions ->setVideoCdRipSequences( true );
selectedItems++;
}
else if ( ( ( ( VideoTrackViewCheckItem* ) it.current()) ->key( 0, false ).compare( i18n("Files" ) ) == 0 ) && ( ( VideoTrackViewCheckItem* ) it.current() ) ->isOn() ) {
m_videooptions ->setVideoCdRipFiles( true );
selectedItems++;
}
else if ( ( ( ( VideoTrackViewCheckItem* ) it.current()) ->key( 0, false ).compare( i18n("Segments" ) ) == 0 ) && ( ( VideoTrackViewCheckItem* ) it.current() ) ->isOn() ) {
m_videooptions ->setVideoCdRipSegments( true );
selectedItems++;
}
}
}
if( selectedItems == 0 ) {
KMessageBox::error( this, i18n("Please select the tracks to rip."), i18n("No Tracks Selected") );
}
else {
unsigned long videocdsize = 0;
// TODO: split SegmentSize and FileSize. Have no infos now
if ( m_videooptions ->getVideoCdRipSegments() || m_videooptions ->getVideoCdRipFiles())
videocdsize += m_videocddatasize;
if ( m_videooptions ->getVideoCdRipSequences() )
videocdsize += m_videocdmpegsize;
kdDebug() << TQString("(K3bVideoCdView::startRip()) m_videooptions ->setVideoCdSize( %1)").arg( videocdsize ) << endl;
m_videooptions ->setVideoCdSize( videocdsize );
K3bVideoCdRippingDialog rip( m_videooptions, this );
rip.exec();
}
}
void K3bVideoCdView::slotSelectAll()
{
for ( TQListViewItemIterator it( m_trackView ); it.current(); ++it )
if ( it.current() ->isSelectable() )
( ( VideoTrackViewCheckItem* ) it.current() ) ->setOn( true );
}
void K3bVideoCdView::slotDeselectAll()
{
for ( TQListViewItemIterator it( m_trackView ); it.current(); ++it )
if ( it.current() ->isSelectable() )
( ( VideoTrackViewCheckItem* ) it.current() ) ->setOn( false );
}
void K3bVideoCdView::slotSelect()
{
if ( TQListViewItem * sel = m_trackView->selectedItem() ) {
( ( VideoTrackViewCheckItem* ) sel) ->setOn( true );
TQListViewItem * item = sel ->firstChild();
while ( item ) {
if ( item ->isSelectable() )
( ( VideoTrackViewCheckItem* ) item) ->setOn( true );
item = item->nextSibling();
}
}
}
void K3bVideoCdView::slotDeselect()
{
if ( TQListViewItem * sel = m_trackView->selectedItem() ) {
( ( VideoTrackViewCheckItem* ) sel) ->setOn( false );
TQListViewItem * item = sel ->firstChild();
while ( item ) {
if ( item ->isSelectable() )
( ( VideoTrackViewCheckItem* ) item) ->setOn( false );
item = item->nextSibling();
}
}
}
void K3bVideoCdView::enableInteraction( bool b )
{
actionCollection()->action( "start_rip" )->setEnabled( b );
}
void K3bVideoCdView::buildTree( TQListViewItem *parentItem, const TQDomElement &parentElement, const TQString& pname )
{
VideoTrackViewItem * thisItem = 0;
TQDomNode node = parentElement.firstChild();
while ( !node.isNull() ) {
if ( node.isElement() && node.nodeName() == "folder" || node.nodeName() == "file" ) {
if ( parentItem == 0 )
thisItem = new VideoTrackViewItem( m_trackView, thisItem );
else
thisItem = new VideoTrackViewItem( parentItem, thisItem );
TQString txt = node.firstChild().toElement().text();
thisItem->setText( 0, txt);
if ( node.nodeName() == "folder" ) {
buildTree( thisItem, node.toElement(), pname + "_" + txt.lower() );
}
else {
thisItem->setText( 1, pname + "_" + txt.lower() );
buildTree( thisItem, node.toElement(), pname );
}
} else if ( node.isElement() && node.nodeName() == "segment-item" || node.nodeName() == "sequence-item" ) {
if ( parentItem == 0 )
thisItem = new VideoTrackViewItem( m_trackView, thisItem );
else
thisItem = new VideoTrackViewItem( parentItem, thisItem );
thisItem->setText( 0, node.toElement().attribute( "src" ) );
buildTree( thisItem, node.toElement() );
}
node = node.nextSibling();
}
}
#include "k3bvideocdview.moc"
|