/*  This file is part of the KDE project
    Copyright (C) 2007 Matthias Kretz <kretz@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

*/

#include "mixercontrolset.h"
#include "mixercontrolset_p.h"
#include "defs_p.h"

namespace Phonon
{
namespace Mixer
{

MixerControlSet::MixerControlSet()
    : d_ptr(new MixerControlSetPrivate)
{
    d_ptr->q_ptr = this;
}

MixerControlSet::MixerControlSet(const Mixer &mixer, const QString &name, const QIcon &icon)
    : d_ptr(new MixerControlSetPrivate)
{
    d_ptr->q_ptr = this;
    d_ptr->s_ptr = new MixerControlSetSharedData(name, icon);
    K_S(MixerControlSet);
    s->m_mixer = const_cast<MixerSharedData *>(mixer.d_func()->s_func());
}

MixerControlSet::~MixerControlSet()
{
    delete d_ptr;
}

MixerControlSet::MixerControlSet(const MixerControlSet &rhs)
    : d_ptr(new MixerControlSetPrivate)
{
    d_ptr->q_ptr = this;
    d_ptr->s_ptr = const_cast<MixerControlSetSharedData *>(rhs.d_func()->s_func());
}

MixerControlSet &MixerControlSet::operator=(const MixerControlSet &rhs)
{
    d_ptr->s_ptr = const_cast<MixerControlSetSharedData *>(rhs.d_func()->s_func());
    return *this;
}

bool MixerControlSet::operator==(const MixerControlSet &rhs) const
{
    return d_func()->s_func() == rhs.d_func()->s_func();
}

bool MixerControlSet::isValid() const
{
    K_S(const MixerControlSet);
    if (s && s->m_mixer) {
        return s->m_mixer->isValid();
    }
    return false;
}

QString MixerControlSet::name() const
{
    K_S(const MixerControlSet);
    return s->m_name;
}

QIcon MixerControlSet::icon() const
{
    K_S(const MixerControlSet);
    return s->m_icon;
}

QList<MixerControl> MixerControlSet::allControls() const
{
    K_S(const MixerControlSet);
    QList<MixerControl> r;
    foreach (const MixerControl &c, s->m_mixer->m_controls) {
        if (c.parentSet() == *this) {
            r << c;
        }
    }
    return r;
}

QList<MixerToggleControl> MixerControlSet::toggleControls() const
{
    K_S(const MixerControlSet);
    QList<MixerToggleControl> r;
    foreach (const MixerControl &c, s->m_mixer->m_controls) {
        if (c.parentSet() == *this) {
            MixerToggleControl tc = mixercontrol_cast<MixerToggleControl>(c);
            if (tc.isValid()) {
                r << tc;
            }
        }
    }
    return r;
}

QList<MixerIntegerControl> MixerControlSet::integerControls() const
{
    K_S(const MixerControlSet);
    QList<MixerIntegerControl> r;
    foreach (const MixerControl &c, s->m_mixer->m_controls) {
        if (c.parentSet() == *this) {
            MixerIntegerControl tc = mixercontrol_cast<MixerIntegerControl>(c);
            if (tc.isValid()) {
                r << tc;
            }
        }
    }
    return r;
}

QList<MixerEnumControl> MixerControlSet::enumControls() const
{
    K_S(const MixerControlSet);
    QList<MixerEnumControl> r;
    foreach (const MixerControl &c, s->m_mixer->m_controls) {
        if (c.parentSet() == *this) {
            MixerEnumControl tc = mixercontrol_cast<MixerEnumControl>(c);
            if (tc.isValid()) {
                r << tc;
            }
        }
    }
    return r;
}

} // namespace Mixer
} // namespace Phonon
