Enlightenment CVS committal
Author : mekius
Project : e17
Module : apps/e
Dir : e17/apps/e/src/modules/battery
Modified Files:
e_mod_config.c e_mod_main.c e_mod_main.h
Log Message:
Add alert popup to battery module. Was broken after batget changes. Popup is
now themeable and also a bit less intrusive.
===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/battery/e_mod_config.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -3 -r1.26 -r1.27
--- e_mod_config.c 11 Jan 2008 07:33:55 -0000 1.26
+++ e_mod_config.c 3 May 2008 19:51:49 -0000 1.27
@@ -3,10 +3,12 @@
struct _E_Config_Dialog_Data
{
- int show_alert;
+ int show_alert;
int poll_interval;
- int alarm_time;
- int alarm_percent;
+ int alert_time;
+ int alert_percent;
+ int dismiss_alert;
+ int alert_timeout;
};
/* Protos */
@@ -46,13 +48,20 @@
_fill_data(E_Config_Dialog_Data *cfdata)
{
if (!battery_config) return;
- cfdata->alarm_time = battery_config->alarm;
- cfdata->alarm_percent = battery_config->alarm_p;
+ cfdata->alert_time = battery_config->alert;
+ cfdata->alert_percent = battery_config->alert_p;
cfdata->poll_interval = battery_config->poll_interval;
- if (cfdata->alarm_time > 0 || cfdata->alarm_percent > 0)
+ cfdata->alert_timeout = battery_config->alert_timeout;
+
+ if (cfdata->alert_time > 0 || cfdata->alert_percent > 0)
cfdata->show_alert = 1;
else
cfdata->show_alert = 0;
+
+ if (cfdata->alert_timeout > 0)
+ cfdata->dismiss_alert = 1;
+ else
+ cfdata->dismiss_alert = 0;
}
static void *
@@ -90,16 +99,23 @@
_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
if (!battery_config) return 0;
+
if (cfdata->show_alert)
- {
- battery_config->alarm = cfdata->alarm_time;
- battery_config->alarm_p = cfdata->alarm_percent;
- }
+ {
+ battery_config->alert = cfdata->alert_time;
+ battery_config->alert_p = cfdata->alert_percent;
+ }
else
- {
- battery_config->alarm = 0;
- battery_config->alarm_p = 0;
- }
+ {
+ battery_config->alert = 0;
+ battery_config->alert_p = 0;
+ }
+
+ if (cfdata->dismiss_alert)
+ battery_config->alert_timeout = cfdata->alert_timeout;
+ else
+ battery_config->alert_timeout = 0;
+
_battery_config_updated();
e_config_save_queue();
return 1;
@@ -117,7 +133,7 @@
ob = e_widget_label_add(evas, _("Check battery every:"));
e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 0, 1, 0);
- ob = e_widget_slider_add(evas, 1, 0, _("%1.0f ticks"), 1, 1024, 4, 0, NULL,
&(cfdata->poll_interval), 200);
+ ob = e_widget_slider_add(evas, 1, 0, _("%1.0f ticks"), 1, 1024, 4, 0, NULL,
&(cfdata->poll_interval), 256);
e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 1, 0, 1, 0);
ob = e_widget_check_add(evas, _("Show alert when battery is low"),
&(cfdata->show_alert));
@@ -126,11 +142,20 @@
ob = e_widget_label_add(evas, _("Alert when battery is down to:"));
e_widget_frametable_object_append(of, ob, 0, 3, 1, 1, 1, 0, 1, 1);
- ob = e_widget_slider_add(evas, 1, 0, _("%1.0f minutes"), 1, 60, 1, 0, NULL,
&(cfdata->alarm_time), 200);
+ ob = e_widget_slider_add(evas, 1, 0, _("%1.0f minutes"), 0, 60, 1, 0, NULL,
&(cfdata->alert_time), 60);
e_widget_frametable_object_append(of, ob, 0, 4, 1, 1, 1, 0, 1, 0);
- ob = e_widget_slider_add(evas, 1, 0, _("%1.0f percent"), 1, 100, 1, 0,
NULL, &(cfdata->alarm_percent), 200);
+ ob = e_widget_slider_add(evas, 1, 0, _("%1.0f percent"), 0, 100, 1, 0,
NULL, &(cfdata->alert_percent), 100);
e_widget_frametable_object_append(of, ob, 0, 5, 1, 1, 1, 0, 1, 0);
+
+ ob = e_widget_check_add(evas, _("Dismiss alert automatically"),
&(cfdata->dismiss_alert));
+ e_widget_frametable_object_append(of, ob, 0, 6, 1, 1, 1, 1, 1, 0);
+
+ ob = e_widget_label_add(evas, _("Dismiss alert after:"));
+ e_widget_frametable_object_append(of, ob, 0, 7, 1, 1, 1, 0, 1, 0);
+
+ ob = e_widget_slider_add(evas, 1, 0, _("%1.0f seconds"), 1, 300, 1, 0,
NULL, &(cfdata->alert_timeout), 150);
+ e_widget_frametable_object_append(of, ob, 0, 8, 1, 1, 1, 0, 1, 0);
e_widget_list_object_append(o, of, 1, 1, 0.5);
return o;
@@ -140,17 +165,25 @@
_advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
if (!battery_config) return 0;
+
battery_config->poll_interval = cfdata->poll_interval;
+
if (cfdata->show_alert)
- {
- battery_config->alarm = cfdata->alarm_time;
- battery_config->alarm_p = cfdata->alarm_percent;
- }
+ {
+ battery_config->alert = cfdata->alert_time;
+ battery_config->alert_p = cfdata->alert_percent;
+ }
else
- {
- battery_config->alarm = 0;
- battery_config->alarm_p = 0;
- }
+ {
+ battery_config->alert = 0;
+ battery_config->alert_p = 0;
+ }
+
+ if (cfdata->dismiss_alert)
+ battery_config->alert_timeout = cfdata->alert_timeout;
+ else
+ battery_config->alert_timeout = 0;
+
_battery_config_updated();
e_config_save_queue();
return 1;
===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/battery/e_mod_main.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -3 -r1.115 -r1.116
--- e_mod_main.c 22 Mar 2008 08:04:12 -0000 1.115
+++ e_mod_main.c 3 May 2008 19:51:49 -0000 1.116
@@ -4,6 +4,8 @@
#include "e.h"
#include "e_mod_main.h"
+#define POPUP_DEBOUNCE_CYCLES 2
+
/***************************************************************************/
/**/
/* gadcon requirements */
@@ -36,15 +38,23 @@
{
E_Gadcon_Client *gcc;
Evas_Object *o_battery;
+ Evas_Object *popup_battery;
+ E_Gadcon_Popup *warning;
};
static int _battery_cb_exe_data(void *data, int type, void *event);
static int _battery_cb_exe_del(void *data, int type, void *event);
static void _button_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void
*event_info);
static void _menu_cb_post(void *data, E_Menu *m);
-static void _battery_face_level_set(Instance *inst, double level);
+static void _battery_face_level_set(Evas_Object *battery, double level);
+static void _battery_face_time_set(Evas_Object *battery, int time);
static void _battery_face_cb_menu_configure(void *data, E_Menu *m, E_Menu_Item
*mi);
+static void _battery_cb_warning_popup_hide(void *data, Evas *e, Evas_Object
*obj, void *event);
+static void _battery_warning_popup_resize(Evas_Object *obj, int *w, int *h);
+static int _battery_warning_popup_destroy(void *data);
+static void _battery_warning_popup(Instance *inst, int time, double percent);
+
static E_Config_DD *conf_edd = NULL;
Config *battery_config = NULL;
@@ -72,7 +82,9 @@
inst->gcc = gcc;
inst->o_battery = o;
-
+ inst->warning = NULL;
+ inst->popup_battery = NULL;
+
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
_button_cb_mouse_down, inst);
battery_config->instances = evas_list_append(battery_config->instances,
inst);
@@ -88,6 +100,11 @@
inst = gcc->data;
battery_config->instances = evas_list_remove(battery_config->instances,
inst);
evas_object_del(inst->o_battery);
+ if(inst->warning)
+ {
+ e_object_del(E_OBJECT(inst->warning));
+ inst->popup_battery = NULL;
+ }
free(inst);
}
@@ -172,6 +189,8 @@
e_util_evas_fake_mouse_up_later(inst->gcc->gadcon->evas,
ev->button);
}
+ if (ev->button == 1)
+ _battery_cb_warning_popup_hide(data, e, obj, event_info);
}
static void
@@ -183,14 +202,31 @@
}
static void
-_battery_face_level_set(Instance *inst, double level)
+_battery_face_level_set(Evas_Object *battery, double level)
{
Edje_Message_Float msg;
+ char buf[256];
+
+ snprintf(buf, sizeof(buf), "%i%%", (int)(level*100.0));
+ edje_object_part_text_set(battery, "e.text.reading", buf);
if (level < 0.0) level = 0.0;
else if (level > 1.0) level = 1.0;
msg.val = level;
- edje_object_message_send(inst->o_battery, EDJE_MESSAGE_FLOAT, 1, &msg);
+ edje_object_message_send(battery, EDJE_MESSAGE_FLOAT, 1, &msg);
+}
+
+static void _battery_face_time_set(Evas_Object *battery, int time_left)
+{
+ char buf[256];
+ int hrs, mins;
+
+ hrs = time_left / 3600;
+ mins = (time_left) / 60 - (hrs * 60);
+ snprintf(buf, sizeof(buf), "%i:%02i", hrs, mins);
+ if (hrs < 0) hrs = 0;
+ if (mins < 0) mins = 0;
+ edje_object_part_text_set(battery, "e.text.time", buf);
}
static void
@@ -223,6 +259,99 @@
NULL);
}
+static int
+_battery_warning_popup_destroy(void *data)
+{
+ Instance *inst;
+
+ inst = data;
+
+ if(!inst || !inst->warning) return;
+
+ e_object_del(E_OBJECT(inst->warning));
+ inst->warning = NULL;
+ inst->popup_battery = NULL;
+
+ return 0;
+}
+
+static void
+_battery_cb_warning_popup_hide(void *data, Evas *e, Evas_Object *obj, void
*event)
+{
+ Instance *inst = NULL;
+
+ inst = (Instance *)data;
+
+ if(!inst || !inst->warning) return;
+
+ _battery_warning_popup_destroy(inst);
+}
+
+static void
+_battery_warning_popup_resize(Evas_Object *obj, int *w, int *h)
+{
+ int mw, mh;
+
+ edje_object_size_min_get(obj,&mw,&mh);
+ if (w) *w = mw;
+ if (h) *h = mh;
+}
+
+static void
+_battery_warning_popup(Instance *inst, int time, double percent)
+{
+ Evas *e = NULL;
+ Evas_Object *rect = NULL, *popup_bg = NULL;
+ int x,y,w,h;
+
+ if(!inst || inst->warning) return;
+
+ inst->warning = e_gadcon_popup_new(inst->gcc,
_battery_warning_popup_resize);
+ if(!inst->warning) return;
+
+ e = inst->warning->win->evas;
+
+ popup_bg = edje_object_add(e);
+ inst->popup_battery = edje_object_add(e);
+
+ if(!popup_bg || !inst->popup_battery)
+ {
+ e_object_free(E_OBJECT(inst->warning));
+ inst->warning = NULL;
+ return;
+ }
+
+ e_theme_edje_object_set(popup_bg, "base/theme/modules/battery/popup",
+ "e/modules/battery/popup");
+ e_theme_edje_object_set(inst->popup_battery, "base/theme/modules/battery",
+ "e/modules/battery/main");
+ edje_object_part_swallow(popup_bg, "battery", inst->popup_battery);
+
+ e_gadcon_popup_content_set(inst->warning, popup_bg);
+ e_gadcon_popup_show(inst->warning);
+
+ evas_object_geometry_get(inst->warning->o_bg, &x, &y, &w, &h);
+
+ rect = evas_object_rectangle_add(e);
+ if(rect)
+ {
+ evas_object_move(rect, x, y);
+ evas_object_resize(rect, w, h);
+ evas_object_color_set(rect, 255, 255, 255, 0);
+ evas_object_event_callback_add(rect, EVAS_CALLBACK_MOUSE_DOWN ,
+ _battery_cb_warning_popup_hide, inst);
+ evas_object_repeat_events_set(rect, 1);
+ evas_object_show(rect);
+ }
+
+ _battery_face_time_set(inst->popup_battery, time);
+ _battery_face_level_set(inst->popup_battery, percent);
+ edje_object_signal_emit(inst->popup_battery, "e,state,discharging", "e");
+
+ if(battery_config->alert_timeout)
+
ecore_timer_add(battery_config->alert_timeout,_battery_warning_popup_destroy,
inst);
+}
+
/***************************************************************************/
/**/
/* module setup */
@@ -243,20 +372,23 @@
#define T Config
#define D conf_edd
E_CONFIG_VAL(D, T, poll_interval, INT);
- E_CONFIG_VAL(D, T, alarm, INT);
- E_CONFIG_VAL(D, T, alarm_p, INT);
+ E_CONFIG_VAL(D, T, alert, INT);
+ E_CONFIG_VAL(D, T, alert_p, INT);
+ E_CONFIG_VAL(D, T, alert_timeout, INT);
battery_config = e_config_domain_load("module.battery", conf_edd);
if (!battery_config)
{
battery_config = E_NEW(Config, 1);
battery_config->poll_interval = 512;
- battery_config->alarm = 30;
- battery_config->alarm_p = 10;
+ battery_config->alert = 30;
+ battery_config->alert_p = 10;
+ battery_config->alert_timeout = 0;
}
E_CONFIG_LIMIT(battery_config->poll_interval, 4, 4096);
- E_CONFIG_LIMIT(battery_config->alarm, 0, 60);
- E_CONFIG_LIMIT(battery_config->alarm_p, 0, 100);
+ E_CONFIG_LIMIT(battery_config->alert, 0, 60);
+ E_CONFIG_LIMIT(battery_config->alert_p, 0, 100);
+ E_CONFIG_LIMIT(battery_config->alert_timeout, 0, 300);
battery_config->module = m;
@@ -359,6 +491,13 @@
edje_object_signal_emit(inst->o_battery,
"e,state,unknown", "e");
edje_object_part_text_set(inst->o_battery,
"e.text.reading", _("ERROR"));
edje_object_part_text_set(inst->o_battery,
"e.text.time", _("ERROR"));
+
+ if(inst->popup_battery)
+ {
+ edje_object_signal_emit(inst->popup_battery,
"e,state,unknown", "e");
+ edje_object_part_text_set(inst->popup_battery,
"e.text.reading", _("ERROR"));
+ edje_object_part_text_set(inst->popup_battery,
"e.text.time", _("ERROR"));
+ }
}
}
else
@@ -368,6 +507,8 @@
int have_battery = 0;
int have_power = 0;
Evas_List *l;
+ int mins, hrs;
+ static int debounce_popup = 0;
if (sscanf(ev->lines[i].line, "%i %i %i %i",
&full, &time_left, &have_battery, &have_power)
@@ -383,36 +524,47 @@
if (have_power)
edje_object_signal_emit(inst->o_battery,
"e,state,charging", "e");
else
- edje_object_signal_emit(inst->o_battery,
"e,state,discharging", "e");
+ {
+ edje_object_signal_emit(inst->o_battery,
"e,state,discharging", "e");
+ if(inst->popup_battery)
+
edje_object_signal_emit(inst->popup_battery, "e,state,discharging", "e");
+ }
}
if (have_battery)
{
- if (battery_config->full != full)
- {
- char buf[256];
-
- snprintf(buf, sizeof(buf), "%i%%", full);
-
edje_object_part_text_set(inst->o_battery, "e.text.reading", buf);
- _battery_face_level_set(inst,
(double)full / 100.0);
- }
+ if (battery_config->full != full)
+ {
+ _battery_face_level_set(inst->o_battery,
(double)full / 100.0);
+ if(inst->popup_battery)
+
_battery_face_level_set(inst->popup_battery, (double)full / 100.0);
+ }
}
else
- {
- edje_object_part_text_set(inst->o_battery,
"e.text.reading", _("N/A"));
- _battery_face_level_set(inst, 0.0);
- }
+ {
+ _battery_face_level_set(inst->o_battery, 0.0);
+ edje_object_part_text_set(inst->o_battery,
"e.text.reading", _("N/A"));
+ }
+
if (time_left != battery_config->time_left)
- {
- char buf[256];
- int mins, hrs;
-
- hrs = time_left / 3600;
- mins = (time_left) / 60 - (hrs * 60);
- snprintf(buf, sizeof(buf), "%i:%02i", hrs,
mins);
- if (hrs < 0) hrs = 0;
- if (mins < 0) mins = 0;
- edje_object_part_text_set(inst->o_battery,
"e.text.time", buf);
- }
+ {
+ _battery_face_time_set(inst->o_battery,
time_left);
+ if(inst->popup_battery)
+ _battery_face_time_set(inst->popup_battery,
time_left);
+ }
+
+ if (have_battery && !have_power && (full != 100) &&
+ ((battery_config->alert && ((time_left/60) <=
battery_config->alert)) ||
+ (battery_config->alert_p && (full <=
battery_config->alert_p)))
+ )
+ {
+ if(++debounce_popup == POPUP_DEBOUNCE_CYCLES)
+ _battery_warning_popup(inst, time_left,
(double)full/100.0);
+ }
+ else if(have_power)
+ {
+ _battery_warning_popup_destroy(inst);
+ debounce_popup = 0;
+ }
}
if (!have_battery)
e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/battery/e_mod_main.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -3 -r1.31 -r1.32
--- e_mod_main.h 3 Mar 2008 09:48:37 -0000 1.31
+++ e_mod_main.h 3 May 2008 19:51:49 -0000 1.32
@@ -17,14 +17,14 @@
{
/* saved * loaded config values */
int poll_interval;
- int alarm; /* Alarm on minutes remaining */
- int alarm_p; /* Alarm on percentage remaining */
+ int alert; /* Alert on minutes remaining */
+ int alert_p; /* Alert on percentage remaining */
+ int alert_timeout; /* Popup dismissal timeout */
/* just config state */
E_Module *module;
E_Config_Dialog *config_dialog;
Evas_List *instances;
E_Menu *menu;
- int alarm_triggered;
Ecore_Exe *batget_exe;
Ecore_Event_Handler *batget_data_handler;
Ecore_Event_Handler *batget_del_handler;
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs