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