Commit 66bef2a3 authored by Benjamin Meyer's avatar Benjamin Meyer
Browse files

Up-port from 3.5

----
-Updated copyright year and e-mail
-Changed all plugins to use cdinfo rather then the 12 arguments
-Fixed a few compiler warnings
-Cleaned up the config dialog a little bit
-Removed unecessary private config items
-Renamed some private functions to be better named
-Removed duplicate code
-Reduced function to the point where it was removed
-Removed hard coded strings that wern't translated


svn path=/trunk/KDE/kdemultimedia/kioslave/audiocd/; revision=442293
parent 061f9608
......@@ -4,8 +4,9 @@ endif
SUBDIRS = plugins $(AUDIO_CD_SUBDIRS)
INCLUDES = -I$(top_srcdir)/libkcddb \
-I$(top_builddir)/libkcddb -I$(top_srcdir)/kscd $(all_includes) \
-I$(srcdir)/plugins $(all_includes)
-I$(top_builddir)/libkcddb $(all_includes) \
-I$(top_srcdir)/kscd $(all_includes) \
-I$(srcdir)/plugins $(all_includes)
KDE_CXXFLAGS=$(ENABLE_PERMISSIVE_FLAG)
......@@ -15,7 +16,7 @@ kio_audiocd_la_SOURCES = audiocd.cpp
kio_audiocd_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
kio_audiocd_la_LIBADD = ./plugins/libaudiocdplugins.la $(LIB_KIO) $(CDPARANOIA_LIBS) $(top_builddir)/libkcddb/libkcddb.la $(top_builddir)/kscd/libkcompactdisc.la
kio_audiocd_la_LIBADD = ./plugins/libaudiocdplugins.la $(LIB_KIO) $(CDPARANOIA_LIBS) $(top_builddir)/libkcddb/libkcddb.la $(top_builddir)/kscd/libkcompactdisc.la
noinst_HEADERS = audiocd.h
......
......@@ -106,12 +106,12 @@ class AudioCDProtocol::Private {
public:
Private() {
clearURLargs();
discid = 0;
s_info = i18n("Information");
s_fullCD = i18n("Full CD");
}
void clearURLargs() {
discid = 0;
req_allTracks = false;
which_dir = Unknown;
req_track = -1;
......@@ -135,8 +135,8 @@ public:
QString s_fullCD;
// Current CD
uint discid;
uint tracks;
unsigned discid;
unsigned tracks;
bool trackIsAudio[100];
// CDDB items
......@@ -152,20 +152,12 @@ public:
QString rreplace;
// Current strings for this CD and or cddb selection
QString cd_title;
QString cd_artist;
QString cd_category;
int cd_year;
QStringList templateTitles;
QString templateAlbumName;
// The current cddb title strings for id3
QStringList track_titles;
};
int paranoia_read_limited_error;
AudioCDProtocol::AudioCDProtocol(const QCString & protocol, const QCString & pool, const QCString & app)
: SlaveBase(protocol, pool, app)
{
......@@ -211,43 +203,47 @@ struct cdrom_drive * AudioCDProtocol::initRequest(const KURL & url)
return 0;
}
// Tell encoders to read their settings.
AudioCDEncoder *encoder;
for ( encoder = encoders.first(); encoder; encoder = encoders.next() )
encoder->init();
// Load OUR Settings.
loadSettings();
// Then url parameters can overrule our settings.
parseURLArgs(url);
struct cdrom_drive * drive = pickDrive();
struct cdrom_drive * drive = getDrive();
if (0 == drive)
return 0;
if (0 != cdda_open(drive))
{
kdDebug(7117) << "cdda_open failed" << endl;
// Update our knowledge of the disc
KCompactDisc cd(KCompactDisc::Asynchronous);
// TODO which one is right?
// qDebug("\"%s\" \"%s\"", drive->cdda_device_name, drive->ioctl_device_name);
cd.setDevice(drive->cdda_device_name, 50, false);
if (cd.discId() != d->discid && cd.discId() != cd.missingDisc){
d->discid = cd.discId();
d->tracks = cd.tracks();
for(uint i=0; i< cd.tracks(); i++)
d->trackIsAudio[i] = cd.isAudio(i+1);
error(KIO::ERR_CANNOT_OPEN_FOR_READING, url.path());
cdda_close(drive);
return 0;
KCDDB::Client c;
d->cddbResult = c.lookup(cd.discSignature());
d->cddbList = c.lookupResponse();
d->cddbBestChoice = c.bestLookupResponse();
generateTemplateTitles();
}
updateCD(drive);
// Determine what file or folder that is wanted.
d->fname = url.fileName(false);
QString dname = url.directory(true, false);
if (!dname.isEmpty() && dname[0] == '/')
dname = dname.mid(1);
// Kong bug where they send dirs as files, double check
// Kong issue where they send dirs as files, double check
/* A hack, for when konqi wants to list the directory audiocd:/Bla
it really submits this URL, instead of audiocd:/Bla/ to us. We could
send (in listDir) the UDS_NAME as "Bla/" for directories, but then
konqi shows them as "Bla//" in the status line. */
// See if it is an encoder directory
AudioCDEncoder *encoder;
for ( encoder = encoders.first(); encoder; encoder = encoders.next() ){
if(encoder->type() == d->fname){
dname = d->fname;
......@@ -256,13 +252,11 @@ struct cdrom_drive * AudioCDProtocol::initRequest(const KURL & url)
}
}
// Other Hard coded directories
if (dname.isEmpty() &&
(d->fname == d->s_info || d->fname == QFL1("Information") ||
d->fname == d->s_fullCD ))
{
dname = d->fname;
d->fname = "";
}
if (dname.isEmpty() && (d->fname == d->s_info || d->fname == d->s_fullCD ))
{
dname = d->fname;
d->fname = "";
}
// end hack
......@@ -278,9 +272,9 @@ struct cdrom_drive * AudioCDProtocol::initRequest(const KURL & url)
if ( Unknown == d->which_dir ){
if (dname.isEmpty())
d->which_dir = Root;
else if (dname == d->s_info || dname == QFL1("Information"))
else if (dname == d->s_info)
d->which_dir = Info;
else if (dname == d->s_fullCD || dname == QFL1("Full CD"))
else if (dname == d->s_fullCD)
d->which_dir = FullCD;
}
......@@ -329,7 +323,7 @@ struct cdrom_drive * AudioCDProtocol::initRequest(const KURL & url)
d->req_track = -1;
// Are we in the directory that lists "full CD" files?
d->req_allTracks = (dname.contains(d->s_fullCD) || dname.contains(QFL1("Full CD")));
d->req_allTracks = (dname.contains(d->s_fullCD));
kdDebug(7117) << "dir=" << dname << " file=" << d->fname
<< " req_track=" << d->req_track << " which_dir=" << d->which_dir << " full CD?=" << d->req_allTracks << endl;
......@@ -405,25 +399,28 @@ void AudioCDProtocol::get(const KURL & url)
AudioCDEncoder *encoder = determineEncoder(d->fname);
if(!encoder){
cdda_close(drive);
return;
cdda_close(drive);
return;
}
KCDDB::CDInfo info;
if(d->cddbResult == KCDDB::CDDB::Success){
info = d->cddbBestChoice;
int track = d->req_track+1;
QString trackName;
// hack
// do we rip the whole CD?
if (d->req_allTracks)
if (d->req_allTracks){
track = 1;
// YES => the title of the file is the title of the CD
trackName = d->cd_title.utf8().data();
else
// Passing the actual track title and not the template to the encoder for id3 type info
// NO => title of the track.
trackName = d->track_titles[d->req_track];
encoder->fillSongInfo(trackName, d->cd_artist, d->cd_title, d->cd_category, d->req_track+1, d->cd_year, "");
info.trackInfoList[track].title = info.title.utf8().data();
}
encoder->fillSongInfo(info, track, "");
}
else {
encoder->fillSongInfo("", "", "", "", d->req_track+1, 0, QString("CDDBDISCID=%1").arg(d->discid));
encoder->fillSongInfo(info, d->req_track+1, QString("CDDBDISCID=%1").arg(d->cddbBestChoice.id));
}
long totalByteCount = CD_FRAMESIZE_RAW * (lastSector - firstSector + 1);
long time_secs = (8 * totalByteCount) / (44100 * 2 * 16);
......@@ -506,42 +503,6 @@ void AudioCDProtocol::stat(const KURL & url)
finished();
}
void AudioCDProtocol::updateCD(struct cdrom_drive * drive)
{
KCompactDisc cd(KCompactDisc::Asynchronous);
// TODO which one is right?
qDebug("\"%s\" \"%s\"", drive->cdda_device_name, drive->ioctl_device_name);
cd.setDevice(drive->ioctl_device_name, 50, false);
if (cd.discId() == d->discid || cd.discId() == cd.missingDisc)
return;
else
d->discid = cd.discId();
d->tracks = cd.tracks();
for(uint i=0; i< cd.tracks(); i++)
d->trackIsAudio[i] = cd.isAudio(i+1);
d->templateTitles.clear();
d->track_titles.clear();
KCDDB::Client c;
d->cddbResult = c.lookup(cd.discSignature());
if (d->cddbResult == KCDDB::CDDB::Success)
{
d->cddbList = c.lookupResponse();
d->cddbBestChoice = c.bestLookupResponse();
generateTemplateTitles();
}
else{
for (unsigned int i = 1; i <= cd.tracks(); i++)
{
d->templateTitles.append( i18n("Track %1").arg((double)i, 2, '0') );
d->track_titles.append( QString::null );
}
}
}
static void app_entry(UDSEntry& e, unsigned int uds, const QString& str)
{
UDSAtom a;
......@@ -648,14 +609,13 @@ void AudioCDProtocol::listDir(const KURL & url)
}
// Now fill in the tracks for the current directory
if (list_tracks && d->which_dir == FullCD) {
// if we're listing the "full CD" subdirectory :
if ( (d->which_dir == FullCD) ) {
AudioCDEncoder *encoder;
for ( encoder = encoders.first(); encoder; encoder = encoders.next() ){
if (d->cddbResult != KCDDB::CDDB::Success)
addEntry(QFL1("Full CD"), encoder, drive, -1);
addEntry(d->s_fullCD, encoder, drive, -1);
else
addEntry(d->templateAlbumName, encoder, drive, -1);
}
......@@ -730,7 +690,7 @@ long AudioCDProtocol::fileSize(long firstSector, long lastSector, AudioCDEncoder
return encoder->size(length_seconds);
}
struct cdrom_drive *AudioCDProtocol::pickDrive()
struct cdrom_drive *AudioCDProtocol::getDrive()
{
QCString device(QFile::encodeName(d->device));
......@@ -761,8 +721,17 @@ struct cdrom_drive *AudioCDProtocol::pickDrive()
error(KIO::ERR_DOES_NOT_EXIST, d->device);
else error(KIO::ERR_SLAVE_DEFINED,
i18n("Unknown error. If you have a cd in the drive try running cdparanoia -vsQ as yourself (not root). Do you see a track list? If not, make sure you have permission to access the CD device. If you are using SCSI emulation (possible if you have an IDE CD writer) then make sure you check that you have read and write permissions on the generic SCSI device, which is probably /dev/sg0, /dev/sg1, etc.. If it still does not work, try typing audiocd:/?device=/dev/sg0 (or similar) to tell kio_audiocd which device your CD-ROM is."));
return 0;
}
if (0 != cdda_open(drive))
{
kdDebug(7117) << "cdda_open failed" << endl;
error(KIO::ERR_CANNOT_OPEN_FOR_READING, d->device);
cdda_close(drive);
return 0;
}
return drive;
}
......@@ -1010,6 +979,7 @@ void AudioCDProtocol::loadSettings()
// Tell the encoders to load their settings
AudioCDEncoder *encoder;
for ( encoder = encoders.first(); encoder; encoder = encoders.next() ){
encoder->init();
encoder->loadSettings();
}
......@@ -1021,33 +991,32 @@ void AudioCDProtocol::loadSettings()
*/
void AudioCDProtocol::generateTemplateTitles()
{
d->templateTitles.clear();
if (d->cddbResult != KCDDB::CDDB::Success)
{
for (unsigned int i = 1; i <= d->tracks; i++){
QString n;
d->templateTitles.append( i18n("Track %1").arg(n.sprintf("%02d", i + 1)));
}
return;
}
KCDDB::CDInfo info = d->cddbBestChoice;
if(d->cddbUserChoice >= 0 && (((uint)d->cddbUserChoice) < d->cddbList.count()))
info = d->cddbList[d->cddbUserChoice];
// First save it for the encoders
// Might it be easier to just save the whole thing?
d->cd_title = info.title;
d->cd_artist = info.artist;
d->cd_category = info.genre;
d->cd_year = info.year;
KCDDB::TrackInfoList t = info.trackInfoList;
for (uint i = 0; i < t.count(); i++)
d->track_titles.append(t[i].title);
// Then generate the templates
d->templateTitles.clear();
for (uint i = 0; i < d->tracks; i++) {
QMap<QString, QString> macros;
macros["albumartist"] = d->cd_artist;
macros["albumtitle"] = d->cd_title;
macros["title"] = d->track_titles[i];
macros["number"] = QString("%1").arg((double)(i+1), 2, '0');
macros["genre"] = d->cd_category;
macros["year"] = QString::number(d->cd_year);
macros["albumartist"] = info.artist;
macros["albumtitle"] = info.title;
macros["title"] = (info.trackInfoList[i].title);
QString n;
macros["number"] = n.sprintf("%02d", i + 1);
//macros["number"] = QString("%1").arg(i+1, 2, 10);
macros["genre"] = info.genre;
macros["year"] = QString::number(info.year);
QString title = KMacroExpander::expandMacros(d->fileNameTemplate, macros, '%').replace('/', QFL1("%2F"));
title.replace( QRegExp(d->rsearch), d->rreplace );
......@@ -1055,10 +1024,10 @@ void AudioCDProtocol::generateTemplateTitles()
}
QMap<QString, QString> macros;
macros["albumartist"] = d->cd_artist;
macros["albumtitle"] = d->cd_title;
macros["genre"] = d->cd_category;
macros["year"] = QString::number(d->cd_year);
macros["albumartist"] = info.artist;
macros["albumtitle"] = info.title;
macros["genre"] = info.genre;
macros["year"] = QString::number(info.year);
d->templateAlbumName = KMacroExpander::expandMacros(d->albumTemplate, macros, '%').replace('/', QFL1("%2F"));
d->templateAlbumName.replace( QRegExp(d->rsearch), d->rreplace );
}
......
......@@ -5,7 +5,7 @@
* Copyright (C) 2001 Adrian Schroeter <adrian@suse.de>
* Copyright (C) 2003 Richard Lärkäng <richard@goteborg.utfors.se>
* Copyright (C) 2003 Scott Wheeler <wheeler@kde.org>
* Copyright (C) 2004 Benjamin Meyer <ben + audiocd at meyerhome dot net>
* Copyright (C) 2004, 2005 Benjamin Meyer <ben at meyerhome dot net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -88,7 +88,6 @@ class AudioCDProtocol : public KIO::SlaveBase
struct cdrom_drive *initRequest(const KURL &);
uint discid(struct cdrom_drive *);
void updateCD(struct cdrom_drive *);
/**
* Add an entry in the KIO directory, using the title you give,
......@@ -113,7 +112,7 @@ private:
void generateTemplateTitles();
QPtrList<AudioCDEncoder> encoders;
cdrom_drive * pickDrive();
cdrom_drive * getDrive();
// These are the only garenteed encoders to be built, the rest
// are dynamic depending on other libraries on the system
......
......@@ -8,10 +8,13 @@
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>551</height>
<width>640</width>
<height>563</height>
</rect>
</property>
<property name="caption">
<string>AudiocdConfig</string>
</property>
<property name="layoutMargin" stdset="0">
</property>
<property name="layoutSpacing" stdset="0">
......@@ -49,129 +52,28 @@
<attribute name="title">
<string>&amp;General</string>
</attribute>
<vbox>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QGroupBox">
<spacer row="4" column="2">
<property name="name">
<cstring>GroupBox9</cstring>
<cstring>Spacer5</cstring>
</property>
<property name="title">
<string>CD Device</string>
<property name="orientation">
<enum>Vertical</enum>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<property name="margin">
<number>11</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<widget class="QCheckBox">
<property name="name">
<cstring>cd_autosearch_check</cstring>
</property>
<property name="text">
<string>De&amp;termine device automatically</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="whatsThis" stdset="0">
<string>Uncheck this if you want to specify a CD device different from the one autoprobed</string>
</property>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>Layout20</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<widget class="QLabel">
<property name="name">
<cstring>TextLabel1</cstring>
</property>
<property name="text">
<string>De&amp;vice:</string>
</property>
<property name="buddy" stdset="0">
<cstring>cd_device_string</cstring>
</property>
</widget>
<widget class="QLineEdit">
<property name="name">
<cstring>cd_device_string</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>/dev/cdrom</string>
</property>
<property name="whatsThis" stdset="0">
<string>Specify a location for the drive you want to use. Normally, this is a file inside the /dev folder representing your CD or DVD drive.</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
<widget class="QGroupBox">
<property name="name">
<cstring>GroupBox19</cstring>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="title">
<string>Error Correction Settings</string>
<property name="sizeHint">
<size>
<width>20</width>
<height>210</height>
</size>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<property name="margin">
<number>11</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<widget class="QCheckBox">
<property name="name">
<cstring>ec_enable_check</cstring>
</property>
<property name="text">
<string>Enable &amp;error correction</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="whatsThis" stdset="0">
<string>If you check this option, the slave will not try to use error correction which can be useful for reading damaged CDs. However, this feature can be problematic in some cases, so you can switch it off here.</string>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>ec_skip_check</cstring>
</property>
<property name="text">
<string>&amp;Skip on errors</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</vbox>
</widget>
<widget class="QGroupBox">
</spacer>
<widget class="QGroupBox" row="3" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>encoderPriority</cstring>
</property>
......@@ -234,24 +136,83 @@
</widget>
</grid>
</widget>
<spacer>
<widget class="QLineEdit" row="0" column="2">
<property name="name">
<cstring>Spacer5</cstring>
<cstring>cd_device_string</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>/dev/cdrom</string>
</property>
<property name="whatsThis" stdset="0">
<string>Specify a location for the drive you want to use. Normally, this is a file inside the /dev folder representing your CD or DVD drive.</string>
</property>
</widget>
<widget class="QCheckBox" row="0" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>cd_autosearch_check</cstring>
</property>
<property name="text">
<string>&amp;Specify CD Device:</string>
</property>
<property name="accel">
<string>Alt+S</string>
</property>
<property name="whatsThis" stdset="0">
<string>Uncheck this if you want to specify a CD device different from the one autoprobed</string>
</property>
</widget>
<widget class="QCheckBox" row="1" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>ec_enable_check</cstring>
</property>
<property name="text">
<string>Use &amp;error correction when reading the CD</string>
</property>
<property name="accel">
<string>Alt+E</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="whatsThis" stdset="0">
<string>If you check this option, the slave will not try to use error correction which can be useful for reading damaged CDs. However, this feature can be problematic in some cases, so you can switch it off here.</string>
</property>
</widget>
<widget class="QCheckBox" row="2" column="1" rowspan="1" colspan="2">
<property name="name">
<cstring>ec_skip_check</cstring>
</property>
<property name="text">
<string>&amp;Skip on errors</string>
</property>
<property name="accel">
<string>Alt+S</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<spacer row="2" column="0">
<property name="name">
<cstring>spacer4_2</cstring>
</property>
<property name="orientation">