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
*/
id: filter
placeholderText: i18nd("kdeconnect-sms", "Filter...")
width: parent.width
height: addButton.height
width: parent.width - newButton.width
z: 10
onTextChanged: {
if (filter.text != "") {
if (conversationListModel.isPhoneNumberValid(filter.text)) {
addButton.visible = true
view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
} else {
addButton.visible = false
filter.width = view.width
view.model.setConversationsFilterRole(Qt.DisplayRole)
}
} else {
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
filter.width = view.width
}
view.model.setFilterFixedString(filter.text)
......@@ -196,32 +191,30 @@ Kirigami.ScrollablePage
Keys.forwardTo: [headerItem]
Button {
id: addButton
text: i18nd("kdeconnect-sms", "Add")
id: newButton
text: i18nd("kdeconnect-sms", "New")
anchors.right: parent.right
height: view.headerItem.height
visible: false
visible: true
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.isPhoneNumberExists(view.headerItem.text)) {
if (!view.model.isPhoneNumberExists(view.headerItem.text) && conversationListModel.isPhoneNumberValid(view.headerItem.text)) {
conversationListModel.createConversationForAddress(view.headerItem.text)
}
view.headerItem.enabled = true
addButton.visible = false
view.headerItem.width = view.width
}
Keys.onReturnPressed: {
event.clicked = true
addButton.onClicked()
newButton.onClicked()
}
Shortcut {
sequence: "Ctrl+A"
onActivated: addButton.forceActiveFocus()
sequence: "Ctrl+N"
onActivated: newButton.forceActiveFocus()
}
}
......
......@@ -129,11 +129,11 @@ QString SmsHelper::canonicalizePhoneNumber(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
QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$"));
return validNumberPattern.match(canonicalizedPhoneNumber).hasMatch();
return validNumberPattern.match(canonicalizedNumber).hasMatch();
}
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