mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-25 12:15:32 +03:00
113 lines
4.1 KiB
Diff
113 lines
4.1 KiB
Diff
From bbf06092209dbc47ff5b53a0cdbf8afe7a45c3b6 Mon Sep 17 00:00:00 2001
|
|
From: Smitty van Bodegom <me@smitop.com>
|
|
Date: Tue, 20 Jul 2021 19:09:11 -0400
|
|
Subject: [PATCH] Normalize numbers for Ofono
|
|
|
|
---
|
|
lib/telephonySupport/phonenumberutils.cpp | 22 +++++++++++++++
|
|
lib/telephonySupport/phonenumberutils.h | 1 +
|
|
src/messagemanager.cpp | 33 +++++++++++++----------
|
|
3 files changed, 42 insertions(+), 14 deletions(-)
|
|
|
|
diff --git a/lib/telephonySupport/phonenumberutils.cpp b/lib/telephonySupport/phonenumberutils.cpp
|
|
index 7865224..f019c86 100644
|
|
--- a/lib/telephonySupport/phonenumberutils.cpp
|
|
+++ b/lib/telephonySupport/phonenumberutils.cpp
|
|
@@ -4,6 +4,7 @@
|
|
|
|
#include "phonenumberutils.h"
|
|
|
|
+#include <QChar>
|
|
#include <QLocale>
|
|
|
|
#include <phonenumbers/phonenumberutil.h>
|
|
@@ -46,4 +47,25 @@ QString normalizeNumber(const QString &numberString, PhoneNumberFormat format)
|
|
return numberString;
|
|
}
|
|
|
|
+// normalize a number so that Ofono can understand it
|
|
+QString normalizeForOfono(const QString &numberString)
|
|
+{
|
|
+ // ofono number parsing:
|
|
+ // https://github.com/rilmodem/ofono/blob/efc9c0a85d32706bc088e449e847be41dcc73b3d/src/common.c#L238
|
|
+
|
|
+ QString normalized;
|
|
+ for (int i = 0; i < numberString.size(); ++i) {
|
|
+ QChar c = numberString.at(i);
|
|
+ if (c == QChar(u'+') && normalized.isEmpty()) {
|
|
+ // plus is allowed but only as first character
|
|
+ normalized.append(u'+');
|
|
+ } else if ((c >= QChar(u'0') && c <= QChar(u'9')) || c == QChar(u'*') ||
|
|
+ c == QChar(u'#')) {
|
|
+ normalized.append(c);
|
|
+ }
|
|
+ // ignore all other characters
|
|
+ }
|
|
+
|
|
+ return normalized;
|
|
+}
|
|
}
|
|
diff --git a/lib/telephonySupport/phonenumberutils.h b/lib/telephonySupport/phonenumberutils.h
|
|
index 6aeb5fd..30da605 100644
|
|
--- a/lib/telephonySupport/phonenumberutils.h
|
|
+++ b/lib/telephonySupport/phonenumberutils.h
|
|
@@ -31,4 +31,5 @@ using NormalizeResult = std::variant<std::string, ErrorType>;
|
|
|
|
NormalizeResult normalizeNumber(const std::string &numberString, PhoneNumberFormat format = International);
|
|
QString normalizeNumber(const QString &numberString, PhoneNumberFormat format = International);
|
|
+QString normalizeForOfono(const QString &numberString);
|
|
};
|
|
diff --git a/src/messagemanager.cpp b/src/messagemanager.cpp
|
|
index 4934a94..6811ace 100644
|
|
--- a/src/messagemanager.cpp
|
|
+++ b/src/messagemanager.cpp
|
|
@@ -7,6 +7,7 @@
|
|
#include <QFutureInterface>
|
|
|
|
#include <global.h>
|
|
+#include <phonenumberutils.h>
|
|
|
|
MessageManager::MessageManager(QObject *parent)
|
|
: QOfonoMessageManager(parent)
|
|
@@ -25,20 +26,24 @@ QFuture<SendMessageResult> MessageManager::sendMessage(const QString &to, const
|
|
return futureInterface->future();
|
|
}
|
|
|
|
- connect(new QDBusPendingCallWatcher(iface->asyncCall(SL("SendMessage"), to, text), iface),
|
|
- &QDBusPendingCallWatcher::finished,
|
|
- [=](QDBusPendingCallWatcher *watcher) {
|
|
- watcher->deleteLater();
|
|
-
|
|
- QDBusPendingReply<QDBusObjectPath> reply = *watcher;
|
|
- if (reply.isError()) {
|
|
- futureInterface->reportResult(reply.error());
|
|
- futureInterface->reportFinished();
|
|
- } else {
|
|
- futureInterface->reportResult(reply.value());
|
|
- futureInterface->reportFinished();
|
|
- }
|
|
- });
|
|
+ connect(new QDBusPendingCallWatcher(
|
|
+ iface->asyncCall(SL("SendMessage"),
|
|
+ phoneNumberUtils::normalizeForOfono(to),
|
|
+ text),
|
|
+ iface),
|
|
+ &QDBusPendingCallWatcher::finished,
|
|
+ [=](QDBusPendingCallWatcher *watcher) {
|
|
+ watcher->deleteLater();
|
|
+
|
|
+ QDBusPendingReply<QDBusObjectPath> reply = *watcher;
|
|
+ if (reply.isError()) {
|
|
+ futureInterface->reportResult(reply.error());
|
|
+ futureInterface->reportFinished();
|
|
+ } else {
|
|
+ futureInterface->reportResult(reply.value());
|
|
+ futureInterface->reportFinished();
|
|
+ }
|
|
+ });
|
|
|
|
return futureInterface->future();
|
|
}
|
|
--
|
|
GitLab
|
|
|