From 3909a06fe6786027c83e3adaef89c343cde4fbe3 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Sun, 17 May 2026 23:38:18 -0400 Subject: ALSA backend, backend switcher, UX fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ALSA backend: AlsaModel, AlsaDevice, AlsaMixerWindow, AlsaTray, AlsaPopup - BackendController: live pulse↔alsa switching, preserves window position/visibility - PA shutdown fix: stop mainloop thread before disconnect/free to prevent crash - Exit crash fix: BackendController deleted explicitly before TQApplication exits - Waiting-for-PulseAudio placeholder when PA not connected - Preferences: live backend stack (Pulse/ALSA), Startup/Exit card with autostart, Recording card, no-tabs greying, remove stale "requires restart" label - Recording tray: track source outputs directly; fix LED init in popup; level meter forwarding for monitor-source recordings via m_monitorSourceToSink - TmixTray: fix config group General→Tray for scroll/mute/popup settings; RecordingTray suppresses right-click menu - audiodevice.h: add recordingActive() virtual accessor Co-Authored-By: Claude Sonnet 4.6 --- src/ui/preferencesdlg.h | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'src/ui/preferencesdlg.h') diff --git a/src/ui/preferencesdlg.h b/src/ui/preferencesdlg.h index 09d740f..93ac377 100644 --- a/src/ui/preferencesdlg.h +++ b/src/ui/preferencesdlg.h @@ -1,17 +1,30 @@ #pragma once #include +#include +#include class TQCheckBox; class TQComboBox; +class TQLabel; class TQSpinBox; +class TQWidgetStack; + +#ifdef WITH_ALSA +class AlsaModel; +#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 + void load(); signals: @@ -23,22 +36,42 @@ 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; + // 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 m_trayCardIndices; + TQValueList m_trayDeviceNames; +#endif }; -- cgit v1.2.3 From 65c7ea9fbf4886fa3d6127c5fa699520f30f386c Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Mon, 18 May 2026 00:00:17 -0400 Subject: OSS backend for FreeBSD support Adds a complete OSS audio backend alongside PulseAudio and ALSA: - OssDevice/OssModel: enumerate /dev/mixer*, poll for changes at 500ms - Full UI layer: mixer window, system tray, mini popup, per-channel widgets - Fake mute (saves/restores volume since OSS has no mute bit) - BackendController and PreferencesDlg updated; backend combo now uses m_backendIds list so any combination of compiled-in backends works Co-Authored-By: Claude Sonnet 4.6 --- src/CMakeLists.txt | 18 +++- src/model/ossdevice.cpp | 89 +++++++++++++++++++ src/model/ossdevice.h | 51 +++++++++++ src/model/ossmodel.cpp | 140 ++++++++++++++++++++++++++++++ src/model/ossmodel.h | 50 +++++++++++ src/ui/backendcontroller.cpp | 58 +++++++++++++ src/ui/backendcontroller.h | 8 +- src/ui/oss/ossdevicewidget.cpp | 154 +++++++++++++++++++++++++++++++++ src/ui/oss/ossdevicewidget.h | 31 +++++++ src/ui/oss/ossmixerwindow.cpp | 192 +++++++++++++++++++++++++++++++++++++++++ src/ui/oss/ossmixerwindow.h | 53 ++++++++++++ src/ui/oss/osspopup.cpp | 78 +++++++++++++++++ src/ui/oss/osspopup.h | 30 +++++++ src/ui/oss/osstray.cpp | 129 +++++++++++++++++++++++++++ src/ui/oss/osstray.h | 34 ++++++++ src/ui/preferencesdlg.cpp | 142 +++++++++++++++++++++++++----- src/ui/preferencesdlg.h | 19 ++++ 17 files changed, 1251 insertions(+), 25 deletions(-) create mode 100644 src/model/ossdevice.cpp create mode 100644 src/model/ossdevice.h create mode 100644 src/model/ossmodel.cpp create mode 100644 src/model/ossmodel.h create mode 100644 src/ui/oss/ossdevicewidget.cpp create mode 100644 src/ui/oss/ossdevicewidget.h create mode 100644 src/ui/oss/ossmixerwindow.cpp create mode 100644 src/ui/oss/ossmixerwindow.h create mode 100644 src/ui/oss/osspopup.cpp create mode 100644 src/ui/oss/osspopup.h create mode 100644 src/ui/oss/osstray.cpp create mode 100644 src/ui/oss/osstray.h (limited to 'src/ui/preferencesdlg.h') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e9ee2d..7a8fd38 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,12 @@ include( FindPkgConfig ) +include( CheckIncludeFile ) pkg_check_modules( PULSE libpulse ) pkg_check_modules( ALSA alsa ) +check_include_file( "sys/soundcard.h" HAVE_OSS_HEADER ) -if( NOT PULSE_FOUND AND NOT ALSA_FOUND ) - message( FATAL_ERROR "Neither libpulse nor libasound found — cannot build tmix" ) +if( NOT PULSE_FOUND AND NOT ALSA_FOUND AND NOT HAVE_OSS_HEADER ) + message( FATAL_ERROR "No audio backend found (need libpulse, libasound, or sys/soundcard.h)" ) endif() set( TMIX_SOURCES @@ -63,6 +65,18 @@ if( ALSA_FOUND ) ) endif() +if( HAVE_OSS_HEADER ) + add_definitions( -DWITH_OSS ) + list( APPEND TMIX_SOURCES + model/ossdevice.cpp + model/ossmodel.cpp + ui/oss/ossdevicewidget.cpp + ui/oss/ossmixerwindow.cpp + ui/oss/osspopup.cpp + ui/oss/osstray.cpp + ) +endif() + include_directories( ${TMIX_INCLUDES} ) link_directories( diff --git a/src/model/ossdevice.cpp b/src/model/ossdevice.cpp new file mode 100644 index 0000000..6a3b70a --- /dev/null +++ b/src/model/ossdevice.cpp @@ -0,0 +1,89 @@ +#include "ossdevice.h" +#include +#include +#include +#include + +OssDevice::OssDevice( Category cat, int cardIdx, const TQString &cardPath, + int fd, int channelIdx, const TQString &name, bool stereo, + TQObject *parent ) + : TQObject(parent), m_fd(fd), m_cardIdx(cardIdx), m_cardPath(cardPath), + m_channelIdx(channelIdx), m_name(name), m_category(cat), + m_stereo(stereo), m_volume(0), m_savedVol(50), m_muted(false), m_pan(0) +{ + syncFromOss(); +} + +void OssDevice::syncFromOss() +{ + if ( m_fd < 0 ) return; + int val = 0; + if ( ::ioctl(m_fd, MIXER_READ(m_channelIdx), &val) < 0 ) return; + + int left = val & 0xff; + int right = (val >> 8) & 0xff; + int mx = std::max(left, right); + + if ( m_muted ) return; // don't overwrite display while muted + + int newVol = mx; + int newPan = 0; + if ( m_stereo && mx > 0 ) { + if ( left >= right ) + newPan = (int)std::lround( -50.0 * (1.0 - (double)right / left) ); + else + newPan = (int)std::lround( 50.0 * (1.0 - (double)left / right) ); + } + + if ( newVol != m_volume ) { m_volume = newVol; emit volumeChanged(m_volume); } + if ( newPan != m_pan ) { m_pan = newPan; emit panChanged(m_pan); } +} + +void OssDevice::pushVolume() +{ + if ( m_fd < 0 ) return; + int vol = m_muted ? 0 : m_volume; + double lf = m_pan >= 0 ? (50.0 - m_pan) / 50.0 : 1.0; + double rf = m_pan <= 0 ? (50.0 + m_pan) / 50.0 : 1.0; + int lv = (int)(vol * lf + 0.5); + int rv = (int)(vol * rf + 0.5); + if ( lv > 100 ) lv = 100; + if ( rv > 100 ) rv = 100; + int val = lv | (rv << 8); + ::ioctl(m_fd, MIXER_WRITE(m_channelIdx), &val); +} + +void OssDevice::setVolume( int v ) +{ + v = v < 0 ? 0 : v > 100 ? 100 : v; + m_volume = v; + if ( !m_muted ) m_savedVol = v; + emit volumeChanged(v); + pushVolume(); +} + +void OssDevice::setMuted( bool m ) +{ + if ( m == m_muted ) return; + if ( m ) { + if ( m_volume > 0 ) m_savedVol = m_volume; + m_muted = true; + pushVolume(); + } else { + m_muted = false; + m_volume = m_savedVol; + pushVolume(); + emit volumeChanged(m_volume); + } + emit muteChanged(m_muted); +} + +void OssDevice::setPan( int p ) +{ + p = p < -50 ? -50 : p > 50 ? 50 : p; + m_pan = p; + emit panChanged(p); + pushVolume(); +} + +#include "ossdevice.moc" diff --git a/src/model/ossdevice.h b/src/model/ossdevice.h new file mode 100644 index 0000000..66a0d1b --- /dev/null +++ b/src/model/ossdevice.h @@ -0,0 +1,51 @@ +#pragma once + +#include +#include + +class OssDevice : public TQObject +{ + TQ_OBJECT +public: + enum Category { Output, Input }; + + OssDevice( Category cat, int cardIdx, const TQString &cardPath, + int fd, int channelIdx, const TQString &name, bool stereo, + TQObject *parent = 0 ); + + TQString name() const { return m_name; } + TQString cardPath() const { return m_cardPath; } + int cardIndex() const { return m_cardIdx; } + Category category() const { return m_category; } + int volume() const { return m_volume; } + bool muted() const { return m_muted; } + int pan() const { return m_pan; } + bool stereo() const { return m_stereo; } + bool hasMute() const { return true; } + + void setVolume( int v ); + void setMuted( bool m ); + void setPan( int p ); + + void syncFromOss(); + +signals: + void volumeChanged( int v ); + void muteChanged( bool m ); + void panChanged( int p ); + +private: + void pushVolume(); + + int m_fd; // borrowed from OssModel — do not close + int m_cardIdx; + TQString m_cardPath; + int m_channelIdx; + TQString m_name; + Category m_category; + bool m_stereo; + int m_volume; + int m_savedVol; // pre-mute volume for fake-mute + bool m_muted; + int m_pan; +}; diff --git a/src/model/ossmodel.cpp b/src/model/ossmodel.cpp new file mode 100644 index 0000000..35aa842 --- /dev/null +++ b/src/model/ossmodel.cpp @@ -0,0 +1,140 @@ +#include "ossmodel.h" +#include +#include +#include +#include +#include +#include +#include +#include + +static const char *ossChannelNames[] = SOUND_DEVICE_NAMES; + +OssModel::OssModel( TQObject *parent ) + : TQObject(parent), m_timer(0) +{ + m_devices.setAutoDelete(true); + m_timer = new TQTimer(this); + connect(m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(onPollTimer())); +} + +OssModel::~OssModel() +{ + close(); +} + +bool OssModel::open() +{ + openCard(0, "/dev/mixer"); + for ( int i = 1; i < 16; ++i ) { + char path[32]; + snprintf(path, sizeof(path), "/dev/mixer%d", i); + int probe = ::open(path, O_RDONLY); + if ( probe < 0 ) break; + ::close(probe); + openCard(i, TQString::fromLocal8Bit(path)); + } + if ( m_devices.isEmpty() ) return false; + m_timer->start(500); + emit ready(); + return true; +} + +void OssModel::openCard( int cardIdx, const TQString &path ) +{ + int fd = ::open(path.local8Bit().data(), O_RDWR); + if ( fd < 0 ) return; + + mixer_info info; + TQString cardName; + if ( ::ioctl(fd, SOUND_MIXER_INFO, &info) == 0 ) + cardName = TQString::fromLocal8Bit(info.name); + else + cardName = path; + + int devmask = 0, stmask = 0, recmask = 0; + ::ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devmask); + ::ioctl(fd, SOUND_MIXER_READ_STEREODEVS, &stmask); + ::ioctl(fd, SOUND_MIXER_READ_RECMASK, &recmask); + + OssCard card; + card.index = cardIdx; + card.path = path; + card.name = cardName; + m_cards.append(card); + m_fds.append(fd); + + for ( int i = 0; i < SOUND_MIXER_NRDEVICES; ++i ) { + if ( !(devmask & (1 << i)) ) continue; + OssDevice::Category cat = (recmask & (1 << i)) + ? OssDevice::Input : OssDevice::Output; + bool stereo = (stmask & (1 << i)) != 0; + TQString name = TQString::fromLocal8Bit(ossChannelNames[i]); + OssDevice *dev = new OssDevice(cat, cardIdx, path, fd, i, name, stereo, this); + m_devices.append(dev); + emit deviceAdded(dev); + } +} + +void OssModel::onPollTimer() +{ + for ( TQPtrListIterator it(m_devices); *it; ++it ) + (*it)->syncFromOss(); +} + +void OssModel::close() +{ + if ( m_timer ) m_timer->stop(); + m_devices.clear(); + m_cards.clear(); + for ( TQValueListIterator it = m_fds.begin(); it != m_fds.end(); ++it ) + ::close(*it); + m_fds.clear(); +} + +TQPtrList OssModel::devicesForCard( int cardIdx ) const +{ + TQPtrList result; + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == cardIdx ) + result.append(*it); + return result; +} + +OssDevice *OssModel::defaultOutput() const +{ + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->category() == OssDevice::Output && (*it)->name() == "vol" ) + return *it; + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->category() == OssDevice::Output ) + return *it; + return 0; +} + +OssDevice *OssModel::preferredOutput() const +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssTray"); + int card = cfg->readNumEntry("TrayCard", -1); + TQString name = cfg->readEntry("TrayDevice", ""); + if ( card >= 0 && !name.isEmpty() ) { + for ( TQPtrListIterator it(m_devices); *it; ++it ) + if ( (*it)->cardIndex() == card && (*it)->name() == name && + (*it)->category() == OssDevice::Output ) + return *it; + } + return defaultOutput(); +} + +void OssModel::setPreferredOutput( int cardIdx, const TQString &name ) +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("OssTray"); + cfg->writeEntry("TrayCard", cardIdx); + cfg->writeEntry("TrayDevice", name); + cfg->sync(); + emit preferredOutputChanged( preferredOutput() ); +} + +#include "ossmodel.moc" diff --git a/src/model/ossmodel.h b/src/model/ossmodel.h new file mode 100644 index 0000000..8c3db8b --- /dev/null +++ b/src/model/ossmodel.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include + +#include "ossdevice.h" + +class TQTimer; + +struct OssCard { + int index; + TQString path; + TQString name; +}; + +class OssModel : public TQObject +{ + TQ_OBJECT +public: + explicit OssModel( TQObject *parent = 0 ); + ~OssModel(); + + bool open(); + void close(); + + TQValueList cards() const { return m_cards; } + TQPtrList devices() const { return m_devices; } + TQPtrList devicesForCard( int cardIdx ) const; + OssDevice *defaultOutput() const; + OssDevice *preferredOutput() const; + void setPreferredOutput( int cardIdx, const TQString &name ); + +signals: + void deviceAdded( OssDevice *dev ); + void preferredOutputChanged( OssDevice *dev ); + void ready(); + +private slots: + void onPollTimer(); + +private: + void openCard( int cardIdx, const TQString &path ); + + TQValueList m_cards; + TQPtrList m_devices; + TQValueList m_fds; // one open fd per card, owned here + TQTimer *m_timer; +}; diff --git a/src/ui/backendcontroller.cpp b/src/ui/backendcontroller.cpp index 3a41b8d..037c797 100644 --- a/src/ui/backendcontroller.cpp +++ b/src/ui/backendcontroller.cpp @@ -17,6 +17,12 @@ #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 @@ -25,6 +31,9 @@ BackendController::BackendController( TQObject *parent ) #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() @@ -41,6 +50,9 @@ void BackendController::start() #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 @@ -53,6 +65,11 @@ void BackendController::stop() 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; } @@ -109,6 +126,33 @@ void BackendController::startAlsa( bool showWindow ) } #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(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(); @@ -148,12 +192,26 @@ void BackendController::doSwitch() } } #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 diff --git a/src/ui/backendcontroller.h b/src/ui/backendcontroller.h index a6cfe6c..5938fdd 100644 --- a/src/ui/backendcontroller.h +++ b/src/ui/backendcontroller.h @@ -23,7 +23,8 @@ private slots: private: void stop(); void startPulse( bool showWindow = false ); - void startAlsa( bool showWindow = false ); + void startAlsa( bool showWindow = false ); + void startOss( bool showWindow = false ); TQString m_currentBackend; @@ -36,4 +37,9 @@ private: 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/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 +#include +#include +#include +#include +#include +#include + +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 + +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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 cards = model->cards(); + for ( TQValueListConstIterator 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 devs = m_model->devicesForCard(cardIdx); + bool hasOutput = false, hasInput = false; + for ( TQPtrListIterator 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 cards = m_model->cards(); + if ( idx < 0 || idx >= (int)cards.count() ) return; + TQValueListConstIterator it = cards.begin(); + for ( int i = 0; i < idx; ++i ) ++it; + rebuildTabs((*it).index); +} + +void OssMixerWindow::onDeviceAdded( OssDevice * ) +{ + m_cardCombo->clear(); + TQValueList cards = m_model->cards(); + for ( TQValueListConstIterator 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 +#include +#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 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 +#include +#include +#include +#include +#include + +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 +#include + +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 +#include +#include +#include +#include +#include +#include +#include + +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 + +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 fa69bd3..9797c93 100644 --- a/src/ui/preferencesdlg.cpp +++ b/src/ui/preferencesdlg.cpp @@ -29,22 +29,32 @@ static TQString autostartPath() #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 ), - 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) + 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(); @@ -58,15 +68,31 @@ PreferencesDlg::PreferencesDlg( TQWidget *parent ) PreferencesDlg::PreferencesDlg( AlsaModel *model, TQWidget *parent ) : KDialogBase( Tabbed, i18n("Configure TMix"), Ok | Apply | Cancel, Ok, parent, 0, false ), - 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), + 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(); @@ -85,9 +111,17 @@ void PreferencesDlg::buildGeneralPage() 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(); @@ -204,10 +238,11 @@ void PreferencesDlg::buildBackendPage() pl->addWidget( viewBox ); pl->addStretch(); - m_backendStack->addWidget( pulseWidget, 0 ); + int nextPage = 0; + m_backendStack->addWidget( pulseWidget, nextPage++ ); #ifdef WITH_ALSA - // ── ALSA page (stack index 1) ───────────────────────────────────────────── + // ── ALSA page ──────────────────────────────────────────────────────────── TQWidget *alsaWidget = new TQWidget( m_backendStack ); TQVBoxLayout *al = new TQVBoxLayout( alsaWidget, 0, spacingHint() ); @@ -235,14 +270,46 @@ void PreferencesDlg::buildBackendPage() al->addLayout( trayRow ); al->addStretch(); - m_backendStack->addWidget( alsaWidget, 1 ); + 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 devs = m_ossModel->devices(); + for ( TQPtrListIterator 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"); - m_backendStack->raiseWidget( backend == "alsa" ? 1 : 0 ); + 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)) ); @@ -283,7 +350,8 @@ void PreferencesDlg::load() cfg->setGroup("General"); TQString backend = cfg->readEntry("Backend", "pulse"); - m_backend->setCurrentItem( backend == "alsa" ? 1 : 0 ); + 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() ) ); @@ -322,13 +390,31 @@ void PreferencesDlg::load() } } #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 ci = m_ossTrayCardIndices.begin(); + TQValueListConstIterator 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( "Backend", m_backend->currentItem() == 1 ? "alsa" : "pulse" ); + 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 @@ -378,6 +464,18 @@ void PreferencesDlg::save() } #endif +#ifdef WITH_OSS + if ( m_ossTrayDevice && m_ossModel ) { + int ti = m_ossTrayDevice->currentItem(); + if ( ti >= 0 && ti < (int)m_ossTrayCardIndices.count() ) { + TQValueListConstIterator ci = m_ossTrayCardIndices.begin(); + TQValueListConstIterator 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 93ac377..85f59c3 100644 --- a/src/ui/preferencesdlg.h +++ b/src/ui/preferencesdlg.h @@ -3,6 +3,7 @@ #include #include #include +#include class TQCheckBox; class TQComboBox; @@ -14,6 +15,10 @@ class TQWidgetStack; class AlsaModel; #endif +#ifdef WITH_OSS +class OssModel; +#endif + class PreferencesDlg : public KDialogBase { TQ_OBJECT @@ -25,6 +30,10 @@ public: PreferencesDlg( AlsaModel *model, TQWidget *parent = 0 ); #endif +#ifdef WITH_OSS + PreferencesDlg( OssModel *model, TQWidget *parent = 0 ); +#endif + void load(); signals: @@ -44,6 +53,9 @@ private: void buildBackendPage(); void save(); + // Maps combo index → backend key ("pulse", "alsa", "oss") + TQStringList m_backendIds; + // General — shared TQComboBox *m_backend; TQCheckBox *m_dockInTray; @@ -74,4 +86,11 @@ private: TQValueList m_trayCardIndices; TQValueList m_trayDeviceNames; #endif + +#ifdef WITH_OSS + OssModel *m_ossModel; + TQComboBox *m_ossTrayDevice; + TQValueList m_ossTrayCardIndices; + TQValueList m_ossTrayDeviceNames; +#endif }; -- cgit v1.2.3