#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 #include #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(); }