Commit 95263431 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk

refactor: change lrc interface and calling mechanism

- now only one method needed to get mutable newaccount model and dataTransfer model

Change-Id: I98d1e32010ee8b1c77fc258b1c3b7d147a102fcf
parent e64c7469
......@@ -155,21 +155,21 @@ AdvancedSettingsWidget::setCallsUntrusted(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.allowIncoming = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setAutoAnswerCalls(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.autoAnswer = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setEnableRingtone(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.Ringtone.ringtoneEnabled = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
......@@ -182,7 +182,7 @@ AdvancedSettingsWidget::openFileCustomRingtone()
if (!fileUrl.isEmpty()) {
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.Ringtone.ringtonePath = fileUrl.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
ui->btnRingtone->setText(QFileInfo(fileUrl).fileName());
} else if (oldPath.isEmpty()) {
ui->btnRingtone->setText(tr("Add a custom ringtone"));
......@@ -195,7 +195,7 @@ AdvancedSettingsWidget::setNameServer(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.RingNS.uri = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
// openDHT config
......@@ -204,7 +204,7 @@ AdvancedSettingsWidget::setEnableProxy(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.proxyEnabled = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
state ? ui->lineEditProxy->setEnabled(true) : ui->lineEditProxy->setEnabled(false);
}
......@@ -213,14 +213,14 @@ AdvancedSettingsWidget::setProxyAddress(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.proxyServer = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setBootstrapAddress(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.hostname = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
// security
......@@ -231,21 +231,21 @@ AdvancedSettingsWidget::setUseUPnP(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.upnpEnabled = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setUseTURN(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.enable = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setUseSTUN(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.STUN.enable = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
state ? ui->lineEditSTUNAddress->setEnabled(true) : ui->lineEditSTUNAddress->setEnabled(false);
}
......@@ -255,28 +255,28 @@ AdvancedSettingsWidget::setTURNAddress(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.server = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setTURNUsername(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.username = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setTURNPsswd(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.password = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
AdvancedSettingsWidget::setSTUNAddress(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.STUN.server = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void
......@@ -288,7 +288,7 @@ AdvancedSettingsWidget::openFileCACert()
if (!fileUrl.isEmpty()) {
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TLS.certificateListFile = fileUrl.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
ui->btnCACert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateListFile)).fileName());
}
......@@ -302,7 +302,7 @@ AdvancedSettingsWidget::openFileUserCert()
if (!fileUrl.isEmpty()) {
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TLS.certificateFile = fileUrl.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
ui->btnUserCert->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.certificateFile)).fileName());
}
......@@ -316,7 +316,7 @@ AdvancedSettingsWidget::openFilePrivateKey()
if (!fileUrl.isEmpty()) {
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TLS.privateKeyFile = fileUrl.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
ui->btnPrivateKey->setText(QFileInfo(QString::fromStdString(LRCInstance::getCurrAccConfig().TLS.privateKeyFile)).fileName());
}
......@@ -437,5 +437,5 @@ AdvancedSettingsWidget::setVideoState(int state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.Video.videoEnabled = (bool)state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
\ No newline at end of file
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
......@@ -125,13 +125,13 @@ void AdvancedSIPSettingsWidget::setAutoAnswerCalls(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.autoAnswer = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::setEnableRingtone(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.Ringtone.ringtoneEnabled = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::openFileCustomRingtone()
......@@ -144,7 +144,7 @@ void AdvancedSIPSettingsWidget::openFileCustomRingtone()
if (!fileUrl.isEmpty()) {
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.Ringtone.ringtonePath = fileUrl.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
ui->btnRingtoneSIP->setText(QFileInfo(fileUrl).fileName());
} else if (oldPath.isEmpty()) {
......@@ -157,19 +157,19 @@ void AdvancedSIPSettingsWidget::setUseUPnP(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.upnpEnabled = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::setUseTURN(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.enable = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::setUseSTUN(bool state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.STUN.enable = state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
state ? ui->lineEditSTUNAddressSIP->setEnabled(true) : ui->lineEditSTUNAddressSIP->setEnabled(false);
}
......@@ -178,25 +178,25 @@ void AdvancedSIPSettingsWidget::setTURNAddress(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.server = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::setTURNUsername(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.username = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::setTURNPsswd(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.TURN.password = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::setSTUNAddress(const QString& name)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.STUN.server = name.toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
void AdvancedSIPSettingsWidget::updateAudioCodecs()
......@@ -310,5 +310,5 @@ void AdvancedSIPSettingsWidget::setVideoState(int state)
{
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.Video.videoEnabled = (bool)state;
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
......@@ -55,6 +55,6 @@ DeleteAccountDialog::on_deleteCancelBtn_clicked()
void
DeleteAccountDialog::on_deleteAcceptBtn_clicked()
{
LRCInstance::editableAccountModel()->removeAccount(LRCInstance::getCurrAccId());
LRCInstance::accountModel().removeAccount(LRCInstance::getCurrAccId());
done(DialogCode::Accepted);
}
\ No newline at end of file
}
......@@ -85,7 +85,7 @@ DeviceItemWidget::toggleEditable()
ui->btnEditDevice->setToolTip(QObject::tr("Edit Device Name"));
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.deviceName = ui->editDeviceName->text().toStdString();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
}
editable_ = !editable_;
}
......@@ -94,4 +94,4 @@ QSize
DeviceItemWidget::sizeHint() const
{
return QSize();
}
\ No newline at end of file
}
......@@ -66,21 +66,15 @@ public:
static void connectivityChanged() {
instance().lrc_->connectivityChanged();
};
static const NewAccountModel& accountModel() {
static NewAccountModel& accountModel() {
return instance().lrc_->getAccountModel();
};
static NewAccountModel* editableAccountModel() {
return const_cast<NewAccountModel*>(&instance().lrc_->getAccountModel());
};
static const BehaviorController& behaviorController() {
static BehaviorController& behaviorController() {
return instance().lrc_->getBehaviorController();
};
static const DataTransferModel& dataTransferModel() {
static DataTransferModel& dataTransferModel() {
return instance().lrc_->getDataTransferModel();
};
static DataTransferModel* editableDataTransferModel() {
return const_cast<DataTransferModel*>(&instance().lrc_->getDataTransferModel());
};
static AVModel& avModel() {
return instance().lrc_->getAVModel();
};
......@@ -165,15 +159,15 @@ public:
bu.open(QIODevice::WriteOnly);
avatarPixmap.save(&bu, "PNG");
auto str = ba.toBase64().toStdString();
instance().editableAccountModel()->setAvatar(getCurrAccId(), str);
accountModel().setAvatar(getCurrAccId(), str);
};
static void setCurrAccAvatar(const std::string& avatar) {
instance().editableAccountModel()->setAvatar(getCurrAccId(), avatar);
accountModel().setAvatar(getCurrAccId(), avatar);
};
static void setCurrAccDisplayName(const std::string& alias) {
instance().editableAccountModel()->setAlias(getCurrAccId(), alias);
accountModel().setAlias(getCurrAccId(), alias);
};
static const account::ConfProperties_t& getCurrAccConfig() {
......
......@@ -309,7 +309,7 @@ void MainWindow::readSettingsFromRegistry()
restoreGeometry(settings.value(SettingsKey::geometry).toByteArray());
restoreState(settings.value(SettingsKey::windowState).toByteArray());
LRCInstance::editableDataTransferModel()->downloadDirectory = settings.value(SettingsKey::downloadPath,
LRCInstance::dataTransferModel().downloadDirectory = settings.value(SettingsKey::downloadPath,
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))
.toString()
.toStdString()
......
......@@ -38,7 +38,7 @@ NameRegistrationDialog::NameRegistrationDialog(const QString& nameToRegister, QW
connect(ui->btnCancel, &QPushButton::clicked, [this]() { reject(); });
connect(ui->btnCloseRegisterDialog, &QPushButton::clicked, [this]() { reject(); });
connect(LRCInstance::editableAccountModel(), &lrc::api::NewAccountModel::nameRegistrationEnded,
connect(&LRCInstance::accountModel(), &lrc::api::NewAccountModel::nameRegistrationEnded,
this, &NameRegistrationDialog::slotNameRegistrationResult);
spinnerAnimation_ = new QMovie(":/images/jami_eclipse_spinner.gif");
......@@ -60,7 +60,7 @@ void
NameRegistrationDialog::slotStartNameRegistration()
{
auto password = ui->passwordEdit->text().toStdString();
LRCInstance::editableAccountModel()->registerName(LRCInstance::getCurrAccId(),
LRCInstance::accountModel().registerName(LRCInstance::getCurrAccId(),
password, nameToRegister_.toStdString());
startSpinner();
}
......@@ -98,4 +98,4 @@ NameRegistrationDialog::startSpinner()
ui->spinnerLabel->setMovie(spinnerAnimation_);
spinnerAnimation_->start();
}
\ No newline at end of file
}
......@@ -459,7 +459,7 @@ NewWizardWidget::createAccount()
LRCInstance::accountModel().setAccountConfig(accountId, confProps);
if (isRing) {
if (!confProps.username.empty()) {
connect(LRCInstance::editableAccountModel(),
connect(&LRCInstance::accountModel(),
&lrc::api::NewAccountModel::nameRegistrationEnded,
[this] {
lrc::api::account::ConfProperties_t accountProperties = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
......@@ -467,7 +467,7 @@ NewWizardWidget::createAccount()
emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountOnBoarded();
});
LRCInstance::editableAccountModel()->registerName(
LRCInstance::accountModel().registerName(
LRCInstance::getCurrAccId(),
"",
registeredName_.toStdString()
......
......@@ -74,16 +74,16 @@ PasswordDialog::validatePassword()
void
PasswordDialog::savePassword()
{
if (LRCInstance::editableAccountModel()->changeAccountPassword(LRCInstance::getCurrAccId(),
if (LRCInstance::accountModel().changeAccountPassword(LRCInstance::getCurrAccId(),
ui->currentPasswordEdit->text().toStdString(), ui->passwordEdit->text().toStdString())) {
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.archiveHasPassword = !ui->passwordEdit->text().isEmpty();
LRCInstance::editableAccountModel()->setAccountConfig(LRCInstance::getCurrAccId(), confProps);
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
accept();
} else {
ui->wrongPasswordLabel->show();
ui->currentPasswordEdit->setText("");
}
}
\ No newline at end of file
}
......@@ -477,7 +477,7 @@ SettingsWidget::slotRegisterName()
void SettingsWidget::setAccEnableSlot(int state)
{
LRCInstance::editableAccountModel()->setAccountEnabled(LRCInstance::getCurrAccId(), static_cast<bool>(state));
LRCInstance::accountModel().setAccountEnabled(LRCInstance::getCurrAccId(), static_cast<bool>(state));
}
void SettingsWidget::delAccountSlot()
......@@ -863,7 +863,7 @@ void SettingsWidget::openDownloadFolderSlot()
if (!dir.isEmpty()) {
Utils::setElidedText(ui->downloadButton, dir);
settings.setValue(SettingsKey::downloadPath, dir);
LRCInstance::editableDataTransferModel()->downloadDirectory = dir.toStdString() + "/";
LRCInstance::dataTransferModel().downloadDirectory = dir.toStdString() + "/";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment