1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
#include "preferencesdlg.h"
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqspinbox.h>
#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
// ── 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)
#ifdef WITH_ALSA
, m_alsaModel(0), m_trayDevice(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 ),
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),
m_alsaModel(model), m_trayDevice(0)
{
buildGeneralPage();
buildBackendPage();
load();
}
#endif
// ── General page ──────────────────────────────────────────────────────────────
void PreferencesDlg::buildGeneralPage()
{
TQFrame *gen = addPage( i18n("General") );
TQVBoxLayout *gl = new TQVBoxLayout( gen, marginHint(), spacingHint() );
TQHBoxLayout *backendRow = new TQHBoxLayout( 0, 0, spacingHint() );
backendRow->addWidget( new TQLabel( i18n("Audio backend:"), gen ) );
m_backend = new TQComboBox( false, gen );
m_backend->insertItem( i18n("PulseAudio") );
#ifdef WITH_ALSA
m_backend->insertItem( i18n("ALSA") );
#endif
backendRow->addWidget( m_backend );
backendRow->addStretch();
gl->addLayout( backendRow );
gl->addSpacing( 8 );
TQGroupBox *trayCard = new TQGroupBox( i18n("System Tray"), gen );
trayCard->setColumnLayout( 0, Qt::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("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();
tl->addLayout( popupRow );
connect( m_popupMode, TQ_SIGNAL(activated(int)), this, TQ_SLOT(onPopupModeChanged(int)) );
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 step:"), trayCard ) );
m_scrollStep = new TQSpinBox( 1, 20, 1, trayCard );
m_scrollStep->setSuffix( i18n(" %") );
stepRow->addWidget( m_scrollStep );
stepRow->addStretch();
tl->addLayout( stepRow );
gl->addWidget( trayCard );
gl->addSpacing( 4 );
TQGroupBox *startupCard = new TQGroupBox( i18n("Startup / Exit"), gen );
startupCard->setColumnLayout( 0, Qt::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();
}
// ── Backend settings page (stacked Pulse / ALSA) ──────────────────────────────
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, Qt::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, Qt::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, Qt::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();
m_backendStack->addWidget( pulseWidget, 0 );
#ifdef WITH_ALSA
// ── ALSA page (stack index 1) ─────────────────────────────────────────────
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, 1 );
#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 );
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 );
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");
TQString backend = cfg->readEntry("Backend", "pulse");
m_backend->setCurrentItem( backend == "alsa" ? 1 : 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) );
m_showRecTray->setChecked( cfg->readBoolEntry("ShowRecordingTray", true) );
cfg->setGroup("View");
m_noTabs->setChecked( cfg->readBoolEntry("NoTabs", false) );
m_showOutput->setChecked( cfg->readBoolEntry("ShowOutput", true) );
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
}
void PreferencesDlg::save()
{
TDEConfig *cfg = TDEGlobal::config();
cfg->setGroup("General");
cfg->writeEntry( "Backend", m_backend->currentItem() == 1 ? "alsa" : "pulse" );
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() );
cfg->writeEntry( "ShowOutput", m_showOutput->isChecked() );
cfg->writeEntry( "ShowInput", m_showInput->isChecked() );
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
cfg->sync();
emit settingsChanged();
}
void PreferencesDlg::slotOk() { save(); accept(); }
void PreferencesDlg::slotApply() { save(); }
#include "preferencesdlg.moc"
|