File indexing completed on 2024-05-05 04:51:49
0001 /* 0002 SPDX-FileCopyrightText: 2003-2004 Christian Kvasny <chris@k3b.org> 0003 SPDX-FileCopyrightText: 2009 Arthur Renato Mello <arthur@mandriva.com> 0004 SPDX-FileCopyrightText: 2009-2010 Michal Malek <michalm@jabster.pl> 0005 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "k3bvcdview.h" 0011 #include "k3bvcdprojectmodel.h" 0012 #include "k3bvcddoc.h" 0013 #include "k3bvcdburndialog.h" 0014 #include "k3bvcdtrackdialog.h" 0015 #include "k3bfillstatusdisplay.h" 0016 #include "k3bexternalbinmanager.h" 0017 #include "k3bcore.h" 0018 #include "k3baction.h" 0019 0020 #include <KLocalizedString> 0021 #include <KMessageBox> 0022 0023 #include <QDebug> 0024 #include <QItemSelectionModel> 0025 #include <QString> 0026 #include <QAction> 0027 #include <QHeaderView> 0028 #include <QLayout> 0029 #include <QTreeView> 0030 0031 K3b::VcdView::VcdView( K3b::VcdDoc* doc, QWidget* parent ) 0032 : 0033 View( doc, parent ), 0034 m_doc( doc ), 0035 m_model( new K3b::VcdProjectModel( m_doc, this ) ), 0036 m_view( new QTreeView( this ) ) 0037 { 0038 m_view->setModel( m_model ); 0039 m_view->setAcceptDrops( true ); 0040 m_view->setDragEnabled( true ); 0041 m_view->setDragDropMode( QTreeView::DragDrop ); 0042 m_view->setItemsExpandable( false ); 0043 m_view->setRootIsDecorated( false ); 0044 m_view->setSelectionMode( QTreeView::ExtendedSelection ); 0045 m_view->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); 0046 m_view->setContextMenuPolicy( Qt::ActionsContextMenu ); 0047 // FIXME: make QHeaderView::Interactive the default but connect to model changes and call header()->resizeSections( QHeaderView::ResizeToContents ); 0048 m_view->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); 0049 m_view->setEditTriggers( QAbstractItemView::NoEditTriggers ); 0050 setMainWidget( m_view ); 0051 0052 // setup actions 0053 m_actionProperties = K3b::createAction( this, i18n("Properties"), "document-properties", 0054 0, this, SLOT(slotProperties()), 0055 actionCollection(), "vcd_show_props" ); 0056 0057 m_actionRemove = K3b::createAction( this, i18n( "Remove" ), "edit-delete", 0058 Qt::Key_Delete, this, SLOT(slotRemove()), 0059 actionCollection(), "vcd_remove_track" ); 0060 0061 connect( m_view, SIGNAL(doubleClicked(QModelIndex)), 0062 this, SLOT(slotItemActivated(QModelIndex)) ); 0063 connect( m_view->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), 0064 this, SLOT(slotSelectionChanged()) ); 0065 0066 QAction* separator = new QAction( this ); 0067 separator->setSeparator( true ); 0068 m_view->addAction( m_actionRemove ); 0069 m_view->addAction( separator ); 0070 m_view->addAction( m_actionProperties ); 0071 m_view->addAction( separator ); 0072 m_view->addAction( actionCollection()->action("project_burn") ); 0073 } 0074 0075 0076 K3b::VcdView::~VcdView() 0077 { 0078 } 0079 0080 0081 K3b::ProjectBurnDialog* K3b::VcdView::newBurnDialog( QWidget * parent) 0082 { 0083 return new K3b::VcdBurnDialog( m_doc, parent ); 0084 } 0085 0086 0087 void K3b::VcdView::init() 0088 { 0089 if( !k3bcore->externalBinManager()->foundBin( "vcdxbuild" ) ) { 0090 qDebug() << "(K3b::VcdView) could not find vcdxbuild executable"; 0091 KMessageBox::information( this, 0092 i18n( "Could not find VcdImager executable. " 0093 "To create Video CDs you have to install VcdImager >= 0.7.12. " 0094 "You can find this on your distribution’s software repository or download " 0095 "it from https://www.gnu.org/software/vcdimager/" ) ); 0096 } 0097 } 0098 0099 0100 void K3b::VcdView::slotSelectionChanged() 0101 { 0102 const QModelIndexList selected = m_view->selectionModel()->selectedRows(); 0103 if( !selected.isEmpty() ) { 0104 m_actionRemove->setEnabled( true ); 0105 } 0106 else { 0107 m_actionRemove->setEnabled( false ); 0108 } 0109 } 0110 0111 0112 void K3b::VcdView::slotProperties() 0113 { 0114 const QModelIndexList selection = m_view->selectionModel()->selectedRows(); 0115 0116 if( selection.isEmpty() ) { 0117 // show project properties 0118 View::slotProperties(); 0119 } 0120 else { 0121 QList<K3b::VcdTrack*> selected; 0122 0123 Q_FOREACH( const QModelIndex& index, selection ) { 0124 selected.append( m_model->trackForIndex(index) ); 0125 } 0126 0127 QList<K3b::VcdTrack*> tracks = *m_doc->tracks(); 0128 0129 K3b::VcdTrackDialog dlg( m_doc, tracks, selected, this ); 0130 dlg.exec(); 0131 } 0132 } 0133 0134 0135 void K3b::VcdView::slotRemove() 0136 { 0137 const QModelIndexList selected = m_view->selectionModel()->selectedRows(); 0138 0139 // create a list of persistent model indexes to be able to remove all of them 0140 QList<QPersistentModelIndex> indexes; 0141 Q_FOREACH( const QModelIndex& index, selected ) { 0142 indexes.append( QPersistentModelIndex( index ) ); 0143 } 0144 0145 // and now ask the indexes to be removed 0146 Q_FOREACH( const QPersistentModelIndex& index, indexes ) { 0147 m_model->removeRow( index.row(), index.parent() ); 0148 } 0149 } 0150 0151 0152 void K3b::VcdView::slotItemActivated( const QModelIndex& index ) 0153 { 0154 if( VcdTrack* track = m_model->trackForIndex( index ) ) { 0155 QList<VcdTrack*> tracks = *m_doc->tracks(); 0156 QList<VcdTrack*> selected; 0157 selected.append( track ); 0158 K3b::VcdTrackDialog dlg( m_doc, tracks, selected, this ); 0159 dlg.exec(); 0160 } 0161 } 0162 0163 #include "moc_k3bvcdview.cpp"