From 338fe8c07408ac7b5b73773560899924fdf5eee7 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 14 Dec 2016 16:44:24 +0100 Subject: [PATCH] feat(ui/views/App/MainWindow/ContactEdit): use vcard of Contact (in progress) --- tests/src/components/chat/ChatModel.cpp | 75 ++++++++----------- .../ui/modules/Linphone/Call/CallControls.qml | 2 +- tests/ui/modules/Linphone/Timeline.qml | 6 +- tests/ui/views/App/MainWindow/ContactEdit.qml | 51 ++++++------- 4 files changed, 61 insertions(+), 73 deletions(-) diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index 077d87e11..e277cc8fe 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -20,7 +20,7 @@ QHash ChatModel::roleNames () const { return roles; } -int ChatModel::rowCount (const QModelIndex &) const { +int ChatModel::rowCount (const QModelIndex&) const { return m_entries.count(); } @@ -40,7 +40,7 @@ QVariant ChatModel::data (const QModelIndex &index, int role) const { return QVariant(); } -bool ChatModel::removeRow (int row, const QModelIndex &) { +bool ChatModel::removeRow (int row, const QModelIndex&) { return removeRows(row, 1); } @@ -92,12 +92,8 @@ void ChatModel::fillMessageEntry ( const shared_ptr &message ) { dest["type"] = EntryType::MessageEntry; - dest["timestamp"] = QDateTime::fromMSecsSinceEpoch( - static_cast(message->getTime()) * 1000 - ); - dest["content"] = Utils::linphoneStringToQString( - message->getText() - ); + dest["timestamp"] = QDateTime::fromMSecsSinceEpoch(static_cast(message->getTime()) * 1000); + dest["content"] = ::Utils::linphoneStringToQString(message->getText()); dest["isOutgoing"] = message->isOutgoing(); } @@ -105,9 +101,7 @@ void ChatModel::fillCallStartEntry ( QVariantMap &dest, const shared_ptr &call_log ) { - QDateTime timestamp = QDateTime::fromMSecsSinceEpoch( - static_cast(call_log->getStartDate()) * 1000 - ); + QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(static_cast(call_log->getStartDate()) * 1000); dest["type"] = EntryType::CallEntry; dest["timestamp"] = timestamp; @@ -121,8 +115,8 @@ void ChatModel::fillCallEndEntry ( const shared_ptr &call_log ) { QDateTime timestamp = QDateTime::fromMSecsSinceEpoch( - static_cast(call_log->getStartDate() + call_log->getDuration()) * 1000 - ); + static_cast(call_log->getStartDate() + call_log->getDuration()) * 1000 + ); dest["type"] = EntryType::CallEntry; dest["timestamp"] = timestamp; @@ -138,9 +132,7 @@ void ChatModel::removeEntry (ChatEntryData &pair) { switch (type) { case ChatModel::MessageEntry: - m_chat_room->deleteMessage( - static_pointer_cast(pair.second) - ); + m_chat_room->deleteMessage(static_pointer_cast(pair.second)); break; case ChatModel::CallEntry: if (pair.first["status"].toInt() == linphone::CallStatusSuccess) { @@ -148,22 +140,21 @@ void ChatModel::removeEntry (ChatEntryData &pair) { // We are between `beginRemoveRows` and `endRemoveRows`. // A solution is to schedule a `removeEntry` call in the Qt main loop. shared_ptr linphone_ptr = pair.second; - QTimer::singleShot(0, this, [this, linphone_ptr]() { - auto it = find_if( - m_entries.begin(), m_entries.end(), - [linphone_ptr](const ChatEntryData &pair) { - return pair.second == linphone_ptr; - } - ); + QTimer::singleShot( + 0, this, [this, linphone_ptr]() { + auto it = find_if( + m_entries.begin(), m_entries.end(), [linphone_ptr](const ChatEntryData &pair) { + return pair.second == linphone_ptr; + } + ); - if (it != m_entries.end()) - removeEntry(static_cast(distance(m_entries.begin(), it))); - }); + if (it != m_entries.end()) + removeEntry(static_cast(distance(m_entries.begin(), it))); + } + ); } - CoreManager::getInstance()->getCore()->removeCallLog( - static_pointer_cast(pair.second) - ); + CoreManager::getInstance()->getCore()->removeCallLog(static_pointer_cast(pair.second)); break; default: qWarning() << QStringLiteral("Unknown chat entry type: %1.").arg(type); @@ -174,7 +165,7 @@ QString ChatModel::getSipAddress () const { if (!m_chat_room) return ""; - return Utils::linphoneStringToQString( + return ::Utils::linphoneStringToQString( m_chat_room->getPeerAddress()->asString() ); } @@ -189,7 +180,7 @@ void ChatModel::setSipAddress (const QString &sip_address) { m_entries.clear(); shared_ptr 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); @@ -203,18 +194,18 @@ void ChatModel::setSipAddress (const QString &sip_address) { // Get calls. auto insert_entry = [this]( - const ChatEntryData &pair, - const QList::iterator *start = NULL - ) { - auto it = lower_bound( - start ? *start : m_entries.begin(), m_entries.end(), pair, - [](const ChatEntryData &a, const ChatEntryData &b) { - return a.first["timestamp"] < b.first["timestamp"]; - } - ); + const ChatEntryData &pair, + const QList::iterator *start = NULL + ) { + auto it = lower_bound( + start ? *start : m_entries.begin(), m_entries.end(), pair, + [](const ChatEntryData &a, const ChatEntryData &b) { + return a.first["timestamp"] < b.first["timestamp"]; + } + ); - return m_entries.insert(it, pair); - }; + return m_entries.insert(it, pair); + }; for (auto &call_log : core->getCallHistoryForAddress(m_chat_room->getPeerAddress())) { linphone::CallStatus status = call_log->getStatus(); diff --git a/tests/ui/modules/Linphone/Call/CallControls.qml b/tests/ui/modules/Linphone/Call/CallControls.qml index 167696b02..b7fe94842 100644 --- a/tests/ui/modules/Linphone/Call/CallControls.qml +++ b/tests/ui/modules/Linphone/Call/CallControls.qml @@ -11,7 +11,7 @@ RowLayout { property string sipAddress // TODO. - property var contact: ContactsListModel.mapSipAddressToContact( + property var contact: ContactsListModel.mapSipAddressTocd ( sipAddress ) diff --git a/tests/ui/modules/Linphone/Timeline.qml b/tests/ui/modules/Linphone/Timeline.qml index 3b57c576f..75e4423a3 100644 --- a/tests/ui/modules/Linphone/Timeline.qml +++ b/tests/ui/modules/Linphone/Timeline.qml @@ -6,7 +6,7 @@ import Linphone 1.0 import Linphone.Styles 1.0 import Utils 1.0 -// =================================================================== +// ============================================================================= ColumnLayout { id: timeline @@ -15,13 +15,13 @@ ColumnLayout { signal entrySelected (var entry) - // ----------------------------------------------------------------- + // --------------------------------------------------------------------------- function resetSelectedItem () { view.currentIndex = -1 } - // ----------------------------------------------------------------- + // --------------------------------------------------------------------------- spacing: 0 diff --git a/tests/ui/views/App/MainWindow/ContactEdit.qml b/tests/ui/views/App/MainWindow/ContactEdit.qml index d7c71080e..cf8d471b9 100644 --- a/tests/ui/views/App/MainWindow/ContactEdit.qml +++ b/tests/ui/views/App/MainWindow/ContactEdit.qml @@ -18,6 +18,7 @@ ColumnLayout { property string sipAddress: '' property var _contact + property var _vcard // ----------------------------------------------------------------- @@ -35,18 +36,14 @@ ColumnLayout { } function _setAvatar (path) { - if (Utils.isObject(_contact) && path) { - _contact.avatar = path.match(/^(?:file:\/\/)?(.*)$/)[1] - } + _vcard.avatar = path.match(/^(?:file:\/\/)?(.*)$/)[1] } function _setUsername (username) { - if (Utils.isObject(_contact)) { - _contact.username = username + _vcard.username = username - // Update current text with new username. - usernameInput.text = _contact.username - } + // Update current text with new username. + usernameInput.text = _vcard.username } function _handleSipAddressChanged (index, default_value, new_value) { @@ -59,8 +56,8 @@ ColumnLayout { } var so_far_so_good = (default_value.length === 0) - ? _contact.addSipAddress(new_value) - : _contact.updateSipAddress(default_value, new_value) + ? _vcard.addSipAddress(new_value) + : _vcard.updateSipAddress(default_value, new_value) addresses.setInvalid(index, !so_far_so_good) } @@ -72,8 +69,8 @@ ColumnLayout { } var so_far_so_good = (default_value.length === 0) - ? url && _contact.addUrl(new_value) - : url && _contact.updateUrl(default_value, new_value) + ? url && _vcard.addUrl(new_value) + : url && _vcard.updateUrl(default_value, new_value) urls.setInvalid(index, !so_far_so_good) } @@ -84,7 +81,7 @@ ColumnLayout { Component.onCompleted: { _contact = ContactsListModel.mapSipAddressToContact(sipAddress) - || ContactsListModel.createDetachedContact() + _vcard = _contact.vcard } // ----------------------------------------------------------------- @@ -126,7 +123,7 @@ ColumnLayout { id: avatar anchors.fill: parent - image: _contact.avatar + image: _vcard.avatar username: LinphoneUtils.getContactUsername(_contact) || 'John Doe' visible: isLoaded() && !parent.hovered } @@ -154,7 +151,7 @@ ColumnLayout { Layout.alignment: Qt.AlignRight iconSize: ContactEditStyle.infoBar.buttons.size spacing: ContactEditStyle.infoBar.buttons.spacing - visible: Utils.isObject(_contact) + visible: _contact != null ActionButton { icon: 'history' @@ -200,13 +197,13 @@ ColumnLayout { Layout.rightMargin: ContactEditStyle.values.rightMargin Layout.topMargin: ContactEditStyle.values.topMargin - defaultData: _contact.sipAddresses + defaultData: _vcard.sipAddresses minValues: 1 placeholder: qsTr('sipAccountsInput') title: qsTr('sipAccounts') onChanged: _handleSipAddressChanged(index, default_value, new_value) - onRemoved: _contact.removeSipAddress(value) + onRemoved: _vcard.removeSipAddress(value) } Rectangle { @@ -221,14 +218,14 @@ ColumnLayout { Layout.leftMargin: ContactEditStyle.values.leftMargin Layout.rightMargin: ContactEditStyle.values.rightMargin - defaultData: _contact.companies + defaultData: _vcard.companies placeholder: qsTr('companiesInput') title: qsTr('companies') onChanged: default_value.length === 0 - ? _contact.addCompany(new_value) - : _contact.updateCompany(default_value, new_value) - onRemoved: _contact.removeCompany(value) + ? _vcard.addCompany(new_value) + : _vcard.updateCompany(default_value, new_value) + onRemoved: _vcard.removeCompany(value) } Rectangle { @@ -243,15 +240,15 @@ ColumnLayout { Layout.leftMargin: ContactEditStyle.values.leftMargin Layout.rightMargin: ContactEditStyle.values.rightMargin - defaultData: _contact.emails + defaultData: _vcard.emails inputMethodHints: Qt.ImhEmailCharactersOnly placeholder: qsTr('emailsInput') title: qsTr('emails') onChanged: default_value.length === 0 - ? _contact.addEmail(new_value) - : _contact.updateEmail(default_value, new_value) - onRemoved: _contact.removeEmail(value) + ? _vcard.addEmail(new_value) + : _vcard.updateEmail(default_value, new_value) + onRemoved: _vcard.removeEmail(value) } Rectangle { @@ -266,13 +263,13 @@ ColumnLayout { Layout.leftMargin: ContactEditStyle.values.leftMargin Layout.rightMargin: ContactEditStyle.values.rightMargin - defaultData: _contact.urls + defaultData: _vcard.urls inputMethodHints: Qt.ImhUrlCharactersOnly placeholder: qsTr('webSitesInput') title: qsTr('webSites') onChanged: _handleUrlChanged(index, default_value, new_value) - onRemoved: _contact.removeUrl(value) + onRemoved: _vcard.removeUrl(value) } Rectangle {