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 UI.

We\textquotesingle{}ll create items on the .EPC file and after handle it on the .C file.\hypertarget{prefs_example_01_prefs-epc-01}{}\doxysection{Creating items on EPC file}\label{prefs_example_01_prefs-epc-01}


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


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{collection}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ page}
\DoxyCodeLine{\ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ name:\ "{}main"{};}
\DoxyCodeLine{\ \ \ \ \ \ version:\ 1;}
\DoxyCodeLine{\ \ \ \ \ \ title:\ "{}Preferences\ Widget"{};}
\DoxyCodeLine{\ \ \ \ \ \ subtitle:\ "{}Example\ 01"{};}

\end{DoxyCodeInclude}
 Here we define a page item. Pages are group of items grouped together, on a given prefs widget.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ widget:\ "{}elm/vertical\_box"{};}

\end{DoxyCodeInclude}
 In this part, we create a {\ttfamily INT} type item, that by default will become a spinner widget in the UI, and default, min and max parameters are optional as well as in {\ttfamily FLOAT} type.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ items\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}universe"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ INT;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ label:\ "{}Ultimate\ Answer\ of\ Life,\ the\ Universe\ and\ Everything"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ editable:\ 1;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ int\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ default:\ 42;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ min:\ 0;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ max:\ 150;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 Other {\ttfamily INT} type widget implementations may exist, as is exemplified on the item that follows.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}another\ int"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ INT;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ widget:\ "{}elm/spinner"{};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ int\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ min:\ 0;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 Now we create a LABEL type item and by default will become a read-\/only label in UI.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}label"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ LABEL;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ label:\ "{}Just\ a\ label..."{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 Now we create a TEXT type item and by default will become a single-\/line text entry in UI. Note that we use a Regular Expression to deny only entries with numbers.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}text"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ TEXT;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ editable:\ 1;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ text\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ placeholder:\ "{}This\ is\ a\ text\ field\ (:"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ default:\ "{}default\ str."{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ deny:\ "{}\string^[0-\/9]*\$"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 In this part we create a DATE type item, by default will become a datetime in UI, and default, min and max parameters are optional.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}date"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ DATE;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ label:\ "{}First\ EFL\ Developer\ Day"{};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ date\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ default:\ 2012\ 11\ 05;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ min:\ 1980\ 11\ 1;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ max:\ 2200\ 12\ 2;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 Here we create a SEPARATOR type item, it has no value bound, serves only to divide and organize prefs items.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}sep"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ SEPARATOR;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 In this part, we create a SAVE type item that will get all the values bounded to items and save it on CFG file. Next time you execute the application, all the values that you saved before will be loaded.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}save"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ SAVE;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ label:\ "{}Save"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 Here we create a RESET type item that will return all the values bounded to items as default declared on .EPC file.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ item\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ name:\ "{}reset"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ type:\ RESET;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ label:\ "{}Reset"{};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}}

\end{DoxyCodeInclude}
 Pages and items have default implementation widgets, but, with the tag \textquotesingle{}widget\textquotesingle{}, 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}{}\doxysection{Handling items on C File}\label{prefs_example_01_prefs-c-01}


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


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ prefs\ =\ \mbox{\hyperlink{group__Elm__Prefs_ga403f94943d89e57101f034ed381c5134}{elm\_prefs\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(prefs,\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}},\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Win__Group_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win,\ prefs);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{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 EPC file changes.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(prefs,\ \textcolor{stringliteral}{"{}page,saved"{}},\ \_page\_saved\_cb,\ NULL);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{evas\_object\_smart\_callback\_add}}(prefs,\ \textcolor{stringliteral}{"{}page,loaded"{}},\ \_page\_loaded\_cb,\ NULL);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{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 UI element changes.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ elm\_prefs\_autosave\_set(prefs,\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}

\end{DoxyCodeInclude}
 In this part we create the prefs data handle and set the .EPB file (.EPC compiled). This .EPB 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 RESET type item. There is another file created when the values from prefs items are saved, the .CFG 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}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Prefs_ga7e2cbea5a9696262669748533f578a53}{Elm\_Prefs\_Data}}\ *prefs\_data;}
