E_VOLUME_UP = 1
};
-struct volume_data;
+struct SVolumeData;
-/**
- * Init volume data
- *
- * @return the pointer of allocated volume_data struct
- */
-struct volume_data *volume_init(void);
+class CVolume {
+private:
+ SVolumeData *m;
-/**
- * Fini volume data
- *
- * @param data the pointer of volume_data struct
- */
-void volume_fini(struct volume_data *data);
+private:
+ void m_SetVolume(volume_val val);
+ void m_SetMute(bool mute);
+ void m_UpdateVolume(void);
-/**
- * Add a volume bar
- *
- * @param data the pointer of volume_data struct
- * @param base the base object of volume layout
- * @return if success EINA_TRUE is returned otherwise will return EINA_FALSE
- */
-Eina_Bool volume_add_bar(struct volume_data *data, Evas_Object *base);
+private:
+ static Eina_Bool sm_CbTimer(void *dt);
-/*
- * hide the volume bar
- *
- * @param data the pointer of volume_data struct
- */
-void volume_hide_bar(struct volume_data *data);
+public:
+ CVolume(void) : m(0) {}
+ virtual ~CVolume(void) {}
-/*
- * Handle the volume key
- *
- * @param data the pointer of volume_data struct
- * @param val value of volme key
- */
-void volume_handle_key(struct volume_data *data, enum volume_val val);
+ /**
+ * Create the volume
+ *
+ * @param base the base object of volume layout
+ * @return if success true is returned otherwise will return false
+ */
+ bool Create(Evas_Object *base);
+
+ /**
+ * Destroy the volume
+ */
+ void Destroy(void);
+
+ /*
+ * show the volume
+ *
+ * @param val value of volme key
+ */
+ void Show(volume_val val);
+
+ /*
+ * hide the volume
+ */
+ void Hide(void);
+};
#endif
char *id;
struct playermgr *player;
- struct volume_data *volume;
+ CVolume *volume;
CVideoController *control;
CVideoSlider *slider;
void CPlayerView::m_ShowBar(void)
{
- volume_hide_bar(m->volume);
+ m->volume->Hide();
if (m->bar_hidden) {
elm_object_signal_emit(m->base, SIG_SHOW_VIEW, "");
CViewMgr::GetInstance()->UpdateView(data->id, (void *)&action);
}
- volume_handle_key(data->volume, (enum volume_val)val);
+ data->volume->Show((volume_val)val);
}
void CPlayerView::sm_CbEcoreEvent(void *dt, int type, void *ei)
if (!m->slider->Create(m->base, m->player))
return false;
- if (!volume_add_bar(m->volume, m->win))
+ if (!m->volume->Create(m->win))
return false;
m->timeout_handle = timeout_handler_init(TIMEOUT_VIDEOPLAYER,
if (!m->control)
_ERR("control init failed");
- m->volume = volume_init();
+ m->volume = new CVolume;
if (!m->volume)
_ERR("volume init failed");
playermgr_fini(m->player);
- volume_fini(m->volume);
-
timeout_handler_fini(m->timeout_handle);
free(m->id);
+ m->volume->Destroy();
+ delete m->volume;
+
m->control->Destroy();
delete m->control;
#include <Elementary.h>
#include <Eina.h>
#include <media/sound_manager.h>
+#include <AppCommon.h>
#include <dbg.h>
#include "define.h"
#include "volume.h"
#define TIME_INTERVAL 3.0
-struct volume_data {
+struct SVolumeData {
Evas_Object *ly;
Evas_Object *bar;
Ecore_Timer *timer;
int volume;
- Eina_Bool mute;
+ bool mute;
};
-static void _set_mute(struct volume_data *data, Eina_Bool mute)
+void CVolume::m_SetMute(bool mute)
{
int r;
int vol;
- if (data->mute == mute)
+ if (m->mute == mute)
return;
if (mute) {
if (r < 0)
return;
- data->volume = vol;
- data->mute = EINA_TRUE;
+ m->volume = vol;
} else {
- sound_manager_set_volume(SOUND_TYPE_MEDIA, data->volume);
- data->mute = EINA_FALSE;
+ sound_manager_set_volume(SOUND_TYPE_MEDIA, m->volume);
}
+
+ m->mute = mute;
}
-static void _handle_volume(struct volume_data *data, enum volume_val val)
+void CVolume::m_SetVolume(volume_val val)
{
int vol;
int r;
switch (val) {
case E_VOLUME_UP:
case E_VOLUME_DOWN:
- _set_mute(data, EINA_FALSE);
+ m_SetMute(false);
r = sound_manager_get_volume(SOUND_TYPE_MEDIA, &vol);
if (r != SOUND_MANAGER_ERROR_NONE) {
sound_manager_set_volume(SOUND_TYPE_MEDIA, vol);
break;
case E_VOLUME_MUTE:
- _set_mute(data, !data->mute);
+ m_SetMute(!m->mute);
break;
default:
break;
}
}
-static void _update_volume_bar(struct volume_data *data)
+void CVolume::m_UpdateVolume(void)
{
double val;
int vol;
char buf[8];
int r;
- if (!data->bar)
+ if (!m->bar)
return;
r = sound_manager_get_volume(SOUND_TYPE_MEDIA, &vol);
vol = 0;
}
- if (vol == 0 || data->mute) {
- elm_object_signal_emit(data->ly, SIG_VOLUME_MUTE, "base");
+ if (vol == 0 || m->mute) {
+ elm_object_signal_emit(m->ly, SIG_VOLUME_MUTE, "base");
val = 0;
} else {
- elm_object_signal_emit(data->ly, SIG_VOLUME_UNMUTE, "base");
+ elm_object_signal_emit(m->ly, SIG_VOLUME_UNMUTE, "base");
val = vol * 0.01;
}
- elm_progressbar_value_set(data->bar, val);
+ elm_progressbar_value_set(m->bar, val);
snprintf(buf, sizeof(buf), "%d", vol);
- elm_object_part_text_set(data->ly, PART_VOLUME_VALUE, buf);
+ elm_object_part_text_set(m->ly, PART_VOLUME_VALUE, buf);
}
-static Eina_Bool _volume_timer_cb(void *dt)
+Eina_Bool CVolume::sm_CbTimer(void *dt)
{
- struct volume_data *data;
+ SVolumeData *data;
if (!dt)
return ECORE_CALLBACK_CANCEL;
- data = (volume_data *)dt;
+ data = (SVolumeData *)dt;
evas_object_hide(data->ly);
data->timer = NULL;
return ECORE_CALLBACK_CANCEL;
}
-void volume_handle_key(struct volume_data *data, enum volume_val val)
+void CVolume::Show(volume_val val)
{
- if (!data)
- return;
+ ASSERT(m);
- if (!data->timer) {
- data->timer = ecore_timer_add(TIME_INTERVAL,
- _volume_timer_cb, data);
- evas_object_show(data->ly);
+ if (!m->timer) {
+ m->timer = ecore_timer_add(TIME_INTERVAL, sm_CbTimer, m);
+ evas_object_show(m->ly);
} else {
- ecore_timer_reset(data->timer);
+ ecore_timer_reset(m->timer);
}
- _handle_volume(data, val);
- _update_volume_bar(data);
+ m_SetVolume(val);
+ m_UpdateVolume();
}
-void volume_hide_bar(struct volume_data *data)
+void CVolume::Hide(void)
{
- if (!data->timer)
- return;
+ ASSERT(m);
- evas_object_hide(data->ly);
- ecore_timer_del(data->timer);
- data->timer = NULL;
+ evas_object_hide(m->ly);
+
+ if (m->timer) {
+ ecore_timer_del(m->timer);
+ m->timer = NULL;
+ }
}
-Eina_Bool volume_add_bar(struct volume_data *data, Evas_Object *base)
+bool CVolume::Create(Evas_Object *base)
{
+ ASSERT(!m);
+
Evas_Object *ly;
Evas_Object *bar;
- if (!base) {
- _ERR("failed to get base object");
- return EINA_FALSE;
+ m = new SVolumeData;
+ if (!m) {
+ _ERR("allocation fail");
+ return false;
}
ly = elm_layout_add(base);
if (!ly) {
- free(data);
- return EINA_FALSE;
+ delete m;
+ return false;
}
elm_layout_file_set(ly, EDJEFILE, GRP_VOLUME);
bar = elm_progressbar_add(ly);
if (!bar) {
_ERR("failed to create progressbar");
- free(data);
+ delete m;
evas_object_del(ly);
- return EINA_FALSE;
+ return false;
}
evas_object_size_hint_weight_set(bar, EVAS_HINT_EXPAND,
elm_object_part_content_set(ly, PART_VOLUME_BAR, bar);
evas_object_show(bar);
- data->ly = ly;
- data->bar = bar;
+ m->ly = ly;
+ m->bar = bar;
- return EINA_TRUE;
-}
+ sound_manager_set_session_type(SOUND_SESSION_TYPE_EXCLUSIVE);
-void volume_fini(struct volume_data *data)
-{
- ecore_timer_del(data->timer);
- free(data);
+ return EINA_TRUE;
}
-struct volume_data *volume_init(void)
+void CVolume::Destroy(void)
{
- struct volume_data *data;
-
- data = (volume_data *)calloc(1, sizeof(*data));
- if (!data) {
- _ERR("allocation fail");
- return NULL;
- }
-
- sound_manager_set_session_type(SOUND_SESSION_TYPE_EXCLUSIVE);
+ ASSERT(m);
- return data;
+ ecore_timer_del(m->timer);
+ delete m;
+ m = NULL;
}