diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-05-12 01:34:29 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2020-05-25 13:24:32 +0900 |
commit | 2251b3395ac880f0b24db47615bf21ed97ec69f3 (patch) | |
tree | 219d0543f15a1b8651b87e78c33c7ae62d5bdb60 | |
parent | a00a998b33895808e19627966f047e7c32d2556c (diff) | |
download | tdemultimedia-2251b3395ac880f0b24db47615bf21ed97ec69f3.tar.gz tdemultimedia-2251b3395ac880f0b24db47615bf21ed97ec69f3.zip |
Added initial support for PulseAudio in KMix. The mixer/device channel to control
from the system tray widget is now selectable from the user and default
to the main one if not specifically selected. This allows to control
PulseAudio volume from KMix correctly.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r-- | kmix/dialogselectmaster.cpp | 63 | ||||
-rw-r--r-- | kmix/dialogselectmaster.h | 6 | ||||
-rw-r--r-- | kmix/kmix.cpp | 16 | ||||
-rw-r--r-- | kmix/kmixdockwidget.cpp | 55 | ||||
-rw-r--r-- | kmix/kmixdockwidget.h | 6 | ||||
-rw-r--r-- | kmix/mixer.cpp | 11 | ||||
-rw-r--r-- | kmix/mixer.h | 2 |
7 files changed, 109 insertions, 50 deletions
diff --git a/kmix/dialogselectmaster.cpp b/kmix/dialogselectmaster.cpp index ec957d4b..06b8d22c 100644 --- a/kmix/dialogselectmaster.cpp +++ b/kmix/dialogselectmaster.cpp @@ -31,6 +31,7 @@ #include <kcombobox.h> #include <kdebug.h> #include <kdialogbase.h> +#include <tdeapplication.h> #include <tdelocale.h> #include "dialogselectmaster.h" @@ -43,7 +44,6 @@ DialogSelectMaster::DialogSelectMaster( Mixer *mixer ) _layout = 0; m_vboxForScrollView = 0; createWidgets(mixer); // Open with Mixer Hardware #0 - } DialogSelectMaster::~DialogSelectMaster() @@ -60,23 +60,29 @@ void DialogSelectMaster::createWidgets(Mixer *ptr_mixer) TQFrame *m_mainFrame = plainPage(); _layout = new TQVBoxLayout(m_mainFrame,0,-1, "_layout" ); + // Default or user selected + TQButtonGroup *bgMasterSelection = new TQButtonGroup(1, Qt::Vertical, i18n("KMix master channel selection"), m_mainFrame); + connect(bgMasterSelection, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(masterSelectionChanged(int))); + _layout->add(bgMasterSelection); + m_defaultMaster = new TQRadioButton(i18n("Default"), bgMasterSelection); + m_userMaster = new TQRadioButton(i18n("Custom"), bgMasterSelection); + + m_vboxChannels = new TQVBox(m_mainFrame); + _layout->add(m_vboxChannels); if ( Mixer::mixers().count() > 1 ) { //kdDebug(67100) << "DialogSelectMaster::createPage count()>1" << "\n"; // More than one Mixer => show Combo-Box to select Mixer // Mixer widget line - TQHBoxLayout* mixerNameLayout = new TQHBoxLayout( _layout ); - //widgetsLayout->setStretchFactor( mixerNameLayout, 0 ); - //TQSizePolicy qsp( TQSizePolicy::Ignored, TQSizePolicy::Maximum); - //mixerNameLayout->setSizePolicy(qsp); - mixerNameLayout->setSpacing(KDialog::spacingHint()); - - TQLabel *qlbl = new TQLabel( i18n("Current Mixer"), m_mainFrame ); - mixerNameLayout->addWidget(qlbl); + TQHBox *hboxMixerName = new TQHBox(m_vboxChannels); + hboxMixerName->setSpacing(KDialog::spacingHint()); + + TQLabel *qlbl = new TQLabel( i18n("Current Mixer"), hboxMixerName ); qlbl->setFixedHeight(qlbl->sizeHint().height()); - m_cMixer = new KComboBox( FALSE, m_mainFrame, "mixerCombo" ); + m_cMixer = new KComboBox( FALSE, hboxMixerName, "mixerCombo" ); m_cMixer->setFixedHeight(m_cMixer->sizeHint().height()); - connect( m_cMixer, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( createPageByID( int ) ) ); + TQToolTip::add(m_cMixer, i18n("Current mixer")); + connect(m_cMixer, TQT_SIGNAL(activated(int)), this, TQT_SLOT(createPageByID(int))); //int id=1; for ( Mixer *mixer = Mixer::mixers().first(); mixer !=0; mixer = Mixer::mixers().next() ) { @@ -87,24 +93,37 @@ void DialogSelectMaster::createWidgets(Mixer *ptr_mixer) } //id++; } // end for all_Mixers - - TQToolTip::add( m_cMixer, i18n("Current mixer" ) ); - mixerNameLayout->addWidget(m_cMixer); - } // end if (more_than_1_Mixer) - TQLabel *qlbl = new TQLabel( i18n("Select the channel representing the master volume:"), m_mainFrame ); + TQLabel *qlbl = new TQLabel( i18n("Select the channel representing the master volume:"), m_vboxChannels ); _layout->addWidget(qlbl); - m_scrollableChannelSelector = new TQScrollView(m_mainFrame, "scrollableChannelSelector"); + m_scrollableChannelSelector = new TQScrollView(m_vboxChannels, "scrollableChannelSelector"); m_scrollableChannelSelector->viewport()->setBackgroundMode(TQt::PaletteBackground); - _layout->add(m_scrollableChannelSelector); m_buttonGroupForScrollView = new TQButtonGroup(this); // invisible TQButtonGroup m_buttonGroupForScrollView->hide(); createPage(ptr_mixer); - connect( this, TQT_SIGNAL(okClicked()) , this, TQT_SLOT(apply()) ); + + kapp->config()->setGroup(0); + bool useDefaultMaster = kapp->config()->readBoolEntry("UseDefaultMaster", true); + if (useDefaultMaster) + { + m_defaultMaster->setChecked(true); + } + else + { + m_userMaster->setChecked(true); + } + masterSelectionChanged(0); + + connect( this, TQT_SIGNAL(okClicked()) , this, TQT_SLOT(apply()) ); +} + +void DialogSelectMaster::masterSelectionChanged(int _unused) +{ + m_vboxChannels->setEnabled(m_userMaster->isChecked()); } /** @@ -180,15 +199,15 @@ void DialogSelectMaster::apply() int channel_id = m_buttonGroupForScrollView->selectedId(); if ( channel_id != -1 ) { // A channel was selected by the user => emit the "newMasterSelected()" signal - //kdDebug(67100) << "DialogSelectMaster::apply(): card=" << soundcard_id << ", channel=" << channel_id << endl; + //kdDebug(67100) << "DialogSelectMaster::apply(): default master=" << m_defaultMaster->isChecked() << ", card=" << soundcard_id << ", channel=" << channel_id << endl; Mixer *mixer = Mixer::mixers().at(soundcard_id); if ( mixer == 0 ) { kdError(67100) << "DialogSelectMaster::createPage(): Invalid Mixer (mixerID=" << soundcard_id << ")" << endl; return; // can not happen } else { - mixer->setMasterDevice( m_mixerPKs[channel_id] ); - emit newMasterSelected(soundcard_id, m_mixerPKs[channel_id] ); + mixer->setMasterDevice(m_mixerPKs[channel_id]); + emit newMasterSelected(m_defaultMaster->isChecked(), soundcard_id, m_mixerPKs[channel_id]); } } } diff --git a/kmix/dialogselectmaster.h b/kmix/dialogselectmaster.h index 8150b197..88ce89f4 100644 --- a/kmix/dialogselectmaster.h +++ b/kmix/dialogselectmaster.h @@ -22,7 +22,7 @@ class DialogSelectMaster : public KDialogBase ~DialogSelectMaster(); signals: - void newMasterSelected(int, TQString& ); + void newMasterSelected(bool defaultMaster, int soundcard_id, const TQString &channel_id); public slots: void apply(); @@ -33,11 +33,13 @@ class DialogSelectMaster : public KDialogBase TQVBoxLayout* _layout; KComboBox* m_cMixer; TQScrollView* m_scrollableChannelSelector; - TQVBox *m_vboxForScrollView; + TQVBox *m_vboxChannels, *m_vboxForScrollView; TQButtonGroup *m_buttonGroupForScrollView; + TQRadioButton *m_defaultMaster, *m_userMaster; TQStringList m_mixerPKs; private slots: + void masterSelectionChanged(int _unused); void createPageByID(int mixerId); }; diff --git a/kmix/kmix.cpp b/kmix/kmix.cpp index fc33d671..98548db9 100644 --- a/kmix/kmix.cpp +++ b/kmix/kmix.cpp @@ -155,7 +155,7 @@ KMixWindow::initWidgets() // Mixer widget line mixerNameLayout = new TQHBox( centralWidget(), "mixerNameLayout" ); - widgetsLayout->setStretchFactor( mixerNameLayout, 0 ); + widgetsLayout->setStretchFactor( mixerNameLayout, 0 ); TQSizePolicy qsp( TQSizePolicy::Ignored, TQSizePolicy::Maximum); mixerNameLayout->setSizePolicy(qsp); mixerNameLayout->setSpacing(KDialog::spacingHint()); @@ -170,7 +170,7 @@ KMixWindow::initWidgets() widgetsLayout->addWidget( mixerNameLayout ); m_wsMixers = new TQWidgetStack( centralWidget(), "MixerWidgetStack" ); - widgetsLayout->setStretchFactor( m_wsMixers, 10 ); + widgetsLayout->setStretchFactor( m_wsMixers, 10 ); widgetsLayout->addWidget( m_wsMixers ); if ( m_showMenubar ) @@ -306,10 +306,14 @@ KMixWindow::loadConfig() m_surroundView = config->readBoolEntry("Experimental-ViewSurround", false ); m_gridView = config->readBoolEntry("Experimental-ViewGrid", false ); const TQString& orientationString = config->readEntry("Orientation", "Horizontal"); - TQString mixerMasterCard = config->readEntry( "MasterMixer", "" ); - Mixer::setMasterCard(mixerMasterCard); - TQString masterDev = config->readEntry( "MasterMixerDevice", "" ); - Mixer::setMasterCardDevice(masterDev); + bool useDefaultMaster = config->readBoolEntry( "UseDefaultMaster", true ); + if (!useDefaultMaster) + { + TQString mixerMasterCard = config->readEntry( "MasterMixer", "" ); + Mixer::setMasterCard(mixerMasterCard); + TQString masterDev = config->readEntry( "MasterMixerDevice", "" ); + Mixer::setMasterCardDevice(masterDev); + } if ( valueStyleString == "Absolute" ) m_valueStyle = MixDeviceWidget::NABSOLUTE; diff --git a/kmix/kmixdockwidget.cpp b/kmix/kmixdockwidget.cpp index 1402191c..42ccccaa 100644 --- a/kmix/kmixdockwidget.cpp +++ b/kmix/kmixdockwidget.cpp @@ -57,7 +57,8 @@ KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name _oldToolTipValue(-1), _oldPixmapType('-'), _volumePopup(volumePopup), - _dockIconMuting(dockIconMuting) + _dockIconMuting(dockIconMuting), + _dsm(NULL) { Mixer* preferredMasterMixer = Mixer::masterCard(); if ( preferredMasterMixer != 0 ) { @@ -74,6 +75,10 @@ KMixDockWidget::KMixDockWidget( Mixer *mixer, TQWidget *parent, const char *name KMixDockWidget::~KMixDockWidget() { + if (_dsm) + { + delete _dsm; + } delete _audioPlayer; delete _dockAreaPopup; } @@ -146,24 +151,52 @@ void KMixDockWidget::slotUpdatePixmap() void KMixDockWidget::selectMaster() { - DialogSelectMaster* dsm = new DialogSelectMaster(m_mixer); - connect ( dsm, TQT_SIGNAL(newMasterSelected(int, TQString&)), TQT_SLOT( handleNewMaster(int,TQString&)) ); - dsm->show(); - // !! The dialog is modal. Does it delete itself? + if (!_dsm) + { + _dsm = new DialogSelectMaster(m_mixer); + connect(_dsm, TQT_SIGNAL(newMasterSelected(bool, int, const TQString&)), TQT_SLOT( handleNewMaster(bool, int, const TQString&))); + } + _dsm->show(); } -void KMixDockWidget::handleNewMaster(int soundcard_id, TQString& channel_id) // !! @todo rework parameters +void KMixDockWidget::handleNewMaster(bool defaultMaster, int soundcard_id, const TQString &channel_id) { - //kdDebug(67100) << "KMixDockWidget::handleNewMaster() soundcard_id=" << soundcard_id << " , channel_id=" << channel_id << endl; - Mixer *mixer = Mixer::mixers().at(soundcard_id); - if ( mixer == 0 ) { - kdError(67100) << "KMixDockWidget::createPage(): Invalid Mixer (soundcard_id=" << soundcard_id << ")" << endl; + //kdDebug(67100) << "KMixDockWidget::handleNewMaster() default master=" << defaultMaster << ", soundcard_id=" << soundcard_id << ", channel_id=" << channel_id << endl; + kapp->config()->setGroup(0); + kapp->config()->writeEntry("UseDefaultMaster", defaultMaster); + Mixer *mixer; + TQString channel = TQString::null; + if (defaultMaster) + { + mixer = Mixer::mixers().first(); + if (mixer) + { + MixSet ms = mixer->getMixSet(); + for (MixDevice *md = ms.first(); md != 0; md = ms.next()) + { + if (!md->isRecordable() && !md->isSwitch() && !md->isEnum()) + { + channel = md->getPK(); + break; + } + } + } + } + else + { + mixer = Mixer::mixers().at(soundcard_id); + channel = channel_id; + } + + if (!mixer || channel.isEmpty()) { + kdError(67100) << "KMixDockWidget::createPage(): Invalid Mixer (default master=" << defaultMaster << ", soundcard_id=" + << soundcard_id << ", channel_id=" << channel_id << ")" << endl; return; // can not happen } m_mixer = mixer; Mixer::setMasterCard(mixer->id()); // We must save this information "somewhere". - Mixer::setMasterCardDevice( channel_id ); + Mixer::setMasterCardDevice(channel); createMasterVolWidget(); } diff --git a/kmix/kmixdockwidget.h b/kmix/kmixdockwidget.h index 0899d28f..6be2b4b7 100644 --- a/kmix/kmixdockwidget.h +++ b/kmix/kmixdockwidget.h @@ -36,11 +36,11 @@ class MixDeviceWidget; class Mixer; class ViewDockAreaPopup; class Volume; +class DialogSelectMaster; class KMixDockWidget : public KSystemTray { Q_OBJECT - friend class KMixWindow; public: @@ -78,10 +78,12 @@ class KMixDockWidget : public KSystemTray { char _oldPixmapType; bool _volumePopup; bool _dockIconMuting; + DialogSelectMaster *_dsm; + private slots: void dockMute(); void selectMaster(); - void handleNewMaster(int soundcard_id, TQString& channel_id); + void handleNewMaster(bool defaultMaster, int soundcard_id, const TQString &channel_id); }; #endif diff --git a/kmix/mixer.cpp b/kmix/mixer.cpp index ba3bfee8..bda80910 100644 --- a/kmix/mixer.cpp +++ b/kmix/mixer.cpp @@ -383,24 +383,23 @@ void Mixer::setMasterCard(TQString& ref_id) Mixer* Mixer::masterCard() { - Mixer *mixer = 0; kdDebug(67100) << "Mixer::masterCard() searching for id=" << _masterCard << "\n"; - for (mixer=Mixer::mixers().first(); mixer!=0; mixer=Mixer::mixers().next()) + for (Mixer *mixer = Mixer::mixers().first(); mixer; mixer = Mixer::mixers().next()) { if ( mixer->id() == _masterCard ) { #ifdef MIXER_MASTER_DEBUG kdDebug(67100) << "Mixer::masterCard() found id=" << mixer->id() << "\n"; #endif - break; + return mixer; } } #ifdef MIXER_MASTER_DEBUG - if ( mixer == 0) kdDebug(67100) << "Mixer::masterCard() found no Mixer* mixer \n"; + kdDebug(67100) << "Mixer::masterCard() found no Mixer* mixer \n"; #endif - return mixer; + return NULL; } -void Mixer::setMasterCardDevice(TQString& ref_id) +void Mixer::setMasterCardDevice(const TQString &ref_id) { // The value is taken over without checking on existance. This allows the User to define // a MasterCard that is not always available (e.g. it is an USB hotplugging device). diff --git a/kmix/mixer.h b/kmix/mixer.h index d9566e81..2fc44a85 100644 --- a/kmix/mixer.h +++ b/kmix/mixer.h @@ -100,7 +100,7 @@ class Mixer : public TQObject, virtual public MixerIface static void setMasterCard(TQString& ref_id); static Mixer* masterCard(); /// The global Master Device inside the current MasterCard (as returned by masterCard()). - static void setMasterCardDevice(TQString& ref_id); + static void setMasterCardDevice(const TQString &ref_id); static MixDevice* masterCardDevice(); |