1 /* 2 SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #include "k3bdebuggingoutputfile.h" 7 8 #include "k3bdevicemanager.h" 9 #include "k3bdevice.h" 10 #include "k3bcore.h" 11 #include "k3bversion.h" 12 #include "k3bdeviceglobals.h" 13 #include "k3bglobals.h" 14 15 #include <kcoreaddons_version.h> 16 17 #include <QDir> 18 #include <QStandardPaths> 19 #include <QTextStream> 20 21 22 namespace 23 { debuggingOutputFilePath()24 QString debuggingOutputFilePath() 25 { 26 QString dirPath = QStandardPaths::writableLocation( QStandardPaths::AppDataLocation ); 27 QDir().mkpath( dirPath ); 28 return dirPath + "/lastlog.log"; 29 } 30 } // namespace 31 DebuggingOutputFile()32K3b::DebuggingOutputFile::DebuggingOutputFile() 33 : QFile( debuggingOutputFilePath() ) 34 { 35 } 36 37 open(OpenMode mode)38bool K3b::DebuggingOutputFile::open( OpenMode mode ) 39 { 40 if( !QFile::open( mode|WriteOnly|Unbuffered ) ) 41 return false; 42 43 addOutput( QLatin1String( "System" ), QString::fromLatin1( "K3b Version: %1" ).arg(k3bcore->version()) ); 44 addOutput( QLatin1String( "System" ), QString::fromLatin1( "KDE Version: %1" ).arg(KCOREADDONS_VERSION_STRING) ); 45 addOutput( QLatin1String( "System" ), QString::fromLatin1( "Qt Version: %1" ).arg(qVersion()) ); 46 addOutput( QLatin1String( "System" ), QString::fromLatin1( "Kernel: %1" ).arg(K3b::kernelVersion()) ); 47 48 // devices in the logfile 49 Q_FOREACH( K3b::Device::Device* dev, k3bcore->deviceManager()->allDevices() ) { 50 addOutput( "Devices", 51 QString( "%1 (%2, %3) [%5] [%6] [%7]" ) 52 .arg( dev->vendor() + ' ' + dev->description() + ' ' + dev->version() ) 53 .arg( dev->blockDeviceName() ) 54 .arg( K3b::Device::deviceTypeString( dev->type() ) ) 55 .arg( K3b::Device::mediaTypeString( dev->supportedProfiles() ) ) 56 .arg( K3b::Device::writingModeString( dev->writingModes() ) ) ); 57 } 58 59 return true; 60 } 61 62 addOutput(const QString & app,const QString & msg)63void K3b::DebuggingOutputFile::addOutput( const QString& app, const QString& msg ) 64 { 65 if( !isOpen() ) 66 open(); 67 68 QTextStream s( this ); 69 s << "[" << app << "] " << msg << endl; 70 flush(); 71 } 72 73 74