1 /* 2 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 #include "k3bdiskinfo.h" 6 #include "k3bdiskinfo_p.h" 7 #include "k3bdevice_i18n.h" 8 #include "k3bdeviceglobals.h" 9 #include "k3bmsf.h" 10 11 #include <KIO/Global> 12 13 #include <QDebug> 14 #include <QStringList> 15 16 DiskInfo()17K3b::Device::DiskInfo::DiskInfo() 18 : d( new DiskInfoPrivate() ) 19 { 20 } 21 22 DiskInfo(const DiskInfo & other)23K3b::Device::DiskInfo::DiskInfo( const DiskInfo& other ) 24 { 25 d = other.d; 26 } 27 28 ~DiskInfo()29K3b::Device::DiskInfo::~DiskInfo() 30 { 31 } 32 33 operator =(const DiskInfo & other)34K3b::Device::DiskInfo& K3b::Device::DiskInfo::operator=( const DiskInfo& other ) 35 { 36 d = other.d; 37 return *this; 38 } 39 40 diskState() const41K3b::Device::MediaState K3b::Device::DiskInfo::diskState() const 42 { 43 return d->diskState; 44 } 45 46 lastSessionState() const47K3b::Device::MediaState K3b::Device::DiskInfo::lastSessionState() const 48 { 49 return d->lastSessionState; 50 } 51 52 bgFormatState() const53K3b::Device::BackGroundFormattingState K3b::Device::DiskInfo::bgFormatState() const 54 { 55 return d->bgFormatState; 56 } 57 58 empty() const59bool K3b::Device::DiskInfo::empty() const 60 { 61 return diskState() == STATE_EMPTY; 62 } 63 64 rewritable() const65bool K3b::Device::DiskInfo::rewritable() const 66 { 67 return d->rewritable; 68 } 69 70 appendable() const71bool K3b::Device::DiskInfo::appendable() const 72 { 73 return diskState() == STATE_INCOMPLETE; 74 } 75 76 mediaType() const77K3b::Device::MediaType K3b::Device::DiskInfo::mediaType() const 78 { 79 return d->mediaType; 80 } 81 82 currentProfile() const83int K3b::Device::DiskInfo::currentProfile() const 84 { 85 return d->currentProfile; 86 } 87 88 mediaId() const89QByteArray K3b::Device::DiskInfo::mediaId() const 90 { 91 return d->mediaId; 92 } 93 94 numSessions() const95int K3b::Device::DiskInfo::numSessions() const 96 { 97 if( empty() ) 98 return 0; 99 else 100 return d->numSessions; 101 } 102 103 numTracks() const104int K3b::Device::DiskInfo::numTracks() const 105 { 106 if( empty() ) 107 return 0; 108 else 109 return d->numTracks; 110 } 111 112 numLayers() const113int K3b::Device::DiskInfo::numLayers() const 114 { 115 if( isDvdMedia( mediaType() ) ) 116 return d->numLayers; 117 else 118 return 1; 119 } 120 121 remainingSize() const122K3b::Msf K3b::Device::DiskInfo::remainingSize() const 123 { 124 if( empty() ) 125 return capacity(); 126 127 // 128 // There is no way to properly determine the used size on an overwrite media 129 // without having a look at the filesystem (or is there?) 130 // 131 else if( appendable() || 132 mediaType() & (MEDIA_DVD_PLUS_RW|MEDIA_DVD_RW_OVWR) ) 133 return capacity() - d->usedCapacity; 134 135 else 136 return 0; 137 } 138 139 capacity() const140K3b::Msf K3b::Device::DiskInfo::capacity() const 141 { 142 return (d->capacity == 0 ? size() : d->capacity); 143 } 144 145 size() const146K3b::Msf K3b::Device::DiskInfo::size() const 147 { 148 if( empty() ) 149 return 0; 150 else 151 return d->usedCapacity; 152 } 153 154 firstLayerSize() const155K3b::Msf K3b::Device::DiskInfo::firstLayerSize() const 156 { 157 if( numLayers() > 1 ) 158 return d->firstLayerSize; 159 else 160 return size(); 161 } 162 163 debug() const164void K3b::Device::DiskInfo::debug() const 165 { 166 qDebug() << "DiskInfo:" << endl 167 << "Mediatype: " << K3b::Device::mediaTypeString( mediaType() ) << endl 168 << "Current Profile: " << K3b::Device::mediaTypeString( currentProfile() ) << endl 169 << "Disk state: " << ( diskState() == K3b::Device::STATE_EMPTY ? 170 "empty" : 171 ( diskState() == K3b::Device::STATE_INCOMPLETE ? 172 "incomplete" : 173 ( diskState() == K3b::Device::STATE_COMPLETE ? 174 "complete" : 175 ( diskState() == K3b::Device::STATE_NO_MEDIA ? 176 "no media" : 177 "unknown" ) ) ) ) << endl 178 << "Empty: " << empty() << endl 179 << "Rewritable: " << rewritable() << endl 180 << "Appendable: " << appendable() << endl 181 << "Sessions: " << numSessions() << endl 182 << "Tracks: " << numTracks() << endl 183 << "Layers: " << numLayers() << endl 184 << "Capacity: " << capacity() 185 << " (LBA " << capacity().lba() 186 << ") (" << capacity().mode1Bytes() << " Bytes)" << endl 187 188 << "Remaining size: " << remainingSize() 189 << " (LBA " << remainingSize().lba() 190 << ") (" << remainingSize().mode1Bytes() << " Bytes)" << endl 191 192 << "Used Size: " << size() 193 << " (LBA " << size().lba() 194 << ") (" << size().mode1Bytes() << " Bytes)" << endl; 195 196 if( mediaType() == K3b::Device::MEDIA_DVD_PLUS_RW ) 197 qDebug() << "Bg Format: " << ( bgFormatState() == BG_FORMAT_NONE ? 198 "none" : 199 ( bgFormatState() == BG_FORMAT_INCOMPLETE ? 200 "incomplete" : 201 ( bgFormatState() == BG_FORMAT_IN_PROGRESS ? 202 "in progress" : 203 ( bgFormatState() == BG_FORMAT_COMPLETE ? 204 "complete" : "unknown" ) ) ) ) << endl; 205 } 206 207 operator ==(const K3b::Device::DiskInfo & other) const208bool K3b::Device::DiskInfo::operator==( const K3b::Device::DiskInfo& other ) const 209 { 210 return( d->mediaType == other.d->mediaType && 211 d->currentProfile == other.d->currentProfile && 212 d->diskState == other.d->diskState && 213 d->lastSessionState == other.d->lastSessionState && 214 d->bgFormatState == other.d->bgFormatState && 215 d->numSessions == other.d->numSessions && 216 d->numTracks == other.d->numTracks && 217 d->numLayers == other.d->numLayers && 218 d->rewritable == other.d->rewritable && 219 d->capacity == other.d->capacity && 220 d->usedCapacity == other.d->usedCapacity && 221 d->firstLayerSize == other.d->firstLayerSize && 222 d->mediaId == other.d->mediaId ); 223 } 224 225 operator !=(const K3b::Device::DiskInfo & other) const226bool K3b::Device::DiskInfo::operator!=( const K3b::Device::DiskInfo& other ) const 227 { 228 return( d->mediaType != other.d->mediaType || 229 d->currentProfile != other.d->currentProfile || 230 d->diskState != other.d->diskState || 231 d->lastSessionState != other.d->lastSessionState || 232 d->bgFormatState != other.d->bgFormatState || 233 d->numSessions != other.d->numSessions || 234 d->numTracks != other.d->numTracks || 235 d->numLayers != other.d->numLayers || 236 d->rewritable != other.d->rewritable || 237 d->capacity != other.d->capacity || 238 d->usedCapacity != other.d->usedCapacity || 239 d->firstLayerSize != other.d->firstLayerSize || 240 d->mediaId != other.d->mediaId ); 241 } 242 243 244 // kdbgstream& K3b::Device::operator<<( kdbgstream& s, const K3b::Device::DiskInfo& ngInf ) 245 // { 246 // s << "DiskInfo:" << endl 247 // << "Mediatype: " << K3b::Device::mediaTypeString( ngInf.mediaType() ) << endl 248 // << "Current Profile: " << K3b::Device::mediaTypeString( ngInf.currentProfile() ) << endl 249 // << "Disk state: " << ( ngInf.diskState() == K3b::Device::STATE_EMPTY ? 250 // "empty" : 251 // ( ngInf.diskState() == K3b::Device::STATE_INCOMPLETE ? 252 // "incomplete" : 253 // ( ngInf.diskState() == K3b::Device::STATE_COMPLETE ? 254 // "complete" : 255 // ( ngInf.diskState() == K3b::Device::STATE_NO_MEDIA ? 256 // "no media" : 257 // "unknown" ) ) ) ) << endl 258 // << "Empty: " << ngInf.empty() << endl 259 // << "Rewritable: " << ngInf.rewritable() << endl 260 // << "Appendable: " << ngInf.appendable() << endl 261 // << "Sessions: " << ngInf.numSessions() << endl 262 // << "Tracks: " << ngInf.numTracks() << endl 263 // << "Size: " << ngInf.capacity().toString() << endl 264 // << "Remaining size: " << ngInf.remainingSize().toString() << endl; 265 266 // return s; 267 // } 268