/* This file is NOT part of KDE ;)
   Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>

   This application is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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 "mixor.h"

//#include <klocale.h>
#include "../mixer/mixerlist.h"
#include "../mixer/mixercontrol.h"
#include "../mixer/mixercontrolset.h"

#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>

#include "mixerwidget.h"

using namespace Phonon::Mixer;

Mixor::Mixor(QWidget *parent)
 : QWidget(parent)
{
    new QVBoxLayout(this);
    foreach(const Mixer &m, MixerList::availableMixers()) {
        mixerAdded(m);
    }
    connect(MixerList::notifier(), SIGNAL(mixerAdded(Phonon::Mixer::Mixer)), SLOT(mixerAdded(Phonon::Mixer::Mixer)));
    connect(MixerList::notifier(), SIGNAL(mixerRemoved(Phonon::Mixer::Mixer)), SLOT(mixerRemoved(Phonon::Mixer::Mixer)));
}


Mixor::~Mixor()
{
}

void Mixor::mixerAdded(const Phonon::Mixer::Mixer &mixer)
{
    QGroupBox *box = new QGroupBox(mixer.name(), this);
    m_boxFor.insert(mixer, box);
    QHBoxLayout *l = new QHBoxLayout;
    layout()->addItem(l);
    l->addWidget(box);
    l->addStretch();
    QGridLayout *layout = new QGridLayout(box);
    int column = 0;
    foreach(const MixerControlSet &cs, mixer.controlSets()) {
        QLabel *nameLabel = new QLabel(cs.name(), box);
        nameLabel->setWordWrap(true);
        layout->addWidget(nameLabel, 0, column);

        MixerWidget *w = new MixerWidget(cs, box);
        m_mixerWidgets.append(w);
        layout->addWidget(w, 1, column);

        ++column;
    }
    /*
    foreach(const MixerControl &c, mixer.allControls()) {
        MixerControlSet set = c.parentSet();
        QLabel *nameLabel = new QLabel(set.name(), box);
        nameLabel->setWordWrap(true);
        layout->addWidget(nameLabel, 0, column);

        MixerWidget *w = new MixerWidget(c, box);
        m_mixerWidgets.append(w);
        layout->addWidget(w, 1, column);

        ++column;
    }
    */
}

void Mixor::mixerRemoved(const Phonon::Mixer::Mixer &mixer)
{
    delete m_boxFor.value(mixer);
}

#include "mixor.moc"
