Commit 6827f31a authored by Aniket Kumar's avatar Aniket Kumar 🤵 Committed by Simon Redman
Browse files

UI chnages and sorting/filtering chnages for multitarget converations

parent 9db5634a
......@@ -141,7 +141,7 @@ void ConversationListModel::printDBusError(const QDBusError& error)
qCWarning(KDECONNECT_SMS_CONVERSATIONS_LIST_MODEL) << error;
}
QStandardItem * ConversationListModel::conversationForThreadId(qint32 threadId)
QStandardItem* ConversationListModel::conversationForThreadId(qint32 threadId)
{
for(int i=0, c=rowCount(); i<c; ++i) {
auto it = item(i, 0);
......@@ -151,7 +151,7 @@ QStandardItem * ConversationListModel::conversationForThreadId(qint32 threadId)
return nullptr;
}
QStandardItem * ConversationListModel::getConversationForAddress(const QString& address)
QStandardItem* ConversationListModel::getConversationForAddress(const QString& address)
{
for(int i = 0; i < rowCount(); ++i) {
const auto& it = item(i, 0);
......
......@@ -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()) {
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
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()) {
......
......@@ -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();
......
......@@ -147,77 +147,83 @@ Kirigami.ScrollablePage
}
}
header: TextField {
/**
* Used as the filter of the list of messages
*/
id: filter
placeholderText: i18nd("kdeconnect-sms", "Filter...")
width: parent.width - newButton.width
header: RowLayout {
width: parent.width
z: 10
onTextChanged: {
if (filter.text != "") {
if (conversationListModel.isPhoneNumberValid(filter.text)) {
view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
Keys.forwardTo: [filter]
TextField {
/**
* Used as the filter of the list of messages
*/
id: filter
placeholderText: i18nd("kdeconnect-sms", "Filter...")
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(Qt.DisplayRole)
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
}
} else {
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
}
view.model.setFilterFixedString(filter.text)
view.model.setFilterFixedString(filter.text)
view.currentIndex = 0
}
onAccepted: {
view.currentItem.startChat()
}
Keys.onReturnPressed: {
event.accepted = true
filter.onAccepted()
}
Keys.onEscapePressed: {
event.accepted = filter.text != ""
filter.text = ""
}
Shortcut {
sequence: "Ctrl+F"
onActivated: filter.forceActiveFocus()
view.currentIndex = 0
}
onAccepted: {
view.currentItem.startChat()
}
Keys.onReturnPressed: {
event.accepted = true
filter.onAccepted()
}
Keys.onEscapePressed: {
event.accepted = filter.text != ""
filter.text = ""
}
Shortcut {
sequence: "Ctrl+F"
onActivated: filter.forceActiveFocus()
}
}
}
headerPositioning: ListView.OverlayHeader
Button {
id: newButton
text: i18nd("kdeconnect-sms", "New")
visible: true
enabled: false
ToolTip.visible: hovered
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: i18nd("kdeconnect-sms", "Start new conversation")
Keys.forwardTo: [headerItem]
Button {
id: newButton
text: i18nd("kdeconnect-sms", "New")
anchors.right: parent.right
height: view.headerItem.height
visible: true
onClicked: {
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
filter.enabled = false
onClicked: {
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
view.headerItem.enabled = false
// If the address entered by the user already exists then ignore adding new contact
if (!view.model.doesPhoneNumberExists(filter.text) && conversationListModel.isPhoneNumberValid(filter.text)) {
conversationListModel.createConversationForAddress(filter.text)
view.currentIndex = 0
}
// 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)
filter.enabled = true
}
view.headerItem.enabled = true
}
Keys.onReturnPressed: {
event.clicked = true
newButton.onClicked()
}
Shortcut {
sequence: "Ctrl+N"
onActivated: newButton.forceActiveFocus()
Shortcut {
sequence: "Ctrl+N"
onActivated: newButton.onClicked()
}
}
}
headerPositioning: ListView.OverlayHeader
Keys.forwardTo: [headerItem]
delegate: Kirigami.AbstractListItem
{
id: listItem
......
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