Fixes magic search :

- remove suggestions items if already in contacts.
- display sip address.
This commit is contained in:
Julien Wadel 2024-11-06 18:05:45 +01:00
parent 8ea3f6f023
commit 8ad4d8be1e
8 changed files with 82 additions and 32 deletions

View file

@ -194,8 +194,7 @@ QVariant MagicSearchList::data(const QModelIndex &index, int role) const {
}
int MagicSearchList::findFriendIndexByAddress(const QString &address) {
int i = 0;
for (int i = 0; i < getCount();) {
for (int i = 0; i < getCount(); ++i) {
auto friendCore = getAt<FriendCore>(i);
if (!friendCore) continue;
for (auto &friendAddress : friendCore->getAllAddresses()) {
@ -204,7 +203,6 @@ int MagicSearchList::findFriendIndexByAddress(const QString &address) {
return i;
}
}
++i;
}
return -1;
}

View file

@ -71,15 +71,24 @@ void MagicSearchProxy::setList(QSharedPointer<MagicSearchList> newList) {
if (oldModel) {
sortFilterList->mShowFavoritesOnly = oldModel->mShowFavoritesOnly;
sortFilterList->mShowLdapContacts = oldModel->mShowLdapContacts;
sortFilterList->mHideListProxy = oldModel->mHideListProxy;
if (sortFilterList->mHideListProxy) {
connect(sortFilterList->mHideListProxy, &MagicSearchProxy::countChanged, sortFilterList,
[this, sortFilterList]() { sortFilterList->invalidate(); });
connect(sortFilterList, &MagicSearchProxy::modelReset, sortFilterList,
[this, sortFilterList]() { sortFilterList->invalidate(); });
}
}
setSourceModels(sortFilterList);
}
int MagicSearchProxy::findFriendIndexByAddress(const QString &address) {
auto magicSearchList = getListModel<MagicSearchList>();
if (magicSearchList)
return mapFromSource(magicSearchList->index(magicSearchList->findFriendIndexByAddress(address), 0)).row();
else return -1;
if (magicSearchList) {
auto listIndex = magicSearchList->findFriendIndexByAddress(address);
if (listIndex == -1) return -1;
return dynamic_cast<SortFilterList *>(sourceModel())->mapFromSource(magicSearchList->index(listIndex, 0)).row();
} else return -1;
}
QString MagicSearchProxy::getSearchText() const {
@ -122,6 +131,25 @@ void MagicSearchProxy::setParentProxy(MagicSearchProxy *proxy) {
emit parentProxyChanged();
}
MagicSearchProxy *MagicSearchProxy::getHideListProxy() const {
auto list = dynamic_cast<SortFilterList *>(sourceModel());
return list ? list->mHideListProxy : nullptr;
}
void MagicSearchProxy::setHideListProxy(MagicSearchProxy *proxy) {
auto list = dynamic_cast<SortFilterList *>(sourceModel());
if (list && list->mHideListProxy != proxy) {
if (list->mHideListProxy) list->disconnect(list->mHideListProxy);
list->mHideListProxy = proxy;
list->invalidate();
if (proxy) {
connect(proxy, &MagicSearchProxy::countChanged, list, [this, list]() { list->invalidate(); });
connect(proxy, &MagicSearchProxy::modelReset, list, [this, list]() { list->invalidate(); });
}
emit hideListProxyChanged();
}
}
LinphoneEnums::MagicSearchAggregation MagicSearchProxy::getAggregationFlag() const {
return mAggregationFlag;
}
@ -135,10 +163,18 @@ void MagicSearchProxy::setAggregationFlag(LinphoneEnums::MagicSearchAggregation
bool MagicSearchProxy::SortFilterList::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
auto friendCore = getItemAtSource<MagicSearchList, FriendCore>(sourceRow);
auto toShow = false;
if (friendCore) {
return (!mShowFavoritesOnly || friendCore->getStarred()) && (mShowLdapContacts || !friendCore->isLdap());
toShow = (!mShowFavoritesOnly || friendCore->getStarred()) && (mShowLdapContacts || !friendCore->isLdap());
if (toShow && mHideListProxy) {
for (auto &friendAddress : friendCore->getAllAddresses()) {
toShow = mHideListProxy->findFriendIndexByAddress(friendAddress.toMap()["address"].toString()) == -1;
if (!toShow) break;
}
}
}
return false;
return toShow;
}
bool MagicSearchProxy::SortFilterList::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const {

View file

@ -36,10 +36,13 @@ class MagicSearchProxy : public LimitProxy {
NOTIFY aggregationFlagChanged)
Q_PROPERTY(bool showFavoritesOnly READ showFavoritesOnly WRITE setShowFavoritesOnly NOTIFY showFavoriteOnlyChanged)
Q_PROPERTY(MagicSearchProxy *parentProxy WRITE setParentProxy NOTIFY parentProxyChanged)
Q_PROPERTY(MagicSearchProxy *hideListProxy READ getHideListProxy WRITE setHideListProxy NOTIFY hideListProxyChanged)
Q_PROPERTY(bool showLdapContacts READ showLdapContacts WRITE setShowLdapContacts CONSTANT)
public:
DECLARE_SORTFILTER_CLASS(bool mShowFavoritesOnly = false; bool mShowLdapContacts = false;)
DECLARE_SORTFILTER_CLASS(bool mShowFavoritesOnly = false; bool mShowLdapContacts = false;
MagicSearchProxy *mHideListProxy = nullptr;)
MagicSearchProxy(QObject *parent = Q_NULLPTR);
~MagicSearchProxy();
@ -62,6 +65,9 @@ public:
void setList(QSharedPointer<MagicSearchList> list);
Q_INVOKABLE void setParentProxy(MagicSearchProxy *proxy);
MagicSearchProxy *getHideListProxy() const;
void setHideListProxy(MagicSearchProxy *proxy);
// Q_INVOKABLE forceUpdate();
Q_INVOKABLE int findFriendIndexByAddress(const QString &address);
@ -73,6 +79,7 @@ signals:
void friendCreated(int index);
void showFavoriteOnlyChanged();
void parentProxyChanged();
void hideListProxyChanged();
void initialized();
protected:

View file

@ -299,8 +299,6 @@ bool ToolModel::friendIsInFriendList(const std::shared_ptr<linphone::FriendList>
const std::shared_ptr<linphone::Friend> &f) {
for (auto contact : friendList->getFriends()) {
if (f == contact) {
qWarning() << Utils::coreStringToAppString(f->getAddress()->asStringUriOnly()) << " / "
<< Utils::coreStringToAppString(contact->getAddress()->asStringUriOnly());
return true;
}
}

View file

@ -11,11 +11,11 @@ ListView {
id: mainItem
height: contentHeight
visible: contentHeight > 0
clip: true
clip: true
currentIndex: -1
//keyNavigationWraps: true
// rightMargin: 5 * DefaultStyle.dp
property bool selectionEnabled: true
property bool hoverEnabled: true
// dots popup menu
@ -25,11 +25,12 @@ ListView {
property bool initialHeadersVisible: true
property bool displayNameCapitalization: true
property bool showFavoritesOnly: false
property bool showDefaultAddress: false
property bool showDefaultAddress: true
property bool showLdapContacts: false
property bool searchOnInitialization: false
property var listProxy: MagicSearchProxy{}
property alias hideListProxy: magicSearchProxy.hideListProxy
// Model properties
// set searchBarText without specifying a model to bold
@ -44,20 +45,9 @@ ListView {
property bool multiSelectionEnabled: false
property list<string> selectedContacts
property int selectedContactCount: selectedContacts.length
Component.onCompleted: {
if (confInfoGui) {
for(var i = 0; i < confInfoGui.core.participants.length; ++i) {
selectedContacts.push(confInfoGui.core.getParticipantAddressAt(i));
}
}
}
currentIndex: -1
property FriendGui selectedContact: model.getAt(currentIndex) || null
onCurrentIndexChanged: selectedContact = model.getAt(currentIndex) || null
onCountChanged: selectedContact = model.getAt(currentIndex) || null
signal contactStarredChanged()
signal contactDeletionRequested(FriendGui contact)
signal contactAddedToSelection(string address)
@ -94,6 +84,21 @@ ListView {
contactRemovedFromSelection(address)
}
}
function haveAddress(address){
var index = magicSearchProxy.findFriendIndexByAddress(address)
return index != -1
}
onCurrentIndexChanged: selectedContact = model.getAt(currentIndex) || null
onCountChanged: selectedContact = model.getAt(currentIndex) || null
Component.onCompleted: {
if (confInfoGui) {
for(var i = 0; i < confInfoGui.core.participants.length; ++i) {
selectedContacts.push(confInfoGui.core.getParticipantAddressAt(i));
}
}
}
// strange behaviour with this lines
// When a popup opens after clicking on a contact, the selected contact
@ -109,13 +114,13 @@ ListView {
// considering its starred status. Otherwise, the row in the list still
// exists even if its delegate is not visible, and creates navigation issues
showFavoritesOnly: mainItem.showFavoritesOnly
onFriendCreated: (index) => {
mainItem.currentIndex = index
}
aggregationFlag: mainItem.aggregationFlag
parentProxy: mainItem.listProxy
showLdapContacts: mainItem.showLdapContacts
sourceFlags: mainItem.sourceFlags
onFriendCreated: (index) => {
mainItem.currentIndex = index
}
onInitialized: {
if(mainItem.searchOnInitialization) magicSearchProxy.forceUpdate()
}
@ -201,6 +206,7 @@ ListView {
Layout.topMargin: 2 * DefaultStyle.dp
visible: mainItem.showDefaultAddress
text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(modelData.core.defaultAddress) : modelData.core.defaultAddress
font {
weight: 300 * DefaultStyle.dp
pixelSize: 12 * DefaultStyle.dp

View file

@ -181,15 +181,16 @@ FocusScope {
}
ContactListView{
id: searchList
contactMenuVisible: false
Layout.fillWidth: true
Layout.fillHeight: true
Control.ScrollBar.vertical.visible: false
Layout.preferredHeight: contentHeight
contactMenuVisible: false
Control.ScrollBar.vertical.visible: false
initialHeadersVisible: false
displayNameCapitalization: false
searchBarText: searchBar.text
sourceFlags: LinphoneEnums.MagicSearchSource.All
hideListProxy: contactList.model
onContactClicked: (contact) => {
mainItem.contactClicked(contact)
}

View file

@ -156,17 +156,18 @@ FocusScope{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.preferredHeight: contentHeight
Control.ScrollBar.vertical.visible: false
contactMenuVisible: false
searchBarText: searchbar.text
sourceFlags: LinphoneEnums.MagicSearchSource.All
multiSelectionEnabled: true
displayNameCapitalization: false
hideListProxy: contactList.model
onContactAddedToSelection: (address) => {
contactList.addContactToSelection(address)
participantList.positionViewAtEnd()
}
onContactRemovedFromSelection: (address) => contactList.removeSelectedContactByAddress(address)
Control.ScrollBar.vertical.visible: false
}
}
}

View file

@ -280,8 +280,9 @@ Item {
footer: FocusScope{
id: suggestionFocusScope
width: contactList.width
height: content.implicitHeight
height: visible ? content.implicitHeight : 0
onActiveFocusChanged: if(activeFocus) contactList.positionViewAtEnd()
visible: !contactList.haveAddress(suggestionText.text)
Rectangle{
anchors.left: parent.left
anchors.right: parent.right
@ -317,12 +318,14 @@ Item {
RowLayout {
id: suggestionRow
spacing: 10 * DefaultStyle.dp
Avatar {
Layout.preferredWidth: 45 * DefaultStyle.dp
Layout.preferredHeight: 45 * DefaultStyle.dp
_address: magicSearchBar.text
}
Text {
id: suggestionText
property var urlObj: UtilsCpp.interpretUrl(magicSearchBar.text)
text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(urlObj?.value) : urlObj?.value
font {