Commit 4369fda4 authored by Christian Esken's avatar Christian Esken
Browse files

Implement configuration of backends in SoundMenu

CCBUGS:328599
parent bf7a7f97
......@@ -1020,9 +1020,16 @@ KMixWindow::addMixerWidget(const QString& mixer_ID, QString guiprofId, int inser
/* A newly added mixer will automatically added at the top
* and thus the window title is also set appropriately */
QString tabLabel = guiprof->getName();
if (tabLabel.isEmpty())
tabLabel = kmw->mixer()->readableName();
/*
* Skip the name from the profile for now. I would at least have to do the '&' quoting for the tab label. But I am
* also not 100% sure whether the current name from the profile is any good - it does (likely) not even contain the
* card ID. This means you cannot distinguish between cards with an identical name.
*/
// QString tabLabel = guiprof->getName();
// if (tabLabel.isEmpty())
// QString tabLabel = kmw->mixer()->readableName(true);
QString tabLabel = kmw->mixer()->readableName(true);
m_dontSetDefaultCardOnStart = true; // inhibit implicit setting of m_defaultCardOnStart
......
......@@ -405,9 +405,23 @@ void Mixer::setBalanceInternal(Volume& vol)
* Returns a name suitable for a human user to read (on a label, ...)
*/
QString Mixer::readableName()
{
return readableName(false);
}
/**
* Returns a name suitable for a human user to read, possibly with quoted ampersand. The latter is required by
* some GUI elements like QRadioButton or when used as a Tab label, as '&' introduces an accelerator there.
*
* @param ampersandQuoted
* @return
*/
QString Mixer::readableName(bool ampersandQuoted)
{
QString finalName = _mixerBackend->getName();
// QString finalName = mixerName.left(mixerName.length() - 2);
if (ampersandQuoted)
finalName.replace('&', "&&");
if ( getCardInstance() > 1)
finalName = finalName.append(" %1").arg(getCardInstance());
......
......@@ -109,7 +109,8 @@ public:
QString translateKernelToWhatsthis(const QString &kernelName);
/// Return the name of the card/chip/hardware, which is suitable for humans
virtual QString readableName();
QString readableName();
QString readableName(bool ampersandQuoted);
// Returns the name of the driver, e.g. "OSS" or "ALSA0.9"
static QString driverName(int num);
......
......@@ -45,21 +45,11 @@
* @param mixerIds A set of preselected mixer ID's
* @param noButtons is a migration option. When DialogChooseBackends has been integrated as a Tab, it will be removed.
*/
DialogChooseBackends::DialogChooseBackends(QSet<QString>& mixerIds, bool noButtons)
: KDialog( 0 )
DialogChooseBackends::DialogChooseBackends(QWidget* parent, const QSet<QString>& mixerIds)
: QWidget(parent)
{
setCaption( i18n( "Select Mixers" ) );
if (noButtons)
{
setButtons( None );
}
else
{
bool empty = Mixer::mixers().isEmpty();
kWarning() << "select empty=" << empty;
setButtons( empty ? Cancel : Ok|Cancel );
setDefaultButton( Ok );
}
// setCaption( i18n( "Select Mixers" ) );
// setButtons( None );
_layout = 0;
m_vboxForScrollView = 0;
......@@ -78,10 +68,11 @@ DialogChooseBackends::~DialogChooseBackends()
/**
* Create basic widgets of the Dialog.
*/
void DialogChooseBackends::createWidgets(QSet<QString>& mixerIds)
void DialogChooseBackends::createWidgets(const QSet<QString>& mixerIds)
{
m_mainFrame = new QFrame( this );
setMainWidget( m_mainFrame );
m_mainFrame = this;
// m_mainFrame = new QFrame( this );
// setMainWidget( m_mainFrame );
_layout = new QVBoxLayout(m_mainFrame);
_layout->setMargin(0);
......@@ -91,7 +82,6 @@ void DialogChooseBackends::createWidgets(QSet<QString>& mixerIds)
_layout->addWidget(qlbl);
createPage(mixerIds);
connect( this, SIGNAL(okClicked()) , this, SLOT(apply()) );
}
else
{
......@@ -105,7 +95,7 @@ void DialogChooseBackends::createWidgets(QSet<QString>& mixerIds)
* Create RadioButton's for the Mixer with number 'mixerId'.
* @par mixerId The Mixer, for which the RadioButton's should be created.
*/
void DialogChooseBackends::createPage(QSet<QString>& mixerIds)
void DialogChooseBackends::createPage(const QSet<QString>& mixerIds)
{
m_buttonGroupForScrollView = new QButtonGroup(this); // invisible QButtonGroup
m_scrollableChannelSelector = new QScrollArea(m_mainFrame);
......@@ -118,25 +108,22 @@ void DialogChooseBackends::createPage(QSet<QString>& mixerIds)
m_vboxForScrollView = new KVBox();
bool hasMixerFilter = !mixerIds.isEmpty();
kDebug() << "MixerIds=" << mixerIds;
foreach ( Mixer* mixer, Mixer::mixers())
{
QString mdName = mixer->readableName();
mdName.replace('&', "&&"); // Quoting the '&' needed, to prevent QCheckBox creating an accelerator
QCheckBox* qrb = new QCheckBox( mdName, m_vboxForScrollView);
qrb->setObjectName(mixer->id());// The object name is used as ID here: see apply()
// m_buttonGroupForScrollView->addButton(qrb); // TODO remove m_buttonGroupForScrollView
QCheckBox* qrb = new QCheckBox(mixer->readableName(true), m_vboxForScrollView);
qrb->setObjectName(mixer->id());// The object name is used as ID here: see getChosenBackends()
checkboxes.append(qrb);
qrb->setChecked( mixerIds.contains(mixer->id()) );// preselect the current master
bool mixerShouldBeShown = !hasMixerFilter || mixerIds.contains(mixer->id());
qrb->setChecked(mixerShouldBeShown);
}
m_scrollableChannelSelector->setWidget(m_vboxForScrollView);
m_vboxForScrollView->show(); // show() is necessary starting with the second call to createPage()
}
void DialogChooseBackends::apply()
QSet<QString> DialogChooseBackends::getChosenBackends()
{
QSet<QString> newMixerList;
foreach ( QCheckBox* qcb, checkboxes)
......@@ -147,13 +134,8 @@ void DialogChooseBackends::apply()
kDebug() << "apply found " << qcb->objectName();
}
}
// Announcing MasterChanged, as the sound menu (aka ViewDockAreaPopup) primarily shows master volume(s).
// In any case, ViewDockAreaPopup treats MasterChanged and ControlList the same, so it is better to announce
// the "smaller" change.
kDebug() << "New list is " << newMixerList;
GlobalConfig::instance().setMixersForSoundmenu(newMixerList);
ControlManager::instance().announce(QString(), ControlChangeType::MasterChanged, QString("Select Backends Dialog"));
return newMixerList;
}
#include "dialogchoosebackends.moc"
......
......@@ -34,25 +34,24 @@ class KComboBox;
class Mixer;
class DialogChooseBackends : public KDialog
class DialogChooseBackends : public QWidget
{
Q_OBJECT
public:
DialogChooseBackends(QSet<QString>& backends, bool noButtons);
DialogChooseBackends(QWidget* parent, const QSet<QString>& backends);
~DialogChooseBackends();
public slots:
void apply();
QSet<QString> getChosenBackends();
private:
void createWidgets(QSet<QString>& backends);
void createPage(QSet<QString>& backends);
void createWidgets(const QSet<QString>& backends);
void createPage(const QSet<QString>& backends);
QVBoxLayout* _layout;
QScrollArea* m_scrollableChannelSelector;
KVBox *m_vboxForScrollView;
QButtonGroup *m_buttonGroupForScrollView;
QList<QCheckBox*> checkboxes;
QFrame *m_mainFrame;
QWidget *m_mainFrame;
};
#endif
......@@ -160,10 +160,9 @@ void DialogSelectMaster::createPage(Mixer* mixer)
m_vboxForScrollView = new KVBox(); //m_scrollableChannelSelector->viewport()
QString masterKey = "----noMaster---"; // Use a non-matching name as default
shared_ptr<MixDevice> master = mixer->getLocalMasterMD();
if ( master.get() != 0 )
masterKey = master->id();
QString masterKey = ( master.get() != 0 ) ? master->id() : "----noMaster---"; // Use non-matching name as default
const MixSet& mixset = mixer->getMixSet();
MixSet& mset = const_cast<MixSet&>(mixset);
......@@ -176,17 +175,10 @@ void DialogSelectMaster::createPage(Mixer* mixer)
// kDebug(67100) << "DialogSelectMaster::createPage() mset append qrb";
QString mdName = md->readableName();
mdName.replace('&', "&&"); // Quoting the '&' needed, to prevent QRadioButton creating an accelerator
QRadioButton* qrb = new QRadioButton( mdName, m_vboxForScrollView);
QRadioButton* qrb = new QRadioButton(mdName, m_vboxForScrollView);
qrb->setObjectName(md->id()); // The object name is used as ID here: see apply()
m_buttonGroupForScrollView->addButton(qrb); //(qrb, md->num());
//_qEnabledCB.append(qrb);
//m_mixerPKs.push_back(md->id());
if ( md->id() == masterKey ) {
qrb->setChecked(true); // preselect the current master
}
else {
qrb->setChecked(false);
}
qrb->setChecked(md->id() == masterKey); // preselect the current master
}
}
......
......@@ -246,9 +246,10 @@ void KMixPrefDlg::createGeneralTab()
void KMixPrefDlg::todoRemoveThisMethodAndInitBackendsCorrectly()
{
GlobalConfig::instance().getMixersForSoundmenu();
QSet<QString> emptyBackendList;
replaceBackendsInTab(emptyBackendList);
replaceBackendsInTab(GlobalConfig::instance().getMixersForSoundmenu());
// GlobalConfig::instance().getMixersForSoundmenu();
// QSet<QString> emptyBackendList;
// replaceBackendsInTab(emptyBackendList);
}
void KMixPrefDlg::createControlsTab()
......@@ -331,6 +332,12 @@ void KMixPrefDlg::updateSettings()
kDebug() << "trayOrientation" << trayOrientation << ", _rbTraypopupHorizontal->isChecked()" << _rbTraypopupHorizontal->isChecked();
dialogConfig.data.setTraypopupOrientation(trayOrientation);
// Announcing MasterChanged, as the sound menu (aka ViewDockAreaPopup) primarily shows master volume(s).
// In any case, ViewDockAreaPopup treats MasterChanged and ControlList the same, so it is better to announce
// the "smaller" change.
GlobalConfig::instance().setMixersForSoundmenu(dvc->getChosenBackends());
ControlManager::instance().announce(QString(), ControlChangeType::MasterChanged, QString("Select Backends Dialog"));
// emit(kmixConfigHasChanged());
}
......@@ -394,7 +401,7 @@ void KMixPrefDlg::showEvent(QShowEvent * event)
}
void KMixPrefDlg::replaceBackendsInTab(QSet<QString>& backends)
void KMixPrefDlg::replaceBackendsInTab(const QSet<QString>& backends)
{
if (dvc != 0)
{
......@@ -403,7 +410,8 @@ void KMixPrefDlg::replaceBackendsInTab(QSet<QString>& backends)
}
QSet<QString> backendsFromConfig = GlobalConfig::instance().getMixersForSoundmenu();
dvc = new DialogChooseBackends(backendsFromConfig, true);
dvc = new DialogChooseBackends(0, backendsFromConfig);
dvc->show();
layoutControlsTab->addWidget(dvc);
// Push everything above to the top
......
......@@ -92,7 +92,7 @@ private:
void addWidgetToLayout(QWidget* widget, QBoxLayout* layout, int spacingBefore, QString tooltip, QString kconfigName);
void createStartupTab();
void replaceBackendsInTab(QSet<QString>& backends);
void replaceBackendsInTab(const QSet<QString>& backends);
void createGeneralTab();
void createControlsTab();
void createOrientationGroup(const QString& labelSliderOrientation, QGridLayout* orientationLayout, int row, KMixPrefDlgPrefOrientationType type);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment