File indexing completed on 2024-04-28 04:49:53

0001 /*
0002     SPDX-FileCopyrightText: 2005-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef _K3B_MEDIUM_H_
0009 #define _K3B_MEDIUM_H_
0010 
0011 #include "k3b_export.h"
0012 
0013 #include "k3bdiskinfo.h"
0014 #include "k3btoc.h"
0015 #include "k3bcdtext.h"
0016 #include "k3bdevice.h"
0017 #include "k3biso9660.h"
0018 
0019 #include <QSharedDataPointer>
0020 #include <QList>
0021 #include <QIcon>
0022 
0023 namespace KCDDB{
0024     class CDInfo;
0025 }
0026 
0027 
0028 namespace K3b {
0029     class MediumPrivate;
0030 
0031     /**
0032      * Medium represents a medium in K3b.
0033      *
0034      * It is implicitly shared, thus copying is very fast.
0035      */
0036     class LIBK3B_EXPORT Medium
0037     {
0038     public:
0039         Medium();
0040         Medium( const Medium& );
0041         explicit Medium( Device::Device* dev );
0042         ~Medium();
0043 
0044         /**
0045          * Copy operator
0046          */
0047         Medium& operator=( const Medium& );
0048 
0049         bool isValid() const;
0050 
0051         void setDevice( Device::Device* dev );
0052 
0053         /**
0054          * Resets everything to default values except the device.
0055          * This means empty toc, cd text, no writing speeds, and a diskinfo
0056          * with state UNKNOWN.
0057          */
0058         void reset();
0059 
0060         /**
0061          * Updates the medium information if the device is not null.
0062          * Do not use this in the GUI thread since it uses blocking
0063          * K3bdevice methods.
0064          */
0065         void update();
0066 
0067         Device::Device* device() const;
0068         Device::DiskInfo diskInfo() const;
0069         Device::Toc toc() const;
0070         Device::CdText cdText() const;
0071 
0072         KCDDB::CDInfo cddbInfo() const;
0073 
0074         /**
0075          * The writing speeds the device supports with the inserted medium.
0076          * With older devices this list might even be empty for writable
0077          * media. In that case refer to Device::Device::maxWriteSpeed
0078          * combined with a manual speed selection.
0079          */
0080         QList<int> writingSpeeds() const;
0081         QString volumeId() const;
0082 
0083         /**
0084          * This method tries to make a volume identificator witch uses a reduced character set
0085          * look more beautiful by, for example, replacing '_' with a space or replacing all upper
0086          * case words.
0087          *
0088          * Volume ids already containing spaces or lower case characters are left unchanged.
0089          */
0090         QString beautifiedVolumeId() const;
0091 
0092         /**
0093          * An icon representing the contents of the medium.
0094          */
0095         QIcon icon() const;
0096 
0097         /**
0098          * Content type. May be combined by a binary OR.
0099          */
0100         enum MediumContent {
0101             ContentUnknown = 0x0,
0102             ContentNone = 0x1,
0103             ContentAudio = 0x2,
0104             ContentData = 0x4,
0105             ContentVideoCD = 0x8,
0106             ContentVideoDVD = 0x10,
0107             ContentAll = ContentNone|ContentAudio|ContentData|ContentVideoCD|ContentVideoDVD
0108         };
0109         Q_DECLARE_FLAGS( MediumContents, MediumContent )
0110 
0111         /**
0112          * \return a bitwise combination of MediumContent.
0113          * A VideoCD for example may have the following content:
0114          * ContentAudio|ContentData|ContentVideoCD
0115          */
0116         MediumContents content() const;
0117 
0118         /**
0119          * \return The volume descriptor from the ISO9660 filesystem.
0120          */
0121         const Iso9660SimplePrimaryDescriptor& iso9660Descriptor() const;
0122 
0123         /**
0124          * The used capacity size on the medium. This only differs from DiskInfo::size()
0125          * in that it handles rewritable media properly. It uses the size of the filesystem
0126          * for overwrite media.
0127          */
0128         K3b::Msf actuallyUsedCapacity() const;
0129 
0130         /**
0131          * The remaining size on the medium. This only differs from DiskInfo::remainingSize()
0132          * in that it handles rewritable media properly. It uses the size of the filesystem
0133          * for overwrite media.
0134          */
0135         K3b::Msf actuallyRemainingSize() const;
0136 
0137         /**
0138          * Format strings for methods shortString and longString
0139          */
0140         enum MediumStringFlag {
0141             NoStringFlags = 0x0, /**< no flags */
0142             WithContents = 0x1,  /**< Include the contents, i.e. the volume id or cd text/cddb values. */
0143             WithDevice = 0x2     /**< Include the device vendor, name, and system name in the long string. */
0144         };
0145         Q_DECLARE_FLAGS( MediumStringFlags, MediumStringFlag )
0146 
0147         QString contentTypeString() const;
0148 
0149         /**
0150          * \return A short one-liner string representing the medium.
0151          *         This string may be used for labels or selection boxes.
0152          * \param flags Can be WithContents in which case the content of the CD/DVD will be used, otherwise
0153          *              the string will simply be something like "empty DVD-R medium".
0154          *
0155          * \sa longString, MediumStringFlag
0156          */
0157         QString shortString( MediumStringFlags flags = WithContents ) const;
0158 
0159         /**
0160          * \return A HTML formatted string describing this medium. This includes the device, the
0161          *         medium type, the contents type, and some detail information like the number of
0162          *         tracks.
0163          *         This string may be used for tooltips or short descriptions.
0164          *
0165          * \sa shortString, MediumStringFlag
0166          */
0167         QString longString( MediumStringFlags flags = WithContents ) const;
0168 
0169         /**
0170          * Compares the plain medium ignoring the cddb information which can differ
0171          * based on the cddb settings.
0172          */
0173         bool sameMedium( const Medium& other ) const;
0174 
0175         bool operator==( const Medium& other ) const;
0176         bool operator!=( const Medium& other ) const;
0177 
0178         /**
0179          * Constructs a user readable string which can be used to request certain media.
0180          */
0181         static QString mediaRequestString( Device::MediaTypes requestedMediaTypes,
0182                                            Device::MediaStates requestedMediaStates,
0183                                            const K3b::Msf& requestedSize = Msf(),
0184                                            Device::Device* dev = 0 );
0185 
0186         static QStringList mediaRequestStrings( QList<K3b::Medium> unsuitableMediums,
0187                                                 Device::MediaTypes requestedMediaTypes,
0188                                                 Device::MediaStates requestedMediaStates,
0189                                                 const K3b::Msf& requestedSize = Msf(),
0190                                                 Device::Device* dev = 0 );
0191 
0192         static QString mediaRequestString( MediumContents content, Device::Device* dev = 0 );
0193 
0194     private:
0195         void analyseContent();
0196 
0197         QSharedDataPointer<MediumPrivate> d;
0198 
0199         friend class MediaCache;
0200     };
0201 }
0202 
0203 Q_DECLARE_OPERATORS_FOR_FLAGS( K3b::Medium::MediumContents )
0204 Q_DECLARE_OPERATORS_FOR_FLAGS( K3b::Medium::MediumStringFlags )
0205 
0206 #endif