Commit 338fe8c0 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/views/App/MainWindow/ContactEdit): use vcard of Contact (in progress)

parent 08fbc20c
...@@ -20,7 +20,7 @@ QHash<int, QByteArray> ChatModel::roleNames () const { ...@@ -20,7 +20,7 @@ QHash<int, QByteArray> ChatModel::roleNames () const {
return roles; return roles;
} }
int ChatModel::rowCount (const QModelIndex &) const { int ChatModel::rowCount (const QModelIndex&) const {
return m_entries.count(); return m_entries.count();
} }
...@@ -40,7 +40,7 @@ QVariant ChatModel::data (const QModelIndex &index, int role) const { ...@@ -40,7 +40,7 @@ QVariant ChatModel::data (const QModelIndex &index, int role) const {
return QVariant(); return QVariant();
} }
bool ChatModel::removeRow (int row, const QModelIndex &) { bool ChatModel::removeRow (int row, const QModelIndex&) {
return removeRows(row, 1); return removeRows(row, 1);
} }
...@@ -92,12 +92,8 @@ void ChatModel::fillMessageEntry ( ...@@ -92,12 +92,8 @@ void ChatModel::fillMessageEntry (
const shared_ptr<linphone::ChatMessage> &message const shared_ptr<linphone::ChatMessage> &message
) { ) {
dest["type"] = EntryType::MessageEntry; dest["type"] = EntryType::MessageEntry;
dest["timestamp"] = QDateTime::fromMSecsSinceEpoch( dest["timestamp"] = QDateTime::fromMSecsSinceEpoch(static_cast<qint64>(message->getTime()) * 1000);
static_cast<qint64>(message->getTime()) * 1000 dest["content"] = ::Utils::linphoneStringToQString(message->getText());
);
dest["content"] = Utils::linphoneStringToQString(
message->getText()
);
dest["isOutgoing"] = message->isOutgoing(); dest["isOutgoing"] = message->isOutgoing();
} }
...@@ -105,9 +101,7 @@ void ChatModel::fillCallStartEntry ( ...@@ -105,9 +101,7 @@ void ChatModel::fillCallStartEntry (
QVariantMap &dest, QVariantMap &dest,
const shared_ptr<linphone::CallLog> &call_log const shared_ptr<linphone::CallLog> &call_log
) { ) {
QDateTime timestamp = QDateTime::fromMSecsSinceEpoch( QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(static_cast<qint64>(call_log->getStartDate()) * 1000);
static_cast<qint64>(call_log->getStartDate()) * 1000
);
dest["type"] = EntryType::CallEntry; dest["type"] = EntryType::CallEntry;
dest["timestamp"] = timestamp; dest["timestamp"] = timestamp;
...@@ -138,9 +132,7 @@ void ChatModel::removeEntry (ChatEntryData &pair) { ...@@ -138,9 +132,7 @@ void ChatModel::removeEntry (ChatEntryData &pair) {
switch (type) { switch (type) {
case ChatModel::MessageEntry: case ChatModel::MessageEntry:
m_chat_room->deleteMessage( m_chat_room->deleteMessage(static_pointer_cast<linphone::ChatMessage>(pair.second));
static_pointer_cast<linphone::ChatMessage>(pair.second)
);
break; break;
case ChatModel::CallEntry: case ChatModel::CallEntry:
if (pair.first["status"].toInt() == linphone::CallStatusSuccess) { if (pair.first["status"].toInt() == linphone::CallStatusSuccess) {
...@@ -148,22 +140,21 @@ void ChatModel::removeEntry (ChatEntryData &pair) { ...@@ -148,22 +140,21 @@ void ChatModel::removeEntry (ChatEntryData &pair) {
// We are between `beginRemoveRows` and `endRemoveRows`. // We are between `beginRemoveRows` and `endRemoveRows`.
// A solution is to schedule a `removeEntry` call in the Qt main loop. // A solution is to schedule a `removeEntry` call in the Qt main loop.
shared_ptr<void> linphone_ptr = pair.second; shared_ptr<void> linphone_ptr = pair.second;
QTimer::singleShot(0, this, [this, linphone_ptr]() { QTimer::singleShot(
0, this, [this, linphone_ptr]() {
auto it = find_if( auto it = find_if(
m_entries.begin(), m_entries.end(), m_entries.begin(), m_entries.end(), [linphone_ptr](const ChatEntryData &pair) {
[linphone_ptr](const ChatEntryData &pair) {
return pair.second == linphone_ptr; return pair.second == linphone_ptr;
} }
); );
if (it != m_entries.end()) if (it != m_entries.end())
removeEntry(static_cast<int>(distance(m_entries.begin(), it))); removeEntry(static_cast<int>(distance(m_entries.begin(), it)));
});
} }
CoreManager::getInstance()->getCore()->removeCallLog(
static_pointer_cast<linphone::CallLog>(pair.second)
); );
}
CoreManager::getInstance()->getCore()->removeCallLog(static_pointer_cast<linphone::CallLog>(pair.second));
break; break;
default: default:
qWarning() << QStringLiteral("Unknown chat entry type: %1.").arg(type); qWarning() << QStringLiteral("Unknown chat entry type: %1.").arg(type);
...@@ -174,7 +165,7 @@ QString ChatModel::getSipAddress () const { ...@@ -174,7 +165,7 @@ QString ChatModel::getSipAddress () const {
if (!m_chat_room) if (!m_chat_room)
return ""; return "";
return Utils::linphoneStringToQString( return ::Utils::linphoneStringToQString(
m_chat_room->getPeerAddress()->asString() m_chat_room->getPeerAddress()->asString()
); );
} }
...@@ -189,7 +180,7 @@ void ChatModel::setSipAddress (const QString &sip_address) { ...@@ -189,7 +180,7 @@ void ChatModel::setSipAddress (const QString &sip_address) {
m_entries.clear(); m_entries.clear();
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
string std_sip_address = Utils::qStringToLinphoneString(sip_address); string std_sip_address = ::Utils::qStringToLinphoneString(sip_address);
m_chat_room = core->getChatRoomFromUri(std_sip_address); m_chat_room = core->getChatRoomFromUri(std_sip_address);
......
...@@ -11,7 +11,7 @@ RowLayout { ...@@ -11,7 +11,7 @@ RowLayout {
property string sipAddress property string sipAddress
// TODO. // TODO.
property var contact: ContactsListModel.mapSipAddressToContact( property var contact: ContactsListModel.mapSipAddressTocd (
sipAddress sipAddress
) )
......
...@@ -6,7 +6,7 @@ import Linphone 1.0 ...@@ -6,7 +6,7 @@ import Linphone 1.0
import Linphone.Styles 1.0 import Linphone.Styles 1.0
import Utils 1.0 import Utils 1.0
// =================================================================== // =============================================================================
ColumnLayout { ColumnLayout {
id: timeline id: timeline
...@@ -15,13 +15,13 @@ ColumnLayout { ...@@ -15,13 +15,13 @@ ColumnLayout {
signal entrySelected (var entry) signal entrySelected (var entry)
// ----------------------------------------------------------------- // ---------------------------------------------------------------------------
function resetSelectedItem () { function resetSelectedItem () {
view.currentIndex = -1 view.currentIndex = -1
} }
// ----------------------------------------------------------------- // ---------------------------------------------------------------------------
spacing: 0 spacing: 0
......
...@@ -18,6 +18,7 @@ ColumnLayout { ...@@ -18,6 +18,7 @@ ColumnLayout {
property string sipAddress: '' property string sipAddress: ''
property var _contact property var _contact
property var _vcard
// ----------------------------------------------------------------- // -----------------------------------------------------------------
...@@ -35,18 +36,14 @@ ColumnLayout { ...@@ -35,18 +36,14 @@ ColumnLayout {
} }
function _setAvatar (path) { function _setAvatar (path) {
if (Utils.isObject(_contact) && path) { _vcard.avatar = path.match(/^(?:file:\/\/)?(.*)$/)[1]
_contact.avatar = path.match(/^(?:file:\/\/)?(.*)$/)[1]
}
} }
function _setUsername (username) { function _setUsername (username) {
if (Utils.isObject(_contact)) { _vcard.username = username
_contact.username = username
// Update current text with new username. // Update current text with new username.
usernameInput.text = _contact.username usernameInput.text = _vcard.username
}
} }
function _handleSipAddressChanged (index, default_value, new_value) { function _handleSipAddressChanged (index, default_value, new_value) {
...@@ -59,8 +56,8 @@ ColumnLayout { ...@@ -59,8 +56,8 @@ ColumnLayout {
} }
var so_far_so_good = (default_value.length === 0) var so_far_so_good = (default_value.length === 0)
? _contact.addSipAddress(new_value) ? _vcard.addSipAddress(new_value)
: _contact.updateSipAddress(default_value, new_value) : _vcard.updateSipAddress(default_value, new_value)
addresses.setInvalid(index, !so_far_so_good) addresses.setInvalid(index, !so_far_so_good)
} }
...@@ -72,8 +69,8 @@ ColumnLayout { ...@@ -72,8 +69,8 @@ ColumnLayout {
} }
var so_far_so_good = (default_value.length === 0) var so_far_so_good = (default_value.length === 0)
? url && _contact.addUrl(new_value) ? url && _vcard.addUrl(new_value)
: url && _contact.updateUrl(default_value, new_value) : url && _vcard.updateUrl(default_value, new_value)
urls.setInvalid(index, !so_far_so_good) urls.setInvalid(index, !so_far_so_good)
} }
...@@ -84,7 +81,7 @@ ColumnLayout { ...@@ -84,7 +81,7 @@ ColumnLayout {
Component.onCompleted: { Component.onCompleted: {
_contact = ContactsListModel.mapSipAddressToContact(sipAddress) _contact = ContactsListModel.mapSipAddressToContact(sipAddress)
|| ContactsListModel.createDetachedContact() _vcard = _contact.vcard
} }
// ----------------------------------------------------------------- // -----------------------------------------------------------------
...@@ -126,7 +123,7 @@ ColumnLayout { ...@@ -126,7 +123,7 @@ ColumnLayout {
id: avatar id: avatar
anchors.fill: parent anchors.fill: parent
image: _contact.avatar image: _vcard.avatar
username: LinphoneUtils.getContactUsername(_contact) || 'John Doe' username: LinphoneUtils.getContactUsername(_contact) || 'John Doe'
visible: isLoaded() && !parent.hovered visible: isLoaded() && !parent.hovered
} }
...@@ -154,7 +151,7 @@ ColumnLayout { ...@@ -154,7 +151,7 @@ ColumnLayout {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
iconSize: ContactEditStyle.infoBar.buttons.size iconSize: ContactEditStyle.infoBar.buttons.size
spacing: ContactEditStyle.infoBar.buttons.spacing spacing: ContactEditStyle.infoBar.buttons.spacing
visible: Utils.isObject(_contact) visible: _contact != null
ActionButton { ActionButton {
icon: 'history' icon: 'history'
...@@ -200,13 +197,13 @@ ColumnLayout { ...@@ -200,13 +197,13 @@ ColumnLayout {
Layout.rightMargin: ContactEditStyle.values.rightMargin Layout.rightMargin: ContactEditStyle.values.rightMargin
Layout.topMargin: ContactEditStyle.values.topMargin Layout.topMargin: ContactEditStyle.values.topMargin
defaultData: _contact.sipAddresses defaultData: _vcard.sipAddresses
minValues: 1 minValues: 1
placeholder: qsTr('sipAccountsInput') placeholder: qsTr('sipAccountsInput')
title: qsTr('sipAccounts') title: qsTr('sipAccounts')
onChanged: _handleSipAddressChanged(index, default_value, new_value) onChanged: _handleSipAddressChanged(index, default_value, new_value)
onRemoved: _contact.removeSipAddress(value) onRemoved: _vcard.removeSipAddress(value)
} }
Rectangle { Rectangle {
...@@ -221,14 +218,14 @@ ColumnLayout { ...@@ -221,14 +218,14 @@ ColumnLayout {
Layout.leftMargin: ContactEditStyle.values.leftMargin Layout.leftMargin: ContactEditStyle.values.leftMargin
Layout.rightMargin: ContactEditStyle.values.rightMargin Layout.rightMargin: ContactEditStyle.values.rightMargin
defaultData: _contact.companies defaultData: _vcard.companies
placeholder: qsTr('companiesInput') placeholder: qsTr('companiesInput')
title: qsTr('companies') title: qsTr('companies')
onChanged: default_value.length === 0 onChanged: default_value.length === 0
? _contact.addCompany(new_value) ? _vcard.addCompany(new_value)
: _contact.updateCompany(default_value, new_value) : _vcard.updateCompany(default_value, new_value)
onRemoved: _contact.removeCompany(value) onRemoved: _vcard.removeCompany(value)
} }
Rectangle { Rectangle {
...@@ -243,15 +240,15 @@ ColumnLayout { ...@@ -243,15 +240,15 @@ ColumnLayout {
Layout.leftMargin: ContactEditStyle.values.leftMargin Layout.leftMargin: ContactEditStyle.values.leftMargin
Layout.rightMargin: ContactEditStyle.values.rightMargin Layout.rightMargin: ContactEditStyle.values.rightMargin
defaultData: _contact.emails defaultData: _vcard.emails
inputMethodHints: Qt.ImhEmailCharactersOnly inputMethodHints: Qt.ImhEmailCharactersOnly
placeholder: qsTr('emailsInput') placeholder: qsTr('emailsInput')
title: qsTr('emails') title: qsTr('emails')
onChanged: default_value.length === 0 onChanged: default_value.length === 0
? _contact.addEmail(new_value) ? _vcard.addEmail(new_value)
: _contact.updateEmail(default_value, new_value) : _vcard.updateEmail(default_value, new_value)
onRemoved: _contact.removeEmail(value) onRemoved: _vcard.removeEmail(value)
} }
Rectangle { Rectangle {
...@@ -266,13 +263,13 @@ ColumnLayout { ...@@ -266,13 +263,13 @@ ColumnLayout {
Layout.leftMargin: ContactEditStyle.values.leftMargin Layout.leftMargin: ContactEditStyle.values.leftMargin
Layout.rightMargin: ContactEditStyle.values.rightMargin Layout.rightMargin: ContactEditStyle.values.rightMargin
defaultData: _contact.urls defaultData: _vcard.urls
inputMethodHints: Qt.ImhUrlCharactersOnly inputMethodHints: Qt.ImhUrlCharactersOnly
placeholder: qsTr('webSitesInput') placeholder: qsTr('webSitesInput')
title: qsTr('webSites') title: qsTr('webSites')
onChanged: _handleUrlChanged(index, default_value, new_value) onChanged: _handleUrlChanged(index, default_value, new_value)
onRemoved: _contact.removeUrl(value) onRemoved: _vcard.removeUrl(value)
} }
Rectangle { Rectangle {
......
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