Commit 9db5634a authored by Aniket Kumar's avatar Aniket Kumar 🤵 Committed by Simon Redman
Browse files

Made New button static in UI

parent 75c87e6f
...@@ -153,22 +153,17 @@ Kirigami.ScrollablePage ...@@ -153,22 +153,17 @@ Kirigami.ScrollablePage
*/ */
id: filter id: filter
placeholderText: i18nd("kdeconnect-sms", "Filter...") placeholderText: i18nd("kdeconnect-sms", "Filter...")
width: parent.width width: parent.width - newButton.width
height: addButton.height
z: 10 z: 10
onTextChanged: { onTextChanged: {
if (filter.text != "") { if (filter.text != "") {
if (conversationListModel.isPhoneNumberValid(filter.text)) { if (conversationListModel.isPhoneNumberValid(filter.text)) {
addButton.visible = true
view.model.setConversationsFilterRole(ConversationListModel.SenderRole) view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
} else { } else {
addButton.visible = false
filter.width = view.width
view.model.setConversationsFilterRole(Qt.DisplayRole) view.model.setConversationsFilterRole(Qt.DisplayRole)
} }
} else { } else {
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole) view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
filter.width = view.width
} }
view.model.setFilterFixedString(filter.text) view.model.setFilterFixedString(filter.text)
...@@ -196,32 +191,30 @@ Kirigami.ScrollablePage ...@@ -196,32 +191,30 @@ Kirigami.ScrollablePage
Keys.forwardTo: [headerItem] Keys.forwardTo: [headerItem]
Button { Button {
id: addButton id: newButton
text: i18nd("kdeconnect-sms", "Add") text: i18nd("kdeconnect-sms", "New")
anchors.right: parent.right anchors.right: parent.right
height: view.headerItem.height height: view.headerItem.height
visible: false visible: true
onClicked: { onClicked: {
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request // We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
view.headerItem.enabled = false view.headerItem.enabled = false
// If the address entered by the user already exists then ignore adding new contact // If the address entered by the user already exists then ignore adding new contact
if (!view.model.isPhoneNumberExists(view.headerItem.text)) { if (!view.model.isPhoneNumberExists(view.headerItem.text) && conversationListModel.isPhoneNumberValid(view.headerItem.text)) {
conversationListModel.createConversationForAddress(view.headerItem.text) conversationListModel.createConversationForAddress(view.headerItem.text)
} }
view.headerItem.enabled = true view.headerItem.enabled = true
addButton.visible = false
view.headerItem.width = view.width
} }
Keys.onReturnPressed: { Keys.onReturnPressed: {
event.clicked = true event.clicked = true
addButton.onClicked() newButton.onClicked()
} }
Shortcut { Shortcut {
sequence: "Ctrl+A" sequence: "Ctrl+N"
onActivated: addButton.forceActiveFocus() onActivated: newButton.forceActiveFocus()
} }
} }
......
...@@ -129,11 +129,11 @@ QString SmsHelper::canonicalizePhoneNumber(const QString& phoneNumber) ...@@ -129,11 +129,11 @@ QString SmsHelper::canonicalizePhoneNumber(const QString& phoneNumber)
bool SmsHelper::isPhoneNumberValid(const QString& phoneNumber) bool SmsHelper::isPhoneNumberValid(const QString& phoneNumber)
{ {
QString canonicalizedPhoneNumber(phoneNumber); QString canonicalizedNumber = canonicalizePhoneNumber(phoneNumber);
// This regular expression matches a wide range of international Phone numbers, minimum of 3 digits and maximum upto 15 digits // This regular expression matches a wide range of international Phone numbers, minimum of 3 digits and maximum upto 15 digits
QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$")); QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$"));
return validNumberPattern.match(canonicalizedPhoneNumber).hasMatch(); return validNumberPattern.match(canonicalizedNumber).hasMatch();
} }
class PersonsCache : public QObject { class PersonsCache : public QObject {
......
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