diff options
| author | Calvin Morrison <calvin@pobox.com> | 2026-05-22 10:16:15 -0400 |
|---|---|---|
| committer | Calvin Morrison <calvin@pobox.com> | 2026-05-22 10:16:15 -0400 |
| commit | cdf72828e599a63fca4a0f1ceeb3145fba581aa3 (patch) | |
| tree | 16ee02f0ce1e317a09fd4c2a3f9fbdc04aadfe60 /src/ui | |
| parent | b30b234afa3ec18156e432b9f2a7ad2ca80cc672 (diff) | |
| parent | d9876849f0208291cc7010522e85593703ff52bd (diff) | |
Merge branch 'and-the-oss-you-rode-in-on'
Diffstat (limited to 'src/ui')
31 files changed, 2495 insertions, 117 deletions
diff --git a/src/ui/alsa/alsadevicespage.cpp b/src/ui/alsa/alsadevicespage.cpp new file mode 100644 index 0000000..2b7ede0 --- /dev/null +++ b/src/ui/alsa/alsadevicespage.cpp @@ -0,0 +1,161 @@ +#include "alsadevicespage.h" +#include "../../model/alsamodel.h" +#include "../../model/alsadevice.h" +#include "../kledbutton.h" + +#include <tqlayout.h> +#include <tqlabel.h> +#include <tqcombobox.h> +#include <tqscrollview.h> +#include <tqframe.h> +#include <tdelocale.h> + +// ── AlsaSwitchRow ───────────────────────────────────────────────────────── + +AlsaSwitchRow::AlsaSwitchRow( AlsaDevice *dev, TQWidget *parent ) + : TQWidget(parent), m_dev(dev) +{ + TQColor ledColor = ( dev->category() == AlsaDevice::Input ) ? TQt::red : TQt::yellow; + m_led = new KLedButton( ledColor, + dev->muted() ? KLed::Off : KLed::On, + KLed::Sunken, KLed::Circular, this ); + m_led->setFixedSize(14, 14); + + TQHBoxLayout *hbox = new TQHBoxLayout(this, 2, 4); + hbox->addWidget(m_led); + hbox->addWidget( new TQLabel(dev->name(), this) ); + hbox->addStretch(1); + + connect(dev, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(onMuteChanged(bool))); + connect(m_led, TQ_SIGNAL(stateChanged(bool)), this, TQ_SLOT(onLedToggled(bool))); +} + +void AlsaSwitchRow::onMuteChanged( bool m ) +{ + m_led->blockSignals(true); + m_led->setState( m ? KLed::Off : KLed::On ); + m_led->blockSignals(false); +} + +void AlsaSwitchRow::onLedToggled( bool on ) +{ + m_dev->setMuted( !on ); +} + +// ── AlsaEnumRow ────────────────────────────────────────────────────────────── + +AlsaEnumRow::AlsaEnumRow( AlsaDevice *dev, TQWidget *parent ) + : TQWidget(parent), m_dev(dev) +{ + m_combo = new TQComboBox(false, this); + TQStringList vals = dev->enumValues(); + for ( TQStringList::ConstIterator it = vals.begin(); it != vals.end(); ++it ) + m_combo->insertItem(*it); + m_combo->setCurrentItem( dev->enumId() ); + + TQHBoxLayout *hbox = new TQHBoxLayout(this, 2, 6); + hbox->addWidget( new TQLabel(dev->name() + ":", this) ); + hbox->addWidget(m_combo, 1); + + connect(dev, TQ_SIGNAL(enumChanged(int)), this, TQ_SLOT(onEnumChanged(int))); + connect(m_combo, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onComboActivated(int))); +} + +void AlsaEnumRow::onEnumChanged( int id ) +{ + m_combo->blockSignals(true); + m_combo->setCurrentItem(id); + m_combo->blockSignals(false); +} + +void AlsaEnumRow::onComboActivated( int idx ) +{ + m_dev->setEnumId(idx); +} + +// ── AlsaDevicesPage ────────────────────────────────────────────────────────── + +AlsaDevicesPage::AlsaDevicesPage( AlsaModel *model, TQWidget *parent ) + : TQWidget(parent), m_model(model), m_cardIndex(-1), m_content(0) +{ + TQVBoxLayout *outer = new TQVBoxLayout(this, 8, 4); + + m_scroll = new TQScrollView(this); + m_scroll->setResizePolicy( TQScrollView::AutoOneFit ); + m_scroll->setFrameStyle( TQFrame::NoFrame ); + outer->addWidget(m_scroll, 1); + + m_content = new TQWidget( m_scroll->viewport() ); + m_scroll->addChild(m_content); + + connect(model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(onDeviceAdded(AlsaDevice*))); +} + +void AlsaDevicesPage::setCard( int cardIndex ) +{ + m_cardIndex = cardIndex; + rebuild(); +} + +void AlsaDevicesPage::rebuild() +{ + delete m_content; + m_content = new TQWidget( m_scroll->viewport() ); + m_scroll->addChild(m_content); + + TQVBoxLayout *vbox = new TQVBoxLayout(m_content, 6, 4); + + if ( m_cardIndex < 0 ) { + vbox->addWidget( new TQLabel( i18n("No card selected."), m_content ) ); + vbox->addStretch(1); + m_content->show(); + return; + } + + TQPtrList<AlsaDevice> devs = m_model->devicesForCard(m_cardIndex); + bool hasSwitches = false, hasEnums = false; + + for ( TQPtrListIterator<AlsaDevice> it(devs); *it; ++it ) { + if ( (*it)->type() == AlsaDevice::Switch ) hasSwitches = true; + if ( (*it)->type() == AlsaDevice::Enum ) hasEnums = true; + } + + if ( hasSwitches ) { + TQLabel *hdr = new TQLabel( TQString("<b>%1</b>").arg(i18n("Switches")), m_content ); + vbox->addWidget(hdr); + for ( TQPtrListIterator<AlsaDevice> it(devs); *it; ++it ) { + if ( (*it)->type() == AlsaDevice::Switch ) { + AlsaSwitchRow *row = new AlsaSwitchRow( *it, m_content ); + vbox->addWidget(row); + } + } + if ( hasEnums ) + vbox->addSpacing(8); + } + + if ( hasEnums ) { + TQLabel *hdr = new TQLabel( TQString("<b>%1</b>").arg(i18n("Routing")), m_content ); + vbox->addWidget(hdr); + for ( TQPtrListIterator<AlsaDevice> it(devs); *it; ++it ) { + if ( (*it)->type() == AlsaDevice::Enum ) { + AlsaEnumRow *row = new AlsaEnumRow( *it, m_content ); + vbox->addWidget(row); + } + } + } + + if ( !hasSwitches && !hasEnums ) { + vbox->addWidget( new TQLabel( i18n("No device settings available for this card."), m_content ) ); + } + + vbox->addStretch(1); + m_content->show(); + m_content->adjustSize(); +} + +void AlsaDevicesPage::onDeviceAdded( AlsaDevice * ) +{ + rebuild(); +} + +#include "alsadevicespage.moc" diff --git a/src/ui/alsa/alsadevicespage.h b/src/ui/alsa/alsadevicespage.h new file mode 100644 index 0000000..4883f85 --- /dev/null +++ b/src/ui/alsa/alsadevicespage.h @@ -0,0 +1,66 @@ +#pragma once + +#include <tqwidget.h> +#include <tqstring.h> + +class AlsaModel; +class AlsaDevice; +class TQScrollView; +class TQComboBox; +class KLedButton; + +// ── One row per Switch element ────────────────────────────────────────────── + +class AlsaSwitchRow : public TQWidget +{ + TQ_OBJECT +public: + AlsaSwitchRow( AlsaDevice *dev, TQWidget *parent = 0 ); + +private slots: + void onMuteChanged( bool m ); + void onLedToggled( bool on ); + +private: + AlsaDevice *m_dev; + KLedButton *m_led; +}; + +// ── One row per Enum element ──────────────────────────────────────────────── + +class AlsaEnumRow : public TQWidget +{ + TQ_OBJECT +public: + AlsaEnumRow( AlsaDevice *dev, TQWidget *parent = 0 ); + +private slots: + void onEnumChanged( int id ); + void onComboActivated( int idx ); + +private: + AlsaDevice *m_dev; + TQComboBox *m_combo; +}; + +// ── Device Settings page ──────────────────────────────────────────────────── + +class AlsaDevicesPage : public TQWidget +{ + TQ_OBJECT +public: + explicit AlsaDevicesPage( AlsaModel *model, TQWidget *parent = 0 ); + + void setCard( int cardIndex ); + +private slots: + void onDeviceAdded( AlsaDevice * ); + +private: + void rebuild(); + + AlsaModel *m_model; + int m_cardIndex; + TQScrollView *m_scroll; + TQWidget *m_content; +}; diff --git a/src/ui/alsa/alsadevicewidget.cpp b/src/ui/alsa/alsadevicewidget.cpp new file mode 100644 index 0000000..214d931 --- /dev/null +++ b/src/ui/alsa/alsadevicewidget.cpp @@ -0,0 +1,175 @@ +#include "alsadevicewidget.h" +#include "../../model/alsadevice.h" +#include "../balanceknob.h" +#include "../kledbutton.h" + +#include <tqlayout.h> +#include <tqslider.h> +#include <tqlabel.h> +#include <tqpixmap.h> +#include <tqpainter.h> +#include <tdeglobal.h> +#include <kstandarddirs.h> + +// ---- rotated label (same as PA widget) -------------------------------------- + +class VerticalLabel : public TQWidget +{ +public: + VerticalLabel( const TQString &text, TQWidget *parent ) + : TQWidget(parent), m_text(text) + { + setMinimumSize( 20, 10 ); + } + TQSize sizeHint() const { return TQSize( 20, 100 ); } + TQSizePolicy sizePolicy() const { + return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding ); + } +protected: + void paintEvent( TQPaintEvent * ) { + TQPainter p( this ); + TQFontMetrics fm = p.fontMetrics(); + int available = height() - 6; + TQString text = m_text; + if ( fm.width(text) > available ) { + while ( text.length() > 1 && fm.width(text) + fm.width("...") > available ) + text.truncate( text.length() - 1 ); + text += "..."; + } + p.rotate( 270 ); + p.translate( 0, -4 ); + p.drawText( -height() + 2, width(), text ); + } +private: + TQString m_text; +}; + +// ---- widget ----------------------------------------------------------------- + +static TQPixmap alsaPic( const char *name ) +{ + TQString path = TDEGlobal::dirs()->findResource("data", + TQString("tmix/pics/") + name); + return path.isEmpty() ? TQPixmap() : TQPixmap(path); +} + +static TQPixmap iconForDevice( AlsaDevice *dev ) +{ + TQString n = dev->name().lower(); + + if ( n.contains("headphone") || n.contains("headset") ) + return alsaPic("mix_headphone.png"); + if ( n.contains("mic") ) + return alsaPic("mix_microphone.png"); + if ( n.contains("line") || n.contains("panel") ) + return alsaPic("mix_ext.png"); + if ( n.contains("capture") || n.contains("record") ) + return alsaPic("mix_record.png"); + if ( n.contains("surround") ) + return alsaPic("mix_surround.png"); + if ( n.contains("bass") || n.contains("lfe") ) + return alsaPic("mix_bass.png"); + if ( n.contains("cd") ) + return alsaPic("mix_cd.png"); + if ( n.contains("digital") || n.contains("iec") || n.contains("spdif") ) + return alsaPic("mix_digital.png"); + if ( n.contains("video") ) + return alsaPic("mix_video.png"); + if ( n.contains("midi") ) + return alsaPic("mix_midi.png"); + if ( n.contains("pcm") || n.contains("wave") ) + return alsaPic("mix_audio.png"); + if ( dev->category() == AlsaDevice::Input ) + return alsaPic("mix_microphone.png"); + return alsaPic("crystal/audio-volume-medium.png"); +} + +AlsaDeviceWidget::AlsaDeviceWidget( AlsaDevice *dev, TQWidget *parent ) + : TQWidget(parent), m_dev(dev), m_balance(0) +{ + // outer centers everything horizontally + TQHBoxLayout *outer = new TQHBoxLayout(this, 4, 0); + outer->addStretch(1); + + TQVBoxLayout *col = new TQVBoxLayout(0, 0, 2); + + // top: icon + vol% + TQHBoxLayout *topRow = new TQHBoxLayout(0, 0, 2); + TQLabel *icon = new TQLabel(this); + TQPixmap px = iconForDevice(dev); + if ( !px.isNull() ) icon->setPixmap(px); + topRow->addWidget(icon, 0, TQt::AlignVCenter); + m_volLabel = new TQLabel(TQString("%1%").arg(dev->volume()), this); + topRow->addWidget(m_volLabel, 0, TQt::AlignVCenter); + col->addLayout(topRow); + + // slider row: rotated label beside slider, so label bottom == slider bottom + TQHBoxLayout *sliderRow = new TQHBoxLayout(0, 0, 2); + VerticalLabel *vlabel = new VerticalLabel(dev->name(), this); + sliderRow->addWidget(vlabel); + m_slider = new TQSlider(0, 100, 5, 100 - dev->volume(), TQt::Vertical, this); + m_slider->setTickmarks( TQSlider::Right ); + m_slider->setTickInterval( 5 ); + m_slider->setMinimumHeight(80); + sliderRow->addWidget(m_slider, 1); + col->addLayout(sliderRow, 1); + + // fixed bottom row: balance + mute + TQWidget *bottom = new TQWidget(this); + bottom->setFixedHeight(30); + TQHBoxLayout *bottomRow = new TQHBoxLayout(bottom, 0, 2); + bottomRow->addStretch(1); + if ( dev->stereo() ) { + m_balance = new BalanceKnob(-50, 50, dev->pan(), bottom); + bottomRow->addWidget(m_balance, 0, TQt::AlignVCenter); + bottomRow->addStretch(1); + connect(m_balance, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(onPanMoved(int))); + } + m_muteBtn = new KLedButton(TQt::green, + dev->muted() ? KLed::Off : KLed::On, + KLed::Raised, KLed::Circular, bottom); + m_muteBtn->setFixedSize(16, 16); + m_muteBtn->setEnabled(dev->hasMute()); + bottomRow->addWidget(m_muteBtn, 0, TQt::AlignVCenter); + bottomRow->addStretch(1); + col->addWidget(bottom, 0); + + outer->addLayout(col); + outer->addStretch(1); + + connect(dev, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(onVolumeChanged(int))); + connect(dev, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(onMuteChanged(bool))); + connect(dev, TQ_SIGNAL(panChanged(int)), this, TQ_SLOT(onPanChanged(int))); + connect(m_slider, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(onSliderMoved(int))); + connect(m_muteBtn, TQ_SIGNAL(stateChanged(bool)), this, TQ_SLOT(onMuteToggled(bool))); +} + +void AlsaDeviceWidget::onVolumeChanged( int v ) +{ + m_slider->blockSignals(true); + m_slider->setValue(100 - v); + m_slider->blockSignals(false); + m_volLabel->setText(TQString("%1%").arg(v)); +} + +void AlsaDeviceWidget::onMuteChanged( bool m ) +{ + m_muteBtn->blockSignals(true); + m_muteBtn->setState(m ? KLed::Off : KLed::On); + m_muteBtn->blockSignals(false); +} + +void AlsaDeviceWidget::onPanChanged( int p ) +{ + if ( m_balance ) { + m_balance->blockSignals(true); + m_balance->setValue(p); + m_balance->blockSignals(false); + } +} + +void AlsaDeviceWidget::onSliderMoved( int v ) { m_dev->setVolume(100 - v); } +void AlsaDeviceWidget::onMuteToggled( bool on ) { m_dev->setMuted(!on); } +void AlsaDeviceWidget::onPanMoved( int p ) { m_dev->setPan(p); } + +#include "alsadevicewidget.moc" diff --git a/src/ui/alsa/alsadevicewidget.h b/src/ui/alsa/alsadevicewidget.h new file mode 100644 index 0000000..aa4d63e --- /dev/null +++ b/src/ui/alsa/alsadevicewidget.h @@ -0,0 +1,31 @@ +#pragma once + +#include <tqwidget.h> + +class AlsaDevice; +class TQSlider; +class TQLabel; +class KLedButton; +class BalanceKnob; + +class AlsaDeviceWidget : public TQWidget +{ + TQ_OBJECT +public: + AlsaDeviceWidget( AlsaDevice *dev, TQWidget *parent = 0 ); + +private slots: + void onVolumeChanged( int v ); + void onMuteChanged( bool m ); + void onPanChanged( int p ); + void onSliderMoved( int v ); + void onMuteToggled( bool on ); + void onPanMoved( int p ); + +private: + AlsaDevice *m_dev; + TQSlider *m_slider; + TQLabel *m_volLabel; + KLedButton *m_muteBtn; + BalanceKnob *m_balance; +}; diff --git a/src/ui/alsa/alsamixerwindow.cpp b/src/ui/alsa/alsamixerwindow.cpp new file mode 100644 index 0000000..6c14ce4 --- /dev/null +++ b/src/ui/alsa/alsamixerwindow.cpp @@ -0,0 +1,206 @@ +#include "alsamixerwindow.h" +#include "alsadevicewidget.h" +#include "alsadevicespage.h" +#include "alsatray.h" +#include "../preferencesdlg.h" +#include "../../model/alsamodel.h" +#include "../../model/alsadevice.h" + +#include <tqlayout.h> +#include <tqcombobox.h> +#include <tqtabwidget.h> +#include <tqlabel.h> +#include <tqhbox.h> +#include <tdeapplication.h> +#include <tdelocale.h> +#include <tdemenubar.h> +#include <tdepopupmenu.h> +#include <tdeaboutapplication.h> +#include <tdeaboutdata.h> +#include <kiconloader.h> +#include <tdeconfig.h> +#include <tdeglobal.h> +#include <twin.h> + +AlsaMixerWindow::AlsaMixerWindow( AlsaModel *model, TQWidget *parent ) + : TDEMainWindow(parent, "AlsaMixerWindow"), + m_model(model), m_tray(0), m_posRestored(false), m_devicesPage(0) +{ + m_widgets.setAutoDelete(true); + setCaption( i18n("Volume Control") ); + + TQWidget *central = new TQWidget(this); + setCentralWidget(central); + TQVBoxLayout *vbox = new TQVBoxLayout(central, 8, 6); + + // card selector row — right aligned + TQHBoxLayout *topRow = new TQHBoxLayout(0, 0, 6); + topRow->addStretch(); + topRow->addWidget( new TQLabel(i18n("Card:"), central) ); + m_cardCombo = new TQComboBox(false, central); + TQValueList<AlsaCard> cards = model->cards(); + for ( TQValueListConstIterator<AlsaCard> it = cards.begin(); it != cards.end(); ++it ) + m_cardCombo->insertItem( (*it).name ); + topRow->addWidget(m_cardCombo); + vbox->addLayout(topRow); + + // tabs + m_tabs = new TQTabWidget(central); + + m_outputPage = new TQWidget(m_tabs); + m_outputLayout = new TQHBoxLayout(m_outputPage, 8, 6); + m_tabs->addTab(m_outputPage, i18n("Output")); + + m_inputPage = new TQWidget(m_tabs); + m_inputLayout = new TQHBoxLayout(m_inputPage, 8, 6); + m_tabs->addTab(m_inputPage, i18n("Input")); + + m_devicesPage = new AlsaDevicesPage(model, m_tabs); + m_tabs->addTab(m_devicesPage, i18n("Device Settings")); + + vbox->addWidget(m_tabs, 1); + + if ( !cards.isEmpty() ) + rebuildTabs( cards.front().index ); + + setMinimumSize( 400, 250 ); + + TDEConfig *gcfg = TDEGlobal::config(); + gcfg->setGroup("AlsaMainWindow"); + if ( gcfg->hasKey("Width") ) + applyMainWindowSettings( gcfg, "AlsaMainWindow" ); + else + resize( 650, 380 ); + + connect(m_cardCombo, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onCardChanged(int))); + connect(model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(onDeviceAdded(AlsaDevice*))); + + TDEPopupMenu *fileMenu = new TDEPopupMenu(this); + fileMenu->insertItem( SmallIcon("application-exit"), i18n("&Quit"), + this, TQ_SLOT(quit()) ); + + TDEPopupMenu *settingsMenu = new TDEPopupMenu(this); + settingsMenu->insertItem( SmallIcon("configure"), i18n("&Configure..."), + this, TQ_SLOT(showPreferences()) ); + + TDEPopupMenu *helpMenu = new TDEPopupMenu(this); + helpMenu->insertItem( SmallIcon("help"), i18n("&About TMix"), + this, TQ_SLOT(showAbout()) ); + + menuBar()->insertItem( i18n("&File"), fileMenu ); + menuBar()->insertItem( i18n("&Settings"), settingsMenu ); + menuBar()->insertItem( i18n("&Help"), helpMenu ); +} + +void AlsaMixerWindow::rebuildTabs( int cardIndex ) +{ + m_widgets.clear(); + + delete m_outputPage->layout(); + m_outputLayout = new TQHBoxLayout(m_outputPage, 8, 6); + + delete m_inputPage->layout(); + m_inputLayout = new TQHBoxLayout(m_inputPage, 8, 6); + + TQPtrList<AlsaDevice> devs = m_model->devicesForCard(cardIndex); + bool hasOutput = false, hasInput = false; + for ( TQPtrListIterator<AlsaDevice> it(devs); *it; ++it ) { + AlsaDevice *dev = *it; + if ( dev->type() != AlsaDevice::Slider ) continue; + + AlsaDeviceWidget *w = new AlsaDeviceWidget(dev, + dev->category() == AlsaDevice::Output ? m_outputPage : m_inputPage); + if ( dev->category() == AlsaDevice::Output ) { + m_outputLayout->addWidget(w); + hasOutput = true; + } else { + m_inputLayout->addWidget(w); + hasInput = true; + } + w->show(); + m_widgets.append(w); + } + + if ( !hasOutput ) m_outputLayout->addWidget( new TQLabel(i18n("No output controls."), m_outputPage) ); + if ( !hasInput ) m_inputLayout->addWidget( new TQLabel(i18n("No input controls."), m_inputPage) ); + + m_outputLayout->addStretch(); + m_inputLayout->addStretch(); + + if ( m_devicesPage ) + m_devicesPage->setCard(cardIndex); +} + +void AlsaMixerWindow::onCardChanged( int idx ) +{ + TQValueList<AlsaCard> cards = m_model->cards(); + if ( idx < 0 || idx >= (int)cards.count() ) return; + TQValueListConstIterator<AlsaCard> it = cards.begin(); + for ( int i = 0; i < idx; ++i ) ++it; + rebuildTabs( (*it).index ); +} + +void AlsaMixerWindow::onDeviceAdded( AlsaDevice * ) +{ + m_cardCombo->clear(); + TQValueList<AlsaCard> cards = m_model->cards(); + for ( TQValueListConstIterator<AlsaCard> it = cards.begin(); it != cards.end(); ++it ) + m_cardCombo->insertItem( (*it).name ); + onCardChanged( m_cardCombo->currentItem() ); +} + +void AlsaMixerWindow::bringToFront() +{ + show(); + KWin::forceActiveWindow( winId() ); +} + +void AlsaMixerWindow::showEvent( TQShowEvent *e ) +{ + TDEMainWindow::showEvent(e); + if ( !m_posRestored ) { + m_posRestored = true; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("AlsaMainWindow"); + int xp = cfg->readNumEntry("XPos", -1); + int yp = cfg->readNumEntry("YPos", -1); + if ( xp >= 0 && yp >= 0 ) + move( xp, yp ); + } +} + +bool AlsaMixerWindow::queryClose() +{ + saveMainWindowSettings( TDEGlobal::config(), "AlsaMainWindow" ); + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("AlsaMainWindow"); + cfg->writeEntry("XPos", x()); + cfg->writeEntry("YPos", y()); + cfg->sync(); + + if ( m_tray ) { hide(); return false; } + // Not in systray — closing the window means quit. + quit(); + return false; +} + +void AlsaMixerWindow::quit() +{ + m_tray = 0; + kapp->quit(); +} + +void AlsaMixerWindow::showPreferences() +{ + PreferencesDlg dlg( m_model, this ); + dlg.exec(); + emit settingsChanged(); +} + +void AlsaMixerWindow::showAbout() +{ + TDEAboutApplication dlg(this); + dlg.exec(); +} + +#include "alsamixerwindow.moc" diff --git a/src/ui/alsa/alsamixerwindow.h b/src/ui/alsa/alsamixerwindow.h new file mode 100644 index 0000000..8d8ef4f --- /dev/null +++ b/src/ui/alsa/alsamixerwindow.h @@ -0,0 +1,55 @@ +#pragma once + +#include <tdemainwindow.h> +#include <tqptrlist.h> + +class AlsaModel; +class AlsaDevice; +class AlsaDevicesPage; +#include "alsadevicewidget.h" +class AlsaTray; +class TQComboBox; +class TQTabWidget; +class TQHBoxLayout; +class TQWidget; + +class AlsaMixerWindow : public TDEMainWindow +{ + TQ_OBJECT +public: + explicit AlsaMixerWindow( AlsaModel *model, TQWidget *parent = 0 ); + + void setTray( AlsaTray *tray ) { m_tray = tray; } + +signals: + void settingsChanged(); + +public slots: + void bringToFront(); + void quit(); + +protected: + bool queryClose(); + void showEvent( TQShowEvent *e ); + +private slots: + void onCardChanged( int idx ); + void onDeviceAdded( AlsaDevice *dev ); + void showPreferences(); + void showAbout(); + +private: + void rebuildTabs( int cardIndex ); + + AlsaModel *m_model; + AlsaTray *m_tray; + bool m_posRestored; + TQComboBox *m_cardCombo; + TQTabWidget *m_tabs; + TQWidget *m_outputPage; + TQWidget *m_inputPage; + TQHBoxLayout *m_outputLayout; + TQHBoxLayout *m_inputLayout; + TQPtrList<AlsaDeviceWidget> m_widgets; + AlsaDevicesPage *m_devicesPage; +}; diff --git a/src/ui/alsa/alsapopup.cpp b/src/ui/alsa/alsapopup.cpp new file mode 100644 index 0000000..0a6269d --- /dev/null +++ b/src/ui/alsa/alsapopup.cpp @@ -0,0 +1,79 @@ +#include "alsapopup.h" +#include "alsadevicewidget.h" +#include "../../model/alsamodel.h" +#include "../../model/alsadevice.h" + +#include <tqlayout.h> +#include <tqlabel.h> +#include <tqapplication.h> +#include <tqdesktopwidget.h> +#include <twin.h> +#include <tdelocale.h> + +AlsaPopup::AlsaPopup( AlsaModel *model, TQWidget *parent ) + : TQWidget( parent, "AlsaPopup", + WStyle_Customize | WType_Popup | WStyle_DialogBorder ), + m_model(model), m_container(0), m_widget(0) +{ + TQVBoxLayout *outer = new TQVBoxLayout( this, 4, 0 ); + m_container = new TQWidget( this ); + outer->addWidget( m_container ); + + connect( model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(rebuild()) ); + connect( model, TQ_SIGNAL(preferredOutputChanged(AlsaDevice*)), this, TQ_SLOT(rebuild()) ); + + rebuild(); +} + +void AlsaPopup::rebuild() +{ + delete m_container->layout(); + if ( m_widget ) { delete m_widget; m_widget = 0; } + + TQVBoxLayout *vbox = new TQVBoxLayout( m_container, 4, 0 ); + AlsaDevice *dev = m_model->preferredOutput(); + if ( dev ) { + m_widget = new AlsaDeviceWidget( dev, m_container ); + vbox->addWidget( m_widget ); + m_widget->show(); + } else { + vbox->addWidget( new TQLabel( i18n("No output device."), m_container ) ); + } + + if ( isVisible() ) + adjustSize(); +} + +void AlsaPopup::toggleAt( const TQPoint &trayPos, const TQSize &traySize ) +{ + if ( isVisible() ) { hide(); return; } + + rebuild(); + adjustSize(); + + TQRect screen = TQApplication::desktop()->screenGeometry( trayPos ); + int x = trayPos.x() + traySize.width() / 2 - width() / 2; + int y = trayPos.y() - height(); + if ( y < screen.top() ) y = trayPos.y() + traySize.height(); + if ( x + width() > screen.right() ) x = screen.right() - width(); + if ( x < screen.left() ) x = screen.left(); + + move( x, y ); + show(); + + KWin::setState( winId(), NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager ); + KWin::setOnAllDesktops( winId(), true ); +} + +bool AlsaPopup::justHidden() const +{ + return m_hideTime.isValid() && m_hideTime.elapsed() < 100; +} + +void AlsaPopup::hideEvent( TQHideEvent *e ) +{ + TQWidget::hideEvent( e ); + m_hideTime.start(); +} + +#include "alsapopup.moc" diff --git a/src/ui/alsa/alsapopup.h b/src/ui/alsa/alsapopup.h new file mode 100644 index 0000000..94b1800 --- /dev/null +++ b/src/ui/alsa/alsapopup.h @@ -0,0 +1,30 @@ +#pragma once + +#include <tqwidget.h> +#include <tqdatetime.h> + +class AlsaModel; +class AlsaDevice; +class AlsaDeviceWidget; + +class AlsaPopup : public TQWidget +{ + TQ_OBJECT +public: + explicit AlsaPopup( AlsaModel *model, TQWidget *parent = 0 ); + + void toggleAt( const TQPoint &trayPos, const TQSize &traySize ); + bool justHidden() const; + +protected: + void hideEvent( TQHideEvent *e ); + +private slots: + void rebuild(); + +private: + AlsaModel *m_model; + TQWidget *m_container; + AlsaDeviceWidget *m_widget; + TQTime m_hideTime; +}; diff --git a/src/ui/alsa/alsatray.cpp b/src/ui/alsa/alsatray.cpp new file mode 100644 index 0000000..46ff59f --- /dev/null +++ b/src/ui/alsa/alsatray.cpp @@ -0,0 +1,131 @@ +#include "alsatray.h" +#include "alsapopup.h" +#include "alsamixerwindow.h" +#include "../../model/alsamodel.h" +#include "../../model/alsadevice.h" + +#include <tqevent.h> +#include <tdeglobal.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <tdelocale.h> +#include <tdeconfig.h> +#include <tdepopupmenu.h> +#include <twin.h> + +AlsaTray::AlsaTray( AlsaModel *model, AlsaMixerWindow *win, TQWidget *parent ) + : KSystemTray(parent), m_model(model), m_win(win), + m_output(model->preferredOutput()), m_popup(0) +{ + setCaption( i18n("Volume Control") ); + + connect(model, TQ_SIGNAL(deviceAdded(AlsaDevice*)), this, TQ_SLOT(updateIcon())); + connect(model, TQ_SIGNAL(preferredOutputChanged(AlsaDevice*)), this, TQ_SLOT(onPreferredChanged(AlsaDevice*))); + + if ( m_output ) { + connect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon())); + connect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon())); + } + + updateIcon(); +} + +void AlsaTray::onPreferredChanged( AlsaDevice *dev ) +{ + if ( m_output ) { + disconnect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon())); + disconnect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon())); + } + m_output = dev; + if ( m_output ) { + connect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon())); + connect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon())); + } + updateIcon(); +} + +void AlsaTray::updateIcon() +{ + if ( !m_output ) + m_output = m_model->preferredOutput(); + + int vol = m_output ? m_output->volume() : 0; + bool mute = m_output ? m_output->muted() : true; + + const char *pic; + if ( mute || vol == 0 ) pic = "audio-volume-muted.png"; + else if ( vol < 34 ) pic = "audio-volume-low.png"; + else if ( vol < 67 ) pic = "audio-volume-medium.png"; + else pic = "audio-volume-high.png"; + + TQString path = TDEGlobal::dirs()->findResource("data", + TQString("tmix/pics/crystal/") + pic); + if ( !path.isEmpty() ) + setPixmap( TQPixmap(path) ); +} + +void AlsaTray::mousePressEvent( TQMouseEvent *e ) +{ + if ( e->button() == TQt::LeftButton ) { + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int mode = cfg->readNumEntry("PopupMode", 1); + if ( mode == 1 ) { + if ( !m_popup ) + m_popup = new AlsaPopup( m_model, this ); + if ( m_popup->justHidden() ) return; + m_popup->toggleAt( mapToGlobal( TQPoint(0,0) ), size() ); + } else { + m_win->bringToFront(); + } + e->accept(); + return; + } + if ( e->button() == TQt::MidButton ) { + middleClickMute(); + e->accept(); + return; + } + KSystemTray::mousePressEvent(e); +} + +void AlsaTray::middleClickMute() +{ + if ( !m_output ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + if ( cfg->readBoolEntry("MiddleClickMute", false) ) + m_output->setMuted( !m_output->muted() ); +} + +void AlsaTray::wheelEvent( TQWheelEvent *e ) +{ + if ( !m_output ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int step = cfg->readNumEntry("ScrollStep", 5); + int delta = e->delta() > 0 ? step : -step; + int vol = m_output->volume() + delta; + if ( vol < 0 ) vol = 0; + if ( vol > 100 ) vol = 100; + m_output->setVolume(vol); +} + +void AlsaTray::contextMenuAboutToShow( TDEPopupMenu *menu ) +{ + while ( menu->count() > 1 ) + menu->removeItemAt(1); + + menu->insertItem( SmallIcon("tmix"), i18n("&Open Mixer"), + m_win, TQ_SLOT(bringToFront()) ); + menu->insertSeparator(); + menu->insertItem( SmallIcon("configure"), i18n("&Configure TMix..."), + m_win, TQ_SLOT(showPreferences()) ); + menu->insertItem( SmallIcon("help"), i18n("&About TMix"), + m_win, TQ_SLOT(showAbout()) ); + menu->insertSeparator(); + menu->insertItem( SmallIcon("application-exit"), i18n("&Quit"), + m_win, TQ_SLOT(quit()) ); +} + +#include "alsatray.moc" diff --git a/src/ui/alsa/alsatray.h b/src/ui/alsa/alsatray.h new file mode 100644 index 0000000..8f518fa --- /dev/null +++ b/src/ui/alsa/alsatray.h @@ -0,0 +1,35 @@ +#pragma once + +#include <ksystemtray.h> + +class AlsaModel; +class AlsaDevice; +class AlsaMixerWindow; +class AlsaPopup; + +class AlsaTray : public KSystemTray +{ + TQ_OBJECT +public: + AlsaTray( AlsaModel *model, AlsaMixerWindow *win, TQWidget *parent = 0 ); + +public slots: + void updateIcon(); + +protected: + void mousePressEvent( TQMouseEvent *e ); + void wheelEvent( TQWheelEvent *e ); + void contextMenuAboutToShow( TDEPopupMenu *menu ); + +private slots: + void onPreferredChanged( AlsaDevice *dev ); + +private: + void middleClickMute(); + +private: + AlsaModel *m_model; + AlsaMixerWindow *m_win; + AlsaDevice *m_output; + AlsaPopup *m_popup; +}; diff --git a/src/ui/backendcontroller.cpp b/src/ui/backendcontroller.cpp new file mode 100644 index 0000000..037c797 --- /dev/null +++ b/src/ui/backendcontroller.cpp @@ -0,0 +1,220 @@ +#include "backendcontroller.h" +#include "tmixapp.h" + +#include <tdeconfig.h> +#include <tdeglobal.h> +#include <tdeapplication.h> +#include <tqtimer.h> + +#ifdef WITH_PULSE +#include "../model/pulsemodel.h" +#include "mixerwindow.h" +#endif + +#ifdef WITH_ALSA +#include "../model/alsamodel.h" +#include "alsa/alsamixerwindow.h" +#include "alsa/alsatray.h" +#endif + +#ifdef WITH_OSS +#include "../model/ossmodel.h" +#include "oss/ossmixerwindow.h" +#include "oss/osstray.h" +#endif + +BackendController::BackendController( TQObject *parent ) + : TQObject(parent) +#ifdef WITH_PULSE + , m_pulseModel(0), m_pulseWin(0) +#endif +#ifdef WITH_ALSA + , m_alsaModel(0), m_alsaWin(0), m_alsaTray(0) +#endif +#ifdef WITH_OSS + , m_ossModel(0), m_ossWin(0), m_ossTray(0) +#endif +{} + +BackendController::~BackendController() +{ + stop(); +} + +void BackendController::start() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + m_currentBackend = cfg->readEntry("Backend", "pulse"); + +#ifdef WITH_ALSA + if ( m_currentBackend == "alsa" ) { startAlsa(); return; } +#endif +#ifdef WITH_OSS + if ( m_currentBackend == "oss" ) { startOss(); return; } +#endif +#ifdef WITH_PULSE + startPulse(); +#endif +} + +void BackendController::stop() +{ +#ifdef WITH_ALSA + if ( m_alsaTray ) { delete m_alsaTray; m_alsaTray = 0; } + if ( m_alsaWin ) { delete m_alsaWin; m_alsaWin = 0; } + if ( m_alsaModel ) { delete m_alsaModel; m_alsaModel = 0; } +#endif +#ifdef WITH_OSS + if ( m_ossTray ) { delete m_ossTray; m_ossTray = 0; } + if ( m_ossWin ) { delete m_ossWin; m_ossWin = 0; } + if ( m_ossModel ) { delete m_ossModel; m_ossModel = 0; } +#endif +#ifdef WITH_PULSE + // Model first: stops the PA mainloop thread before any widget is destroyed. + if ( m_pulseModel ) { delete m_pulseModel; m_pulseModel = 0; } + if ( m_pulseWin ) { delete m_pulseWin; m_pulseWin = 0; } +#endif +} + +#ifdef WITH_PULSE +void BackendController::startPulse( bool showWindow ) +{ + m_pulseModel = new PulseModel( this ); + if ( !m_pulseModel->open() ) { + delete m_pulseModel; + m_pulseModel = 0; + return; + } + m_pulseWin = new MixerWindow( m_pulseModel ); + connect( m_pulseWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast<TmixApp*>(kapp)->setMainWindow( m_pulseWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( !dockInTray || showWindow ) + m_pulseWin->show(); +} +#endif + +#ifdef WITH_ALSA +void BackendController::startAlsa( bool showWindow ) +{ + m_alsaModel = new AlsaModel( this ); + if ( !m_alsaModel->open() ) { + delete m_alsaModel; + m_alsaModel = 0; + return; + } + m_alsaWin = new AlsaMixerWindow( m_alsaModel ); + connect( m_alsaWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast<TmixApp*>(kapp)->setMainWindow( m_alsaWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( dockInTray ) { + m_alsaTray = new AlsaTray( m_alsaModel, m_alsaWin, m_alsaWin ); + m_alsaWin->setTray( m_alsaTray ); + m_alsaTray->show(); + } + if ( !dockInTray || showWindow ) + m_alsaWin->show(); +} +#endif + +#ifdef WITH_OSS +void BackendController::startOss( bool showWindow ) +{ + m_ossModel = new OssModel( this ); + if ( !m_ossModel->open() ) { + delete m_ossModel; + m_ossModel = 0; + return; + } + m_ossWin = new OssMixerWindow( m_ossModel ); + connect( m_ossWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast<TmixApp*>(kapp)->setMainWindow( m_ossWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( dockInTray ) { + m_ossTray = new OssTray( m_ossModel, m_ossWin, m_ossWin ); + m_ossWin->setTray( m_ossTray ); + m_ossTray->show(); + } + if ( !dockInTray || showWindow ) + m_ossWin->show(); +} +#endif + +void BackendController::onSettingsChanged() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + TQString newBackend = cfg->readEntry("Backend", "pulse"); + if ( newBackend != m_currentBackend ) + TQTimer::singleShot( 0, this, TQ_SLOT(doSwitch()) ); +} + +void BackendController::doSwitch() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + m_currentBackend = cfg->readEntry("Backend", "pulse"); + + // Remember whether the mixer window was open so we can reopen it after the switch. + bool wasVisible = false; +#ifdef WITH_PULSE + if ( m_pulseWin ) { + wasVisible = m_pulseWin->isVisible(); + if ( wasVisible ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_pulseWin->x()); + cfg->writeEntry("YPos", m_pulseWin->y()); + cfg->sync(); + } + } +#endif +#ifdef WITH_ALSA + if ( m_alsaWin ) { + wasVisible = wasVisible || m_alsaWin->isVisible(); + if ( m_alsaWin->isVisible() ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_alsaWin->x()); + cfg->writeEntry("YPos", m_alsaWin->y()); + cfg->sync(); + } + } +#endif +#ifdef WITH_OSS + if ( m_ossWin ) { + wasVisible = wasVisible || m_ossWin->isVisible(); + if ( m_ossWin->isVisible() ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_ossWin->x()); + cfg->writeEntry("YPos", m_ossWin->y()); + cfg->sync(); + } + } +#endif + + stop(); + +#ifdef WITH_ALSA + if ( m_currentBackend == "alsa" ) { startAlsa( wasVisible ); return; } +#endif +#ifdef WITH_OSS + if ( m_currentBackend == "oss" ) { startOss( wasVisible ); return; } +#endif +#ifdef WITH_PULSE + startPulse( wasVisible ); +#endif +} + +#include "backendcontroller.moc" diff --git a/src/ui/backendcontroller.h b/src/ui/backendcontroller.h new file mode 100644 index 0000000..5938fdd --- /dev/null +++ b/src/ui/backendcontroller.h @@ -0,0 +1,45 @@ +#pragma once + +#include <tqobject.h> +#include <tqstring.h> + +class TmixApp; + +class BackendController : public TQObject +{ + TQ_OBJECT +public: + explicit BackendController( TQObject *parent = 0 ); + ~BackendController(); + + void start(); + +public slots: + void onSettingsChanged(); + +private slots: + void doSwitch(); + +private: + void stop(); + void startPulse( bool showWindow = false ); + void startAlsa( bool showWindow = false ); + void startOss( bool showWindow = false ); + + TQString m_currentBackend; + +#ifdef WITH_PULSE + class PulseModel *m_pulseModel; + class MixerWindow *m_pulseWin; +#endif +#ifdef WITH_ALSA + class AlsaModel *m_alsaModel; + class AlsaMixerWindow *m_alsaWin; + class AlsaTray *m_alsaTray; +#endif +#ifdef WITH_OSS + class OssModel *m_ossModel; + class OssMixerWindow *m_ossWin; + class OssTray *m_ossTray; +#endif +}; diff --git a/src/ui/devicespage.cpp b/src/ui/devicespage.cpp index 6ae12e6..fd61acb 100644 --- a/src/ui/devicespage.cpp +++ b/src/ui/devicespage.cpp @@ -38,8 +38,8 @@ static TQPixmap availDot( bool plugged, int size ) TQBitmap mask( size, size, true ); { TQPainter mp( &mask ); - mp.setBrush( Qt::color1 ); - mp.setPen( Qt::NoPen ); + mp.setBrush(TQt::color1 ); + mp.setPen(TQt::NoPen ); mp.drawEllipse( 1, 1, size-2, size-2 ); } pm.setMask( mask ); @@ -89,7 +89,7 @@ void DevicesPage::rebuild() PulseCardInfo &info = *it; TQGroupBox *grp = new TQGroupBox( info.description, m_container ); - grp->setColumnLayout( 0, Qt::Vertical ); + grp->setColumnLayout( 0, TQt::Vertical ); grp->layout()->setSpacing( 4 ); grp->layout()->setMargin( 8 ); vbox->addWidget( grp ); diff --git a/src/ui/devicewidget.cpp b/src/ui/devicewidget.cpp index f7ac79a..645ffaa 100644 --- a/src/ui/devicewidget.cpp +++ b/src/ui/devicewidget.cpp @@ -178,7 +178,8 @@ DeviceWidget::DeviceWidget( AudioDevice *device, PulseModel *model, TQWidget *pa // Red recording-active LED — Input only, shows when a stream is capturing if ( device->category() == AudioDevice::Input ) { - m_recordingLed = new KLed( TQt::red, KLed::Off, KLed::Raised, KLed::Circular, bottomWidget ); + KLed::State initState = device->recordingActive() ? KLed::On : KLed::Off; + m_recordingLed = new KLed( TQt::red, initState, KLed::Raised, KLed::Circular, bottomWidget ); m_recordingLed->setFixedSize( 16, 16 ); TQToolTip::add( m_recordingLed, i18n("Microphone in use") ); connect( device, TQ_SIGNAL(recordingActiveChanged(bool)), @@ -291,7 +292,7 @@ void DeviceWidget::onDeviceName( const TQString &name ) void DeviceWidget::wheelEvent( TQWheelEvent *e ) { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int step = cfg->readNumEntry("ScrollStep", 5); int delta = e->delta() > 0 ? step : -step; int vol = TQMAX( 0, TQMIN( 100, m_device->volume() + delta ) ); diff --git a/src/ui/mixerwindow.cpp b/src/ui/mixerwindow.cpp index af6cc67..57dfbfc 100644 --- a/src/ui/mixerwindow.cpp +++ b/src/ui/mixerwindow.cpp @@ -4,6 +4,7 @@ #include "../model/pulsemodel.h" #include <tqlayout.h> +#include <tqlabel.h> #include <tqscrollview.h> #include <tqwidgetstack.h> #include <tqtoolbutton.h> @@ -54,7 +55,8 @@ static MixerWindow::Tab makeTab( KTabWidget *tabs, const TQString &label ) MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) : TDEMainWindow(parent), m_model(model), m_prefsDlg(0), - m_devicesBtn(0), m_devicesPage(0), m_devicesInTabs(false), m_quitting(false) + m_devicesBtn(0), m_devicesPage(0), m_devicesInTabs(false), + m_quitting(false), m_totalDevCount(0), m_waitLabel(0) { setPlainCaption( i18n("Volume Control") ); setIcon( TDEGlobal::iconLoader()->loadIcon( "kmix", TDEIcon::Desktop, 48 ) ); @@ -82,7 +84,7 @@ MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) onDefaultOutputChanged( model->defaultOutput() ); TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); if ( cfg->readBoolEntry("DockInTray", true) ) m_tray->show(); @@ -93,14 +95,23 @@ MixerWindow::MixerWindow( PulseModel *model, TQWidget *parent ) TQVBoxLayout *top = new TQVBoxLayout( central, 0, 0 ); - // Outer stack: page 0 = mixer content, page 1 = devices (no-tab mode only) + // Outer stack: page 0 = mixer, page 1 = devices (no-tab mode), page 2 = waiting m_outerStack = new TQWidgetStack( central ); top->addWidget( m_outerStack, 1 ); TQWidget *mixerPage = new TQWidget( m_outerStack ); TQVBoxLayout *mixerLayout = new TQVBoxLayout( mixerPage, 0, 0 ); m_outerStack->addWidget( mixerPage, 0 ); - m_outerStack->raiseWidget( 0 ); + + // Page 2: shown when PA is not yet connected / no devices present + TQWidget *waitPage = new TQWidget( m_outerStack ); + TQVBoxLayout *waitLayout = new TQVBoxLayout( waitPage, 0, 0 ); + m_waitLabel = new TQLabel( i18n("Waiting for PulseAudio to start..."), waitPage ); + m_waitLabel->setAlignment( TQt::AlignCenter ); + waitLayout->addWidget( m_waitLabel ); + m_outerStack->addWidget( waitPage, 2 ); + + m_outerStack->raiseWidget( 2 ); // start on waiting page; switch to 0 on first device m_stack = new TQWidgetStack( mixerPage ); mixerLayout->addWidget( m_stack ); @@ -189,7 +200,7 @@ bool MixerWindow::queryClose() if ( m_quitting || tdeApp->sessionSaving() ) return true; TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); if ( cfg->readBoolEntry("DockInTray", true) ) { saveMainWindowSettings( TDEGlobal::config(), "MainWindow" ); TDEConfig *c = TDEGlobal::config(); @@ -200,6 +211,21 @@ bool MixerWindow::queryClose() hide(); return false; } + // Not in systray — show confirm if needed, then let TDE close the window + // normally (returning true). TDE quits the app when the last main window closes. + TDEConfig *gcfg = TDEGlobal::config(); + gcfg->setGroup("General"); + if ( gcfg->readBoolEntry("ConfirmQuit", false) ) { + int r = KMessageBox::questionYesNo( + this, + i18n("Are you sure you want to quit TMix?"), + i18n("Quit TMix"), + KStdGuiItem::quit(), + KStdGuiItem::cancel() ); + if ( r != KMessageBox::Yes ) + return false; + } + m_quitting = true; return true; } @@ -249,6 +275,10 @@ static void updateSeparators( TQHBoxLayout *layout ) void MixerWindow::onDeviceAdded( AudioDevice *dev ) { + if ( m_totalDevCount == 0 ) + m_outerStack->raiseWidget( 0 ); + m_totalDevCount++; + if ( m_stack->id( m_stack->visibleWidget() ) == 1 ) { TQWidget *w = dev->createWidget( m_allStrip ); m_allLayout->insertWidget( m_allCount, w ); @@ -291,6 +321,9 @@ void MixerWindow::onDeviceRemoved( AudioDevice *dev ) delete w; updateSeparators( t.layout ); } + m_totalDevCount--; + if ( m_totalDevCount == 0 ) + m_outerStack->raiseWidget( 2 ); } @@ -380,7 +413,7 @@ void MixerWindow::applySettings() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); if ( cfg->readBoolEntry("DockInTray", true) ) m_tray->show(); else @@ -397,6 +430,7 @@ void MixerWindow::applySettings() m_tabs->setTabEnabled( m_playback.scroll, cfg->readBoolEntry("ShowPlayback", true) ); m_tabs->setTabEnabled( m_recording.scroll, cfg->readBoolEntry("ShowRecording", true) ); } + emit settingsChanged(); } void MixerWindow::toggleDevices() diff --git a/src/ui/mixerwindow.h b/src/ui/mixerwindow.h index 8dc740d..893f903 100644 --- a/src/ui/mixerwindow.h +++ b/src/ui/mixerwindow.h @@ -12,6 +12,7 @@ class TQWidgetStack; class TQToolButton; class DevicesPage; class TQResizeEvent; +class TQLabel; class MixerWindow : public TDEMainWindow { @@ -34,6 +35,9 @@ protected: void showEvent( TQShowEvent *e ); void hideEvent( TQHideEvent *e ); +signals: + void settingsChanged(); + public slots: void bringToFront(); @@ -66,8 +70,10 @@ private: class TmixTray *m_tray; TQToolButton *m_devicesBtn; DevicesPage *m_devicesPage; - bool m_devicesInTabs; // true = DevicesPage is a tab in m_tabs + bool m_devicesInTabs; bool m_quitting; + int m_totalDevCount; + TQLabel *m_waitLabel; Tab m_output; Tab m_input; diff --git a/src/ui/oss/ossdevicewidget.cpp b/src/ui/oss/ossdevicewidget.cpp new file mode 100644 index 0000000..03fd91b --- /dev/null +++ b/src/ui/oss/ossdevicewidget.cpp @@ -0,0 +1,154 @@ +#include "ossdevicewidget.h" +#include "../../model/ossdevice.h" +#include "../balanceknob.h" +#include "../kledbutton.h" + +#include <tqlayout.h> +#include <tqslider.h> +#include <tqlabel.h> +#include <tqpixmap.h> +#include <tqpainter.h> +#include <tdeglobal.h> +#include <kstandarddirs.h> + +class VerticalLabel : public TQWidget +{ +public: + VerticalLabel( const TQString &text, TQWidget *parent ) + : TQWidget(parent), m_text(text) { setMinimumSize(20, 10); } + TQSize sizeHint() const { return TQSize(20, 100); } + TQSizePolicy sizePolicy() const { + return TQSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Expanding); + } +protected: + void paintEvent( TQPaintEvent * ) { + TQPainter p(this); + TQFontMetrics fm = p.fontMetrics(); + int available = height() - 6; + TQString text = m_text; + if ( fm.width(text) > available ) { + while ( text.length() > 1 && fm.width(text) + fm.width("...") > available ) + text.truncate(text.length() - 1); + text += "..."; + } + p.rotate(270); + p.translate(0, -4); + p.drawText(-height() + 2, width(), text); + } +private: + TQString m_text; +}; + +static TQPixmap ossPic( const char *name ) +{ + TQString path = TDEGlobal::dirs()->findResource("data", + TQString("tmix/pics/") + name); + return path.isEmpty() ? TQPixmap() : TQPixmap(path); +} + +static TQPixmap iconForDevice( OssDevice *dev ) +{ + TQString n = dev->name().lower(); + if ( n == "vol" || n.contains("master") ) + return ossPic("crystal/audio-volume-medium.png"); + if ( n.contains("headphone") || n.contains("headset") ) + return ossPic("mix_headphone.png"); + if ( n.contains("mic") ) + return ossPic("mix_microphone.png"); + if ( n.contains("line") ) + return ossPic("mix_ext.png"); + if ( n.contains("cd") ) + return ossPic("mix_cd.png"); + if ( n.contains("dig") || n.contains("spdif") || n.contains("iec") ) + return ossPic("mix_digital.png"); + if ( n.contains("pcm") || n.contains("wave") ) + return ossPic("mix_audio.png"); + if ( dev->category() == OssDevice::Input ) + return ossPic("mix_microphone.png"); + return ossPic("crystal/audio-volume-medium.png"); +} + +OssDeviceWidget::OssDeviceWidget( OssDevice *dev, TQWidget *parent ) + : TQWidget(parent), m_dev(dev), m_balance(0) +{ + TQHBoxLayout *outer = new TQHBoxLayout(this, 4, 0); + outer->addStretch(1); + + TQVBoxLayout *col = new TQVBoxLayout(0, 0, 2); + + TQHBoxLayout *topRow = new TQHBoxLayout(0, 0, 2); + TQLabel *icon = new TQLabel(this); + TQPixmap px = iconForDevice(dev); + if ( !px.isNull() ) icon->setPixmap(px); + topRow->addWidget(icon, 0, TQt::AlignVCenter); + m_volLabel = new TQLabel(TQString("%1%").arg(dev->volume()), this); + topRow->addWidget(m_volLabel, 0, TQt::AlignVCenter); + col->addLayout(topRow); + + TQHBoxLayout *sliderRow = new TQHBoxLayout(0, 0, 2); + VerticalLabel *vlabel = new VerticalLabel(dev->name(), this); + sliderRow->addWidget(vlabel); + m_slider = new TQSlider(0, 100, 5, 100 - dev->volume(), TQt::Vertical, this); + m_slider->setTickmarks(TQSlider::Right); + m_slider->setTickInterval(5); + m_slider->setMinimumHeight(80); + sliderRow->addWidget(m_slider, 1); + col->addLayout(sliderRow, 1); + + TQWidget *bottom = new TQWidget(this); + bottom->setFixedHeight(30); + TQHBoxLayout *bottomRow = new TQHBoxLayout(bottom, 0, 2); + bottomRow->addStretch(1); + if ( dev->stereo() ) { + m_balance = new BalanceKnob(-50, 50, dev->pan(), bottom); + bottomRow->addWidget(m_balance, 0, TQt::AlignVCenter); + bottomRow->addStretch(1); + connect(m_balance, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(onPanMoved(int))); + } + m_muteBtn = new KLedButton(TQt::green, + dev->muted() ? KLed::Off : KLed::On, + KLed::Raised, KLed::Circular, bottom); + m_muteBtn->setFixedSize(16, 16); + bottomRow->addWidget(m_muteBtn, 0, TQt::AlignVCenter); + bottomRow->addStretch(1); + col->addWidget(bottom, 0); + + outer->addLayout(col); + outer->addStretch(1); + + connect(dev, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(onVolumeChanged(int))); + connect(dev, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(onMuteChanged(bool))); + connect(dev, TQ_SIGNAL(panChanged(int)), this, TQ_SLOT(onPanChanged(int))); + connect(m_slider, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(onSliderMoved(int))); + connect(m_muteBtn, TQ_SIGNAL(stateChanged(bool)), this, TQ_SLOT(onMuteToggled(bool))); +} + +void OssDeviceWidget::onVolumeChanged( int v ) +{ + m_slider->blockSignals(true); + m_slider->setValue(100 - v); + m_slider->blockSignals(false); + m_volLabel->setText(TQString("%1%").arg(v)); +} + +void OssDeviceWidget::onMuteChanged( bool m ) +{ + m_muteBtn->blockSignals(true); + m_muteBtn->setState(m ? KLed::Off : KLed::On); + m_muteBtn->blockSignals(false); +} + +void OssDeviceWidget::onPanChanged( int p ) +{ + if ( m_balance ) { + m_balance->blockSignals(true); + m_balance->setValue(p); + m_balance->blockSignals(false); + } +} + +void OssDeviceWidget::onSliderMoved( int v ) { m_dev->setVolume(100 - v); } +void OssDeviceWidget::onMuteToggled( bool on ) { m_dev->setMuted(!on); } +void OssDeviceWidget::onPanMoved( int p ) { m_dev->setPan(p); } + +#include "ossdevicewidget.moc" diff --git a/src/ui/oss/ossdevicewidget.h b/src/ui/oss/ossdevicewidget.h new file mode 100644 index 0000000..8a136cf --- /dev/null +++ b/src/ui/oss/ossdevicewidget.h @@ -0,0 +1,31 @@ +#pragma once + +#include <tqwidget.h> + +class OssDevice; +class TQSlider; +class TQLabel; +class KLedButton; +class BalanceKnob; + +class OssDeviceWidget : public TQWidget +{ + TQ_OBJECT +public: + OssDeviceWidget( OssDevice *dev, TQWidget *parent = 0 ); + +private slots: + void onVolumeChanged( int v ); + void onMuteChanged( bool m ); + void onPanChanged( int p ); + void onSliderMoved( int v ); + void onMuteToggled( bool on ); + void onPanMoved( int p ); + +private: + OssDevice *m_dev; + TQSlider *m_slider; + TQLabel *m_volLabel; + KLedButton *m_muteBtn; + BalanceKnob *m_balance; +}; diff --git a/src/ui/oss/ossmixerwindow.cpp b/src/ui/oss/ossmixerwindow.cpp new file mode 100644 index 0000000..04c2fc6 --- /dev/null +++ b/src/ui/oss/ossmixerwindow.cpp @@ -0,0 +1,192 @@ +#include "ossmixerwindow.h" +#include "ossdevicewidget.h" +#include "osstray.h" +#include "../preferencesdlg.h" +#include "../../model/ossmodel.h" +#include "../../model/ossdevice.h" + +#include <tqlayout.h> +#include <tqcombobox.h> +#include <tqtabwidget.h> +#include <tqlabel.h> +#include <tdeapplication.h> +#include <tdelocale.h> +#include <tdemenubar.h> +#include <tdepopupmenu.h> +#include <tdeaboutapplication.h> +#include <tdeaboutdata.h> +#include <kiconloader.h> +#include <tdeconfig.h> +#include <tdeglobal.h> +#include <twin.h> + +OssMixerWindow::OssMixerWindow( OssModel *model, TQWidget *parent ) + : TDEMainWindow(parent, "OssMixerWindow"), + m_model(model), m_tray(0), m_posRestored(false) +{ + m_widgets.setAutoDelete(true); + setCaption(i18n("Volume Control")); + + TQWidget *central = new TQWidget(this); + setCentralWidget(central); + TQVBoxLayout *vbox = new TQVBoxLayout(central, 8, 6); + + TQHBoxLayout *topRow = new TQHBoxLayout(0, 0, 6); + topRow->addStretch(); + topRow->addWidget(new TQLabel(i18n("Card:"), central)); + m_cardCombo = new TQComboBox(false, central); + TQValueList<OssCard> cards = model->cards(); + for ( TQValueListConstIterator<OssCard> it = cards.begin(); it != cards.end(); ++it ) + m_cardCombo->insertItem((*it).name); + topRow->addWidget(m_cardCombo); + vbox->addLayout(topRow); + + m_tabs = new TQTabWidget(central); + + m_outputPage = new TQWidget(m_tabs); + m_outputLayout = new TQHBoxLayout(m_outputPage, 8, 6); + m_tabs->addTab(m_outputPage, i18n("Output")); + + m_inputPage = new TQWidget(m_tabs); + m_inputLayout = new TQHBoxLayout(m_inputPage, 8, 6); + m_tabs->addTab(m_inputPage, i18n("Input")); + + vbox->addWidget(m_tabs, 1); + + if ( !cards.isEmpty() ) + rebuildTabs(cards.front().index); + + setMinimumSize(400, 250); + + TDEConfig *gcfg = TDEGlobal::config(); + gcfg->setGroup("OssMainWindow"); + if ( gcfg->hasKey("Width") ) + applyMainWindowSettings(gcfg, "OssMainWindow"); + else + resize(550, 320); + + connect(m_cardCombo, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onCardChanged(int))); + connect(model, TQ_SIGNAL(deviceAdded(OssDevice*)), this, TQ_SLOT(onDeviceAdded(OssDevice*))); + + TDEPopupMenu *fileMenu = new TDEPopupMenu(this); + fileMenu->insertItem(SmallIcon("application-exit"), i18n("&Quit"), + this, TQ_SLOT(quit())); + + TDEPopupMenu *settingsMenu = new TDEPopupMenu(this); + settingsMenu->insertItem(SmallIcon("configure"), i18n("&Configure..."), + this, TQ_SLOT(showPreferences())); + + TDEPopupMenu *helpMenu = new TDEPopupMenu(this); + helpMenu->insertItem(SmallIcon("help"), i18n("&About TMix"), + this, TQ_SLOT(showAbout())); + + menuBar()->insertItem(i18n("&File"), fileMenu); + menuBar()->insertItem(i18n("&Settings"), settingsMenu); + menuBar()->insertItem(i18n("&Help"), helpMenu); +} + +void OssMixerWindow::rebuildTabs( int cardIdx ) +{ + m_widgets.clear(); + + delete m_outputPage->layout(); + m_outputLayout = new TQHBoxLayout(m_outputPage, 8, 6); + + delete m_inputPage->layout(); + m_inputLayout = new TQHBoxLayout(m_inputPage, 8, 6); + + TQPtrList<OssDevice> devs = m_model->devicesForCard(cardIdx); + bool hasOutput = false, hasInput = false; + for ( TQPtrListIterator<OssDevice> it(devs); *it; ++it ) { + OssDevice *dev = *it; + OssDeviceWidget *w = new OssDeviceWidget(dev, + dev->category() == OssDevice::Output ? m_outputPage : m_inputPage); + if ( dev->category() == OssDevice::Output ) { + m_outputLayout->addWidget(w); + hasOutput = true; + } else { + m_inputLayout->addWidget(w); + hasInput = true; + } + w->show(); + m_widgets.append(w); + } + + if ( !hasOutput ) m_outputLayout->addWidget(new TQLabel(i18n("No output controls."), m_outputPage)); + if ( !hasInput ) m_inputLayout->addWidget( new TQLabel(i18n("No input controls."), m_inputPage)); + + m_outputLayout->addStretch(); + m_inputLayout->addStretch(); +} + +void OssMixerWindow::onCardChanged( int idx ) +{ + TQValueList<OssCard> cards = m_model->cards(); + if ( idx < 0 || idx >= (int)cards.count() ) return; + TQValueListConstIterator<OssCard> it = cards.begin(); + for ( int i = 0; i < idx; ++i ) ++it; + rebuildTabs((*it).index); +} + +void OssMixerWindow::onDeviceAdded( OssDevice * ) +{ + m_cardCombo->clear(); + TQValueList<OssCard> cards = m_model->cards(); + for ( TQValueListConstIterator<OssCard> it = cards.begin(); it != cards.end(); ++it ) + m_cardCombo->insertItem((*it).name); + onCardChanged(m_cardCombo->currentItem()); +} + +void OssMixerWindow::bringToFront() +{ + show(); + KWin::forceActiveWindow(winId()); +} + +void OssMixerWindow::showEvent( TQShowEvent *e ) +{ + TDEMainWindow::showEvent(e); + if ( !m_posRestored ) { + m_posRestored = true; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssMainWindow"); + int xp = cfg->readNumEntry("XPos", -1); + int yp = cfg->readNumEntry("YPos", -1); + if ( xp >= 0 && yp >= 0 ) move(xp, yp); + } +} + +bool OssMixerWindow::queryClose() +{ + saveMainWindowSettings(TDEGlobal::config(), "OssMainWindow"); + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssMainWindow"); + cfg->writeEntry("XPos", x()); + cfg->writeEntry("YPos", y()); + cfg->sync(); + + if ( m_tray ) { hide(); return false; } + quit(); + return false; +} + +void OssMixerWindow::quit() +{ + m_tray = 0; + kapp->quit(); +} + +void OssMixerWindow::showPreferences() +{ + PreferencesDlg dlg(m_model, this); + dlg.exec(); + emit settingsChanged(); +} + +void OssMixerWindow::showAbout() +{ + TDEAboutApplication dlg(this); + dlg.exec(); +} + +#include "ossmixerwindow.moc" diff --git a/src/ui/oss/ossmixerwindow.h b/src/ui/oss/ossmixerwindow.h new file mode 100644 index 0000000..220c0cd --- /dev/null +++ b/src/ui/oss/ossmixerwindow.h @@ -0,0 +1,53 @@ +#pragma once + +#include <tdemainwindow.h> +#include <tqptrlist.h> +#include "ossdevicewidget.h" + +class OssModel; +class OssDevice; +class OssTray; +class TQComboBox; +class TQTabWidget; +class TQHBoxLayout; +class TQWidget; + +class OssMixerWindow : public TDEMainWindow +{ + TQ_OBJECT +public: + explicit OssMixerWindow( OssModel *model, TQWidget *parent = 0 ); + + void setTray( OssTray *tray ) { m_tray = tray; } + +signals: + void settingsChanged(); + +public slots: + void bringToFront(); + void quit(); + void showPreferences(); + void showAbout(); + +protected: + bool queryClose(); + void showEvent( TQShowEvent *e ); + +private slots: + void onCardChanged( int idx ); + void onDeviceAdded( OssDevice *dev ); + +private: + void rebuildTabs( int cardIdx ); + + OssModel *m_model; + OssTray *m_tray; + bool m_posRestored; + TQComboBox *m_cardCombo; + TQTabWidget *m_tabs; + TQWidget *m_outputPage; + TQWidget *m_inputPage; + TQHBoxLayout *m_outputLayout; + TQHBoxLayout *m_inputLayout; + TQPtrList<OssDeviceWidget> m_widgets; +}; diff --git a/src/ui/oss/osspopup.cpp b/src/ui/oss/osspopup.cpp new file mode 100644 index 0000000..39279b5 --- /dev/null +++ b/src/ui/oss/osspopup.cpp @@ -0,0 +1,78 @@ +#include "osspopup.h" +#include "ossdevicewidget.h" +#include "../../model/ossmodel.h" +#include "../../model/ossdevice.h" + +#include <tqlayout.h> +#include <tqlabel.h> +#include <tqapplication.h> +#include <tqdesktopwidget.h> +#include <twin.h> +#include <tdelocale.h> + +OssPopup::OssPopup( OssModel *model, TQWidget *parent ) + : TQWidget( parent, "OssPopup", + WStyle_Customize | WType_Popup | WStyle_DialogBorder ), + m_model(model), m_container(0), m_widget(0) +{ + TQVBoxLayout *outer = new TQVBoxLayout(this, 4, 0); + m_container = new TQWidget(this); + outer->addWidget(m_container); + + connect(model, TQ_SIGNAL(deviceAdded(OssDevice*)), this, TQ_SLOT(rebuild())); + connect(model, TQ_SIGNAL(preferredOutputChanged(OssDevice*)), this, TQ_SLOT(rebuild())); + + rebuild(); +} + +void OssPopup::rebuild() +{ + delete m_container->layout(); + if ( m_widget ) { delete m_widget; m_widget = 0; } + + TQVBoxLayout *vbox = new TQVBoxLayout(m_container, 4, 0); + OssDevice *dev = m_model->preferredOutput(); + if ( dev ) { + m_widget = new OssDeviceWidget(dev, m_container); + vbox->addWidget(m_widget); + m_widget->show(); + } else { + vbox->addWidget(new TQLabel(i18n("No output device."), m_container)); + } + + if ( isVisible() ) adjustSize(); +} + +void OssPopup::toggleAt( const TQPoint &trayPos, const TQSize &traySize ) +{ + if ( isVisible() ) { hide(); return; } + + rebuild(); + adjustSize(); + + TQRect screen = TQApplication::desktop()->screenGeometry(trayPos); + int x = trayPos.x() + traySize.width() / 2 - width() / 2; + int y = trayPos.y() - height(); + if ( y < screen.top() ) y = trayPos.y() + traySize.height(); + if ( x + width() > screen.right() ) x = screen.right() - width(); + if ( x < screen.left() ) x = screen.left(); + + move(x, y); + show(); + + KWin::setState(winId(), NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager); + KWin::setOnAllDesktops(winId(), true); +} + +bool OssPopup::justHidden() const +{ + return m_hideTime.isValid() && m_hideTime.elapsed() < 100; +} + +void OssPopup::hideEvent( TQHideEvent *e ) +{ + TQWidget::hideEvent(e); + m_hideTime.start(); +} + +#include "osspopup.moc" diff --git a/src/ui/oss/osspopup.h b/src/ui/oss/osspopup.h new file mode 100644 index 0000000..1a2c80e --- /dev/null +++ b/src/ui/oss/osspopup.h @@ -0,0 +1,30 @@ +#pragma once + +#include <tqwidget.h> +#include <tqdatetime.h> + +class OssModel; +class OssDevice; +class OssDeviceWidget; + +class OssPopup : public TQWidget +{ + TQ_OBJECT +public: + explicit OssPopup( OssModel *model, TQWidget *parent = 0 ); + + void toggleAt( const TQPoint &trayPos, const TQSize &traySize ); + bool justHidden() const; + +protected: + void hideEvent( TQHideEvent *e ); + +private slots: + void rebuild(); + +private: + OssModel *m_model; + TQWidget *m_container; + OssDeviceWidget *m_widget; + TQTime m_hideTime; +}; diff --git a/src/ui/oss/osstray.cpp b/src/ui/oss/osstray.cpp new file mode 100644 index 0000000..dfa63d0 --- /dev/null +++ b/src/ui/oss/osstray.cpp @@ -0,0 +1,129 @@ +#include "osstray.h" +#include "osspopup.h" +#include "ossmixerwindow.h" +#include "../../model/ossmodel.h" +#include "../../model/ossdevice.h" + +#include <tqevent.h> +#include <tdeglobal.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <tdelocale.h> +#include <tdeconfig.h> +#include <tdepopupmenu.h> +#include <twin.h> + +OssTray::OssTray( OssModel *model, OssMixerWindow *win, TQWidget *parent ) + : KSystemTray(parent), m_model(model), m_win(win), + m_output(model->preferredOutput()), m_popup(0) +{ + setCaption(i18n("Volume Control")); + + connect(model, TQ_SIGNAL(deviceAdded(OssDevice*)), this, TQ_SLOT(updateIcon())); + connect(model, TQ_SIGNAL(preferredOutputChanged(OssDevice*)), this, TQ_SLOT(onPreferredChanged(OssDevice*))); + + if ( m_output ) { + connect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon())); + connect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon())); + } + + updateIcon(); +} + +void OssTray::onPreferredChanged( OssDevice *dev ) +{ + if ( m_output ) { + disconnect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon())); + disconnect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon())); + } + m_output = dev; + if ( m_output ) { + connect(m_output, TQ_SIGNAL(volumeChanged(int)), this, TQ_SLOT(updateIcon())); + connect(m_output, TQ_SIGNAL(muteChanged(bool)), this, TQ_SLOT(updateIcon())); + } + updateIcon(); +} + +void OssTray::updateIcon() +{ + if ( !m_output ) m_output = m_model->preferredOutput(); + + int vol = m_output ? m_output->volume() : 0; + bool mute = m_output ? m_output->muted() : true; + + const char *pic; + if ( mute || vol == 0 ) pic = "audio-volume-muted.png"; + else if ( vol < 34 ) pic = "audio-volume-low.png"; + else if ( vol < 67 ) pic = "audio-volume-medium.png"; + else pic = "audio-volume-high.png"; + + TQString path = TDEGlobal::dirs()->findResource("data", + TQString("tmix/pics/crystal/") + pic); + if ( !path.isEmpty() ) setPixmap(TQPixmap(path)); +} + +void OssTray::mousePressEvent( TQMouseEvent *e ) +{ + if ( e->button() == TQt::LeftButton ) { + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int mode = cfg->readNumEntry("PopupMode", 1); + if ( mode == 1 ) { + if ( !m_popup ) + m_popup = new OssPopup(m_model, this); + if ( m_popup->justHidden() ) return; + m_popup->toggleAt(mapToGlobal(TQPoint(0,0)), size()); + } else { + m_win->bringToFront(); + } + e->accept(); + return; + } + if ( e->button() == TQt::MidButton ) { + middleClickMute(); + e->accept(); + return; + } + KSystemTray::mousePressEvent(e); +} + +void OssTray::middleClickMute() +{ + if ( !m_output ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + if ( cfg->readBoolEntry("MiddleClickMute", false) ) + m_output->setMuted( !m_output->muted() ); +} + +void OssTray::wheelEvent( TQWheelEvent *e ) +{ + if ( !m_output ) return; + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + int step = cfg->readNumEntry("ScrollStep", 5); + int delta = e->delta() > 0 ? step : -step; + int vol = m_output->volume() + delta; + if ( vol < 0 ) vol = 0; + if ( vol > 100 ) vol = 100; + m_output->setVolume(vol); +} + +void OssTray::contextMenuAboutToShow( TDEPopupMenu *menu ) +{ + while ( menu->count() > 1 ) + menu->removeItemAt(1); + + menu->insertItem(SmallIcon("tmix"), i18n("&Open Mixer"), + m_win, TQ_SLOT(bringToFront())); + menu->insertSeparator(); + menu->insertItem(SmallIcon("configure"), i18n("&Configure TMix..."), + m_win, TQ_SLOT(showPreferences())); + menu->insertItem(SmallIcon("help"), i18n("&About TMix"), + m_win, TQ_SLOT(showAbout())); + menu->insertSeparator(); + menu->insertItem(SmallIcon("application-exit"), i18n("&Quit"), + m_win, TQ_SLOT(quit())); +} + +#include "osstray.moc" diff --git a/src/ui/oss/osstray.h b/src/ui/oss/osstray.h new file mode 100644 index 0000000..dda1c76 --- /dev/null +++ b/src/ui/oss/osstray.h @@ -0,0 +1,34 @@ +#pragma once + +#include <ksystemtray.h> + +class OssModel; +class OssDevice; +class OssMixerWindow; +class OssPopup; + +class OssTray : public KSystemTray +{ + TQ_OBJECT +public: + OssTray( OssModel *model, OssMixerWindow *win, TQWidget *parent = 0 ); + +public slots: + void updateIcon(); + +protected: + void mousePressEvent( TQMouseEvent *e ); + void wheelEvent( TQWheelEvent *e ); + void contextMenuAboutToShow( TDEPopupMenu *menu ); + +private slots: + void onPreferredChanged( OssDevice *dev ); + +private: + void middleClickMute(); + + OssModel *m_model; + OssMixerWindow *m_win; + OssDevice *m_output; + OssPopup *m_popup; +}; diff --git a/src/ui/preferencesdlg.cpp b/src/ui/preferencesdlg.cpp index b263850..1167f97 100644 --- a/src/ui/preferencesdlg.cpp +++ b/src/ui/preferencesdlg.cpp @@ -7,112 +7,366 @@ #include <tqlabel.h> #include <tqframe.h> #include <tqgroupbox.h> +#include <tqwidgetstack.h> +#include <tqfile.h> +#include <tqtextstream.h> +#include <tqdir.h> +#include <cstdlib> #include <tdeglobal.h> #include <tdeconfig.h> #include <tdelocale.h> +static TQString autostartPath() +{ + TQString tdehome = TQString::fromLocal8Bit( ::getenv("TDEHOME") ); + if ( tdehome.isEmpty() ) + tdehome = TQDir::homeDirPath() + "/.trinity"; + return tdehome + "/Autostart/tmix.desktop"; +} + +#ifdef WITH_ALSA +#include "../model/alsamodel.h" +#include "../model/alsadevice.h" +#endif + +#ifdef WITH_OSS +#include "../model/ossmodel.h" +#include "../model/ossdevice.h" +#endif + +#define PREFS_INIT_LIST \ + m_backend(0), m_dockInTray(0), m_popupMode(0), \ + m_scrollStep(0), m_confirmQuit(0), m_middleClickMute(0), \ + m_startOnLogin(0), m_backendStack(0), \ + m_popupShowOutput(0), m_popupShowMic(0), m_popupShowApps(0), \ + m_showRecTray(0), \ + m_noTabs(0), m_showTabsLabel(0), m_showOutput(0), m_showInput(0), \ + m_showPlayback(0), m_showRecording(0) + +// ── Pulse constructor ───────────────────────────────────────────────────────── + PreferencesDlg::PreferencesDlg( TQWidget *parent ) : KDialogBase( Tabbed, i18n("Configure TMix"), - Ok | Apply | Cancel, Ok, parent, 0, false ) + Ok | Apply | Cancel, Ok, parent, 0, false ), + PREFS_INIT_LIST +#ifdef WITH_ALSA + , m_alsaModel(0), m_trayDevice(0) +#endif +#ifdef WITH_OSS + , m_ossModel(0), m_ossTrayDevice(0) +#endif +{ + buildGeneralPage(); + buildBackendPage(); + load(); +} + +#ifdef WITH_ALSA + +// ── ALSA constructor ────────────────────────────────────────────────────────── + +PreferencesDlg::PreferencesDlg( AlsaModel *model, TQWidget *parent ) + : KDialogBase( Tabbed, i18n("Configure TMix"), + Ok | Apply | Cancel, Ok, parent, 0, false ), + PREFS_INIT_LIST, + m_alsaModel(model), m_trayDevice(0) +#ifdef WITH_OSS + , m_ossModel(0), m_ossTrayDevice(0) +#endif +{ + buildGeneralPage(); + buildBackendPage(); + load(); +} + +#endif + +#ifdef WITH_OSS + +// ── OSS constructor ─────────────────────────────────────────────────────────── + +PreferencesDlg::PreferencesDlg( OssModel *model, TQWidget *parent ) + : KDialogBase( Tabbed, i18n("Configure TMix"), + Ok | Apply | Cancel, Ok, parent, 0, false ), + PREFS_INIT_LIST +#ifdef WITH_ALSA + , m_alsaModel(0), m_trayDevice(0) +#endif + , m_ossModel(model), m_ossTrayDevice(0) +{ + buildGeneralPage(); + buildBackendPage(); + load(); +} + +#endif + +// ── General page ────────────────────────────────────────────────────────────── + +void PreferencesDlg::buildGeneralPage() { - // ---- General ------------------------------------------------------------- TQFrame *gen = addPage( i18n("General") ); TQVBoxLayout *gl = new TQVBoxLayout( gen, marginHint(), spacingHint() ); - m_dockInTray = new TQCheckBox( i18n("Dock in system tray"), gen ); - gl->addWidget( m_dockInTray ); + TQHBoxLayout *backendRow = new TQHBoxLayout( 0, 0, spacingHint() ); + backendRow->addWidget( new TQLabel( i18n("Audio backend:"), gen ) ); + m_backend = new TQComboBox( false, gen ); +#ifdef WITH_PULSE + m_backend->insertItem( i18n("PulseAudio") ); + m_backendIds << "pulse"; +#endif +#ifdef WITH_ALSA + m_backend->insertItem( i18n("ALSA") ); + m_backendIds << "alsa"; +#endif +#ifdef WITH_OSS + m_backend->insertItem( i18n("OSS") ); + m_backendIds << "oss"; +#endif + backendRow->addWidget( m_backend ); + backendRow->addStretch(); + gl->addLayout( backendRow ); - gl->addSpacing( 4 ); + gl->addSpacing( 8 ); + + TQGroupBox *trayCard = new TQGroupBox( i18n("System Tray"), gen ); + trayCard->setColumnLayout( 0, TQt::Vertical ); + trayCard->layout()->setSpacing( spacingHint() ); + trayCard->layout()->setMargin( marginHint() ); + TQVBoxLayout *tl = new TQVBoxLayout( trayCard->layout() ); + + m_dockInTray = new TQCheckBox( i18n("Dock in system tray"), trayCard ); + tl->addWidget( m_dockInTray ); TQHBoxLayout *popupRow = new TQHBoxLayout( 0, 0, spacingHint() ); - popupRow->addWidget( new TQLabel( i18n("Tray left-click:"), gen ) ); - m_popupMode = new TQComboBox( false, gen ); + popupRow->addWidget( new TQLabel( i18n("Left-click:"), trayCard ) ); + m_popupMode = new TQComboBox( false, trayCard ); m_popupMode->insertItem( i18n("Show mixer window") ); m_popupMode->insertItem( i18n("Show mini popup") ); popupRow->addWidget( m_popupMode ); popupRow->addStretch(); - gl->addLayout( popupRow ); - - TQGroupBox *popupContent = new TQGroupBox( i18n("Mini popup shows:"), gen ); - popupContent->setColumnLayout( 0, Qt::Vertical ); - popupContent->layout()->setSpacing( spacingHint() ); - popupContent->layout()->setMargin( marginHint() ); - TQVBoxLayout *pcl = new TQVBoxLayout( popupContent->layout() ); - m_popupShowOutput = new TQCheckBox( i18n("Default output (speakers/headphones)"), popupContent ); - m_popupShowMic = new TQCheckBox( i18n("Microphone inputs"), popupContent ); - m_popupShowApps = new TQCheckBox( i18n("Active app streams"), popupContent ); - pcl->addWidget( m_popupShowOutput ); - pcl->addWidget( m_popupShowMic ); - pcl->addWidget( m_popupShowApps ); - gl->addWidget( popupContent ); + tl->addLayout( popupRow ); connect( m_popupMode, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onPopupModeChanged(int)) ); - gl->addSpacing( 4 ); - - m_showRecTray = new TQCheckBox( i18n("Show microphone-in-use icon in tray"), gen ); - gl->addWidget( m_showRecTray ); - - m_confirmQuit = new TQCheckBox( i18n("Ask for confirmation before quitting"), gen ); - gl->addWidget( m_confirmQuit ); - - gl->addSpacing( 8 ); + m_middleClickMute = new TQCheckBox( i18n("Middle-click mutes/unmutes"), trayCard ); + tl->addWidget( m_middleClickMute ); TQHBoxLayout *stepRow = new TQHBoxLayout( 0, 0, spacingHint() ); - stepRow->addWidget( new TQLabel( i18n("Scroll wheel volume step:"), gen ) ); - m_scrollStep = new TQSpinBox( 1, 20, 1, gen ); + stepRow->addWidget( new TQLabel( i18n("Scroll wheel step:"), trayCard ) ); + m_scrollStep = new TQSpinBox( 1, 20, 1, trayCard ); m_scrollStep->setSuffix( i18n(" %") ); stepRow->addWidget( m_scrollStep ); stepRow->addStretch(); - gl->addLayout( stepRow ); + tl->addLayout( stepRow ); + + gl->addWidget( trayCard ); + + gl->addSpacing( 4 ); + + TQGroupBox *startupCard = new TQGroupBox( i18n("Startup / Exit"), gen ); + startupCard->setColumnLayout( 0, TQt::Vertical ); + startupCard->layout()->setSpacing( spacingHint() ); + startupCard->layout()->setMargin( marginHint() ); + TQVBoxLayout *sl = new TQVBoxLayout( startupCard->layout() ); + m_startOnLogin = new TQCheckBox( i18n("Start TMix when Trinity starts"), startupCard ); + sl->addWidget( m_startOnLogin ); + m_confirmQuit = new TQCheckBox( i18n("Ask for confirmation before quitting"), startupCard ); + sl->addWidget( m_confirmQuit ); + gl->addWidget( startupCard ); gl->addStretch(); +} - // ---- View ---------------------------------------------------------------- - TQFrame *view = addPage( i18n("View") ); - TQVBoxLayout *vl = new TQVBoxLayout( view, marginHint(), spacingHint() ); - - m_noTabs = new TQCheckBox( i18n("Show all devices in one view (no tabs)"), view ); - vl->addWidget( m_noTabs ); - - vl->addSpacing( 8 ); - vl->addWidget( new TQLabel( i18n("Show tabs:"), view ) ); - m_showOutput = new TQCheckBox( i18n("Output"), view ); - m_showInput = new TQCheckBox( i18n("Input"), view ); - m_showPlayback = new TQCheckBox( i18n("Playback"), view ); - m_showRecording = new TQCheckBox( i18n("Recording"), view ); - vl->addWidget( m_showOutput ); - vl->addWidget( m_showInput ); - vl->addWidget( m_showPlayback ); - vl->addWidget( m_showRecording ); - vl->addStretch(); +// ── Backend settings page (stacked Pulse / ALSA) ────────────────────────────── - load(); +void PreferencesDlg::buildBackendPage() +{ + TQFrame *page = addPage( i18n("Audio Settings") ); + TQVBoxLayout *vl = new TQVBoxLayout( page, marginHint(), spacingHint() ); + + m_backendStack = new TQWidgetStack( page ); + vl->addWidget( m_backendStack ); + + // ── Pulse page (stack index 0) ──────────────────────────────────────────── + TQWidget *pulseWidget = new TQWidget( m_backendStack ); + TQVBoxLayout *pl = new TQVBoxLayout( pulseWidget, 0, spacingHint() ); + + TQGroupBox *popupBox = new TQGroupBox( i18n("Mini popup shows:"), pulseWidget ); + popupBox->setColumnLayout( 0, TQt::Vertical ); + popupBox->layout()->setSpacing( spacingHint() ); + popupBox->layout()->setMargin( marginHint() ); + TQVBoxLayout *pcl = new TQVBoxLayout( popupBox->layout() ); + m_popupShowOutput = new TQCheckBox( i18n("Default output (speakers/headphones)"), popupBox ); + m_popupShowMic = new TQCheckBox( i18n("Microphone inputs"), popupBox ); + m_popupShowApps = new TQCheckBox( i18n("Active app streams"), popupBox ); + pcl->addWidget( m_popupShowOutput ); + pcl->addWidget( m_popupShowMic ); + pcl->addWidget( m_popupShowApps ); + pl->addWidget( popupBox ); + + TQGroupBox *recBox = new TQGroupBox( i18n("Recording"), pulseWidget ); + recBox->setColumnLayout( 0, TQt::Vertical ); + recBox->layout()->setSpacing( spacingHint() ); + recBox->layout()->setMargin( marginHint() ); + TQVBoxLayout *rcl = new TQVBoxLayout( recBox->layout() ); + m_showRecTray = new TQCheckBox( i18n("Show microphone-in-use icon in tray"), recBox ); + rcl->addWidget( m_showRecTray ); + pl->addWidget( recBox ); + + pl->addSpacing( 8 ); + + TQGroupBox *viewBox = new TQGroupBox( i18n("View"), pulseWidget ); + viewBox->setColumnLayout( 0, TQt::Vertical ); + viewBox->layout()->setSpacing( spacingHint() ); + viewBox->layout()->setMargin( marginHint() ); + TQVBoxLayout *vbl = new TQVBoxLayout( viewBox->layout() ); + m_noTabs = new TQCheckBox( i18n("Show all devices in one view (no tabs)"), viewBox ); + connect( m_noTabs, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(onNoTabsToggled(bool)) ); + vbl->addWidget( m_noTabs ); + vbl->addSpacing( 4 ); + m_showTabsLabel = new TQLabel( i18n("Show tabs:"), viewBox ); + vbl->addWidget( m_showTabsLabel ); + m_showOutput = new TQCheckBox( i18n("Output"), viewBox ); + m_showInput = new TQCheckBox( i18n("Input"), viewBox ); + m_showPlayback = new TQCheckBox( i18n("Playback"), viewBox ); + m_showRecording = new TQCheckBox( i18n("Recording"), viewBox ); + vbl->addWidget( m_showOutput ); + vbl->addWidget( m_showInput ); + vbl->addWidget( m_showPlayback ); + vbl->addWidget( m_showRecording ); + pl->addWidget( viewBox ); + pl->addStretch(); + + int nextPage = 0; + m_backendStack->addWidget( pulseWidget, nextPage++ ); + +#ifdef WITH_ALSA + // ── ALSA page ──────────────────────────────────────────────────────────── + TQWidget *alsaWidget = new TQWidget( m_backendStack ); + TQVBoxLayout *al = new TQVBoxLayout( alsaWidget, 0, spacingHint() ); + + TQHBoxLayout *trayRow = new TQHBoxLayout( 0, 0, spacingHint() ); + trayRow->addWidget( new TQLabel( i18n("Tray device:"), alsaWidget ) ); + m_trayDevice = new TQComboBox( false, alsaWidget ); + + if ( m_alsaModel ) { + TQPtrList<AlsaDevice> devs = m_alsaModel->devices(); + for ( TQPtrListIterator<AlsaDevice> it(devs); *it; ++it ) { + AlsaDevice *dev = *it; + if ( dev->category() == AlsaDevice::Output && + dev->type() == AlsaDevice::Slider ) { + m_trayDevice->insertItem( + TQString("%1 - %2").arg(dev->cardName()).arg(dev->name()) ); + m_trayCardIndices.append( dev->cardIndex() ); + m_trayDeviceNames.append( dev->name() ); + } + } + } else { + m_trayDevice->setEnabled( false ); + } + + trayRow->addWidget( m_trayDevice, 1 ); + al->addLayout( trayRow ); + al->addStretch(); + + m_backendStack->addWidget( alsaWidget, nextPage++ ); +#endif + +#ifdef WITH_OSS + // ── OSS page ───────────────────────────────────────────────────────────── + TQWidget *ossWidget = new TQWidget( m_backendStack ); + TQVBoxLayout *ol = new TQVBoxLayout( ossWidget, 0, spacingHint() ); + + TQHBoxLayout *ossTrayRow = new TQHBoxLayout( 0, 0, spacingHint() ); + ossTrayRow->addWidget( new TQLabel( i18n("Tray device:"), ossWidget ) ); + m_ossTrayDevice = new TQComboBox( false, ossWidget ); + + if ( m_ossModel ) { + TQPtrList<OssDevice> devs = m_ossModel->devices(); + for ( TQPtrListIterator<OssDevice> it(devs); *it; ++it ) { + OssDevice *dev = *it; + if ( dev->category() == OssDevice::Output ) { + m_ossTrayDevice->insertItem( + TQString("%1 - %2").arg(dev->cardPath()).arg(dev->name()) ); + m_ossTrayCardIndices.append( dev->cardIndex() ); + m_ossTrayDeviceNames.append( dev->name() ); + } + } + } else { + m_ossTrayDevice->setEnabled( false ); + } + + ossTrayRow->addWidget( m_ossTrayDevice, 1 ); + ol->addLayout( ossTrayRow ); + ol->addStretch(); + + m_backendStack->addWidget( ossWidget, nextPage++ ); +#endif + + // Show the page matching the current backend + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + TQString backend = cfg->readEntry("Backend", "pulse"); + int backendPage = m_backendIds.findIndex(backend); + m_backendStack->raiseWidget( backendPage >= 0 ? backendPage : 0 ); + + connect( m_backend, TQ_SIGNAL(activated(int)), + this, TQ_SLOT(onBackendComboChanged(int)) ); } +// ── Slot: backend combo changed ─────────────────────────────────────────────── + +void PreferencesDlg::onBackendComboChanged( int idx ) +{ + m_backendStack->raiseWidget( idx ); +} + +void PreferencesDlg::onNoTabsToggled( bool checked ) +{ + bool tabsEnabled = !checked; + m_showTabsLabel->setEnabled( tabsEnabled ); + m_showOutput->setEnabled( tabsEnabled ); + m_showInput->setEnabled( tabsEnabled ); + m_showPlayback->setEnabled( tabsEnabled ); + m_showRecording->setEnabled( tabsEnabled ); +} + +// ── onPopupModeChanged ──────────────────────────────────────────────────────── + void PreferencesDlg::onPopupModeChanged( int idx ) { bool popupEnabled = ( idx == 1 ); - m_popupShowOutput->setEnabled( popupEnabled ); - m_popupShowMic->setEnabled( popupEnabled ); - m_popupShowApps->setEnabled( popupEnabled ); + if ( m_popupShowOutput ) m_popupShowOutput->setEnabled( popupEnabled ); + if ( m_popupShowMic ) m_popupShowMic->setEnabled( popupEnabled ); + if ( m_popupShowApps ) m_popupShowApps->setEnabled( popupEnabled ); } +// ── load / save ─────────────────────────────────────────────────────────────── + void PreferencesDlg::load() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); - m_dockInTray->setChecked( cfg->readBoolEntry("DockInTray", true) ); + + TQString backend = cfg->readEntry("Backend", "pulse"); + int backendIdx = m_backendIds.findIndex(backend); + m_backend->setCurrentItem( backendIdx >= 0 ? backendIdx : 0 ); + m_confirmQuit->setChecked( cfg->readBoolEntry("ConfirmQuit", false) ); + m_startOnLogin->setChecked( TQFile::exists( autostartPath() ) ); + + cfg->setGroup("Tray"); + m_dockInTray->setChecked( cfg->readBoolEntry("DockInTray", true) ); int mode = cfg->readNumEntry("PopupMode", 1); m_popupMode->setCurrentItem( mode ); + onPopupModeChanged( mode ); + m_middleClickMute->setChecked( cfg->readBoolEntry("MiddleClickMute", false) ); + m_scrollStep->setValue( cfg->readNumEntry( "ScrollStep", 5 ) ); + m_popupShowOutput->setChecked( cfg->readBoolEntry("PopupShowOutput", true) ); m_popupShowMic->setChecked( cfg->readBoolEntry("PopupShowMic", false) ); m_popupShowApps->setChecked( cfg->readBoolEntry("PopupShowApps", true) ); - onPopupModeChanged( mode ); - m_showRecTray->setChecked( cfg->readBoolEntry("ShowRecordingTray", true) ); - m_confirmQuit->setChecked( cfg->readBoolEntry("ConfirmQuit", false) ); - m_scrollStep->setValue( cfg->readNumEntry( "ScrollStep", 5) ); + m_showRecTray->setChecked( cfg->readBoolEntry("ShowRecordingTray", true) ); cfg->setGroup("View"); m_noTabs->setChecked( cfg->readBoolEntry("NoTabs", false) ); @@ -120,21 +374,76 @@ void PreferencesDlg::load() m_showInput->setChecked( cfg->readBoolEntry("ShowInput", true) ); m_showPlayback->setChecked( cfg->readBoolEntry("ShowPlayback", true) ); m_showRecording->setChecked( cfg->readBoolEntry("ShowRecording", true) ); + +#ifdef WITH_ALSA + if ( m_trayDevice && !m_trayCardIndices.isEmpty() ) { + cfg->setGroup("Tray"); + int preferredCard = cfg->readNumEntry("TrayCard", -1); + TQString preferredName = cfg->readEntry( "TrayDevice", ""); + TQValueListConstIterator<int> ci = m_trayCardIndices.begin(); + TQValueListConstIterator<TQString> ni = m_trayDeviceNames.begin(); + for ( int i = 0; ci != m_trayCardIndices.end(); ++ci, ++ni, ++i ) { + if ( *ci == preferredCard && *ni == preferredName ) { + m_trayDevice->setCurrentItem(i); + break; + } + } + } +#endif + +#ifdef WITH_OSS + if ( m_ossTrayDevice && !m_ossTrayCardIndices.isEmpty() ) { + cfg->setGroup("OssTray"); + int preferredCard = cfg->readNumEntry("TrayCard", -1); + TQString preferredName = cfg->readEntry( "TrayDevice", ""); + TQValueListConstIterator<int> ci = m_ossTrayCardIndices.begin(); + TQValueListConstIterator<TQString> ni = m_ossTrayDeviceNames.begin(); + for ( int i = 0; ci != m_ossTrayCardIndices.end(); ++ci, ++ni, ++i ) { + if ( *ci == preferredCard && *ni == preferredName ) { + m_ossTrayDevice->setCurrentItem(i); + break; + } + } + } +#endif } void PreferencesDlg::save() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); - cfg->writeEntry( "DockInTray", m_dockInTray->isChecked() ); - cfg->writeEntry( "PopupMode", m_popupMode->currentItem() ); - cfg->writeEntry( "PopupShowOutput", m_popupShowOutput->isChecked() ); - cfg->writeEntry( "PopupShowMic", m_popupShowMic->isChecked() ); - cfg->writeEntry( "PopupShowApps", m_popupShowApps->isChecked() ); - cfg->writeEntry( "ShowRecordingTray", m_showRecTray->isChecked() ); - cfg->writeEntry( "ConfirmQuit", m_confirmQuit->isChecked() ); - cfg->writeEntry( "ScrollStep", m_scrollStep->value() ); + int bi = m_backend->currentItem(); + TQString backendKey = (bi >= 0 && bi < (int)m_backendIds.count()) ? m_backendIds[bi] : "pulse"; + cfg->writeEntry( "Backend", backendKey ); + cfg->writeEntry( "ConfirmQuit", m_confirmQuit->isChecked() ); + + // Autostart: create or remove ~/.trinity/Autostart/tmix.desktop + TQString apath = autostartPath(); + if ( m_startOnLogin->isChecked() ) { + if ( !TQFile::exists( apath ) ) { + TQFile f( apath ); + if ( f.open( IO_WriteOnly ) ) { + TQTextStream ts( &f ); + ts << "[Desktop Entry]\n" + << "Type=Application\n" + << "Name=TMix\n" + << "Exec=tmix\n" + << "X-TDE-StartupNotify=false\n"; + } + } + } else { + TQFile::remove( apath ); + } + + cfg->setGroup("Tray"); + cfg->writeEntry( "DockInTray", m_dockInTray->isChecked() ); + cfg->writeEntry( "PopupMode", m_popupMode->currentItem() ); + cfg->writeEntry( "MiddleClickMute", m_middleClickMute->isChecked() ); + cfg->writeEntry( "ScrollStep", m_scrollStep->value() ); + cfg->writeEntry( "PopupShowOutput", m_popupShowOutput->isChecked() ); + cfg->writeEntry( "PopupShowMic", m_popupShowMic->isChecked() ); + cfg->writeEntry( "PopupShowApps", m_popupShowApps->isChecked() ); + cfg->writeEntry( "ShowRecordingTray", m_showRecTray->isChecked() ); cfg->setGroup("View"); cfg->writeEntry( "NoTabs", m_noTabs->isChecked() ); @@ -143,6 +452,30 @@ void PreferencesDlg::save() cfg->writeEntry( "ShowPlayback", m_showPlayback->isChecked() ); cfg->writeEntry( "ShowRecording", m_showRecording->isChecked() ); +#ifdef WITH_ALSA + if ( m_trayDevice && m_alsaModel ) { + int ti = m_trayDevice->currentItem(); + if ( ti >= 0 && ti < (int)m_trayCardIndices.count() ) { + TQValueListConstIterator<int> ci = m_trayCardIndices.begin(); + TQValueListConstIterator<TQString> ni = m_trayDeviceNames.begin(); + for ( int i = 0; i < ti; ++i ) { ++ci; ++ni; } + m_alsaModel->setPreferredOutput( *ci, *ni ); + } + } +#endif + +#ifdef WITH_OSS + if ( m_ossTrayDevice && m_ossModel ) { + int ti = m_ossTrayDevice->currentItem(); + if ( ti >= 0 && ti < (int)m_ossTrayCardIndices.count() ) { + TQValueListConstIterator<int> ci = m_ossTrayCardIndices.begin(); + TQValueListConstIterator<TQString> ni = m_ossTrayDeviceNames.begin(); + for ( int i = 0; i < ti; ++i ) { ++ci; ++ni; } + m_ossModel->setPreferredOutput( *ci, *ni ); + } + } +#endif + cfg->sync(); emit settingsChanged(); } diff --git a/src/ui/preferencesdlg.h b/src/ui/preferencesdlg.h index 09d740f..85f59c3 100644 --- a/src/ui/preferencesdlg.h +++ b/src/ui/preferencesdlg.h @@ -1,17 +1,39 @@ #pragma once #include <kdialogbase.h> +#include <tqvaluelist.h> +#include <tqstring.h> +#include <tqstringlist.h> class TQCheckBox; class TQComboBox; +class TQLabel; class TQSpinBox; +class TQWidgetStack; + +#ifdef WITH_ALSA +class AlsaModel; +#endif + +#ifdef WITH_OSS +class OssModel; +#endif class PreferencesDlg : public KDialogBase { TQ_OBJECT public: - PreferencesDlg( TQWidget *parent = 0 ); + explicit PreferencesDlg( TQWidget *parent = 0 ); + +#ifdef WITH_ALSA + PreferencesDlg( AlsaModel *model, TQWidget *parent = 0 ); +#endif + +#ifdef WITH_OSS + PreferencesDlg( OssModel *model, TQWidget *parent = 0 ); +#endif + void load(); signals: @@ -23,22 +45,52 @@ protected slots: private slots: void onPopupModeChanged( int idx ); + void onBackendComboChanged( int idx ); + void onNoTabsToggled( bool checked ); private: + void buildGeneralPage(); + void buildBackendPage(); void save(); - TQCheckBox *m_dockInTray; - TQComboBox *m_popupMode; + // Maps combo index → backend key ("pulse", "alsa", "oss") + TQStringList m_backendIds; + + // General — shared + TQComboBox *m_backend; + TQCheckBox *m_dockInTray; + TQComboBox *m_popupMode; + TQSpinBox *m_scrollStep; + TQCheckBox *m_confirmQuit; + TQCheckBox *m_middleClickMute; + TQCheckBox *m_startOnLogin; + + // Backend settings stack + TQWidgetStack *m_backendStack; + + // Pulse widgets — always built, may be on the inactive stack page TQCheckBox *m_popupShowOutput; TQCheckBox *m_popupShowMic; TQCheckBox *m_popupShowApps; TQCheckBox *m_showRecTray; - TQCheckBox *m_confirmQuit; - TQSpinBox *m_scrollStep; - TQCheckBox *m_noTabs; + TQLabel *m_showTabsLabel; TQCheckBox *m_showOutput; TQCheckBox *m_showInput; TQCheckBox *m_showPlayback; TQCheckBox *m_showRecording; + +#ifdef WITH_ALSA + AlsaModel *m_alsaModel; + TQComboBox *m_trayDevice; + TQValueList<int> m_trayCardIndices; + TQValueList<TQString> m_trayDeviceNames; +#endif + +#ifdef WITH_OSS + OssModel *m_ossModel; + TQComboBox *m_ossTrayDevice; + TQValueList<int> m_ossTrayCardIndices; + TQValueList<TQString> m_ossTrayDeviceNames; +#endif }; diff --git a/src/ui/tmixapp.cpp b/src/ui/tmixapp.cpp index 20c509e..2bed54a 100644 --- a/src/ui/tmixapp.cpp +++ b/src/ui/tmixapp.cpp @@ -1,5 +1,5 @@ #include "tmixapp.h" -#include "mixerwindow.h" +#include <tqwidget.h> #include <twin.h> TmixApp::TmixApp() : KUniqueApplication(), m_win(0), m_firstInstance(true) {} diff --git a/src/ui/tmixapp.h b/src/ui/tmixapp.h index 8f41245..78b2687 100644 --- a/src/ui/tmixapp.h +++ b/src/ui/tmixapp.h @@ -1,8 +1,7 @@ #pragma once #include <kuniqueapplication.h> - -class MixerWindow; +#include <tqwidget.h> class TmixApp : public KUniqueApplication { @@ -10,8 +9,8 @@ class TmixApp : public KUniqueApplication public: TmixApp(); int newInstance(); - void setMainWindow( MixerWindow *w ) { m_win = w; } + void setMainWindow( TQWidget *w ) { m_win = w; } private: - MixerWindow *m_win; - bool m_firstInstance; + TQWidget *m_win; + bool m_firstInstance; }; diff --git a/src/ui/tmixpopup.cpp b/src/ui/tmixpopup.cpp index 2cdd16a..29911fa 100644 --- a/src/ui/tmixpopup.cpp +++ b/src/ui/tmixpopup.cpp @@ -191,7 +191,7 @@ void TmixPopup::wheelEvent( TQWheelEvent *e ) AudioDevice *dev = m_model->defaultOutput(); if ( !dev ) return; TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int step = cfg->readNumEntry("ScrollStep", 5); int delta = e->delta() > 0 ? step : -step; int vol = TQMAX( 0, TQMIN( 100, dev->volume() + delta ) ); diff --git a/src/ui/tmixtray.cpp b/src/ui/tmixtray.cpp index c9aed4e..db04de1 100644 --- a/src/ui/tmixtray.cpp +++ b/src/ui/tmixtray.cpp @@ -14,7 +14,7 @@ protected: m_owner->toggleRecordingPopup(); e->accept(); } else { - KSystemTray::mousePressEvent( e ); + e->accept(); } } private: @@ -68,13 +68,15 @@ void TmixTray::setDevice( AudioDevice *dev ) void TmixTray::setModel( PulseModel *model ) { m_model = model; - TQPtrList<AudioDevice> inputs = model->devices( AudioDevice::Input ); - for ( TQPtrListIterator<AudioDevice> it(inputs); *it; ++it ) { - connect( *it, TQ_SIGNAL(recordingActiveChanged(bool)), - this, TQ_SLOT(onRecordingActive(bool)) ); - } connect( model, TQ_SIGNAL(deviceAdded(AudioDevice*)), this, TQ_SLOT(onDeviceAdded(AudioDevice*)) ); + connect( model, TQ_SIGNAL(deviceRemoved(AudioDevice*)), + this, TQ_SLOT(onDeviceRemoved(AudioDevice*)) ); + // Count any Recording devices already present (e.g. after reconnect). + TQPtrList<AudioDevice> recs = model->devices( AudioDevice::Recording ); + for ( TQPtrListIterator<AudioDevice> it(recs); *it; ++it ) + m_recordingCount++; + updateRecordingTray(); } void TmixTray::mousePressEvent( TQMouseEvent *e ) @@ -85,6 +87,15 @@ void TmixTray::mousePressEvent( TQMouseEvent *e ) e->accept(); return; } + if ( e->button() == TQt::MidButton && m_device ) { + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + if ( cfg->readBoolEntry("MiddleClickMute", false) ) { + m_device->setMuted( !m_device->muted() ); + e->accept(); + return; + } + } KSystemTray::mousePressEvent( e ); } @@ -92,7 +103,7 @@ void TmixTray::mousePressEvent( TQMouseEvent *e ) void TmixTray::executeSingleClick() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int mode = cfg->readNumEntry( "PopupMode", 1 ); bool showOutput = cfg->readBoolEntry("PopupShowOutput", true ); bool showMic = cfg->readBoolEntry("PopupShowMic", false ); @@ -141,24 +152,33 @@ void TmixTray::updateIcon() setPixmap( TQPixmap(path) ); } -void TmixTray::onRecordingActive( bool active ) +void TmixTray::onRecordingActive( bool /*active*/ ) { - m_recordingCount += active ? 1 : -1; - if ( m_recordingCount < 0 ) m_recordingCount = 0; - updateRecordingTray(); + // Kept for any future per-source signal use; recording count is now + // driven by onDeviceAdded/onDeviceRemoved for Recording devices. } void TmixTray::onDeviceAdded( AudioDevice *dev ) { - if ( dev->category() == AudioDevice::Input ) - connect( dev, TQ_SIGNAL(recordingActiveChanged(bool)), - this, TQ_SLOT(onRecordingActive(bool)) ); + if ( dev->category() == AudioDevice::Recording ) { + m_recordingCount++; + updateRecordingTray(); + } +} + +void TmixTray::onDeviceRemoved( AudioDevice *dev ) +{ + if ( dev->category() == AudioDevice::Recording ) { + if ( m_recordingCount > 0 ) + m_recordingCount--; + updateRecordingTray(); + } } void TmixTray::updateRecordingTray() { TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); bool showRec = cfg->readBoolEntry("ShowRecordingTray", true); if ( m_recordingCount > 0 && showRec ) { @@ -213,7 +233,7 @@ void TmixTray::wheelEvent( TQWheelEvent *e ) { if ( !m_device ) return; TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); + cfg->setGroup("Tray"); int step = cfg->readNumEntry("ScrollStep", 5); int delta = e->delta() > 0 ? step : -step; int newVol = m_device->volume() + delta; @@ -229,12 +249,9 @@ void TmixTray::contextMenuAboutToShow( TDEPopupMenu *menu ) MixerWindow *win = static_cast<MixerWindow*>( parentWidget() ); - TDEConfig *cfg = TDEGlobal::config(); - cfg->setGroup("General"); - if ( cfg->readNumEntry("PopupMode", 1) >= 1 ) - menu->insertItem( SmallIcon("tmix"), i18n("&Open Mixer"), - win, TQ_SLOT(bringToFront()) ); - + menu->insertItem( SmallIcon("tmix"), i18n("&Open Mixer"), + win, TQ_SLOT(bringToFront()) ); + menu->insertSeparator(); menu->insertItem( SmallIcon("configure"), i18n("&Configure TMix..."), win, TQ_SLOT(showPreferences()) ); menu->insertItem( SmallIcon("help"), i18n("&About TMix"), diff --git a/src/ui/tmixtray.h b/src/ui/tmixtray.h index f04450c..8e0f0a3 100644 --- a/src/ui/tmixtray.h +++ b/src/ui/tmixtray.h @@ -19,6 +19,7 @@ public slots: void updateIcon(); void onRecordingActive( bool active ); void onDeviceAdded( AudioDevice *dev ); + void onDeviceRemoved( AudioDevice *dev ); protected: void mousePressEvent( TQMouseEvent *e ); |
