aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-11-21 17:13:34 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-11-21 17:13:34 +0000
commit90b71df1362b7e128ca99ee09cc8402b8421f76d (patch)
tree24faee1a7b7b0f7610015a8f57ffa60b2865f7c9 /src/qmmpui
parentbfda47d04f9f520638f652bdb7fffb6de3dfd992 (diff)
downloadqmmp-90b71df1362b7e128ca99ee09cc8402b8421f76d.tar.gz
qmmp-90b71df1362b7e128ca99ee09cc8402b8421f76d.tar.bz2
qmmp-90b71df1362b7e128ca99ee09cc8402b8421f76d.zip
added metadata formatter
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1389 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/qmmpui')
-rw-r--r--src/qmmpui/CMakeLists.txt3
-rw-r--r--src/qmmpui/metadataformatter.cpp98
-rw-r--r--src/qmmpui/metadataformatter.h43
-rw-r--r--src/qmmpui/playlistitem.cpp42
-rw-r--r--src/qmmpui/playlistitem.h1
5 files changed, 147 insertions, 40 deletions
diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt
index 84b640b7a..595cf4f0c 100644
--- a/src/qmmpui/CMakeLists.txt
+++ b/src/qmmpui/CMakeLists.txt
@@ -39,6 +39,7 @@ SET(libqmmpui_SRCS
detailsdialog.cpp
tageditor.cpp
playlistmanager.cpp
+ metadataformatter.cpp
)
SET(libqmmpui_MOC_HDRS
@@ -62,6 +63,7 @@ SET(libqmmpui_MOC_HDRS
detailsdialog.h
tageditor.h
playlistmanager.h
+ metadataformatter.h
)
SET(libqmmpui_DEVEL_HDRS
@@ -81,6 +83,7 @@ SET(libqmmpui_DEVEL_HDRS
detailsdialog.h
tageditor.h
playlistmanager.h
+ metadataformatter.h
)
diff --git a/src/qmmpui/metadataformatter.cpp b/src/qmmpui/metadataformatter.cpp
new file mode 100644
index 000000000..9a055f4e9
--- /dev/null
+++ b/src/qmmpui/metadataformatter.cpp
@@ -0,0 +1,98 @@
+/***************************************************************************
+ * Copyright (C) 2009 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. *
+ ***************************************************************************/
+
+
+/*
+Syntax:
+%p - artist
+%a - album
+%t - title
+%n - track,
+%NN - 2-digit track
+%g - genre
+%c - comment
+%C - composer
+%D - disc number
+%f - file name
+%F - full path
+%y - year
+%if(A,B,C)
+%if(A&B&C,D,E)
+*/
+
+#include <QStringList>
+#include <QUrl>
+#include "metadataformatter.h"
+
+MetaDataFormatter::MetaDataFormatter(const QString &format)
+{
+ m_format = format;
+}
+
+QString MetaDataFormatter::parse(const QMap<Qmmp::MetaData, QString> metaData)
+{
+ QString title = m_format;
+ title.replace("\\(", "%28");
+ title.replace("\\)", "%29");
+ title.replace(")", "%)");
+ title.replace("&", "%&");
+ title.replace("%p", metaData[Qmmp::ARTIST]);
+ title.replace("%a", metaData[Qmmp::ALBUM]);
+ title.replace("%t", metaData[Qmmp::TITLE]);
+ title.replace("%n", metaData[Qmmp::TRACK]);
+ title.replace("%NN", QString("%1").arg(metaData[Qmmp::TRACK],2,'0'));
+ title.replace("%g", metaData[Qmmp::GENRE]);
+ title.replace("%c", metaData[Qmmp::COMMENT]);
+ title.replace("%C", metaData[Qmmp::COMPOSER]);
+ title.replace("%D", metaData[Qmmp::DISCNUMBER]);
+ title.replace("%f", metaData[Qmmp::URL].section('/',-1));
+ title.replace("%F", metaData[Qmmp::URL]);
+ title.replace("%y", metaData[Qmmp::YEAR]);
+
+ if(title.contains("%if"))
+ title = processIfKeyWord(title);
+ title.replace("%28", "(");
+ title.replace("%29", ")");
+ return title;
+}
+
+QString MetaDataFormatter::processIfKeyWord(QString title)
+{
+ int pos = title.indexOf("%if(");
+ int size = title.indexOf("%)",pos) - pos;
+
+ QStringList args = title.mid (pos + 4, size - 4).split(",");
+ if(args.count() < 3)
+ {
+ qWarning("TitleFormatter: invalid title format");
+ return title;
+ }
+ //process condition
+ bool cond = TRUE;
+ foreach(QString arg, args.at(0).split("%&"))
+ {
+ cond &= !arg.isEmpty();
+ }
+ QString r_str = cond ? args.at(1) : args.at(2);
+ title.replace (pos, size + 2, r_str);
+ if(title.contains("%if"))
+ return processIfKeyWord(title);
+ return title;
+}
diff --git a/src/qmmpui/metadataformatter.h b/src/qmmpui/metadataformatter.h
new file mode 100644
index 000000000..c826cb499
--- /dev/null
+++ b/src/qmmpui/metadataformatter.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (C) 2009 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 METADATAFORMATTER_H
+#define METADATAFORMATTER_H
+
+#include <QString>
+#include <QMap>
+#include <qmmp/qmmp.h>
+
+/*!
+ * @author Ilya Kotov <forkotov02@hotmail.ru>
+ */
+class MetaDataFormatter
+{
+public:
+ MetaDataFormatter(const QString &format);
+ QString parse(const QMap<Qmmp::MetaData, QString> metaData);
+
+private:
+ QString m_format;
+ QString processIfKeyWord(QString title);
+
+};
+
+#endif // METADATAFORMATTER_H
diff --git a/src/qmmpui/playlistitem.cpp b/src/qmmpui/playlistitem.cpp
index 60422aee1..3bb57963a 100644
--- a/src/qmmpui/playlistitem.cpp
+++ b/src/qmmpui/playlistitem.cpp
@@ -21,6 +21,7 @@
#include <QDir>
#include <qmmp/metadatamanager.h>
+#include "metadataformatter.h"
#include "playlistsettings.h"
#include "playlistitem.h"
@@ -117,18 +118,8 @@ void PlayListItem::setText(const QString &title)
void PlayListItem::readMetadata()
{
- m_title = PlaylistSettings::instance()->format();
- m_title = printTag(m_title, "%p", artist());
- m_title = printTag(m_title, "%a", album());
- m_title = printTag(m_title, "%t", title());
- m_title = printTag(m_title, "%n", track());
- m_title = printTag(m_title, "%c", comment());
- m_title = printTag(m_title, "%C", composer());
- m_title = printTag(m_title, "%g", genre());
- m_title = printTag(m_title, "%D", discNumber());
- m_title = printTag(m_title, "%f", url().section('/',-1));
- m_title = printTag(m_title, "%F", url());
- m_title = printTag(m_title, "%y", year ());
+ MetaDataFormatter f(PlaylistSettings::instance()->format());
+ m_title = f.parse(metaData());
//TODO rewrite this
if (m_title.isEmpty())
{
@@ -143,30 +134,3 @@ void PlayListItem::readMetadata()
if (PlaylistSettings::instance()->convertTwenty())
m_title.replace("%20", " ");
}
-
-QString PlayListItem::printTag(QString str, QString regExp, QString tagStr)
-{
- QString format = PlaylistSettings::instance()->format();
- if (!tagStr.isEmpty())
- str.replace(regExp, tagStr);
- else
- {
- //remove unused separators
- int regExpPos = str.indexOf(regExp);
- if (regExpPos < 0)
- return str;
- int nextPos = str.indexOf("%", regExpPos + 1);
- if (nextPos < 0)
- {
- //last separator
- regExpPos = format.lastIndexOf(regExp);
- nextPos = format.lastIndexOf("%", regExpPos - 1);
- QString lastSep = format.right (format.size() - nextPos - 2);
- str.remove(lastSep);
- str.remove(regExp);
- }
- else
- str.remove ( regExpPos, nextPos - regExpPos);
- }
- return str;
-}
diff --git a/src/qmmpui/playlistitem.h b/src/qmmpui/playlistitem.h
index 86d89d50d..c1bec3e38 100644
--- a/src/qmmpui/playlistitem.h
+++ b/src/qmmpui/playlistitem.h
@@ -104,7 +104,6 @@ public:
private:
void readMetadata();
- QString printTag(QString str, QString regExp, QString tagStr);
QString m_title;
FileInfo *m_info;
bool m_selected;