1
/***************************************************************************
2
begin : Thu Oct 28 2004
3
copyright : (C) 2004 by Michael Pyne
4
email : michael.pyne@kdemail.net
5
***************************************************************************/
7
/***************************************************************************
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
14
***************************************************************************/
20
#include <kconfigbase.h>
22
#include "tagrenameroptions.h"
24
TagRenamerOptions::TagRenamerOptions() :
25
m_emptyAction(IgnoreEmptyTag),
32
TagRenamerOptions::TagRenamerOptions(const TagRenamerOptions &other) :
33
m_prefix(other.m_prefix),
34
m_suffix(other.m_suffix),
35
m_emptyAction(other.m_emptyAction),
36
m_emptyText(other.m_emptyText),
37
m_trackWidth(other.m_trackWidth),
38
m_disabled(other.m_disabled),
39
m_category(other.m_category)
43
TagRenamerOptions::TagRenamerOptions(TagType category)
44
: m_category(category)
46
// Make sure we don't use translated strings for the config file keys.
48
const QString typeKey = getTagTypeText(category, false);
49
KConfigGroup config(KGlobal::config(), "FileRenamer");
51
setSuffix(config.readEntry(QString("%1Suffix").arg(typeKey)));
52
setPrefix(config.readEntry(QString("%1Prefix").arg(typeKey)));
54
// Default the emptyAction to ignoring the empty tag.
56
const QString emptyAction = config.readEntry(QString("%1EmptyAction").arg(typeKey)).lower();
57
setEmptyAction(IgnoreEmptyTag);
59
if(emptyAction == "forceemptyinclude")
60
setEmptyAction(ForceEmptyInclude);
61
else if(emptyAction == "usereplacementvalue")
62
setEmptyAction(UseReplacementValue);
64
setEmptyText(config.readEntry(QString("%1EmptyText").arg(typeKey)));
65
setTrackWidth(config.readUnsignedNumEntry(QString("%1TrackWidth").arg(typeKey)));
66
setDisabled(config.readBoolEntry(QString("%1Disabled").arg(typeKey)));
69
QString TagRenamerOptions::getTagTypeText(TagType type, bool translate)
71
// These must be declared in the same order that they are defined in
72
// the TagType enum in test.h. We can dynamically translate these strings,
73
// so make sure that I18N_NOOP() is used instead of i18n().
75
const char *tags[] = {
76
I18N_NOOP("Title"), I18N_NOOP("Artist"), I18N_NOOP("Album"),
77
I18N_NOOP("Track"), I18N_NOOP("Genre"), I18N_NOOP("Year")
80
if(type < StartTag || type >= NumTypes) {
81
kdWarning() << "I don't know what category we're looking up, this is a problem." << endl;
82
kdWarning() << "The category ID is " << (unsigned) type << endl;
83
return translate ? i18n("Unknown") : "Unknown";
86
return translate ? i18n(tags[type]) : tags[type];
89
void TagRenamerOptions::saveConfig() const
91
// Make sure we don't use translated strings for the config file keys.
93
const QString typeKey = getTagTypeText(false);
94
KConfigGroup config(KGlobal::config(), "FileRenamer");
96
config.writeEntry(QString("%1Suffix").arg(typeKey), suffix());
97
config.writeEntry(QString("%1Prefix").arg(typeKey), prefix());
101
switch(emptyAction()) {
102
case ForceEmptyInclude:
103
emptyStr = "ForceEmptyInclude";
107
emptyStr = "IgnoreEmptyTag";
110
case UseReplacementValue:
111
emptyStr = "UseReplacementValue";
115
config.writeEntry(QString("%1EmptyAction").arg(typeKey), emptyStr);
116
config.writeEntry(QString("%1EmptyText").arg(typeKey), emptyText());
117
config.writeEntry(QString("%1Disabled").arg(typeKey), disabled());
119
if(category() == Track)
120
config.writeEntry(QString("%1TrackWidth").arg(typeKey), trackWidth());
125
TagRenamerOptions &TagRenamerOptions::operator=(const TagRenamerOptions &other)
130
setPrefix(other.prefix());
131
setSuffix(other.suffix());
132
setEmptyText(other.emptyText());
133
setEmptyAction(other.emptyAction());
134
setTrackWidth(other.trackWidth());
135
setDisabled(other.disabled());
136
setCategory(other.category());
141
// vim: set et ts=4 sw=4: