14
#include <kpopupmenu.h>
19
Plugin *create_plugin()
26
NID3::NID3() : QObject(0, "NID3"), Plugin(), mEditor(0)
29
connect(napp->player(), SIGNAL(newSong()), SLOT(newSong()));
30
menuID = napp->pluginMenuAdd(i18n("&ID3 Edit"), this, SLOT(editID3()));
31
connect(new IDPrefs(this), SIGNAL(saved()), SLOT(newSong()));
36
napp->pluginMenuRemove(menuID);
42
if (mEditor->isVisible())
50
static QString parseFormat(const QString &format, const QString &name, const QString &artist, const QString &album,
51
const QString &comment, const QString &year, const QString &genre);
55
PlaylistItem *item=napp->player()->current();
58
if (mEditor && !mEditor->isVisible())
65
mEditor=new Editor(this);
66
mEditor->open(item->file());
67
connect(mEditor, SIGNAL(saved()), SLOT(newSong()));
70
if (!mEditor->name().stripWhiteSpace().length()) return;
72
KConfig *config = KGlobal::config();
73
KConfigGroupSaver saver(config, "ID3 Tags");
74
QString format=config->readEntry("ID3Format", "%t");
76
QString title = parseFormat(format,mEditor->name(), mEditor->artist(),
77
mEditor->album(), mEditor->comment(), mEditor->year(), mEditor->genre());
78
// some titles/authors/songs might contain a / which is encoded as %2f
79
// so replace the encoding with the /
80
title.replace( QRegExp("%2f"), "/" );
81
item->setTitle( title );
83
// item->setProperty("title", mEditor->name());
84
item->setProperty("artist", mEditor->artist());
85
item->setProperty("album", mEditor->album());
86
item->setProperty("date", mEditor->year());
87
item->setProperty("comment", mEditor->comment());
90
static QString parseFormat(const QString &format, const QString &name, const QString &artist, const QString &album,
91
const QString &comment, const QString &year, const QString &genre)
93
QString parsed(format);
95
for (unsigned int pos=1; pos< parsed.length()-1; pos++)
97
if ((parsed[pos]=='%') && (parsed[pos-1]!='%'))
99
switch (parsed[pos+1].latin1())
102
parsed.replace(pos, 2, "%");
105
parsed.replace(pos, 2, artist);
108
parsed.replace(pos, 2, album);
111
parsed.replace(pos, 2, comment);
114
parsed.replace(pos, 2, name);
117
parsed.replace(pos, 2, year);
120
parsed.replace(pos, 2, year.right(2));
123
parsed.replace(pos, 2, genre);
128
return parsed.remove(0, 1);
132
IDPrefs::IDPrefs(QObject *parent)
133
: CModule(i18n("ID3 Tag Loading"), i18n("Format Strings for ID3 Tag Loading"), parent)
135
(new QVBoxLayout(this))->setAutoAdd(true);
137
KConfig *config = KGlobal::config();
138
KConfigGroupSaver saver(config, "ID3 Tags");
139
mString=new KLineEdit(config->readEntry("ID3Format", "%t"), this);
140
(mPreview=new QLineEdit(this))->setReadOnly(true);
141
QLabel *l=new QLabel(i18n("Enter the format for the ID Tag. Every %[something] will be "
142
"replaced with the following field, with the exception of '%%', which is replaced with '%'"),
144
l->setAlignment(AlignLeft | AlignVCenter | ExpandTabs | WordBreak);
146
new QLabel(i18n("%a - Artist"), this);
147
new QLabel(i18n("%A - Album"), this);
148
new QLabel(i18n("%c - Comment"), this);
149
new QLabel(i18n("%t - Title"), this);
150
new QLabel(i18n("%y - Year (4 Digits)"), this);
151
new QLabel(i18n("%Y - Year (2 Digits)"), this);
152
new QLabel(i18n("%g - Genre"), this);
154
connect(mString, SIGNAL(textChanged(const QString &)), SLOT(changed(const QString&)));
155
changed(mString->text());
158
void IDPrefs::changed(const QString &t)
160
mPreview->setText(parseFormat(t, "Mea Culpa", "Enigma", "MCMXC a.D.", "I'm guilty", "1990", "New Age"));
165
KConfig *config=KGlobal::config();
166
KConfigGroupSaver saver(config, "ID3 Tags");
167
config->writeEntry("ID3Format", mString->text());
173
#include "id3tag.moc"