File indexing completed on 2024-10-06 04:25:58

0001 /*
0002     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3bdebuggingoutputdialog.h"
0007 
0008 #include "k3bdevicemanager.h"
0009 #include "k3bdevice.h"
0010 #include "k3bdeviceglobals.h"
0011 #include "k3bcore.h"
0012 #include "k3bversion.h"
0013 #include "k3bglobals.h"
0014 
0015 #include <KLocalizedString>
0016 #include <KStandardGuiItem>
0017 #include <KMessageBox>
0018 
0019 #include <QFile>
0020 #include <QTextStream>
0021 #include <QClipboard>
0022 #include <QCursor>
0023 #include <QFontDatabase>
0024 #include <QApplication>
0025 #include <QDialogButtonBox>
0026 #include <QFileDialog>
0027 #include <QPushButton>
0028 #include <QTextEdit>
0029 #include <QVBoxLayout>
0030 
0031 
0032 K3b::DebuggingOutputDialog::DebuggingOutputDialog( QWidget* parent )
0033   : QDialog( parent)
0034 {
0035   setModal(true);
0036   setWindowTitle(i18n("Debugging Output"));
0037 
0038   debugView = new QTextEdit( this );
0039   debugView->setReadOnly(true);
0040   debugView->setAcceptRichText( false );
0041   debugView->setCurrentFont( QFontDatabase::systemFont( QFontDatabase::FixedFont ) );
0042   debugView->setWordWrapMode( QTextOption::NoWrap );
0043 
0044   QPushButton* saveButton = new QPushButton( this );
0045   KStandardGuiItem::assign( saveButton, KStandardGuiItem::SaveAs );
0046   saveButton->setToolTip( i18n("Save to file") );
0047   connect( saveButton, SIGNAL(clicked()), this, SLOT(slotSaveAsClicked()) );
0048 
0049   QPushButton* copyButton = new QPushButton( this );
0050   KGuiItem::assign( copyButton, KGuiItem( i18n("Copy"), QString::fromLatin1( "edit-copy" ), i18n("Copy to clipboard") ) );
0051   connect( copyButton, SIGNAL(clicked()), this, SLOT(slotCopyClicked()) );
0052 
0053   QDialogButtonBox* buttonBox = new QDialogButtonBox( this );
0054   buttonBox->addButton( QDialogButtonBox::Close );
0055   buttonBox->addButton( saveButton, QDialogButtonBox::NoRole );
0056   buttonBox->addButton( copyButton, QDialogButtonBox::NoRole );
0057   connect( buttonBox->button( QDialogButtonBox::Close ), SIGNAL(clicked()), this, SLOT(accept()) );
0058 
0059   QVBoxLayout* layout = new QVBoxLayout( this );
0060   layout->addWidget( debugView );
0061   layout->addWidget( buttonBox );
0062 
0063   resize( 600, 300 );
0064 }
0065 
0066 
0067 void K3b::DebuggingOutputDialog::setOutput( const QString& data )
0068 {
0069   // the following may take some time
0070   QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
0071 
0072   debugView->setText( data );
0073 
0074   QApplication::restoreOverrideCursor();
0075 }
0076 
0077 
0078 void K3b::DebuggingOutputDialog::slotSaveAsClicked()
0079 {
0080   QString filename = QFileDialog::getSaveFileName( this );
0081   if( !filename.isEmpty() ) {
0082     QFile f( filename );
0083     if( !f.exists() || KMessageBox::warningContinueCancel( this,
0084                           i18n("Do you want to overwrite %1?",filename),
0085                           i18n("File Exists"), KStandardGuiItem::overwrite() )
0086     == KMessageBox::Continue ) {
0087 
0088       if( f.open( QIODevice::WriteOnly ) ) {
0089     QTextStream t( &f );
0090     t << debugView->toPlainText();
0091       }
0092       else {
0093     KMessageBox::error( this, i18n("Could not open file %1",filename) );
0094       }
0095     }
0096   }
0097 }
0098 
0099 
0100 void K3b::DebuggingOutputDialog::slotCopyClicked()
0101 {
0102   QApplication::clipboard()->setText( debugView->toPlainText(), QClipboard::Clipboard );
0103 }
0104 
0105 #include "moc_k3bdebuggingoutputdialog.cpp"