1 /* TODO: config dialog to select which modem to monitor */
4 #include "e_mod_main.h"
6 static E_Module *ofono_mod = NULL;
7 static char tmpbuf[4096];
9 const char _e_ofono_name[] = "ofono";
10 const char _e_ofono_Name[] = N_("Mobile Modems Info");
11 int _e_ofono_module_log_dom = -1;
13 static void _ofono_gadget_update(E_Ofono_Instance *inst);
14 static void _ofono_tip_update(E_Ofono_Instance *inst);
17 e_ofono_theme_path(void)
19 #define TF "/e-module-ofono.edj"
22 dirlen = strlen(ofono_mod->dir);
23 if (dirlen >= sizeof(tmpbuf) - sizeof(TF))
26 memcpy(tmpbuf, ofono_mod->dir, dirlen);
27 memcpy(tmpbuf + dirlen, TF, sizeof(TF));
33 static void _ofono_popup_del(E_Ofono_Instance *inst);
36 _ofono_popup_input_window_mouse_up_cb(void *data,
40 Ecore_Event_Mouse_Button *ev = event;
41 E_Ofono_Instance *inst = data;
43 if (ev->window != inst->ui.input.win)
44 return ECORE_CALLBACK_PASS_ON;
46 _ofono_popup_del(inst);
48 return ECORE_CALLBACK_PASS_ON;
52 _ofono_popup_input_window_key_down_cb(void *data,
56 Ecore_Event_Key *ev = event;
57 E_Ofono_Instance *inst = data;
60 if (ev->window != inst->ui.input.win)
61 return ECORE_CALLBACK_PASS_ON;
64 if (!strcmp(keysym, "Escape"))
65 _ofono_popup_del(inst);
67 return ECORE_CALLBACK_PASS_ON;
71 _ofono_popup_input_window_destroy(E_Ofono_Instance *inst)
73 ecore_x_window_free(inst->ui.input.win);
74 inst->ui.input.win = 0;
76 ecore_event_handler_del(inst->ui.input.mouse_up);
77 inst->ui.input.mouse_up = NULL;
79 ecore_event_handler_del(inst->ui.input.key_down);
80 inst->ui.input.key_down = NULL;
84 _ofono_popup_input_window_create(E_Ofono_Instance *inst)
86 Ecore_X_Window_Configure_Mask mask;
87 Ecore_X_Window w, popup_w;
90 man = e_manager_current_get();
92 w = ecore_x_window_input_new(man->root, 0, 0, man->w, man->h);
93 mask = (ECORE_X_WINDOW_CONFIGURE_MASK_STACK_MODE |
94 ECORE_X_WINDOW_CONFIGURE_MASK_SIBLING);
95 popup_w = inst->popup->win->evas_win;
96 ecore_x_window_configure(w, mask, 0, 0, 0, 0, 0, popup_w,
97 ECORE_X_WINDOW_STACK_BELOW);
98 ecore_x_window_show(w);
100 inst->ui.input.mouse_up =
101 ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
102 _ofono_popup_input_window_mouse_up_cb, inst);
104 inst->ui.input.key_down =
105 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
106 _ofono_popup_input_window_key_down_cb, inst);
108 inst->ui.input.win = w;
112 _ofono_toggle_powered_cb(void *data,
113 DBusMessage *msg __UNUSED__,
116 E_Ofono_Instance *inst = data;
118 if ((error) && (dbus_error_is_set(error)))
119 _ofono_dbus_error_show(_("Failed to power modem on/off."), error);
121 DBG("new powered value set");
123 e_widget_disabled_set(inst->ui.powered, (int)EINA_FALSE);
124 inst->powered_pending = EINA_FALSE;
126 dbus_error_free(error);
130 _ofono_popup_cb_powered_changed(void *data,
132 void *event __UNUSED__)
134 E_Ofono_Instance *inst = data;
135 E_Ofono_Module_Context *ctxt = inst->ctxt;
136 Eina_Bool powered = e_widget_check_checked_get(obj);
138 if ((!ctxt) || (!ctxt->has_manager))
140 _ofono_operation_error_show(_("oFono Daemon is not running."));
144 if (!e_ofono_modem_powered_set(inst->modem_element, powered,
145 _ofono_toggle_powered_cb, inst))
147 _ofono_operation_error_show(_("Cannot toggle modem's powered state."));
150 e_widget_disabled_set(obj, EINA_TRUE);
151 inst->powered_pending = EINA_TRUE;
152 DBG("powered = %d pending", !inst->powered);
156 _ofono_popup_update(E_Ofono_Instance *inst)
159 e_widget_label_text_set(inst->ui.name, inst->name);
161 e_widget_label_text_set(inst->ui.name, _("No modem available"));
162 e_widget_check_checked_set(inst->ui.powered, inst->powered);
166 _ofono_popup_del(E_Ofono_Instance *inst)
168 _ofono_popup_input_window_destroy(inst);
169 e_object_del(E_OBJECT(inst->popup));
174 _ofono_popup_new(E_Ofono_Instance *inst)
181 e_gadcon_popup_show(inst->popup);
185 inst->popup = e_gadcon_popup_new(inst->gcc);
186 evas = inst->popup->win->evas;
188 inst->ui.table = e_widget_table_add(evas, 0);
191 inst->ui.name = e_widget_label_add(evas, inst->name);
193 inst->ui.name = e_widget_label_add(evas, "No modem available");
194 e_widget_table_object_append(inst->ui.table, inst->ui.name,
195 0, 0, 1, 1, 1, 1, 1, 1);
196 evas_object_show(inst->ui.name);
198 inst->int_powered = inst->powered;
199 inst->ui.powered = e_widget_check_add(evas, _("Powered"),
201 e_widget_table_object_append(inst->ui.table, inst->ui.powered,
202 0, 1, 1, 1, 1, 1, 1, 1);
203 if (inst->powered_pending)
204 e_widget_disabled_set(inst->ui.powered, (int)EINA_TRUE);
205 evas_object_show(inst->ui.powered);
206 evas_object_smart_callback_add(inst->ui.powered, "changed",
207 _ofono_popup_cb_powered_changed, inst);
209 _ofono_popup_update(inst);
211 e_widget_size_min_get(inst->ui.table, &mw, &mh);
212 e_widget_size_min_set(inst->ui.table, mw, mh);
214 e_gadcon_popup_content_set(inst->popup, inst->ui.table);
215 e_gadcon_popup_show(inst->popup);
216 _ofono_popup_input_window_create(inst);
220 _ofono_menu_new(E_Ofono_Instance *inst,
221 Evas_Event_Mouse_Down *ev)
227 zone = e_util_zone_current_get(e_manager_current_get());
230 m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
231 e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
232 e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y,
233 1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
234 evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
235 EVAS_BUTTON_NONE, ev->timestamp, NULL);
239 _ofono_tip_new(E_Ofono_Instance *inst)
243 inst->tip = e_gadcon_popup_new(inst->gcc);
244 if (!inst->tip) return;
246 e = inst->tip->win->evas;
248 inst->o_tip = edje_object_add(e);
249 e_theme_edje_object_set(inst->o_tip, "base/theme/modules/ofono/tip",
250 "e/modules/ofono/tip");
252 _ofono_tip_update(inst);
254 e_gadcon_popup_content_set(inst->tip, inst->o_tip);
255 e_gadcon_popup_show(inst->tip);
259 _ofono_tip_del(E_Ofono_Instance *inst)
261 evas_object_del(inst->o_tip);
262 e_object_del(E_OBJECT(inst->tip));
268 _ofono_cb_mouse_down(void *data,
269 Evas *evas __UNUSED__,
270 Evas_Object *obj __UNUSED__,
273 E_Ofono_Instance *inst;
274 Evas_Event_Mouse_Down *ev;
284 _ofono_popup_new(inst);
286 _ofono_popup_del(inst);
288 else if (ev->button == 2)
289 _ofono_popup_cb_powered_changed(inst, inst->ui.powered, NULL);
290 else if (ev->button == 3)
291 _ofono_menu_new(inst, ev);
295 _ofono_cb_mouse_in(void *data,
296 Evas *evas __UNUSED__,
297 Evas_Object *obj __UNUSED__,
298 void *event __UNUSED__)
300 E_Ofono_Instance *inst = data;
305 _ofono_tip_new(inst);
309 _ofono_cb_mouse_out(void *data,
310 Evas *evas __UNUSED__,
311 Evas_Object *obj __UNUSED__,
312 void *event __UNUSED__)
314 E_Ofono_Instance *inst = data;
319 _ofono_tip_del(inst);
323 _ofono_edje_view_update(E_Ofono_Instance *inst,
326 Edje_Message_Int msg;
329 if (!inst->ctxt->has_manager)
331 edje_object_signal_emit(o, "e,unavailable", "e");
332 edje_object_part_text_set(o, "e.text.error", _("ofonod is not running"));
336 edje_object_signal_emit(o, "e,available", "e");
339 edje_object_part_text_set(o, "e.text.name", inst->name);
341 edje_object_part_text_set(o, "e.text.name", _("Unknown name"));
345 edje_object_part_text_set(o, "e.text.error", _("Modem powered off"));
346 edje_object_signal_emit(o, "e,netinfo,unavailable", "e");
352 snprintf(buf, sizeof(buf), "%c%s",
353 toupper(inst->status[0]), inst->status + 1);
354 edje_object_part_text_set(o, "e.text.status", buf);
355 edje_object_signal_emit(o, "e,netinfo,available", "e");
358 edje_object_part_text_set(o, "e.text.status", _("Unknown status"));
362 edje_object_part_text_set(o, "e.text.op", inst->op);
363 edje_object_signal_emit(o, "e,netinfo,available", "e");
366 edje_object_part_text_set(o, "e.text.op", _("Unknown operator"));
368 msg.val = inst->strength;
369 edje_object_message_send(o, EDJE_MESSAGE_INT, 1, &msg);
373 _ofono_tip_update(E_Ofono_Instance *inst)
375 _ofono_edje_view_update(inst, inst->o_tip);
379 _ofono_gadget_update(E_Ofono_Instance *inst)
381 E_Ofono_Module_Context *ctxt = inst->ctxt;
383 if (!ctxt->has_manager && inst->popup)
384 _ofono_popup_del(inst);
387 _ofono_popup_update(inst);
389 _ofono_tip_update(inst);
391 _ofono_edje_view_update(inst, inst->ui.gadget);
394 /* Gadcon Api Functions */
396 static E_Gadcon_Client *
397 _gc_init(E_Gadcon *gc,
402 E_Ofono_Instance *inst;
403 E_Ofono_Module_Context *ctxt;
408 ctxt = ofono_mod->data;
410 inst = E_NEW(E_Ofono_Instance, 1);
412 inst->ui.gadget = edje_object_add(gc->evas);
413 e_theme_edje_object_set(inst->ui.gadget, "base/theme/modules/ofono",
414 "e/modules/ofono/main");
418 inst->powered = EINA_FALSE;
419 inst->int_powered = 0;
423 inst->modem_element = NULL;
424 inst->netreg_element = NULL;
426 inst->gcc = e_gadcon_client_new(gc, name, id, style, inst->ui.gadget);
427 inst->gcc->data = inst;
429 evas_object_event_callback_add
430 (inst->ui.gadget, EVAS_CALLBACK_MOUSE_DOWN, _ofono_cb_mouse_down, inst);
431 evas_object_event_callback_add
432 (inst->ui.gadget, EVAS_CALLBACK_MOUSE_IN, _ofono_cb_mouse_in, inst);
433 evas_object_event_callback_add
434 (inst->ui.gadget, EVAS_CALLBACK_MOUSE_OUT, _ofono_cb_mouse_out, inst);
436 _ofono_gadget_update(inst);
438 ctxt->instances = eina_list_append(ctxt->instances, inst);
444 _gc_shutdown(E_Gadcon_Client *gcc)
446 E_Ofono_Module_Context *ctxt;
447 E_Ofono_Instance *inst;
452 ctxt = ofono_mod->data;
461 _ofono_popup_del(inst);
463 _ofono_tip_del(inst);
465 evas_object_del(inst->ui.gadget);
467 eina_stringshare_del(inst->path);
468 eina_stringshare_del(inst->name);
469 eina_stringshare_del(inst->status);
470 eina_stringshare_del(inst->op);
472 ctxt->instances = eina_list_remove(ctxt->instances, inst);
478 _gc_orient(E_Gadcon_Client *gcc,
479 E_Gadcon_Orient orient __UNUSED__)
481 e_gadcon_client_aspect_set(gcc, 16, 16);
482 e_gadcon_client_min_size_set(gcc, 16, 16);
486 _gc_label(const E_Gadcon_Client_Class *client_class __UNUSED__)
488 return _(_e_ofono_Name);
492 _gc_icon(const E_Gadcon_Client_Class *client_class __UNUSED__,
497 o = edje_object_add(evas);
498 edje_object_file_set(o, e_ofono_theme_path(), "icon");
503 _gc_id_new(const E_Gadcon_Client_Class *client_class __UNUSED__)
505 E_Ofono_Module_Context *ctxt;
506 Eina_List *instances;
511 ctxt = ofono_mod->data;
515 instances = ctxt->instances;
516 snprintf(tmpbuf, sizeof(tmpbuf), "ofono.%d", eina_list_count(instances));
520 static const E_Gadcon_Client_Class _gc_class =
522 GADCON_CLIENT_CLASS_VERSION, _e_ofono_name,
524 _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL,
525 e_gadcon_site_is_not_toolbar
527 E_GADCON_CLIENT_STYLE_PLAIN
530 EAPI E_Module_Api e_modapi = {E_MODULE_API_VERSION, _e_ofono_Name};
533 _ofono_manager_changed_do(void *data)
535 E_Ofono_Module_Context *ctxt = data;
537 ctxt->poller.manager_changed = NULL;
538 return ECORE_CALLBACK_CANCEL;
542 _ofono_manager_changed(void *data,
543 const E_Ofono_Element *element __UNUSED__)
545 E_Ofono_Module_Context *ctxt = data;
546 if (ctxt->poller.manager_changed)
547 ecore_poller_del(ctxt->poller.manager_changed);
548 ctxt->poller.manager_changed = ecore_poller_add
549 (ECORE_POLLER_CORE, 1, _ofono_manager_changed_do, ctxt);
553 _ofono_event_manager_in(void *data,
555 void *event __UNUSED__)
557 E_Ofono_Element *element;
558 E_Ofono_Module_Context *ctxt = data;
559 E_Ofono_Instance *inst;
564 ctxt->has_manager = EINA_TRUE;
566 element = e_ofono_manager_get();
567 e_ofono_element_listener_add(element, _ofono_manager_changed, ctxt, NULL);
569 EINA_LIST_FOREACH(ctxt->instances, l, inst)
570 _ofono_gadget_update(inst);
572 return ECORE_CALLBACK_PASS_ON;
576 _ofono_event_manager_out(void *data,
578 void *event __UNUSED__)
580 E_Ofono_Module_Context *ctxt = data;
581 E_Ofono_Instance *inst;
586 ctxt->has_manager = EINA_FALSE;
588 EINA_LIST_FOREACH(ctxt->instances, l, inst)
589 _ofono_gadget_update(inst);
591 return ECORE_CALLBACK_PASS_ON;
595 _eofono_event_element_add(void *data,
599 E_Ofono_Element *element = info;
600 E_Ofono_Module_Context *ctxt = data;
601 E_Ofono_Instance *inst;
603 Eina_Bool have_inst = EINA_FALSE;
605 DBG(">>> %s %s", element->path, element->interface);
607 /* is there any instance taking care of this modem already? */
608 EINA_LIST_FOREACH(ctxt->instances, l, inst)
609 if ((inst->path) && (inst->path == element->path))
611 have_inst = EINA_TRUE;
615 /* if no instance is handling this, is there any instance available */
616 if ((!have_inst) && (e_ofono_element_is_modem(element)))
617 EINA_LIST_FOREACH(ctxt->instances, l, inst)
620 inst->path = eina_stringshare_ref(element->path);
621 DBG("bound %s to an ofono module instance", inst->path);
622 have_inst = EINA_TRUE;
626 /* if still orphan, do nothing */
628 return ECORE_CALLBACK_PASS_ON;
630 if (e_ofono_element_is_modem(element))
631 inst->modem_element = element;
632 else if (e_ofono_element_is_netreg(element))
633 inst->netreg_element = element;
635 _ofono_gadget_update(inst);
637 return ECORE_CALLBACK_PASS_ON;
641 _eofono_event_element_del(void *data,
645 E_Ofono_Element *element = info;
646 E_Ofono_Module_Context *ctxt = data;
647 E_Ofono_Instance *inst;
649 Eina_Bool inst_found = EINA_FALSE;
651 DBG("<<< %s %s", element->path, element->interface);
653 EINA_LIST_FOREACH(ctxt->instances, l, inst)
654 if ((inst->path) && (inst->path == element->path))
656 inst_found = EINA_TRUE;
661 return ECORE_CALLBACK_PASS_ON;
663 if (e_ofono_element_is_modem(element))
665 inst->modem_element = NULL;
666 eina_stringshare_replace(&inst->name, NULL);
667 inst->powered = EINA_FALSE;
669 else if (e_ofono_element_is_netreg(element))
671 inst->netreg_element = NULL;
672 eina_stringshare_replace(&inst->status, NULL);
673 eina_stringshare_replace(&inst->op, NULL);
677 _ofono_gadget_update(inst);
679 return ECORE_CALLBACK_PASS_ON;
683 _eofono_event_element_updated(void *data,
687 E_Ofono_Element *element = event_info;
688 E_Ofono_Module_Context *ctxt = data;
689 E_Ofono_Instance *inst;
691 Eina_Bool inst_found = EINA_FALSE;
694 DBG("!!! %s %s", element->path, element->interface);
696 EINA_LIST_FOREACH(ctxt->instances, l, inst)
697 if ((inst->path) && (inst->path == element->path))
699 inst_found = EINA_TRUE;
704 return ECORE_CALLBACK_PASS_ON;
706 if (e_ofono_element_is_modem(element))
708 if (!e_ofono_modem_powered_get(element, &(inst->powered)))
711 if (!e_ofono_modem_name_get(element, &tmp))
713 if ((!tmp) || (!tmp[0]))
715 eina_stringshare_replace(&inst->name, tmp);
717 DBG("!!! powered = %d, name = %s", inst->powered, inst->name);
719 else if (e_ofono_element_is_netreg(element))
721 if (!e_ofono_netreg_status_get(element, &tmp))
723 eina_stringshare_replace(&inst->status, tmp);
725 if (!e_ofono_netreg_operator_get(element, &tmp))
727 eina_stringshare_replace(&inst->op, tmp);
729 if (!e_ofono_netreg_strength_get(element, &(inst->strength)))
732 DBG("!!! status = %s, operator = %s, strength = %d",
733 inst->status, inst->op, inst->strength);
736 _ofono_gadget_update(inst);
738 return ECORE_CALLBACK_PASS_ON;
742 _ofono_events_register(E_Ofono_Module_Context *ctxt)
744 ctxt->event.manager_in = ecore_event_handler_add
745 (E_OFONO_EVENT_MANAGER_IN, _ofono_event_manager_in, ctxt);
746 ctxt->event.manager_out = ecore_event_handler_add
747 (E_OFONO_EVENT_MANAGER_OUT, _ofono_event_manager_out, ctxt);
748 ctxt->event.element_add = ecore_event_handler_add
749 (E_OFONO_EVENT_ELEMENT_ADD, _eofono_event_element_add, ctxt);
750 ctxt->event.element_del = ecore_event_handler_add
751 (E_OFONO_EVENT_ELEMENT_DEL, _eofono_event_element_del, ctxt);
752 ctxt->event.element_updated = ecore_event_handler_add
753 (E_OFONO_EVENT_ELEMENT_UPDATED, _eofono_event_element_updated, ctxt);
757 _ofono_events_unregister(E_Ofono_Module_Context *ctxt)
759 if (ctxt->event.manager_in)
760 ecore_event_handler_del(ctxt->event.manager_in);
761 if (ctxt->event.manager_out)
762 ecore_event_handler_del(ctxt->event.manager_out);
763 if (ctxt->event.element_add)
764 ecore_event_handler_del(ctxt->event.element_add);
765 if (ctxt->event.element_del)
766 ecore_event_handler_del(ctxt->event.element_del);
767 if (ctxt->event.element_updated)
768 ecore_event_handler_del(ctxt->event.element_updated);
772 e_modapi_init(E_Module *m)
774 E_Ofono_Module_Context *ctxt;
775 E_DBus_Connection *c;
777 c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
779 goto error_dbus_bus_get;
780 if (!e_ofono_system_init(c))
781 goto error_ofono_system_init;
783 ctxt = E_NEW(E_Ofono_Module_Context, 1);
785 goto error_ofono_context;
789 if (_e_ofono_module_log_dom < 0)
791 _e_ofono_module_log_dom = eina_log_domain_register("e_module_ofono",
793 if (_e_ofono_module_log_dom < 0)
795 EINA_LOG_CRIT("could not register logging domain e_module_ofono");
796 goto error_log_domain;
800 e_gadcon_provider_register(&_gc_class);
802 _ofono_events_register(ctxt);
807 _e_ofono_module_log_dom = -1;
811 e_ofono_system_shutdown();
812 error_ofono_system_init:
818 _ofono_instances_free(E_Ofono_Module_Context *ctxt)
820 while (ctxt->instances)
822 E_Ofono_Instance *inst;
824 inst = ctxt->instances->data;
827 _ofono_popup_del(inst);
829 _ofono_tip_del(inst);
831 e_object_del(E_OBJECT(inst->gcc));
836 e_modapi_shutdown(E_Module *m)
838 E_Ofono_Module_Context *ctxt;
839 E_Ofono_Element *element;
845 element = e_ofono_manager_get();
846 e_ofono_element_listener_del(element, _ofono_manager_changed, ctxt);
848 _ofono_events_unregister(ctxt);
850 _ofono_instances_free(ctxt);
852 e_gadcon_provider_unregister(&_gc_class);
854 if (ctxt->poller.manager_changed)
855 ecore_poller_del(ctxt->poller.manager_changed);
860 e_ofono_system_shutdown();
866 e_modapi_save(E_Module *m)
868 E_Ofono_Module_Context *ctxt;