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

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 
0011 #include "k3bdataview.h"
0012 #include "k3bdataburndialog.h"
0013 #include "k3bdatadoc.h"
0014 #include "k3bdataprojectmodel.h"
0015 #include "k3bdataviewimpl.h"
0016 #include "k3bdirproxymodel.h"
0017 
0018 #include <KLocalizedString>
0019 #include <KMessageBox>
0020 #include <KActionCollection>
0021 #include <KToolBar>
0022 
0023 #include <QDebug>
0024 #include <QUrl>
0025 #include <QAction>
0026 #include <QHeaderView>
0027 #include <QTreeView>
0028 #include <QSplitter>
0029 
0030 
0031 K3b::DataView::DataView( K3b::DataDoc* doc, QWidget* parent )
0032 :
0033     View( doc, parent ),
0034     m_doc( doc ),
0035     m_dataViewImpl( new DataViewImpl( this, m_doc, actionCollection() ) ),
0036     m_dirView( new QTreeView( this ) ),
0037     m_dirProxy( new DirProxyModel( this ) )
0038 {
0039     m_dirProxy->setSourceModel( m_dataViewImpl->model() );
0040 
0041     // Dir panel
0042     m_dirView->setRootIsDecorated( false );
0043     m_dirView->setHeaderHidden( true );
0044     m_dirView->setAcceptDrops( true );
0045     m_dirView->setDragEnabled( true );
0046     m_dirView->setDragDropMode( QTreeView::DragDrop );
0047     m_dirView->setSelectionMode( QTreeView::SingleSelection );
0048     m_dirView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
0049     m_dirView->setModel( m_dirProxy );
0050     m_dirView->expandToDepth( 1 ); // Show first-level directories directories by default
0051     m_dirView->setColumnHidden( DataProjectModel::TypeColumn, true );
0052     m_dirView->setColumnHidden( DataProjectModel::SizeColumn, true );
0053 
0054     QSplitter* splitter = new QSplitter( this );
0055     splitter->addWidget( m_dirView );
0056     splitter->addWidget( m_dataViewImpl->view() );
0057     splitter->setStretchFactor( 0, 1 );
0058     splitter->setStretchFactor( 1, 3 );
0059     setMainWidget( splitter );
0060 
0061     // FIXME: always sort folders first in fileview
0062     // FIXME: allow sorting by clicking fileview headers
0063 
0064     connect( actionCollection()->action( "parent_dir" ), SIGNAL(triggered()),
0065              this, SLOT(slotParentDir()) );
0066     connect( m_dirView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
0067              this, SLOT(slotCurrentDirChanged()) );
0068     connect( m_dataViewImpl, SIGNAL(setCurrentRoot(QModelIndex)),
0069              this, SLOT(slotSetCurrentRoot(QModelIndex)) );
0070 
0071     if( m_dirProxy->rowCount() > 0 )
0072         m_dirView->setCurrentIndex( m_dirProxy->index( 0, 0 ) );
0073 
0074     // Setup toolbar
0075     toolBox()->addAction( actionCollection()->action( "project_data_import_session" ) );
0076     toolBox()->addAction( actionCollection()->action( "project_data_clear_imported_session" ) );
0077     toolBox()->addAction( actionCollection()->action( "project_data_edit_boot_images" ) );
0078     toolBox()->addSeparator();
0079     toolBox()->addAction( actionCollection()->action( "parent_dir" ) );
0080     toolBox()->addSeparator();
0081     toolBox()->addActions( createPluginsActions( m_doc->type() ) );
0082     toolBox()->addSeparator();
0083     toolBox()->addAction( actionCollection()->action( "project_volume_name" ) );
0084 
0085     // this is just for testing (or not?)
0086     // most likely every project type will have it's rc file in the future
0087     // we only add the additional actions since View already added the default actions
0088     setXML( "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">"
0089             "<gui name=\"k3bproject\" version=\"1\">"
0090             "<MenuBar>"
0091             " <Menu name=\"project\"><text>&amp;Project</text>"
0092             "  <Action name=\"project_data_import_session\"/>"
0093             "  <Action name=\"project_data_clear_imported_session\"/>"
0094             "  <Action name=\"project_data_edit_boot_images\"/>"
0095             " </Menu>"
0096             "</MenuBar>"
0097             "</gui>", true );
0098 }
0099 
0100 
0101 K3b::DataView::~DataView()
0102 {
0103 }
0104 
0105 
0106 K3b::ProjectBurnDialog* K3b::DataView::newBurnDialog( QWidget* parent )
0107 {
0108     return new DataBurnDialog( m_doc, parent );
0109 }
0110 
0111 
0112 void K3b::DataView::slotBurn()
0113 {
0114     if( m_doc->burningSize() == 0 ) {
0115         KMessageBox::information( this, i18n("Please add files to your project first."),
0116                                   i18n("No Data to Burn") );
0117     }
0118     else {
0119         ProjectBurnDialog* dlg = newBurnDialog( this );
0120         dlg->execBurnDialog(true);
0121         delete dlg;
0122     }
0123 }
0124 
0125 
0126 void K3b::DataView::addUrls( const QList<QUrl>& urls )
0127 {
0128     m_dataViewImpl->addUrls( m_dirProxy->mapToSource( m_dirView->currentIndex() ), urls );
0129 }
0130 
0131 
0132 void K3b::DataView::slotParentDir()
0133 {
0134     m_dirView->setCurrentIndex( m_dirView->currentIndex().parent() );
0135 }
0136 
0137 
0138 void K3b::DataView::slotCurrentDirChanged()
0139 {
0140     QModelIndexList indexes = m_dirView->selectionModel()->selectedRows();
0141     if( indexes.count() ) {
0142         m_dataViewImpl->slotCurrentRootChanged( m_dirProxy->mapToSource( indexes.first() ) );
0143     }
0144 }
0145 
0146 
0147 void K3b::DataView::slotSetCurrentRoot( const QModelIndex& index )
0148 {
0149     m_dirView->setCurrentIndex( m_dirProxy->mapFromSource( index ) );
0150 }
0151 
0152 #include "moc_k3bdataview.cpp"