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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
|
/*
Copyright (C) 2005-2009 Michel de Boer <michel@twinklephone.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QPixmap>
#include <QComboBox>
#include "gui.h"
#include "sockets/interfaces.h"
#include "selectprofileform.h"
#include <QStringList>
#include "audits/memman.h"
#include <QSpinBox>
#include <QFileDialog>
#include <QFileInfo>
#include "twinkle_config.h"
#include <QRegExp>
#include <QValidator>
#include <QRegExpValidator>
#include "syssettingsform.h"
/*
* Constructs a SysSettingsForm as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
SysSettingsForm::SysSettingsForm(QWidget* parent)
: QDialog(parent)
{
setupUi(this);
init();
}
/*
* Destroys the object and frees any allocated resources
*/
SysSettingsForm::~SysSettingsForm()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void SysSettingsForm::languageChange()
{
retranslateUi(this);
}
// Indices of categories in the category list box
#define idxCatGeneral 0
#define idxCatAudio 1
#define idxCatRingtones 2
#define idxCatAddressBook 3
#define idxCatNetwork 4
#define idxCatLog 5
void SysSettingsForm::init()
{
// Set toolbutton icons for disabled options.
QIcon i;
i = openRingtoneToolButton->icon();
i.addPixmap(QPixmap(":/icons/images/fileopen-disabled.png"),
QIcon::Disabled);
openRingtoneToolButton->setIcon(i);
i = openRingbackToolButton->icon();
i.addPixmap(QPixmap(":/icons/images/fileopen-disabled.png"),
QIcon::Disabled);
openRingbackToolButton->setIcon(i);
QRegExp rxNumber("[0-9]+");
maxUdpSizeLineEdit->setValidator(new QRegExpValidator(rxNumber, this));
maxTcpSizeLineEdit->setValidator(new QRegExpValidator(rxNumber, this));
}
void SysSettingsForm::showCategory( int index )
{
if (index == idxCatGeneral) {
settingsWidgetStack->setCurrentWidget(pageGeneral);
} else if (index == idxCatAudio) {
settingsWidgetStack->setCurrentWidget(pageAudio);
} else if (index == idxCatRingtones) {
settingsWidgetStack->setCurrentWidget(pageRingtones);
} else if (index == idxCatAddressBook) {
settingsWidgetStack->setCurrentWidget(pageAddressBook);
} else if (index == idxCatNetwork) {
settingsWidgetStack->setCurrentWidget(pageNetwork);
} else if (index == idxCatLog) {
settingsWidgetStack->setCurrentWidget(pageLog);
}
}
string SysSettingsForm::comboItem2audio_dev(QString item, QLineEdit *qleOther, bool playback)
{
if (item == QString("ALSA: ") + DEV_OTHER) {
if (qleOther->text().isEmpty()) return "";
return (QString(PFX_ALSA) + qleOther->text()).toStdString();
}
if (item == QString("OSS: ") + DEV_OTHER) {
if (qleOther->text().isEmpty()) return "";
return (QString(PFX_OSS) + qleOther->text()).toStdString();
}
list<t_audio_device> &list_audio_dev = (playback ?
list_audio_playback_dev : list_audio_capture_dev);
for (list<t_audio_device>::iterator i = list_audio_dev.begin();
i != list_audio_dev.end(); i++)
{
if (i->get_description() == item.toStdString()) {
return i->get_settings_value();
}
}
return "";
}
void SysSettingsForm::populateComboBox(QComboBox *cb, const QString &s)
{
for (int i = 0; i < cb->count(); i++) {
if (cb->itemText(i) == s) {
cb->setCurrentIndex(i);
return;
}
}
}
void SysSettingsForm::populate()
{
QString msg;
int idx;
// Select the Audio category
categoryListBox->setCurrentRow(idxCatGeneral);
settingsWidgetStack->setCurrentWidget(pageGeneral);
// Set focus on first field
categoryListBox->setFocus();
// Audio settings
list_audio_playback_dev = sys_config->get_audio_devices(true);
list_audio_capture_dev = sys_config->get_audio_devices(false);
ringtoneComboBox->clear();
speakerComboBox->clear();
micComboBox->clear();
bool devRingtoneFound = false;
bool devSpeakerFound = false;
bool devMicFound = false;
// Playback devices
idx = 0;
for (list<t_audio_device>::iterator i = list_audio_playback_dev.begin();
i != list_audio_playback_dev.end(); i++, idx++) {
string item = i->get_description();
ringtoneComboBox->addItem(QString(item.c_str()));
speakerComboBox->addItem(QString(item.c_str()));
// Select audio device
if (sys_config->get_dev_ringtone().device == i->device) {
ringtoneComboBox->setCurrentIndex(idx);
otherRingtoneLineEdit->clear();
devRingtoneFound = true;
}
if (sys_config->get_dev_speaker().device == i->device) {
speakerComboBox->setCurrentIndex(idx);
otherSpeakerLineEdit->clear();
devSpeakerFound = true;
}
// Determine index for other non-standard device
if (i->device == DEV_OTHER) {
if (i->type == t_audio_device::ALSA) {
idxOtherPlaybackDevAlsa = idx;
} else {
idxOtherPlaybackDevOss = idx;
}
}
}
// Check for non-standard audio devices
if (!devRingtoneFound) {
t_audio_device dev = sys_config->get_dev_ringtone();
otherRingtoneLineEdit->setText(dev.device.c_str());
ringtoneComboBox->setCurrentIndex(
(dev.type == t_audio_device::ALSA ? idxOtherPlaybackDevAlsa : idxOtherPlaybackDevOss));
}
if (!devSpeakerFound) {
t_audio_device dev = sys_config->get_dev_speaker();
otherSpeakerLineEdit->setText(dev.device.c_str());
speakerComboBox->setCurrentIndex(
(dev.type == t_audio_device::ALSA ? idxOtherPlaybackDevAlsa : idxOtherPlaybackDevOss));
}
// Capture device
idx = 0;
for (list<t_audio_device>::iterator i = list_audio_capture_dev.begin();
i != list_audio_capture_dev.end(); i++, idx++) {
string item = i->get_description();
micComboBox->addItem(QString(item.c_str()));
// Select audio device
if (sys_config->get_dev_mic().device == i->device) {
micComboBox->setCurrentIndex(idx);
otherMicLineEdit->clear();
devMicFound = true;
}
// Determine index for other non-standard device
if (i->device == DEV_OTHER) {
if (i->type == t_audio_device::ALSA) {
idxOtherCaptureDevAlsa = idx;
} else {
idxOtherCaptureDevOss = idx;
}
}
}
// Check for non-standard audio devices
if (!devMicFound) {
t_audio_device dev = sys_config->get_dev_mic();
otherMicLineEdit->setText(dev.device.c_str());
micComboBox->setCurrentIndex(
(dev.type == t_audio_device::ALSA ? idxOtherCaptureDevAlsa : idxOtherCaptureDevOss));
}
// Enable/disable line edit for non-standard device
devRingtoneSelected(ringtoneComboBox->currentIndex());
devSpeakerSelected(speakerComboBox->currentIndex());
devMicSelected(micComboBox->currentIndex());
validateAudioCheckBox->setChecked(sys_config->get_validate_audio_dev());
populateComboBox(ossFragmentComboBox,
QString::number(sys_config->get_oss_fragment_size()));
populateComboBox(alsaPlayPeriodComboBox,
QString::number(sys_config->get_alsa_play_period_size()));
populateComboBox(alsaCapturePeriodComboBox,
QString::number(sys_config->get_alsa_capture_period_size()));
// Log settings
logMaxSizeSpinBox->setValue(sys_config->get_log_max_size());
logDebugCheckBox->setChecked(sys_config->get_log_show_debug());
logSipCheckBox->setChecked(sys_config->get_log_show_sip());
logStunCheckBox->setChecked(sys_config->get_log_show_stun());
logMemoryCheckBox->setChecked(sys_config->get_log_show_memory());
// General settings
guiUseSystrayCheckBox->setChecked(sys_config->get_gui_use_systray());
guiHideCheckBox->setChecked(sys_config->get_gui_hide_on_close());
guiHideCheckBox->setEnabled(sys_config->get_gui_use_systray());
// Call history
histSizeSpinBox->setValue(sys_config->get_ch_max_size());
// Auto show on incoming call
autoShowCheckBox->setChecked(sys_config->get_gui_auto_show_incoming());
autoShowTimeoutSpinBox->setValue(sys_config->get_gui_auto_show_timeout());
// Services
callWaitingCheckBox->setChecked(sys_config->get_call_waiting());
hangupBothCheckBox->setChecked(sys_config->get_hangup_both_3way());
// Startup settings
startHiddenCheckBox->setChecked(sys_config->get_start_hidden());
osdCheckBox->setChecked(sys_config->get_gui_show_call_osd());
QStringList profiles;
if (!SelectProfileForm::getUserProfiles(profiles, msg)) {
((t_gui *)ui)->cb_show_msg(this, msg.toStdString(), MSG_CRITICAL);
}
profileListView->clear();
for (QStringList::Iterator i = profiles.begin(); i != profiles.end(); i++) {
// Strip off the .cfg suffix
QString profile = *i;
profile.truncate(profile.length() - 4);
QListWidgetItem* item = new QListWidgetItem(profile, profileListView);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
item->setData(Qt::DecorationRole, QPixmap(":/icons/images/penguin-small.png"));
list<string> l = sys_config->get_start_user_profiles();
if (std::find(l.begin(), l.end(), profile.toStdString()) != l.end())
{
item->setCheckState(Qt::Checked);
}
}
// Web browser command
browserLineEdit->setText(sys_config->get_gui_browser_cmd().c_str());
// Network settings
sipUdpPortSpinBox->setValue(sys_config->get_config_sip_port());
rtpPortSpinBox->setValue(sys_config->get_rtp_port());
maxUdpSizeLineEdit->setText(QString::number(sys_config->get_sip_max_udp_size()));
maxTcpSizeLineEdit->setText(QString::number(sys_config->get_sip_max_tcp_size()));
// Ring tone settings
playRingtoneCheckBox->setChecked(sys_config->get_play_ringtone());
defaultRingtoneRadioButton->setChecked(sys_config->get_ringtone_file().empty());
customRingtoneRadioButton->setChecked(!sys_config->get_ringtone_file().empty());
ringtoneLineEdit->setText(sys_config->get_ringtone_file().c_str());
defaultRingtoneRadioButton->setEnabled(sys_config->get_play_ringtone());
customRingtoneRadioButton->setEnabled(sys_config->get_play_ringtone());
ringtoneLineEdit->setEnabled(!sys_config->get_ringtone_file().empty());
openRingtoneToolButton->setEnabled(!sys_config->get_ringtone_file().empty());
playRingbackCheckBox->setChecked(sys_config->get_play_ringback());
defaultRingbackRadioButton->setChecked(sys_config->get_ringback_file().empty());
customRingbackRadioButton->setChecked(!sys_config->get_ringback_file().empty());
ringbackLineEdit->setText(sys_config->get_ringback_file().c_str());
defaultRingbackRadioButton->setEnabled(sys_config->get_play_ringback());
customRingbackRadioButton->setEnabled(sys_config->get_play_ringback());
ringbackLineEdit->setEnabled(!sys_config->get_ringback_file().empty());
openRingbackToolButton->setEnabled(!sys_config->get_ringback_file().empty());
// Address book settings
abLookupNameCheckBox->setChecked(sys_config->get_ab_lookup_name());
abOverrideDisplayCheckBox->setChecked(sys_config->get_ab_override_display());
abOverrideDisplayCheckBox->setEnabled(sys_config->get_ab_lookup_name());
abLookupPhotoCheckBox->setChecked(sys_config->get_ab_lookup_photo());
}
void SysSettingsForm::validate()
{
bool conversion_ok = false;
unsigned short sip_max_udp_size = maxUdpSizeLineEdit->text().toUShort(&conversion_ok);
if (!conversion_ok) sip_max_udp_size = sys_config->get_sip_max_udp_size();
unsigned long sip_max_tcp_size = maxTcpSizeLineEdit->text().toULong(&conversion_ok);
if (!conversion_ok) sip_max_tcp_size = sys_config->get_sip_max_tcp_size();
// Audio
string dev;
dev = comboItem2audio_dev(ringtoneComboBox->currentText(), otherRingtoneLineEdit, true);
if (dev != "") sys_config->set_dev_ringtone(sys_config->audio_device(dev));
dev = comboItem2audio_dev(speakerComboBox->currentText(), otherSpeakerLineEdit, true);
if (dev != "") sys_config->set_dev_speaker(sys_config->audio_device(dev));
dev = comboItem2audio_dev(micComboBox->currentText(), otherMicLineEdit, false);
if (dev != "") sys_config->set_dev_mic(sys_config->audio_device(dev));
sys_config->set_validate_audio_dev(validateAudioCheckBox->isChecked());
sys_config->set_oss_fragment_size(
ossFragmentComboBox->currentText().toInt());
sys_config->set_alsa_play_period_size(
alsaPlayPeriodComboBox->currentText().toInt());
sys_config->set_alsa_capture_period_size(
alsaCapturePeriodComboBox->currentText().toInt());
// Log
sys_config->set_log_max_size(logMaxSizeSpinBox->value());
sys_config->set_log_show_debug(logDebugCheckBox->isChecked());
sys_config->set_log_show_sip(logSipCheckBox->isChecked());
sys_config->set_log_show_stun(logStunCheckBox->isChecked());
sys_config->set_log_show_memory(logMemoryCheckBox->isChecked());
// General
sys_config->set_gui_use_systray(guiUseSystrayCheckBox->isChecked());
sys_config->set_gui_hide_on_close(guiHideCheckBox->isChecked());
sys_config->set_gui_show_call_osd(osdCheckBox->isChecked());
// Auto show on incoming call
sys_config->set_gui_auto_show_incoming(autoShowCheckBox->isChecked());
sys_config->set_gui_auto_show_timeout(autoShowTimeoutSpinBox->value());
// Call history
sys_config->set_ch_max_size(histSizeSpinBox->value());
// Services
sys_config->set_call_waiting(callWaitingCheckBox->isChecked());
sys_config->set_hangup_both_3way(hangupBothCheckBox->isChecked());
// Startup
sys_config->set_start_hidden(startHiddenCheckBox->isChecked() &&
guiUseSystrayCheckBox->isChecked());
list<string> start_user_profiles;
for (int i = 0; i < profileListView->count(); i++)
{
QListWidgetItem *item = profileListView->item(i);
if (item->checkState() == Qt::Checked)
start_user_profiles.push_back(item->text().toStdString());
}
sys_config->set_start_user_profiles(start_user_profiles);
// Web browser command
sys_config->set_gui_browser_cmd(browserLineEdit->text().trimmed().toStdString());
// Network
if (sys_config->get_config_sip_port() != sipUdpPortSpinBox->value()) {
sys_config->set_config_sip_port(sipUdpPortSpinBox->value());
emit sipUdpPortChanged();
}
if (sys_config->get_rtp_port() != rtpPortSpinBox->value()) {
sys_config->set_rtp_port(rtpPortSpinBox->value());
emit rtpPortChanged();
}
sys_config->set_sip_max_udp_size(sip_max_udp_size);
sys_config->set_sip_max_tcp_size(sip_max_tcp_size);
// Ring tones
sys_config->set_play_ringtone(playRingtoneCheckBox->isChecked());
if (sys_config->get_play_ringtone()) {
if (defaultRingtoneRadioButton->isChecked()) {
sys_config->set_ringtone_file("");
} else {
sys_config->set_ringtone_file(ringtoneLineEdit->
text().trimmed().toStdString());
}
} else {
sys_config->set_ringtone_file("");
}
sys_config->set_play_ringback(playRingbackCheckBox->isChecked());
if (sys_config->get_play_ringback()) {
if (defaultRingbackRadioButton->isChecked()) {
sys_config->set_ringback_file("");
} else {
sys_config->set_ringback_file(ringbackLineEdit->
text().trimmed().toStdString());
}
} else {
sys_config->set_ringback_file("");
}
// Address book settings
sys_config->set_ab_lookup_name(abLookupNameCheckBox->isChecked());
sys_config->set_ab_override_display(abOverrideDisplayCheckBox->isChecked());
sys_config->set_ab_lookup_photo(abLookupPhotoCheckBox->isChecked());
// Save user config
string error_msg;
if (!sys_config->write_config(error_msg)) {
// Failed to write config file
((t_gui *)ui)->cb_show_msg(this, error_msg, MSG_CRITICAL);
return;
}
accept();
}
void SysSettingsForm::show()
{
populate();
QDialog::show();
}
int SysSettingsForm::exec()
{
populate();
return QDialog::exec();
}
void SysSettingsForm::chooseRingtone()
{
QString file = QFileDialog::getOpenFileName(this, tr("Choose ring tone"),
((t_gui *)ui)->get_last_file_browse_path(),
tr("Ring tones", "Description of .wav files in file dialog").append(" (*.wav)"));
if (!file.isEmpty()) {
ringtoneLineEdit->setText(file);
((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).absolutePath());
}
}
void SysSettingsForm::chooseRingback()
{
QString file = QFileDialog::getOpenFileName(this, tr("Choose ring back tone"),
((t_gui *)ui)->get_last_file_browse_path(),
tr("Ring back tones", "Description of .wav files in file dialog").append(" (*.wav)"));
if (!file.isEmpty()) {
ringbackLineEdit->setText(file);
((t_gui *)ui)->set_last_file_browse_path(QFileInfo(file).absolutePath());
}
}
void SysSettingsForm::devRingtoneSelected(int idx) {
bool b = (idx == idxOtherPlaybackDevAlsa || idx == idxOtherPlaybackDevOss);
otherRingtoneTextLabel->setEnabled(b);
otherRingtoneLineEdit->setEnabled(b);
}
void SysSettingsForm::devSpeakerSelected(int idx) {
bool b = (idx == idxOtherPlaybackDevAlsa || idx == idxOtherPlaybackDevOss);
otherSpeakerTextLabel->setEnabled(b);
otherSpeakerLineEdit->setEnabled(b);
}
void SysSettingsForm::devMicSelected(int idx) {
bool b = (idx == idxOtherCaptureDevAlsa || idx == idxOtherCaptureDevOss);
otherMicTextLabel->setEnabled(b);
otherMicLineEdit->setEnabled(b);
}
void SysSettingsForm::playRingToneCheckBoxToggles(bool on) {
if (on) {
ringtoneLineEdit->setEnabled(customRingtoneRadioButton->isChecked());
} else {
ringtoneLineEdit->setEnabled(false);
}
}
void SysSettingsForm::playRingBackToneCheckBoxToggles(bool on) {
if (on) {
ringbackLineEdit->setEnabled(customRingbackRadioButton->isChecked());
} else {
ringbackLineEdit->setEnabled(false);
}
}
|