95eaf42d572126f40dc77fb881654d6a1be42fd4
[framework/uifw/e17.git] / src / modules / illume-home-toggle / e_mod_main.c
1 #include "e.h"
2 #include "e_mod_main.h"
3
4 typedef struct _Instance Instance;
5 struct _Instance 
6 {
7    E_Gadcon_Client *gcc;
8    Evas_Object *o_toggle;
9 };
10
11 /* local function prototypes */
12 static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
13 static void _gc_shutdown(E_Gadcon_Client *gcc);
14 static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
15 static char *_gc_label(E_Gadcon_Client_Class *cc);
16 static Evas_Object *_gc_icon(E_Gadcon_Client_Class *cc, Evas *evas);
17 static const char *_gc_id_new(E_Gadcon_Client_Class *cc);
18 static void _cb_action_home(void *data, Evas_Object *obj, const char *emission, const char *source);
19
20 /* local variables */
21 static Eina_List *instances = NULL;
22 static const char *mod_dir = NULL;
23
24 static const E_Gadcon_Client_Class _gc_class = 
25 {
26    GADCON_CLIENT_CLASS_VERSION, "illume-home-toggle", 
27      { _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, 
28           e_gadcon_site_is_not_toolbar
29      }, E_GADCON_CLIENT_STYLE_PLAIN
30 };
31
32 /* public functions */
33 EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Illume Home Toggle" };
34
35 EAPI void *
36 e_modapi_init(E_Module *m) 
37 {
38    mod_dir = eina_stringshare_add(m->dir);
39    e_gadcon_provider_register(&_gc_class);
40    return m;
41 }
42
43 EAPI int 
44 e_modapi_shutdown(E_Module *m __UNUSED__) 
45 {
46    e_gadcon_provider_unregister(&_gc_class);
47    if (mod_dir) eina_stringshare_del(mod_dir);
48    mod_dir = NULL;
49    return 1;
50 }
51
52 EAPI int 
53 e_modapi_save(E_Module *m __UNUSED__) 
54 {
55    return 1;
56 }
57
58 /* local functions */
59 static E_Gadcon_Client *
60 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style) 
61 {
62    Instance *inst;
63
64    inst = E_NEW(Instance, 1);
65    inst->o_toggle = edje_object_add(gc->evas);
66    e_theme_edje_object_set(inst->o_toggle, 
67                            "base/theme/modules/illume_home_toggle",
68                            "e/modules/illume_home_toggle/main");
69
70    inst->gcc = e_gadcon_client_new(gc, name, id, style, inst->o_toggle);
71    inst->gcc->data = inst;
72
73    edje_object_signal_callback_add(inst->o_toggle, "e,action,home", "",
74                                    _cb_action_home, inst);
75
76    instances = eina_list_append(instances, inst);
77    return inst->gcc;
78 }
79
80 static void 
81 _gc_shutdown(E_Gadcon_Client *gcc) 
82 {
83    Instance *inst;
84
85    if (!(inst = gcc->data)) return;
86    instances = eina_list_remove(instances, inst);
87    if (inst->o_toggle) evas_object_del(inst->o_toggle);
88    E_FREE(inst);
89 }
90
91 static void 
92 _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__) 
93 {
94    e_gadcon_client_aspect_set(gcc, 16, 16);
95    e_gadcon_client_min_size_set(gcc, 16, 16);
96 }
97
98 static char *
99 _gc_label(E_Gadcon_Client_Class *cc __UNUSED__) 
100 {
101    return _("Illume-Home-Toggle");
102 }
103
104 static Evas_Object *
105 _gc_icon(E_Gadcon_Client_Class *cc __UNUSED__, Evas *evas) 
106 {
107    Evas_Object *o;
108    char buff[PATH_MAX];
109
110    snprintf(buff, sizeof(buff), "%s/e-module-illume-home-toggle.edj", mod_dir);
111    o = edje_object_add(evas);
112    edje_object_file_set(o, buff, "icon");
113    return o;
114 }
115
116 static const char *
117 _gc_id_new(E_Gadcon_Client_Class *cc __UNUSED__) 
118 {
119    static char buff[32];
120
121    snprintf(buff, sizeof(buff), "%s.%d", _gc_class.name, 
122             eina_list_count(instances));
123    return buff;
124 }
125
126 static void 
127 _cb_action_home(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
128 {
129    Instance *inst;
130    E_Zone *zone;
131
132    if (!(inst = data)) return;
133    zone = inst->gcc->gadcon->zone;
134    ecore_x_e_illume_focus_home_send(zone->black_win);
135 }