This example shows how to create a simple prefs widget with Elementary, where some items properties are changed on each timer tick.

We\textquotesingle{}ll create items on the .E\+PC file and after handle it on the .C file.\hypertarget{prefs_example_02_prefs-epc-02}{}\section{Creating items on E\+P\+C file}\label{prefs_example_02_prefs-epc-02}


First we\textquotesingle{}ll create prefs items on .E\+PC file that we\textquotesingle{}ll use later on the .C file. Note that the code is similar to .E\+DC (edje) files.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


In this part, we create a {\ttfamily T\+E\+X\+T\+A\+R\+EA} item and, by default, it will become a multi-\/line text entry in the UI. Note that we use a regular expression to accept only characters and whitespaces in it.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Now we create a F\+L\+O\+AT type item, by default will become a spinner in UI, and default, min and max parameters are optional as well as in I\+NT type.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Here we create a B\+O\+OL type item, by default will become a checkbox in UI.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Here we create two items, separator and save types, that we\textquotesingle{}ve already covered in \hyperlink{prefs_example_01}{Prefs Example 01}


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


In this part, we create a A\+C\+T\+I\+ON type item. when clicked, the action item will emit a signal to .C file and call a smart callback.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
\hypertarget{prefs_example_02_prefs-c-02}{}\section{Handling items on C File}\label{prefs_example_02_prefs-c-02}


Now we\textquotesingle{}re handling the .C file and first we\textquotesingle{}ll create a prefs widget.


\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


In this part we add the action smart callback, that will be called when the action item be clicked.


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

\end{DoxyCodeInclude}


Here we add a simple action item callback that sets a text to another item.

 
\begin{DoxyCodeInclude}
\_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);
     \}

\end{DoxyCodeInclude}


Now we set the prefs to save its values back (on the user data file) automatically on every UI element changes.


\begin{DoxyCodeInclude}
   elm_prefs_autosave_set(prefs, EINA\_TRUE);

\end{DoxyCodeInclude}


In this part we create the prefs data handle and set the .E\+PB file (.E\+PC compiled).

 
\begin{DoxyCodeInclude}
   Elm_Prefs_Data *prefs\_data;

\end{DoxyCodeInclude}



\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


Here we just create a notify widget to appear when the items properties are changed.


\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


Now we add a timer to change text editable, spinners visibility and checkbox enable/disable properties on each 5.\+0 seconds and show the notify.


\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


 
\begin{DoxyCodeInclude}
\_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;
\}

\end{DoxyCodeInclude}


Here we finish the example. The full source code can be found on \hyperlink{prefs_example_02_c}{prefs\+\_\+example\+\_\+02.\+c} and \hyperlink{prefs_example_02_epc}{prefs\+\_\+example\+\_\+02.\+epc} 