davemds pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=c76392d4c8a1e5b1c2298aa621ca2492cce00dd1

commit c76392d4c8a1e5b1c2298aa621ca2492cce00dd1
Author: Dave Andreoli <d...@gurumeditation.it>
Date:   Mon Mar 12 21:20:17 2018 +0100

    PackageKit: add support for new gadget API
    
    The gadget can now live in both shelves and bryces.
    
    There is still a strange issue in the popup: the progressbar
    (that should be hidden on show) dont want to honor the
    evas_object_hide call. This only happen when inside an elm
    ctxpopup while works as expected when in a gadcon popup, so
    I suspect a bug in ctxpopup...
---
 src/modules/packagekit/e_mod_main.c       | 84 ++++++++++++++++++++++++++++++-
 src/modules/packagekit/e_mod_packagekit.c | 56 +++++++++++++++++----
 src/modules/packagekit/e_mod_packagekit.h |  3 +-
 3 files changed, 130 insertions(+), 13 deletions(-)

diff --git a/src/modules/packagekit/e_mod_main.c 
b/src/modules/packagekit/e_mod_main.c
index 7753f09cc..f983e20d2 100644
--- a/src/modules/packagekit/e_mod_main.c
+++ b/src/modules/packagekit/e_mod_main.c
@@ -26,7 +26,7 @@ _mouse_down_cb(void *data, Evas *evas EINA_UNUSED, 
Evas_Object *obj EINA_UNUSED,
         if (inst->popup)
           packagekit_popup_del(inst);
         else
-          packagekit_popup_new(inst);
+          packagekit_popup_new(inst, EINA_TRUE);
      }
    else if (ev->button == 2)
      {
@@ -77,6 +77,76 @@ _refresh_timer_cb(void *data)
 }
 
 
+/* Gadget Api Functions */
+static void
+_gadget_mouse_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event)
+{
+   E_PackageKit_Instance *inst = data;
+   E_PackageKit_Module_Context *ctxt = packagekit_mod->data;
+   Evas_Event_Mouse_Down *ev = event;
+
+   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
+   ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+
+   if (ev->button == 1)
+     {
+        if (inst->ctxpopup)
+          packagekit_popup_del(inst);
+        else
+          packagekit_popup_new(inst, EINA_FALSE);
+     }
+   else if (ev->button == 2)
+     {
+        packagekit_create_transaction_and_exec(ctxt, packagekit_get_updates);
+     }
+   else if (ev->button == 3)
+     {
+        if (inst->ctxpopup)
+          packagekit_popup_del(inst);
+        packagekit_config_show(inst->ctxt);
+     }
+}
+
+static void
+_gadget_del_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event EINA_UNUSED)
+{
+   E_PackageKit_Instance *inst = data;
+   E_PackageKit_Module_Context *ctxt = packagekit_mod->data;
+
+   if (inst->ctxpopup) packagekit_popup_del(inst);
+   ctxt->instances = eina_list_remove(ctxt->instances, inst);
+   free(inst);
+}
+
+EINTERN Evas_Object *
+_gadget_create_cb(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient)
+{
+   E_PackageKit_Instance *inst;
+   E_PackageKit_Module_Context *ctxt = packagekit_mod->data;
+
+   inst = E_NEW(E_PackageKit_Instance, 1);
+   inst->ctxt = ctxt;
+   inst->gadget = edje_object_add(evas_object_evas_get(parent));
+   e_theme_edje_object_set(inst->gadget, "base/theme/modules/packagekit",
+                                         "e/modules/packagekit/main");
+   evas_object_event_callback_add(inst->gadget, EVAS_CALLBACK_DEL,
+                                 _gadget_del_cb, inst);
+   ctxt->instances = eina_list_append(ctxt->instances, inst);
+   if (*id >= 0)
+     {  // normal mode
+        evas_object_event_callback_add(inst->gadget, EVAS_CALLBACK_MOUSE_DOWN,
+                                       _gadget_mouse_down_cb, inst);
+        packagekit_icon_update(ctxt, EINA_FALSE);
+     }
+   else
+     {  // demo mode
+        edje_object_signal_emit(inst->gadget, "packagekit,state,updated", "e");
+     }
+
+   return inst->gadget;
+}
+
+
 /* Gadcon Api Functions */
 static E_Gadcon_Client *
 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
@@ -185,9 +255,17 @@ e_modapi_init(E_Module *m)
         ctxt->config->update_interval = 60 * 24;  // once a day
         ctxt->config->show_description = 1;  // extended list
      }
+   m->data = ctxt;
    ctxt->module = m;
    packagekit_mod = m;
+
+   // add the gadget to the new E gadgets system
+   // TODO should this name be translated? also on type_del??
+   e_gadget_type_add("PackageKit", _gadget_create_cb, NULL);
+
+   // add the gadget to the old E gadcon system
    e_gadcon_provider_register(&_gc_class);
+
    packagekit_dbus_connect(ctxt);
    ctxt->refresh_timer = ecore_timer_loop_add(60.0, _refresh_timer_cb, ctxt);
    return ctxt;
@@ -207,6 +285,10 @@ e_modapi_shutdown(E_Module *m)
    E_FREE(ctxt->config);
    E_CONFIG_DD_FREE(ctxt->conf_edd);
 
+   // remove the gadget from the new E gadgets system
+   e_gadget_type_del("PackageKit");
+
+   // remove the gadget from the old E gadcon system
    e_gadcon_provider_unregister(&_gc_class);
 
    E_PackageKit_Package *pkg;
