Commit 59c0154f authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/views/App/MainWindow/ContactEdit): support address edition (unstable)

parent 3839f917
......@@ -149,6 +149,20 @@ bool VcardModel::setAvatar (const QString &path) {
// -----------------------------------------------------------------------------
inline shared_ptr<belcard::BelCardAddress> getOrCreateBelCardAddress (shared_ptr<belcard::BelCard> belcard) {
list<shared_ptr<belcard::BelCardAddress> > addresses = belcard->getAddresses();
shared_ptr<belcard::BelCardAddress> address;
if (addresses.empty()) {
address = belcard::BelCardGeneric::create<belcard::BelCardAddress>();
if (!belcard->addAddress(address))
qWarning() << "Unable to create a new address.";
} else
address = addresses.front();
return address;
}
QVariantMap VcardModel::getAddress () const {
list<shared_ptr<belcard::BelCardAddress> > addresses = m_vcard->getBelcard()->getAddresses();
QVariantMap map;
......@@ -165,27 +179,32 @@ QVariantMap VcardModel::getAddress () const {
return map;
}
bool VcardModel::setAddress (const QVariantMap &address) {
shared_ptr<belcard::BelCard> belcard = m_vcard->getBelcard();
list<shared_ptr<belcard::BelCardAddress> > addresses = belcard->getAddresses();
while (!addresses.empty())
belcard->removeAddress(addresses.front());
shared_ptr<belcard::BelCardAddress> belcard_address = belcard::BelCardGeneric::create<belcard::BelCardAddress>();
void VcardModel::setStreet (const QString &street) {
shared_ptr<belcard::BelCardAddress> address = getOrCreateBelCardAddress(m_vcard->getBelcard());
address->setStreet(::Utils::qStringToLinphoneString(street));
emit vcardUpdated();
}
belcard_address->setStreet(::Utils::qStringToLinphoneString(address["street"].toString()));
belcard_address->setLocality(::Utils::qStringToLinphoneString(address["locality"].toString()));
belcard_address->setPostalCode(::Utils::qStringToLinphoneString(address["postalCode"].toString()));
belcard_address->setCountry(::Utils::qStringToLinphoneString(address["country"].toString()));
void VcardModel::setLocality (const QString &locality) {
shared_ptr<belcard::BelCardAddress> address = getOrCreateBelCardAddress(m_vcard->getBelcard());
address->setLocality(::Utils::qStringToLinphoneString(locality));
emit vcardUpdated();
}
if (!belcard->addAddress(belcard_address))
return false;
void VcardModel::setPostalCode (const QString &postal_code) {
shared_ptr<belcard::BelCardAddress> address = getOrCreateBelCardAddress(m_vcard->getBelcard());
address->setPostalCode(::Utils::qStringToLinphoneString(postal_code));
emit vcardUpdated();
}
void VcardModel::setCountry (const QString &country) {
shared_ptr<belcard::BelCardAddress> address = getOrCreateBelCardAddress(m_vcard->getBelcard());
address->setCountry(::Utils::qStringToLinphoneString(country));
emit vcardUpdated();
return true;
}
// -----------------------------------------------------------------------------
QVariantList VcardModel::getSipAddresses () const {
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
QVariantList list;
......
......@@ -11,7 +11,7 @@ class VcardModel : public QObject {
Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY vcardUpdated);
Q_PROPERTY(QString avatar READ getAvatar WRITE setAvatar NOTIFY vcardUpdated);
Q_PROPERTY(QVariantMap address READ getAddress WRITE setAddress NOTIFY vcardUpdated);
Q_PROPERTY(QVariantMap address READ getAddress NOTIFY vcardUpdated);
Q_PROPERTY(QVariantList sipAddresses READ getSipAddresses NOTIFY vcardUpdated);
Q_PROPERTY(QVariantList companies READ getCompanies NOTIFY vcardUpdated);
Q_PROPERTY(QVariantList emails READ getEmails NOTIFY vcardUpdated);
......@@ -43,6 +43,11 @@ public slots:
void removeUrl (const QString &url);
bool updateUrl (const QString &old_url, const QString &url);
void setStreet (const QString &street);
void setLocality (const QString &locality);
void setPostalCode (const QString &postal_code);
void setCountry (const QString &country);
signals:
void vcardUpdated ();
......@@ -53,8 +58,6 @@ private:
bool setAvatar (const QString &path);
QVariantMap getAddress () const;
bool setAddress (const QVariantMap &address);
QVariantList getSipAddresses () const;
QVariantList getCompanies () const;
QVariantList getEmails () const;
......
......@@ -132,7 +132,7 @@ RowLayout {
}
padding: ListFormStyle.value.text.padding
visible: values.model.count === 0 && !listForm.readOnly
visible: values.model.count === 0 // TODO: placeholder click machin
verticalAlignment: Text.AlignVCenter
MouseArea {
......
......@@ -12,6 +12,16 @@ RowLayout {
property bool readOnly: false
property var fields
signal changed (int index, string value)
// ---------------------------------------------------------------------------
function _handleEditionFinished (index, text) {
if (text !== fields[index].text) {
form.changed(index, text)
}
}
// ---------------------------------------------------------------------------
spacing: 0
......@@ -48,7 +58,9 @@ RowLayout {
placeholder: modelData.placeholder || ''
readOnly: form.readOnly
text: modelData.text || ''
onEditingFinished: _handleEditionFinished(index, text)
}
}
}
}
}
......@@ -76,7 +76,7 @@ Item {
width: textInput.width
verticalAlignment: Text.AlignVCenter
visible: textInput.text.length === 0 && !textInput.activeFocus && !textInput.readOnly
visible: textInput.text.length === 0 && (!textInput.activeFocus || textInput.readOnly)
}
TextInput {
......
......@@ -237,13 +237,27 @@ ColumnLayout {
return
}
var so_far_so_good = (defaultValue.length === 0)
? url && _vcard.addUrl(newValue)
: url && _vcard.updateUrl(defaultValue, newValue)
var so_far_so_good = url && (
defaultValue.length === 0
? _vcard.addUrl(newValue)
: _vcard.updateUrl(defaultValue, newValue)
)
urls.setInvalid(index, !so_far_so_good)
}
function _handleAddressChanged (index, value) {
if (index === 0) { // Street.
_vcard.setStreet(value)
} else if (index === 1) { // Locality.
_vcard.setLocality(value)
} else if (index === 2) { // Postal code.
_vcard.setPostalCode(value)
} else if (index === 3) { // Country.
_vcard.setCountry(value)
}
}
// -----------------------------------------------------------------------
ScrollBar.vertical: ForceScrollBar {}
......@@ -371,6 +385,8 @@ ColumnLayout {
readOnly: !_edition
title: qsTr('address')
onChanged: _handleAddressChanged(index, value)
}
// ---------------------------------------------------------------------
......
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