\DoxyCodeLine{\ \ \ prefs\_data\ =\ \mbox{\hyperlink{group__Elm__Prefs_ga3f5a79c40a17ca1565503a30f810c463}{elm\_prefs\_data\_new}}(\textcolor{stringliteral}{"{}./prefs\_example\_01.cfg"{}},\ NULL,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Eet__File__Group_ggaa8e1a7af50fefaf15eb2f69543d24998a763d29c19960a4e0d4eb7bc7bb512481}{EET\_FILE\_MODE\_READ\_WRITE}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ elm\_prefs\_file\_set(prefs,\ \textcolor{stringliteral}{"{}prefs\_example\_01.epb"{}},\ NULL);}
\DoxyCodeLine{\ \ \ 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}{0}
\DoxyCodeLine{\ \ \ label\ =\ \mbox{\hyperlink{group__Elm__Label__Group_ga39a584d245f8a4b18d742e3ede702507}{elm\_label\_add}}(win);}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(label,\ \textcolor{stringliteral}{"{}Setting\ Values\ Programmatically"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(label,\ 0.5,\ 0.5);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ notify\ =\ \mbox{\hyperlink{group__Elm__Notify__Group_ga994ea9d6b1c3cd4b29b83ccb2c653ad9}{elm\_notify\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Notify__Group_ga5ae77afb4efaeae7952268ca7aac89d1}{elm\_notify\_align\_set}}(notify,\ 0.5,\ 1);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Notify__Group_gafdefb215afc5707a10482207acbacc32}{elm\_notify\_timeout\_set}}(notify,\ 2);}
\DoxyCodeLine{\ \ \ elm\_object\_content\_set(notify,\ label);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(notify,\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}},\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{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}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Extras_ga3061f8abe8f1a1f657d622ae0409d8e3}{evas\_object\_data\_set}}(notify,\ \textcolor{stringliteral}{"{}prefs\_data"{}},\ prefs\_data);}

\end{DoxyCodeInclude}
  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_elm\_prefs\_data\_change(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *notify\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Prefs_ga7e2cbea5a9696262669748533f578a53}{Elm\_Prefs\_Data}}\ *prefs\_data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Prefs_ga7525bee64184478acad1e807c3e570ae}{Elm\_Prefs\_Item\_Type}}\ type;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__Value}{Eina\_Value}}\ value;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ prefs\_data\ =\ evas\_object\_data\_get(notify,\ \textcolor{stringliteral}{"{}prefs\_data"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (\mbox{\hyperlink{group__Elm__Prefs_ga2b692083e7d307512858f1adc2563519}{elm\_prefs\_data\_value\_get}}(prefs\_data,\ \textcolor{stringliteral}{"{}main:universe"{}},\ \&type,\ \&value))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ eina\_value\_set(\&value,\ 42);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Prefs_gaae2c2d085d8c0e9d6c24ff580807a54e}{elm\_prefs\_data\_value\_set}}(prefs\_data,\ \textcolor{stringliteral}{"{}main:universe"{}},\ type,\ \&value);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (\mbox{\hyperlink{group__Elm__Prefs_ga2b692083e7d307512858f1adc2563519}{elm\_prefs\_data\_value\_get}}(prefs\_data,\ \textcolor{stringliteral}{"{}main:text"{}},\ \&type,\ \&value))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ eina\_value\_set(\&value,\ \textcolor{stringliteral}{"{}This\ is\ a\ text\ field\ (:"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Prefs_gaae2c2d085d8c0e9d6c24ff580807a54e}{elm\_prefs\_data\_value\_set}}(prefs\_data,\ \textcolor{stringliteral}{"{}main:text"{}},\ type,\ \&value);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(notify);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}

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