\section{prefs\-\_\-example\-\_\-02.\-c}

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

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

\textcolor{keyword}{static} Eina\_Bool visible = EINA\_TRUE;
\textcolor{keyword}{static} Eina\_Bool editable = EINA\_TRUE;
\textcolor{keyword}{static} Eina\_Bool disabled = EINA\_FALSE;

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

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

   visible = !visible;
   elm_prefs_item_visible_set(prefs, \textcolor{stringliteral}{"main:floatsp"}, visible);

   disabled = !disabled;
   elm_prefs_item_disabled_set(prefs, \textcolor{stringliteral}{"main:checkb"}, disabled);

   editable = !editable;
   elm_prefs_item_editable_set(prefs, \textcolor{stringliteral}{"main:text"}, editable);
   \textcolor{keywordflow}{if} (elm_prefs_data_value_get(prefs\_data, \textcolor{stringliteral}{"main:text"}, &type, &value))
     \{
        eina\_value\_set(&value, editable ? \textcolor{stringliteral}{"This is a editable text entry"} :
                       \textcolor{stringliteral}{"This is a non-editable text entry"});
        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}
\_action\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   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:text"}, &type, &value))
     \{
        eina\_value\_set(&value, \textcolor{stringliteral}{"Action!"});
        elm_prefs_data_value_set(prefs\_data, \textcolor{stringliteral}{"main:text"}, type, &value);
     \}
\}

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 02"});
   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);

   elm_prefs_autosave_set(prefs, EINA\_TRUE);

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

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

   label = elm_label_add(win);
   elm\_object\_text\_set(label, \textcolor{stringliteral}{"Editable, Visible and Disable! Just Saying..."});
   evas\_object\_size\_hint\_weight\_set(label, 0.0, 0.0);
   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"}, prefs);
   evas\_object\_data\_set(notify, \textcolor{stringliteral}{"prefs\_data"}, prefs\_data);

   evas\_object\_smart\_callback\_add(prefs, \textcolor{stringliteral}{"action"}, \_action\_cb, notify);

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

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

   elm_run();

   elm_prefs_data_unref(prefs\_data);

   elm_shutdown();

   \textcolor{keywordflow}{return} 0;
\}

ELM_MAIN()
\end{DoxyCodeInclude}
 