summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/e_mod_edgar.c284
1 files changed, 2 insertions, 282 deletions
diff --git a/src/e_mod_edgar.c b/src/e_mod_edgar.c
index 43d9229..c4c50de 100644
--- a/src/e_mod_edgar.c
+++ b/src/e_mod_edgar.c
@@ -28,16 +28,10 @@
28#include "efl.eo_api.h" 28#include "efl.eo_api.h"
29 29
30 30
31// undef this to disable bryce integration 31/*
32#define EDGAR_GADGETS_DOMAIN "Edgar" 32TODO
33
34
35/* TODO:
36
37 - correctly manage the new bryce orientations
38 - gadget configurations (and thus id management) 33 - gadget configurations (and thus id management)
39 - gadget actions (keybindings) 34 - gadget actions (keybindings)
40
41*/ 35*/
42 36
43/* Local typedefs */ 37/* Local typedefs */
@@ -70,14 +64,6 @@ static const char *_edgar_gc_id_new(const E_Gadcon_Client_Class *client_class);
70static void _edgar_gc_id_del(const E_Gadcon_Client_Class *client_class, const char *id); 64static void _edgar_gc_id_del(const E_Gadcon_Client_Class *client_class, const char *id);
71static Evas_Object *_edgar_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas); 65static Evas_Object *_edgar_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas);
72 66
73#ifdef EDGAR_GADGETS_DOMAIN
74/* Local Gadget/Bryce Prototypes */
75EINTERN Evas_Object *edgar_bryce_create_cb(Evas_Object *parent, const char *type, int *id, E_Gadget_Site_Orient orient);
76EINTERN char *edgar_bryce_name_cb(const char *type);
77static Evas_Object *edgar_bryce_popup_new(Edgar_Py_Gadget *gadget, Evas_Object *gadget_object);
78static void edgar_bryce_popup_del(Edgar_Py_Gadget *gadget, Evas_Object *ctx_popup);
79#endif
80
81/* Python eapi module proto */ 67/* Python eapi module proto */
82PyMODINIT_FUNC PyInit_eapi(void); 68PyMODINIT_FUNC PyInit_eapi(void);
83 69
@@ -342,14 +328,6 @@ edgar_gadget_load(const char *name, const char *path)
342 e_gadcon_provider_register(cclass); 328 e_gadcon_provider_register(cclass);
343 eina_hash_add(edgar_gadgets, name, gadget); 329 eina_hash_add(edgar_gadgets, name, gadget);
344 330
345#ifdef EDGAR_GADGETS_DOMAIN
346 // add the gadget to the bryce gadgets system
347 e_gadget_external_type_add(EDGAR_GADGETS_DOMAIN, name,
348 edgar_bryce_create_cb, NULL);
349 e_gadget_external_type_name_cb_set(EDGAR_GADGETS_DOMAIN, name,
350 edgar_bryce_name_cb);
351#endif
352
353 return gadget; 331 return gadget;
354} 332}
355 333
@@ -365,11 +343,6 @@ edgar_gadget_unload(Edgar_Py_Gadget *gadget)
365 EINA_LIST_FOREACH_SAFE(gadget->pops_obj, l, l2, popup_content) 343 EINA_LIST_FOREACH_SAFE(gadget->pops_obj, l, l2, popup_content)
366 E_FREE_FUNC(popup_content, evas_object_del); 344 E_FREE_FUNC(popup_content, evas_object_del);
367 345
368#ifdef EDGAR_GADGETS_DOMAIN
369 // remove the gadget from the bryce gadgets system
370 e_gadget_external_type_del(EDGAR_GADGETS_DOMAIN, gadget->name);
371#endif
372
373 // Free the gadcon client class 346 // Free the gadcon client class
374 e_gadcon_provider_unregister(gadget->cclass); 347 e_gadcon_provider_unregister(gadget->cclass);
375 eina_stringshare_del(gadget->cclass->name); 348 eina_stringshare_del(gadget->cclass->name);
@@ -669,259 +642,6 @@ edgar_mouse_down1_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
669 } 642 }
670} 643}
671 644
672
673#ifdef EDGAR_GADGETS_DOMAIN
674/*****************************************************************************/
675/***** Gadget/Bryce Pupup *************************************************/
676/*****************************************************************************/
677static void
678edgar_bryce_ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *info EINA_UNUSED)
679{
680 Edgar_Py_Gadget *gadget = data;
681 edgar_bryce_popup_del(gadget, obj);
682}
683
684static Evas_Object *
685edgar_bryce_popup_new(Edgar_Py_Gadget *gadget, Evas_Object *gadget_object)
686{
687 Evas_Object *ctxpopup, *content;
688
689 DBG("EDGAR: Bryce popup for gadget:%s", gadget->name);
690
691 // create an elm ctxpopup to hold the content generated by the gadget
692 ctxpopup = elm_ctxpopup_add(e_comp->elm);
693 elm_object_style_set(ctxpopup, "noblock");
694 evas_object_smart_callback_add(ctxpopup, "dismissed",
695 edgar_bryce_ctxpopup_dismissed_cb, gadget);
696
697 // request the popup content from the python gadget
698 content = edgar_request_popup_content(gadget, ctxpopup);
699 if (!content)
700 {
701 evas_object_del(ctxpopup);
702 return NULL;
703 }
704
705 // keep track of the popup
706 evas_object_data_set(gadget_object, "edgar-ctxpopup", ctxpopup);
707 evas_object_data_set(ctxpopup, "edgar-ctxpopup-owner", gadget_object);
708
709 // put the content in the ctxpopup and show everything
710 elm_object_content_set(ctxpopup, content);
711 e_gadget_util_ctxpopup_place(gadget_object, ctxpopup, NULL);
712 evas_object_show(ctxpopup);
713
714 return ctxpopup;
715}
716
717static void
718edgar_bryce_popup_del(Edgar_Py_Gadget *gadget, Evas_Object *ctxpopup)
719{
720 Evas_Object *popup_content = elm_object_content_get(ctxpopup);
721 Evas_Object *gadget_object = evas_object_data_get(ctxpopup, "edgar-ctxpopup-owner");
722
723 DBG("EDGAR: Bryce popup delete for gadget:%s", gadget->name);
724 edgar_notify_popup_deleted(gadget, popup_content);
725
726 // remove popup references
727 evas_object_data_del(gadget_object, "edgar-ctxpopup");
728 evas_object_data_del(ctxpopup, "edgar-ctxpopup-owner");
729
730 // delete the ctxpopup itself and the content object
731 evas_object_del(ctxpopup);
732}
733
734
735/*****************************************************************************/
736/***** Gadget/Bryce Menu *************************************************/
737/*****************************************************************************/
738static void
739edgar_bryce_menu_info_cb(void *data, E_Menu *m, E_Menu_Item *mi)
740{
741 edgar_show_gadget_info(data);
742}
743
744static void
745edgar_bryce_menu_cb(Evas_Object *gadget_obj, E_Menu *m)
746{
747 Edgar_Py_Gadget *gadget = evas_object_data_get(gadget_obj, "edgar-gadget");
748 E_Menu_Item *mi;
749
750 mi = e_menu_item_new(m);
751 e_menu_item_separator_set(mi, 1);
752
753 mi = e_menu_item_new(m);
754 e_menu_item_label_set(mi, "Gadget info");
755 e_util_menu_item_theme_icon_set(mi, "help-about");
756 e_menu_item_callback_set(mi, edgar_bryce_menu_info_cb, gadget);
757}
758
759static void
760edgar_bryce_mouse_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event)
761{
762 Edgar_Py_Gadget *gadget = data;
763 Evas_Event_Mouse_Down *ev = event;
764 Eina_Bool pop_on_desk = (uintptr_t)evas_object_data_get(obj, "edgar-pop-on-desk");
765
766 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
767
768 if (ev->button == 1 && !pop_on_desk) // left button (gadget popup)
769 {
770 Evas_Object *ctxpopup;
771
772 if ((ctxpopup = evas_object_data_get(obj, "edgar-ctxpopup")))
773 elm_ctxpopup_dismiss(ctxpopup);
774 else if ((ctxpopup = edgar_bryce_popup_new(gadget, obj)))
775 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
776 }
777}
778
779//static Evas_Object *
780//edgar_bryce_configure_cb(Evas_Object *gadget_obj)
781//{
782 //Edgar_Py_Gadget *gadget = evas_object_data_get(gadget_obj, "edgar-gadget");
783 //DBG("EDGAR: Bryce configure for gadget: %s", gadget->name);
784 //return NULL;
785//}
786
787/*****************************************************************************/
788/***** Gadget/Bryce IFace *************************************************/
789/*****************************************************************************/
790static void
791edgar_bryce_delete_cb(void *data, const Efl_Event *event)
792{
793 Edgar_Py_Gadget *gadget = data;
794 Evas_Object *gadget_object = event->object;
795 Evas_Object *ctxpopup;
796 PyObject *pyobj, *ret;
797 Eina_Bool pop_on_desk = (uintptr_t)evas_object_data_get(gadget_object,
798 "edgar-pop-on-desk");
799
800 DBG("EDGAR: Bryce instance del for gadget:%s", gadget->name);
801
802 // is there a popup opened for this gadget object?
803 if ((ctxpopup = evas_object_data_get(gadget_object, "edgar-ctxpopup")))
804 edgar_bryce_popup_del(gadget, ctxpopup);
805
806 // call the correct method in the python gadget
807 pyobj = object_from_instance(gadget_object);
808 if (pop_on_desk)
809 {
810 ret = PyObject_CallMethod(gadget->instance, "popup_destroyed",
811 "(S)", pyobj);
812 PY_ON_ERROR_RETURN(!ret, , "Cannot call popup_destroyed()");
813 }
814 else
815 {
816 ret = PyObject_CallMethod(gadget->instance, "instance_destroyed",
817 "(S)", pyobj);
818 PY_ON_ERROR_RETURN(!ret, , "Cannot call instance_destroyed()");
819 }
820 Py_XDECREF(ret);
821 Py_XDECREF(pyobj);
822}
823
824static void
825_edgar_bryce_created_cb(void *data, Evas_Object *obj, void *event_data)
826{
827 Edgar_Py_Gadget *gadget = data;
828 Evas_Object *gadget_obj = event_data;
829
830 evas_object_smart_callback_del_full(obj, "gadget_created",
831 _edgar_bryce_created_cb, data);
832
833 //e_gadget_configure_cb_set(gadget_obj, edgar_bryce_configure_cb);
834 e_gadget_menu_populate_cb_set(gadget_obj, edgar_bryce_menu_cb);
835 evas_object_event_callback_add(gadget_obj, EVAS_CALLBACK_MOUSE_DOWN,
836 edgar_bryce_mouse_down_cb, gadget);
837}
838
839EINTERN Evas_Object *
840edgar_bryce_create_cb(Evas_Object *parent, const char *type, int *id, E_Gadget_Site_Orient orient)
841{
842 Edgar_Py_Gadget *gadget;
843 Evas_Object *obj;
844 Eina_Bool pop_on_desk = EINA_FALSE;
845
846 gadget = eina_hash_find(edgar_gadgets, type);
847 if (!gadget) return NULL;
848
849 DBG("EDGAR: Bryce create type:%s id:%d (orient:%d) (edjefile:%s)",
850 type, *id, orient, gadget->edjefile);
851
852 // create the python Gadget class instance (if not already done)
853 if (!gadget->instance)
854 {
855 DBG("EDGAR: Instantiate the python class");
856 gadget->instance = PyObject_CallMethod(gadget->mod, "Gadget", "");
857 PY_ON_ERROR_RETURN(!gadget->instance, NULL, "Cannot create the Gadget instance");
858 }
859
860 // do we want the popup expanded on desktop ?
861 if (gadget->opt_pop_on_desk && orient == E_GADGET_SITE_ORIENT_NONE && *id >= 0)
862 pop_on_desk = EINA_TRUE;
863
864 if (!pop_on_desk)
865 {
866 // create the main edje object
867 obj = edje_object_add(evas_object_evas_get(parent));
868 if (!edgar_theme_object_set(gadget, obj, "main"))
869 {
870 DBG("EDGAR: ERROR, cannot find a theme for the gadget: '%s'", type);
871 evas_object_del(obj);
872 return NULL;
873 }
874
875 // notify the gadget about the created object
876 PyObject *pyobj = object_from_instance(obj);
877 PyObject *ret = NULL;
878 ret = PyObject_CallMethod(gadget->instance, "instance_created",
879 // "(Si)", pyobj, gc->location->site);
880 "(Si)", pyobj, 0); // TODO PASS THE CORRECT ORIENT !!
881 PY_ON_ERROR_RETURN(!ret, NULL, "Cannot call instance_created()");
882 Py_XDECREF(ret);
883 Py_XDECREF(pyobj);
884
885 }
886 else
887 {
888 // request the popup content from the python gadget
889 obj = edgar_request_popup_content(gadget, parent);
890 if (!obj) return NULL;
891 }
892 evas_object_data_set(obj, "edgar-gadget", gadget);
893 evas_object_data_set(obj, "edgar-pop-on-desk", (void*)(uintptr_t)pop_on_desk);
894 evas_object_smart_callback_add(parent, "gadget_created",
895 _edgar_bryce_created_cb, gadget);
896
897
898 // keep track of this instance lifetime (I would have really preferred an explicit callback here!!)
899 // NOTE: del cb with priority to be called before the python-efl one.
900 // Otherwise python-efl delete the python obj too soon.
901 efl_event_callback_priority_add(obj, EFL_EVENT_DEL,
902 EFL_CALLBACK_PRIORITY_BEFORE,
903 edgar_bryce_delete_cb, gadget);
904
905 return obj;
906}
907
908EINTERN char *
909edgar_bryce_name_cb(const char *type)
910{
911 Edgar_Py_Gadget *gadget;
912 Eina_Strbuf *buf = eina_strbuf_new();
913
914 if (!buf) return NULL;
915 gadget = eina_hash_find(edgar_gadgets, type);
916 if (!gadget) return NULL;
917
918 eina_strbuf_append_printf(buf, "%s (python)", gadget->label);
919
920 return eina_strbuf_release(buf);
921}
922#endif
923
924
925/*****************************************************************************/ 645/*****************************************************************************/
926/***** Gadcon IFace *******************************************************/ 646/***** Gadcon IFace *******************************************************/
927/*****************************************************************************/ 647/*****************************************************************************/