mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-17 03:18:07 +00:00
Centralize variant creation into Utils
This commit is contained in:
parent
aceaa05ec6
commit
fd11013047
5 changed files with 74 additions and 61 deletions
|
|
@ -35,13 +35,6 @@ QSharedPointer<AccountCore> AccountCore::create(const std::shared_ptr<linphone::
|
|||
return model;
|
||||
}
|
||||
|
||||
QVariantMap createDialPlanVariant(QString flag, QString text) {
|
||||
QVariantMap m;
|
||||
m["flag"] = flag;
|
||||
m["text"] = text;
|
||||
return m;
|
||||
}
|
||||
|
||||
AccountCore::AccountCore(const std::shared_ptr<linphone::Account> &account) : QObject(nullptr) {
|
||||
App::getInstance()->mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership);
|
||||
// Should be call from model Thread
|
||||
|
|
@ -94,10 +87,10 @@ AccountCore::AccountCore(const std::shared_ptr<linphone::Account> &account) : QO
|
|||
mAccountModel = Utils::makeQObject_ptr<AccountModel>(account); // OK
|
||||
mAccountModel->setSelf(mAccountModel);
|
||||
mNotificationsAllowed = mAccountModel->getNotificationsAllowed();
|
||||
mDialPlan = createDialPlanVariant("", " ");
|
||||
mDialPlan = Utils::createDialPlanVariant("", " ");
|
||||
mDialPlans << mDialPlan;
|
||||
for (auto dialPlan : linphone::Factory::get()->getDialPlans()) {
|
||||
mDialPlans << createDialPlanVariant(
|
||||
mDialPlans << Utils::createDialPlanVariant(
|
||||
Utils::coreStringToAppString(dialPlan->getFlag()),
|
||||
Utils::coreStringToAppString(dialPlan->getCountry() + " | +" + dialPlan->getCountryCallingCode()));
|
||||
if (dialPlan->getCountryCallingCode() == account->getParams()->getInternationalPrefix()) {
|
||||
|
|
|
|||
|
|
@ -90,13 +90,6 @@ bool VideoStats::operator!=(VideoStats s) {
|
|||
|
||||
/***********************************************************************/
|
||||
|
||||
QVariant createDeviceVariant(const QString &id, const QString &name) {
|
||||
QVariantMap map;
|
||||
map.insert("id", id);
|
||||
map.insert("name", name);
|
||||
return map;
|
||||
}
|
||||
|
||||
QSharedPointer<CallCore> CallCore::create(const std::shared_ptr<linphone::Call> &call) {
|
||||
auto sharedPointer = QSharedPointer<CallCore>(new CallCore(call), &QObject::deleteLater);
|
||||
sharedPointer->setSelf(sharedPointer);
|
||||
|
|
|
|||
|
|
@ -29,21 +29,6 @@ DEFINE_ABSTRACT_OBJECT(FriendCore)
|
|||
const QString _addressLabel = FriendCore::tr("Adresse SIP");
|
||||
const QString _phoneLabel = FriendCore::tr("Téléphone");
|
||||
|
||||
QVariant createFriendAddressVariant(const QString &label, const QString &address) {
|
||||
QVariantMap map;
|
||||
map.insert("label", label);
|
||||
map.insert("address", address);
|
||||
return map;
|
||||
}
|
||||
|
||||
QVariant createFriendDevice(const QString &name, const QString &address, LinphoneEnums::SecurityLevel level) {
|
||||
QVariantMap map;
|
||||
map.insert("name", name);
|
||||
map.insert("address", address);
|
||||
map.insert("securityLevel", QVariant::fromValue(level));
|
||||
return map;
|
||||
}
|
||||
|
||||
QSharedPointer<FriendCore> FriendCore::create(const std::shared_ptr<linphone::Friend> &contact, bool isStored) {
|
||||
auto sharedPointer = QSharedPointer<FriendCore>(new FriendCore(contact, isStored), &QObject::deleteLater);
|
||||
sharedPointer->setSelf(sharedPointer);
|
||||
|
|
@ -73,8 +58,8 @@ FriendCore::FriendCore(const std::shared_ptr<linphone::Friend> &contact, bool is
|
|||
|
||||
auto addresses = contact->getAddresses();
|
||||
for (auto &address : addresses) {
|
||||
mAddressList.append(
|
||||
createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(address->asStringUriOnly())));
|
||||
mAddressList.append(Utils::createFriendAddressVariant(
|
||||
_addressLabel, Utils::coreStringToAppString(address->asStringUriOnly())));
|
||||
}
|
||||
mDefaultAddress = defaultAddress ? Utils::coreStringToAppString(defaultAddress->asStringUriOnly()) : QString();
|
||||
mDefaultFullAddress = defaultAddress ? Utils::coreStringToAppString(defaultAddress->asString()) : QString();
|
||||
|
|
@ -82,16 +67,17 @@ FriendCore::FriendCore(const std::shared_ptr<linphone::Friend> &contact, bool is
|
|||
auto phoneNumbers = contact->getPhoneNumbersWithLabel();
|
||||
for (auto &phoneNumber : phoneNumbers) {
|
||||
mPhoneNumberList.append(
|
||||
createFriendAddressVariant(Utils::coreStringToAppString(phoneNumber->getLabel()),
|
||||
Utils::coreStringToAppString(phoneNumber->getPhoneNumber())));
|
||||
Utils::createFriendAddressVariant(Utils::coreStringToAppString(phoneNumber->getLabel()),
|
||||
Utils::coreStringToAppString(phoneNumber->getPhoneNumber())));
|
||||
}
|
||||
|
||||
auto devices = contact->getDevices();
|
||||
for (auto &device : devices) {
|
||||
mDeviceList.append(createFriendDevice(Utils::coreStringToAppString(device->getDisplayName()),
|
||||
// do not use uri only as we want the unique device
|
||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||
mDeviceList.append(
|
||||
Utils::createFriendDeviceVariant(Utils::coreStringToAppString(device->getDisplayName()),
|
||||
// do not use uri only as we want the unique device
|
||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||
}
|
||||
updateVerifiedDevicesCount();
|
||||
|
||||
|
|
@ -145,11 +131,11 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
|||
auto devices = mFriendModel->getDevices();
|
||||
QVariantList devicesList;
|
||||
for (auto &device : devices) {
|
||||
devicesList.append(
|
||||
createFriendDevice(Utils::coreStringToAppString(device->getDisplayName()),
|
||||
// do not use uri only as we want the unique device
|
||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||
devicesList.append(Utils::createFriendDeviceVariant(
|
||||
Utils::coreStringToAppString(device->getDisplayName()),
|
||||
// do not use uri only as we want the unique device
|
||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||
}
|
||||
mFriendModelConnection->invokeToCore(
|
||||
[this, consolidatedPresence, presenceTimestamp, devicesList]() {
|
||||
|
|
@ -185,8 +171,8 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
|||
auto numbers = mFriendModel->getAddresses();
|
||||
QList<QVariant> addr;
|
||||
for (auto &num : numbers) {
|
||||
addr.append(createFriendAddressVariant(_addressLabel,
|
||||
Utils::coreStringToAppString(num->asStringUriOnly())));
|
||||
addr.append(Utils::createFriendAddressVariant(
|
||||
_addressLabel, Utils::coreStringToAppString(num->asStringUriOnly())));
|
||||
}
|
||||
mFriendModelConnection->invokeToCore([this, addr]() { resetPhoneNumbers(addr); });
|
||||
});
|
||||
|
|
@ -194,8 +180,8 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
|||
auto numbers = mFriendModel->getPhoneNumbers();
|
||||
QList<QVariant> addr;
|
||||
for (auto &num : numbers) {
|
||||
addr.append(
|
||||
createFriendAddressVariant(_phoneLabel, Utils::coreStringToAppString(num->getPhoneNumber())));
|
||||
addr.append(Utils::createFriendAddressVariant(_phoneLabel,
|
||||
Utils::coreStringToAppString(num->getPhoneNumber())));
|
||||
}
|
||||
mFriendModelConnection->invokeToCore([this, addr]() { resetPhoneNumbers(addr); });
|
||||
});
|
||||
|
|
@ -219,11 +205,11 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
|||
auto devices = mFriendModel->getDevices();
|
||||
QVariantList devicesList;
|
||||
for (auto &device : devices) {
|
||||
devicesList.append(
|
||||
createFriendDevice(Utils::coreStringToAppString(device->getDisplayName()),
|
||||
// do not use uri only as we want the unique device
|
||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||
devicesList.append(Utils::createFriendDeviceVariant(
|
||||
Utils::coreStringToAppString(device->getDisplayName()),
|
||||
// do not use uri only as we want the unique device
|
||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||
}
|
||||
mCoreModelConnection->invokeToCore([this, devicesList]() {
|
||||
setDevices(devicesList);
|
||||
|
|
@ -339,7 +325,8 @@ void FriendCore::setPhoneNumberAt(int index, const QString &label, const QString
|
|||
auto map = mPhoneNumberList[index].toMap();
|
||||
auto oldLabel = map["label"].toString();
|
||||
if (/*oldLabel != label || */ map["address"] != phoneNumber) {
|
||||
mPhoneNumberList.replace(index, createFriendAddressVariant(label.isEmpty() ? oldLabel : label, phoneNumber));
|
||||
mPhoneNumberList.replace(index,
|
||||
Utils::createFriendAddressVariant(label.isEmpty() ? oldLabel : label, phoneNumber));
|
||||
emit phoneNumberChanged();
|
||||
setIsSaved(false);
|
||||
}
|
||||
|
|
@ -351,7 +338,7 @@ void FriendCore::removePhoneNumber(int index) {
|
|||
}
|
||||
|
||||
void FriendCore::appendPhoneNumber(const QString &label, const QString &number) {
|
||||
mPhoneNumberList.append(createFriendAddressVariant(label, number));
|
||||
mPhoneNumberList.append(Utils::createFriendAddressVariant(label, number));
|
||||
emit phoneNumberChanged();
|
||||
}
|
||||
|
||||
|
|
@ -381,14 +368,14 @@ void FriendCore::setAddressAt(int index, QString label, QString address) {
|
|||
QString interpretedAddr = Utils::coreStringToAppString(linphoneAddr->asStringUriOnly());
|
||||
if (interpretedAddr != currentAddress) {
|
||||
mCoreModelConnection->invokeToCore([this, index, label, interpretedAddr]() {
|
||||
mAddressList.replace(index, createFriendAddressVariant(label, interpretedAddr));
|
||||
mAddressList.replace(index, Utils::createFriendAddressVariant(label, interpretedAddr));
|
||||
emit addressChanged();
|
||||
setIsSaved(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (address != currentAddress) {
|
||||
mAddressList.replace(index, createFriendAddressVariant(label, address));
|
||||
mAddressList.replace(index, Utils::createFriendAddressVariant(label, address));
|
||||
emit addressChanged();
|
||||
setIsSaved(false);
|
||||
}
|
||||
|
|
@ -410,7 +397,7 @@ void FriendCore::appendAddress(const QString &addr) {
|
|||
mCoreModelConnection->invokeToCore([this, interpretedAddress]() {
|
||||
if (interpretedAddress.isEmpty()) Utils::showInformationPopup(tr("Erreur"), tr("Adresse invalide"), false);
|
||||
else {
|
||||
mAddressList.append(createFriendAddressVariant(_addressLabel, interpretedAddress));
|
||||
mAddressList.append(Utils::createFriendAddressVariant(_addressLabel, interpretedAddress));
|
||||
if (mDefaultFullAddress.isEmpty()) mDefaultFullAddress = interpretedAddress;
|
||||
emit addressChanged();
|
||||
}
|
||||
|
|
@ -588,14 +575,14 @@ void FriendCore::writeFromModel(const std::shared_ptr<FriendModel> &model) {
|
|||
QList<QVariant> addresses;
|
||||
for (auto &addr : model->getAddresses()) {
|
||||
addresses.append(
|
||||
createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(addr->asStringUriOnly())));
|
||||
Utils::createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(addr->asStringUriOnly())));
|
||||
}
|
||||
mAddressList = addresses;
|
||||
|
||||
QList<QVariant> phones;
|
||||
for (auto &number : model->getPhoneNumbers()) {
|
||||
phones.append(createFriendAddressVariant(Utils::coreStringToAppString(number->getLabel()),
|
||||
Utils::coreStringToAppString(number->getPhoneNumber())));
|
||||
phones.append(Utils::createFriendAddressVariant(Utils::coreStringToAppString(number->getLabel()),
|
||||
Utils::coreStringToAppString(number->getPhoneNumber())));
|
||||
}
|
||||
mPhoneNumberList = phones;
|
||||
mGivenName = model->getGivenName();
|
||||
|
|
|
|||
|
|
@ -1398,3 +1398,35 @@ void Utils::checkDownloadedCodecsUpdates() {
|
|||
if (codec->shouldDownloadUpdate()) codec->downloadAndExtract(true);
|
||||
}
|
||||
}
|
||||
|
||||
// VARIANT CREATORS
|
||||
|
||||
QVariantMap Utils::createDeviceVariant(const QString &id, const QString &name) {
|
||||
QVariantMap map;
|
||||
map.insert("id", id);
|
||||
map.insert("name", name);
|
||||
return map;
|
||||
}
|
||||
|
||||
QVariantMap Utils::createDialPlanVariant(QString flag, QString text) {
|
||||
QVariantMap m;
|
||||
m["flag"] = flag;
|
||||
m["text"] = text;
|
||||
return m;
|
||||
}
|
||||
|
||||
QVariantMap Utils::createFriendAddressVariant(const QString &label, const QString &address) {
|
||||
QVariantMap map;
|
||||
map.insert("label", label);
|
||||
map.insert("address", address);
|
||||
return map;
|
||||
}
|
||||
|
||||
QVariantMap
|
||||
Utils::createFriendDeviceVariant(const QString &name, const QString &address, LinphoneEnums::SecurityLevel level) {
|
||||
QVariantMap map;
|
||||
map.insert("name", name);
|
||||
map.insert("address", address);
|
||||
map.insert("securityLevel", QVariant::fromValue(level));
|
||||
return map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,14 @@ public:
|
|||
return (volume - VuMin) / (VuMax - VuMin);
|
||||
}
|
||||
|
||||
// Variant creators:
|
||||
|
||||
static QVariantMap createDeviceVariant(const QString &id, const QString &name);
|
||||
static QVariantMap createDialPlanVariant(QString flag, QString text);
|
||||
static QVariantMap createFriendAddressVariant(const QString &label, const QString &address);
|
||||
static QVariantMap
|
||||
createFriendDeviceVariant(const QString &name, const QString &address, LinphoneEnums::SecurityLevel level);
|
||||
|
||||
private:
|
||||
DECLARE_ABSTRACT_OBJECT
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue