summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-05-18 00:00:17 -0400
committerCalvin Morrison <calvin@pobox.com>2026-05-18 00:00:17 -0400
commit65c7ea9fbf4886fa3d6127c5fa699520f30f386c (patch)
treebca364e1c1f0244d477349345ec7dd531b8032f8 /src
parent3909a06fe6786027c83e3adaef89c343cde4fbe3 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt18
-rw-r--r--src/model/ossdevice.cpp89
-rw-r--r--src/model/ossdevice.h51
-rw-r--r--src/model/ossmodel.cpp140
-rw-r--r--src/model/ossmodel.h50
-rw-r--r--src/ui/backendcontroller.cpp58
-rw-r--r--src/ui/backendcontroller.h8
-rw-r--r--src/ui/oss/ossdevicewidget.cpp154
-rw-r--r--src/ui/oss/ossdevicewidget.h31
-rw-r--r--src/ui/oss/ossmixerwindow.cpp192
-rw-r--r--src/ui/oss/ossmixerwindow.h53
-rw-r--r--src/ui/oss/osspopup.cpp78
-rw-r--r--src/ui/oss/osspopup.h30
-rw-r--r--src/ui/oss/osstray.cpp129
-rw-r--r--src/ui/oss/osstray.h34
-rw-r--r--src/ui/preferencesdlg.cpp142
-rw-r--r--src/ui/preferencesdlg.h19
17 files changed, 1251 insertions, 25 deletions
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 <sys/soundcard.h>
+#include <sys/ioctl.h>
+#include <algorithm>
+#include <cmath>
+
+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 <tqobject.h>
+#include <tqstring.h>
+
+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 <sys/soundcard.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <tdeconfig.h>
+#include <tdeglobal.h>
+#include <tqtimer.h>
+
+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<OssDevice> it(m_devices); *it; ++it )
+ (*it)->syncFromOss();
+}
+
+void OssModel::close()
+{
+ if ( m_timer ) m_timer->stop();
+ m_devices.clear();
+ m_cards.clear();
+ for ( TQValueListIterator<int> it = m_fds.begin(); it != m_fds.end(); ++it )
+ ::close(*it);
+ m_fds.clear();
+}
+
+TQPtrList<OssDevice> OssModel::devicesForCard( int cardIdx ) const
+{
+ TQPtrList<OssDevice> result;
+ for ( TQPtrListIterator<OssDevice> it(m_devices); *it; ++it )
+ if ( (*it)->cardIndex() == cardIdx )
+ result.append(*it);
+ return result;
+}
+
+OssDevice *OssModel::defaultOutput() const
+{
+ for ( TQPtrListIterator<OssDevice> it(m_devices); *it; ++it )
+ if ( (*it)->category() == OssDevice::Output && (*it)->name() == "vol" )
+ return *it;
+ for ( TQPtrListIterator<OssDevice> 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<OssDevice> 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 <tqobject.h>
+#include <tqptrlist.h>
+#include <tqvaluelist.h>
+#include <tqstring.h>
+
+#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<OssCard> cards() const { return m_cards; }
+ TQPtrList<OssDevice> devices() const { return m_devices; }
+ TQPtrList<OssDevice> 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<OssCard> m_cards;
+ TQPtrList<OssDevice> m_devices;
+ TQValueList<int> 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<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();
@@ -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 <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 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<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");
- 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<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( "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<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 93ac377..85f59c3 100644
--- a/src/ui/preferencesdlg.h
+++ b/src/ui/preferencesdlg.h
@@ -3,6 +3,7 @@
#include <kdialogbase.h>
#include <tqvaluelist.h>
#include <tqstring.h>
+#include <tqstringlist.h>
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<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
};