Merge lp:~renatofilho/telephony-service/phonenumber-format into lp:telephony-service

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 850
Merged at revision: 850
Proposed branch: lp:~renatofilho/telephony-service/phonenumber-format
Merge into: lp:telephony-service
Diff against target: 267 lines (+198/-9)
6 files modified
Ubuntu/Telephony/PhoneNumber/CMakeLists.txt (+2/-0)
Ubuntu/Telephony/PhoneNumber/phonenumber.cpp (+10/-0)
Ubuntu/Telephony/PhoneNumber/phoneutils.cpp (+84/-0)
Ubuntu/Telephony/PhoneNumber/phoneutils.h (+45/-0)
Ubuntu/Telephony/tests/CMakeLists.txt (+13/-9)
Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml (+44/-0)
To merge this branch: bzr merge lp:~renatofilho/telephony-service/phonenumber-format
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+226541@code.launchpad.net

Commit message

Implemented PhoneNumber.format.

PhoneNumber.format can be used to format any string into a phone number formatted value.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
849. By Renato Araujo Oliveira Filho

Added missing license header.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
850. By Renato Araujo Oliveira Filho

[PhoneNumber] Does not try format phone numbers starting with "*" or "#"

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote :

Are there any related MPs required for this MP to build/function as expected? NO

Is your branch in sync with latest trunk? YES

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator? YES

Did you successfully run all tests found in your component's Test Plan on device or emulator? YES

If you changed the UI, was the change specified/approved by design? NO UI CHANGE

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP? NO PACKAGE CHANGE

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
Yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

