summaryrefslogtreecommitdiffstats
path: root/src/rip/videodvd/k3bvideodvdrippingview.cpp
blob: 6ecc0767d08c4c66efa24a9501636f94fbfa57c3 (plain)
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
/*
 *
 * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
 * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * 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.
 */

#include "k3bvideodvdrippingview.h"
#include "k3bvideodvdrippingtitlelistview.h"
#include "k3bvideodvdrippingdialog.h"

#include <k3bvideodvd.h>
#include <k3bvideodvdtitletranscodingjob.h>
#include <k3btoolbox.h>
#include <k3bthememanager.h>
#include <k3bglobals.h>
#include <k3blibdvdcss.h>
#include <k3bcore.h>
#include <k3bexternalbinmanager.h>

#include <tqcursor.h>
#include <layout.h>
#include <tqlabel.h>

#include <kapplication.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kaction.h>
#include <kconfig.h>


K3bVideoDVDRippingView::K3bVideoDVDRippingView( TQWidget* parent, const char * name )
  : K3bMediaContentsView( true,
			  K3bMedium::CONTENT_VIDEO_DVD,
			  K3bDevice::MEDIA_DVD_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 title view
  // ----------------------------------------------------------------------------------
  m_titleView = new K3bVideoDVDRippingTitleListView( mainWidget() );

  connect( m_titleView, TQT_SIGNAL(contextMenu(KListView*, TQListViewItem*, const TQPoint&)),
	   this, TQT_SLOT(slotContextMenu(KListView*, TQListViewItem*, const TQPoint&)) );

  // general layout
  // ----------------------------------------------------------------------------------
  mainGrid->addLayout( toolBoxLayout, 0, 0 );
  mainGrid->addWidget( m_titleView, 1, 0 );


  initActions();

  m_toolBox->addButton( actionCollection()->action("start_rip"), true );

  setLeftPixmap( K3bTheme::MEDIA_LEFT );
  setRightPixmap( K3bTheme::MEDIA_VIDEO );
}


K3bVideoDVDRippingView::~K3bVideoDVDRippingView()
{
}


void K3bVideoDVDRippingView::reloadMedium()
{
  //
  // For VideoDVD reading it is important that the DVD is not mounted
  //
  if( K3b::isMounted( device() ) && !K3b::unmount( device() ) ) {
    KMessageBox::error( this,
			i18n("K3b was unable to unmount device '%1' containing medium '%2'. "
			     "Video DVD ripping will not work if the device is mounted. "
			     "Please unmount manually."),
			i18n("Unmounting failed") );
  }

  //
  // K3bVideoDVD::open does not necessarily fail on encrypted DVDs if dvdcss is not
  // available. Thus, we test the availability of libdvdcss here
  //
  if( device()->copyrightProtectionSystemType() == 1 ) {
    K3bLibDvdCss* css = K3bLibDvdCss::create();
    if( !css ) {
      KMessageBox::error( this, i18n("<p>Unable to read Video DVD contents: Found encrypted Video DVD."
				     "<p>Install <i>libdvdcss</i> to get Video DVD decryption support.") );
      return;
    }
    else
      delete css;
  }

  TQApplication::setOverrideCursor( TQCursor(TQt::WaitCursor) );

  if( m_dvd.open( device() ) ) {
    setTitle( medium().beautifiedVolumeId() + " (" + i18n("Video DVD") + ")" );
    m_labelLength->setText( i18n("%n title", "%n titles", m_dvd.numTitles() ) );
    m_titleView->setVideoDVD( m_dvd );
    TQApplication::restoreOverrideCursor();

    bool transcodeUsable = true;

    if( !k3bcore ->externalBinManager() ->foundBin( "transcode" ) ) {
      KMessageBox::sorry( this,
			  i18n("K3b uses transcode to rip Video DVDs. "
			       "Please make sure it is installed.") );
      transcodeUsable = false;
    }
    else {
      int vc = 0, ac = 0;
      for( int i = 0; i < K3bVideoDVDTitleTranscodingJob::VIDEO_CODEC_NUM_ENTRIES; ++i )
	if( K3bVideoDVDTitleTranscodingJob::transcodeBinaryHasSupportFor( (K3bVideoDVDTitleTranscodingJob::VideoCodec)i ) )
	  ++vc;
      for( int i = 0; i < K3bVideoDVDTitleTranscodingJob::AUDIO_CODEC_NUM_ENTRIES; ++i )
	if( K3bVideoDVDTitleTranscodingJob::transcodeBinaryHasSupportFor( (K3bVideoDVDTitleTranscodingJob::AudioCodec)i ) )
	  ++ac;
      if( !ac || !vc ) {
	KMessageBox::sorry( this,
			    i18n("<p>K3b uses transcode to rip Video DVDs. "
				 "Your installation of transcode (<em>%1</em>) lacks support for any of the "
				 "codecs supported by K3b."
				 "<p>Please make sure it is installed properly.") );
	transcodeUsable = false;
      }
    }

    actionCollection()->action("start_rip")->setEnabled( transcodeUsable );
  }
  else {
    TQApplication::restoreOverrideCursor();

    KMessageBox::error( this, i18n("Unable to read Video DVD contents.") );
  }
}


