File indexing completed on 2024-06-09 04:00:38

0001 /*
0002     SPDX-FileCopyrightText: 2006 Kevin Ottens <ervin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "iokitopticaldisc.h"
0008 
0009 #include <CoreFoundation/CoreFoundation.h>
0010 
0011 using namespace Solid::Backends::IOKit;
0012 
0013 IOKitOpticalDisc::IOKitOpticalDisc(IOKitDevice *device)
0014     : IOKitVolume(device)
0015 {
0016 }
0017 
0018 IOKitOpticalDisc::IOKitOpticalDisc(const IOKitDevice *device)
0019     : IOKitVolume(device)
0020 {
0021 }
0022 
0023 IOKitOpticalDisc::~IOKitOpticalDisc()
0024 {
0025 }
0026 
0027 QString IOKitOpticalDisc::device() const
0028 {
0029     const QString devName = m_device->property(QLatin1String("BSD Name")).toString();
0030     if (devName.startsWith(QLatin1Char('r'))) {
0031         return QStringLiteral("/dev/") + devName;
0032     } else {
0033         return QStringLiteral("/dev/r") + devName;
0034     }
0035 }
0036 
0037 Solid::OpticalDisc::ContentTypes IOKitOpticalDisc::availableContent() const
0038 {
0039     if (fsType() == QStringLiteral("cddafs")) {
0040         return Solid::OpticalDisc::Audio;
0041     }
0042     return Solid::OpticalDisc::Data;
0043 }
0044 
0045 Solid::OpticalDisc::DiscType IOKitOpticalDisc::discType() const
0046 {
0047     QString type = m_device->property(QStringLiteral("Type")).toString();
0048 
0049     if (type == "CD-ROM") {
0050         return Solid::OpticalDisc::CdRom;
0051     } else if (type == "CD-R") {
0052         return Solid::OpticalDisc::CdRecordable;
0053     } else if (type == "CD-RW") {
0054         return Solid::OpticalDisc::CdRewritable;
0055     } else if (type == "DVD-ROM") {
0056         return Solid::OpticalDisc::DvdRom;
0057     } else if (type == "DVD-RAM") {
0058         return Solid::OpticalDisc::DvdRam;
0059     } else if (type == "DVD-R") {
0060         return Solid::OpticalDisc::DvdRecordable;
0061     } else if (type == "DVD-RW") {
0062         return Solid::OpticalDisc::DvdRewritable;
0063     } else if (type == "DVD+R") {
0064         return Solid::OpticalDisc::DvdPlusRecordable;
0065     } else if (type == "DVD+RW") {
0066         return Solid::OpticalDisc::DvdPlusRewritable;
0067     } else if (type == "BD-ROM") {
0068         return Solid::OpticalDisc::BluRayRom;
0069     } else if (type == "BD-R") {
0070         return Solid::OpticalDisc::BluRayRecordable;
0071     } else if (type == "BD-RE") {
0072         return Solid::OpticalDisc::BluRayRewritable;
0073     } else if (type == "HD DVD-ROM") {
0074         return Solid::OpticalDisc::HdDvdRom;
0075     } else if (type == "HD DVD-R") {
0076         return Solid::OpticalDisc::HdDvdRecordable;
0077     } else if (type == "HD DVD-RW") {
0078         return Solid::OpticalDisc::HdDvdRewritable;
0079     } else {
0080         return Solid::OpticalDisc::UnknownDiscType;
0081     }
0082 }
0083 
0084 bool IOKitOpticalDisc::isAppendable() const
0085 {
0086     // TODO!
0087     return isRewritable();
0088 }
0089 
0090 bool IOKitOpticalDisc::isBlank() const
0091 {
0092     // TODO!
0093     return isRewritable();
0094 }
0095 
0096 bool IOKitOpticalDisc::isRewritable() const
0097 {
0098     return m_device->property(QStringLiteral("Writable")).toBool();
0099 }
0100 
0101 qulonglong IOKitOpticalDisc::capacity() const
0102 {
0103     return size();
0104 }
0105 
0106 #include "moc_iokitopticaldisc.cpp"