UI chnages and sorting/filtering chnages for multitarget converations

This commit is contained in:
Aniket Kumar 2020-04-13 07:50:04 +05:30 committed by Simon Redman
parent 9db5634a6c
commit 6827f31aa1
4 changed files with 96 additions and 66 deletions

View file

@ -44,6 +44,19 @@ void ConversationsSortFilterProxyModel::setConversationsFilterRole(int role)
bool ConversationsSortFilterProxyModel::lessThan(const QModelIndex& leftIndex, const QModelIndex& rightIndex) const
{
// This if block checks for multitarget conversations and sorts it at bottom of the list when the filtring is done on the basis of SenderRole
// This keeps the individual contacts with matching address at the top of the list
if (filterRole() == ConversationListModel::SenderRole) {
const bool isLeftMultitarget = sourceModel()->data(leftIndex, ConversationListModel::MultitargetRole).toBool();
const bool isRightMultitarget = sourceModel()->data(leftIndex, ConversationListModel::MultitargetRole).toBool();
if (isLeftMultitarget && !isRightMultitarget) {
return false;
}
if (!isLeftMultitarget && isRightMultitarget) {
return true;
}
}
QVariant leftDataTimeStamp = sourceModel()->data(leftIndex, ConversationListModel::DateRole);
QVariant rightDataTimeStamp = sourceModel()->data(rightIndex, ConversationListModel::DateRole);
@ -63,13 +76,24 @@ bool ConversationsSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QM
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
if (filterRole() == ConversationListModel::SenderRole && !sourceModel()->data(index, ConversationListModel::MultitargetRole).toBool()) {
if (filterRole() == ConversationListModel::SenderRole) {
if (!sourceModel()->data(index, ConversationListModel::MultitargetRole).toBool()) {
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
} else {
// This block of code compares each address in the multi target conversation to find a match
QList<ConversationAddress> addressList = sourceModel()->data(index, ConversationListModel::AddressesRole).value<QList<ConversationAddress>>();
for (const ConversationAddress address : addressList) {
if (address.address().contains(filterRegExp())) {
return true;
}
}
return false;
}
}
return sourceModel()->data(index, ConversationListModel::ConversationIdRole) != INVALID_THREAD_ID;
}
bool ConversationsSortFilterProxyModel::isPhoneNumberExists(const QString &address)
bool ConversationsSortFilterProxyModel::doesPhoneNumberExists(const QString &address)
{
for(int i = 0; i < rowCount(); ++i) {
if (!data(index(i, 0), ConversationListModel::MultitargetRole).toBool()) {

View file

@ -52,9 +52,9 @@ public:
/**
* This method gets name of conversations or contact if it find any matching address
* Needed for checking if the converstion already or contact already exist or no before adding an arbbitrary contact
* Needed to check if the conversation or contact already exist or no before adding an arbitrary contact
*/
Q_INVOKABLE bool isPhoneNumberExists(const QString& address);
Q_INVOKABLE bool doesPhoneNumberExists(const QString& address);
ConversationsSortFilterProxyModel();
~ConversationsSortFilterProxyModel();

View file

@ -147,20 +147,25 @@ Kirigami.ScrollablePage
}
}
header: TextField {
header: RowLayout {
width: parent.width
z: 10
Keys.forwardTo: [filter]
TextField {
/**
* Used as the filter of the list of messages
*/
id: filter
placeholderText: i18nd("kdeconnect-sms", "Filter...")
width: parent.width - newButton.width
z: 10
Layout.fillWidth: true
onTextChanged: {
if (filter.text != "") {
if (conversationListModel.isPhoneNumberValid(filter.text)) {
view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
newButton.enabled = true
} else {
view.model.setConversationsFilterRole(Qt.DisplayRole)
newButton.enabled = false
}
} else {
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
@ -186,37 +191,38 @@ Kirigami.ScrollablePage
}
}
headerPositioning: ListView.OverlayHeader
Keys.forwardTo: [headerItem]
Button {
id: newButton
text: i18nd("kdeconnect-sms", "New")
anchors.right: parent.right
height: view.headerItem.height
visible: true
enabled: false
ToolTip.visible: hovered
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: i18nd("kdeconnect-sms", "Start new conversation")
onClicked: {
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
view.headerItem.enabled = false
filter.enabled = false
// If the address entered by the user already exists then ignore adding new contact
if (!view.model.isPhoneNumberExists(view.headerItem.text) && conversationListModel.isPhoneNumberValid(view.headerItem.text)) {
conversationListModel.createConversationForAddress(view.headerItem.text)
if (!view.model.doesPhoneNumberExists(filter.text) && conversationListModel.isPhoneNumberValid(filter.text)) {
conversationListModel.createConversationForAddress(filter.text)
view.currentIndex = 0
}
view.headerItem.enabled = true
}
Keys.onReturnPressed: {
event.clicked = true
newButton.onClicked()
filter.enabled = true
}
Shortcut {
sequence: "Ctrl+N"
onActivated: newButton.forceActiveFocus()
onActivated: newButton.onClicked()
}
}
}
headerPositioning: ListView.OverlayHeader
Keys.forwardTo: [headerItem]
delegate: Kirigami.AbstractListItem
{