File indexing completed on 2024-10-13 04:22:09

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3bburnprogressdialog.h"
0007 
0008 #include "k3bapplication.h"
0009 #include "k3bdevice.h"
0010 #include "k3bjob.h"
0011 #include "k3bstdguiitems.h"
0012 #include "k3bthemedlabel.h"
0013 #include "k3bthememanager.h"
0014 
0015 #include <KLocalizedString>
0016 
0017 #include <QLocale>
0018 #include <QGridLayout>
0019 #include <QLabel>
0020 #include <QProgressBar>
0021 
0022 
0023 K3b::BurnProgressDialog::BurnProgressDialog( QWidget *parent, bool showSubProgress )
0024     : K3b::JobProgressDialog( parent, showSubProgress )
0025 {
0026     m_labelWritingSpeed = new QLabel( m_frameExtraInfo );
0027     //  m_labelWritingSpeed->setAlignment( int( Qt::AlignVCenter | Qt::AlignRight ) );
0028 
0029     m_frameExtraInfoLayout->addWidget( m_labelWritingSpeed, 2, 0 );
0030     m_frameExtraInfoLayout->addWidget( new QLabel( i18n("Estimated writing speed:"), m_frameExtraInfo ), 1, 0 );
0031 
0032     QFrame* labelParentWriter = new QFrame( m_frameExtraInfo );
0033     labelParentWriter->setFrameShape( QFrame::StyledPanel );
0034     labelParentWriter->setFrameShadow( QFrame::Sunken );
0035     labelParentWriter->setLineWidth( 1 );
0036     labelParentWriter->setLayout( new QVBoxLayout() );
0037     labelParentWriter->layout()->setSpacing(0);
0038     labelParentWriter->layout()->setContentsMargins(0, 0, 0, 0);
0039 
0040     m_labelWriter = new K3b::ThemedLabel( labelParentWriter );
0041     m_labelWriter->setFrameStyle( QFrame::NoFrame );
0042     m_labelWriter->setContentsMargins( 5, 5, 5, 5 );
0043     QFont textLabel14_font( m_labelWriter->font() );
0044     textLabel14_font.setBold( true );
0045     m_labelWriter->setFont( textLabel14_font );
0046     labelParentWriter->layout()->addWidget( m_labelWriter );
0047 
0048     m_frameExtraInfoLayout->addWidget( labelParentWriter, 0, 0, 1, 4 );
0049     m_frameExtraInfoLayout->addWidget( new QLabel( i18n("Software buffer:"), m_frameExtraInfo ), 1, 2 );
0050     m_frameExtraInfoLayout->addWidget( new QLabel( i18n("Device buffer:"), m_frameExtraInfo ), 2, 2 );
0051 
0052     m_progressWritingBuffer = new QProgressBar( m_frameExtraInfo );
0053     m_frameExtraInfoLayout->addWidget( m_progressWritingBuffer, 1, 3 );
0054 
0055     m_progressDeviceBuffer = new QProgressBar( m_frameExtraInfo );
0056     m_frameExtraInfoLayout->addWidget( m_progressDeviceBuffer, 2, 3 );
0057     m_frameExtraInfoLayout->addWidget( K3b::StdGuiItems::verticalLine( m_frameExtraInfo ), 1, 1, 2, 1 );
0058 }
0059 
0060 K3b::BurnProgressDialog::~BurnProgressDialog()
0061 {
0062 }
0063 
0064 
0065 void K3b::BurnProgressDialog::setJob( K3b::Job* job )
0066 {
0067     if( K3b::BurnJob* burnJob = dynamic_cast<K3b::BurnJob*>(job) )
0068         setBurnJob(burnJob);
0069     else
0070         K3b::JobProgressDialog::setJob(job);
0071 }
0072 
0073 
0074 void K3b::BurnProgressDialog::setBurnJob( K3b::BurnJob* burnJob )
0075 {
0076     K3b::JobProgressDialog::setJob(burnJob);
0077 
0078     if( burnJob ) {
0079         connect( burnJob, SIGNAL(bufferStatus(int)), this, SLOT(slotBufferStatus(int)) );
0080         connect( burnJob, SIGNAL(deviceBuffer(int)), this, SLOT(slotDeviceBuffer(int)) );
0081         connect( burnJob, SIGNAL(writeSpeed(int,K3b::Device::SpeedMultiplicator)), this, SLOT(slotWriteSpeed(int,K3b::Device::SpeedMultiplicator)) );
0082         connect( burnJob, SIGNAL(burning(bool)), m_progressWritingBuffer, SLOT(setEnabled(bool)) );
0083         connect( burnJob, SIGNAL(burning(bool)), m_progressDeviceBuffer, SLOT(setEnabled(bool)) );
0084         connect( burnJob, SIGNAL(burning(bool)), m_labelWritingSpeed, SLOT(setEnabled(bool)) );
0085 
0086         if( burnJob->writer() )
0087             m_labelWriter->setText( i18n("Writer: %1 %2",burnJob->writer()->vendor(),
0088                                          burnJob->writer()->description()) );
0089 
0090         m_labelWritingSpeed->setText( i18n("no info") );
0091         m_progressWritingBuffer->setFormat( i18n("no info") );
0092         m_progressDeviceBuffer->setFormat( i18n("no info") );
0093     }
0094 }
0095 
0096 
0097 void K3b::BurnProgressDialog::slotFinished( bool success )
0098 {
0099     K3b::JobProgressDialog::slotFinished( success );
0100     if( success ) {
0101         m_labelWritingSpeed->setEnabled( false );
0102         m_progressWritingBuffer->setEnabled( false );
0103         m_progressDeviceBuffer->setEnabled( false );
0104     }
0105 }
0106 
0107 
0108 void K3b::BurnProgressDialog::slotBufferStatus( int b )
0109 {
0110     m_progressWritingBuffer->setFormat( "%p%" );
0111     m_progressWritingBuffer->setValue( b );
0112 }
0113 
0114 
0115 void K3b::BurnProgressDialog::slotDeviceBuffer( int b )
0116 {
0117     m_progressDeviceBuffer->setFormat( "%p%" );
0118     m_progressDeviceBuffer->setValue( b );
0119 }
0120 
0121 
0122 void K3b::BurnProgressDialog::slotWriteSpeed( int s, K3b::Device::SpeedMultiplicator multiplicator )
0123 {
0124     m_labelWritingSpeed->setText( QString("%1 KB/s (%2x)").arg(s).arg(QLocale::system().toString((double)s/(double)multiplicator,'g',2)) );
0125 }
0126 
0127 #include "moc_k3bburnprogressdialog.cpp"