diff --git a/src/modules/packagekit/e_mod_packagekit.c 
b/src/modules/packagekit/e_mod_packagekit.c
index 0e667e32b..e7983bae2 100644
--- a/src/modules/packagekit/e_mod_packagekit.c
+++ b/src/modules/packagekit/e_mod_packagekit.c
@@ -15,6 +15,9 @@ packagekit_icon_update(E_PackageKit_Module_Context *ctxt,
    char buf[16];
    Eina_List *l;
 
+   if (!ctxt->instances)
+     return;
+
    if (working)
      state = "packagekit,state,working";
    else if (ctxt->error)
@@ -426,16 +429,34 @@ _genlist_selunsel_cb(void *data, Evas_Object *obj 
EINA_UNUSED,
    packagekit_popup_update(data, EINA_FALSE);
 }
 
+static void
+_ctxpopup_dismissed(void *data, Evas_Object *obj, void *info EINA_UNUSED)
+{
+   E_PackageKit_Instance *inst = data;
+
+   evas_object_del(obj);
+   inst->ctxpopup = NULL;
+}
+
 void
-packagekit_popup_new(E_PackageKit_Instance *inst)
+packagekit_popup_new(E_PackageKit_Instance *inst, Eina_Bool is_gadcon)
 {
    Evas_Object *table, *bt, *ic, *lb, *li, *pb, *fr, *bx, *size_rect;
    const char *p;
 
-   inst->popup = e_gadcon_popup_new(inst->gcc, EINA_FALSE);
-
-   // main table
-   table = elm_table_add(e_comp->elm);
+   if (is_gadcon)
+     {
+        inst->popup = e_gadcon_popup_new(inst->gcc, EINA_FALSE);
+        table = elm_table_add(e_comp->elm);
+     }
+   else
+     {
+        inst->ctxpopup = elm_ctxpopup_add(e_comp->elm);
+        elm_object_style_set(inst->ctxpopup, "noblock");
+        evas_object_smart_callback_add(inst->ctxpopup, "dismissed",
+                                       _ctxpopup_dismissed, inst);
+        table = elm_table_add(inst->ctxpopup);
+     }
    evas_object_show(table);
 
    // horiz box for title and buttons
@@ -478,7 +499,7 @@ packagekit_popup_new(E_PackageKit_Instance *inst)
    evas_object_show(bt);
 
    // central area (sizer)
-   size_rect = evas_object_rectangle_add(e_comp->evas);
+   size_rect = evas_object_rectangle_add(evas_object_evas_get(table));
    evas_object_size_hint_min_set(size_rect, 300 * elm_config_scale_get(),
                                             300 * elm_config_scale_get());
    elm_table_pack(table, size_rect, 0, 1, 1, 1);
@@ -549,10 +570,19 @@ packagekit_popup_new(E_PackageKit_Instance *inst)
      }
 
    // setup and show the popup
-   e_gadcon_popup_content_set(inst->popup, table);
-   e_object_data_set(E_OBJECT(inst->popup), inst);
-   E_OBJECT_DEL_SET(inst->popup, _popup_del_cb);
-   e_gadcon_popup_show(inst->popup);
+   if (is_gadcon)
+     {
+        e_gadcon_popup_content_set(inst->popup, table);
+        e_object_data_set(E_OBJECT(inst->popup), inst);
+        E_OBJECT_DEL_SET(inst->popup, _popup_del_cb);
+        e_gadcon_popup_show(inst->popup);
+     }
+   else
+     {
+        elm_object_content_set(inst->ctxpopup, table);
+        e_gadget_util_ctxpopup_place(inst->gadget, inst->ctxpopup, NULL);
+        evas_object_show(inst->ctxpopup);
+     }
 
    // update the popup state and contents
    packagekit_popup_update(inst, EINA_TRUE);
@@ -561,7 +591,11 @@ packagekit_popup_new(E_PackageKit_Instance *inst)
 void
 packagekit_popup_del(E_PackageKit_Instance *inst)
 {
-   E_FREE_FUNC(inst->popup, e_object_del);
+   if (inst->popup)
+     E_FREE_FUNC(inst->popup, e_object_del);
+   if (inst->ctxpopup)
+     elm_ctxpopup_dismiss(inst->ctxpopup);
+
    inst->popup_genlist = inst->popup_title_entry = inst->popup_progressbar = 
NULL;
    if (inst->popup_genlist_itc)
      {
diff --git a/src/modules/packagekit/e_mod_packagekit.h 
b/src/modules/packagekit/e_mod_packagekit.h
index de737df5e..8e0742611 100644
--- a/src/modules/packagekit/e_mod_packagekit.h
+++ b/src/modules/packagekit/e_mod_packagekit.h
@@ -79,6 +79,7 @@ typedef struct _E_PackageKit_Instance
    E_Gadcon_Client *gcc;
    Evas_Object *gadget;
    E_Gadcon_Popup *popup;
+   Evas_Object *ctxpopup;
    Evas_Object *popup_title_entry;
    Evas_Object *popup_error_label;
    Evas_Object *popup_install_button;
@@ -111,7 +112,7 @@ void      
packagekit_get_updates(E_PackageKit_Module_Context *ctxt, const char *
 void      packagekit_refresh_cache(E_PackageKit_Module_Context *ctxt, const 
char *transaction);
 void      packagekit_update_packages(E_PackageKit_Module_Context *ctxt, const 
char *transaction);
 void      packagekit_icon_update(E_PackageKit_Module_Context *ctxt, Eina_Bool 
working);
-void      packagekit_popup_new(E_PackageKit_Instance *inst);
+void      packagekit_popup_new(E_PackageKit_Instance *inst, Eina_Bool 
is_gadcon);
 void      packagekit_popup_del(E_PackageKit_Instance *inst);
 void      packagekit_popup_update(E_PackageKit_Instance *inst, Eina_Bool 
rebuild_list);
 

-- 


Reply via email to