mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-04-30 16:06:24 +00:00
fix(ui/views/App/Main/ContactEdit): handle correctly new info
This commit is contained in:
parent
da8bdb43c0
commit
3a7851728a
7 changed files with 118 additions and 88 deletions
|
|
@ -194,6 +194,7 @@
|
|||
<file>ui/modules/Common/Form/Fields/TextAreaField.qml</file>
|
||||
<file>ui/modules/Common/Form/Fields/TextField.qml</file>
|
||||
<file>ui/modules/Common/Form/+linux/SearchBox.qml</file>
|
||||
<file>ui/modules/Common/Form/ListForm.js</file>
|
||||
<file>ui/modules/Common/Form/ListForm.qml</file>
|
||||
<file>ui/modules/Common/Form/Placements/FormEmptyLine.qml</file>
|
||||
<file>ui/modules/Common/Form/Placements/FormGroup.qml</file>
|
||||
|
|
|
|||
|
|
@ -280,13 +280,13 @@ bool VcardModel::addSipAddress (const QString &sipAddress) {
|
|||
shared_ptr<belcard::BelCardImpp> value = belcard::BelCardGeneric::create<belcard::BelCardImpp>();
|
||||
value->setValue(linphoneAddress->asStringUriOnly());
|
||||
|
||||
qInfo() << QStringLiteral("Add new sip address on vcard: `%1`.").arg(sipAddress);
|
||||
|
||||
if (!belcard->addImpp(value)) {
|
||||
qWarning() << QStringLiteral("Unable to add sip address on vcard: `%1`.").arg(sipAddress);
|
||||
return false;
|
||||
}
|
||||
|
||||
qInfo() << QStringLiteral("Add new sip address on vcard: `%1`.").arg(sipAddress);
|
||||
|
||||
emit vcardUpdated();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -338,13 +338,13 @@ bool VcardModel::addCompany (const QString &company) {
|
|||
shared_ptr<belcard::BelCardRole> value = belcard::BelCardGeneric::create<belcard::BelCardRole>();
|
||||
value->setValue(::Utils::qStringToLinphoneString(company));
|
||||
|
||||
qInfo() << QStringLiteral("Add new company on vcard: `%1`.").arg(company);
|
||||
|
||||
if (!belcard->addRole(value)) {
|
||||
qWarning() << QStringLiteral("Unable to add company on vcard: `%1`.").arg(company);
|
||||
return false;
|
||||
}
|
||||
|
||||
qInfo() << QStringLiteral("Add new company on vcard: `%1`.").arg(company);
|
||||
|
||||
emit vcardUpdated();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -389,13 +389,13 @@ bool VcardModel::addEmail (const QString &email) {
|
|||
shared_ptr<belcard::BelCardEmail> value = belcard::BelCardGeneric::create<belcard::BelCardEmail>();
|
||||
value->setValue(::Utils::qStringToLinphoneString(email));
|
||||
|
||||
qInfo() << QStringLiteral("Add new email on vcard: `%1`.").arg(email);
|
||||
|
||||
if (!belcard->addEmail(value)) {
|
||||
qWarning() << QStringLiteral("Unable to add email on vcard: `%1`.").arg(email);
|
||||
return false;
|
||||
}
|
||||
|
||||
qInfo() << QStringLiteral("Add new email on vcard: `%1`.").arg(email);
|
||||
|
||||
emit vcardUpdated();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -440,13 +440,13 @@ bool VcardModel::addUrl (const QString &url) {
|
|||
shared_ptr<belcard::BelCardURL> value = belcard::BelCardGeneric::create<belcard::BelCardURL>();
|
||||
value->setValue(::Utils::qStringToLinphoneString(url));
|
||||
|
||||
qInfo() << QStringLiteral("Add new url on vcard: `%1`.").arg(url);
|
||||
|
||||
if (!belcard->addURL(value)) {
|
||||
qWarning() << QStringLiteral("Unable to add url on vcard: `%1`.").arg(url);
|
||||
return false;
|
||||
}
|
||||
|
||||
qInfo() << QStringLiteral("Add new url on vcard: `%1`.").arg(url);
|
||||
|
||||
emit vcardUpdated();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ import QtQuick.Layouts 1.3
|
|||
import Common 1.0
|
||||
import Common.Styles 1.0
|
||||
|
||||
import Utils 1.0
|
||||
|
||||
import 'ComboBox.js' as Logic
|
||||
|
||||
// =============================================================================
|
||||
|
|
|
|||
86
linphone-desktop/ui/modules/Common/Form/ListForm.js
Normal file
86
linphone-desktop/ui/modules/Common/Form/ListForm.js
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// =============================================================================
|
||||
// `ListForm.qml` Logic.
|
||||
// =============================================================================
|
||||
|
||||
.import 'qrc:/ui/scripts/Utils/utils.js' as Utils
|
||||
|
||||
// =============================================================================
|
||||
|
||||
function setData (data) {
|
||||
var model = values.model
|
||||
|
||||
model.clear()
|
||||
data.forEach(function (data) {
|
||||
model.append({ $value: data, $isInvalid: false })
|
||||
})
|
||||
}
|
||||
|
||||
function setInvalid (index, status) {
|
||||
Utils.assert(
|
||||
index >= 0 && index < values.model.count,
|
||||
'Index ' + index + 'not exists.'
|
||||
)
|
||||
|
||||
values.model.setProperty(index, '$isInvalid', status)
|
||||
}
|
||||
|
||||
function updateValue (index, value) {
|
||||
var model = values.model
|
||||
|
||||
// Unable to set property directly. Qt uses a cache of the value.
|
||||
// It's necessary to remove then insert.
|
||||
model.remove(index)
|
||||
model.insert(index, {
|
||||
$isInvalid: false,
|
||||
$value: value
|
||||
})
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
function addValue (value) {
|
||||
values.model.append({ $value: value, $isInvalid: false })
|
||||
|
||||
if (value.length === 0) {
|
||||
addButton.enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleEditionFinished (index, text) {
|
||||
var model = values.model
|
||||
var oldValue = model.get(index).$value
|
||||
|
||||
if (text.length === 0) {
|
||||
// No changes. It must exists at least n min values.
|
||||
if (minValues != null && minValues >= model.count) {
|
||||
updateValue(index, oldValue)
|
||||
return
|
||||
}
|
||||
|
||||
model.remove(index)
|
||||
|
||||
if (oldValue.length !== 0) {
|
||||
listForm.removed(index, oldValue)
|
||||
}
|
||||
} else if (text !== oldValue) {
|
||||
// Update changes.
|
||||
updateValue(index, text)
|
||||
listForm.changed(index, oldValue, text)
|
||||
}
|
||||
|
||||
addButton.enabled = true
|
||||
}
|
||||
|
||||
function handleItemCreation () {
|
||||
if (this.text.length === 0) {
|
||||
// FIXME: Find the source of this problem.
|
||||
//
|
||||
// Magic code. If it's the first inserted value,
|
||||
// an event or a callback steal the item focus.
|
||||
// I suppose it's an internal Qt qml event...
|
||||
//
|
||||
// So, I choose to run a callback executed after this
|
||||
// internal event.
|
||||
Utils.setTimeout(values, 0, this.forceActiveFocus)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,8 @@ import QtQuick.Layouts 1.3
|
|||
|
||||
import Common 1.0
|
||||
import Common.Styles 1.0
|
||||
import Utils 1.0
|
||||
|
||||
import 'ListForm.js' as Logic
|
||||
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -21,64 +22,21 @@ RowLayout {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
signal changed (int index, string defaultValue, string newValue)
|
||||
signal changed (int index, string oldValue, string newValue)
|
||||
signal removed (int index, string value)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function setInvalid (index, status) {
|
||||
Utils.assert(
|
||||
index >= 0 && index < values.model.count,
|
||||
'Index ' + index + 'not exists.'
|
||||
)
|
||||
|
||||
values.model.setProperty(index, '$isInvalid', status)
|
||||
function setData () {
|
||||
Logic.setData.apply(this, arguments)
|
||||
}
|
||||
|
||||
function setData (data) {
|
||||
var model = values.model
|
||||
|
||||
model.clear()
|
||||
data.forEach(function (data) {
|
||||
model.append({ $value: data, $isInvalid: false })
|
||||
})
|
||||
function setInvalid () {
|
||||
Logic.setInvalid.apply(this, arguments)
|
||||
}
|
||||
|
||||
function _addValue (value) {
|
||||
values.model.append({ $value: value, $isInvalid: false })
|
||||
|
||||
if (value.length === 0) {
|
||||
addButton.enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
function _handleEditionFinished (index, text) {
|
||||
var model = values.model
|
||||
var defaultValue = model.get(index).$value
|
||||
|
||||
if (text.length === 0) {
|
||||
// No changes. It must exists at least n min values.
|
||||
if (minValues != null && minValues >= model.count) {
|
||||
// Unable to set property directly. Qt uses a cache of the value.
|
||||
model.remove(index)
|
||||
model.insert(index, {
|
||||
$isInvalid: false,
|
||||
$value: defaultValue
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
model.remove(index)
|
||||
|
||||
if (defaultValue.length !== 0) {
|
||||
listForm.removed(index, defaultValue)
|
||||
}
|
||||
} else if (text !== defaultValue) {
|
||||
// Update changes.
|
||||
listForm.changed(index, defaultValue, text)
|
||||
}
|
||||
|
||||
addButton.enabled = true
|
||||
function updateValue () {
|
||||
Logic.updateValue.apply(this, arguments)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -99,9 +57,9 @@ RowLayout {
|
|||
|
||||
icon: 'add'
|
||||
iconSize: ListFormStyle.titleArea.iconSize
|
||||
opacity: _edition ? 1 : 0
|
||||
opacity: !listForm.readOnly ? 1 : 0
|
||||
|
||||
onClicked: _edition && _addValue('')
|
||||
onClicked: !listForm.readOnly && Logic.addValue('')
|
||||
}
|
||||
|
||||
Text {
|
||||
|
|
@ -140,7 +98,7 @@ RowLayout {
|
|||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: !listForm.readOnly && _addValue('')
|
||||
onClicked: !listForm.readOnly && Logic.addValue('')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,23 +129,9 @@ RowLayout {
|
|||
height: ListFormStyle.lineHeight
|
||||
width: parent.width
|
||||
|
||||
onEditingFinished: _handleEditionFinished(index, text)
|
||||
Component.onCompleted: Logic.handleItemCreation.apply(this)
|
||||
|
||||
Component.onCompleted: {
|
||||
if ($value.length === 0) {
|
||||
// FIXME: Find the source of this problem.
|
||||
//
|
||||
// Magic code. If it's the first inserted value,
|
||||
// an event or a callback steal the item focus.
|
||||
// I suppose it's an internal Qt qml event...
|
||||
//
|
||||
// So, I choose to run a callback executed after this
|
||||
// internal event.
|
||||
Utils.setTimeout(values, 0, function () {
|
||||
textInput.forceActiveFocus()
|
||||
})
|
||||
}
|
||||
}
|
||||
onEditingFinished: Logic.handleEditionFinished(index, text)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,15 +116,16 @@ function setUsername (username) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
function handleValueChanged (fields, index, defaultValue, newValue, add, update) {
|
||||
if (newValue === defaultValue) {
|
||||
function handleValueChanged (fields, index, oldValue, newValue, add, update) {
|
||||
if (newValue === oldValue) {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('handle', oldValue, newValue)
|
||||
var vcard = contactEdit._vcard
|
||||
var soFarSoGood = (defaultValue.length === 0)
|
||||
var soFarSoGood = (oldValue.length === 0)
|
||||
? vcard[add](newValue)
|
||||
: vcard[update](defaultValue, newValue)
|
||||
: vcard[update](oldValue, newValue)
|
||||
|
||||
fields.setInvalid(index, !soFarSoGood)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ ColumnLayout {
|
|||
readOnly: !_edition
|
||||
title: qsTr('sipAccounts')
|
||||
|
||||
onChanged: Logic.handleSipAddressChanged(addresses, index, defaultValue, newValue)
|
||||
onChanged: Logic.handleSipAddressChanged(addresses, index, oldValue, newValue)
|
||||
onRemoved: _vcard.removeSipAddress(value)
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +226,7 @@ ColumnLayout {
|
|||
readOnly: !_edition
|
||||
title: qsTr('companies')
|
||||
|
||||
onChanged: Logic.handleCompanyChanged(companies, index, defaultValue, newValue)
|
||||
onChanged: Logic.handleCompanyChanged(companies, index, oldValue, newValue)
|
||||
onRemoved: _vcard.removeCompany(value)
|
||||
}
|
||||
|
||||
|
|
@ -246,7 +246,7 @@ ColumnLayout {
|
|||
readOnly: !_edition
|
||||
title: qsTr('emails')
|
||||
|
||||
onChanged: Logic.handleEmailChanged(emails, index, defaultValue, newValue)
|
||||
onChanged: Logic.handleEmailChanged(emails, index, oldValue, newValue)
|
||||
onRemoved: _vcard.removeEmail(value)
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ ColumnLayout {
|
|||
readOnly: !_edition
|
||||
title: qsTr('webSites')
|
||||
|
||||
onChanged: Logic.handleUrlChanged(urls, index, defaultValue, newValue)
|
||||
onChanged: Logic.handleUrlChanged(urls, index, oldValue, newValue)
|
||||
onRemoved: _vcard.removeUrl(value)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue