/*************************************************************************** * Copyright (C) 2016 by Savoir-faire Linux * * Author: Edric Ladent Milaret * * Author: Stepan Salenikovich * * * * 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 3 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 . * **************************************************************************/ #include "qualitydialog.h" #include "ui_qualitydialog.h" #include "callmodel.h" #include "account.h" #include "audio/codecmodel.h" #include QualityDialog::QualityDialog(QWidget *parent) : QDialog(parent), ui(new Ui::QualityDialog) { ui->setupUi(this); this->setWindowFlags(Qt::CustomizeWindowHint); this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); } QualityDialog::~QualityDialog() { delete ui; } void QualityDialog::on_autoCheckBox_toggled(bool checked) { setQuality(); ui->qualitySlider->setEnabled(not checked); } void QualityDialog::on_qualitySlider_sliderReleased() { setQuality(); } void QualityDialog::showEvent(QShowEvent* event) { QWidget::showEvent(event); ui->autoCheckBox->blockSignals(true); const auto& call = CallModel::instance().selectedCall(); if (const auto& codecModel = call->account()->codecModel()) { const auto& videoCodecs = codecModel->videoCodecs(); if (videoCodecs->rowCount() > 0) { /* we only need to check the first codec since by default it is ON for all, and the * client sets its ON or OFF for all codecs as well */ const auto& idx = videoCodecs->index(0,0); auto auto_quality_enabled = idx.data(static_cast(CodecModel::Role::AUTO_QUALITY_ENABLED)).toString() == "true"; ui->autoCheckBox->setChecked(auto_quality_enabled); ui->qualitySlider->setEnabled(not auto_quality_enabled); // TODO: save the manual quality setting in the client and set the slider to that value here; // the daemon resets the bitrate/quality between each call, and the default may be // different for each codec, so there is no reason to check it here } } ui->autoCheckBox->blockSignals(false); } void QualityDialog::setQuality() { /* set auto quality true or false, also set the bitrate and quality values; * the slider is from 0 to 100, use the min and max vals to scale each value accordingly */ const auto& call = CallModel::instance().selectedCall(); if (const auto& codecModel = call->account()->codecModel()) { const auto& videoCodecs = codecModel->videoCodecs(); for (int i=0; i < videoCodecs->rowCount();i++) { const auto& idx = videoCodecs->index(i,0); if (ui->autoCheckBox->isChecked()) { videoCodecs->setData(idx, "true", CodecModel::Role::AUTO_QUALITY_ENABLED); } else { auto min_bitrate = idx.data(static_cast(CodecModel::Role::MIN_BITRATE)).toInt(); auto max_bitrate = idx.data(static_cast(CodecModel::Role::MAX_BITRATE)).toInt(); auto min_quality = idx.data(static_cast(CodecModel::Role::MIN_QUALITY)).toInt(); auto max_quality = idx.data(static_cast(CodecModel::Role::MAX_QUALITY)).toInt(); double bitrate; bitrate = min_bitrate + (double)(max_bitrate - min_bitrate)*(ui->qualitySlider->value()/100.0); if (bitrate < 0) bitrate = 0; double quality; // note: a lower value means higher quality quality = (double)min_quality - (min_quality - max_quality)*(ui->qualitySlider->value()/100.0); if (quality < 0) quality = 0; videoCodecs->setData(idx, "false", CodecModel::Role::AUTO_QUALITY_ENABLED); videoCodecs->setData(idx, QString::number((int)bitrate), CodecModel::Role::BITRATE); videoCodecs->setData(idx, QString::number((int)quality), CodecModel::Role::QUALITY); } } codecModel << CodecModel::EditAction::SAVE; } }