File indexing completed on 2024-05-05 04:51:46

0001 /*
0002     SPDX-FileCopyrightText: 2003-2008 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-FileCopyrightText: 2009 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
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 "k3bmixedview.h"
0011 #include "k3baudiodoc.h"
0012 #include "k3baudioprojectmodel.h"
0013 #include "k3baudioviewimpl.h"
0014 #include "k3bdatadoc.h"
0015 #include "k3bdataprojectmodel.h"
0016 #include "k3bdataviewimpl.h"
0017 #include "k3bdirproxymodel.h"
0018 #include "k3bmetaitemmodel.h"
0019 #include "k3bmixeddoc.h"
0020 #include "k3bmixedburndialog.h"
0021 
0022 #include "config-k3b.h"
0023 #ifdef ENABLE_AUDIO_PLAYER
0024 #include "k3baudiotrackplayer.h"
0025 #endif // ENABLE_AUDIO_PLAYER
0026 
0027 #include <KLocalizedString>
0028 #include <KMessageBox>
0029 #include <KActionCollection>
0030 #include <KToolBar>
0031 
0032 #include <QDebug>
0033 #include <QAction>
0034 #include <QSplitter>
0035 #include <QStackedWidget>
0036 #include <QTreeView>
0037 
0038 K3b::MixedView::MixedView( K3b::MixedDoc* doc, QWidget* parent )
0039 :
0040     View( doc, parent ),
0041     m_doc( doc ),
0042     m_audioViewImpl( new AudioViewImpl( this, m_doc->audioDoc(), actionCollection() ) ),
0043     m_dataViewImpl( new DataViewImpl( this, m_doc->dataDoc(), actionCollection() ) ),
0044     m_model( new MetaItemModel( this ) ),
0045     m_dirProxy( new DirProxyModel( this ) ),
0046     m_dirView( new QTreeView( this ) ),
0047     m_fileViewWidget( new QStackedWidget( this ) )
0048 {
0049     m_model->addSubModel( i18n("Audio Section"), QIcon::fromTheme("media-optical-audio"), m_audioViewImpl->model() );
0050     m_model->addSubModel( i18n("Data Section"), QIcon::fromTheme("media-optical-data"), m_dataViewImpl->model(), true );
0051     m_dirProxy->setSourceModel( m_model );
0052 
0053     // Dir panel
0054     m_dirView->setRootIsDecorated( false );
0055     m_dirView->setHeaderHidden( true );
0056     m_dirView->setAcceptDrops( true );
0057     m_dirView->setDragEnabled( true );
0058     m_dirView->setDragDropMode( QTreeView::DragDrop );
0059     m_dirView->setSelectionMode( QTreeView::SingleSelection );
0060     m_dirView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
0061     m_dirView->setModel( m_dirProxy );
0062     m_dirView->expandToDepth( 1 ); // Show first-level directories directories by default
0063 
0064     m_fileViewWidget->addWidget( m_dataViewImpl->view() );
0065     m_fileViewWidget->addWidget( m_audioViewImpl->view() );
0066 
0067     QSplitter* splitter = new QSplitter( this );
0068     splitter->addWidget( m_dirView );
0069     splitter->addWidget( m_fileViewWidget );
0070     splitter->setStretchFactor( 0, 1 );
0071     splitter->setStretchFactor( 1, 3 );
0072     setMainWidget( splitter );
0073 
0074     connect( actionCollection()->action( "parent_dir" ), SIGNAL(triggered()),
0075              this, SLOT(slotParentDir()) );
0076     connect( m_dirView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
0077              this, SLOT(slotCurrentDirChanged()) );
0078 #ifdef ENABLE_AUDIO_PLAYER
0079     connect( m_audioViewImpl->player(), SIGNAL(stateChanged()),
0080              this, SLOT(slotUpdateActions()) );
0081 #endif // ENABLE_AUDIO_PLAYER
0082     connect( m_dataViewImpl, SIGNAL(setCurrentRoot(QModelIndex)),
0083              this, SLOT(slotSetCurrentRoot(QModelIndex)) );
0084 
0085     // Setup toolbar
0086     m_audioActions.push_back( actionCollection()->action( "project_audio_convert" ) );
0087     m_audioActions += createPluginsActions( doc->audioDoc()->type() );
0088 
0089     QList<QAction*> playerActions;
0090 #ifdef ENABLE_AUDIO_PLAYER
0091     playerActions.push_back( actionCollection()->action( "player_previous" ) );
0092     playerActions.push_back( actionCollection()->action( "player_play" ) );
0093     playerActions.push_back( actionCollection()->action( "player_pause" ) );
0094     playerActions.push_back( actionCollection()->action( "player_stop" ) );
0095     playerActions.push_back( actionCollection()->action( "player_next" ) );
0096     playerActions.push_back( actionCollection()->action( "player_seek" ) );
0097 #endif // ENABLE_AUDIO_PLAYER
0098 
0099     m_dataActions.push_back( actionCollection()->action( "parent_dir" ) );
0100     m_dataActions += createPluginsActions( doc->dataDoc()->type() );
0101 
0102     toolBox()->addActions( m_audioActions );
0103     toolBox()->addSeparator();
0104     toolBox()->addActions( playerActions );
0105     toolBox()->addSeparator();
0106     toolBox()->addActions( m_dataActions );
0107     toolBox()->addSeparator();
0108     toolBox()->addAction( actionCollection()->action( "project_volume_name" ) );
0109     m_dataActions.push_back( actionCollection()->action( "project_volume_name" ) );
0110 
0111     m_audioActions += playerActions;
0112 
0113     if( m_dirProxy->rowCount() > 0 )
0114         m_dirView->setCurrentIndex( m_dirProxy->index( 0, 0 ) );
0115 }
0116 
0117 
0118 K3b::MixedView::~MixedView()
0119 {
0120 }
0121 
0122 
0123 void K3b::MixedView::slotBurn()
0124 {
0125     if( m_doc->audioDoc()->numOfTracks() == 0 || m_doc->dataDoc()->size() == 0 ) {
0126         KMessageBox::information( this, i18n("Please add files and audio titles to your project first."),
0127                                   i18n("No Data to Burn") );
0128     }
0129     else {
0130         K3b::ProjectBurnDialog* dlg = newBurnDialog( this );
0131         if( dlg ) {
0132             dlg->execBurnDialog(true);
0133             delete dlg;
0134         }
0135         else {
0136             qDebug() << "(K3b::Doc) Error: no burndialog available.";
0137         }
0138     }
0139 }
0140 
0141 
0142 void K3b::MixedView::addUrls( const QList<QUrl>& urls )
0143 {
0144     if( m_fileViewWidget->currentWidget() == m_dataViewImpl->view() ) {
0145         QModelIndex parent = m_model->mapToSubModel( m_dirProxy->mapToSource( m_dirView->currentIndex() ) );
0146         m_dataViewImpl->addUrls( parent, urls );
0147     }
0148     else if( m_fileViewWidget->currentWidget() == m_audioViewImpl->view() ) {
0149         m_audioViewImpl->addUrls( urls );
0150     }
0151 }
0152 
0153 
0154 void K3b::MixedView::slotParentDir()
0155 {
0156     m_dirView->setCurrentIndex( m_dirView->currentIndex().parent() );
0157 }
0158 
0159 
0160 void K3b::MixedView::slotCurrentDirChanged()
0161 {
0162     QModelIndex newRoot = m_dirProxy->mapToSource( m_dirView->currentIndex() );
0163 
0164     QAbstractItemModel* currentSubModel = m_model->subModelForIndex( newRoot );
0165 
0166     if( currentSubModel == m_dataViewImpl->model() ) {
0167         m_dataViewImpl->slotCurrentRootChanged( m_model->mapToSubModel( newRoot ) );
0168         if( m_fileViewWidget->currentWidget() != m_dataViewImpl->view() ) {
0169             m_fileViewWidget->setCurrentWidget( m_dataViewImpl->view() );
0170         }
0171     }
0172     else if( currentSubModel == m_audioViewImpl->model() ) {
0173         if( m_fileViewWidget->currentWidget() != m_audioViewImpl->view() ) {
0174             m_fileViewWidget->setCurrentWidget( m_audioViewImpl->view() );
0175         }
0176     }
0177     slotUpdateActions();
0178 }
0179 
0180 
0181 void K3b::MixedView::slotUpdateActions()
0182 {
0183     if( m_fileViewWidget->currentWidget() == m_dataViewImpl->view() ) {
0184         Q_FOREACH( QAction* action, m_dataActions ) {
0185             action->setVisible( true );
0186         }
0187         Q_FOREACH( QAction* action, m_audioActions ) {
0188             action->setVisible( false );
0189         }
0190     }
0191     else if( m_fileViewWidget->currentWidget() == m_audioViewImpl->view() ) {
0192         Q_FOREACH( QAction* action, m_dataActions ) {
0193             action->setVisible( false );
0194         }
0195         Q_FOREACH( QAction* action, m_audioActions ) {
0196             action->setVisible( true );
0197         }
0198 
0199 #ifdef ENABLE_AUDIO_PLAYER
0200         if( m_audioViewImpl->player()->state() == AudioTrackPlayer::Playing ) {
0201             actionCollection()->action( "player_play" )->setVisible( false );
0202         }
0203         else {
0204             actionCollection()->action( "player_pause" )->setVisible( false );
0205         }
0206 #endif // ENABLE_AUDIO_PLAYER
0207     }
0208 }
0209 
0210 
0211 void K3b::MixedView::slotSetCurrentRoot( const QModelIndex& index )
0212 {
0213     m_dirView->setCurrentIndex( m_dirProxy->mapFromSource( m_model->mapFromSubModel( index ) ) );
0214 }
0215 
0216 
0217 K3b::ProjectBurnDialog* K3b::MixedView::newBurnDialog( QWidget* parent )
0218 {
0219     return new K3b::MixedBurnDialog( m_doc, parent );
0220 }
0221 
0222 #include "moc_k3bmixedview.cpp"