Subversion Repositories tpanel

Rev

Rev 140 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 140 Rev 141
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
2
 * Copyright (C) 2020, 2022 by Andreas Theofilu <andreas@theosys.at>
3
 *
3
 *
4
 * This program is free software; you can redistribute it and/or modify
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
7
 * (at your option) any later version.
Line 16... Line 16...
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
17
 */
18
#include <QFileDialog>
18
#include <QFileDialog>
19
#include <QComboBox>
19
#include <QComboBox>
20
#include <QMessageBox>
20
#include <QMessageBox>
-
 
21
#include <QAudioOutput>
21
 
22
 
22
#include <unistd.h>
23
#include <unistd.h>
23
 
24
 
24
#include "tqtsettings.h"
25
#include "tqtsettings.h"
-
 
26
#include "tdirectory.h"
-
 
27
#include "tresources.h"
-
 
28
#include "tpagemanager.h"
25
#include "terror.h"
29
#include "terror.h"
-
 
30
#include "tqtplaysound.h"
26
#include "ui_tqtsettings.h"
31
#include "ui_tqtsettings.h"
27
 
32
 
28
#ifdef __ANDROID__
33
#ifdef __ANDROID__
29
#include <QtAndroidExtras/QAndroidJniObject>
34
#include <QtAndroidExtras/QAndroidJniObject>
30
#include <QtAndroid>
35
#include <QtAndroid>
Line 43... Line 48...
43
#define RLOG_PROTOCOL       0x00f8
48
#define RLOG_PROTOCOL       0x00f8
44
#define RLOG_ALL            0x00e0
49
#define RLOG_ALL            0x00e0
45
 
50
 
46
using std::string;
51
using std::string;
47
using std::vector;
52
using std::vector;
-
 
53
using std::sort;
-
 
54
 
-
 
55
extern TPageManager *gPageManager;
48
 
56
 
49
TQtSettings::TQtSettings(QWidget *parent)
57
TQtSettings::TQtSettings(QWidget *parent)
50
	: QDialog(parent),
58
	: QDialog(parent),
51
	  ui(new Ui::TQtSettings)
59
	  ui(new Ui::TQtSettings)
52
{
60
{
Line 138... Line 146...
138
            fwIdx = 0;
146
            fwIdx = 0;
139
    }
147
    }
140
 
148
 
141
    ui->comboBox_SIPfirewall->setCurrentIndex(fwIdx);
149
    ui->comboBox_SIPfirewall->setCurrentIndex(fwIdx);
