diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-10-13 16:03:35 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-10-13 16:03:35 +0000 |
| commit | 7acba956ed3ef3528c6fafe7cb38d94d796e6a4a (patch) | |
| tree | 541cf8a5ab5ad5685917ff18cc9acc57aeca32c5 /src | |
| parent | 54e71369e1b2dde50af1ee6f41c5375f7ae32610 (diff) | |
| download | qmmp-7acba956ed3ef3528c6fafe7cb38d94d796e6a4a.tar.gz qmmp-7acba956ed3ef3528c6fafe7cb38d94d796e6a4a.tar.bz2 qmmp-7acba956ed3ef3528c6fafe7cb38d94d796e6a4a.zip | |
CUE plugin: additional metadata support, CUE codepage settings
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@583 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/Input/cue/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | src/plugins/Input/cue/cue.pro | 8 | ||||
| -rw-r--r-- | src/plugins/Input/cue/cueparser.cpp | 39 | ||||
| -rw-r--r-- | src/plugins/Input/cue/decoder_cue.cpp | 4 | ||||
| -rw-r--r-- | src/plugins/Input/cue/decodercuefactory.cpp | 17 | ||||
| -rw-r--r-- | src/plugins/Input/cue/decodercuefactory.h | 1 | ||||
| -rw-r--r-- | src/plugins/Input/cue/settingsdialog.cpp | 93 | ||||
| -rw-r--r-- | src/plugins/Input/cue/settingsdialog.h | 51 | ||||
| -rw-r--r-- | src/plugins/Input/cue/settingsdialog.ui | 90 | ||||
| -rw-r--r-- | src/ui/playlistmodel.cpp | 3 |
10 files changed, 291 insertions, 31 deletions
diff --git a/src/plugins/Input/cue/CMakeLists.txt b/src/plugins/Input/cue/CMakeLists.txt index b27497e1f..5327c59e3 100644 --- a/src/plugins/Input/cue/CMakeLists.txt +++ b/src/plugins/Input/cue/CMakeLists.txt @@ -30,15 +30,15 @@ link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) SET(libcue_SRCS decoder_cue.cpp decodercuefactory.cpp -# detailsdialog.cpp + settingsdialog.cpp cueparser.cpp ) SET(libcue_MOC_HDRS decodercuefactory.h decoder_cue.h -# detailsdialog.h - cueparser.h + settingsdialog.h + cueparser.h ) #SET(libcue_RCCS translations/translations.qrc) @@ -50,16 +50,16 @@ QT4_WRAP_CPP(libcue_MOC_SRCS ${libcue_MOC_HDRS}) # user interface -#SET(libcue_UIS -# detailsdialog.ui -#) +SET(libcue_UIS + settingsdialog.ui +) -#QT4_WRAP_UI(libcue_UIS_H ${libcue_UIS}) +QT4_WRAP_UI(libcue_UIS_H ${libcue_UIS}) # Don't forget to include output directory, otherwise # the UI file won't be wrapped! include_directories(${CMAKE_CURRENT_BINARY_DIR}) -ADD_LIBRARY(cue SHARED ${libcue_SRCS} ${libcue_MOC_SRCS} ${libcue_RCC_SRCS}) +ADD_LIBRARY(cue SHARED ${libcue_SRCS} ${libcue_MOC_SRCS} ${libcue_RCC_SRCS} ${libcue_UIS_H}) add_dependencies(cue qmmp) target_link_libraries(cue ${QT_LIBRARIES} -lqmmp) install(TARGETS cue DESTINATION ${LIB_DIR}/qmmp/Input) diff --git a/src/plugins/Input/cue/cue.pro b/src/plugins/Input/cue/cue.pro index 1c0771d5c..3146ae514 100644 --- a/src/plugins/Input/cue/cue.pro +++ b/src/plugins/Input/cue/cue.pro @@ -3,10 +3,12 @@ include(../../plugins.pri) #FORMS += detailsdialog.ui HEADERS += decodercuefactory.h \ cueparser.h \ - decoder_cue.h + decoder_cue.h \ + settingsdialog.h SOURCES += decoder_cue.cpp \ decodercuefactory.cpp \ - cueparser.cpp + cueparser.cpp \ + settingsdialog.cpp TARGET =$$PLUGINS_PREFIX/Input/cue QMAKE_CLEAN =$$PLUGINS_PREFIX/Input/libcue.so @@ -34,3 +36,5 @@ isEmpty(LIB_DIR){ } target.path = $$LIB_DIR/qmmp/Input INSTALLS += target +FORMS += settingsdialog.ui + diff --git a/src/plugins/Input/cue/cueparser.cpp b/src/plugins/Input/cue/cueparser.cpp index 6fdf5d0f8..768203edc 100644 --- a/src/plugins/Input/cue/cueparser.cpp +++ b/src/plugins/Input/cue/cueparser.cpp @@ -22,6 +22,9 @@ #include <QFileInfo> #include <QRegExp> #include <QDir> +#include <QSettings> +#include <QTextStream> +#include <QTextCodec> #include <qmmp/decoder.h> @@ -29,24 +32,26 @@ CUEParser::CUEParser(const QString &fileName) { - QString album; QFile file(fileName); - if(!file.open(QIODevice::ReadOnly)) + if (!file.open(QIODevice::ReadOnly)) { - qDebug("CUEParser: Error: %s", qPrintable(file.errorString())); + qDebug("CUEParser: error: %s", qPrintable(file.errorString())); return; } - - while (!file.atEnd()) + QString album, genre, date, comment; + QTextStream textStream (&file); + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + QTextCodec *codec = QTextCodec::codecForName(settings.value("CUE/encoding","ISO-8859-1").toByteArray ()); + textStream.setCodec(codec); + while (!textStream.atEnd()) { - QString line = file.readLine().trimmed(); + QString line = textStream.readLine().trimmed(); QStringList words = splitLine(line); if (words.size() < 2) continue; if (words[0] == "FILE") { - //TODO check support m_filePath = QUrl(fileName).path (); m_filePath = QFileInfo(m_filePath).dir().filePath(words[1]); } @@ -79,10 +84,21 @@ CUEParser::CUEParser(const QString &fileName) m_infoList.last ().setLength(getLength(words[2])); m_offsets.last() = getLength(words[2]); } + else if (words[0] == "REM") + { + if (words.size() < 3) + continue; + if (words[1] == "GENRE") + genre = words[2]; + else if (words[1] == "DATE") + date = words[2]; + else if (words[1] == "COMMENT") + comment = words[2]; + } } //calculate length for (int i = 0; i < m_infoList.size() - 1; ++i) - m_infoList[i].setLength(m_infoList[i+1].length()-m_infoList[i].length()); + m_infoList[i].setLength(m_infoList[i+1].length() - m_infoList[i].length()); //calculate last item length QList <FileInfo *> f_list; f_list = Decoder::createPlayList(m_filePath); @@ -92,9 +108,12 @@ CUEParser::CUEParser(const QString &fileName) else m_infoList.last().setLength(0); - foreach(FileInfo info, m_infoList) + for(int i = 0; i < m_infoList.size(); ++i) { - info.setMetaData(Qmmp::ALBUM, album); + m_infoList[i].setMetaData(Qmmp::ALBUM, album); + m_infoList[i].setMetaData(Qmmp::GENRE, genre); + m_infoList[i].setMetaData(Qmmp::YEAR, date); + m_infoList[i].setMetaData(Qmmp::COMMENT, comment); } file.close(); } diff --git a/src/plugins/Input/cue/decoder_cue.cpp b/src/plugins/Input/cue/decoder_cue.cpp index 3ebc0fdca..8e570e478 100644 --- a/src/plugins/Input/cue/decoder_cue.cpp +++ b/src/plugins/Input/cue/decoder_cue.cpp @@ -50,14 +50,14 @@ bool DecoderCUE::initialize() CUEParser parser(QUrl(path).path()); if (parser.count() == 0) { - qWarning("DecoderCUE: Invalid cue file"); + qWarning("DecoderCUE: invalid cue file"); return FALSE; } int track = path.section("#", -1).toInt(); path = parser.filePath(); if (!QFile::exists(path)) { - qWarning("DecoderCUE: File \"%s\" doesn't exist", qPrintable(path)); + qWarning("DecoderCUE: file \"%s\" doesn't exist", qPrintable(path)); return FALSE; } DecoderFactory *df = Decoder::findByPath(path); diff --git a/src/plugins/Input/cue/decodercuefactory.cpp b/src/plugins/Input/cue/decodercuefactory.cpp index c87c4f4a6..d1baf3fcf 100644 --- a/src/plugins/Input/cue/decodercuefactory.cpp +++ b/src/plugins/Input/cue/decodercuefactory.cpp @@ -21,6 +21,7 @@ #include "decoder_cue.h" #include "cueparser.h" +#include "settingsdialog.h" #include "decodercuefactory.h" @@ -31,7 +32,7 @@ bool DecoderCUEFactory::supports(const QString &source) const return source.right(4).toLower() == ".cue"; } -bool DecoderCUEFactory::canDecode(QIODevice *input) const +bool DecoderCUEFactory::canDecode(QIODevice *) const { return FALSE; } @@ -46,7 +47,7 @@ const DecoderProperties DecoderCUEFactory::properties() const //properties.contentType = "application/ogg;audio/x-vorbis+ogg"; properties.protocols = "cue"; properties.hasAbout = TRUE; - properties.hasSettings = FALSE; + properties.hasSettings = TRUE; properties.noInput = TRUE; properties.noOutput = TRUE; return properties; @@ -55,23 +56,27 @@ const DecoderProperties DecoderCUEFactory::properties() const Decoder *DecoderCUEFactory::create(QObject *parent, QIODevice *input, Output *output, const QString &url) { + Q_UNUSED(input); + Q_UNUSED(output); return new DecoderCUE(parent, this, url); } -//FileInfo *DecoderCUEFactory::createFileInfo(const QString &source) QList<FileInfo *> DecoderCUEFactory::createPlayList(const QString &fileName) { CUEParser parser(fileName); return parser.createPlayList(); } -QObject* DecoderCUEFactory::showDetails(QWidget *parent, const QString &path) +QObject* DecoderCUEFactory::showDetails(QWidget *, const QString &) { return 0; } -void DecoderCUEFactory::showSettings(QWidget *) -{} +void DecoderCUEFactory::showSettings(QWidget *parent) +{ + SettingsDialog *s = new SettingsDialog(parent); + s->show(); +} void DecoderCUEFactory::showAbout(QWidget *parent) { diff --git a/src/plugins/Input/cue/decodercuefactory.h b/src/plugins/Input/cue/decodercuefactory.h index 8cf38c6ad..2375fc896 100644 --- a/src/plugins/Input/cue/decodercuefactory.h +++ b/src/plugins/Input/cue/decodercuefactory.h @@ -40,7 +40,6 @@ public: bool canDecode(QIODevice *input) const; const DecoderProperties properties() const; Decoder *create(QObject *, QIODevice *, Output *, const QString &); - //FileInfo *createFileInfo(const QString &source); QList<FileInfo *> createPlayList(const QString &fileName); QObject* showDetails(QWidget *parent, const QString &path); void showSettings(QWidget *parent); diff --git a/src/plugins/Input/cue/settingsdialog.cpp b/src/plugins/Input/cue/settingsdialog.cpp new file mode 100644 index 000000000..d0bb845ca --- /dev/null +++ b/src/plugins/Input/cue/settingsdialog.cpp @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include <QTextCodec> +#include <QSettings> +#include <QDir> + +#include "settingsdialog.h" + +SettingsDialog::SettingsDialog(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + findCodecs(); + foreach (QTextCodec *codec, codecs) + { + ui.cueEncComboBox->addItem(codec->name()); + } + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + settings.beginGroup("CUE"); + int pos = ui.cueEncComboBox->findText(settings.value("encoding","ISO-8859-1").toString()); + ui.cueEncComboBox->setCurrentIndex(pos); + settings.endGroup(); + connect(ui.okButton, SIGNAL(clicked()), SLOT(writeSettings())); +} + + +SettingsDialog::~SettingsDialog() +{} + +void SettingsDialog::writeSettings() +{ + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + settings.beginGroup("CUE"); + settings.setValue("encoding", ui.cueEncComboBox->currentText()); + settings.endGroup(); + accept(); +} + +void SettingsDialog::findCodecs() +{ + QMap<QString, QTextCodec *> codecMap; + QRegExp iso8859RegExp("ISO[- ]8859-([0-9]+).*"); + + foreach (int mib, QTextCodec::availableMibs()) + { + QTextCodec *codec = QTextCodec::codecForMib(mib); + + QString sortKey = codec->name().toUpper(); + int rank; + + if (sortKey.startsWith("UTF-8")) + { + rank = 1; + } + else if (sortKey.startsWith("UTF-16")) + { + rank = 2; + } + else if (iso8859RegExp.exactMatch(sortKey)) + { + if (iso8859RegExp.cap(1).size() == 1) + rank = 3; + else + rank = 4; + } + else + { + rank = 5; + } + sortKey.prepend(QChar('0' + rank)); + + codecMap.insert(sortKey, codec); + } + codecs = codecMap.values(); +} diff --git a/src/plugins/Input/cue/settingsdialog.h b/src/plugins/Input/cue/settingsdialog.h new file mode 100644 index 000000000..3c3d7a563 --- /dev/null +++ b/src/plugins/Input/cue/settingsdialog.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include <QDialog> + + +#include "ui_settingsdialog.h" + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class SettingsDialog : public QDialog +{ +Q_OBJECT +public: + SettingsDialog(QWidget *parent = 0); + + ~SettingsDialog(); + + +private slots: + void writeSettings(); + +private: + void findCodecs(); + + Ui::SettingsDialog ui; + QList<QTextCodec *> codecs; + +}; + +#endif diff --git a/src/plugins/Input/cue/settingsdialog.ui b/src/plugins/Input/cue/settingsdialog.ui new file mode 100644 index 000000000..8f4eb1ab7 --- /dev/null +++ b/src/plugins/Input/cue/settingsdialog.ui @@ -0,0 +1,90 @@ +<ui version="4.0" > + <class>SettingsDialog</class> + <widget class="QDialog" name="SettingsDialog" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>261</width> + <height>72</height> + </rect> + </property> + <property name="windowTitle" > + <string>CUE Plugin Settings</string> + </property> + <layout class="QGridLayout" name="gridLayout" > + <property name="margin" > + <number>5</number> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="label_17_2_2" > + <property name="focusPolicy" > + <enum>Qt::TabFocus</enum> + </property> + <property name="layoutDirection" > + <enum>Qt::LeftToRight</enum> + </property> + <property name="text" > + <string>CUE encoding:</string> + </property> + <property name="alignment" > + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QComboBox" name="cueEncComboBox" /> + </item> + <item row="1" column="0" colspan="2" > + <layout class="QHBoxLayout" name="horizontalLayout" > + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>131</width> + <height>31</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="okButton" > + <property name="text" > + <string>OK</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="cancelButton" > + <property name="text" > + <string>Cancel</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>cancelButton</sender> + <signal>clicked()</signal> + <receiver>SettingsDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel" > + <x>336</x> + <y>210</y> + </hint> + <hint type="destinationlabel" > + <x>179</x> + <y>224</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/ui/playlistmodel.cpp b/src/ui/playlistmodel.cpp index c17c78550..d891fe02c 100644 --- a/src/ui/playlistmodel.cpp +++ b/src/ui/playlistmodel.cpp @@ -305,7 +305,7 @@ void PlayListModel::showDetails() { if (m_items.at(i)->isSelected()) { - if (m_items.at(i)->path().startsWith("http://")) + if (!QFile::exists(m_items.at(i)->path())) { PlayListItem *item = m_items.at(i); QString str; @@ -396,7 +396,6 @@ void PlayListModel::writeSettings() { QFile file(QDir::homePath() +"/.qmmp/playlist.txt"); file.open(QIODevice::WriteOnly); - file.write(QString("count=%1").arg(m_items.count()).toUtf8() +"\n"); foreach(PlayListItem* m, m_items) { file.write(QString("file=%1").arg(m->path()).toUtf8() +"\n"); |
