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;
|
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) {
|
AccountCore::AccountCore(const std::shared_ptr<linphone::Account> &account) : QObject(nullptr) {
|
||||||
App::getInstance()->mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership);
|
App::getInstance()->mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership);
|
||||||
// Should be call from model Thread
|
// 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 = Utils::makeQObject_ptr<AccountModel>(account); // OK
|
||||||
mAccountModel->setSelf(mAccountModel);
|
mAccountModel->setSelf(mAccountModel);
|
||||||
mNotificationsAllowed = mAccountModel->getNotificationsAllowed();
|
mNotificationsAllowed = mAccountModel->getNotificationsAllowed();
|
||||||
mDialPlan = createDialPlanVariant("", " ");
|
mDialPlan = Utils::createDialPlanVariant("", " ");
|
||||||
mDialPlans << mDialPlan;
|
mDialPlans << mDialPlan;
|
||||||
for (auto dialPlan : linphone::Factory::get()->getDialPlans()) {
|
for (auto dialPlan : linphone::Factory::get()->getDialPlans()) {
|
||||||
mDialPlans << createDialPlanVariant(
|
mDialPlans << Utils::createDialPlanVariant(
|
||||||
Utils::coreStringToAppString(dialPlan->getFlag()),
|
Utils::coreStringToAppString(dialPlan->getFlag()),
|
||||||
Utils::coreStringToAppString(dialPlan->getCountry() + " | +" + dialPlan->getCountryCallingCode()));
|
Utils::coreStringToAppString(dialPlan->getCountry() + " | +" + dialPlan->getCountryCallingCode()));
|
||||||
if (dialPlan->getCountryCallingCode() == account->getParams()->getInternationalPrefix()) {
|
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) {
|
QSharedPointer<CallCore> CallCore::create(const std::shared_ptr<linphone::Call> &call) {
|
||||||
auto sharedPointer = QSharedPointer<CallCore>(new CallCore(call), &QObject::deleteLater);
|
auto sharedPointer = QSharedPointer<CallCore>(new CallCore(call), &QObject::deleteLater);
|
||||||
sharedPointer->setSelf(sharedPointer);
|
sharedPointer->setSelf(sharedPointer);
|
||||||
|
|
|
||||||
|
|
@ -29,21 +29,6 @@ DEFINE_ABSTRACT_OBJECT(FriendCore)
|
||||||
const QString _addressLabel = FriendCore::tr("Adresse SIP");
|
const QString _addressLabel = FriendCore::tr("Adresse SIP");
|
||||||
const QString _phoneLabel = FriendCore::tr("Téléphone");
|
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) {
|
QSharedPointer<FriendCore> FriendCore::create(const std::shared_ptr<linphone::Friend> &contact, bool isStored) {
|
||||||
auto sharedPointer = QSharedPointer<FriendCore>(new FriendCore(contact, isStored), &QObject::deleteLater);
|
auto sharedPointer = QSharedPointer<FriendCore>(new FriendCore(contact, isStored), &QObject::deleteLater);
|
||||||
sharedPointer->setSelf(sharedPointer);
|
sharedPointer->setSelf(sharedPointer);
|
||||||
|
|
@ -73,8 +58,8 @@ FriendCore::FriendCore(const std::shared_ptr<linphone::Friend> &contact, bool is
|
||||||
|
|
||||||
auto addresses = contact->getAddresses();
|
auto addresses = contact->getAddresses();
|
||||||
for (auto &address : addresses) {
|
for (auto &address : addresses) {
|
||||||
mAddressList.append(
|
mAddressList.append(Utils::createFriendAddressVariant(
|
||||||
createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(address->asStringUriOnly())));
|
_addressLabel, Utils::coreStringToAppString(address->asStringUriOnly())));
|
||||||
}
|
}
|
||||||
mDefaultAddress = defaultAddress ? Utils::coreStringToAppString(defaultAddress->asStringUriOnly()) : QString();
|
mDefaultAddress = defaultAddress ? Utils::coreStringToAppString(defaultAddress->asStringUriOnly()) : QString();
|
||||||
mDefaultFullAddress = defaultAddress ? Utils::coreStringToAppString(defaultAddress->asString()) : 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();
|
auto phoneNumbers = contact->getPhoneNumbersWithLabel();
|
||||||
for (auto &phoneNumber : phoneNumbers) {
|
for (auto &phoneNumber : phoneNumbers) {
|
||||||
mPhoneNumberList.append(
|
mPhoneNumberList.append(
|
||||||
createFriendAddressVariant(Utils::coreStringToAppString(phoneNumber->getLabel()),
|
Utils::createFriendAddressVariant(Utils::coreStringToAppString(phoneNumber->getLabel()),
|
||||||
Utils::coreStringToAppString(phoneNumber->getPhoneNumber())));
|
Utils::coreStringToAppString(phoneNumber->getPhoneNumber())));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto devices = contact->getDevices();
|
auto devices = contact->getDevices();
|
||||||
for (auto &device : devices) {
|
for (auto &device : devices) {
|
||||||
mDeviceList.append(createFriendDevice(Utils::coreStringToAppString(device->getDisplayName()),
|
mDeviceList.append(
|
||||||
// do not use uri only as we want the unique device
|
Utils::createFriendDeviceVariant(Utils::coreStringToAppString(device->getDisplayName()),
|
||||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
// do not use uri only as we want the unique device
|
||||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||||
|
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||||
}
|
}
|
||||||
updateVerifiedDevicesCount();
|
updateVerifiedDevicesCount();
|
||||||
|
|
||||||
|
|
@ -145,11 +131,11 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
||||||
auto devices = mFriendModel->getDevices();
|
auto devices = mFriendModel->getDevices();
|
||||||
QVariantList devicesList;
|
QVariantList devicesList;
|
||||||
for (auto &device : devices) {
|
for (auto &device : devices) {
|
||||||
devicesList.append(
|
devicesList.append(Utils::createFriendDeviceVariant(
|
||||||
createFriendDevice(Utils::coreStringToAppString(device->getDisplayName()),
|
Utils::coreStringToAppString(device->getDisplayName()),
|
||||||
// do not use uri only as we want the unique device
|
// do not use uri only as we want the unique device
|
||||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||||
}
|
}
|
||||||
mFriendModelConnection->invokeToCore(
|
mFriendModelConnection->invokeToCore(
|
||||||
[this, consolidatedPresence, presenceTimestamp, devicesList]() {
|
[this, consolidatedPresence, presenceTimestamp, devicesList]() {
|
||||||
|
|
@ -185,8 +171,8 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
||||||
auto numbers = mFriendModel->getAddresses();
|
auto numbers = mFriendModel->getAddresses();
|
||||||
QList<QVariant> addr;
|
QList<QVariant> addr;
|
||||||
for (auto &num : numbers) {
|
for (auto &num : numbers) {
|
||||||
addr.append(createFriendAddressVariant(_addressLabel,
|
addr.append(Utils::createFriendAddressVariant(
|
||||||
Utils::coreStringToAppString(num->asStringUriOnly())));
|
_addressLabel, Utils::coreStringToAppString(num->asStringUriOnly())));
|
||||||
}
|
}
|
||||||
mFriendModelConnection->invokeToCore([this, addr]() { resetPhoneNumbers(addr); });
|
mFriendModelConnection->invokeToCore([this, addr]() { resetPhoneNumbers(addr); });
|
||||||
});
|
});
|
||||||
|
|
@ -194,8 +180,8 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
||||||
auto numbers = mFriendModel->getPhoneNumbers();
|
auto numbers = mFriendModel->getPhoneNumbers();
|
||||||
QList<QVariant> addr;
|
QList<QVariant> addr;
|
||||||
for (auto &num : numbers) {
|
for (auto &num : numbers) {
|
||||||
addr.append(
|
addr.append(Utils::createFriendAddressVariant(_phoneLabel,
|
||||||
createFriendAddressVariant(_phoneLabel, Utils::coreStringToAppString(num->getPhoneNumber())));
|
Utils::coreStringToAppString(num->getPhoneNumber())));
|
||||||
}
|
}
|
||||||
mFriendModelConnection->invokeToCore([this, addr]() { resetPhoneNumbers(addr); });
|
mFriendModelConnection->invokeToCore([this, addr]() { resetPhoneNumbers(addr); });
|
||||||
});
|
});
|
||||||
|
|
@ -219,11 +205,11 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
|
||||||
auto devices = mFriendModel->getDevices();
|
auto devices = mFriendModel->getDevices();
|
||||||
QVariantList devicesList;
|
QVariantList devicesList;
|
||||||
for (auto &device : devices) {
|
for (auto &device : devices) {
|
||||||
devicesList.append(
|
devicesList.append(Utils::createFriendDeviceVariant(
|
||||||
createFriendDevice(Utils::coreStringToAppString(device->getDisplayName()),
|
Utils::coreStringToAppString(device->getDisplayName()),
|
||||||
// do not use uri only as we want the unique device
|
// do not use uri only as we want the unique device
|
||||||
Utils::coreStringToAppString(device->getAddress()->asString()),
|
Utils::coreStringToAppString(device->getAddress()->asString()),
|
||||||
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
LinphoneEnums::fromLinphone(device->getSecurityLevel())));
|
||||||
}
|
}
|
||||||
mCoreModelConnection->invokeToCore([this, devicesList]() {
|
mCoreModelConnection->invokeToCore([this, devicesList]() {
|
||||||
setDevices(devicesList);
|
setDevices(devicesList);
|
||||||
|
|
@ -339,7 +325,8 @@ void FriendCore::setPhoneNumberAt(int index, const QString &label, const QString
|
||||||
auto map = mPhoneNumberList[index].toMap();
|
auto map = mPhoneNumberList[index].toMap();
|
||||||
auto oldLabel = map["label"].toString();
|
auto oldLabel = map["label"].toString();
|
||||||
if (/*oldLabel != label || */ map["address"] != phoneNumber) {
|
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();
|
emit phoneNumberChanged();
|
||||||
setIsSaved(false);
|
setIsSaved(false);
|
||||||
}
|
}
|
||||||
|
|
@ -351,7 +338,7 @@ void FriendCore::removePhoneNumber(int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendCore::appendPhoneNumber(const QString &label, const QString &number) {
|
void FriendCore::appendPhoneNumber(const QString &label, const QString &number) {
|
||||||
mPhoneNumberList.append(createFriendAddressVariant(label, number));
|
mPhoneNumberList.append(Utils::createFriendAddressVariant(label, number));
|
||||||
emit phoneNumberChanged();
|
emit phoneNumberChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -381,14 +368,14 @@ void FriendCore::setAddressAt(int index, QString label, QString address) {
|
||||||
QString interpretedAddr = Utils::coreStringToAppString(linphoneAddr->asStringUriOnly());
|
QString interpretedAddr = Utils::coreStringToAppString(linphoneAddr->asStringUriOnly());
|
||||||
if (interpretedAddr != currentAddress) {
|
if (interpretedAddr != currentAddress) {
|
||||||
mCoreModelConnection->invokeToCore([this, index, label, interpretedAddr]() {
|
mCoreModelConnection->invokeToCore([this, index, label, interpretedAddr]() {
|
||||||
mAddressList.replace(index, createFriendAddressVariant(label, interpretedAddr));
|
mAddressList.replace(index, Utils::createFriendAddressVariant(label, interpretedAddr));
|
||||||
emit addressChanged();
|
emit addressChanged();
|
||||||
setIsSaved(false);
|
setIsSaved(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (address != currentAddress) {
|
} else if (address != currentAddress) {
|
||||||
mAddressList.replace(index, createFriendAddressVariant(label, address));
|
mAddressList.replace(index, Utils::createFriendAddressVariant(label, address));
|
||||||
emit addressChanged();
|
emit addressChanged();
|
||||||
setIsSaved(false);
|
setIsSaved(false);
|
||||||
}
|
}
|
||||||
|
|
@ -410,7 +397,7 @@ void FriendCore::appendAddress(const QString &addr) {
|
||||||
mCoreModelConnection->invokeToCore([this, interpretedAddress]() {
|
mCoreModelConnection->invokeToCore([this, interpretedAddress]() {
|
||||||
if (interpretedAddress.isEmpty()) Utils::showInformationPopup(tr("Erreur"), tr("Adresse invalide"), false);
|
if (interpretedAddress.isEmpty()) Utils::showInformationPopup(tr("Erreur"), tr("Adresse invalide"), false);
|
||||||
else {
|
else {
|
||||||
mAddressList.append(createFriendAddressVariant(_addressLabel, interpretedAddress));
|
mAddressList.append(Utils::createFriendAddressVariant(_addressLabel, interpretedAddress));
|
||||||
if (mDefaultFullAddress.isEmpty()) mDefaultFullAddress = interpretedAddress;
|
if (mDefaultFullAddress.isEmpty()) mDefaultFullAddress = interpretedAddress;
|
||||||
emit addressChanged();
|
emit addressChanged();
|
||||||
}
|
}
|
||||||
|
|
@ -588,14 +575,14 @@ void FriendCore::writeFromModel(const std::shared_ptr<FriendModel> &model) {
|
||||||
QList<QVariant> addresses;
|
QList<QVariant> addresses;
|
||||||
for (auto &addr : model->getAddresses()) {
|
for (auto &addr : model->getAddresses()) {
|
||||||
addresses.append(
|
addresses.append(
|
||||||
createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(addr->asStringUriOnly())));
|
Utils::createFriendAddressVariant(_addressLabel, Utils::coreStringToAppString(addr->asStringUriOnly())));
|
||||||
}
|
}
|
||||||
mAddressList = addresses;
|
mAddressList = addresses;
|
||||||
|
|
||||||
QList<QVariant> phones;
|
QList<QVariant> phones;
|
||||||
for (auto &number : model->getPhoneNumbers()) {
|
for (auto &number : model->getPhoneNumbers()) {
|
||||||
phones.append(createFriendAddressVariant(Utils::coreStringToAppString(number->getLabel()),
|
phones.append(Utils::createFriendAddressVariant(Utils::coreStringToAppString(number->getLabel()),
|
||||||
Utils::coreStringToAppString(number->getPhoneNumber())));
|
Utils::coreStringToAppString(number->getPhoneNumber())));
|
||||||
}
|
}
|
||||||
mPhoneNumberList = phones;
|
mPhoneNumberList = phones;
|
||||||
mGivenName = model->getGivenName();
|
mGivenName = model->getGivenName();
|
||||||
|
|
|
||||||
|
|
@ -1398,3 +1398,35 @@ void Utils::checkDownloadedCodecsUpdates() {
|
||||||
if (codec->shouldDownloadUpdate()) codec->downloadAndExtract(true);
|
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);
|
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:
|
private:
|
||||||
DECLARE_ABSTRACT_OBJECT
|
DECLARE_ABSTRACT_OBJECT
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue