mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(ui/views/App/MainWindow/ContactEdit): use vcard of Contact (in progress)
This commit is contained in:
parent
08fbc20c97
commit
338fe8c074
4 changed files with 61 additions and 73 deletions
|
|
@ -20,7 +20,7 @@ QHash<int, QByteArray> 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<linphone::ChatMessage> &message
|
||||
) {
|
||||
dest["type"] = EntryType::MessageEntry;
|
||||
dest["timestamp"] = QDateTime::fromMSecsSinceEpoch(
|
||||
static_cast<qint64>(message->getTime()) * 1000
|
||||
);
|
||||
dest["content"] = Utils::linphoneStringToQString(
|
||||
message->getText()
|
||||
);
|
||||
dest["timestamp"] = QDateTime::fromMSecsSinceEpoch(static_cast<qint64>(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<linphone::CallLog> &call_log
|
||||
) {
|
||||
QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(
|
||||
static_cast<qint64>(call_log->getStartDate()) * 1000
|
||||
);
|
||||
QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(static_cast<qint64>(call_log->getStartDate()) * 1000);
|
||||
|
||||
dest["type"] = EntryType::CallEntry;
|
||||
dest["timestamp"] = timestamp;
|
||||
|
|
@ -121,8 +115,8 @@ void ChatModel::fillCallEndEntry (
|
|||
const shared_ptr<linphone::CallLog> &call_log
|
||||
) {
|
||||
QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(
|
||||
static_cast<qint64>(call_log->getStartDate() + call_log->getDuration()) * 1000
|
||||
);
|
||||
static_cast<qint64>(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<linphone::ChatMessage>(pair.second)
|
||||
);
|
||||
m_chat_room->deleteMessage(static_pointer_cast<linphone::ChatMessage>(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<void> 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<int>(distance(m_entries.begin(), it)));
|
||||
});
|
||||
if (it != m_entries.end())
|
||||
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;
|
||||
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<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);
|
||||
|
||||
|
|
@ -203,18 +194,18 @@ void ChatModel::setSipAddress (const QString &sip_address) {
|
|||
|
||||
// Get calls.
|
||||
auto insert_entry = [this](
|
||||
const ChatEntryData &pair,
|
||||
const QList<ChatEntryData>::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<ChatEntryData>::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();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ RowLayout {
|
|||
property string sipAddress
|
||||
|
||||
// TODO.
|
||||
property var contact: ContactsListModel.mapSipAddressToContact(
|
||||
property var contact: ContactsListModel.mapSipAddressTocd (
|
||||
sipAddress
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue