This example shows how to create a simple prefs widget with Elementary, where the items values are \char`\"{}reset\char`\"{} on each timer tick.

We do that {\bfseries programmatically}, to demonstrate that by touching a given prefs widgets prefs data values, the changes reflect instantly on the U\-I.

We'll create items on the .E\-P\-C file and after handle it on the .C file.\hypertarget{prefs_example_01_prefs-epc-01}{}\section{Creating items on E\-P\-C file}\label{prefs_example_01_prefs-epc-01}


First we'll create prefs items on .E\-P\-C file that we'll use later on the .C file. Note that the code is similar to .E\-D\-C (edje) files.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Here we define a page item. Pages are group of items grouped together, on a given prefs widget.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


In this part, we create a {\ttfamily I\-N\-T} type item, that by default will become a spinner widget in the U\-I, and default, min and max parameters are optional as well as in {\ttfamily F\-L\-O\-A\-T} type.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Other {\ttfamily I\-N\-T} type widget implementations may exist, as is exemplifyed on the item that follows.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Now we create a L\-A\-B\-E\-L type item and by default will become a read-\/only label in U\-I.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Now we create a T\-E\-X\-T type item and by default will become a single-\/line text entry in U\-I. Note that we use a Regular Expression to deny only entries with numbers.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


In this part we create a D\-A\-T\-E type item, by default will become a datetime in U\-I, and default, min and max parameters are optional.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Here we create a S\-E\-P\-A\-R\-A\-T\-O\-R type item, it has no value bound, serves only to divide and organize prefs items.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


In this part, we create a S\-A\-V\-E type item that will get all the values bounded to items and save it on C\-F\-G file. Next time you execute the application, all the values that you saved before will be loaded.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Here we create a R\-E\-S\-E\-T type item that will return all the values bounded to items as default declared on .E\-P\-C file.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Pages and items have default implementation widgets, but, with the tag 'widget', you can use different widgets for prefs items. To a list of default widgets supported by each type, by default, refer to the Elementary Prefs Collection reference sheet. One can also register, at run time, custom item widget handlers too.\hypertarget{prefs_example_01_prefs-c-01}{}\section{Handling items on C File}\label{prefs_example_01_prefs-c-01}


Now we're handling the .C file and first we'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}


Here we add some specific callbacks, for example \char`\"{}item,changed\char`\"{} that will be called when any item that we created on E\-P\-C file changes.


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

\end{DoxyCodeInclude}


Here we set the prefs to save its values back (on the user data file) automatically on every U\-I 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\-P\-B file (.E\-P\-C compiled). This .E\-P\-B file contains all the default values from the items that we created, this file will be loaded when the program starts or when clicked on a R\-E\-S\-E\-T type item. There is another file created when the values from prefs items are saved, the .C\-F\-G file, that contains all the non-\/standard saved values from the prefs items, this file will be loaded when program starts as well.

 
\begin{DoxyCodeInclude}
   Elm_Prefs_Data *prefs\_data;

\end{DoxyCodeInclude}



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

\end{DoxyCodeInclude}


Here we just create a notify widget to appear when the values are reset.


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

\end{DoxyCodeInclude}


Now we add a timer to reset the items values on each 5.\-0 seconds and show the notify.


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

\end{DoxyCodeInclude}


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

\end{DoxyCodeInclude}


Here we finish the example. The full source code can be found on \hyperlink{prefs_example_01_c}{prefs\-\_\-example\-\_\-01.\-c} and \hyperlink{prefs_example_01_epc}{prefs\-\_\-example\-\_\-01.\-epc} 