2 * KMix -- KDE's full featured mini mixer
5 * Copyright (C) 1996-2004 Christian Esken <esken@kde.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this program; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <qbuttongroup.h>
24 #include <qradiobutton.h>
25 #include <qscrollarea.h>
26 #include <QVBoxLayout>
27 #include <QHBoxLayout>
29 #include <kcombobox.h>
33 #include "dialogselectmaster.h"
34 #include "mixdevice.h"
37 DialogSelectMaster::DialogSelectMaster( Mixer
*mixer
)
40 setCaption( i18n( "Select Master Channel" ) );
41 setButtons( Ok
|Cancel
);
42 setDefaultButton( Ok
);
44 m_vboxForScrollView
= 0;
45 m_scrollableChannelSelector
= 0;
46 m_buttonGroupForScrollView
= 0;
47 createWidgets(mixer
); // Open with Mixer Hardware #0
51 DialogSelectMaster::~DialogSelectMaster()
54 delete m_vboxForScrollView
;
58 * Create basic widgets of the Dialog.
60 void DialogSelectMaster::createWidgets(Mixer
*ptr_mixer
)
62 m_mainFrame
= new QFrame( this );
63 setMainWidget( m_mainFrame
);
64 _layout
= new QVBoxLayout(m_mainFrame
);
66 if ( Mixer::mixers().count() > 1 ) {
67 // More than one Mixer => show Combo-Box to select Mixer
69 QHBoxLayout
* mixerNameLayout
= new QHBoxLayout();
70 _layout
->addItem( mixerNameLayout
);
71 mixerNameLayout
->setSpacing(KDialog::spacingHint());
73 QLabel
*qlbl
= new QLabel( i18n("Current Mixer"), m_mainFrame
);
74 mixerNameLayout
->addWidget(qlbl
);
75 qlbl
->setFixedHeight(qlbl
->sizeHint().height());
77 m_cMixer
= new KComboBox( false, m_mainFrame
);
78 m_cMixer
->setObjectName( "mixerCombo" );
79 m_cMixer
->setFixedHeight(m_cMixer
->sizeHint().height());
80 connect( m_cMixer
, SIGNAL( activated( int ) ), this, SLOT( createPageByID( int ) ) );
82 for( int i
=0; i
<Mixer::mixers().count(); i
++ )
84 Mixer
*mixer
= (Mixer::mixers())[i
];
85 m_cMixer
->addItem( mixer
->readableName() );
86 } // end for all_Mixers
87 // Make the current Mixer the current item in the ComboBox
88 int findIndex
= m_cMixer
->findText( ptr_mixer
->readableName() );
89 if ( findIndex
!= -1 ) m_cMixer
->setCurrentIndex( findIndex
);
92 m_cMixer
->setToolTip( i18n("Current mixer" ) );
93 mixerNameLayout
->addWidget(m_cMixer
);
95 } // end if (more_than_1_Mixer)
99 QLabel
*qlbl
= new QLabel( i18n("Select the channel representing the master volume:"), m_mainFrame
);
100 _layout
->addWidget(qlbl
);
102 createPage(ptr_mixer
);
103 connect( this, SIGNAL(okClicked()) , this, SLOT(apply()) );
107 * Create RadioButton's for the Mixer with number 'mixerId'.
108 * @par mixerId The Mixer, for which the RadioButton's should be created.
110 void DialogSelectMaster::createPageByID(int mixerId
)
112 //kDebug(67100) << "DialogSelectMaster::createPage()";
113 QString selectedMixerName
= m_cMixer
->itemText(mixerId
);
114 for( int i
=0; i
<Mixer::mixers().count(); i
++ )
116 Mixer
*mixer
= (Mixer::mixers())[i
];
117 if ( mixer
->readableName() == selectedMixerName
) {
125 * Create RadioButton's for the Mixer with number 'mixerId'.
126 * @par mixerId The Mixer, for which the RadioButton's should be created.
128 void DialogSelectMaster::createPage(Mixer
* mixer
)
131 /** --- Reset page -----------------------------------------------
132 * In case the user selected a new Mixer via m_cMixer, we need
133 * to remove the stuff created on the last call.
135 // delete the VBox. This should automatically remove all contained QRadioButton's.
136 delete m_vboxForScrollView
;
137 delete m_scrollableChannelSelector
;
138 delete m_buttonGroupForScrollView
;
140 /** Reset page end -------------------------------------------------- */
142 m_buttonGroupForScrollView
= new QButtonGroup(this); // invisible QButtonGroup
143 //m_buttonGroupForScrollView->hide();
145 m_scrollableChannelSelector
= new QScrollArea(m_mainFrame
);
146 // m_scrollableChannelSelector->viewport()->setBackgroundRole(QPalette::Background);
147 _layout
->addWidget(m_scrollableChannelSelector
);
149 m_vboxForScrollView
= new KVBox(); //m_scrollableChannelSelector->viewport()
151 QString masterKey
= "----noMaster---"; // Use a non-matching name as default
152 MixDevice
* master
= mixer
->getLocalMasterMD();
153 if ( master
!= 0 ) masterKey
= master
->id();
155 const MixSet
& mixset
= mixer
->getMixSet();
156 MixSet
& mset
= const_cast<MixSet
&>(mixset
);
157 for( int i
=0; i
< mset
.count(); ++i
)
159 MixDevice
* md
= mset
[i
];
160 // Create a RadioButton for each MixDevice (excluding Enum's)
161 if ( md
->playbackVolume().hasVolume() || md
->captureVolume().hasVolume() ) {
162 // kDebug(67100) << "DialogSelectMaster::createPage() mset append qrb";
163 QString mdName
= md
->readableName();
164 mdName
.replace('&', "&&"); // Quoting the '&' needed, to prevent QRadioButton creating an accelerator
165 QRadioButton
* qrb
= new QRadioButton( mdName
, m_vboxForScrollView
);
166 qrb
->setObjectName(md
->id()); // The object name is used as ID here: see apply()
167 m_buttonGroupForScrollView
->addButton(qrb
); //(qrb, md->num());
168 //_qEnabledCB.append(qrb);
169 //m_mixerPKs.push_back(md->id());
170 if ( md
->id() == masterKey
) {
171 qrb
->setChecked(true); // preselect the current master
174 qrb
->setChecked(false);
179 m_scrollableChannelSelector
->setWidget(m_vboxForScrollView
);
180 m_vboxForScrollView
->show(); // show() is necessary starting with the second call to createPage()
184 void DialogSelectMaster::apply()
187 if ( Mixer::mixers().count() == 1 ) {
188 // only one mxier => no combo box => take first entry
189 mixer
= (Mixer::mixers())[0];
191 else if ( Mixer::mixers().count() > 1 ) {
192 // find mixer that is currently active in the ComboBox
193 QString selectedMixerName
= m_cMixer
->itemText(m_cMixer
->currentIndex());
195 for( int i
=0; i
<Mixer::mixers().count(); i
++ )
197 mixer
= (Mixer::mixers())[i
];
198 if ( mixer
->readableName() == selectedMixerName
) {
199 mixer
= (Mixer::mixers())[i
];
205 QAbstractButton
* button
= m_buttonGroupForScrollView
->checkedButton();
207 QString control_id
= button
->objectName();
208 // A channel was selected by the user => emit the "newMasterSelected()" signal
209 //kDebug(67100) << "DialogSelectMaster::apply(): card=" << soundcard_id << ", channel=" << channel_id;
211 kError(67100) << "DialogSelectMaster::createPage(): Invalid Mixer (mixer=0)" << endl
;
212 return; // can not happen
215 mixer
->setLocalMasterMD( control_id
);
216 Mixer::setGlobalMaster(mixer
->id(), control_id
);
217 emit
newMasterSelected( mixer
->id(), control_id
);
222 #include "dialogselectmaster.moc"