diff --git a/Linphone/core/account/AccountCore.cpp b/Linphone/core/account/AccountCore.cpp index cbc68afd5..34f6752ff 100644 --- a/Linphone/core/account/AccountCore.cpp +++ b/Linphone/core/account/AccountCore.cpp @@ -35,13 +35,6 @@ QSharedPointer AccountCore::create(const std::shared_ptr &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 &account) : QO mAccountModel = Utils::makeQObject_ptr(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()) { diff --git a/Linphone/core/call/CallCore.cpp b/Linphone/core/call/CallCore.cpp index 6dc6d579c..a5fd16794 100644 --- a/Linphone/core/call/CallCore.cpp +++ b/Linphone/core/call/CallCore.cpp @@ -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::create(const std::shared_ptr &call) { auto sharedPointer = QSharedPointer(new CallCore(call), &QObject::deleteLater); sharedPointer->setSelf(sharedPointer); diff --git a/Linphone/core/friend/FriendCore.cpp b/Linphone/core/friend/FriendCore.cpp index a0c3327ce..1cc0bff4f 100644 --- a/Linphone/core/friend/FriendCore.cpp +++ b/Linphone/core/friend/FriendCore.cpp @@ -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::create(const std::shared_ptr &contact, bool isStored) { auto sharedPointer = QSharedPointer(new FriendCore(contact, isStored), &QObject::deleteLater); sharedPointer->setSelf(sharedPointer); @@ -73,8 +58,8 @@ FriendCore::FriendCore(const std::shared_ptr &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 &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 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 me) { auto numbers = mFriendModel->getAddresses(); QList 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 me) { auto numbers = mFriendModel->getPhoneNumbers(); QList 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 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 &model) { QList addresses; for (auto &addr : model->getAddresses()) { addresses.append( - createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(addr->asStringUriOnly()))); + Utils::createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(addr->asStringUriOnly()))); } mAddressList = addresses; QList 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(); diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index d94804e83..b4ea9662d 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -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; +} diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index 726495198..283060f54 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -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 };