diff options
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/devicespage.cpp | 183 | ||||
| -rw-r--r-- | src/ui/devicespage.h | 7 | ||||
| -rw-r--r-- | src/ui/devicewidget.cpp | 9 | ||||
| -rw-r--r-- | src/ui/devicewidget.h | 1 |
4 files changed, 77 insertions, 123 deletions
diff --git a/src/ui/devicespage.cpp b/src/ui/devicespage.cpp index 0b39ece..2433412 100644 --- a/src/ui/devicespage.cpp +++ b/src/ui/devicespage.cpp @@ -148,77 +148,8 @@ void DevicesPage::rebuild() connect( combo, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onProfileActivated(int)) ); - // Sink port dropdowns — only when a sink has 2+ ports - TQValueList<PulseModel::DevicePortInfo> sinks = m_model->sinksForCard( info.index ); - bool multiSink = false; - for ( TQValueList<PulseModel::DevicePortInfo>::Iterator sit = sinks.begin(); - sit != sinks.end(); ++sit ) - if ( (int)sit->ports.count() >= 2 ) { multiSink = ( sinks.count() > 1 ); break; } - - for ( TQValueList<PulseModel::DevicePortInfo>::Iterator sit = sinks.begin(); - sit != sinks.end(); ++sit ) { - if ( (int)sit->ports.count() < 2 ) continue; - - TQComboBox *pc = new TQComboBox( false, grp ); - pc->setSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ); - TQString label = multiSink - ? sit->description + i18n(" port:") - : i18n("Output port:"); - addRow( label, pc ); - - TQValueList<TQString> portNames; - int activePort = 0, pi = 0; - for ( TQValueList<PulseDevicePort>::ConstIterator pit = sit->ports.begin(); - pit != sit->ports.end(); ++pit, ++pi ) { - pc->insertItem( (*pit).description ); - portNames.append( (*pit).name ); - if ( (*pit).name == sit->activePort ) - activePort = pi; - } - pc->setCurrentItem( activePort ); - - m_sinkPortComboNames[pc] = portNames; - m_sinkPortComboSink[pc] = sit->paIndex; - m_sinkPortCombos[sit->paIndex] = pc; - - connect( pc, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onSinkPortActivated(int)) ); - } - - // Source port dropdowns — only when a source has 2+ ports - TQValueList<PulseModel::DevicePortInfo> sources = m_model->sourcesForCard( info.index ); - bool multiSource = false; - for ( TQValueList<PulseModel::DevicePortInfo>::Iterator sit = sources.begin(); - sit != sources.end(); ++sit ) - if ( (int)sit->ports.count() >= 2 ) { multiSource = ( sources.count() > 1 ); break; } - - for ( TQValueList<PulseModel::DevicePortInfo>::Iterator sit = sources.begin(); - sit != sources.end(); ++sit ) { - if ( (int)sit->ports.count() < 2 ) continue; - - TQComboBox *pc = new TQComboBox( false, grp ); - pc->setSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ); - TQString label = multiSource - ? sit->description + i18n(" port:") - : i18n("Input port:"); - addRow( label, pc ); - - TQValueList<TQString> portNames; - int activePort = 0, pi = 0; - for ( TQValueList<PulseDevicePort>::ConstIterator pit = sit->ports.begin(); - pit != sit->ports.end(); ++pit, ++pi ) { - pc->insertItem( (*pit).description ); - portNames.append( (*pit).name ); - if ( (*pit).name == sit->activePort ) - activePort = pi; - } - pc->setCurrentItem( activePort ); - - m_sourcePortComboNames[pc] = portNames; - m_sourcePortComboSource[pc] = sit->paIndex; - m_sourcePortCombos[sit->paIndex] = pc; - - connect( pc, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onSourcePortActivated(int)) ); - } + addPortCombos( grid, gridRow, grp, m_model->sinksForCard( info.index ), true ); + addPortCombos( grid, gridRow, grp, m_model->sourcesForCard( info.index ), false ); // Ports — 2-column grid to keep tall cards compact if ( !info.ports.isEmpty() ) { @@ -275,6 +206,57 @@ void DevicesPage::rebuild() m_container->show(); } +void DevicesPage::addPortCombos( TQGridLayout *grid, int &gridRow, TQWidget *grp, + const TQValueList<PulseModel::DevicePortInfo> &devices, bool isSink ) +{ + bool multi = false; + for ( TQValueList<PulseModel::DevicePortInfo>::ConstIterator it = devices.begin(); + it != devices.end(); ++it ) + if ( (int)(*it).ports.count() >= 2 ) { multi = ( devices.count() > 1 ); break; } + + for ( TQValueList<PulseModel::DevicePortInfo>::ConstIterator sit = devices.begin(); + sit != devices.end(); ++sit ) { + const PulseModel::DevicePortInfo &dev = *sit; + if ( (int)dev.ports.count() < 2 ) continue; + + TQComboBox *pc = new TQComboBox( false, grp ); + pc->setSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Fixed ); + TQString label = multi + ? dev.description + i18n(" port:") + : ( isSink ? i18n("Output port:") : i18n("Input port:") ); + + TQLabel *lbl = new TQLabel( label, grp ); + lbl->setAlignment( TQt::AlignRight | TQt::AlignVCenter ); + grid->addWidget( lbl, gridRow, 0 ); + grid->addWidget( pc, gridRow, 1 ); + ++gridRow; + + TQValueList<TQString> portNames; + int activePort = 0, pi = 0; + for ( TQValueList<PulseDevicePort>::ConstIterator pit = dev.ports.begin(); + pit != dev.ports.end(); ++pit, ++pi ) { + const PulseDevicePort &port = *pit; + pc->insertItem( port.description ); + portNames.append( port.name ); + if ( port.name == dev.activePort ) + activePort = pi; + } + pc->setCurrentItem( activePort ); + + if ( isSink ) { + m_sinkPortComboNames[pc] = portNames; + m_sinkPortComboSink[pc] = dev.paIndex; + m_sinkPortCombos[dev.paIndex] = pc; + connect( pc, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onSinkPortActivated(int)) ); + } else { + m_sourcePortComboNames[pc] = portNames; + m_sourcePortComboSource[pc] = dev.paIndex; + m_sourcePortCombos[dev.paIndex] = pc; + connect( pc, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onSourcePortActivated(int)) ); + } + } +} + void DevicesPage::onCardAdded( uint32_t ) { rebuild(); } void DevicesPage::onCardRemoved( uint32_t ) { rebuild(); } void DevicesPage::onCardUpdated( uint32_t ) { rebuild(); } @@ -322,55 +304,25 @@ void DevicesPage::onSourcePortActivated( int idx ) m_model->setSourcePort( cit.data(), nit.data()[idx] ); } -void DevicesPage::onSinkUpdated( uint32_t paIndex ) +void DevicesPage::updatePortCombo( uint32_t paIndex, bool isSink ) { - TQMap<uint32_t, TQComboBox*>::Iterator cit = m_sinkPortCombos.find( paIndex ); - if ( cit == m_sinkPortCombos.end() ) { - // Sink with ports appeared after last rebuild — refresh. - rebuild(); - return; - } - TQComboBox *combo = cit.data(); - TQMap<TQComboBox*, TQValueList<TQString>>::Iterator nit = m_sinkPortComboNames.find( combo ); - if ( nit == m_sinkPortComboNames.end() ) return; + TQMap<uint32_t, TQComboBox*> &combos = isSink ? m_sinkPortCombos : m_sourcePortCombos; + TQMap<uint32_t, TQComboBox*>::Iterator cit = combos.find( paIndex ); + if ( cit == combos.end() ) { rebuild(); return; } - // Find current active port from the model's sinksForCard lookup. - // Walk all cards to find this sink. - TQValueList<PulseCardInfo> cards = m_model->cards(); - for ( TQValueList<PulseCardInfo>::ConstIterator it = cards.begin(); it != cards.end(); ++it ) { - TQValueList<PulseModel::DevicePortInfo> sinks = m_model->sinksForCard( (*it).index ); - for ( TQValueList<PulseModel::DevicePortInfo>::ConstIterator sit = sinks.begin(); - sit != sinks.end(); ++sit ) { - if ( (*sit).paIndex != paIndex ) continue; - TQValueList<TQString> &names = nit.data(); - for ( int i = 0; i < (int)names.count(); ++i ) { - if ( names[i] == (*sit).activePort ) { - combo->blockSignals( true ); - combo->setCurrentItem( i ); - combo->blockSignals( false ); - return; - } - } - } - } -} - -void DevicesPage::onSourceUpdated( uint32_t paIndex ) -{ - TQMap<uint32_t, TQComboBox*>::Iterator cit = m_sourcePortCombos.find( paIndex ); - if ( cit == m_sourcePortCombos.end() ) { - rebuild(); - return; - } TQComboBox *combo = cit.data(); - TQMap<TQComboBox*, TQValueList<TQString>>::Iterator nit = m_sourcePortComboNames.find( combo ); - if ( nit == m_sourcePortComboNames.end() ) return; + TQMap<TQComboBox*, TQValueList<TQString>> &nameMap = + isSink ? m_sinkPortComboNames : m_sourcePortComboNames; + TQMap<TQComboBox*, TQValueList<TQString>>::Iterator nit = nameMap.find( combo ); + if ( nit == nameMap.end() ) return; TQValueList<PulseCardInfo> cards = m_model->cards(); for ( TQValueList<PulseCardInfo>::ConstIterator it = cards.begin(); it != cards.end(); ++it ) { - TQValueList<PulseModel::DevicePortInfo> sources = m_model->sourcesForCard( (*it).index ); - for ( TQValueList<PulseModel::DevicePortInfo>::ConstIterator sit = sources.begin(); - sit != sources.end(); ++sit ) { + TQValueList<PulseModel::DevicePortInfo> devices = isSink + ? m_model->sinksForCard( (*it).index ) + : m_model->sourcesForCard( (*it).index ); + for ( TQValueList<PulseModel::DevicePortInfo>::ConstIterator sit = devices.begin(); + sit != devices.end(); ++sit ) { if ( (*sit).paIndex != paIndex ) continue; TQValueList<TQString> &names = nit.data(); for ( int i = 0; i < (int)names.count(); ++i ) { @@ -385,4 +337,7 @@ void DevicesPage::onSourceUpdated( uint32_t paIndex ) } } +void DevicesPage::onSinkUpdated( uint32_t paIndex ) { updatePortCombo( paIndex, true ); } +void DevicesPage::onSourceUpdated( uint32_t paIndex ) { updatePortCombo( paIndex, false ); } + #include "devicespage.moc" diff --git a/src/ui/devicespage.h b/src/ui/devicespage.h index b059787..feedcdd 100644 --- a/src/ui/devicespage.h +++ b/src/ui/devicespage.h @@ -5,8 +5,9 @@ #include <tqmap.h> #include <tqvaluelist.h> #include <tqstring.h> +#include "../model/pulsemodel.h" -class PulseModel; +class TQGridLayout; class TQScrollView; class TQComboBox; class TQLabel; @@ -36,6 +37,10 @@ private slots: private: void rebuild(); + void addPortCombos( TQGridLayout *grid, int &gridRow, TQWidget *grp, + const TQValueList<PulseModel::DevicePortInfo> &devices, + bool isSink ); + void updatePortCombo( uint32_t paIndex, bool isSink ); PulseModel *m_model; TQScrollView *m_scroll; diff --git a/src/ui/devicewidget.cpp b/src/ui/devicewidget.cpp index 22e2995..f7ac79a 100644 --- a/src/ui/devicewidget.cpp +++ b/src/ui/devicewidget.cpp @@ -312,12 +312,12 @@ void DeviceWidget::contextMenuEvent( TQContextMenuEvent *e ) if ( cat == AudioDevice::Output ) { menu.insertSeparator(); - int id = menu.insertItem( i18n("Set as Default Output"), this, TQ_SLOT(onSetDefault()) ); + int id = menu.insertItem( i18n("Set as Default Output"), this, TQ_SLOT(onDefaultClicked()) ); menu.setItemChecked( id, m_model->defaultOutput() == m_device ); } else if ( cat == AudioDevice::Input ) { menu.insertSeparator(); - int id = menu.insertItem( i18n("Set as Default Input"), this, TQ_SLOT(onSetDefault()) ); + int id = menu.insertItem( i18n("Set as Default Input"), this, TQ_SLOT(onDefaultClicked()) ); menu.setItemChecked( id, m_model->defaultInput() == m_device ); } else if ( cat == AudioDevice::Playback ) { @@ -376,11 +376,6 @@ void DeviceWidget::onRecordingActive( bool active ) m_recordingLed->setState( active ? KLed::On : KLed::Off ); } -void DeviceWidget::onSetDefault() -{ - onDefaultClicked(); -} - void DeviceWidget::setSeparatorVisible( bool v ) { if ( m_sep ) v ? m_sep->show() : m_sep->hide(); diff --git a/src/ui/devicewidget.h b/src/ui/devicewidget.h index 802014e..4851cd1 100644 --- a/src/ui/devicewidget.h +++ b/src/ui/devicewidget.h @@ -38,7 +38,6 @@ private slots: void onBalanceChanged( int v ); void onMuteClicked(); void onToggleMute(); - void onSetDefault(); void onDefaultClicked(); void onMoveToSink( int id ); void onDefaultChanged( AudioDevice *dev ); |
