summaryrefslogtreecommitdiff
path: root/src/ui/mixerwindow.cpp
blob: 91cea65a625c4f3d076038e9faaa9c49835c9999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "mixerwindow.h"
#include "../model/pulsemodel.h"

#include <tqlayout.h>
#include <tqscrollview.h>
#include <ktabwidget.h>
#include <tdelocale.h>

static MixerWindow::Tab makeTab( KTabWidget *tabs, const TQString &label )
{
    MixerWindow::Tab t;
    TQScrollView *scroll = new TQScrollView( tabs );
    scroll->setResizePolicy( TQScrollView::AutoOneFit );
    scroll->setHScrollBarMode( TQScrollView::Auto );
    scroll->setVScrollBarMode( TQScrollView::AlwaysOff );
    scroll->setFrameStyle( TQFrame::NoFrame );

    t.page = new TQWidget( scroll->viewport() );
    scroll->addChild( t.page );
    t.layout = new TQHBoxLayout( t.page, 6, 4 );

    tabs->addTab( scroll, label );
    return t;
}

MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent )
    : TQWidget(parent), m_model(model)
{
    setCaption( i18n("TMix") );

    TQVBoxLayout *top = new TQVBoxLayout( this, 4, 0 );
    m_tabs = new KTabWidget( this );
    top->addWidget( m_tabs );

    m_output    = makeTab( m_tabs, i18n("Output") );
    m_input     = makeTab( m_tabs, i18n("Input") );
    m_playback  = makeTab( m_tabs, i18n("Playback") );
    m_recording = makeTab( m_tabs, i18n("Recording") );

    connect( model, TQ_SIGNAL(deviceAdded(AudioDevice*)),   this, TQ_SLOT(onDeviceAdded(AudioDevice*)) );
    connect( model, TQ_SIGNAL(deviceRemoved(AudioDevice*)), this, TQ_SLOT(onDeviceRemoved(AudioDevice*)) );

    // Populate with any devices already known at construction time.
    AudioDevice::Category cats[] = {
        AudioDevice::Output, AudioDevice::Input,
        AudioDevice::Playback, AudioDevice::Recording
    };
    for ( int i = 0; i < 4; i++ ) {
        TQPtrList<AudioDevice> devs = model->devices( cats[i] );
        for ( TQPtrListIterator<AudioDevice> it(devs); *it; ++it )
            onDeviceAdded( *it );
    }
}

MixerWindow::Tab &MixerWindow::tabForCategory( AudioDevice::Category cat )
{
    switch ( cat ) {
        case AudioDevice::Output:    return m_output;
        case AudioDevice::Input:     return m_input;
        case AudioDevice::Playback:  return m_playback;
        case AudioDevice::Recording: return m_recording;
    }
    return m_output;
}

void MixerWindow::onDeviceAdded( AudioDevice *dev )
{
    Tab &t = tabForCategory( dev->category() );
    TQWidget *w = dev->createWidget( t.page );
    t.layout->addWidget( w );
    w->show();
    m_widgets.insert( dev, w );
}

void MixerWindow::onDeviceRemoved( AudioDevice *dev )
{
    TQWidget *w = m_widgets[dev];
    if ( !w ) return;
    Tab &t = tabForCategory( dev->category() );
    t.layout->remove( w );
    m_widgets.remove( dev );
    delete w;
}

#include "mixerwindow.moc"