Commit 8de2b05b authored by Ronan Abhamon's avatar Ronan Abhamon

unstable

parent efcd75c6
...@@ -37,9 +37,25 @@ inline shared_ptr<T> findBelCardValue ( ...@@ -37,9 +37,25 @@ inline shared_ptr<T> findBelCardValue (
// ------------------------------------------------------------------- // -------------------------------------------------------------------
ContactModel::ContactModel (shared_ptr<linphone::Friend> linphone_friend) { ContactModel::ContactModel (
shared_ptr<linphone::Friend> linphone_friend,
bool is_detached
) {
linphone_friend->setData("contact-model", *this); linphone_friend->setData("contact-model", *this);
m_linphone_friend = linphone_friend; m_linphone_friend = linphone_friend;
m_is_detached = is_detached;
}
// -------------------------------------------------------------------
void ContactModel::edit () {
if (!m_is_detached)
m_linphone_friend->edit();
}
void ContactModel::done () {
if (!m_is_detached)
m_linphone_friend->done();
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -54,12 +70,12 @@ void ContactModel::setUsername (const QString &username) { ...@@ -54,12 +70,12 @@ void ContactModel::setUsername (const QString &username) {
if (username.length() == 0 || username == getUsername()) if (username.length() == 0 || username == getUsername())
return; return;
m_linphone_friend->edit(); edit();
if (!m_linphone_friend->setName(Utils::qStringToLinphoneString(username))) if (!m_linphone_friend->setName(Utils::qStringToLinphoneString(username)))
emit contactUpdated(); emit contactUpdated();
m_linphone_friend->done(); done();
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -109,7 +125,7 @@ void ContactModel::setAvatar (const QString &path) { ...@@ -109,7 +125,7 @@ void ContactModel::setAvatar (const QString &path) {
.arg(getUsername()).arg(dest); .arg(getUsername()).arg(dest);
// 2. Edit vcard. // 2. Edit vcard.
m_linphone_friend->edit(); edit();
shared_ptr<belcard::BelCard> belCard = m_linphone_friend->getVcard()->getBelcard(); shared_ptr<belcard::BelCard> belCard = m_linphone_friend->getVcard()->getBelcard();
list<shared_ptr<belcard::BelCardPhoto> > photos = belCard->getPhotos(); list<shared_ptr<belcard::BelCardPhoto> > photos = belCard->getPhotos();
...@@ -136,7 +152,7 @@ void ContactModel::setAvatar (const QString &path) { ...@@ -136,7 +152,7 @@ void ContactModel::setAvatar (const QString &path) {
photo->setValue(VCARD_SCHEME + Utils::qStringToLinphoneString(file_id)); photo->setValue(VCARD_SCHEME + Utils::qStringToLinphoneString(file_id));
belCard->addPhoto(photo); belCard->addPhoto(photo);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
...@@ -167,9 +183,9 @@ bool ContactModel::addSipAddress (const QString &sip_address) { ...@@ -167,9 +183,9 @@ bool ContactModel::addSipAddress (const QString &sip_address) {
qInfo() << QStringLiteral("Add new sip address: `%1`.").arg(sip_address); qInfo() << QStringLiteral("Add new sip address: `%1`.").arg(sip_address);
m_linphone_friend->edit(); edit();
m_linphone_friend->addAddress(address); m_linphone_friend->addAddress(address);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
...@@ -201,9 +217,9 @@ void ContactModel::removeSipAddress (const QString &sip_address) { ...@@ -201,9 +217,9 @@ void ContactModel::removeSipAddress (const QString &sip_address) {
qInfo() << QStringLiteral("Remove sip address: `%1`.").arg(sip_address); qInfo() << QStringLiteral("Remove sip address: `%1`.").arg(sip_address);
m_linphone_friend->edit(); edit();
m_linphone_friend->removeAddress(*it); m_linphone_friend->removeAddress(*it);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
...@@ -238,9 +254,9 @@ void ContactModel::addCompany (const QString &company) { ...@@ -238,9 +254,9 @@ void ContactModel::addCompany (const QString &company) {
qInfo() << QStringLiteral("Add new company: `%1`.").arg(company); qInfo() << QStringLiteral("Add new company: `%1`.").arg(company);
m_linphone_friend->edit(); edit();
belCard->addRole(value); belCard->addRole(value);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
} }
...@@ -256,9 +272,9 @@ void ContactModel::removeCompany (const QString &company) { ...@@ -256,9 +272,9 @@ void ContactModel::removeCompany (const QString &company) {
qInfo() << QStringLiteral("Remove company: `%1`.").arg(company); qInfo() << QStringLiteral("Remove company: `%1`.").arg(company);
m_linphone_friend->edit(); edit();
belCard->removeRole(value); belCard->removeRole(value);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
} }
...@@ -290,9 +306,9 @@ bool ContactModel::addEmail (const QString &email) { ...@@ -290,9 +306,9 @@ bool ContactModel::addEmail (const QString &email) {
qInfo() << QStringLiteral("Add new email: `%1`.").arg(email); qInfo() << QStringLiteral("Add new email: `%1`.").arg(email);
m_linphone_friend->edit(); edit();
belCard->addEmail(value); belCard->addEmail(value);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
...@@ -311,9 +327,9 @@ void ContactModel::removeEmail (const QString &email) { ...@@ -311,9 +327,9 @@ void ContactModel::removeEmail (const QString &email) {
qInfo() << QStringLiteral("Remove email: `%1`.").arg(email); qInfo() << QStringLiteral("Remove email: `%1`.").arg(email);
m_linphone_friend->edit(); edit();
belCard->removeEmail(value); belCard->removeEmail(value);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
} }
...@@ -332,6 +348,8 @@ bool ContactModel::updateEmail (const QString &old_email, const QString &email) ...@@ -332,6 +348,8 @@ bool ContactModel::updateEmail (const QString &old_email, const QString &email)
QVariantList ContactModel::getUrls () const { QVariantList ContactModel::getUrls () const {
QVariantList list; QVariantList list;
qDebug() << "card" << m_linphone_friend->getVcard().get();
for (const auto &url : m_linphone_friend->getVcard()->getBelcard()->getURLs()) for (const auto &url : m_linphone_friend->getVcard()->getBelcard()->getURLs())
list.append(Utils::linphoneStringToQString(url->getValue())); list.append(Utils::linphoneStringToQString(url->getValue()));
...@@ -346,9 +364,9 @@ bool ContactModel::addUrl (const QString &url) { ...@@ -346,9 +364,9 @@ bool ContactModel::addUrl (const QString &url) {
qInfo() << QStringLiteral("Add new url: `%1`.").arg(url); qInfo() << QStringLiteral("Add new url: `%1`.").arg(url);
m_linphone_friend->edit(); edit();
belCard->addURL(value); belCard->addURL(value);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
...@@ -367,9 +385,9 @@ void ContactModel::removeUrl (const QString &url) { ...@@ -367,9 +385,9 @@ void ContactModel::removeUrl (const QString &url) {
qInfo() << QStringLiteral("Remove url: `%1`.").arg(url); qInfo() << QStringLiteral("Remove url: `%1`.").arg(url);
m_linphone_friend->edit(); edit();
belCard->removeURL(value); belCard->removeURL(value);
m_linphone_friend->done(); done();
emit contactUpdated(); emit contactUpdated();
} }
......
...@@ -41,9 +41,13 @@ class ContactModel : public QObject { ...@@ -41,9 +41,13 @@ class ContactModel : public QObject {
); );
public: public:
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend); ContactModel (
std::shared_ptr<linphone::Friend> linphone_friend,
bool is_detached = false
);
public slots: public slots:
bool addSipAddress (const QString &sip_address); bool addSipAddress (const QString &sip_address);
void removeSipAddress (const QString &sip_address); void removeSipAddress (const QString &sip_address);
bool updateSipAddress (const QString &old_sip_address, const QString &sip_address); bool updateSipAddress (const QString &old_sip_address, const QString &sip_address);
...@@ -64,6 +68,9 @@ signals: ...@@ -64,6 +68,9 @@ signals:
void contactUpdated (); void contactUpdated ();
private: private:
void edit ();
void done ();
QString getUsername () const; QString getUsername () const;
void setUsername (const QString &username); void setUsername (const QString &username);
...@@ -84,6 +91,8 @@ private: ...@@ -84,6 +91,8 @@ private:
// TODO: Remove!!! // TODO: Remove!!!
QString getSipAddress () const; QString getSipAddress () const;
bool m_is_detached;
Presence::PresenceStatus m_presence_status = Presence::Offline; Presence::PresenceStatus m_presence_status = Presence::Offline;
std::shared_ptr<linphone::Friend> m_linphone_friend; std::shared_ptr<linphone::Friend> m_linphone_friend;
......
...@@ -16,6 +16,9 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren ...@@ -16,6 +16,9 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
// Init contacts with linphone friends list. // Init contacts with linphone friends list.
for (const auto &friend_ : m_linphone_friends->getFriends()) { for (const auto &friend_ : m_linphone_friends->getFriends()) {
ContactModel *contact = new ContactModel(friend_); ContactModel *contact = new ContactModel(friend_);
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
App::getInstance()->getEngine()->setObjectOwnership( App::getInstance()->getEngine()->setObjectOwnership(
contact, QQmlEngine::CppOwnership contact, QQmlEngine::CppOwnership
); );
...@@ -72,6 +75,13 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren ...@@ -72,6 +75,13 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
// ------------------------------------------------------------------- // -------------------------------------------------------------------
ContactModel *ContactsListModel::createDetachedContact () const {
return new ContactModel(
CoreManager::getInstance()->getCore()->createFriend(),
true
);
}
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const { ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const {
// Maybe use a hashtable in future version to get a lower cost? // Maybe use a hashtable in future version to get a lower cost?
std::shared_ptr<linphone::Friend> friend_ = m_linphone_friends->findFriendByUri( std::shared_ptr<linphone::Friend> friend_ = m_linphone_friends->findFriendByUri(
......
...@@ -25,12 +25,10 @@ public: ...@@ -25,12 +25,10 @@ public:
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override; bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
public slots: public slots:
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership ContactModel *createDetachedContact () const;
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
ContactModel *mapSipAddressToContact (const QString &sipAddress) const; ContactModel *mapSipAddressToContact (const QString &sipAddress) const;
void removeContact (ContactModel *contact); void removeContact (ContactModel *contact);
private: private:
QList<ContactModel *> m_list; QList<ContactModel *> m_list;
std::shared_ptr<linphone::FriendList> m_linphone_friends; std::shared_ptr<linphone::FriendList> m_linphone_friends;
......
...@@ -12,7 +12,9 @@ RowLayout { ...@@ -12,7 +12,9 @@ RowLayout {
property alias placeholder: placeholder.text property alias placeholder: placeholder.text
property alias title: text.text property alias title: text.text
property int inputMethodHints
property var defaultData: [] property var defaultData: []
property var minValues
signal changed (int index, string default_value, string new_value) signal changed (int index, string default_value, string new_value)
signal removed (int index, string value) signal removed (int index, string value)
...@@ -47,15 +49,31 @@ RowLayout { ...@@ -47,15 +49,31 @@ RowLayout {
function _handleEditionFinished (index, text) { function _handleEditionFinished (index, text) {
if (text.length === 0) { if (text.length === 0) {
// Remove.
var default_value = values.model.get(index).$value var default_value = values.model.get(index).$value
if (minValues != null && minValues >= values.model.count) {
var model = values.model
// Unable to set property directly. Qt uses a cache of the value.
model.remove(index)
model.insert(index, {
$isInvalid: false,
$value: default_value
})
return
}
values.model.remove(index) values.model.remove(index)
if (default_value.length !== 0) { if (default_value.length !== 0) {
listForm.removed(index, default_value) listForm.removed(index, default_value)
} }
} else { } else {
// Update.
var default_value = values.model.get(index).$value var default_value = values.model.get(index).$value
// If no changes, no signal.
if (text !== default_value) { if (text !== default_value) {
listForm.changed(index, default_value, text) listForm.changed(index, default_value, text)
} }
...@@ -145,6 +163,7 @@ RowLayout { ...@@ -145,6 +163,7 @@ RowLayout {
TransparentTextInput { TransparentTextInput {
id: textInput id: textInput
inputMethodHints: listForm.inputMethodHints
isInvalid: $isInvalid isInvalid: $isInvalid
text: $value text: $value
......
...@@ -10,11 +10,11 @@ import Common.Styles 1.0 ...@@ -10,11 +10,11 @@ import Common.Styles 1.0
Item { Item {
property alias color: textInput.color property alias color: textInput.color
property alias font: textInput.font property alias font: textInput.font
property alias inputMethodHints: textInput.inputMethodHints
property alias readOnly: textInput.readOnly property alias readOnly: textInput.readOnly
property alias text: textInput.text property alias text: textInput.text
property bool isInvalid: false property bool isInvalid: false
property int padding: TransparentTextInputStyle.padding property int padding: TransparentTextInputStyle.padding
signal editingFinished signal editingFinished
// ----------------------------------------------------------------- // -----------------------------------------------------------------
......
...@@ -62,9 +62,7 @@ ColumnLayout { ...@@ -62,9 +62,7 @@ ColumnLayout {
? _contact.addSipAddress(new_value) ? _contact.addSipAddress(new_value)
: _contact.updateSipAddress(default_value, new_value) : _contact.updateSipAddress(default_value, new_value)
if (!so_far_so_good) { addresses.setInvalid(index, !so_far_so_good)
addresses.setInvalid(index, true)
}
} }
function _handleUrlChanged (index, default_value, new_value) { function _handleUrlChanged (index, default_value, new_value) {
...@@ -77,30 +75,16 @@ ColumnLayout { ...@@ -77,30 +75,16 @@ ColumnLayout {
? url && _contact.addUrl(new_value) ? url && _contact.addUrl(new_value)
: url && _contact.updateUrl(default_value, new_value) : url && _contact.updateUrl(default_value, new_value)
if (!so_far_so_good) { urls.setInvalid(index, !so_far_so_good)
urls.setInvalid(index, true)
}
} }
// ----------------------------------------------------------------- // -----------------------------------------------------------------
spacing: 0 spacing: 0
Component.onCompleted: { Component.onCompleted: {
var contact = ContactsListModel.mapSipAddressToContact(sipAddress) _contact = ContactsListModel.mapSipAddressToContact(sipAddress)
|| ContactsListModel.createDetachedContact()
if (contact) {
infoUpdater.connect(contact, 'onContactUpdated', function () {
addresses.setData(contact.sipAddresses)
companies.setData(contact.companies)
emails.setData(contact.emails)
urls.setData(contact.urls)
})
_contact = contact
} else {
_contact = sipAddress
}
} }
// ----------------------------------------------------------------- // -----------------------------------------------------------------
...@@ -209,10 +193,6 @@ ColumnLayout { ...@@ -209,10 +193,6 @@ ColumnLayout {
width: flick.contentWidth width: flick.contentWidth
SmartConnect {
id: infoUpdater
}
ListForm { ListForm {
id: addresses id: addresses
...@@ -221,6 +201,7 @@ ColumnLayout { ...@@ -221,6 +201,7 @@ ColumnLayout {
Layout.topMargin: ContactEditStyle.values.topMargin Layout.topMargin: ContactEditStyle.values.topMargin
defaultData: _contact.sipAddresses defaultData: _contact.sipAddresses
minValues: 1
placeholder: qsTr('sipAccountsInput') placeholder: qsTr('sipAccountsInput')
title: qsTr('sipAccounts') title: qsTr('sipAccounts')
...@@ -263,6 +244,7 @@ ColumnLayout { ...@@ -263,6 +244,7 @@ ColumnLayout {
Layout.rightMargin: ContactEditStyle.values.rightMargin Layout.rightMargin: ContactEditStyle.values.rightMargin
defaultData: _contact.emails defaultData: _contact.emails
inputMethodHints: Qt.ImhEmailCharactersOnly
placeholder: qsTr('emailsInput') placeholder: qsTr('emailsInput')
title: qsTr('emails') title: qsTr('emails')
...@@ -285,6 +267,7 @@ ColumnLayout { ...@@ -285,6 +267,7 @@ ColumnLayout {
Layout.rightMargin: ContactEditStyle.values.rightMargin Layout.rightMargin: ContactEditStyle.values.rightMargin
defaultData: _contact.urls defaultData: _contact.urls
inputMethodHints: Qt.ImhUrlCharactersOnly
placeholder: qsTr('webSitesInput') placeholder: qsTr('webSitesInput')
title: qsTr('webSites') title: qsTr('webSites')
......
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