<li><a href="#pl_get">Getting Logs</a></li>\r
<li><a href="#pl_delete">Deleting a Log</a></li>\r
</ul>\r
- </li> \r
+ </li>\r
<li>Records\r
<ul class="toc">\r
<li><a href="#insert2">Inserting New Records</a></li>\r
<li><a href="#import">Importing from vCard</a></li>\r
<li><a href="#export">Exporting to vCard</a></li>\r
</ul></li>\r
- </ul> \r
+ </ul>\r
<p class="toc-title">Related Info</p>\r
<ul class="toc">\r
<li><a href="../../../../org.tizen.guides/html/native/social/contact_n.htm">Contacts Guide</a></li>\r
\r
<h1>Contacts: Managing Contacts and Groups, and Accessing the Contact Database</h1>\r
\r
- \r
+\r
<p>This tutorial demonstrates how you can manage contacts and groups, and import them to or export them from the vCard format.</p>\r
\r
<p>This feature is supported in mobile applications only.</p>\r
<li><a href="#parse">Parsing a vCard</a>\r
<p>Parse a vCard from a file and insert to the database.</p></li>\r
</ul></li>\r
- <li>Speed dials \r
+ <li>Speed dials\r
<ul>\r
<li><a href="#sd_create">Creating a Speed Dial</a>\r
<p>Create a new speed dial.</p></li>\r
<li><a href="#sd_delete">Deleting a Speed Dial</a>\r
<p>Delete the speed dial from the database.</p></li>\r
</ul></li>\r
- <li>Phone logs \r
+ <li>Phone logs\r
<ul>\r
<li><a href="#pl_create">Creating a Log</a>\r
<p>Create a new log.</p></li>\r
<p>Retrieve single log or a list of logs.</p></li>\r
<li><a href="#pl_delete">Deleting a Log</a>\r
<p>Delete the log from the database.</p></li>\r
- </ul> \r
+ </ul>\r
</li></ul>\r
- <h2>Follow-up</h2> \r
+ <h2>Follow-up</h2>\r
<p>Once we have learned the basics of the Contacts API, we can now move on to more advanced tasks, including:</p>\r
<ul>\r
<li>Records\r
<li>Contact settings\r
<ul>\r
<li><a href="#settings">Managing Contact Settings</a>\r
- <p>Change the display settings of contacts.</p></li> \r
+ <p>Change the display settings of contacts.</p></li>\r
<li><a href="#sim">Managing Contacts on the SIM Card</a>\r
<p>Check that the SIM card is initialized and import contacts from the SIM card.</p></li>\r
</ul></li>\r
<p>Export contacts to vCard files.</p></li>\r
</ul></li>\r
</ul>\r
- \r
+\r
\r
<h2 id="init" name="init">Initializing Contacts</h2>\r
\r
<p>To start with the Contact Service:</p>\r
-<ol><li> \r
+<ol><li>\r
<p>To use the functions and data types of the <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__MODULE.html">Contacts</a> API, include the <span style="font-family: Courier New,Courier,monospace"><contacts.h></span> header file in your application:</p>\r
<pre class="prettyprint">\r
#include <contacts.h>\r
-</pre></li> \r
+</pre></li>\r
<li>Most of the API functions return error codes, therefore define at the beginning of your code the <span style="font-family: Courier New,Courier,monospace">int</span> type, which is used to store error codes. Each time when a function returns error codes, verify the result of the operation.</li>\r
<li><p>Call the <span style="font-family: Courier New,Courier,monospace">contacts_connect()</span> function, which connects your application with the Contact Service. Without this function, you cannot get access to the contacts database.</p>\r
<pre class="prettyprint">int error_code;\r
</pre></li>\r
<li><p id="iterate_c" name="iterate_c">Iterate the list and read the records:</p>\r
\r
- <table class="note"> \r
- <tbody> \r
- <tr> \r
- <th class="note">Note</th> \r
- </tr> \r
- <tr> \r
- <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td> \r
- </tr> \r
- </tbody> \r
- </table> \r
-\r
-<ol type="a"><li><p>To get the records from the list, use the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, and <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span> or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> functions. Get the details of each record in the loop.</p> \r
- \r
+ <table class="note">\r
+ <tbody>\r
+ <tr>\r
+ <th class="note">Note</th>\r
+ </tr>\r
+ <tr>\r
+ <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
+\r
+<ol type="a"><li><p>To get the records from the list, use the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, and <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span> or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> functions. Get the details of each record in the loop.</p>\r
+\r
<pre class="prettyprint">contacts_record_h record;\r
while (contacts_list_get_current_record_p(list, &record) == CONTACTS_ERROR_NONE)\r
{\r
}</pre></li>\r
<li>The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial:\r
<pre class="prettyprint">\r
-typedef struct \r
+typedef struct\r
_contacts_gl_person_data\r
{\r
int id;\r
contacts_list_h associated_contacts;\r
} contacts_gl_person_data_t;\r
\r
-static void \r
+static void\r
_free_gl_person_data(contacts_gl_person_data_t *gl_person_data)\r
{\r
if (NULL == gl_person_data)\r
free(gl_person_data);\r
}\r
\r
-static contacts_gl_person_data_t* \r
+static contacts_gl_person_data_t*\r
_create_gl_person_data(contacts_record_h record)\r
{\r
contacts_gl_person_data_t *gl_person_data;\r
<li>Get the display name.\r
<p>Assuming that you have the person record handle (<span style="font-family: Courier New,Courier,monospace">contacts_record_h</span>), you can access the <span style="font-family: Courier New,Courier,monospace">display_name</span> property. You can read the display name property and print it.</p>\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_display_name(contacts_record_h record, char **display_name)\r
{\r
int error_code;\r
}</pre></li>\r
<li>Get associated contacts of a person by query:\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_associated_contacts(contacts_record_h record, contacts_list_h *associated_contacts)\r
{\r
int error_code;\r
}</pre></li>\r
<li>Get phone numbers by iterating the contacts list. The following example shows how to get all the number records and print them.\r
<pre class="prettyprint">\r
-static void \r
+static void\r
_print_phone_numbers(contacts_list_h associated_contacts)\r
{\r
int error_code;\r
contacts_record_h contact;\r
- if (NULL == associated_contacts) \r
+ if (NULL == associated_contacts)\r
{\r
dlog_print(DLOG_ERROR, LOG_TAG, "associated_contacts is NULL");\r
\r
unsigned int count = 0;\r
\r
error_code = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);\r
- if (CONTACTS_ERROR_NONE != error_code) \r
+ if (CONTACTS_ERROR_NONE != error_code)\r
{\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts_record_get_child_record_count(%d)", error_code);\r
\r
<li>Get the default phone number.\r
<p>If a contact has multiple phone numbers, one of them is defined as the default phone number. A person also has a default phone number. The Contact Service provides the <span style="font-family: Courier New,Courier,monospace">_contacts_person_number</span> view for getting the default phone number of a person. In the default phone number record, the <span style="font-family: Courier New,Courier,monospace">is_primary_default</span> property value is <span style="font-family: Courier New,Courier,monospace">true</span>. The following example shows how to get the default phone number of a person by query.</p>\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_default_phone_number(contacts_record_h record, char **default_phone_number)\r
{\r
contacts_query_h query = NULL;\r
}</pre></li>\r
<li>Get events by iterating the contacts list:\r
<pre class="prettyprint">\r
-static void \r
+static void\r
_print_events(contacts_list_h associated_contacts)\r
{\r
int error_code;\r
contacts_record_h contact;\r
- if (NULL == associated_contacts) \r
+ if (NULL == associated_contacts)\r
{\r
dlog_print(DLOG_ERROR, LOG_TAG, "associated_contacts is NULL");\r
\r
unsigned int count = 0;\r
\r
error_code = contacts_record_get_child_record_count(contact, _contacts_contact.event, &count);\r
- if (CONTACTS_ERROR_NONE != error_code) \r
+ if (CONTACTS_ERROR_NONE != error_code)\r
{\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts_record_get_child_record_count(%d)", error_code);\r
\r
<p>The callback function is called when the person data changes. The following example shows how to update person details in the callback function.</p>\r
<pre class="prettyprint">\r
static contacts_gl_person_data_t *_gl_person_data = ...\r
-void \r
+void\r
_person_changed_callback(const char *view_uri, void *user_data)\r
{\r
int error_code;\r
\r
<li>To iterate the list and read the records:\r
\r
- <table class="note"> \r
- <tbody> \r
- <tr> \r
- <th class="note">Note</th> \r
- </tr> \r
- <tr> \r
- <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td> \r
- </tr> \r
- </tbody> \r
- </table> \r
+ <table class="note">\r
+ <tbody>\r
+ <tr>\r
+ <th class="note">Note</th>\r
+ </tr>\r
+ <tr>\r
+ <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
<ol type="a">\r
<li>\r
<p>To get the records from the list, use the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, and <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span> or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> functions. The following example gets the details of each record in the loop.</p>\r
</li>\r
<li>The memory for the record data is allocated, and the data is copied from the record by the functions listed in the following example:\r
<pre class="prettyprint">\r
-typedef struct \r
+typedef struct\r
_contacts_gl_group_data\r
{\r
int id;\r
char *ringtone_path;\r
} contacts_gl_group_data_t;\r
\r
-static void \r
+static void\r
_free_gl_group_data(contacts_gl_group_data_t *gl_group_data)\r
{\r
if (NULL == gl_group_data)\r
free(gl_group_data);\r
}\r
\r
-static contacts_gl_group_data_t* \r
+static contacts_gl_group_data_t*\r
_create_gl_group_data(contacts_record_h record)\r
{\r
contacts_gl_group_data_t *gl_group_data;\r
</ol></li>\r
<li>To iterate the list and read the records:\r
\r
- <table class="note"> \r
- <tbody> \r
- <tr> \r
- <th class="note">Note</th> \r
- </tr> \r
- <tr> \r
- <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td> \r
- </tr> \r
- </tbody> \r
- </table> \r
+ <table class="note">\r
+ <tbody>\r
+ <tr>\r
+ <th class="note">Note</th>\r
+ </tr>\r
+ <tr>\r
+ <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
\r
<ol type="a"><li><p>To get the records from the list, use the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, and <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span> or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> functions. Get the details of each record in the loop.</p>\r
\r
}</pre></li>\r
<li><p>The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial:</p>\r
<pre class="prettyprint">\r
-typedef struct \r
+typedef struct\r
_contacts_gl_group_data\r
{\r
int id;\r
char *ringtone_path;\r
} contacts_gl_group_data_t;\r
\r
-static void \r
+static void\r
_free_gl_group_data(contacts_gl_group_data_t *gl_group_data)\r
{\r
if (NULL == gl_group_data)\r
free(gl_group_data);\r
}\r
\r
-static contacts_gl_group_data_t* \r
+static contacts_gl_group_data_t*\r
_create_gl_group_data(contacts_record_h record)\r
{\r
contacts_gl_group_data_t *gl_group_data;\r
</pre></li>\r
<li>Define the callback function to be called when the group data changes:\r
<pre class="prettyprint">static contacts_gl_group_data_t *_gl_group_data = ...\r
-static void \r
+static void\r
_group_changed_callback(const char *view_uri, void *user_data)\r
{\r
int error_code;\r
\r
<p>The vCard stream contains multiple contact objects. The callback function is called after parsing each contact. If you return <span style="font-family: Courier New,Courier,monospace">false</span> on the callback function, parsing stops.</p>\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_vcard_parse_cb(contacts_record_h contact, void *user_data)\r
{\r
if (NULL == contact)\r
</pre>\r
</li>\r
</ol>\r
- \r
+\r
<h2 id="sd_insert" name="sd_insert">Inserting a Speed Dial to the Database</h2>\r
\r
<p>To insert a speed dial record:</p>\r
<pre class="prettyprint">\r
int added_speeddial_id = -1;\r
\r
-error_code = contacts_db_insert_record(speeddial, &added_speeddial_id); \r
+error_code = contacts_db_insert_record(speeddial, &added_speeddial_id);\r
</pre>\r
</li>\r
\r
</li>\r
\r
<li>To iterate the list and read the records, you can get the records from the list using the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span>, or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> function. Get the details of each record in the loop.\r
- \r
- <table class="note"> \r
- <tbody> \r
- <tr> \r
- <th class="note">Note</th> \r
- </tr> \r
- <tr> \r
- <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td> \r
- </tr> \r
- </tbody> \r
- </table> \r
- \r
+\r
+ <table class="note">\r
+ <tbody>\r
+ <tr>\r
+ <th class="note">Note</th>\r
+ </tr>\r
+ <tr>\r
+ <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
+\r
\r
<pre class="prettyprint">\r
contacts_record_h record;\r
<p>The memory for the record data is allocated, and the data is copied from the record by the functions shown in the following example:</p>\r
\r
<pre class="prettyprint">\r
-typedef struct \r
+typedef struct\r
_contacts_gl_speeddial_data\r
{\r
int speeddial_number;\r
char *image_thumbnail_path;\r
} contacts_gl_speeddial_data_t;\r
\r
-static void \r
+static void\r
_free_gl_speeddial_data(contacts_gl_speeddial_data_t *gl_speeddial_data)\r
{\r
if (NULL == gl_speeddial_data)\r
free(gl_speeddial_data);\r
}\r
\r
-static contacts_gl_speeddial_data_t* \r
+static contacts_gl_speeddial_data_t*\r
_create_gl_speeddial_data(contacts_record_h record)\r
{\r
contacts_gl_speeddial_data_t *gl_speeddial_data;\r
</pre>\r
</li>\r
\r
- <li>Connect the query with the list: \r
+ <li>Connect the query with the list:\r
<pre class="prettyprint">\r
error_code = contacts_query_set_filter(query, filter);\r
\r
<p>The third parameter refers to the limit of the results. If 0 is passed, there are no limits. Remember that after all operations, the list must be released.</p>\r
</li>\r
\r
-<li>Free the filter and query: \r
+<li>Free the filter and query:\r
<pre class="prettyprint">\r
contacts_filter_destroy(filter);\r
contacts_query_destroy(query);\r
\r
<li>To iterate the list and read the records, you can get the records from the list using the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span>, or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> function. Get the details of each record in the loop.\r
\r
- <table class="note"> \r
- <tbody> \r
- <tr> \r
- <th class="note">Note</th> \r
- </tr> \r
- <tr> \r
- <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td> \r
- </tr> \r
- </tbody> \r
- </table> \r
+ <table class="note">\r
+ <tbody>\r
+ <tr>\r
+ <th class="note">Note</th>\r
+ </tr>\r
+ <tr>\r
+ <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
\r
<pre class="prettyprint">\r
contacts_record_h record;\r
</pre>\r
<p>The memory for the record data is allocated, and the data is copied from the record by the functions shown in the following example.</p>\r
<pre class="prettyprint">\r
-typedef struct \r
+typedef struct\r
_contacts_gl_speeddial_data\r
{\r
int speeddial_number;\r
char *image_thumbnail_path;\r
} contacts_gl_speeddial_data_t;\r
\r
-static void \r
+static void\r
_free_gl_speeddial_data(contacts_gl_speeddial_data_t *gl_speeddial_data)\r
{\r
if (NULL == gl_speeddial_data)\r
free(gl_speeddial_data);\r
}\r
\r
-static contacts_gl_speeddial_data_t* \r
+static contacts_gl_speeddial_data_t*\r
_create_gl_speeddial_data(contacts_record_h record)\r
{\r
contacts_gl_speeddial_data_t *gl_speeddial_data;\r
\r
<p>To change the number ID of an existing speed dial:</p>\r
<ol>\r
-<li>Get the speed dial. \r
+<li>Get the speed dial.\r
<p>To modify a record, you need to have a handle (<span style="font-family: Courier New,Courier,monospace">contacts_record_h</span> type variable) to a memory object representing the record in the database. One of the ways to acquire it is to use the speed dial number:</p>\r
<pre class="prettyprint">\r
int speeddial_number = ... // Acquire speed dial number\r
\r
error_code = contacts_db_delete_record(_contacts_speeddial._uri, speeddial_number);\r
</pre>\r
- \r
+\r
\r
<h2 id="pl_create" name="pl_create">Creating a Log</h2>\r
\r
\r
<p>To get all log records one by one, or to filter them by one of the properties:</p>\r
<ol>\r
-<li>Get a single log record: \r
+<li>Get a single log record:\r
<ol type="a"><li><p>Use the <span style="font-family: Courier New,Courier,monospace">contacts_db_get_record()</span> function with the appropriate <span style="font-family: Courier New,Courier,monospace">log_id</span>:</p>\r
<pre class="prettyprint">contacts_record_h log;\r
int log_id = ... // Acquire log ID\r
\r
<li>To iterate the list and read the records, you can get the records from the list using the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span>, or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> function. Get the details of each record in the loop.\r
\r
- <table class="note"> \r
- <tbody> \r
- <tr> \r
- <th class="note">Note</th> \r
- </tr> \r
- <tr> \r
- <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td> \r
- </tr> \r
- </tbody> \r
- </table> \r
+ <table class="note">\r
+ <tbody>\r
+ <tr>\r
+ <th class="note">Note</th>\r
+ </tr>\r
+ <tr>\r
+ <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
\r
\r
<pre class="prettyprint">\r
<p>The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial.</p>\r
\r
<pre class="prettyprint">\r
-typedef struct \r
+typedef struct\r
_contacts_gl_log_data\r
{\r
int id;\r
int log_time;\r
} contacts_gl_log_data_t;\r
\r
-static void \r
+static void\r
_free_gl_log_data(contacts_gl_log_data_t *gl_log_data)\r
{\r
if (NULL == gl_log_data)\r
free(gl_log_data);\r
}\r
\r
-static contacts_gl_log_data_t* \r
+static contacts_gl_log_data_t*\r
_create_gl_log_data(contacts_record_h record)\r
{\r
contacts_gl_log_data_t *gl_log_data;\r
return NULL;\r
}\r
if (CONTACTS_ERROR_NONE != contacts_record_get_str(record, _contacts_phone_log.address, &gl_log_data->address))\r
- { \r
+ {\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts record get string failed ");\r
_free_gl_log_data(gl_log_data);\r
\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts query create failed: %x", error_code);\r
</pre>\r
</li>\r
- \r
- <li>Before getting the logs, filter the list. There is a possibility to filter based on various parameters. To create a filter: \r
+\r
+ <li>Before getting the logs, filter the list. There is a possibility to filter based on various parameters. To create a filter:\r
<pre class="prettyprint">\r
contacts_filter_h filter = NULL;\r
\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts filter create failed: %x", error_code);\r
</pre>\r
</li>\r
- \r
+\r
<li>Add a condition, such as the log type.\r
<p>The following example retrieves only those logs which type is <span style="font-family: Courier New,Courier,monospace">CONTACTS_PLOG_TYPE_VOICE_INCOMING</span>.</p>\r
<pre class="prettyprint">\r
if (error_code != CONTACTS_ERROR_NONE)\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts filter add integer failed: %x", error_code);\r
</pre>\r
- \r
+\r
<p>To use multiple conditions, add an operator between them:</p>\r
<pre class="prettyprint">\r
error_code = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts filter add integer failed: %x", error_code);\r
</pre>\r
</li>\r
- \r
- <li>Connect the query with the list: \r
+\r
+ <li>Connect the query with the list:\r
<pre class="prettyprint">\r
error_code = contacts_query_set_filter(query, filter);\r
if (error_code != CONTACTS_ERROR_NONE)\r
</pre>\r
<p>The third parameter refers to the limit of the results. If 0 is passed, there are no limits. After all operations, release the list.</p>\r
</li>\r
- \r
- <li>Free the filter and query: \r
+\r
+ <li>Free the filter and query:\r
<pre class="prettyprint">\r
contacts_filter_destroy(filter);\r
contacts_query_destroy(query);\r
<li>To iterate the list and read the records, use the <span style="font-family: Courier New,Courier,monospace">contacts_list_get_current_record_p()</span>, <span style="font-family: Courier New,Courier,monospace">contacts_list_next()</span>, or <span style="font-family: Courier New,Courier,monospace">contacts_list_prev()</span> function. Get the details of each record in the loop.\r
\r
\r
- <table class="note"> \r
- <tbody> \r
- <tr> \r
- <th class="note">Note</th> \r
- </tr> \r
- <tr> \r
- <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td> \r
- </tr> \r
- </tbody> \r
- </table> \r
+ <table class="note">\r
+ <tbody>\r
+ <tr>\r
+ <th class="note">Note</th>\r
+ </tr>\r
+ <tr>\r
+ <td class="note">Some functions have the <span style="font-family: Courier New,Courier,monospace">_p</span> postfix. It means that the returned value must not be freed by the application, as it is a pointer to the data in an existing record.</td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
\r
<pre class="prettyprint">\r
contacts_record_h record;\r
</pre>\r
<p>The memory for the record data is allocated, and the data is copied from the record by the functions listed further on in this tutorial.</p>\r
<pre class="prettyprint">\r
-typedef struct \r
+typedef struct\r
_contacts_gl_log_data\r
{\r
int id;\r
int log_time;\r
} contacts_gl_log_data_t;\r
\r
-static void \r
+static void\r
_free_gl_log_data(contacts_gl_log_data_t *gl_log_data)\r
{\r
if (NULL == gl_log_data)\r
free(gl_log_data);\r
}\r
\r
-static contacts_gl_log_data_t* \r
+static contacts_gl_log_data_t*\r
_create_gl_log_data(contacts_record_h record)\r
{\r
contacts_gl_log_data_t *gl_log_data;\r
return NULL;\r
}\r
if (CONTACTS_ERROR_NONE != contacts_record_get_str(record, _contacts_phone_log.address, &gl_log_data->address))\r
- { \r
+ {\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts record get string failed ");\r
_free_gl_log_data(gl_log_data);\r
\r
contacts_record_h child_record;\r
contacts_record_get_child_record_at_p(record, _contacts_contact.name, 0, &child_record);\r
// In the child_record, you have the record form name view\r
-char *f_name;\r
-contacts_record_get_str(record, _contacts_name.first_name, f_name);\r
+char *f_name = NULL;\r
+contacts_record_get_str(child_record, _contacts_name.first_name, &f_name);\r
free(f_name);\r
</pre>\r
</li>\r
contacts_record_h parent_record;\r
int parent_id;\r
contacts_record_get_int(record, _contacts_name.contact_id, &parent_id);\r
-contacts_db_get_child_record(_contacts_contact._uri, parent_id, &parent_record);\r
+contacts_db_get_record(_contacts_contact._uri, parent_id, &parent_record);\r
// In the parent_record, get bool\r
bool h_email;\r
contacts_record_get_bool(parent_record, _contacts_contact.has_email, &h_email);\r
gldata = _create_gl_data(record);\r
char * number = gldata->number;\r
\r
-typedef struct \r
+typedef struct\r
_contact_gl_data\r
{\r
int id;\r
<ul><li><p>To get the name details, get the <span style="font-family: Courier New,Courier,monospace;">_contacts_contact.name</span> (representing the child) from the <span style="font-family: Courier New,Courier,monospace;">r_contact</span> parent. Both structures have the <span style="font-family: Courier New,Courier,monospace;">contacts_record_h</span> type. After obtaining a child record, get the desired data from it using the <span style="font-family: Courier New,Courier,monospace;">contacts_record_get_str()</span> function.</p>\r
\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_contact_last(contacts_record_h r_contact, char **last)\r
{\r
contacts_record_h r_name;\r
<li><p>Obtain the record ID directly from the parent record. An ID is a unique number representing the record key in the database. You can manipulate a record with functions, such as <span style="font-family: Courier New,Courier,monospace;">contacts_db_get_record()</span> or <span style="font-family: Courier New,Courier,monospace;">contacts_db_delete_records()</span>, if you know their ID.</p>\r
\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_contact_id(contacts_record_h r_contact, int *id)\r
{\r
int error_code;\r
<li><p>To get a contact number, check whether it exists using the <span style="font-family: Courier New,Courier,monospace;">contacts_record_get_bool()</span> function. If it exists, use the various <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__QUERY__MODULE.html">Query</a> and <a href="../../../../org.tizen.native.mobile.apireference/group__CAPI__SOCIAL__CONTACTS__SVC__FILTER__MODULE.html">Filter</a> functions from the Contacts API to make a query to get a list. At the end, free any data returned by a function not containing the <span style="font-family: Courier New,Courier,monospace;">_p</span> suffix.</p>\r
<ul><li>Get a list of all numbers and filter the list to get the default:\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_contact_number(contacts_record_h r_contact, char **number)\r
{\r
int id;\r
<li><p>Directly access the default number:</p>\r
\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_contact_number(contacts_record_h r_contact, char **number)\r
{\r
int error_code;\r
\r
return true;\r
}\r
+ int i;\r
+ unsigned int count = 0;\r
+ bool is_default = false;\r
+ error_code = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);\r
\r
- error_code = contacts_record_get_child_record_at_p(r_contact, _contacts_contact.number, 0, &r_number);\r
-\r
- error_code = contacts_record_get_str(r_number, _contacts_number.number, number);\r
+ for (i = 0; i < count; i++)\r
+ {\r
+ error_code = contacts_record_get_child_record_at_p(r_contact, _contacts_contact.number, i, &r_number);\r
+ error_code = contacts_record_get_bool(r_number, _contacts_number.is_default, &is_default);\r
+ if(is_default)\r
+ {\r
+ error_code = contacts_record_get_str(r_number, _contacts_number.number, number);\r
+ return true;\r
+ }\r
+ }\r
+ *number = NULL;\r
\r
- return true;\r
+ return false;\r
}\r
</pre>\r
<p>To get a second number, change the third parameter (<span style="font-family: Courier New,Courier,monospace;">contacts_record_get_child_record_at_p</span>) from 0 to 1.</p></li></ul></li>\r
<li><p>Obtain an image directly from the parent record:</p>\r
\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_contact_image(contacts_record_h r_contact, char **image_path)\r
{\r
int error_code;\r
<li><p>Get the first name as the last name:</p>\r
\r
<pre class="prettyprint">\r
-static bool \r
+static bool\r
_get_contact_first(contacts_record_h r_contact, char **first)\r
{\r
contacts_record_h r_name;\r
{\r
int record_id;\r
contacts_record_h c_record;\r
- contacts_record_get_int(record, _contacts_name._uri, &contact_id);\r
+ contacts_record_get_int(record, _contacts_name.contact_id, &contact_id);\r
contacts_db_get_record(_contacts_contact._uri, contact_id, &c_record);\r
gldata = _create_gl_data(c_record);\r
\r
<ol type="a"><li>Register callbacks with the <span style="font-family: Courier New,Courier,monospace;">contacts_setting_add_name_display_order_changed_cb()</span> and <span style="font-family: Courier New,Courier,monospace;">contacts_setting_add_name_sorting_order_changed_cb()</span> functions. </li>\r
<li>Define the callbacks themselves:\r
<pre class="prettyprint">\r
-static void \r
+static void\r
display_changed_cb(contacts_name_display_order_e name_display_order, void *user_data)\r
{\r
dlog_print(DLOG_DEBUG, LOG_TAG, "changed display order: %s", name_display_order==CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST?"CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST":"CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST");\r
}\r
\r
-static void \r
+static void\r
sorting_changed_cb(contacts_name_sorting_order_e name_display_order, void *user_data)\r
{\r
dlog_print(DLOG_DEBUG, LOG_TAG, "changed sorting order: %s", name_display_order==CONTACTS_NAME_SORTING_ORDER_FIRSTLAST?"CONTACTS_NAME_SORTING_ORDER_FIRSTLAST":"CONTACTS_NAME_SORTING_ORDER_LASTFIRST");\r
contacts_list_h contacts_list;\r
int err = contacts_vcard_parse_to_contacts(vcard_stream, contacts_list);\r
\r
-while (contacts_list_get_current_record_p(list_import, &record) == 0) \r
+while (contacts_list_get_current_record_p(list_import, &record) == 0)\r
{\r
// Get next records from file\r
err = contacts_list_next(list_import);\r
<p>You can also use the <span style="font-family: Courier New,Courier,monospace;">contacts_vcard_parse_to_contact_foreach()</span> function. With this function, you have to get the file content manually, and it needs a callback.</p>\r
\r
<pre class="prettyprint">\r
-bool \r
+bool\r
contacts_vcard_cb(contacts_record_h record, void *user_data)\r
{\r
// Here you have a record\r
int internal_storage_id;\r
char *vcf_path = NULL;\r
\r
-static bool \r
+static bool\r
storage_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data)\r
{\r
if (type == STORAGE_TYPE_INTERNAL)\r
return true;\r
}\r
\r
-void \r
+void\r
_get_storage_path()\r
{\r
int error_code = 0;\r
}\r
}\r
\r
-void \r
+void\r
_import_vcard()\r
{\r
int path_len = 0;\r
continue;\r
char * filepath = malloc(strlen(vcf_path)+strlen(pDirent->d_name)+4);\r
sprintf(filepath, "%s/%s", vcf_path, pDirent->d_name);\r
- \r
+\r
// Full path to file available through filepath string\r
\r
free(filepath);\r
\r
char * vcard_stream = malloc(sizeof(char) * (bufsize));\r
memset(vcard_stream, '\0', sizeof(vcard_stream));\r
-if (fp != NULL) \r
+if (fp != NULL)\r
{\r
char str[200];\r
while(fgets(str, 200, fp) != NULL)\r
sprintf(vcard_stream+strlen(vcard_stream), "%s", str);\r
- fclose(fp); \r
-} \r
+ fclose(fp);\r
+}\r
else\r
// Error handling\r
int err = contacts_vcard_parse_to_contacts(vcard_stream, contacts_list);\r
<li><p>You can also use the <span style="font-family: Courier New,Courier,monospace;">contacts_vcard_parse_to_contact_foreach()</span> function. It requires a callback and retrieves the file path instead of a file stream.</p>\r
\r
<pre class="prettyprint">\r
-bool \r
+bool\r
contacts_vcard_cb(contacts_record_h record, void *user_data)\r
{\r
// Here you have a record\r
contacts_record_h record;\r
err = contacts_vcard_parse_to_contacts(content, &list_import);\r
\r
-while (contacts_list_get_current_record_p(list_import, &record) == 0) \r
+while (contacts_list_get_current_record_p(list_import, &record) == 0)\r
{\r
int id = -1;\r
err = contacts_db_insert_record(record, &id); // Add to list\r
\r
DIR *dir = opendir(folder);\r
struct dirent *pDirent = NULL;\r
-if (dir) \r
+if (dir)\r
{\r
- while ((pDirent = readdir(dir)) != NULL) \r
+ while ((pDirent = readdir(dir)) != NULL)\r
{\r
if (pDirent->d_type != DT_REG)\r
continue;\r
// Error handling\r
int bufsize = ftell(fp);\r
rewind(fp);\r
- dlog_print(DLOG_DEBUG, LOG_TAG, "file size: %i", bufsize); \r
+ dlog_print(DLOG_DEBUG, LOG_TAG, "file size: %i", bufsize);\r
if (bufsize < 1)\r
return 1;\r
\r
char * vcard_stream = malloc(sizeof(char) * (bufsize));\r
memset(vcard_stream, '\0', sizeof(vcard_stream));\r
- if (fp != NULL) \r
+ if (fp != NULL)\r
{\r
char str[150];\r
while(fgets(str, 150, fp) != NULL)\r
sprintf(vcard_stream+strlen(vcard_stream), "%s", str);\r
fclose(fp);\r
- } \r
+ }\r
else\r
return 1;\r
\r
if (err != 0)\r
dlog_print(DLOG_ERROR, LOG_TAG, "contacts_vcard_parse_to_contacts failed: %d", err);\r
free(vcard_stream);\r
- while (contacts_list_get_current_record_p(list_import, &record) == 0) \r
+ while (contacts_list_get_current_record_p(list_import, &record) == 0)\r
{\r
int id = -1;\r
err = contacts_db_insert_record(record, &id); // Add to list\r
contacts_record_h record;\r
FILE * file = fopen(file_path, "w");\r
\r
-while (contacts_list_get_current_record_p(list, &record) == 0) \r
+while (contacts_list_get_current_record_p(list, &record) == 0)\r
{\r
err = contacts_vcard_make_from_contact(record, &vcard_stream);\r
// Save to file\r
</script>\r
\r
</body>\r
-</html>
\ No newline at end of file
+</html>\r