File indexing completed on 2025-03-16 04:29:57
0001 /* 0002 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 #include "k3bdiskinfo.h" 0006 #include "k3bdiskinfo_p.h" 0007 #include "k3bdevice_i18n.h" 0008 #include "k3bdeviceglobals.h" 0009 #include "k3bmsf.h" 0010 0011 #include <KIO/Global> 0012 0013 #include <QDebug> 0014 #include <QStringList> 0015 0016 0017 K3b::Device::DiskInfo::DiskInfo() 0018 : d( new DiskInfoPrivate() ) 0019 { 0020 } 0021 0022 0023 K3b::Device::DiskInfo::DiskInfo( const DiskInfo& other ) 0024 { 0025 d = other.d; 0026 } 0027 0028 0029 K3b::Device::DiskInfo::~DiskInfo() 0030 { 0031 } 0032 0033 0034 K3b::Device::DiskInfo& K3b::Device::DiskInfo::operator=( const DiskInfo& other ) 0035 { 0036 d = other.d; 0037 return *this; 0038 } 0039 0040 0041 K3b::Device::MediaState K3b::Device::DiskInfo::diskState() const 0042 { 0043 return d->diskState; 0044 } 0045 0046 0047 K3b::Device::MediaState K3b::Device::DiskInfo::lastSessionState() const 0048 { 0049 return d->lastSessionState; 0050 } 0051 0052 0053 K3b::Device::BackGroundFormattingState K3b::Device::DiskInfo::bgFormatState() const 0054 { 0055 return d->bgFormatState; 0056 } 0057 0058 0059 bool K3b::Device::DiskInfo::empty() const 0060 { 0061 return diskState() == STATE_EMPTY; 0062 } 0063 0064 0065 bool K3b::Device::DiskInfo::rewritable() const 0066 { 0067 return d->rewritable; 0068 } 0069 0070 0071 bool K3b::Device::DiskInfo::appendable() const 0072 { 0073 return diskState() == STATE_INCOMPLETE; 0074 } 0075 0076 0077 K3b::Device::MediaType K3b::Device::DiskInfo::mediaType() const 0078 { 0079 return d->mediaType; 0080 } 0081 0082 0083 int K3b::Device::DiskInfo::currentProfile() const 0084 { 0085 return d->currentProfile; 0086 } 0087 0088 0089 QByteArray K3b::Device::DiskInfo::mediaId() const 0090 { 0091 return d->mediaId; 0092 } 0093 0094 0095 int K3b::Device::DiskInfo::numSessions() const 0096 { 0097 if( empty() ) 0098 return 0; 0099 else 0100 return d->numSessions; 0101 } 0102 0103 0104 int K3b::Device::DiskInfo::numTracks() const 0105 { 0106 if( empty() ) 0107 return 0; 0108 else 0109 return d->numTracks; 0110 } 0111 0112 0113 int K3b::Device::DiskInfo::numLayers() const 0114 { 0115 if( isDvdMedia( mediaType() ) ) 0116 return d->numLayers; 0117 else 0118 return 1; 0119 } 0120 0121 0122 K3b::Msf K3b::Device::DiskInfo::remainingSize() const 0123 { 0124 if( empty() ) 0125 return capacity(); 0126 0127 // 0128 // There is no way to properly determine the used size on an overwrite media 0129 // without having a look at the filesystem (or is there?) 0130 // 0131 else if( appendable() || 0132 mediaType() & (MEDIA_DVD_PLUS_RW|MEDIA_DVD_RW_OVWR) ) 0133 return capacity() - d->usedCapacity; 0134 0135 else 0136 return 0; 0137 } 0138 0139 0140 K3b::Msf K3b::Device::DiskInfo::capacity() const 0141 { 0142 return (d->capacity == 0 ? size() : d->capacity); 0143 } 0144 0145 0146 K3b::Msf K3b::Device::DiskInfo::size() const 0147 { 0148 if( empty() ) 0149 return 0; 0150 else 0151 return d->usedCapacity; 0152 } 0153 0154 0155 K3b::Msf K3b::Device::DiskInfo::firstLayerSize() const 0156 { 0157 if( numLayers() > 1 ) 0158 return d->firstLayerSize; 0159 else 0160 return size(); 0161 } 0162 0163 0164 void K3b::Device::DiskInfo::debug() const 0165 { 0166 qDebug() << "DiskInfo:" << Qt::endl 0167 << "Mediatype: " << K3b::Device::mediaTypeString( mediaType() ) << Qt::endl 0168 << "Current Profile: " << K3b::Device::mediaTypeString( currentProfile() ) << Qt::endl 0169 << "Disk state: " << ( diskState() == K3b::Device::STATE_EMPTY ? 0170 "empty" : 0171 ( diskState() == K3b::Device::STATE_INCOMPLETE ? 0172 "incomplete" : 0173 ( diskState() == K3b::Device::STATE_COMPLETE ? 0174 "complete" : 0175 ( diskState() == K3b::Device::STATE_NO_MEDIA ? 0176 "no media" : 0177 "unknown" ) ) ) ) << Qt::endl 0178 << "Empty: " << empty() << Qt::endl 0179 << "Rewritable: " << rewritable() << Qt::endl 0180 << "Appendable: " << appendable() << Qt::endl 0181 << "Sessions: " << numSessions() << Qt::endl 0182 << "Tracks: " << numTracks() << Qt::endl 0183 << "Layers: " << numLayers() << Qt::endl 0184 << "Capacity: " << capacity() 0185 << " (LBA " << capacity().lba() 0186 << ") (" << capacity().mode1Bytes() << " Bytes)" << Qt::endl 0187 0188 << "Remaining size: " << remainingSize() 0189 << " (LBA " << remainingSize().lba() 0190 << ") (" << remainingSize().mode1Bytes() << " Bytes)" << Qt::endl 0191 0192 << "Used Size: " << size() 0193 << " (LBA " << size().lba() 0194 << ") (" << size().mode1Bytes() << " Bytes)" << Qt::endl; 0195 0196 if( mediaType() == K3b::Device::MEDIA_DVD_PLUS_RW ) 0197 qDebug() << "Bg Format: " << ( bgFormatState() == BG_FORMAT_NONE ? 0198 "none" : 0199 ( bgFormatState() == BG_FORMAT_INCOMPLETE ? 0200 "incomplete" : 0201 ( bgFormatState() == BG_FORMAT_IN_PROGRESS ? 0202 "in progress" : 0203 ( bgFormatState() == BG_FORMAT_COMPLETE ? 0204 "complete" : "unknown" ) ) ) ) << Qt::endl; 0205 } 0206 0207 0208 bool K3b::Device::DiskInfo::operator==( const K3b::Device::DiskInfo& other ) const 0209 { 0210 return( d->mediaType == other.d->mediaType && 0211 d->currentProfile == other.d->currentProfile && 0212 d->diskState == other.d->diskState && 0213 d->lastSessionState == other.d->lastSessionState && 0214 d->bgFormatState == other.d->bgFormatState && 0215 d->numSessions == other.d->numSessions && 0216 d->numTracks == other.d->numTracks && 0217 d->numLayers == other.d->numLayers && 0218 d->rewritable == other.d->rewritable && 0219 d->capacity == other.d->capacity && 0220 d->usedCapacity == other.d->usedCapacity && 0221 d->firstLayerSize == other.d->firstLayerSize && 0222 d->mediaId == other.d->mediaId ); 0223 } 0224 0225 0226 bool K3b::Device::DiskInfo::operator!=( const K3b::Device::DiskInfo& other ) const 0227 { 0228 return( d->mediaType != other.d->mediaType || 0229 d->currentProfile != other.d->currentProfile || 0230 d->diskState != other.d->diskState || 0231 d->lastSessionState != other.d->lastSessionState || 0232 d->bgFormatState != other.d->bgFormatState || 0233 d->numSessions != other.d->numSessions || 0234 d->numTracks != other.d->numTracks || 0235 d->numLayers != other.d->numLayers || 0236 d->rewritable != other.d->rewritable || 0237 d->capacity != other.d->capacity || 0238 d->usedCapacity != other.d->usedCapacity || 0239 d->firstLayerSize != other.d->firstLayerSize || 0240 d->mediaId != other.d->mediaId ); 0241 } 0242 0243 0244 // kdbgstream& K3b::Device::operator<<( kdbgstream& s, const K3b::Device::DiskInfo& ngInf ) 0245 // { 0246 // s << "DiskInfo:" << Qt::endl 0247 // << "Mediatype: " << K3b::Device::mediaTypeString( ngInf.mediaType() ) << Qt::endl 0248 // << "Current Profile: " << K3b::Device::mediaTypeString( ngInf.currentProfile() ) << Qt::endl 0249 // << "Disk state: " << ( ngInf.diskState() == K3b::Device::STATE_EMPTY ? 0250 // "empty" : 0251 // ( ngInf.diskState() == K3b::Device::STATE_INCOMPLETE ? 0252 // "incomplete" : 0253 // ( ngInf.diskState() == K3b::Device::STATE_COMPLETE ? 0254 // "complete" : 0255 // ( ngInf.diskState() == K3b::Device::STATE_NO_MEDIA ? 0256 // "no media" : 0257 // "unknown" ) ) ) ) << Qt::endl 0258 // << "Empty: " << ngInf.empty() << Qt::endl 0259 // << "Rewritable: " << ngInf.rewritable() << Qt::endl 0260 // << "Appendable: " << ngInf.appendable() << Qt::endl 0261 // << "Sessions: " << ngInf.numSessions() << Qt::endl 0262 // << "Tracks: " << ngInf.numTracks() << Qt::endl 0263 // << "Size: " << ngInf.capacity().toString() << Qt::endl 0264 // << "Remaining size: " << ngInf.remainingSize().toString() << Qt::endl; 0265 0266 // return s; 0267 // }