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

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 // application specific includes
0008 #include "k3bview.h"
0009 #include "k3bdoc.h"
0010 #include "k3bfillstatusdisplay.h"
0011 #include "k3bprojectburndialog.h"
0012 #include "k3bprojectplugindialog.h"
0013 #include "k3bpluginmanager.h"
0014 #include "k3bprojectplugin.h"
0015 #include "k3bcore.h"
0016 #include "k3baction.h"
0017 
0018 #include <KLocalizedString>
0019 #include <KMessageBox>
0020 #include <KToolBar>
0021 
0022 #include <QDebug>
0023 #include <QList>
0024 #include <QAction>
0025 #include <QVBoxLayout>
0026 
0027 K3b::View::View( K3b::Doc* pDoc, QWidget *parent )
0028     : QWidget( parent ),
0029       m_doc( pDoc )
0030 {
0031     m_toolBox = new KToolBar( this );
0032     m_fillStatusDisplay = new K3b::FillStatusDisplay( m_doc, this );
0033 
0034     QVBoxLayout* fillStatusDisplayLayout = new QVBoxLayout;
0035     fillStatusDisplayLayout->addWidget( m_fillStatusDisplay );
0036     fillStatusDisplayLayout->setContentsMargins( 0, 5, 0, 0 );
0037 
0038     m_layout = new QVBoxLayout( this );
0039     m_layout->addWidget( m_toolBox );
0040     m_layout->addLayout( fillStatusDisplayLayout );
0041     m_layout->setSpacing( 0 );
0042     m_layout->setContentsMargins( 0, 0, 0, 0 );
0043 
0044     QAction* burnAction = K3b::createAction(this,i18n("&Burn"), "tools-media-optical-burn", Qt::CTRL + Qt::Key_B, this, SLOT(slotBurn()),
0045                                             actionCollection(), "project_burn");
0046     burnAction->setToolTip( i18n("Open the burn dialog for the current project") );
0047     QAction* propAction = K3b::createAction(this, i18n("&Properties"), "document-properties", Qt::CTRL + Qt::Key_P, this, SLOT(slotProperties()),
0048                                             actionCollection(), "project_properties");
0049     propAction->setToolTip( i18n("Open the properties dialog") );
0050 
0051     m_toolBox->addAction( burnAction/*, true*/ );
0052     m_toolBox->addSeparator();
0053 
0054     // this is just for testing (or not?)
0055     // most likely every project type will have it's rc file in the future
0056     setXML( "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">"
0057             "<gui name=\"k3bproject\" version=\"1\">"
0058             "<MenuBar>"
0059             " <Menu name=\"project\"><text>&amp;Project</text>"
0060             "  <Action name=\"project_burn\"/>"
0061             "  <Action name=\"project_properties\"/>"
0062             " </Menu>"
0063             "</MenuBar>"
0064             "</gui>", true );
0065 }
0066 
0067 K3b::View::~View()
0068 {
0069 }
0070 
0071 
0072 void K3b::View::setMainWidget( QWidget* w )
0073 {
0074     m_layout->insertWidget( 1, w, 1 );
0075 }
0076 
0077 
0078 void K3b::View::slotBurn()
0079 {
0080     if( m_doc->numOfTracks() == 0 || m_doc->size() == 0 ) {
0081         KMessageBox::information( this, i18n("Please add files to your project first."),
0082                                   i18n("No Data to Burn") );
0083     }
0084     else {
0085         K3b::ProjectBurnDialog* dlg = newBurnDialog( this );
0086         if( dlg ) {
0087             dlg->execBurnDialog(true);
0088             delete dlg;
0089         }
0090         else {
0091             qDebug() << "(K3b::Doc) Error: no burndialog available.";
0092         }
0093     }
0094 }
0095 
0096 
0097 void K3b::View::slotProperties()
0098 {
0099     K3b::ProjectBurnDialog* dlg = newBurnDialog( this );
0100     if( dlg ) {
0101         dlg->execBurnDialog(false);
0102         delete dlg;
0103     }
0104     else {
0105         qDebug() << "(K3b::Doc) Error: no burndialog available.";
0106     }
0107 }
0108 
0109 
0110 QList<QAction*> K3b::View::createPluginsActions( Doc::Type docType )
0111 {
0112     QList<QAction*> actions;
0113     Q_FOREACH( Plugin* plugin, k3bcore->pluginManager()->plugins( "ProjectPlugin" ) ) {
0114         ProjectPlugin* pp = dynamic_cast<ProjectPlugin*>( plugin );
0115         if( pp && pp->type().testFlag( docType) ) {
0116             QAction* action = new QAction( pp->icon(), pp->text(), this );
0117             action->setToolTip( pp->toolTip() );
0118             action->setWhatsThis( pp->whatsThis() );
0119             connect( action, SIGNAL(triggered(bool)),
0120                      this, SLOT(slotPluginButtonClicked()) );
0121             actions.push_back( action );
0122             m_plugins.insert( action, pp );
0123         }
0124     }
0125     return actions;
0126 }
0127 
0128 
0129 void K3b::View::slotPluginButtonClicked()
0130 {
0131     const QObject* o = sender();
0132     if( K3b::ProjectPlugin* p = m_plugins[o] ) {
0133         if( p->hasGUI() ) {
0134             K3b::ProjectPluginDialog dlg( p, doc(), this );
0135             dlg.exec();
0136         }
0137         else
0138             p->activate( doc(), this );
0139     }
0140 }
0141 
0142 
0143 void K3b::View::addUrl( const QUrl& url )
0144 {
0145     addUrls( QList<QUrl>() << url );
0146 }
0147 
0148 
0149 void K3b::View::addUrls( const QList<QUrl>& urls )
0150 {
0151     doc()->addUrls( urls );
0152 }
0153 
0154 #include "moc_k3bview.cpp"