142
    ui->checkBox_SIPenabled->setCheckState((TConfig::getSIPstatus() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
150
    ui->checkBox_SIPenabled->setCheckState((TConfig::getSIPstatus() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
-
 
151
 
-
 
152
    // Sound settings
-
 
153
    string sySound = TConfig::getSystemSound();
-
 
154
    size_t pos = sySound.find_last_of(".");
-
 
155
    int numpos;
-
 
156
 
-
 
157
    if (pos != string::npos)
-
 
158
        numpos = atoi(sySound.substr(pos - 2, 2).c_str());
-
 
159
 
-
 
160
    dir::TDirectory dir;
-
 
161
    int num = dir.readDir(TConfig::getProjectPath() + "/__system/graphics/sounds");
-
 
162
    vector<string> tmpFiles;
-
 
163
 
-
 
164
    for (int i = 0; i < num; i++)
-
 
165
    {
-
 
166
        dir::DFILES_T entry = dir.getEntry(i);
-
 
167
        pos = entry.name.find_last_of("/");
-
 
168
        string file;
-
 
169
 
-
 
170
        if (pos != string::npos)
-
 
171
            file = entry.name.substr(pos + 1);
-
 
172
 
-
 
173
        if ((pos = file.find_last_of(".")) != string::npos)
-
 
174
            file = file.substr(0, pos);
-
 
175
 
-
 
176
        if (startsWith(file, "singleBeep"))
-
 
177
            tmpFiles.push_back(file);
-
 
178
    }
-
 
179
 
-
 
180
    sort(tmpFiles.begin(), tmpFiles.end());
-
 
181
    vector<string>::iterator iter;
-
 
182
 
-
 
183
    for (iter = tmpFiles.begin(); iter != tmpFiles.end(); ++iter)
-
 
184
        ui->comboBox_SystemSound->addItem(iter->c_str());
-
 
185
 
-
 
186
    ui->comboBox_SystemSound->setCurrentIndex(numpos);
-
 
187
 
-
 
188
    string siBeep = TConfig::getSingleBeepSound();
-
 
189
    pos = siBeep.find_last_of(".");
-
 
190
 
-
 
191
    if (pos != string::npos)
-
 
192
    {
-
 
193
        int num = atoi(siBeep.substr(pos - 2, 2).c_str());
-
 
194
 
-
 
195
        if (num > 0)
-
 
196
            siBeep = "Single Beep " + std::to_string(num);
-
 
197
    }
-
 
198
 
-
 
199
    int sel = 0;
-
 
200
 
-
 
201
    for (int i = 1; i <= 10; i++)
-
 
202
    {
-
 
203
        QString e = QString("Single Beep %1").arg(i);
-
 
204
        ui->comboBox_SingleBeep->addItem(e);
-
 
205
 
-
 
206
        if (e == QString(siBeep.c_str()))
-
 
207
            sel = i - 1;
-
 
208
    }
-
 
209
 
-
 
210
    ui->comboBox_SingleBeep->setCurrentIndex(sel);
-
 
211
 
-
 
212
    string siDBeep = TConfig::getDoubleBeepSound();
-
 
213
    pos = siDBeep.find_last_of(".");
-
 
214
 
-
 
215
    if (pos != string::npos)
-
 
216
    {
-
 
217
        int num = atoi(siDBeep.substr(pos - 2, 2).c_str());
-
 
218
 
-
 
219
        if (num > 0)
-
 
220
            siBeep = "Double Beep " + std::to_string(num);
-
 
221
    }
-
 
222
 
-
 
223
    sel = 0;
-
 
224
 
-
 
225
    for (int i = 1; i <= 10; i++)
-
 
226
    {
-
 
227
        QString e = QString("Double Beep %1").arg(i);
-
 
228
        ui->comboBox_DoubleBeep->addItem(e);
-
 
229
 
-
 
230
        if (e == QString(siBeep.c_str()))
-
 
231
            sel = i - 1;
-
 
232
    }
-
 
233
 
-
 
234
    ui->comboBox_DoubleBeep->setCurrentIndex(sel);
-
 
235
    ui->checkBox_SystemSound->setCheckState((TConfig::getSystemSoundState() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked));
-
 
236
 
-
 
237
    int volume = TConfig::getSystemVolume();
-
 
238
    int gain = TConfig::getSystemGain();
-
 
239
    ui->horizontalSlider_Volume->setValue(volume);
-
 
240
    ui->horizontalSlider_Gain->setValue(gain);
-
 
241
 
143
#ifdef __ANDROID__
242
#ifdef __ANDROID__
144
    ui->tabWidget->setPalette(qt_fusionPalette());
243
    ui->tabWidget->setPalette(qt_fusionPalette());
145
    ui->tabCtrl->setPalette(qt_fusionPalette());
244
    ui->tabCtrl->setPalette(qt_fusionPalette());
146
    ui->tabLog->setPalette(qt_fusionPalette());
245
    ui->tabLog->setPalette(qt_fusionPalette());
147
    ui->tabSIP->setPalette(qt_fusionPalette());
246
    ui->tabSIP->setPalette(qt_fusionPalette());
Line 344... Line 443...
344
                                scaleObject(dynamic_cast<QLineEdit *>(on));
443
                                scaleObject(dynamic_cast<QLineEdit *>(on));
345
                            else if (n.startsWith("spinBox"))
444
                            else if (n.startsWith("spinBox"))
346
                                scaleObject(dynamic_cast<QSpinBox *>(on));
445
                                scaleObject(dynamic_cast<QSpinBox *>(on));
347
                            else if (n.startsWith("comboBox"))
446
                            else if (n.startsWith("comboBox"))
348
                                scaleObject(dynamic_cast<QComboBox *>(on));
447
                                scaleObject(dynamic_cast<QComboBox *>(on));
-
 
448
                            else if (n.startsWith("horizontalSlider") || n.startsWith("verticalSlider"))
-
 
449
                                scaleObject(dynamic_cast<QSlider *>(on));
349
                            else if (n.startsWith("label"))
450
                            else if (n.startsWith("label"))
350
                            {
451
                            {
351
                                scaleObject(dynamic_cast<QLabel *>(on));
452
                                scaleObject(dynamic_cast<QLabel *>(on));
352
#ifdef __ANDROID__
453
#ifdef __ANDROID__
353
                                QLabel *lb = dynamic_cast<QLabel *>(on);
454
                                QLabel *lb = dynamic_cast<QLabel *>(on);
Line 918... Line 1019...
918
        return;
1019
        return;
919
 
1020
 
920
    mSetChanged = true;
1021
    mSetChanged = true;
921
    TConfig::setSIPiphone(checked);
1022
    TConfig::setSIPiphone(checked);
922
}
1023
}
-
 
1024
 
-
 
1025
void TQtSettings::on_comboBox_SystemSound_currentIndexChanged(const QString& arg1)
-
 
1026
{
-
 
1027
    DECL_TRACER("TQtSettings::on_comboBox_SystemSound_currentIndexChanged(const QString& arg1)");
-
 
1028
 
-
 
1029
    if (arg1.compare(TConfig::getSystemSound().c_str()) == 0)
-
 
1030
        return;
-
 
1031
 
-
 
1032
    mSetChanged = true;
-
 
1033
    TConfig::saveSystemSoundFile(arg1.toStdString() + ".wav");
-
 
1034
}
-
 
1035
 
-
 
1036
void TQtSettings::on_toolButton_SystemSound_clicked()
-
 
1037
{
-
 
1038
    DECL_TRACER("TQtSettings::on_toolButton_SystemSound_clicked()");
-
 
1039
 
-
 
1040
    QString selected = ui->comboBox_SystemSound->currentText();
-
 
1041
    string file = TConfig::getProjectPath() + "/__system/graphics/sounds/" + selected.toStdString() + ".wav";
-
 
1042
 
-
 
1043
    if (gPageManager)
-
 
1044
        gPageManager->getCallPlaySound()(file);
-
 
1045
}
-
 
1046
 
-
 
1047
void TQtSettings::on_comboBox_SingleBeep_currentIndexChanged(const QString& arg1)
-
 
1048
{
-
 
1049
    DECL_TRACER("TQtSettings::on_comboBox_SingleBeep_currentIndexChanged(const QString& arg1)");
-
 
1050
 
-
 
1051
    if (arg1.compare(TConfig::getSingleBeepSound().c_str()) == 0)
-
 
1052
        return;
-
 
1053
 
-
 
1054
    string file = arg1.toStdString();
-
 
1055
    size_t pos = file.find_last_of(" ");
-
 
1056
 
-
 
1057
    if (pos != string::npos)
-
 
1058
    {
-
 
1059
        int num = atoi(file.substr(pos).c_str());
-
 
1060
        file = "singleBeep";
-
 
1061
 
-
 
1062
        if (num > 0)
-
 
1063
        {
-
 
1064
            if (num < 10)
-
 
1065
                file += "0" + std::to_string(num);
-
 
1066
            else
-
 
1067
                file += std::to_string(num);
-
 
1068
        }
-
 
1069
 
-
 
1070
        file += ".wav";
-
 
1071
    }
-
 
1072
 
-
 
1073
    mSetChanged = true;
-
 
1074
    TConfig::saveSingleBeepFile(file);
-
 
1075
}
-
 
1076
 
-
 
1077
void TQtSettings::on_toolButton_SingleBeep_clicked()
-
 
1078
{
-
 
1079
    DECL_TRACER("TQtSettings::on_toolButton_SingleBeep_clicked()");
-
 
1080
 
-
 
1081
    QString selected = ui->comboBox_SingleBeep->currentText();
-
 
1082
    string file = selected.toStdString();
-
 
1083
    size_t pos = file.find_last_of(" ");
-
 
1084
 
-
 
1085
    if (pos != string::npos)
-
 
1086
    {
-
 
1087
        int num = atoi(file.substr(pos).c_str());
-
 
1088
        file = TConfig::getProjectPath() + "/__system/graphics/sounds/singleBeep";
-
 
1089
 
-
 
1090
        if (num > 0)
-
 
1091
        {
-
 
1092
            if (num < 10)
-
 
1093
                file += "0" + std::to_string(num);
-
 
1094
            else
-
 
1095
                file += std::to_string(num);
-
 
1096
        }
-
 
1097
 
-
 
1098
        file += ".wav";
-
 
1099
    }
-
 
1100
 
-
 
1101
//    playFile(file);
-
 
1102
 
-
 
1103
    if (gPageManager)
-
 
1104
        gPageManager->getCallPlaySound()(file);
-
 
1105
}
-
 
1106
 
-
 
1107
void TQtSettings::on_comboBox_DoubleBeep_currentIndexChanged(const QString& arg1)
-
 
1108
{
-
 
1109
    DECL_TRACER("TQtSettings::on_comboBox_DoubleBeep_currentIndexChanged(const QString& arg1)");
-
 
1110
 
-
 
1111
    if (arg1.compare(TConfig::getDoubleBeepSound().c_str()) == 0)
-
 
1112
        return;
-
 
1113
 
-
 
1114
    string file = arg1.toStdString();
-
 
1115
    size_t pos = file.find_last_of(" ");
-
 
1116
 
-
 
1117
    if (pos != string::npos)
-
 
1118
    {
-
 
1119
        int num = atoi(file.substr(pos).c_str());
-
 
1120
        file = "doubleBeep";
-
 
1121
 
-
 
1122
        if (num > 0)
-
 
1123
        {
-
 
1124
            if (num < 10)
-
 
1125
                file += "0" + std::to_string(num);
-
 
1126
            else
-
 
1127
                file += std::to_string(num);
-
 
1128
        }
-
 
1129
 
-
 
1130
        file += ".wav";
-
 
1131
    }
-
 
1132
 
-
 
1133
    mSetChanged = true;
-
 
1134
    TConfig::saveDoubleBeepFile(file);
-
 
1135
}
-
 
1136
 
-
 
1137
void TQtSettings::on_toolButton_DoubleBeep_clicked()
-
 
1138
{
-
 
1139
    DECL_TRACER("TQtSettings::on_toolButton_DoubleBeep_clicked()");
-
 
1140
 
-
 
1141
    QString selected = ui->comboBox_DoubleBeep->currentText();
-
 
1142
    string file = selected.toStdString();
-
 
1143
    size_t pos = file.find_last_of(" ");
-
 
1144
 
-
 
1145
    if (pos != string::npos)
-
 
1146
    {
-
 
1147
        int num = atoi(file.substr(pos).c_str());
-
 
1148
        file = TConfig::getProjectPath() + "/__system/graphics/sounds/doubleBeep";
-
 
1149
 
-
 
1150
        if (num > 0)
-
 
1151
        {
-
 
1152
            if (num < 10)
-
 
1153
                file += "0" + std::to_string(num);
-
 
1154
            else
-
 
1155
                file += std::to_string(num);
-
 
1156
        }
-
 
1157
 
-
 
1158
        file += ".wav";
-
 
1159
    }
-
 
1160
 
-
 
1161
 
-
 
1162
//    playFile(file);
-
 
1163
 
-
 
1164
    if (gPageManager)
-
 
1165
        gPageManager->getCallPlaySound()(file);
-
 
1166
}
-
 
1167
 
-
 
1168
void TQtSettings::on_checkBox_SystemSound_toggled(bool checked)
-
 
1169
{
-
 
1170
    DECL_TRACER("TQtSettings::on_checkBox_SystemSound_toggled(bool checked)");
-
 
1171
 
-
 
1172
    if (TConfig::getSystemSoundState() == checked)
-
 
1173
        return;
-
 
1174
 
-
 
1175
    mSetChanged = true;
-
 
1176
    TConfig::saveSystemSoundState(checked);
-
 
1177
}
-
 
1178
 
-
 
1179
void TQtSettings::on_toolButton_TestSound_clicked()
-
 
1180
{
-
 
1181
    DECL_TRACER("TQtSettings::on_toolButton_TestSound_clicked()");
-
 
1182
 
-
 
1183
    if (gPageManager)
-
 
1184
        gPageManager->getCallPlaySound()(TConfig::getProjectPath() + "/__system/graphics/sounds/audioTest.wav");
-
 
1185
}
-
 
1186
 
-
 
1187
void TQtSettings::on_horizontalSlider_Volume_valueChanged(int value)
-
 
1188
{
-
 
1189
    DECL_TRACER("TQtSettings::on_horizontalSlider_Volume_valueChanged(int value)");
-
 
1190
 
-
 
1191
    if (TConfig::getSystemVolume() == value)
-
 
1192
        return;
-
 
1193
 
-
 
1194
    TConfig::saveSystemVolume(value);
-
 
1195
}
-
 
1196
 
-
 
1197
void TQtSettings::on_horizontalSlider_Gain_valueChanged(int value)
-
 
1198
{
-
 
1199
    DECL_TRACER("TQtSettings::on_horizontalSlider_Gain_valueChanged(int value)");
-
 
1200
 
-
 
1201
    if (TConfig::getSystemGain() == value)
-
 
1202
        return;
-
 
1203
 
-
 
1204
    TConfig::saveSystemGain(value);
-
 
1205
}