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

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

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

\textcolor{preprocessor}{#define WIDTH (500)}
\textcolor{preprocessor}{#define HEIGHT (700)}
\textcolor{preprocessor}{#define MSG\_ID\_VEL (1)}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_update\_animation(Evas\_Object *prefs, Evas\_Object *layout)
\{
   Eina\_Value value;
   Eina\_Bool animation;

   elm_prefs_item_value_get(prefs, \textcolor{stringliteral}{"main:config:options:animation"}, &value);
   eina\_value\_get(&value, &animation);
   \textcolor{keywordflow}{if} (animation)
     elm_layout_signal_emit(layout, \textcolor{stringliteral}{"start"}, \textcolor{stringliteral}{"animation"});
   \textcolor{keywordflow}{else}
     elm_layout_signal_emit(layout, \textcolor{stringliteral}{"stop"}, \textcolor{stringliteral}{"animation"});
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_update\_animation\_time(Evas\_Object *prefs, Evas\_Object *layout)
\{
   Eina\_Value value;
   \textcolor{keywordtype}{float} animation\_time;
   Edje\_Message\_Float msg;

   elm_prefs_item_value_get(prefs, \textcolor{stringliteral}{"main:config:options:animation\_time"}, &value);
   eina\_value\_get(&value, &animation\_time);
   \textcolor{keywordflow}{if} (animation\_time < 0.01) animation\_time = 0.01;
   msg.val = animation\_time;
   edje\_object\_message\_send(elm_layout_edje_get(layout), EDJE\_MESSAGE\_FLOAT,
                            MSG\_ID\_VEL, &msg);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_update(Evas\_Object *prefs, Evas\_Object *layout)
\{
   \_update\_animation(prefs, layout);
   \_update\_animation\_time(prefs, layout);
\}

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

   \_update(obj, layout);
\}

\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;
   Evas\_Object *layout = data;

   \textcolor{keywordflow}{if} (!strcmp(item, \textcolor{stringliteral}{"main:config:options:animation\_time"}))
     \_update\_animation\_time(obj, layout);
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp(item, \textcolor{stringliteral}{"main:config:options:animation"}))
     \_update\_animation(obj, layout);
\}

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

   elm_policy_set(ELM\_POLICY\_QUIT, ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"Prefs"}, \textcolor{stringliteral}{"Prefs Example 03"});
   elm_win_autodel_set(win, EINA\_TRUE);

   layout = elm_layout_add(win);
   elm_layout_file_set(layout, \textcolor{stringliteral}{"prefs\_example\_03.edj"}, \textcolor{stringliteral}{"prefs\_edje"});

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

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

   elm_prefs_autosave_set(prefs, EINA\_TRUE);

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

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

   elm_prefs_item_swallow(prefs, \textcolor{stringliteral}{"main:swal"}, layout);

   \_update\_animation\_time(prefs, layout);
   \_update\_animation(prefs, layout);

   evas\_object\_resize(win, WIDTH, HEIGHT);
   evas\_object\_show(win);

   elm_run();

   elm_prefs_data_unref(prefs\_data);

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