Code looks good and works as expected!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Ubuntu/Telephony/PhoneNumber/CMakeLists.txt'
--- Ubuntu/Telephony/PhoneNumber/CMakeLists.txt 2014-07-04 17:16:59 +0000
+++ Ubuntu/Telephony/PhoneNumber/CMakeLists.txt 2014-07-12 13:26:42 +0000
@@ -1,6 +1,8 @@
1set(PHONENUMBER_SRCS1set(PHONENUMBER_SRCS
2 phonenumber.h2 phonenumber.h
3 phonenumber.cpp3 phonenumber.cpp
4 phoneutils.h
5 phoneutils.cpp
4 asyoutypeformatter.h6 asyoutypeformatter.h
5 asyoutypeformatter.cpp7 asyoutypeformatter.cpp
6 )8 )
79
=== modified file 'Ubuntu/Telephony/PhoneNumber/phonenumber.cpp'
--- Ubuntu/Telephony/PhoneNumber/phonenumber.cpp 2014-04-23 20:55:13 +0000
+++ Ubuntu/Telephony/PhoneNumber/phonenumber.cpp 2014-07-12 13:26:42 +0000
@@ -22,10 +22,19 @@
2222
23#include "phonenumber.h"23#include "phonenumber.h"
24#include "asyoutypeformatter.h"24#include "asyoutypeformatter.h"
25#include "phoneutils.h"
2526
26#include <QQmlEngine>27#include <QQmlEngine>
27#include <qqml.h>28#include <qqml.h>
2829
30
31static QObject *phoneUtilsProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
32{
33 Q_UNUSED(engine)
34 Q_UNUSED(scriptEngine)
35 return new PhoneUtils;
36}
37
29void PhoneNumber::initializeEngine(QQmlEngine *engine, const char *uri)38void PhoneNumber::initializeEngine(QQmlEngine *engine, const char *uri)
30{39{
31 Q_UNUSED(engine);40 Q_UNUSED(engine);
@@ -36,4 +45,5 @@
36{45{
37 // @uri Telephony.PhoneNumber46 // @uri Telephony.PhoneNumber
38 qmlRegisterType<AsYouTypeFormatter>(uri, 0, 1, "AsYouTypeFormatter");47 qmlRegisterType<AsYouTypeFormatter>(uri, 0, 1, "AsYouTypeFormatter");
48 qmlRegisterSingletonType<PhoneUtils>(uri, 0, 1, "PhoneUtils", phoneUtilsProvider);
39}49}
4050
=== added file 'Ubuntu/Telephony/PhoneNumber/phoneutils.cpp'
--- Ubuntu/Telephony/PhoneNumber/phoneutils.cpp 1970-01-01 00:00:00 +0000
+++ Ubuntu/Telephony/PhoneNumber/phoneutils.cpp 2014-07-12 13:26:42 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * Authors:
5 * Renato Araujo Oliveira Filho <renato.filho@canonical.com>
6 *
7 * This file is part of telephony-service.
8 *
9 * telephony-service is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * telephony-service is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "phoneutils.h"
23
24#include <QtCore/QDebug>
25#include <phonenumbers/phonenumberutil.h>
26
27
28PhoneUtils::PhoneUtils(QObject *parent)
29 : QObject(parent)
30{
31}
32
33PhoneUtils::~PhoneUtils()
34{
35}
36
37QString PhoneUtils::format(const QString &phoneNumber, const QString &defaultRegion, PhoneUtils::PhoneNumberFormat format)
38{
39 std::string formattedNumber;
40 i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat pNFormat;
41 if (format == PhoneUtils::Auto) {
42 // skip if it is a special number or a command
43 if (phoneNumber.startsWith("#") || phoneNumber.startsWith("*")) {
44 return phoneNumber;
45 } else if (phoneNumber.startsWith("+")) {
46 pNFormat = i18n::phonenumbers::PhoneNumberUtil::INTERNATIONAL;
47 } else {
48 pNFormat = i18n::phonenumbers::PhoneNumberUtil::NATIONAL;
49 }
50 } else {
51 pNFormat = static_cast<i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat>(format);
52 }
53
54
55 i18n::phonenumbers::PhoneNumberUtil *phonenumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
56
57 i18n::phonenumbers::PhoneNumber number;
58 i18n::phonenumbers::PhoneNumberUtil::ErrorType error;
59 error = phonenumberUtil->Parse(phoneNumber.toStdString(), defaultRegion.toStdString(), &number);
60
61 switch(error) {
62 case i18n::phonenumbers::PhoneNumberUtil::INVALID_COUNTRY_CODE_ERROR:
63 qWarning() << "Invalid coutry code for:" << phoneNumber;
64 return "";
65 case i18n::phonenumbers::PhoneNumberUtil::NOT_A_NUMBER:
66 qWarning() << "The phone number is not a valid number:" << phoneNumber;
67 return "";
68 case i18n::phonenumbers::PhoneNumberUtil::TOO_SHORT_AFTER_IDD:
69 case i18n::phonenumbers::PhoneNumberUtil::TOO_SHORT_NSN:
70 case i18n::phonenumbers::PhoneNumberUtil::TOO_LONG_NSN:
71 qWarning() << "Invalid phone number" << phoneNumber;
72 return "";
73 default:
74 break;
75 }
76
77
78 phonenumberUtil->Format(number,
79 pNFormat,
80 &formattedNumber);
81 return QString::fromStdString(formattedNumber);
82}
83
84
085
=== added file 'Ubuntu/Telephony/PhoneNumber/phoneutils.h'
--- Ubuntu/Telephony/PhoneNumber/phoneutils.h 1970-01-01 00:00:00 +0000
+++ Ubuntu/Telephony/PhoneNumber/phoneutils.h 2014-07-12 13:26:42 +0000
@@ -0,0 +1,45 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * Authors:
5 * Renato Araujo Oliveira Filho <renato.filho@canonical.com>
6 *
7 * This file is part of telephony-service.
8 *
9 * telephony-service is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * telephony-service is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef TELEPHONY_PHONEUTILS_H
23#define TELEPHONY_PHONEUTILS_H
24
25#include <QtCore/QObject>
26
27class PhoneUtils : public QObject
28{
29 Q_OBJECT
30public:
31 enum PhoneNumberFormat {
32 E164 = 0,
33 International,
34 National,
35 RFC3966,
36 Auto
37 };
38
39 PhoneUtils(QObject *parent = 0);
40 ~PhoneUtils();
41
42 Q_INVOKABLE QString format(const QString &phoneNumber, const QString &defaultRegion, PhoneNumberFormat format = Auto);
43};
44
45#endif
046
=== modified file 'Ubuntu/Telephony/tests/CMakeLists.txt'
--- Ubuntu/Telephony/tests/CMakeLists.txt 2014-07-04 17:16:59 +0000
+++ Ubuntu/Telephony/tests/CMakeLists.txt 2014-07-12 13:26:42 +0000
@@ -14,19 +14,23 @@
14 endforeach(test)14 endforeach(test)
15endmacro(generate_tests)15endmacro(generate_tests)
1616
17macro(DECLARE_QML_TEST TST_NAME TST_QML_FILE)
18 add_test(NAME ${TST_NAME}
19 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
20 COMMAND xvfb-run -a -s "-screen 0 1024x768x24" qmltestrunner -import ${CMAKE_BINARY_DIR} -input ${CMAKE_CURRENT_SOURCE_DIR}/${TST_QML_FILE}
21 )
22endmacro()
23
1724
18generate_tests(25generate_tests(
19 ContactWatcherTest26 ContactWatcherTest
20 )27 )
2128
29declare_qml_test("context_properties" tst_contextProperties.qml)
30declare_qml_test("phonenumber_field" tst_PhoneNumberField.qml)
31declare_qml_test("phonenumber_input" tst_PhoneNumberInput.qml)
32declare_qml_test("phonenumber_utils" tst_PhoneNumberPhoneUtils.qml)
33
34# make the files visible on qtcreator
22file(GLOB QML_TESTS *.qml *.js)35file(GLOB QML_TESTS *.qml *.js)
23
24# make the files visible on qtcreator
25add_custom_target(telephonyservice_QMLTESTS ALL SOURCES ${QML_TESTS})36add_custom_target(telephonyservice_QMLTESTS ALL SOURCES ${QML_TESTS})
26
27# FIXME: those tests are disabled because qmltestrunner is crashing on armhf.
28# They should be re-enabled once the problem is found and fixed.
29add_test(NAME qmltestrunner
30 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
31 COMMAND xvfb-run -a -s "-screen 0 1024x768x24" qmltestrunner -import ${CMAKE_BINARY_DIR} -input ${CMAKE_CURRENT_SOURCE_DIR}
32)
3337
=== added file 'Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml'
--- Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml 1970-01-01 00:00:00 +0000
+++ Ubuntu/Telephony/tests/tst_PhoneNumberPhoneUtils.qml 2014-07-12 13:26:42 +0000
@@ -0,0 +1,44 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This file is part of telephony-service.
5 *
6 * telephony-service is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * telephony-service is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import QtTest 1.0
21import Ubuntu.Telephony.PhoneNumber 0.1 as PhoneNumber
22
23TestCase {
24 id: phoneNumberPhoneUtils
25 name: "phoneNumberPhoneUtils"
26
27 function test_formatPhone_data()
28 {
29 var data = [];
30 data.push({input: "6681800", expectedOutput: "668-1800"}) // Local number
31 data.push({input: "7327572923", expectedOutput: "(732) 757-2923"}) // Coutry number
32 data.push({input: "+558187042155", expectedOutput: "+55 81 8704-2155"}) // International number
33 data.push({input: "55555555555", expectedOutput: "55555555555"}) // Ivalid number
34 data.push({input: "*144", expectedOutput: "*144"}) // Special number
35 data.push({input: "#123#", expectedOutput: "#123#"}) // Operators command
36 return data
37 }
38
39 function test_formatPhone(data)
40 {
41 var formatted = PhoneNumber.PhoneUtils.format(data.input, "US")
42 compare(formatted, data.expectedOutput)
43 }
44}

Subscribers

People subscribed via source and target branches