isettingwidget.cpp
10.1 KB
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
#include "isettingwidget.h"
#include "ui_isettingwidget.h"
#include "downloadfile.h"
#include "iwebRequest.h"
#include "grape/zmf.h"
#include "avatar/zos/zos_type.h"
#include "lemon/service/rcs/mtc_cli.h"
#include "lemon/service/rcs/mtc_call.h"
#include "lemon/service/rcs/mtc_cli_cfg.h"
#include "lemon/service/rcs/mtc_cli_cb.h"
#include "lemon/service/rcs/mtc_ue.h"
#include "lemon/service/rcs/mtc_ue_db.h"
#include "lemon/service/rcs/mtc_user.h"
#include "lemon/service/rcs/mtc_prof.h"
#include "lemon/service/rcs/mtc_prov_db.h"
#include "lemon/service/rcs/mtc_media.h"
#include "lemon/service/rcs/mtc_mdm.h"
#include "lemon/service/rcs/mtc_call_db.h"
#include "JusDoodle/DoodleManager.h"
#include "JusCall/CallManager.h"
#include "GlobalSetting.h"
#include <QDebug>
#include <QMessageBox>
#define MIC_CONFIG_NAME "MyMic"
#define SPK_CONFIG_NAME "MySpk"
#define CAM_CONFIG_NAME "MyCam"
ISettingWidget::ISettingWidget(QWidget *parent) :
BaseMainWidget(parent),
ui(new Ui::ISettingWidget)
{
ui->setupUi(this);
connect(ui->pushButton_accounts, SIGNAL(clicked()), this, SLOT(changeStackWidget()));
connect(ui->pushButton_general, SIGNAL(clicked()), this, SLOT(changeStackWidget()));
ui->pushButton_accounts->setChecked(true);
currentButton = ui->pushButton_accounts;
// init audio and video interfaces
Zmf_AudioInitialize((void *)winId());
Zmf_VideoInitialize((void *)winId());
QStringList names;
QStringList ids;
char acName[512];
char acId[512];
int i;
int count;
// add micphone
count = Zmf_AudioInputGetCount();
for (i = 0, names.clear(), ids.clear(); i< count; i++)
{
Zmf_AudioInputGetName(i, acId, acName);
names << QString::fromUtf8(acName);
ids << QString::fromUtf8(acId);
}
initDeivce(ui->comboBox_mic, names, ids, MIC_CONFIG_NAME);
count = Zmf_VideoCaptureGetCount();
for (i = 0, names.clear(), ids.clear(); i< count; i++)
{
Zmf_VideoCaptureGetName(i, acId, acName);
names << QString::fromUtf8(acName);
ids << QString::fromUtf8(acId);
}
initDeivce(ui->comboBox_camera, names, ids, CAM_CONFIG_NAME);
connect(ui->comboBox_mic, SIGNAL(currentIndexChanged(int)), this,SLOT(onMicphoneChanged(int)));
connect(ui->comboBox_camera, SIGNAL(currentIndexChanged(int)), this,SLOT(onCameraChanged(int)));
//通讯消息注册
IWebRequest *webrequest = IWebRequest::Instance();
connect(webrequest, SIGNAL(response(int,int,QString,QString)), this, SLOT(doResponse(int,int,QString,QString)));
ui->label_header->setStyleSheet("background-color:rgb(200,200,200)");
ui->horizontalSlider_volume->setValue(Mtc_CallGetSpkVol(RCallManager::Instance()->getSessId()));
readConfig();//读取配置
}
void ISettingWidget::initDeivce(QComboBox *box, const QStringList &names, const QStringList &ids,
const char *configName)
{
QStringList::const_iterator itName;
QStringList::const_iterator itId;
for (itName = names.begin(), itId = ids.begin(); itName != names.end(); itName++, itId++)
{
box->addItem(*itName, *itId);
}
QString value = _GlobalSetting.readConfigValue(configName);
int selectIndex = box->findData(value);
if (selectIndex != - 1)
{
box->setCurrentIndex(selectIndex);
}
else if (ids.count())
{
box->setCurrentIndex(0);
_GlobalSetting.writeConfigValue(configName, ids[0]);
}
}
void ISettingWidget::changeStackWidget()
{
QPushButton *button = (QPushButton *)sender();
if(!button)
{
return;
}
if(button->objectName().contains("pushButton_accounts"))
{
ui->stackedWidget->setCurrentIndex(0);
}
else if(button->objectName().contains("pushButton_general"))
{
ui->stackedWidget->setCurrentIndex(1);
}
if(currentButton != button)
{
currentButton->setChecked(false);
currentButton = button;
}
currentButton->setChecked(true);
}
ISettingWidget::~ISettingWidget()
{
delete ui;
}
void ISettingWidget::on_pushButton_clicked()
{
this->hide();
}
void ISettingWidget::onMicphoneChanged(int currentIndex)
{
if (currentIndex != -1)
{
QString id = ui->comboBox_mic->itemData(currentIndex).toString();
RCallManager::Instance()->setMicphone(id);
_GlobalSetting.writeConfigValue(MIC_CONFIG_NAME, id);
}
}
//void JustTalkTest::onSpeakerChanged(int currentIndex)
//{
// if (currentIndex != -1)
// {
//// QString id = ui->speakerBox->itemData(currentIndex).toString();
//// RCallManager::Instance()->setSpeaker(id);
//// Mtc_ProvDbSetExtnParm((char *)SPK_CONFIG_NAME, id.toUtf8().data());
// }
//}
void ISettingWidget::doResponse(int cmd,int code,QString ,QString)
{
switch(cmd)
{
case REQ_USER_GET:
{
qDebug() << "void ISettingWidget::doResponse(int cmd,int code,QString ,QString)";
QString headerImg = QCoreApplication::applicationDirPath()+"/img/"+_GlobalSetting.userHeadImg.file_name+_GlobalSetting.userHeadImg.ext;
QFile file(headerImg);
if(file.exists()/* && file.size() == _GlobalSetting.userHeadImg.size*/)
{
ui->label_header->setPixmap(QPixmap(headerImg).scaled(90,90));
}
else
{
//userInfoTip->setHeaderImg(":/Images/Home/default.png");
ui->label_header->setPixmap(QPixmap(":/Images/Home/default.png").scaled(90,90));
IDownloadFile *downfile = IDownloadFile::Instance();
downfile->downloadFile(_GlobalSetting.userHeadImg.s_url, headerImg, _GlobalSetting.userHeadImg.file_id);
}
ui->label_nickname->setText(_GlobalSetting.userInfo.user_name);
break;
}
default:
break;
}
}
void ISettingWidget::show()
{
QStringList params;
IWebRequest::Instance()->sendRequestToServer(REQ_USER_GET, params);
QWidget::show();
}
void ISettingWidget::onCameraChanged(int currentIndex)
{
if (currentIndex != -1)
{
QString id = ui->comboBox_camera->itemData(currentIndex).toString();
RCallManager::Instance()->setSpeaker(id);
_GlobalSetting.writeConfigValue(CAM_CONFIG_NAME, id);
}
}
static int ChMessageOkCancel(QString info)
{
QMessageBox msg;
msg.setWindowTitle("Log Out");
msg.setText(info);
msg.setStyleSheet("color:rgb(220, 0, 0);font: 10pt");
//msg.setIcon(QMessageBox::Information);
msg.addButton("Ok",QMessageBox::ActionRole);
msg.addButton("Cancel",QMessageBox::ActionRole);
return msg.exec();
}
void ISettingWidget::on_pushButton_logout_clicked()
{
QMessageBox::StandardButton rb = QMessageBox::question(NULL, "Log Out", "You won't be prompted of any new messages and calls after logout. Log out?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if(rb == QMessageBox::Yes)
{
this->close();
QStringList params;
//1:在线 2:忙碌 3:离线
params << "4";
IWebRequest::Instance()->sendRequestToServer(REQ_LOGOUT, params);
// qApp->exit(773);
}
}
void ISettingWidget::on_horizontalSlider_volume_actionTriggered(int action)
{
Mtc_CallSetSpkVol(RCallManager::Instance()->getSessId(),action);
}
void ISettingWidget::readConfig()
{
QString filename = QCoreApplication::applicationDirPath() + QString("/config/settingConfig.ini");
//Qt中使用QSettings类读写ini文件
//QSettings构造函数的第一个参数是ini文件的路径,第二个参数表示针对ini文件,第三个参数可以缺省
QSettings *configIniRead = new QSettings(filename, QSettings::IniFormat);
//向ini文件中写入内容,setValue函数的两个参数是键值对
QString Remember = configIniRead->value("/user/bootRun").toString();
if(Remember.toInt())
{
ui->checkBox_boots->setChecked(true);
}
else
{
ui->checkBox_boots->setChecked(false);
}
QString username = configIniRead->value("/user/callPlay").toString();
if(username.toInt())
{
ui->checkBox_callsounds->setChecked(true);
}
else
{
ui->checkBox_callsounds->setChecked(false);
}
QString password = configIniRead->value("/user/messagePlay").toString();
if(password.toInt())
{
ui->checkBox_messagesounds->setChecked(true);
}
else
{
ui->checkBox_messagesounds->setChecked(false);
}
//写入完成后删除指针
delete configIniRead;
}
void ISettingWidget::writeConfig()
{
QString filename = QCoreApplication::applicationDirPath() + QString("/config/settingConfig.ini");
//Qt中使用QSettings类读写ini文件
//QSettings构造函数的第一个参数是ini文件的路径,第二个参数表示针对ini文件,第三个参数可以缺省
QSettings *configIniWrite = new QSettings(filename, QSettings::IniFormat);
//向ini文件中写入内容,setValue函数的两个参数是键值对
if(ui->checkBox_boots->isChecked())
configIniWrite->setValue("user/bootRun", 1);
else
configIniWrite->setValue("user/bootRun", 0);
if(ui->checkBox_callsounds->isChecked())
configIniWrite->setValue("user/callPlay", 1);
else
configIniWrite->setValue("user/callPlay", 0);
if(ui->checkBox_messagesounds->isChecked())
configIniWrite->setValue("user/messagePlay", 1);
else
configIniWrite->setValue("user/messagePlay", 0);
delete configIniWrite;
}
#define REG_RUN "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
void ISettingWidget::on_checkBox_boots_clicked(bool checked)
{
QString application_name = QApplication::applicationName();
QSettings *settings = new QSettings(REG_RUN, QSettings::NativeFormat);
if(checked)
{
QString application_path = QApplication::applicationFilePath();
settings->setValue(application_name, application_path.replace("/", "\\"));
}
else
{
settings->remove(application_name);
}
delete settings;
writeConfig();
}
void ISettingWidget::on_pushButton_6_clicked()
{
this->showMinimized();
}
void ISettingWidget::on_checkBox_callsounds_clicked(bool checked)
{
writeConfig();
}
void ISettingWidget::on_checkBox_messagesounds_clicked(bool checked)
{
writeConfig();
}