\section{prefs\+\_\+example\+\_\+01.\+c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -o prefs\_example\_01 prefs\_example\_01.c -g `pkg-config --cflags --libs elementary`}

\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{comment}{//testing ui reflection on prefs data changes}
\textcolor{keyword}{static} Eina\_Bool
\_elm\_prefs\_data\_change(\textcolor{keywordtype}{void} *data)
\{
   Evas\_Object *notify = data;
   Elm_Prefs_Data *prefs\_data;
   Elm_Prefs_Item_Type type;
   Eina\_Value value;

   prefs\_data = evas\_object\_data\_get(notify, \textcolor{stringliteral}{"prefs\_data"});

   \textcolor{keywordflow}{if} (elm_prefs_data_value_get(prefs\_data, \textcolor{stringliteral}{"main:universe"}, &type, &value))
     \{
        eina\_value\_set(&value, 42);
        elm_prefs_data_value_set(prefs\_data, \textcolor{stringliteral}{"main:universe"}, type, &value);
     \}

   \textcolor{keywordflow}{if} (elm_prefs_data_value_get(prefs\_data, \textcolor{stringliteral}{"main:text"}, &type, &value))
     \{
        eina\_value\_set(&value, \textcolor{stringliteral}{"This is a text field (:"});
        elm_prefs_data_value_set(prefs\_data, \textcolor{stringliteral}{"main:text"}, type, &value);
     \}

   evas\_object\_show(notify);

   \textcolor{keywordflow}{return} ECORE\_CALLBACK\_RENEW;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_page\_saved\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *page = event\_info;

   printf(\textcolor{stringliteral}{"page %s was saved!\(\backslash\)n"}, page);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_page\_loaded\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *page = event\_info;

   printf(\textcolor{stringliteral}{"page %s was loaded!\(\backslash\)n"}, page);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_item\_changed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *item = event\_info;

   printf(\textcolor{stringliteral}{"item %s was changed!\(\backslash\)n"}, item);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *prefs, *notify, *label;
   Elm_Prefs_Data *prefs\_data;

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"prefs"}, \textcolor{stringliteral}{"Prefs Example 01"});
   elm_policy_set(ELM\_POLICY\_QUIT, ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED);
   elm\_win\_autodel\_set(win, EINA\_TRUE);

   prefs = elm_prefs_add(win);
   evas\_object\_size\_hint\_weight\_set(prefs, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_win\_resize\_object\_add(win, prefs);
   evas\_object\_show(prefs);

   evas\_object\_smart\_callback\_add(prefs, \textcolor{stringliteral}{"page,saved"}, \_page\_saved\_cb, NULL);
   evas\_object\_smart\_callback\_add(prefs, \textcolor{stringliteral}{"page,loaded"}, \_page\_loaded\_cb, NULL);
   evas\_object\_smart\_callback\_add(prefs, \textcolor{stringliteral}{"item,changed"}, \_item\_changed\_cb, win);

   elm_prefs_autosave_set(prefs, EINA\_TRUE);

   prefs\_data = elm_prefs_data_new(\textcolor{stringliteral}{"./prefs\_example\_01.cfg"}, NULL,
                                   EET\_FILE\_MODE\_READ\_WRITE);

   elm_prefs_file_set(prefs, \textcolor{stringliteral}{"prefs\_example\_01.epb"}, NULL);
   elm_prefs_data_set(prefs, prefs\_data);

   label = elm_label_add(win);
   elm\_object\_text\_set(label, \textcolor{stringliteral}{"Setting Values Programmatically"});
   evas\_object\_size\_hint\_align\_set(label, 0.5, 0.5);

   notify = elm_notify_add(win);
   elm\_notify\_align\_set(notify, 0.5, 1);
   elm\_notify\_timeout\_set(notify, 2);
   elm\_object\_content\_set(notify, label);
   evas\_object\_size\_hint\_weight\_set(notify, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_show(notify);

   evas\_object\_data\_set(notify, \textcolor{stringliteral}{"prefs\_data"}, prefs\_data);

   evas\_object\_resize(win, 320, 320);
   evas\_object\_show(win);

   ecore\_timer\_add(5.0, \_elm\_prefs\_data\_change, notify);

   elm_run();

   elm_prefs_data_unref(prefs\_data);

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()
\end{DoxyCodeInclude}
 