[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdemultimedia/kioslave/audiocd
From:       David Faure <faure () kde ! org>
Date:       2005-12-28 20:52:32
Message-ID: 1135803152.499560.19174.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 492124 by dfaure:

Call lame with --genre-list in init(), and check if it knows the genre
that we want to pass it via --tg, to avoid errors.
To make the code simple I copied collectingprocess from libkdepim,
this will go away in final kde4 hopefully, but is still needed for now.


 M  +1 -1      audiocd.cpp  
 M  +1 -1      plugins/lame/Makefile.am  
 A             plugins/lame/collectingprocess.cpp   [License: GPL (v2+) (+Qt \
exception)]  A             plugins/lame/collectingprocess.h   [License: GPL (v2+) \
(+Qt exception)]  M  +30 -2     plugins/lame/encoderlame.cpp  


--- trunk/KDE/kdemultimedia/kioslave/audiocd/audiocd.cpp #492123:492124
@@ -964,7 +964,7 @@
 	AudioCDEncoder *encoder;
 	for (int i = encoders.size()-1; i >= 0; --i) {
             	encoder = encoders.at(i);
-		encoder->init();
+		encoder->init(); // ### TODO check return value!
 		encoder->loadSettings();
 	}
 
--- trunk/KDE/kdemultimedia/kioslave/audiocd/plugins/lame/Makefile.am #492123:492124
@@ -4,7 +4,7 @@
 
 kde_module_LTLIBRARIES = libaudiocd_encoder_lame.la
 
-libaudiocd_encoder_lame_la_SOURCES = audiocd_lame_encoder.kcfgc encoderlame.cpp \
encoderlameconfig.ui +libaudiocd_encoder_lame_la_SOURCES = audiocd_lame_encoder.kcfgc \
encoderlame.cpp encoderlameconfig.ui collectingprocess.cpp  
 libaudiocd_encoder_lame_la_LIBADD = $(LIB_KIO) ../libaudiocdplugins.la
 
--- trunk/KDE/kdemultimedia/kioslave/audiocd/plugins/lame/encoderlame.cpp \
#492123:492124 @@ -32,6 +32,7 @@
 #include <qfileinfo.h>
 #include <ktempfile.h>
 #include <kstandarddirs.h>
+#include "collectingprocess.h"
 
 extern "C"
 {
@@ -49,6 +50,7 @@
 	bool waitingForWrite;
 	bool processHasExited;
 	QString lastErrorMessage;
+	QStringList genreList;
 	uint lastSize;
 	KProcess *currentEncodeProcess;
 	KTempFile *tempFile;
@@ -76,7 +78,32 @@
 
 bool EncoderLame::init(){
 	// Determine if lame is installed on the system or not.
-        return !KStandardDirs::findExe( "lame" ).isEmpty();
+	if ( KStandardDirs::findExe( "lame" ).isEmpty() )
+		return false;
+
+	// Ask lame for the list of genres it knows; otherwise it barfs when doing
+	// e.g. lame --tg 'Vocal Jazz'
+    CollectingProcess proc;
+	proc << "lame" << "--genre-list";
+	proc.start(KProcess::Block, KProcess::Stdout);
+
+	if(proc.exitStatus() != 0)
+		return false;
+
+	QString str = QString::fromLocal8Bit( proc.collectedStdout() );
+	d->genreList = QStringList::split( '\n', str );
+	// Remove the numbers in front of every genre
+	for( QStringList::Iterator it = d->genreList.begin(); it != d->genreList.end(); \
++it ) { +		QString& genre = *it;
+		int i = 0;
+		while ( i < genre.length() && ( genre[i].isSpace() || genre[i].isDigit() ) )
+			++i;
+		genre = genre.mid( i );
+
+	}
+	//kdDebug(7117) << "Available genres:" << d->genreList << endl;
+
+	return true;
 }
 
 void EncoderLame::loadSettings(){
@@ -184,6 +211,7 @@
 	d->tempFile = new KTempFile(prefix, ".mp3");
 	d->tempFile->setAutoDelete(true);
 	d->lastErrorMessage = QString::null;
+	d->processHasExited = false;
 
 	// -x bitswap
 	// -r raw/pcm
@@ -313,7 +341,7 @@
 	trackInfo.append(QString("%1").arg(track));
 
 	const QString genre = info.get( "genre" ).toString();
-	if ( genre != "Unknown" ) // lame barfs on "--tg Unknown"
+	if ( d->genreList.find( genre ) != d->genreList.end() )
 	{
 	trackInfo.append("--tg");
 		trackInfo.append(genre);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic