From 87cad14c63df542097174455a0f2bb7d53a890ba Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Thu, 20 Jan 2011 17:32:05 +0000 Subject: improved cue parser (patch by Evgeny Gleyzerman) (Closes issue 375) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2019 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/cue/cueparser.cpp | 53 +++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'src/plugins/Input/cue/cueparser.cpp') diff --git a/src/plugins/Input/cue/cueparser.cpp b/src/plugins/Input/cue/cueparser.cpp index c21276229..3cb308ef5 100644 --- a/src/plugins/Input/cue/cueparser.cpp +++ b/src/plugins/Input/cue/cueparser.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2010 by Ilya Kotov * + * Copyright (C) 2008-2011 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -44,6 +45,7 @@ CUEParser::CUEParser(const QString &fileName) QTextCodec *codec = QTextCodec::codecForName(settings.value("encoding","ISO-8859-1").toByteArray ()); if(!codec) codec = QTextCodec::codecForName("UTF-8"); + m_dirty = settings.value("dirty_cue", false).toBool(); #ifdef WITH_ENCA EncaAnalyser analyser = 0; if(settings.value("use_enca", false).toBool()) @@ -88,7 +90,7 @@ CUEParser::CUEParser(const QString &fileName) else m_infoList.last().setLength(0); } - file_path = QFileInfo(fileName).dir().filePath(words[1]); + file_path = getDirtyPath(fileName, QFileInfo(fileName).dir().filePath(words[1])); new_file = true; } @@ -247,3 +249,50 @@ qint64 CUEParser::getLength(const QString &str) return (qint64)list.at(0).toInt()*60000 + list.at(1).toInt()*1000 + list.at(2).toInt()*1000/75; return 0; } + +QString CUEParser::getDirtyPath(const QString &cue, const QString &path) +{ + + if (Decoder::findByPath(path) || ! m_dirty) + return path; + + QStringList candidates; + QDirIterator it(QFileInfo(path).dir().path(), QDir::Files); + while (it.hasNext()) + { + it.next(); + QString f = it.filePath(); + if ((f != cue) && Decoder::findByPath(f)) + candidates.push_back(f); + } + + if (candidates.empty()) + return path; + else if (candidates.count() == 1) + return candidates.first(); + + int dot = cue.lastIndexOf('.'); + if (dot != -1) + { + QRegExp r(QRegExp::escape(cue.left(dot)) + "\\.[^\\.]+$"); + + int index = candidates.indexOf(r); + int rindex = candidates.lastIndexOf(r); + + if ((index != -1) && (index == rindex)) + return candidates[index]; + } + dot = path.lastIndexOf('.'); + if (dot != -1) + { + QRegExp r(QRegExp::escape(path.left(dot)) + "\\.[^\\.]+$"); + + int index = candidates.indexOf(r); + int rindex = candidates.lastIndexOf(r); + + if ((index != -1) && (index == rindex)) + return candidates[index]; + } + + return path; +} -- cgit v1.2.3-13-gbd6f