void K3bVideoDVDRippingView::slotStartRipping()
{
  TQValueList<int> titles;
  int i = 1;
  for( TQListViewItemIterator it( m_titleView ); *it; ++it, ++i )
    if( static_cast<K3bCheckListViewItem*>( *it )->isChecked() )
      titles.append( i );

  if( titles.isEmpty() ) {
    KMessageBox::error( this, i18n("Please select the titles to rip."),
			i18n("No Titles Selected") );
  }
  else {
    K3bVideoDVDRippingDialog dlg( m_dvd, titles, this );
    dlg.exec();
  }
}


void K3bVideoDVDRippingView::slotContextMenu( KListView*, TQListViewItem*, const TQPoint& p )
{
  m_popupMenu->popup(p);
}


void K3bVideoDVDRippingView::slotCheckAll()
{
  for( TQListViewItemIterator it( m_titleView ); it.current(); ++it )
    dynamic_cast<K3bCheckListViewItem*>(it.current())->setChecked(true);
}


void K3bVideoDVDRippingView::slotUncheckAll()
{
  for( TQListViewItemIterator it( m_titleView ); it.current(); ++it )
    dynamic_cast<K3bCheckListViewItem*>(it.current())->setChecked(false);
}


void K3bVideoDVDRippingView::slotCheck()
{
  TQPtrList<TQListViewItem> items( m_titleView->selectedItems() );
  for( TQPtrListIterator<TQListViewItem> it( items );
       it.current(); ++it )
    dynamic_cast<K3bCheckListViewItem*>(it.current())->setChecked(true);
}


void K3bVideoDVDRippingView::slotUncheck()
{
  TQPtrList<TQListViewItem> items( m_titleView->selectedItems() );
  for( TQPtrListIterator<TQListViewItem> it( items );
       it.current(); ++it )
    dynamic_cast<K3bCheckListViewItem*>(it.current())->setChecked(false);
}


void K3bVideoDVDRippingView::initActions()
{
  m_actionCollection = new KActionCollection( this );

  KAction* actionSelectAll = new KAction( i18n("Check All"), 0, 0, TQT_TQOBJECT(this),
					  TQT_SLOT(slotCheckAll()), actionCollection(),
					  "check_all" );
  KAction* actionDeselectAll = new KAction( i18n("Uncheck All"), 0, 0, TQT_TQOBJECT(this),
					    TQT_SLOT(slotUncheckAll()), actionCollection(),
					    "uncheck_all" );
  KAction* actionSelect = new KAction( i18n("Check Track"), 0, 0, TQT_TQOBJECT(this),
				       TQT_SLOT(slotCheck()), actionCollection(),
				       "select_track" );
  KAction* actionDeselect = new KAction( i18n("Uncheck Track"), 0, 0, TQT_TQOBJECT(this),
					 TQT_SLOT(slotUncheck()), actionCollection(),
					 "deselect_track" );
  KAction* actionStartRip = new KAction( i18n("Start Ripping"), "gear", 0, TQT_TQOBJECT(this),
					 TQT_SLOT(slotStartRipping()), m_actionCollection, "start_rip" );

  actionStartRip->setToolTip( i18n("Open the Video DVD ripping dialog") );

  // setup the popup menu
  m_popupMenu = new KActionMenu( actionCollection(), "popup_menu" );
  KAction* separator = new KActionSeparator( 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 );
}


void K3bVideoDVDRippingView::enableInteraction( bool enable )
{
  actionCollection()->action( "start_rip" )->setEnabled( enable );
}


#include "k3bvideodvdrippingview.moc"