* e_phone_number_get_country_code_for_region:
* @region_code: (allow-none): a two-letter country code, a locale name, or
* %NULL
+ * @error: (out): a #GError to set an error, if any
*
* Retrieves the preferred country calling code for @region_code,
* e.g. 358 for "fi" or 1 for "en_US@UTF-8".
* Since: 3.8
*/
gint
-e_phone_number_get_country_code_for_region (const gchar *region_code)
+e_phone_number_get_country_code_for_region (const gchar *region_code,
+ GError **error)
{
#ifdef ENABLE_PHONENUMBER
#else /* ENABLE_PHONENUMBER */
- g_warning ("%s: The library was built without phone number support.", G_STRFUNC);
+ _e_phone_number_set_error (error, E_PHONE_NUMBER_ERROR_NOT_IMPLEMENTED);
return 0;
#endif /* ENABLE_PHONENUMBER */
/**
* e_phone_number_get_default_region:
+ * @error: (out): a #GError to set an error, if any
*
* Retrieves the current two-letter country code that's used by default for
* parsing phone numbers in e_phone_number_from_string(). It can be useful
* Since: 3.8
*/
gchar *
-e_phone_number_get_default_region (void)
+e_phone_number_get_default_region (GError **error)
{
#ifdef ENABLE_PHONENUMBER
#else /* ENABLE_PHONENUMBER */
- g_warning ("%s: The library was built without phone number support.", G_STRFUNC);
+ _e_phone_number_set_error (error, E_PHONE_NUMBER_ERROR_NOT_IMPLEMENTED);
return NULL;
#endif /* ENABLE_PHONENUMBER */
#else /* ENABLE_PHONENUMBER */
+ /* The EPhoneNumber instance must be invalid. We'd also bail out with
+ * a warning if phone numbers are supported. Any code triggering this
+ * is broken and should be fixed. */
g_warning ("%s: The library was built without phone number support.", G_STRFUNC);
return NULL;
#else /* ENABLE_PHONENUMBER */
+ /* The EPhoneNumber instance must be invalid. We'd also bail out with
+ * a warning if phone numbers are supported. Any code triggering this
+ * is broken and should be fixed. */
g_warning ("%s: The library was built without phone number support.", G_STRFUNC);
return 0;
#else /* ENABLE_PHONENUMBER */
+ /* The EPhoneNumber instance must be invalid. We'd also bail out with
+ * a warning if phone numbers are supported. Any code triggering this
+ * is broken and should be fixed. */
g_warning ("%s: The library was built without phone number support.", G_STRFUNC);
return NULL;
#else /* ENABLE_PHONENUMBER */
- /* NOTE: This calls for a dedicated return value, but I sense broken
- * client code that only checks for E_PHONE_NUMBER_MATCH_NONE and then
- * treats the "not-implemented" return value as a match */
+ /* The EPhoneNumber instance must be invalid. We'd also bail out with
+ * a warning if phone numbers are supported. Any code triggering this
+ * is broken and should be fixed. */
g_warning ("%s: The library was built without phone number support.", G_STRFUNC);
return E_PHONE_NUMBER_MATCH_NONE;
gboolean e_phone_number_is_supported (void) G_GNUC_CONST;
gint e_phone_number_get_country_code_for_region
- (const gchar *region_code);
+ (const gchar *region_code,
+ GError **error);
gchar * e_phone_number_get_default_region
- (void);
+ (GError **error);
EPhoneNumber * e_phone_number_from_string (const gchar *phone_number,
const gchar *region_code,
db, name, SQLITE_UTF8, GINT_TO_POINTER (country_code),
ixphone_compare_for_country);
} else if (strcmp (name, "ixphone_national") == 0) {
- country_code = e_phone_number_get_country_code_for_region (NULL);
+ country_code = e_phone_number_get_country_code_for_region (NULL, NULL);
ret = sqlite3_create_collation_v2 (
db, name, SQLITE_UTF8,
return FALSE;
}
- if (e_phone_number_is_supported ())
- default_region = e_phone_number_get_default_region ();
+ if (e_phone_number_is_supported ()) {
+ default_region = e_phone_number_get_default_region (error);
+
+ if (default_region == NULL)
+ success = FALSE;
+ }
for (l = contacts; success && l != NULL; l = g_slist_next (l)) {
EContact *contact = (EContact *) l->data;
* o Normalize the string
* o Check the E.164 column instead
*/
- const gint country_code = e_phone_number_get_country_code_for_region (region);
+ const gint country_code = e_phone_number_get_country_code_for_region (region, NULL);
if (ebsdb->priv->summary_fields[summary_index].type == E_TYPE_CONTACT_ATTR_LIST) {
field_name = g_strdup ("multi.value_phone");
if (e_phone_number_is_supported ()) {
g_message ("The phone number indexes' format has changed. Rebuilding them.");
- default_region = e_phone_number_get_default_region ();
+ default_region = e_phone_number_get_default_region (error);
+
+ if (default_region == NULL)
+ success = FALSE;
}
for (l = vcard_data; success && l; l = l->next) {
static void
test_country_code_for_region (void)
{
+ GError *error = NULL;
+ gint code;
+
g_assert_cmpstr (setlocale (LC_ADDRESS, NULL), ==, "en_US.UTF-8");
- g_assert_cmpint (e_phone_number_get_country_code_for_region ("CH"), ==, 41);
- g_assert_cmpint (e_phone_number_get_country_code_for_region (NULL), ==, 1);
- g_assert_cmpint (e_phone_number_get_country_code_for_region ("C"), ==, 0);
- g_assert_cmpint (e_phone_number_get_country_code_for_region (""), ==, 1);
+
+#ifdef ENABLE_PHONENUMBER
+
+ code = e_phone_number_get_country_code_for_region ("CH", &error);
+ g_assert_cmpstr (error ? error->message : NULL, ==, NULL);
+ g_assert_cmpint (code, ==, 41);
+
+ code = e_phone_number_get_country_code_for_region (NULL, &error);
+ g_assert_cmpstr (error ? error->message : NULL, ==, NULL);
+ g_assert_cmpint (code, ==, 1);
+
+ code = e_phone_number_get_country_code_for_region ("C", &error);
+ g_assert_cmpstr (error ? error->message : NULL, ==, NULL);
+ g_assert_cmpint (code, ==, 0);
+
+ code = e_phone_number_get_country_code_for_region ("", &error);
+ g_assert_cmpstr (error ? error->message : NULL, ==, NULL);
+ g_assert_cmpint (code, ==, 1);
+
+#else /* ENABLE_PHONENUMBER */
+
+ code = e_phone_number_get_country_code_for_region ("CH", &error);
+
+ g_assert (error != NULL);
+ g_assert (error->domain == E_PHONE_NUMBER_ERROR);
+ g_assert (error->code == E_PHONE_NUMBER_ERROR_NOT_IMPLEMENTED);
+ g_assert (error->message != NULL);
+ g_assert_cmpint (code, ==, 0);
+
+#endif /* ENABLE_PHONENUMBER */
}
static void
test_default_region (void)
{
+ GError *error = NULL;
gchar *country;
g_assert_cmpstr (setlocale (LC_ADDRESS, NULL), ==, "en_US.UTF-8");
+ country = e_phone_number_get_default_region (&error);
+
+#ifdef ENABLE_PHONENUMBER
- country = e_phone_number_get_default_region ();
+ g_assert_cmpstr (error ? error->message : NULL, ==, NULL);
g_assert_cmpstr (country, ==, "US");
+
+#else /* ENABLE_PHONENUMBER */
+
+ g_assert (error != NULL);
+ g_assert (error->domain == E_PHONE_NUMBER_ERROR);
+ g_assert (error->code == E_PHONE_NUMBER_ERROR_NOT_IMPLEMENTED);
+ g_assert (error->message != NULL);
+ g_assert_cmpstr (country, ==, NULL);
+
+#endif /* ENABLE_PHONENUMBER */
+
g_free (country);
}