#include <Elementary.h>
#ifndef ELM_LIB_QUICKLAUNCH
-static Evas_Object *slideshow;
+static Evas_Object *slideshow, *bt_start, *bt_stop;
static void
_notify_show(void *data, Evas_Object *obj, void *event_info)
elm_hoversel_label_set(obj, data);
}
+static void
+_start(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ elm_slideshow_timeout_set(slideshow, (int)elm_spinner_value_get(data));
+
+ elm_widget_disabled_set(bt_start, 1);
+ elm_widget_disabled_set(bt_stop, 0);
+}
+
+static void
+_stop(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ elm_slideshow_timeout_set(slideshow, 0);
+ elm_widget_disabled_set(bt_start, 0);
+ elm_widget_disabled_set(bt_stop, 1);
+}
+
+static void
+_spin(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ if(elm_slideshow_timeout_get(slideshow) > 0)
+ elm_slideshow_timeout_set(slideshow, (int)elm_spinner_value_get(data));
+}
void
test_slideshow(void *data, Evas_Object *obj, void *event_info)
{
- Evas_Object *win, *bg, *notify, *bx, *bt, *hv;
+ Evas_Object *win, *bg, *notify, *bx, *bt, *hv, *spin;
char buf[PATH_MAX];
const Eina_List *l;
const char *transition;
evas_object_show(bg);
slideshow = elm_slideshow_add(win);
+ elm_slideshow_loop_set(slideshow, 1);
elm_win_resize_object_add(win, slideshow);
evas_object_size_hint_weight_set(slideshow, 1.0, 1.0);
evas_object_show(slideshow);
elm_hoversel_label_set(hv, eina_list_data_get(elm_slideshow_transitions_get(slideshow)));
evas_object_show(hv);
+ spin = elm_spinner_add(win);
+ elm_spinner_label_format_set(spin, "%2.0f secs.");
+ evas_object_smart_callback_add(spin, "changed", _spin, spin);
+ elm_spinner_step_set(spin, 1);
+ elm_spinner_min_max_set(spin, 1, 30);
+ elm_spinner_value_set(spin, 3);
+ elm_box_pack_end(bx, spin);
+ evas_object_show(spin);
+
+ bt = elm_button_add(win);
+ bt_start = bt;
+ elm_button_label_set(bt, "Start");
+ evas_object_smart_callback_add(bt, "clicked", _start, spin);
+ elm_box_pack_end(bx, bt);
+ evas_object_show(bt);
+
+ bt = elm_button_add(win);
+ bt_stop = bt;
+ elm_button_label_set(bt, "Stop");
+ evas_object_smart_callback_add(bt, "clicked", _stop, spin);
+ elm_box_pack_end(bx, bt);
+ elm_widget_disabled_set(bt, 1);
+ evas_object_show(bt);
+
+
evas_object_smart_callback_add(slideshow, "clicked", _notify_show, notify);
evas_object_smart_callback_add(slideshow, "move", _notify_show, notify);
- evas_object_resize(win, 250, 200);
+ evas_object_resize(win, 350, 200);
evas_object_show(win);
}
struct _Widget_Data
{
Evas_Object *slideshow;
- Evas_Object *img1, *img2;
// list of char*
Eina_List *images;
int current;
+ int loop;
Eina_List *transitions;
const char *transition;
+
+ Ecore_Timer *timer;
+ int timeout;
};
static void _del_hook(Evas_Object *obj);
_del_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
+ elm_slideshow_clear(obj);
+ _stringlist_free(wd->transitions);
free(wd);
}
static void
_sub_del(void *data, Evas_Object *obj, void *event_info)
{
+ Node *node;
Widget_Data *wd = elm_widget_data_get(obj);
Evas_Object *sub = event_info;
- evas_object_event_callback_del
- (wd->img1, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints);
- evas_object_del(wd->img1);
-
- evas_object_event_callback_del
- (wd->img2, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints);
- evas_object_del(wd->img2);
}
-static void
+ static void
_signal_clicked(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
evas_object_smart_callback_call(data, "clicked", NULL);
}
-static void
+ static void
_signal_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
evas_object_smart_callback_call(data, "move", NULL);
}
-static void
+ static void
_end(void *data, Evas_Object *obj, const char *emission, const char *source)
{
Node *node;
evas_object_image_file_set((Evas_Object *)o, node->file, node->group);
}
+
+ static int
+_timer_cb(void *data)
+{
+ Evas_Object *obj = data;
+ Widget_Data *wd = elm_widget_data_get(obj);
+
+ wd->timer = NULL;
+ elm_slideshow_next(obj);
+ return 0;
+}
+
/**
* Add a new slideshow to the parent
*
if(pos<0 || pos>=eina_list_count(wd->images))
return ;
- if(wd->img1)
- evas_object_del(wd->img1);
-
wd->current = pos;
node = eina_list_nth(wd->images, wd->current);
char buf[1024];
const Evas_Object *o;
Node *node;
+ int next;
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
- if(wd->current >= eina_list_count(wd->images) - 1)
+ if(eina_list_count(wd->images) <= 0
+ || (wd->current >= eina_list_count(wd->images) - 1
+ && !wd->loop))
return ;
- node = eina_list_nth(wd->images, wd->current + 1);
+ if(wd->current >= eina_list_count(wd->images) - 1)
+ next = 0;
+ else
+ next = wd->current + 1;
+
+ node = eina_list_nth(wd->images, next);
_end(obj, obj, NULL, NULL);
snprintf(buf, 1024, "%s,next", wd->transition);
edje_object_signal_emit(wd->slideshow, buf, "slideshow");
- wd->current++;
+ wd->current = next;
+
+ if(wd->timer)
+ ecore_timer_del(wd->timer);
+ wd->timer = NULL;
+ if(wd->timeout>0)
+ wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
}
/**
char buf[1024];
const Evas_Object *o;
Node *node;
+ int previous;
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd) return;
- if(wd->current <= 0)
+ if(eina_list_count(wd->images) <= 0
+ || (wd->current <= 0
+ && !wd->loop))
return ;
- node = eina_list_nth(wd->images, wd->current - 1);
+ if(wd->current <= 0)
+ previous = eina_list_count(wd->images) - 1;
+ else
+ previous = wd->current - 1;
+
+ node = eina_list_nth(wd->images, previous);
_end(obj, obj, NULL, NULL);
snprintf(buf, 1024, "%s,previous", wd->transition);
edje_object_signal_emit(wd->slideshow, buf, "slideshow");
- wd->current--;
+ wd->current = previous;
+
+ if(wd->timer)
+ ecore_timer_del(wd->timer);
+ wd->timer = NULL;
+ if(wd->timeout>0)
+ wd->timer = ecore_timer_add(wd->timeout, _timer_cb, obj);
}
/**
wd->transition = eina_stringshare_add(transition);
}
+/**
+ * The object can go to the next image automatically after a few seconds.
+ * This method set the timeout to use. A timeout <=0 disable the timer.
+ *
+ * @param obj The slideshow object
+ * @param timeout The new timeout
+ */
+ EAPI void
+elm_slideshow_timeout_set(Evas_Object *obj ,int timeout)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if(!wd) return;
+
+ wd->timeout = timeout;
+ if(wd->timer)
+ ecore_timer_del(wd->timer);
+ wd->timer = NULL;
+ if(timeout>0)
+ wd->timer = ecore_timer_add(timeout, _timer_cb, obj);
+}
+
+/**
+ * Returns the timeout value
+ *
+ * @param obj The slideshow object
+ * @return Returns the timeout
+ */
+ EAPI int
+elm_slideshow_timeout_get(Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if(!wd) return;
+
+ return wd->timeout;
+}
+
+/**
+ * Set if the first image should follow the last
+ *
+ * @param obj The slideshow object
+ * @param loop if 1, the first image will follow the last
+ */
+ EAPI void
+elm_slideshow_loop_set(Evas_Object *obj, int loop)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if(!wd) return;
+
+ wd->loop = loop;
+}
+
+/**
+ * Delete all the images
+ *
+ * @param obj The slideshow object
+ */
+ EAPI void
+elm_slideshow_clear(Evas_Object *obj)
+{
+ Node *node;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if(!wd) return;
+
+ EINA_LIST_FREE(wd->images, node)
+ {
+ if(node->file) eina_stringshare_del(node->file);
+ if(node->group) eina_stringshare_del(node->group);
+ }
+}
+