Commit d37c3b81 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/modules/Linphone/SmartSearchBar): supports not registered sip addresses

parent 39e83ddb
......@@ -134,6 +134,16 @@ void SipAddressesModel::handleAllHistoryEntriesRemoved () {
// -----------------------------------------------------------------------------
QString SipAddressesModel::interpretUrl (const QString &sip_address) {
shared_ptr<linphone::Address> l_address = CoreManager::getInstance()->getCore()->interpretUrl(
::Utils::qStringToLinphoneString(sip_address)
);
return l_address ? ::Utils::linphoneStringToQString(l_address->asStringUriOnly()) : "";
}
// -----------------------------------------------------------------------------
bool SipAddressesModel::removeRow (int row, const QModelIndex &parent) {
return removeRows(row, 1, parent);
}
......
......@@ -27,6 +27,8 @@ public:
Q_INVOKABLE void handleAllHistoryEntriesRemoved ();
Q_INVOKABLE QString interpretUrl (const QString &sip_address);
private:
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override;
......
......@@ -19,6 +19,7 @@ Rectangle {
property alias usernameColor: description.usernameColor
property var entry
property var _contact: entry.contact
// ---------------------------------------------------------------------------
......
......@@ -19,57 +19,138 @@ SearchBox {
// ---------------------------------------------------------------------------
header: MouseArea {
id: headerContent
header: Column {
readonly property string interpretableSipAddress: SipAddressesModel.interpretUrl(searchBox.filter)
height: SmartSearchBarStyle.header.height
height: {
var height = SmartSearchBarStyle.header.addButtonHeight
return defaultContact.visible ? height + searchBox.entryHeight : height
}
width: parent.width
onClicked: {
searchBox.hideMenu()
searchBox.addContact(searchBox.filter)
spacing: 0
// -------------------------------------------------------------------------
// Default contact.
// -------------------------------------------------------------------------
Loader {
id: defaultContact
height: searchBox.entryHeight
width: parent.width
visible: interpretableSipAddress.length > 0
sourceComponent: Rectangle {
anchors.fill: parent
color: SmartSearchBarStyle.entry.color.normal
RowLayout {
anchors {
fill: parent
rightMargin: SmartSearchBarStyle.entry.rightMargin
}
spacing: 0
Contact {
id: contact
Layout.fillHeight: true
Layout.fillWidth: true
entry: Object ({
sipAddress: interpretableSipAddress
})
}
ActionBar {
iconSize: SmartSearchBarStyle.entry.iconSize
ActionButton {
icon: 'video_call'
onClicked: {
searchBox.hideMenu()
searchBox.launchVideoCall(interpretableSipAddress)
}
}
ActionButton {
icon: 'call'
onClicked: {
searchBox.hideMenu()
searchBox.launchCall(interpretableSipAddress)
}
}
ActionButton {
icon: 'chat'
onClicked: {
searchBox.hideMenu()
searchBox.launchChat(interpretableSipAddress)
}
}
}
}
}
}
Rectangle {
anchors.fill: parent
color: parent.pressed
// -------------------------------------------------------------------------
// Add contact button.
// -------------------------------------------------------------------------
MouseArea {
id: addContactButton
height: SmartSearchBarStyle.header.addButtonHeight
width: parent.width
onClicked: {
searchBox.hideMenu()
searchBox.addContact(interpretableSipAddress)
}
Rectangle {
anchors.fill: parent
color: parent.pressed
? SmartSearchBarStyle.header.color.pressed
: SmartSearchBarStyle.header.color.normal
Text {
anchors {
left: parent.left
leftMargin: SmartSearchBarStyle.header.leftMargin
verticalCenter: parent.verticalCenter
}
font {
bold: true
pointSize: SmartSearchBarStyle.header.text.fontSize
}
color: headerContent.pressed
Text {
anchors {
left: parent.left
leftMargin: SmartSearchBarStyle.header.leftMargin
verticalCenter: parent.verticalCenter
}
font {
bold: true
pointSize: SmartSearchBarStyle.header.text.fontSize
}
color: addContactButton.pressed
? SmartSearchBarStyle.header.text.color.pressed
: SmartSearchBarStyle.header.text.color.normal
text: qsTr('addContact')
}
text: qsTr('addContact')
}
Icon {
anchors {
right: parent.right
rightMargin: SmartSearchBarStyle.header.rightMargin
verticalCenter: parent.verticalCenter
Icon {
anchors {
right: parent.right
rightMargin: SmartSearchBarStyle.header.rightMargin
verticalCenter: parent.verticalCenter
}
icon: 'contact_add'
iconSize: SmartSearchBarStyle.header.iconSize
}
icon: 'contact_add'
iconSize: SmartSearchBarStyle.header.iconSize
}
}
}
// ---------------------------------------------------------------------------
// Entries.
// ---------------------------------------------------------------------------
delegate: Rectangle {
id: searchBoxEntry
id: sipAddressEntry
color: SmartSearchBarStyle.entry.color.normal
height: searchBox.entryHeight
......@@ -97,9 +178,9 @@ SearchBox {
}
spacing: 0
// ---------------------------------------------------------------------
// -------------------------------------------------------------------
// Contact or address info.
// ---------------------------------------------------------------------
// -------------------------------------------------------------------
Contact {
Layout.fillHeight: true
......@@ -107,9 +188,9 @@ SearchBox {
entry: $entry
}
// ---------------------------------------------------------------------
// -------------------------------------------------------------------
// Actions
// ---------------------------------------------------------------------
// -------------------------------------------------------------------
ActionBar {
iconSize: SmartSearchBarStyle.entry.iconSize
......@@ -155,7 +236,7 @@ SearchBox {
PropertyChanges {
color: SmartSearchBarStyle.entry.color.hovered
target: searchBoxEntry
target: sipAddressEntry
}
PropertyChanges {
......
......@@ -27,7 +27,7 @@ QtObject {
}
property QtObject header: QtObject {
property int height: 40
property int addButtonHeight: 40
property int iconSize: 22
property int leftMargin: 20
property int rightMargin: 10
......
......@@ -89,9 +89,7 @@ ColumnLayout {
_vcard = CoreManager.createDetachedVcardModel()
if (sipAddress && sipAddress.length > 0) {
_vcard.addSipAddress(
Utils.startsWith(sipAddress, 'sip:') ? sipAddress : 'sip:' + sipAddress
)
_vcard.addSipAddress(sipAddress)
}
_edition = true
......@@ -215,12 +213,8 @@ ColumnLayout {
// -----------------------------------------------------------------------
function _handleSipAddressChanged (index, defaultValue, newValue) {
if (!Utils.startsWith(newValue, 'sip:')) {
newValue = 'sip:' + newValue
if (newValue === defaultValue) {
return
}
if (newValue === defaultValue) {
return
}
var so_far_so_good = (defaultValue.length === 0)
......
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