filerenameroptions.cpp 4.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/***************************************************************************
    begin                : Thu Oct 28 2004
    copyright            : (C) 2004 by Michael Pyne
    email                : michael.pyne@kdemail.net
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

16 17
#include "filerenameroptions.h"

18 19 20 21 22 23 24
#include <klocale.h>
#include <kdebug.h>
#include <knuminput.h>


FileRenamerTagOptions::FileRenamerTagOptions(QWidget *parent,
                                             const TagRenamerOptions &options) :
25 26 27
    QWidget(parent),
    Ui::FileRenamerTagOptionsBase(),
    m_options(options)
28
{
29 30
    setupUi(this);

31 32 33 34 35
    layout()->setMargin(0);

    if(m_options.category() != Track)
        m_trackGroup->hide();

Scott Wheeler's avatar
Scott Wheeler committed
36
    QString tagText = m_options.tagTypeText();
37

38
    setWindowTitle(i18nc("%1 will be a music tag category like Artist or Album", "%1 Options",tagText));
Laurent Montel's avatar
Laurent Montel committed
39 40 41
    m_tagFormatGroup->setTitle(i18n("%1 Format",tagText));
    m_emptyTagGroup->setTitle(i18n("When the Track's %1 is Empty",tagText));
    m_description->setText(i18n("When using the file renamer your files will be renamed to the values that you have in your track's %1 tag, plus any additional text that you specify below.",tagText));
42
    m_tagLabel->setText(tagText);
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

    m_prefixText->setText(options.prefix());
    m_suffixText->setText(options.suffix());
    if(options.emptyAction() == TagRenamerOptions::ForceEmptyInclude)
        m_includeEmptyButton->setChecked(true);
    else if(options.emptyAction() == TagRenamerOptions::UseReplacementValue)
        m_useValueButton->setChecked(true);
    m_emptyTagValue->setText(options.emptyText());
    m_trackWidth->setValue(options.trackWidth());

    slotBracketsChanged();
    slotEmptyActionChanged();
    slotTrackWidthChanged();
}

void FileRenamerTagOptions::slotBracketsChanged()
{
Scott Wheeler's avatar
Scott Wheeler committed
60
    QString tag = m_options.tagTypeText();
61 62 63 64 65 66 67 68 69

    m_options.setPrefix(m_prefixText->text());
    m_options.setSuffix(m_suffixText->text());

    m_substitution->setText(m_options.prefix() + tag + m_options.suffix());
}

void FileRenamerTagOptions::slotTrackWidthChanged()
{
70
    int width = m_trackWidth->value();
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

    m_options.setTrackWidth(width);

    QString singleDigitText = m_singleDigit->text();
    singleDigitText.remove(" ->");
    QString doubleDigitText = m_doubleDigit->text();
    doubleDigitText.remove(" ->");

    if(singleDigitText.length() < width) {
        QString p;
        p.fill('0', width - singleDigitText.length());
        singleDigitText.prepend(p);
    }

    if(doubleDigitText.length() < width) {
        QString p;
        p.fill('0', width - doubleDigitText.length());
        doubleDigitText.prepend(p);
    }

    m_singleDigitExample->setText(singleDigitText);
    m_doubleDigitExample->setText(doubleDigitText);
}

void FileRenamerTagOptions::slotEmptyActionChanged()
{
    m_options.setEmptyText(m_emptyTagValue->text());

    m_options.setEmptyAction(TagRenamerOptions::IgnoreEmptyTag);

    if(m_useValueButton->isChecked())
        m_options.setEmptyAction(TagRenamerOptions::UseReplacementValue);
    else if(m_includeEmptyButton->isChecked())
        m_options.setEmptyAction(TagRenamerOptions::ForceEmptyInclude);
}

107 108 109
TagOptionsDialog::TagOptionsDialog(QWidget *parent,
                                   const TagRenamerOptions &options,
                                   unsigned categoryNumber) :
110
    KDialog(parent, 0),
111 112
    m_options(options),
    m_categoryNumber(categoryNumber)
113
{
114 115 116 117
    setModal(true);
    setCaption(i18n("File Renamer"));
    setButtons(Ok|Cancel);

118 119 120 121 122 123 124 125 126 127 128 129 130
    loadConfig();

    m_widget = new FileRenamerTagOptions(this, m_options);
    m_widget->setMinimumSize(400, 200);

    setMainWidget(m_widget);
}

void TagOptionsDialog::accept()
{
    m_options = m_widget->options();

    saveConfig();
131
    KDialog::accept();
132 133 134 135 136 137 138
}

void TagOptionsDialog::loadConfig()
{
    // Our m_options may not have been loaded from KConfig, force that to
    // happen.

139 140
    CategoryID category(m_options.category(), m_categoryNumber);
    m_options = TagRenamerOptions(category);
141 142 143 144
}

void TagOptionsDialog::saveConfig()
{
145
    m_options.saveConfig(m_categoryNumber);
146 147 148 149
}

#include "filerenameroptions.moc"

150
// vim: set et sw=4 tw=0 sta: