Merge lp:~tiagosh/telepathy-ofono/use-libphonenumber into lp:telepathy-ofono

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 166
Merged at revision: 159
Proposed branch: lp:~tiagosh/telepathy-ofono/use-libphonenumber
Merge into: lp:telepathy-ofono
Diff against target: 1336 lines (+574/-422)
17 files modified
CMakeLists.txt (+4/-2)
cmake/modules/FindLibPhoneNumber.cmake (+23/-0)
cmake/modules/LibFindMacros.cmake (+112/-0)
connection.cpp (+17/-12)
connection.h (+1/-1)
countrycodes.qrc (+5/-0)
countrycodes.txt (+224/-0)
debian/control (+1/-0)
debian/copyright (+0/-17)
emergencymodeiface.cpp (+30/-0)
emergencymodeiface.h (+12/-0)
phonenumberutils_p.h (+0/-301)
phoneutils.cpp (+112/-43)
phoneutils_p.h (+0/-38)
tests/CMakeLists.txt (+2/-0)
tests/PhoneUtilsTest.cpp (+8/-8)
tools/generate_country_codes.py (+23/-0)
To merge this branch: bzr merge lp:~tiagosh/telepathy-ofono/use-libphonenumber
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+264905@code.launchpad.net

Commit message

Use libphonenumber for phone number validation, normalization and comparison.

Description of the change

Use libphonenumber for phone number validation, normalization and comparison.

--Checklist--
Are there any related MPs required for this MP to build/function as expected? Please list.
No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
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 (https://wiki.ubuntu.com/Process/Merges/TestPlan/<package-name>) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed UI labels, did you update the pot file?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
155. By Tiago Salem Herrmann

Provide a fallback to country code if none is provided.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
156. By Tiago Salem Herrmann

Add country code support in the emergency mode interface

157. By Tiago Salem Herrmann

Add country code database and an auto generation tool

158. By Tiago Salem Herrmann

Set MCC in PhoneUtils when needed

159. By Tiago Salem Herrmann

Also use SimManager interface to retrieve mobile country code

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
160. By Tiago Salem Herrmann

Initialize mMcc

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
161. By Tiago Salem Herrmann

Use IsEmergencyNumber() instead of ConnectsToEmergencyNumber()

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
162. By Tiago Salem Herrmann

Don't notify the same country code twice

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
163. By Tiago Salem Herrmann

Don't check for emergency numbers. This check must be done by the upper layers. We simply bypass the request to ofono

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
164. By Tiago Salem Herrmann

remove unused include

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Just a couple remarks, other than that looks good.

review: Needs Fixing
165. By Tiago Salem Herrmann

fix header copyright

166. By Tiago Salem Herrmann

add test for phone numbers with slashes

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
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
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-05-08 20:48:08 +0000
3+++ CMakeLists.txt 2015-08-07 19:10:15 +0000
4@@ -30,6 +30,7 @@
5 ENABLE_COVERAGE_REPORT(TARGETS ${TELEPATHY_OFONO})
6 ENDIF(CMAKE_BUILD_TYPE MATCHES [cC][oO][vV][eE][rR][aA][gG][eE])
7
8+find_package(LibPhoneNumber REQUIRED)
9 find_package(Qt5Core)
10 find_package(Qt5DBus)
11 add_definitions(-DQT_NO_KEYWORDS)
12@@ -58,6 +59,7 @@
13 include_directories(${Qt5Core_INCLUDE_DIRS})
14 include_directories(${Qt5DBus_INCLUDE_DIRS})
15 include_directories(${SQLITE3_INCLUDE_DIRS})
16+include_directories(${LibPhoneNumber_INCLUDE_DIRS})
17 include_directories(/usr/include/telepathy-qt5/)
18 include_directories(/usr/include/ofono-qt/)
19
20@@ -65,7 +67,7 @@
21 find_library(TELEPATHY_QT5_SERVICE_LIBRARIES telepathy-qt5-service)
22 find_library(OFONO_QT_LIBRARIES ofono-qt)
23
24-qt5_add_resources(telepathyfono_RES sqlitetelepathyofono.qrc)
25+qt5_add_resources(telepathyfono_RES sqlitetelepathyofono.qrc countrycodes.qrc)
26
27 # update the .qrc file automatically when there are new schema files
28 file(GLOB QRC_RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.sql ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.info)
29@@ -109,7 +111,7 @@
30
31 enable_testing()
32
33-target_link_libraries(${TELEPATHY_OFONO} ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${WAUDIO_LIBRARIES} -ltelepathy-qt5 ${TELEPATHY_QT5_SERVICE_LIBRARIES} ${OFONO_QT_LIBRARIES} ${PULSEAUDIO_LIBRARIES} ${SQLITE3_LIBRARIES})
34+target_link_libraries(${TELEPATHY_OFONO} ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${WAUDIO_LIBRARIES} -ltelepathy-qt5 ${TELEPATHY_QT5_SERVICE_LIBRARIES} ${OFONO_QT_LIBRARIES} ${PULSEAUDIO_LIBRARIES} ${SQLITE3_LIBRARIES} ${LibPhoneNumber_LIBRARIES})
35 install(TARGETS ${TELEPATHY_OFONO} DESTINATION ${DAEMON_DIR})
36
37 configure_file(ofono.service.in org.freedesktop.Telepathy.ConnectionManager.ofono.service)
38
39=== added file 'cmake/modules/FindLibPhoneNumber.cmake'
40--- cmake/modules/FindLibPhoneNumber.cmake 1970-01-01 00:00:00 +0000
41+++ cmake/modules/FindLibPhoneNumber.cmake 2015-08-07 19:10:15 +0000
42@@ -0,0 +1,23 @@
43+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
44+
45+include(GNUInstallDirs)
46+include(LibFindMacros)
47+
48+# Include dir
49+find_path(LibPhoneNumber_INCLUDE_DIR
50+ NAMES phonenumberutil.h
51+ PATHS "/usr/local/${CMAKE_INSTALL_INCLUDEDIR}" ${CMAKE_INSTALL_FULL_INCLUDEDIR}
52+ PATH_SUFFIXES "phonenumbers"
53+)
54+
55+# library itself
56+find_library(LibPhoneNumber_LIBRARY
57+ NAMES phonenumber
58+ PATHS "/usr/local/${CMAKE_INSTALL_LIBDIR}" ${CMAKE_INSTALL_FULL_LIBDIR}
59+)
60+
61+# Set the include dir variables and the libraries and let libfind_process do the rest.
62+# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
63+set(LibPhoneNumber_PROCESS_INCLUDES LibPhoneNumber_INCLUDE_DIR)
64+set(LibPhoneNumber_PROCESS_LIBS LibPhoneNumber_LIBRARY)
65+libfind_process(LibPhoneNumber)
66
67=== added file 'cmake/modules/LibFindMacros.cmake'
68--- cmake/modules/LibFindMacros.cmake 1970-01-01 00:00:00 +0000
69+++ cmake/modules/LibFindMacros.cmake 2015-08-07 19:10:15 +0000
70@@ -0,0 +1,112 @@
71+# Version 1.0 (2013-04-12)
72+# Public Domain, originally written by Lasse Kärkkäinen <tronic@zi.fi>
73+# Published at http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries
74+
75+# If you improve the script, please modify the forementioned wiki page because
76+# I no longer maintain my scripts (hosted as static files at zi.fi). Feel free
77+# to remove this entire header if you use real version control instead.
78+
79+# Changelog:
80+# 2013-04-12 Added version number (1.0) and this header, no other changes
81+# 2009-10-08 Originally published
82+
83+
84+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
85+# used for the current package. For this to work, the first parameter must be the
86+# prefix of the current package, then the prefix of the new package etc, which are
87+# passed to find_package.
88+macro (libfind_package PREFIX)
89+ set (LIBFIND_PACKAGE_ARGS ${ARGN})
90+ if (${PREFIX}_FIND_QUIETLY)
91+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
92+ endif (${PREFIX}_FIND_QUIETLY)
93+ if (${PREFIX}_FIND_REQUIRED)
94+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
95+ endif (${PREFIX}_FIND_REQUIRED)
96+ find_package(${LIBFIND_PACKAGE_ARGS})
97+endmacro (libfind_package)
98+
99+# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
100+# where they added pkg_check_modules. Consequently I need to support both in my scripts
101+# to avoid those deprecated warnings. Here's a helper that does just that.
102+# Works identically to pkg_check_modules, except that no checks are needed prior to use.
103+macro (libfind_pkg_check_modules PREFIX PKGNAME)
104+ if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
105+ include(UsePkgConfig)
106+ pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
107+ else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
108+ find_package(PkgConfig)
109+ if (PKG_CONFIG_FOUND)
110+ pkg_check_modules(${PREFIX} ${PKGNAME})
111+ endif (PKG_CONFIG_FOUND)
112+ endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
113+endmacro (libfind_pkg_check_modules)
114+
115+# Do the final processing once the paths have been detected.
116+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
117+# all the variables, each of which contain one include directory.
118+# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
119+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
120+# Also handles errors in case library detection was required, etc.
121+macro (libfind_process PREFIX)
122+ # Skip processing if already processed during this run
123+ if (NOT ${PREFIX}_FOUND)
124+ # Start with the assumption that the library was found
125+ set (${PREFIX}_FOUND TRUE)
126+
127+ # Process all includes and set _FOUND to false if any are missing
128+ foreach (i ${${PREFIX}_PROCESS_INCLUDES})
129+ if (${i})
130+ set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
131+ mark_as_advanced(${i})
132+ else (${i})
133+ set (${PREFIX}_FOUND FALSE)
134+ endif (${i})
135+ endforeach (i)
136+
137+ # Process all libraries and set _FOUND to false if any are missing
138+ foreach (i ${${PREFIX}_PROCESS_LIBS})
139+ if (${i})
140+ set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
141+ mark_as_advanced(${i})
142+ else (${i})
143+ set (${PREFIX}_FOUND FALSE)
144+ endif (${i})
145+ endforeach (i)
146+
147+ # Print message and/or exit on fatal error
148+ if (${PREFIX}_FOUND)
149+ if (NOT ${PREFIX}_FIND_QUIETLY)
150+ message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
151+ endif (NOT ${PREFIX}_FIND_QUIETLY)
152+ else (${PREFIX}_FOUND)
153+ if (${PREFIX}_FIND_REQUIRED)
154+ foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
155+ message("${i}=${${i}}")
156+ endforeach (i)
157+ message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
158+ endif (${PREFIX}_FIND_REQUIRED)
159+ endif (${PREFIX}_FOUND)
160+ endif (NOT ${PREFIX}_FOUND)
161+endmacro (libfind_process)
162+
163+macro(libfind_library PREFIX basename)
164+ set(TMP "")
165+ if(MSVC80)
166+ set(TMP -vc80)
167+ endif(MSVC80)
168+ if(MSVC90)
169+ set(TMP -vc90)
170+ endif(MSVC90)
171+ set(${PREFIX}_LIBNAMES ${basename}${TMP})
172+ if(${ARGC} GREATER 2)
173+ set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
174+ string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
175+ set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
176+ endif(${ARGC} GREATER 2)
177+ find_library(${PREFIX}_LIBRARY
178+ NAMES ${${PREFIX}_LIBNAMES}
179+ PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
180+ )
181+endmacro(libfind_library)
182+
183
184=== modified file 'connection.cpp'
185--- connection.cpp 2015-07-28 14:40:12 +0000
186+++ connection.cpp 2015-08-07 19:10:15 +0000
187@@ -229,6 +229,7 @@
188 QObject::connect(mOfonoSimManager, SIGNAL(subscriberNumbersChanged(QStringList)), SLOT(updateOnlineStatus()));
189 QObject::connect(mOfonoNetworkRegistration, SIGNAL(statusChanged(QString)), SLOT(updateOnlineStatus()));
190 QObject::connect(mOfonoNetworkRegistration, SIGNAL(nameChanged(QString)), SLOT(updateOnlineStatus()));
191+ QObject::connect(mOfonoNetworkRegistration, SIGNAL(mccChanged(QString)), SLOT(updateOnlineStatus(QString)));
192 QObject::connect(mOfonoNetworkRegistration, SIGNAL(validityChanged(bool)), SLOT(onValidityChanged(bool)));
193 QObject::connect(mOfonoMessageWaiting, SIGNAL(voicemailMessageCountChanged(int)), voicemailIface.data(), SLOT(setVoicemailCount(int)));
194 QObject::connect(mOfonoMessageWaiting, SIGNAL(voicemailWaitingChanged(bool)), voicemailIface.data(), SLOT(setVoicemailIndicator(bool)));
195@@ -308,6 +309,19 @@
196 }
197 }
198
199+void oFonoConnection::updateMcc()
200+{
201+ QString mcc;
202+ // check if the network mcc is available first, then try the sim card mcc
203+ if (!mOfonoNetworkRegistration->mcc().isEmpty()) {
204+ mcc = mOfonoNetworkRegistration->mcc();
205+ } else if (!mOfonoSimManager->mobileCountryCode().isEmpty()) {
206+ mcc = mOfonoSimManager->mobileCountryCode();
207+ }
208+ PhoneUtils::setMcc(mcc);
209+ emergencyModeIface->setCountryCode(PhoneUtils::countryCodeForMCC(mcc));
210+}
211+
212 void oFonoConnection::onMMSDServiceAdded(const QString &path)
213 {
214 MMSDService *service = new MMSDService(path, this);
215@@ -508,17 +522,6 @@
216 status.isEmpty());
217 }
218
219-bool oFonoConnection::isEmergencyNumber(const QString &number)
220-{
221- Q_FOREACH (const QString &emergencyNumber, mOfonoVoiceCallManager->emergencyNumbers()) {
222- if (PhoneUtils::comparePhoneNumbers(emergencyNumber, number)) {
223- return true;
224- break;
225- }
226- }
227- return false;
228-}
229-
230 uint oFonoConnection::setPresence(const QString& status, const QString& statusMessage, Tp::DBusError *error)
231 {
232 qDebug() << "setPresence" << status;
233@@ -601,6 +604,8 @@
234
235 presences[selfHandle()] = mSelfPresence;
236 simplePresenceIface->setPresences(presences);
237+
238+ updateMcc();
239 }
240
241 uint oFonoConnection::newHandle(const QString &identifier)
242@@ -720,7 +725,7 @@
243 (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")) || request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType")] == Tp::HandleTypeNone) &&
244 (!request.contains(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")) || request[TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle")] == 0));
245
246- if (!available && (isConference || !isEmergencyNumber(newPhoneNumber))) {
247+ if (!available && isConference) {
248 error->set(TP_QT_ERROR_NETWORK_ERROR, "No network available");
249 return Tp::BaseChannelPtr();
250 }
251
252=== modified file 'connection.h'
253--- connection.h 2015-07-28 14:31:21 +0000
254+++ connection.h 2015-08-07 19:10:15 +0000
255@@ -154,8 +154,8 @@
256 #endif
257
258 private:
259+ void updateMcc();
260 bool isNetworkRegistered();
261- bool isEmergencyNumber(const QString &number);
262 void addMMSToService(const QString &path, const QVariantMap &properties, const QString &servicePath);
263 void ensureTextChannel(const QString &message, const QVariantMap &info, bool flash);
264 QMap<uint, QString> mHandles;
265
266=== added file 'countrycodes.qrc'
267--- countrycodes.qrc 1970-01-01 00:00:00 +0000
268+++ countrycodes.qrc 2015-08-07 19:10:15 +0000
269@@ -0,0 +1,5 @@
270+<RCC>
271+ <qresource prefix="/">
272+ <file>countrycodes.txt</file>
273+ </qresource>
274+</RCC>
275
276=== added file 'countrycodes.txt'
277--- countrycodes.txt 1970-01-01 00:00:00 +0000
278+++ countrycodes.txt 2015-08-07 19:10:15 +0000
279@@ -0,0 +1,224 @@
280+514:TP
281+515:PH
282+520:TH
283+525:SG
284+528:BN
285+530:NZ
286+537:PG
287+539:TO
288+540:SB
289+541:VU
290+542:FJ
291+544:AS
292+545:KI
293+546:NC
294+547:PF
295+548:CK
296+549:WS
297+550:FM
298+552:PW
299+553:TV
300+555:NU
301+602:EG
302+603:DZ
303+604:MA
304+605:TN
305+606:LY
306+607:GM
307+608:SN
308+609:MR
309+610:ML
310+611:GN
311+612:CI
312+613:BF
313+614:NE
314+615:TG
315+616:BJ
316+617:MU
317+618:LR
318+619:SL
319+620:GH
320+621:NG
321+622:TD
322+623:CF
323+624:CM
324+625:CV
325+626:ST
326+627:GQ
327+628:GA
328+629:CG
329+630:CD
330+631:AO
331+632:GW
332+633:SC
333+634:SD
334+635:RW
335+636:ET
336+637:SO
337+638:DJ
338+639:KE
339+640:TZ
340+641:UG
341+642:BI
342+643:MZ
343+645:ZM
344+646:MG
345+647:RE
346+648:ZW
347+649:NA
348+650:MW
349+651:LS
350+652:BW
351+653:SZ
352+654:KM
353+655:ZA
354+657:ER
355+659:SS
356+714:PA
357+702:BZ
358+704:GT
359+706:SV
360+708:HN
361+710:NI
362+712:CR
363+716:PE
364+202:GR
365+204:NL
366+206:BE
367+208:FR
368+722:AR
369+724:BR
370+213:AD
371+214:ES
372+216:HU
373+730:CL
374+219:HR
375+732:CO
376+222:IT
377+736:BO
378+738:GY
379+740:EC
380+230:CZ
381+231:SK
382+232:AT
383+746:SR
384+235:GB
385+748:UY
386+750:FK
387+240:SE
388+242:NO
389+244:FI
390+246:LT
391+247:LV
392+248:EE
393+212:MC
394+250:RU
395+255:UA
396+257:BY
397+259:MD
398+260:PL
399+262:DE
400+266:GI
401+268:PT
402+270:LU
403+272:IE
404+274:IS
405+276:AL
406+278:MT
407+280:CY
408+282:GE
409+283:AM
410+284:BG
411+218:BA
412+286:TR
413+288:FO
414+289:GE
415+290:GL
416+292:SM
417+293:SI
418+294:MK
419+295:LI
420+297:ME
421+302:CA
422+308:PM
423+734:VE
424+310:US
425+311:US
426+312:US
427+316:US
428+330:PR
429+226:RO
430+334:MX
431+338:JM
432+340:MQ
433+342:BB
434+344:AG
435+228:CH
436+346:KY
437+348:VG
438+350:BM
439+352:GD
440+354:MS
441+356:KN
442+358:LC
443+360:VC
444+362:AN
445+363:AW
446+364:BS
447+365:AI
448+366:DM
449+368:CU
450+744:PY
451+370:DO
452+372:HT
453+374:TT
454+376:VI
455+234:GB
456+405:IN
457+400:AZ
458+401:KZ
459+402:BT
460+404:IN
461+238:DK
462+410:PK
463+412:AF
464+413:LK
465+414:MM
466+415:LB
467+416:JO
468+417:SY
469+418:IQ
470+419:KW
471+420:SA
472+421:YE
473+422:OM
474+424:AE
475+425:PS
476+426:BH
477+427:QA
478+428:MN
479+429:NP
480+430:AE
481+431:AE
482+432:IR
483+434:UZ
484+436:TK
485+437:KG
486+438:TM
487+440:JP
488+441:JP
489+450:KR
490+452:VN
491+454:HK
492+455:MO
493+456:KH
494+457:LA
495+460:CN
496+466:TW
497+467:KP
498+220:RS
499+470:BD
500+472:MV
501+502:MY
502+505:AU
503+510:ID
504
505=== modified file 'debian/control'
506--- debian/control 2015-06-03 18:54:43 +0000
507+++ debian/control 2015-08-07 19:10:15 +0000
508@@ -9,6 +9,7 @@
509 gnome-keyring,
510 libmission-control-plugins-dev (>= 1:5.14.0),
511 libofono-qt-dev (>= 1.5),
512+ libphonenumber-dev,
513 libqt5sql5-sqlite,
514 libtelepathy-qt5-dev (>= 0.9.3),
515 libpulse-dev [armhf],
516
517=== modified file 'debian/copyright'
518--- debian/copyright 2015-05-08 20:48:08 +0000
519+++ debian/copyright 2015-08-07 19:10:15 +0000
520@@ -7,10 +7,6 @@
521 Copyright: 2013 Canonical, Ltd.
522 License: LGPL-3
523
524-Files: phoneutils.h
525-Copyright: 2006 The Android Open Source Project
526-License: Apache-2.0
527-
528 Files: debian/*
529 Copyright: 2013 Canonical, Ltd.
530 License: LGPL-3
531@@ -29,19 +25,6 @@
532 2012 Collabora Ltd
533 License: LGPL-2.1+
534
535-License: Apache-2.0
536- Licensed under the Apache License, Version 2.0 (the "License");
537- you may not use this file except in compliance with the License.
538- You may obtain a copy of the License at
539- .
540- http://www.apache.org/licenses/LICENSE-2.0
541- .
542- Unless required by applicable law or agreed to in writing, software
543- distributed under the License is distributed on an "AS IS" BASIS,
544- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
545- See the License for the specific language governing permissions and
546- limitations under the License.
547-
548 License: LGPL-3
549 This package is free software; you can redistribute it and/or
550 modify it under the terms of the GNU Lesser General Public
551
552=== modified file 'emergencymodeiface.cpp'
553--- emergencymodeiface.cpp 2015-01-20 16:00:58 +0000
554+++ emergencymodeiface.cpp 2015-08-07 19:10:15 +0000
555@@ -38,6 +38,7 @@
556 EmergencyNumbersCallback emergencyNumbersCB;
557 BaseConnectionEmergencyModeInterface::Adaptee *adaptee;
558 QString fakeEmergencyNumber;
559+ QString countryCode;
560 };
561
562 BaseConnectionEmergencyModeInterface::Adaptee::~Adaptee()
563@@ -63,6 +64,11 @@
564 }
565 }
566
567+void BaseConnectionEmergencyModeInterface::Adaptee::countryCode(const ConnectionInterfaceEmergencyModeAdaptor::CountryCodeContextPtr &context)
568+{
569+ context->setFinished(mInterface->mPriv->countryCode);
570+}
571+
572 BaseConnectionEmergencyModeInterface::BaseConnectionEmergencyModeInterface()
573 : AbstractConnectionInterface(TP_QT_IFACE_CONNECTION_EMERGENCYMODE),
574 mPriv(new Private(this))
575@@ -90,6 +96,15 @@
576 Q_EMIT mPriv->adaptee->emergencyNumbersChanged(finalEmergencyList);
577 }
578
579+void BaseConnectionEmergencyModeInterface::setCountryCode(const QString &countryCode)
580+{
581+ if (mPriv->countryCode == countryCode) {
582+ return;
583+ }
584+ mPriv->countryCode = countryCode;
585+ Q_EMIT mPriv->adaptee->countryCodeChanged(mPriv->countryCode);
586+}
587+
588 void BaseConnectionEmergencyModeInterface::setFakeEmergencyNumber(const QString &fakeEmergencyNumber)
589 {
590 mPriv->fakeEmergencyNumber = fakeEmergencyNumber;
591@@ -112,6 +127,7 @@
592 : Tp::AbstractAdaptor(bus, adaptee, parent)
593 {
594 connect(adaptee, SIGNAL(emergencyNumbersChanged(QStringList)), SIGNAL(EmergencyNumbersChanged(QStringList)));
595+ connect(adaptee, SIGNAL(countryCodeChanged(QString)), SIGNAL(CountryCodeChanged(QString)));
596 }
597
598 ConnectionInterfaceEmergencyModeAdaptor::~ConnectionInterfaceEmergencyModeAdaptor()
599@@ -131,3 +147,17 @@
600 Q_ARG(ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr, ctx));
601 return QStringList();
602 }
603+
604+QString ConnectionInterfaceEmergencyModeAdaptor::CountryCode(const QDBusMessage& dbusMessage)
605+{
606+ if (!adaptee()->metaObject()->indexOfMethod("countryCode(ConnectionInterfaceEmergencyModeAdaptor::CountryCodeContextPtr)") == -1) {
607+ dbusConnection().send(dbusMessage.createErrorReply(TP_QT_ERROR_NOT_IMPLEMENTED, QLatin1String("Not implemented")));
608+ return QString();
609+ }
610+
611+ CountryCodeContextPtr ctx = CountryCodeContextPtr(
612+ new Tp::MethodInvocationContext< QString >(dbusConnection(), dbusMessage));
613+ QMetaObject::invokeMethod(adaptee(), "countryCode",
614+ Q_ARG(ConnectionInterfaceEmergencyModeAdaptor::CountryCodeContextPtr, ctx));
615+ return QString();
616+}
617
618=== modified file 'emergencymodeiface.h'
619--- emergencymodeiface.h 2015-01-20 16:00:58 +0000
620+++ emergencymodeiface.h 2015-08-07 19:10:15 +0000
621@@ -56,6 +56,7 @@
622
623 public Q_SLOTS:
624 void setEmergencyNumbers(const QStringList &numbers);
625+ void setCountryCode(const QString &countryCode);
626
627 protected:
628 BaseConnectionEmergencyModeInterface();
629@@ -83,6 +84,12 @@
630 " <signal name=\"EmergencyNumbersChanged\">\n"
631 " <arg type=\"as\" name=\"numbers\"/>\n"
632 " </signal>\n"
633+" <method name=\"CountryCode\">\n"
634+" <arg direction=\"out\" type=\"s\" name=\"countryCode\"/>\n"
635+" </method>\n"
636+" <signal name=\"CountryCodeChanged\">\n"
637+" <arg type=\"s\" name=\"countryCode\"/>\n"
638+" </signal>\n"
639 " </interface>\n"
640 "")
641
642@@ -91,12 +98,15 @@
643 virtual ~ConnectionInterfaceEmergencyModeAdaptor();
644
645 typedef Tp::MethodInvocationContextPtr< QStringList > EmergencyNumbersContextPtr;
646+ typedef Tp::MethodInvocationContextPtr< QString > CountryCodeContextPtr;
647
648 public Q_SLOTS: // METHODS
649 QStringList EmergencyNumbers(const QDBusMessage& dbusMessage);
650+ QString CountryCode(const QDBusMessage& dbusMessage);
651
652 Q_SIGNALS: // SIGNALS
653 void EmergencyNumbersChanged(const QStringList &numbers);
654+ void CountryCodeChanged(const QString &countryCode);
655 };
656
657
658@@ -110,9 +120,11 @@
659
660 private Q_SLOTS:
661 void emergencyNumbers(const ConnectionInterfaceEmergencyModeAdaptor::EmergencyNumbersContextPtr &context);
662+ void countryCode(const ConnectionInterfaceEmergencyModeAdaptor::CountryCodeContextPtr &context);
663
664 Q_SIGNALS:
665 void emergencyNumbersChanged(const QStringList &numbers);
666+ void countryCodeChanged(const QString &countryCode);
667
668 public:
669 BaseConnectionEmergencyModeInterface *mInterface;
670
671=== removed file 'phonenumberutils_p.h'
672--- phonenumberutils_p.h 2013-11-08 14:53:53 +0000
673+++ phonenumberutils_p.h 1970-01-01 00:00:00 +0000
674@@ -1,301 +0,0 @@
675-/*
676- * Copyright (C) 2006 The Android Open Source Project
677- *
678- * Licensed under the Apache License, Version 2.0 (the "License");
679- * you may not use this file except in compliance with the License.
680- * You may obtain a copy of the License at
681- *
682- * http://www.apache.org/licenses/LICENSE-2.0
683- *
684- * Unless required by applicable law or agreed to in writing, software
685- * distributed under the License is distributed on an "AS IS" BASIS,
686- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
687- * See the License for the specific language governing permissions and
688- * limitations under the License.
689- *
690- * Original source code available at: http://androidxref.com/4.0.4/xref/frameworks/base/telephony/java/android/telephony/PhoneNumberUtils.java
691- */
692-
693-#ifndef PHONENUMBERUTILS_H
694-#define PHONENUMBERUTILS_H
695-
696-namespace PhoneNumberUtils
697-{
698-
699-/** True if c is ISO-LATIN characters 0-9, *, # , +, WILD, WAIT, PAUSE */
700-bool isNonSeparator(char c)
701-{
702- return (c >= '0' && c <= '9') || c == '*' || c == '#' || c == '+'
703- || c == 'N' || c == ';' || c == ',';
704-}
705-
706-/** True if c is ISO-LATIN characters 0-9, *, # , +, WILD */
707-bool isDialable(char c)
708-{
709- return (c >= '0' && c <= '9') || c == '*' || c == '#' || c == '+' || c == 'N';
710-}
711-
712-/** True if c is ISO-LATIN characters 0-9 */
713-bool isISODigit (char c) {
714- return c >= '0' && c <= '9';
715-}
716-
717-/** or -1 if both are negative */
718-int minPositive (int a, int b)
719-{
720- if (a >= 0 && b >= 0) {
721- return (a < b) ? a : b;
722- } else if (a >= 0) { /* && b < 0 */
723- return a;
724- } else if (b >= 0) { /* && a < 0 */
725- return b;
726- } else { /* a < 0 && b < 0 */
727- return -1;
728- }
729-}
730-
731-/** index of the last character of the network portion
732- * (eg anything after is a post-dial string)
733- */
734-int indexOfLastNetworkChar(const QString &a)
735-{
736- int pIndex, wIndex;
737- int origLength;
738- int trimIndex;
739-
740- origLength = a.length();
741-
742- pIndex = a.indexOf(',');
743- wIndex = a.indexOf(';');
744-
745- trimIndex = minPositive(pIndex, wIndex);
746-
747- if (trimIndex < 0) {
748- return origLength - 1;
749- } else {
750- return trimIndex - 1;
751- }
752-}
753-
754-/** all of a up to len must be an international prefix or
755- * separators/non-dialing digits
756- */
757-bool matchIntlPrefix(const QString &a, int len)
758-{
759- /* '([^0-9*#+pwn]\+[^0-9*#+pwn] | [^0-9*#+pwn]0(0|11)[^0-9*#+pwn] )$' */
760- /* 0 1 2 3 45 */
761-
762- int state = 0;
763- for (int i = 0 ; i < len ; i++) {
764- char c = a.at(i).toLatin1();
765-
766- switch (state) {
767- case 0:
768- if (c == '+') state = 1;
769- else if (c == '0') state = 2;
770- else if (isNonSeparator(c)) return false;
771- break;
772-
773- case 2:
774- if (c == '0') state = 3;
775- else if (c == '1') state = 4;
776- else if (isNonSeparator(c)) return false;
777- break;
778-
779- case 4:
780- if (c == '1') state = 5;
781- else if (isNonSeparator(c)) return false;
782- break;
783-
784- default:
785- if (isNonSeparator(c)) return false;
786- break;
787-
788- }
789- }
790-
791- return state == 1 || state == 3 || state == 5;
792-}
793-
794-/** all of 'a' up to len must match non-US trunk prefix ('0') */
795-bool matchTrunkPrefix(const QString &a, int len) {
796- bool found;
797-
798- found = false;
799-
800- for (int i = 0 ; i < len ; i++) {
801- char c = a.at(i).toLatin1();
802-
803- if (c == '0' && !found) {
804- found = true;
805- } else if (isNonSeparator(c)) {
806- return false;
807- }
808- }
809-
810- return found;
811-}
812-
813-/** all of 'a' up to len must be a (+|00|011)country code)
814- * We're fast and loose with the country code. Any \d{1,3} matches */
815-bool matchIntlPrefixAndCC(const QString &a, int len) {
816- /* [^0-9*#+pwn]*(\+|0(0|11)\d\d?\d? [^0-9*#+pwn] $ */
817- /* 0 1 2 3 45 6 7 8 */
818-
819- int state = 0;
820- for (int i = 0 ; i < len ; i++ ) {
821- char c = a.at(i).toLatin1();
822-
823- switch (state) {
824- case 0:
825- if (c == '+') state = 1;
826- else if (c == '0') state = 2;
827- else if (isNonSeparator(c)) return false;
828- break;
829-
830- case 2:
831- if (c == '0') state = 3;
832- else if (c == '1') state = 4;
833- else if (isNonSeparator(c)) return false;
834- break;
835-
836- case 4:
837- if (c == '1') state = 5;
838- else if (isNonSeparator(c)) return false;
839- break;
840-
841- case 1:
842- case 3:
843- case 5:
844- if (isISODigit(c)) state = 6;
845- else if (isNonSeparator(c)) return false;
846- break;
847-
848- case 6:
849- case 7:
850- if (isISODigit(c)) state++;
851- else if (isNonSeparator(c)) return false;
852- break;
853-
854- default:
855- if (isNonSeparator(c)) return false;
856- }
857- }
858-
859- return state == 6 || state == 7 || state == 8;
860-}
861-
862-
863-/**
864- * Compare phone numbers a and b, return true if they're identical
865- * enough for caller ID purposes.
866- *
867- * - Compares from right to left
868- * - requires MIN_MATCH (7) characters to match
869- * - handles common trunk prefixes and international prefixes
870- * (basically, everything except the Russian trunk prefix)
871- *
872- * Note that this method does not return false even when the two phone numbers
873- * are not exactly same; rather; we can call this method "similar()", not "equals()".
874- *
875- * @hide
876- */
877-bool compareLoosely(const QString &a, const QString &b)
878-{
879- int ia, ib;
880- int matched;
881- int numNonDialableCharsInA = 0;
882- int numNonDialableCharsInB = 0;
883-
884- if (a.length() == 0 || b.length() == 0) {
885- return false;
886- }
887-
888- if (a == b) {
889- return true;
890- }
891-
892- ia = indexOfLastNetworkChar (a);
893- ib = indexOfLastNetworkChar (b);
894- matched = 0;
895-
896- while (ia >= 0 && ib >=0) {
897- char ca, cb;
898- bool skipCmp = false;
899-
900- ca = a.at(ia).toLatin1();
901-
902- if (!isDialable(ca)) {
903- ia--;
904- skipCmp = true;
905- numNonDialableCharsInA++;
906- }
907-
908- cb = b.at(ib).toLatin1();
909-
910- if (!isDialable(cb)) {
911- ib--;
912- skipCmp = true;
913- numNonDialableCharsInB++;
914- }
915-
916- if (!skipCmp) {
917- if (cb != ca && ca != 'N' && cb != 'N') {
918- break;
919- }
920- ia--; ib--; matched++;
921- }
922- }
923-
924- if (matched < 7) {
925- int effectiveALen = a.length() - numNonDialableCharsInA;
926- int effectiveBLen = b.length() - numNonDialableCharsInB;
927-
928-
929- // if the number of dialable chars in a and b match, but the matched chars < MIN_MATCH,
930- // treat them as equal (i.e. 404-04 and 40404)
931- if (effectiveALen == effectiveBLen && effectiveALen == matched) {
932- return true;
933- }
934-
935- return false;
936- }
937-
938- // At least one string has matched completely;
939- if (matched >= 7 && (ia < 0 || ib < 0)) {
940- return true;
941- }
942-
943- /*
944- * Now, what remains must be one of the following for a
945- * match:
946- *
947- * - a '+' on one and a '00' or a '011' on the other
948- * - a '0' on one and a (+,00)<country code> on the other
949- * (for this, a '0' and a '00' prefix would have succeeded above)
950- */
951-
952- if (matchIntlPrefix(a, ia + 1)
953- && matchIntlPrefix (b, ib +1)
954- ) {
955- return true;
956- }
957-
958- if (matchTrunkPrefix(a, ia + 1)
959- && matchIntlPrefixAndCC(b, ib +1)
960- ) {
961- return true;
962- }
963-
964- if (matchTrunkPrefix(b, ib + 1)
965- && matchIntlPrefixAndCC(a, ia +1)
966- ) {
967- return true;
968- }
969-
970- return false;
971-}
972-
973-}
974-
975-#endif
976
977=== modified file 'phoneutils.cpp'
978--- phoneutils.cpp 2015-06-17 20:19:50 +0000
979+++ phoneutils.cpp 2015-08-07 19:10:15 +0000
980@@ -1,8 +1,9 @@
981 /*
982- * Copyright (C) 2012-2013 Canonical, Ltd.
983+ * Copyright (C) 2012-2015 Canonical, Ltd.
984 *
985 * Authors:
986 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
987+ * Renato Araujo Oliveira Filho <renato.filho@canonical.com>
988 * Tiago Salem Herrmann <tiago.herrmann@canonical.com>
989 *
990 * This file is part of telepathy-ofono.
991@@ -20,46 +21,114 @@
992 * along with this program. If not, see <http://www.gnu.org/licenses/>.
993 */
994
995-#include <QRegExp>
996 #include "phoneutils_p.h"
997-#include "phonenumberutils_p.h"
998-
999-PhoneUtils::PhoneUtils(QObject *parent) :
1000- QObject(parent)
1001-{
1002-}
1003-
1004-bool PhoneUtils::comparePhoneNumbers(const QString &number1, const QString &number2)
1005-{
1006- if (isPhoneNumber(number1) && isPhoneNumber(number2)) {
1007- return PhoneNumberUtils::compareLoosely(number1, number2);
1008- }
1009- return number1 == number2;
1010-}
1011-
1012-bool PhoneUtils::isPhoneNumber(const QString &identifier) {
1013- // remove all non diable digits
1014- QString finalNumber = QString(identifier).replace(QRegExp("[p+*#/(),;-]"),"");
1015- finalNumber = finalNumber.replace(QRegExp("(\\s+)"), "");
1016- // if empty, the number is invalid
1017- if (finalNumber.isEmpty())
1018- return false;
1019-
1020- finalNumber = finalNumber.replace(QRegExp("(\\d+)"), "");
1021- return finalNumber.isEmpty();
1022-}
1023-
1024-// TODO improve this normalization algorithm. More complex numbers
1025-// like "+1 234 234-1234 w 12345678#" should be normalizd to "+12342341234"
1026-QString PhoneUtils::normalizePhoneNumber(const QString &identifier) {
1027- if (!isPhoneNumber(identifier)) {
1028- // do not normalize non phone numbers
1029- return identifier;
1030- }
1031- QRegExp regexp = QRegExp("(\\s+)");
1032- QString finalNumber = QString(identifier).replace(regexp,"");
1033- finalNumber = finalNumber.replace(QRegExp("[()/-]"),"");
1034- return finalNumber;
1035-}
1036-
1037-
1038+
1039+
1040+#include <phonenumbers/phonenumbermatch.h>
1041+#include <phonenumbers/phonenumbermatcher.h>
1042+#include <phonenumbers/phonenumberutil.h>
1043+
1044+#include <QLocale>
1045+#include <QDebug>
1046+#include <QTextStream>
1047+#include <QFile>
1048+
1049+QString PhoneUtils::mMcc = QString();
1050+
1051+void PhoneUtils::setMcc(const QString &mcc)
1052+{
1053+ mMcc = mcc;
1054+}
1055+
1056+QString PhoneUtils::countryCodeForMCC(const QString &mcc, bool useFallback)
1057+{
1058+ static QMap<QString, QString> countryCodes;
1059+ if (countryCodes.isEmpty()) {
1060+ QFile countryCodesFile(":/countrycodes.txt");
1061+ if (!countryCodesFile.open(QFile::ReadOnly)) {
1062+ qCritical() << "Failed to open " << countryCodesFile.fileName();
1063+ if (useFallback) {
1064+ return region();
1065+ }
1066+ return QString();
1067+ }
1068+ QTextStream stream(&countryCodesFile);
1069+ while (!stream.atEnd()) {
1070+ QString line = stream.readLine();
1071+ QStringList tuple = line.split(":");
1072+ if (tuple.size() != 2) {
1073+ qCritical() << "Failed to parse line" << line;
1074+ if (useFallback) {
1075+ return region();
1076+ }
1077+ return QString();
1078+ }
1079+ countryCodes[tuple[0]] = tuple[1];
1080+ }
1081+ }
1082+ if (!countryCodes.contains(mcc) && useFallback) {
1083+ return region();
1084+ }
1085+ return countryCodes[mcc];
1086+}
1087+
1088+QString PhoneUtils::region()
1089+{
1090+ QString countryCode = QLocale::system().name().split("_").last();
1091+ if (countryCode.size() < 2) {
1092+ // fallback to US if no valid country code was provided, otherwise libphonenumber
1093+ // will fail to parse any numbers
1094+ return QString("US");
1095+ }
1096+ return countryCode;
1097+}
1098+
1099+QString PhoneUtils::normalizePhoneNumber(const QString &phoneNumber)
1100+{
1101+ static i18n::phonenumbers::PhoneNumberUtil *phonenumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
1102+ if (!isPhoneNumber(phoneNumber)) {
1103+ return phoneNumber;
1104+ }
1105+ std::string number = phoneNumber.toStdString();
1106+ phonenumberUtil->NormalizeDiallableCharsOnly(&number);
1107+ return QString::fromStdString(number);
1108+}
1109+
1110+bool PhoneUtils::comparePhoneNumbers(const QString &phoneNumberA, const QString &phoneNumberB)
1111+{
1112+ static i18n::phonenumbers::PhoneNumberUtil *phonenumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
1113+ // if any of the number isn't a phone number, just do a simple string comparison
1114+ if (!isPhoneNumber(phoneNumberA) || !isPhoneNumber(phoneNumberB)) {
1115+ return phoneNumberA == phoneNumberB;
1116+ }
1117+ i18n::phonenumbers::PhoneNumberUtil::MatchType match = phonenumberUtil->
1118+ IsNumberMatchWithTwoStrings(phoneNumberA.toStdString(),
1119+ phoneNumberB.toStdString());
1120+ return (match > i18n::phonenumbers::PhoneNumberUtil::NO_MATCH);
1121+}
1122+
1123+bool PhoneUtils::isPhoneNumber(const QString &phoneNumber)
1124+{
1125+ static i18n::phonenumbers::PhoneNumberUtil *phonenumberUtil = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
1126+ std::string formattedNumber;
1127+ i18n::phonenumbers::PhoneNumber number;
1128+ i18n::phonenumbers::PhoneNumberUtil::ErrorType error;
1129+ error = phonenumberUtil->Parse(phoneNumber.toStdString(), countryCodeForMCC(mMcc, true).toStdString(), &number);
1130+
1131+ switch(error) {
1132+ case i18n::phonenumbers::PhoneNumberUtil::INVALID_COUNTRY_CODE_ERROR:
1133+ qWarning() << "Invalid country code for:" << phoneNumber;
1134+ return false;
1135+ case i18n::phonenumbers::PhoneNumberUtil::NOT_A_NUMBER:
1136+ qWarning() << "The phone number is not a valid number:" << phoneNumber;
1137+ return false;
1138+ case i18n::phonenumbers::PhoneNumberUtil::TOO_SHORT_AFTER_IDD:
1139+ case i18n::phonenumbers::PhoneNumberUtil::TOO_SHORT_NSN:
1140+ case i18n::phonenumbers::PhoneNumberUtil::TOO_LONG_NSN:
1141+ qWarning() << "Invalid phone number" << phoneNumber;
1142+ return false;
1143+ default:
1144+ break;
1145+ }
1146+ return true;
1147+}
1148
1149=== added file 'phoneutils_p.h'
1150--- phoneutils_p.h 1970-01-01 00:00:00 +0000
1151+++ phoneutils_p.h 2015-08-07 19:10:15 +0000
1152@@ -0,0 +1,51 @@
1153+/*
1154+ * Copyright (C) 2015 Canonical, Ltd.
1155+ *
1156+ * Authors:
1157+ * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
1158+ * Renato Araujo Oliveira Filho <renato.filho@canonical.com>
1159+ * Tiago Salem Herrmann <tiago.herrmann@canonical.com>
1160+ *
1161+ * This file is part of telepathy-ofono.
1162+ *
1163+ * telepathy-ofono is free software; you can redistribute it and/or modify
1164+ * it under the terms of the GNU General Public License as published by
1165+ * the Free Software Foundation; version 3.
1166+ *
1167+ * telepathy-ofono is distributed in the hope that it will be useful,
1168+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1169+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1170+ * GNU General Public License for more details.
1171+ *
1172+ * You should have received a copy of the GNU General Public License
1173+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1174+ */
1175+
1176+#ifndef TELEPHONY_PHONEUTILS_H
1177+#define TELEPHONY_PHONEUTILS_H
1178+
1179+#include <QtCore/QObject>
1180+
1181+class PhoneUtils : public QObject
1182+{
1183+ Q_OBJECT
1184+public:
1185+ enum PhoneNumberFormat {
1186+ E164 = 0,
1187+ International,
1188+ National,
1189+ RFC3966,
1190+ Auto
1191+ };
1192+
1193+ static QString normalizePhoneNumber(const QString &phoneNumber);
1194+ static bool comparePhoneNumbers(const QString &phoneNumberA,const QString &phoneNumberB);
1195+ static bool isPhoneNumber(const QString &identifier);
1196+ static QString countryCodeForMCC(const QString &mcc, bool useFallback = true);
1197+ static void setMcc(const QString &mcc);
1198+private:
1199+ static QString region();
1200+ static QString mMcc;
1201+};
1202+
1203+#endif
1204
1205=== removed file 'phoneutils_p.h'
1206--- phoneutils_p.h 2013-11-11 15:10:00 +0000
1207+++ phoneutils_p.h 1970-01-01 00:00:00 +0000
1208@@ -1,38 +0,0 @@
1209-/*
1210- * Copyright (C) 2012 Canonical, Ltd.
1211- *
1212- * Authors:
1213- * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
1214- * Tiago Salem Herrmann <tiago.herrmann@canonical.com>
1215- *
1216- * This file is part of telepathy-ofono.
1217- *
1218- * telepathy-ofono is free software; you can redistribute it and/or modify
1219- * it under the terms of the GNU General Public License as published by
1220- * the Free Software Foundation; version 3.
1221- *
1222- * telepathy-ofono is distributed in the hope that it will be useful,
1223- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1224- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1225- * GNU General Public License for more details.
1226- *
1227- * You should have received a copy of the GNU General Public License
1228- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1229- */
1230-
1231-#ifndef PHONEUTILS_H
1232-#define PHONEUTILS_H
1233-
1234-#include <QObject>
1235-
1236-class PhoneUtils : public QObject
1237-{
1238- Q_OBJECT
1239-public:
1240- explicit PhoneUtils(QObject *parent = 0);
1241- Q_INVOKABLE static bool comparePhoneNumbers(const QString &number1, const QString &number2);
1242- Q_INVOKABLE static bool isPhoneNumber(const QString &identifier);
1243- Q_INVOKABLE static QString normalizePhoneNumber(const QString &identifier);
1244-};
1245-
1246-#endif // PHONEUTILS_H
1247
1248=== modified file 'tests/CMakeLists.txt'
1249--- tests/CMakeLists.txt 2014-02-24 16:31:18 +0000
1250+++ tests/CMakeLists.txt 2015-08-07 19:10:15 +0000
1251@@ -26,12 +26,14 @@
1252 XDG_DATA_DIRS=${TMPDIR};
1253 MC_ACCOUNT_DIR=${TMPDIR};
1254 MC_MANAGER_DIR=${TMPDIR};
1255+ MC_CLIENTS_DIR=${TMPDIR};
1256 PA_DISABLED=1")
1257 set_tests_properties(${TESTNAME} PROPERTIES
1258 ENVIRONMENT "${TEST_ENVIRONMENT}"
1259 TIMEOUT 30)
1260 target_link_libraries(${TESTNAME}
1261 ${TP_QT5_LIBRARIES}
1262+ ${LibPhoneNumber_LIBRARIES}
1263 )
1264 endmacro(generate_test)
1265
1266
1267=== modified file 'tests/PhoneUtilsTest.cpp'
1268--- tests/PhoneUtilsTest.cpp 2013-12-04 14:31:39 +0000
1269+++ tests/PhoneUtilsTest.cpp 2015-08-07 19:10:15 +0000
1270@@ -43,10 +43,12 @@
1271 QTest::newRow("number with dash") << "1234-5678" << true;
1272 QTest::newRow("number with area code") << "(123)12345678" << true;
1273 QTest::newRow("number with extension") << "12345678#123" << true;
1274- QTest::newRow("number with comma") << "33333333,1,1" << true;
1275- QTest::newRow("number with semicolon") << "33333333;1" << true;
1276+ QTest::newRow("number with comma") << "33333333,1,1" << false;
1277+ QTest::newRow("number with semicolon") << "33333333;1" << false;
1278 QTest::newRow("short/emergency number") << "190" << true;
1279 QTest::newRow("non phone numbers") << "abcdefg" << false;
1280+ QTest::newRow("phone number with dots") << "+31 (475) 12.34.56" << true;
1281+ QTest::newRow("number with slash") << "+421 2/123 456 78" << true;
1282 }
1283
1284 void PhoneUtilsTest::testIsPhoneNumber()
1285@@ -67,18 +69,16 @@
1286 QTest::newRow("string equal") << "12345678" << "12345678" << true;
1287 QTest::newRow("number with dash") << "1234-5678" << "12345678" << true;
1288 QTest::newRow("number with area code") << "12312345678" << "12345678" << true;
1289- QTest::newRow("number with extension") << "12345678#123" << "12345678" << false;
1290+ QTest::newRow("number with extension") << "12345678#123" << "12345678" << true;
1291 QTest::newRow("both numbers with extension") << "(123)12345678#1" << "12345678#1" << true;
1292 QTest::newRow("numbers with different extension") << "1234567#1" << "1234567#2" << false;
1293- QTest::newRow("number with comma") << "33333333,1,1" << "33333333" << true;
1294- QTest::newRow("both numbers with comma") << "22222222,1" << "22222222,2,1" << true;
1295- QTest::newRow("number with semicolon") << "33333333;1" << "33333333" << true;
1296- QTest::newRow("both numbers with semicolon") << "22222222;1" << "22222222;2" << true;
1297 QTest::newRow("short/emergency numbers") << "190" << "190" << true;
1298 QTest::newRow("different numbers") << "12345678" << "1234567" << false;
1299 QTest::newRow("both non phone numbers") << "abcdefg" << "abcdefg" << true;
1300 QTest::newRow("different non phone numbers") << "abcdefg" << "bcdefg" << false;
1301- QTest::newRow("phone number and custom string") << "abc12345678" << "12345678" << false;
1302+ QTest::newRow("phone number and custom string") << "abc12345678" << "12345678" << true;
1303+ QTest::newRow("phone number with dots") << "+31 (475) 12.34.56" << "+31 (475) 12 34 56" << true;
1304+ QTest::newRow("phone number with slash") << "+421 2/123 456 78" << "212345678" << true;
1305 // FIXME: check what other cases we need to test here"
1306 }
1307
1308
1309=== added directory 'tools'
1310=== added file 'tools/generate_country_codes.py'
1311--- tools/generate_country_codes.py 1970-01-01 00:00:00 +0000
1312+++ tools/generate_country_codes.py 2015-08-07 19:10:15 +0000
1313@@ -0,0 +1,23 @@
1314+# originally available at https://github.com/musalbas/mcc-mnc-table/blob/master/get-mcc-mnc-table-csv.py
1315+import re
1316+import urllib2
1317+
1318+html = urllib2.urlopen('http://mcc-mnc.com/').read()
1319+td_re = re.compile('<td>([^<]*)</td>'*6)
1320+codes = {}
1321+tbody_start = False
1322+for line in html.split('\n'):
1323+ if '<tbody>' in line:
1324+ tbody_start = True
1325+ elif '</tbody>' in line:
1326+ break
1327+ elif tbody_start:
1328+ td_search = td_re.search(line)
1329+ mcc = int(td_search.group(1))
1330+ isoCountryCode = td_search.group(3).upper()
1331+ if (len(isoCountryCode) != 2):
1332+ continue
1333+ codes[mcc] = isoCountryCode
1334+
1335+for mcc in codes:
1336+ print str(mcc) + ":" + codes[mcc]

Subscribers

People subscribed via source and target branches