Fixes magic search :
- remove suggestions items if already in contacts. - display sip address.
This commit is contained in:
parent
8ea3f6f023
commit
8ad4d8be1e
8 changed files with 82 additions and 32 deletions
|
|
@ -194,8 +194,7 @@ QVariant MagicSearchList::data(const QModelIndex &index, int role) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
int MagicSearchList::findFriendIndexByAddress(const QString &address) {
|
int MagicSearchList::findFriendIndexByAddress(const QString &address) {
|
||||||
int i = 0;
|
for (int i = 0; i < getCount(); ++i) {
|
||||||
for (int i = 0; i < getCount();) {
|
|
||||||
auto friendCore = getAt<FriendCore>(i);
|
auto friendCore = getAt<FriendCore>(i);
|
||||||
if (!friendCore) continue;
|
if (!friendCore) continue;
|
||||||
for (auto &friendAddress : friendCore->getAllAddresses()) {
|
for (auto &friendAddress : friendCore->getAllAddresses()) {
|
||||||
|
|
@ -204,7 +203,6 @@ int MagicSearchList::findFriendIndexByAddress(const QString &address) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,15 +71,24 @@ void MagicSearchProxy::setList(QSharedPointer<MagicSearchList> newList) {
|
||||||
if (oldModel) {
|
if (oldModel) {
|
||||||
sortFilterList->mShowFavoritesOnly = oldModel->mShowFavoritesOnly;
|
sortFilterList->mShowFavoritesOnly = oldModel->mShowFavoritesOnly;
|
||||||
sortFilterList->mShowLdapContacts = oldModel->mShowLdapContacts;
|
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);
|
setSourceModels(sortFilterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MagicSearchProxy::findFriendIndexByAddress(const QString &address) {
|
int MagicSearchProxy::findFriendIndexByAddress(const QString &address) {
|
||||||
auto magicSearchList = getListModel<MagicSearchList>();
|
auto magicSearchList = getListModel<MagicSearchList>();
|
||||||
if (magicSearchList)
|
if (magicSearchList) {
|
||||||
return mapFromSource(magicSearchList->index(magicSearchList->findFriendIndexByAddress(address), 0)).row();
|
auto listIndex = magicSearchList->findFriendIndexByAddress(address);
|
||||||
else return -1;
|
if (listIndex == -1) return -1;
|
||||||
|
return dynamic_cast<SortFilterList *>(sourceModel())->mapFromSource(magicSearchList->index(listIndex, 0)).row();
|
||||||
|
} else return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MagicSearchProxy::getSearchText() const {
|
QString MagicSearchProxy::getSearchText() const {
|
||||||
|
|
@ -122,6 +131,25 @@ void MagicSearchProxy::setParentProxy(MagicSearchProxy *proxy) {
|
||||||
emit parentProxyChanged();
|
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 {
|
LinphoneEnums::MagicSearchAggregation MagicSearchProxy::getAggregationFlag() const {
|
||||||
return mAggregationFlag;
|
return mAggregationFlag;
|
||||||
}
|
}
|
||||||
|
|
@ -135,10 +163,18 @@ void MagicSearchProxy::setAggregationFlag(LinphoneEnums::MagicSearchAggregation
|
||||||
|
|
||||||
bool MagicSearchProxy::SortFilterList::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
|
bool MagicSearchProxy::SortFilterList::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
|
||||||
auto friendCore = getItemAtSource<MagicSearchList, FriendCore>(sourceRow);
|
auto friendCore = getItemAtSource<MagicSearchList, FriendCore>(sourceRow);
|
||||||
|
auto toShow = false;
|
||||||
if (friendCore) {
|
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 {
|
bool MagicSearchProxy::SortFilterList::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const {
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,13 @@ class MagicSearchProxy : public LimitProxy {
|
||||||
NOTIFY aggregationFlagChanged)
|
NOTIFY aggregationFlagChanged)
|
||||||
Q_PROPERTY(bool showFavoritesOnly READ showFavoritesOnly WRITE setShowFavoritesOnly NOTIFY showFavoriteOnlyChanged)
|
Q_PROPERTY(bool showFavoritesOnly READ showFavoritesOnly WRITE setShowFavoritesOnly NOTIFY showFavoriteOnlyChanged)
|
||||||
Q_PROPERTY(MagicSearchProxy *parentProxy WRITE setParentProxy NOTIFY parentProxyChanged)
|
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)
|
Q_PROPERTY(bool showLdapContacts READ showLdapContacts WRITE setShowLdapContacts CONSTANT)
|
||||||
|
|
||||||
public:
|
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(QObject *parent = Q_NULLPTR);
|
||||||
~MagicSearchProxy();
|
~MagicSearchProxy();
|
||||||
|
|
@ -62,6 +65,9 @@ public:
|
||||||
void setList(QSharedPointer<MagicSearchList> list);
|
void setList(QSharedPointer<MagicSearchList> list);
|
||||||
Q_INVOKABLE void setParentProxy(MagicSearchProxy *proxy);
|
Q_INVOKABLE void setParentProxy(MagicSearchProxy *proxy);
|
||||||
|
|
||||||
|
MagicSearchProxy *getHideListProxy() const;
|
||||||
|
void setHideListProxy(MagicSearchProxy *proxy);
|
||||||
|
|
||||||
// Q_INVOKABLE forceUpdate();
|
// Q_INVOKABLE forceUpdate();
|
||||||
Q_INVOKABLE int findFriendIndexByAddress(const QString &address);
|
Q_INVOKABLE int findFriendIndexByAddress(const QString &address);
|
||||||
|
|
||||||
|
|
@ -73,6 +79,7 @@ signals:
|
||||||
void friendCreated(int index);
|
void friendCreated(int index);
|
||||||
void showFavoriteOnlyChanged();
|
void showFavoriteOnlyChanged();
|
||||||
void parentProxyChanged();
|
void parentProxyChanged();
|
||||||
|
void hideListProxyChanged();
|
||||||
void initialized();
|
void initialized();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -299,8 +299,6 @@ bool ToolModel::friendIsInFriendList(const std::shared_ptr<linphone::FriendList>
|
||||||
const std::shared_ptr<linphone::Friend> &f) {
|
const std::shared_ptr<linphone::Friend> &f) {
|
||||||
for (auto contact : friendList->getFriends()) {
|
for (auto contact : friendList->getFriends()) {
|
||||||
if (f == contact) {
|
if (f == contact) {
|
||||||
qWarning() << Utils::coreStringToAppString(f->getAddress()->asStringUriOnly()) << " / "
|
|
||||||
<< Utils::coreStringToAppString(contact->getAddress()->asStringUriOnly());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ ListView {
|
||||||
id: mainItem
|
id: mainItem
|
||||||
height: contentHeight
|
height: contentHeight
|
||||||
visible: contentHeight > 0
|
visible: contentHeight > 0
|
||||||
clip: true
|
clip: true
|
||||||
|
currentIndex: -1
|
||||||
//keyNavigationWraps: true
|
//keyNavigationWraps: true
|
||||||
// rightMargin: 5 * DefaultStyle.dp
|
// rightMargin: 5 * DefaultStyle.dp
|
||||||
|
|
||||||
|
|
||||||
property bool selectionEnabled: true
|
property bool selectionEnabled: true
|
||||||
property bool hoverEnabled: true
|
property bool hoverEnabled: true
|
||||||
// dots popup menu
|
// dots popup menu
|
||||||
|
|
@ -25,11 +25,12 @@ ListView {
|
||||||
property bool initialHeadersVisible: true
|
property bool initialHeadersVisible: true
|
||||||
property bool displayNameCapitalization: true
|
property bool displayNameCapitalization: true
|
||||||
property bool showFavoritesOnly: false
|
property bool showFavoritesOnly: false
|
||||||
property bool showDefaultAddress: false
|
property bool showDefaultAddress: true
|
||||||
property bool showLdapContacts: false
|
property bool showLdapContacts: false
|
||||||
property bool searchOnInitialization: false
|
property bool searchOnInitialization: false
|
||||||
|
|
||||||
property var listProxy: MagicSearchProxy{}
|
property var listProxy: MagicSearchProxy{}
|
||||||
|
property alias hideListProxy: magicSearchProxy.hideListProxy
|
||||||
|
|
||||||
// Model properties
|
// Model properties
|
||||||
// set searchBarText without specifying a model to bold
|
// set searchBarText without specifying a model to bold
|
||||||
|
|
@ -44,20 +45,9 @@ ListView {
|
||||||
property bool multiSelectionEnabled: false
|
property bool multiSelectionEnabled: false
|
||||||
property list<string> selectedContacts
|
property list<string> selectedContacts
|
||||||
property int selectedContactCount: selectedContacts.length
|
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
|
property FriendGui selectedContact: model.getAt(currentIndex) || null
|
||||||
|
|
||||||
onCurrentIndexChanged: selectedContact = model.getAt(currentIndex) || null
|
|
||||||
onCountChanged: selectedContact = model.getAt(currentIndex) || null
|
|
||||||
|
|
||||||
signal contactStarredChanged()
|
signal contactStarredChanged()
|
||||||
signal contactDeletionRequested(FriendGui contact)
|
signal contactDeletionRequested(FriendGui contact)
|
||||||
signal contactAddedToSelection(string address)
|
signal contactAddedToSelection(string address)
|
||||||
|
|
@ -94,6 +84,21 @@ ListView {
|
||||||
contactRemovedFromSelection(address)
|
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
|
// strange behaviour with this lines
|
||||||
// When a popup opens after clicking on a contact, the selected contact
|
// 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
|
// considering its starred status. Otherwise, the row in the list still
|
||||||
// exists even if its delegate is not visible, and creates navigation issues
|
// exists even if its delegate is not visible, and creates navigation issues
|
||||||
showFavoritesOnly: mainItem.showFavoritesOnly
|
showFavoritesOnly: mainItem.showFavoritesOnly
|
||||||
onFriendCreated: (index) => {
|
|
||||||
mainItem.currentIndex = index
|
|
||||||
}
|
|
||||||
aggregationFlag: mainItem.aggregationFlag
|
aggregationFlag: mainItem.aggregationFlag
|
||||||
parentProxy: mainItem.listProxy
|
parentProxy: mainItem.listProxy
|
||||||
showLdapContacts: mainItem.showLdapContacts
|
showLdapContacts: mainItem.showLdapContacts
|
||||||
sourceFlags: mainItem.sourceFlags
|
sourceFlags: mainItem.sourceFlags
|
||||||
|
onFriendCreated: (index) => {
|
||||||
|
mainItem.currentIndex = index
|
||||||
|
}
|
||||||
onInitialized: {
|
onInitialized: {
|
||||||
if(mainItem.searchOnInitialization) magicSearchProxy.forceUpdate()
|
if(mainItem.searchOnInitialization) magicSearchProxy.forceUpdate()
|
||||||
}
|
}
|
||||||
|
|
@ -201,6 +206,7 @@ ListView {
|
||||||
Layout.topMargin: 2 * DefaultStyle.dp
|
Layout.topMargin: 2 * DefaultStyle.dp
|
||||||
visible: mainItem.showDefaultAddress
|
visible: mainItem.showDefaultAddress
|
||||||
text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(modelData.core.defaultAddress) : modelData.core.defaultAddress
|
text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(modelData.core.defaultAddress) : modelData.core.defaultAddress
|
||||||
|
|
||||||
font {
|
font {
|
||||||
weight: 300 * DefaultStyle.dp
|
weight: 300 * DefaultStyle.dp
|
||||||
pixelSize: 12 * DefaultStyle.dp
|
pixelSize: 12 * DefaultStyle.dp
|
||||||
|
|
|
||||||
|
|
@ -181,15 +181,16 @@ FocusScope {
|
||||||
}
|
}
|
||||||
ContactListView{
|
ContactListView{
|
||||||
id: searchList
|
id: searchList
|
||||||
contactMenuVisible: false
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Control.ScrollBar.vertical.visible: false
|
|
||||||
Layout.preferredHeight: contentHeight
|
Layout.preferredHeight: contentHeight
|
||||||
|
contactMenuVisible: false
|
||||||
|
Control.ScrollBar.vertical.visible: false
|
||||||
initialHeadersVisible: false
|
initialHeadersVisible: false
|
||||||
displayNameCapitalization: false
|
displayNameCapitalization: false
|
||||||
searchBarText: searchBar.text
|
searchBarText: searchBar.text
|
||||||
sourceFlags: LinphoneEnums.MagicSearchSource.All
|
sourceFlags: LinphoneEnums.MagicSearchSource.All
|
||||||
|
hideListProxy: contactList.model
|
||||||
onContactClicked: (contact) => {
|
onContactClicked: (contact) => {
|
||||||
mainItem.contactClicked(contact)
|
mainItem.contactClicked(contact)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,17 +156,18 @@ FocusScope{
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.preferredHeight: contentHeight
|
Layout.preferredHeight: contentHeight
|
||||||
|
Control.ScrollBar.vertical.visible: false
|
||||||
contactMenuVisible: false
|
contactMenuVisible: false
|
||||||
searchBarText: searchbar.text
|
searchBarText: searchbar.text
|
||||||
sourceFlags: LinphoneEnums.MagicSearchSource.All
|
sourceFlags: LinphoneEnums.MagicSearchSource.All
|
||||||
multiSelectionEnabled: true
|
multiSelectionEnabled: true
|
||||||
displayNameCapitalization: false
|
displayNameCapitalization: false
|
||||||
|
hideListProxy: contactList.model
|
||||||
onContactAddedToSelection: (address) => {
|
onContactAddedToSelection: (address) => {
|
||||||
contactList.addContactToSelection(address)
|
contactList.addContactToSelection(address)
|
||||||
participantList.positionViewAtEnd()
|
participantList.positionViewAtEnd()
|
||||||
}
|
}
|
||||||
onContactRemovedFromSelection: (address) => contactList.removeSelectedContactByAddress(address)
|
onContactRemovedFromSelection: (address) => contactList.removeSelectedContactByAddress(address)
|
||||||
Control.ScrollBar.vertical.visible: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -280,8 +280,9 @@ Item {
|
||||||
footer: FocusScope{
|
footer: FocusScope{
|
||||||
id: suggestionFocusScope
|
id: suggestionFocusScope
|
||||||
width: contactList.width
|
width: contactList.width
|
||||||
height: content.implicitHeight
|
height: visible ? content.implicitHeight : 0
|
||||||
onActiveFocusChanged: if(activeFocus) contactList.positionViewAtEnd()
|
onActiveFocusChanged: if(activeFocus) contactList.positionViewAtEnd()
|
||||||
|
visible: !contactList.haveAddress(suggestionText.text)
|
||||||
Rectangle{
|
Rectangle{
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
@ -317,12 +318,14 @@ Item {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: suggestionRow
|
id: suggestionRow
|
||||||
spacing: 10 * DefaultStyle.dp
|
spacing: 10 * DefaultStyle.dp
|
||||||
|
|
||||||
Avatar {
|
Avatar {
|
||||||
Layout.preferredWidth: 45 * DefaultStyle.dp
|
Layout.preferredWidth: 45 * DefaultStyle.dp
|
||||||
Layout.preferredHeight: 45 * DefaultStyle.dp
|
Layout.preferredHeight: 45 * DefaultStyle.dp
|
||||||
_address: magicSearchBar.text
|
_address: magicSearchBar.text
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
|
id: suggestionText
|
||||||
property var urlObj: UtilsCpp.interpretUrl(magicSearchBar.text)
|
property var urlObj: UtilsCpp.interpretUrl(magicSearchBar.text)
|
||||||
text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(urlObj?.value) : urlObj?.value
|
text: SettingsCpp.onlyDisplaySipUriUsername ? UtilsCpp.getUsername(urlObj?.value) : urlObj?.value
|
||||||
font {
|
font {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue