2011-08-05 02:15:16 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-08-11 00:15:26 +02:00
|
|
|
#include <QFileInfo>
|
2011-08-05 02:15:16 +02:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QWaitCondition>
|
|
|
|
|
2012-10-31 18:42:38 +01:00
|
|
|
// This must come after Qt includes
|
|
|
|
#include <cdio/cdio.h>
|
|
|
|
|
2011-08-05 02:15:16 +02:00
|
|
|
#include "cddalister.h"
|
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/song.h"
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QStringList CddaLister::DeviceUniqueIDs() { return devices_list_; }
|
2011-08-05 02:15:16 +02:00
|
|
|
|
|
|
|
QVariantList CddaLister::DeviceIcons(const QString&) {
|
|
|
|
QVariantList icons;
|
|
|
|
icons << QString("media-optical");
|
|
|
|
return icons;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CddaLister::DeviceManufacturer(const QString& id) {
|
2014-02-07 16:34:20 +01:00
|
|
|
CdIo_t* cdio = cdio_open(id.toLocal8Bit().constData(), DRIVER_DEVICE);
|
2011-08-05 02:15:16 +02:00
|
|
|
cdio_hwinfo_t cd_info;
|
|
|
|
if (cdio_get_hwinfo(cdio, &cd_info)) {
|
|
|
|
cdio_destroy(cdio);
|
|
|
|
return QString(cd_info.psz_vendor);
|
|
|
|
}
|
|
|
|
cdio_destroy(cdio);
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CddaLister::DeviceModel(const QString& id) {
|
2014-02-07 16:34:20 +01:00
|
|
|
CdIo_t* cdio = cdio_open(id.toLocal8Bit().constData(), DRIVER_DEVICE);
|
2011-08-05 02:15:16 +02:00
|
|
|
cdio_hwinfo_t cd_info;
|
|
|
|
if (cdio_get_hwinfo(cdio, &cd_info)) {
|
|
|
|
cdio_destroy(cdio);
|
|
|
|
return QString(cd_info.psz_model);
|
|
|
|
}
|
|
|
|
cdio_destroy(cdio);
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
quint64 CddaLister::DeviceCapacity(const QString&) { return 0; }
|
2011-08-05 02:15:16 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
quint64 CddaLister::DeviceFreeSpace(const QString&) { return 0; }
|
2011-08-05 02:15:16 +02:00
|
|
|
|
|
|
|
QVariantMap CddaLister::DeviceHardwareInfo(const QString&) {
|
|
|
|
return QVariantMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CddaLister::MakeFriendlyName(const QString& id) {
|
2014-02-07 16:34:20 +01:00
|
|
|
CdIo_t* cdio = cdio_open(id.toLocal8Bit().constData(), DRIVER_DEVICE);
|
2011-08-05 02:15:16 +02:00
|
|
|
cdio_hwinfo_t cd_info;
|
|
|
|
if (cdio_get_hwinfo(cdio, &cd_info)) {
|
|
|
|
cdio_destroy(cdio);
|
|
|
|
return QString(cd_info.psz_model);
|
|
|
|
}
|
|
|
|
cdio_destroy(cdio);
|
|
|
|
return QString("CD (") + id + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QUrl> CddaLister::MakeDeviceUrls(const QString& id) {
|
|
|
|
return QList<QUrl>() << QUrl("cdda://" + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CddaLister::UnmountDevice(const QString& id) {
|
|
|
|
cdio_eject_media_drive(id.toLocal8Bit().constData());
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void CddaLister::UpdateDeviceFreeSpace(const QString&) {}
|
2011-08-05 02:15:16 +02:00
|
|
|
|
|
|
|
void CddaLister::Init() {
|
2011-08-09 20:20:45 +02:00
|
|
|
cdio_init();
|
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
if (!cdio_have_driver(DRIVER_OSX)) {
|
|
|
|
qLog(Error) << "libcdio was compiled without support for OS X!";
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-07 16:34:20 +01:00
|
|
|
char** devices = cdio_get_devices(DRIVER_DEVICE);
|
2011-08-08 13:59:21 +02:00
|
|
|
if (!devices) {
|
2011-08-09 20:20:45 +02:00
|
|
|
qLog(Debug) << "No CD devices found";
|
2011-08-08 13:59:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-02-06 16:49:49 +01:00
|
|
|
for (; *devices != nullptr; ++devices) {
|
2011-08-05 02:15:16 +02:00
|
|
|
QString device(*devices);
|
2011-08-11 00:15:26 +02:00
|
|
|
QFileInfo device_info(device);
|
2012-11-18 22:05:18 +01:00
|
|
|
if (device_info.isSymLink()) {
|
|
|
|
device = device_info.symLinkTarget();
|
|
|
|
}
|
2011-08-09 21:30:28 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
2014-02-07 16:34:20 +01:00
|
|
|
// Every track is detected as a separate device on Darwin. The raw disk
|
|
|
|
// looks
|
2011-08-09 21:30:28 +02:00
|
|
|
// like /dev/rdisk1
|
|
|
|
if (!device.contains(QRegExp("^/dev/rdisk[0-9]$"))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-18 22:05:18 +01:00
|
|
|
if (!devices_list_.contains(device)) {
|
|
|
|
devices_list_ << device;
|
|
|
|
emit DeviceAdded(device);
|
|
|
|
}
|
2011-08-05 02:15:16 +02:00
|
|
|
}
|
|
|
|
}
|