\section{progressbar\-\_\-example.\-c}

\begin{DoxyCodeInclude}

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

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

\textcolor{keyword}{typedef} \textcolor{keyword}{struct }Progressbar\_Example
\{
   Evas\_Object *pb1;
   Evas\_Object *pb2; \textcolor{comment}{/* pulsing */}
   Evas\_Object *pb3;
   Evas\_Object *pb4;
   Evas\_Object *pb5;
   Evas\_Object *pb6; \textcolor{comment}{/* pulsing */}
   Evas\_Object *pb7;
   Evas\_Object *pb8; \textcolor{comment}{/* pulsing */}

   Eina\_Bool    run;
   Ecore\_Timer *timer;
\} Progressbar\_Example;

\textcolor{keyword}{static} Progressbar\_Example example\_data;

\textcolor{keyword}{static} Eina\_Bool
\_progressbar\_example\_value\_set(\textcolor{keywordtype}{void} *data)
\{
   \textcolor{keywordtype}{double} progress;

   progress = elm_progressbar_value_get(example\_data.pb1);
   \textcolor{keywordflow}{if} (progress < 1.0) progress += 0.0123;
   \textcolor{keywordflow}{else} progress = 0.0;

   \textcolor{comment}{/* just the non-pulsing ones need an update */}
   elm_progressbar_value_set(example\_data.pb1, progress);
   elm_progressbar_value_set(example\_data.pb3, progress);
   elm_progressbar_value_set(example\_data.pb4, progress);
   elm_progressbar_value_set(example\_data.pb5, progress);
   elm_progressbar_value_set(example\_data.pb7, progress);

   \textcolor{keywordflow}{if} (progress < 1.0) \textcolor{keywordflow}{return} ECORE\_CALLBACK\_RENEW;

   example\_data.run = 0;
   \textcolor{keywordflow}{return} ECORE\_CALLBACK\_CANCEL;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_progressbar\_example\_start(\textcolor{keywordtype}{void}        *data,
                           Evas\_Object *obj,
                           \textcolor{keywordtype}{void}        *event\_info)
\{
   elm_progressbar_pulse(example\_data.pb2, EINA\_TRUE);
   elm_progressbar_pulse(example\_data.pb6, EINA\_TRUE);
   elm_progressbar_pulse(example\_data.pb8, EINA\_TRUE);

   \textcolor{keywordflow}{if} (!example\_data.run)
     \{
        example\_data.timer = ecore\_timer\_add(
           0.1, \_progressbar\_example\_value\_set, NULL);
        example\_data.run = EINA\_TRUE;
     \}
\}

\textcolor{comment}{/* end of show */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_progressbar\_example\_stop(\textcolor{keywordtype}{void}        *data,
                          Evas\_Object *obj,
                          \textcolor{keywordtype}{void}        *event\_info)
\{
   elm_progressbar_pulse(example\_data.pb2, EINA\_FALSE);
   elm_progressbar_pulse(example\_data.pb6, EINA\_FALSE);
   elm_progressbar_pulse(example\_data.pb8, EINA\_FALSE);

   \textcolor{keywordflow}{if} (example\_data.run)
     \{
        ecore\_timer\_del(example\_data.timer);
        example\_data.run = EINA\_FALSE;
     \}
\}

\textcolor{comment}{/* Format callback */}
\textcolor{keyword}{static} \textcolor{keywordtype}{char} *
\_progress\_format\_cb(\textcolor{keywordtype}{double} val)
\{
   \textcolor{keyword}{static} \textcolor{keywordtype}{char} buf[30];
   \textcolor{keywordtype}{int} files = (1-val)*14000;
   \textcolor{keywordflow}{if} (snprintf(buf, 30, \textcolor{stringliteral}{"%i files left"}, files) > 0)
     \textcolor{keywordflow}{return} strdup(buf);
   \textcolor{keywordflow}{return} NULL;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_progress\_format\_free(\textcolor{keywordtype}{char} *str)
\{
   free(str);
\}

\textcolor{comment}{/* Callback for "changed" signal */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_changed(\textcolor{keywordtype}{void}        *data,
            Evas\_Object *obj,
            \textcolor{keywordtype}{void}        *event\_info)
\{
   \textcolor{keyword}{static} \textcolor{keywordtype}{char} buf[30];
   \textcolor{keyword}{static} time\_t tstart = 0;
   \textcolor{keyword}{static} \textcolor{keywordtype}{double} eta = 0;
   time\_t tdiff;
   \textcolor{keywordtype}{double} val;
   Evas\_Object *label =  (Evas\_Object *)data;

   val = elm_progressbar_value_get(obj);
   \textcolor{keywordflow}{if} (val == 0)
     \{
        tstart = 0;
        elm\_object\_text\_set(label, \textcolor{stringliteral}{"ETA: N/A"});
        \textcolor{keywordflow}{return};
     \}

   \textcolor{comment}{/* First invocation */}
   \textcolor{keywordflow}{if} (tstart == 0)
     \{
        tstart = time(NULL);
     \}

   \textcolor{comment}{/* Calculate ETA and update */}
   tdiff = time(NULL) - tstart;
   eta = 0.3*eta + 0.7*(tdiff/val)*(1-val);
   snprintf(buf, 30, \textcolor{stringliteral}{"ETA: %.0fs"}, eta);
   elm\_object\_text\_set(label, buf);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_done(\textcolor{keywordtype}{void}        *data,
         Evas\_Object *obj,
         \textcolor{keywordtype}{void}        *event\_info)
\{
   \_progressbar\_example\_stop(NULL, NULL, NULL);
   elm_exit();
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int}    argc,
         \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *pb, *bx, *hbx, *bt, *bt\_bx, *ic1, *ic2, *label;
   \textcolor{keywordtype}{char} buf[PATH\_MAX];

   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"images/logo\_small.png"});

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"progressbar"}, \textcolor{stringliteral}{"Progress bar example"});
   evas\_object\_smart\_callback\_add(win, \textcolor{stringliteral}{"delete,request"}, \_on\_done, NULL);

   bx = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(bx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas\_object\_show(bx);

   \textcolor{comment}{/* pb with no label, default unit label and no icon */}
   pb = elm_progressbar_add(win);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   elm_box_pack_end(bx, pb);
   evas\_object\_show(pb);
   example\_data.pb1 = pb;

   \textcolor{comment}{/* pb with label, and set to pulse */}
   pb = elm_progressbar_add(win);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Infinite bounce"});
   elm_progressbar_pulse_set(pb, EINA\_TRUE);
   elm_box_pack_end(bx, pb);
   evas\_object\_show(pb);
   example\_data.pb2 = pb;

   ic1 = elm_icon_add(win);
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%s/images/logo\_small.png"}, elm_app_data_dir_get());
   elm_image_file_set(ic1, buf, NULL);
   evas\_object\_size\_hint\_aspect\_set(ic1, EVAS\_ASPECT\_CONTROL\_VERTICAL, 1, 1);

   \textcolor{comment}{/* pb with label, icon, custom unit label function and span size set */}
   pb = elm_progressbar_add(win);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Label"});
   elm_object_part_content_set(pb, \textcolor{stringliteral}{"icon"}, ic1);
   elm_progressbar_inverted_set(pb, EINA\_TRUE);
   elm_progressbar_unit_format_function_set(pb, \_progress\_format\_cb,
                                            \_progress\_format\_free);
   elm_progressbar_span_size_set(pb, 200);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(bx, pb);
   evas\_object\_show(ic1);
   evas\_object\_show(pb);
   example\_data.pb3 = pb;

   \textcolor{comment}{/* pb with label and changed trigger  */}
   pb = elm_progressbar_add(win);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Label"});
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(bx, pb);
   evas\_object\_show(pb);

   label = elm_label_add(win);
   elm\_object\_text\_set(label, \textcolor{stringliteral}{"ETA: N/A"});
   evas\_object\_size\_hint\_align\_set(label, 0.5, 0.5);
   evas\_object\_size\_hint\_weight\_set(label, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(bx, label);
   evas\_object\_show(label);

   evas\_object\_smart\_callback\_add(pb, \textcolor{stringliteral}{"changed"}, \_on\_changed, label);
   example\_data.pb4 = pb;

   hbx = elm_box_add(win);
   elm_box_horizontal_set(hbx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(hbx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(hbx, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bx, hbx);
   evas\_object\_show(hbx);

   \textcolor{comment}{/* vertical pb */}
   pb = elm_progressbar_add(win);
   elm_progressbar_horizontal_set(pb, EINA\_FALSE);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(hbx, pb);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"percent"});
   evas\_object\_show(pb);
   example\_data.pb5 = pb;

   \textcolor{comment}{/* vertical pb, with pulse and custom (small) span size */}
   pb = elm_progressbar_add(win);
   elm_progressbar_horizontal_set(pb, EINA\_FALSE);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_progressbar_span_size_set(pb, 80);
   elm_progressbar_pulse_set(pb, EINA\_TRUE);
   elm_progressbar_unit_format_set(pb, NULL);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Infinite bounce"});
   elm_box_pack_end(hbx, pb);
   evas\_object\_show(pb);
   example\_data.pb6 = pb;

   ic2 = elm_icon_add(win);
   elm_image_file_set(ic2, buf, NULL);
   evas\_object\_size\_hint\_aspect\_set(ic2, EVAS\_ASPECT\_CONTROL\_HORIZONTAL, 1, 1);

   \textcolor{comment}{/* vertical pb, inverted, with custom unit format and icon*/}
   pb = elm_progressbar_add(win);
   elm_progressbar_horizontal_set(pb, EINA\_FALSE);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Label"});
   elm_object_part_content_set(pb, \textcolor{stringliteral}{"icon"}, ic2);
   elm_progressbar_inverted_set(pb, EINA\_TRUE);
   elm_progressbar_unit_format_set(pb, \textcolor{stringliteral}{"%1.2f%%"});
   elm_progressbar_span_size_set(pb, 200);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(hbx, pb);
   evas\_object\_show(ic2);
   evas\_object\_show(pb);
   example\_data.pb7 = pb;

   \textcolor{comment}{/* "wheel" style progress bar */}
   pb = elm_progressbar_add(win);
   elm_object_style_set(pb, \textcolor{stringliteral}{"wheel"});
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Style: wheel"});
   elm_progressbar_pulse_set(pb, EINA\_TRUE);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(bx, pb);
   evas\_object\_show(pb);
   example\_data.pb8 = pb;

   bt\_bx = elm_box_add(win);
   elm_box_horizontal_set(bt\_bx, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(bt\_bx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(bx, bt\_bx);
   evas\_object\_show(bt\_bx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Start"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_progressbar\_example\_start,
                                  NULL);
   elm_box_pack_end(bt\_bx, bt);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Stop"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_progressbar\_example\_stop,
                                  NULL);
   elm_box_pack_end(bt\_bx, bt);
   evas\_object\_show(bt);

   evas\_object\_show(win);

   elm_run();
   elm_shutdown();

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