File indexing completed on 2024-10-13 04:22:09
0001 /* 0002 SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "k3bdebuggingoutputfile.h" 0007 0008 #include "k3bdevicemanager.h" 0009 #include "k3bdevice.h" 0010 #include "k3bcore.h" 0011 #include "k3bversion.h" 0012 #include "k3bdeviceglobals.h" 0013 #include "k3bglobals.h" 0014 0015 #include <kcoreaddons_version.h> 0016 0017 #include <QDir> 0018 #include <QStandardPaths> 0019 #include <QTextStream> 0020 0021 0022 namespace 0023 { 0024 QString debuggingOutputFilePath() 0025 { 0026 QString dirPath = QStandardPaths::writableLocation( QStandardPaths::AppDataLocation ); 0027 QDir().mkpath( dirPath ); 0028 return dirPath + "/lastlog.log"; 0029 } 0030 } // namespace 0031 0032 K3b::DebuggingOutputFile::DebuggingOutputFile() 0033 : QFile( debuggingOutputFilePath() ) 0034 { 0035 } 0036 0037 0038 bool K3b::DebuggingOutputFile::open( OpenMode mode ) 0039 { 0040 if( !QFile::open( mode|WriteOnly|Unbuffered ) ) 0041 return false; 0042 0043 addOutput( QLatin1String( "System" ), QString::fromLatin1( "K3b Version: %1" ).arg(k3bcore->version()) ); 0044 addOutput( QLatin1String( "System" ), QString::fromLatin1( "KDE Version: %1" ).arg(KCOREADDONS_VERSION_STRING) ); 0045 addOutput( QLatin1String( "System" ), QString::fromLatin1( "Qt Version: %1" ).arg(qVersion()) ); 0046 addOutput( QLatin1String( "System" ), QString::fromLatin1( "Kernel: %1" ).arg(K3b::kernelVersion()) ); 0047 0048 // devices in the logfile 0049 Q_FOREACH( K3b::Device::Device* dev, k3bcore->deviceManager()->allDevices() ) { 0050 addOutput( "Devices", 0051 QString( "%1 (%2, %3) [%5] [%6] [%7]" ) 0052 .arg( dev->vendor() + ' ' + dev->description() + ' ' + dev->version() ) 0053 .arg( dev->blockDeviceName() ) 0054 .arg( K3b::Device::deviceTypeString( dev->type() ) ) 0055 .arg( K3b::Device::mediaTypeString( dev->supportedProfiles() ) ) 0056 .arg( K3b::Device::writingModeString( dev->writingModes() ) ) ); 0057 } 0058 0059 return true; 0060 } 0061 0062 0063 void K3b::DebuggingOutputFile::addOutput( const QString& app, const QString& msg ) 0064 { 0065 if( !isOpen() ) 0066 open(); 0067 0068 QTextStream s( this ); 0069 s << "[" << app << "] " << msg << Qt::endl; 0070 flush(); 0071 } 0072 0073 #include "moc_k3bdebuggingoutputfile.cpp"