3224d4f1c7316b6c67ad84fca39a3c3bf062464c
[framework/uifw/e17.git] / src / modules / everything / e_mod_main.h
1 #ifndef EVRY_H
2 #define EVRY_H
3
4 #include "e.h"
5 #include "evry_api.h"
6
7 #define MOD_CONFIG_FILE_EPOCH 0x0005
8 #define MOD_CONFIG_FILE_GENERATION 0x0002
9 #define MOD_CONFIG_FILE_VERSION                                 \
10   ((MOD_CONFIG_FILE_EPOCH << 16) | MOD_CONFIG_FILE_GENERATION)
11
12 #define SLIDE_LEFT   1
13 #define SLIDE_RIGHT -1
14
15 typedef struct _Evry_View       Evry_View;
16 typedef struct _History         Evry_History;
17 typedef struct _Config          Evry_Config;
18 typedef struct _Evry_Selector   Evry_Selector;
19 typedef struct _Tab_View        Tab_View;
20 typedef struct _Evry_Window     Evry_Window;
21
22 struct _Evry_Window
23 {
24   E_Win *ewin;
25   Evas *evas;
26   E_Zone *zone;
27   Eina_Bool shaped;
28   Evas_Object *o_main;
29
30   Eina_Bool request_selection;
31   Eina_Bool plugin_dedicated;
32   Eina_Bool visible;
33
34   Eina_List *handlers;
35
36   Evry_Selector  *selector;
37   Evry_Selector **selectors;
38   Evry_Selector **sel_list;
39
40   unsigned int level;
41
42   unsigned int mouse_button;
43   Eina_Bool mouse_out;
44   
45   Eina_Bool grab;
46
47   Evry_State *state_clearing;
48 };
49
50 struct _Evry_Selector
51 {
52   Evry_Window *win;
53
54   /* current state */
55   Evry_State  *state;
56
57   /* stack of states (for browseable plugins) */
58   Eina_List   *states;
59
60   /* provides collection of items from other plugins */
61   Evry_Plugin *aggregator;
62
63   /* action selector plugin */
64   Evry_Plugin *actions;
65
66   /* all plugins that belong to this selector*/
67   Eina_List   *plugins;
68
69   /* list view instance */
70   Evry_View   *view;
71
72   Evas_Object *o_icon;
73   Evas_Object *o_thumb;
74   Eina_Bool    do_thumb;
75
76   Ecore_Timer *update_timer;
77   Ecore_Timer *action_timer;
78
79   const char *edje_part;
80 };
81
82 struct _Evry_State
83 {
84   Evry_Selector *selector;
85
86   char *inp; /* alloced input */
87
88   char *input; /* pointer to input + trigger */
89   /* all available plugins for current state */
90   Eina_List   *plugins;
91
92   /* currently active plugins, i.e. those that provide items */
93   Eina_List   *cur_plugins;
94
95   /* active plugin */
96   Evry_Plugin *plugin;
97
98   /* aggregator instance */
99   Evry_Plugin *aggregator;
100
101   /* selected item */
102   Evry_Item   *cur_item;
103
104   /* marked items */
105   Eina_List   *sel_items;
106
107   Eina_Bool plugin_auto_selected;
108   Eina_Bool item_auto_selected;
109
110   /* current view instance */
111   Evry_View *view;
112
113   Eina_Bool changed;
114   Eina_Bool trigger_active;
115
116   unsigned int request;
117
118   Ecore_Timer *clear_timer;
119
120   Eina_Bool delete_me;
121 };
122
123 struct _Evry_View
124 {
125   Evry_View  *id;
126   const char *name;
127   const char *trigger;
128   int active;
129   Evas_Object *o_list;
130   Evas_Object *o_bar;
131
132   Evry_View *(*create) (Evry_View *view, const Evry_State *s, const Evas_Object *swallow);
133   void (*destroy)      (Evry_View *view);
134   int  (*cb_key_down)  (Evry_View *view, const Ecore_Event_Key *ev);
135   int  (*update)       (Evry_View *view);
136   void (*clear)        (Evry_View *view);
137
138   int priority;
139
140   Evry_State *state;
141 };
142
143 struct _Tab_View
144 {
145   const Evry_State *state;
146
147   Evry_View *view;
148   Evas *evas;
149
150   Evas_Object *o_tabs;
151   Eina_List *tabs;
152
153   void (*update) (Tab_View *tv);
154   void (*clear) (Tab_View *tv);
155   int (*key_down) (Tab_View *tv, const Ecore_Event_Key *ev);
156
157   double align;
158   double align_to;
159   Ecore_Animator *animator;
160   Ecore_Timer *timer;
161 };
162
163 struct _Config
164 {
165   int version;
166   /* position */
167   double rel_x, rel_y;
168   /* size */
169   int width, height;
170   int edge_width, edge_height;
171
172   Eina_List *modules;
173
174   /* generic plugin config */
175   Eina_List *conf_subjects;
176   Eina_List *conf_actions;
177   Eina_List *conf_objects;
178   Eina_List *conf_views;
179   Eina_List *collections;
180
181   int scroll_animate;
182   double scroll_speed;
183
184   int hide_input;
185   int hide_list;
186
187   /* quick navigation mode */
188   int quick_nav;
189
190   /* default view mode */
191   int view_mode;
192   int view_zoom;
193
194   int history_sort_mode;
195
196   /* use up/down keys for prev/next in thumb view */
197   int cycle_mode;
198
199   unsigned char first_run;
200
201   /* not saved data */
202   Eina_List *actions;
203   Eina_List *views;
204
205   int min_w, min_h;
206 };
207
208 struct _History
209 {
210   int version;
211   Eina_Hash *subjects;
212   double begin;
213 };
214
215 /*** Evry_Api functions ***/
216 void  evry_item_select(const Evry_State *s, Evry_Item *it);
217 void  evry_item_mark(const Evry_State *state, Evry_Item *it, Eina_Bool mark);
218 void  evry_plugin_select(Evry_Plugin *p);
219 Evry_Item *evry_item_new(Evry_Item *base, Evry_Plugin *p, const char *label,
220                               Evas_Object *(*icon_get) (Evry_Item *it, Evas *e),
221                               void (*cb_free) (Evry_Item *item));
222 void  evry_item_free(Evry_Item *it);
223 void  evry_item_ref(Evry_Item *it);
224
225 void  evry_plugin_update(Evry_Plugin *plugin, int state);
226 void  evry_clear_input(Evry_Plugin *p);
227
228 /* evry_util.c */
229 Evas_Object *evry_icon_mime_get(const char *mime, Evas *e);
230 Evas_Object *evry_icon_theme_get(const char *icon, Evas *e);
231 int   evry_fuzzy_match(const char *str, const char *match);
232 Eina_List *evry_fuzzy_match_sort(Eina_List *items);
233 int   evry_util_exec_app(const Evry_Item *it_app, const Evry_Item *it_file);
234 char *evry_util_url_escape(const char *string, int inlength);
235 char *evry_util_url_unescape(const char *string, int length);
236 void  evry_util_file_detail_set(Evry_Item_File *file);
237 int   evry_util_module_config_check(const char *module_name, int conf, int epoch, int version);
238 Evas_Object *evry_util_icon_get(Evry_Item *it, Evas *e);
239 int   evry_util_plugin_items_add(Evry_Plugin *p, Eina_List *items, const char *input, int match_detail, int set_usage);
240 int   evry_items_sort_func(const void *data1, const void *data2);
241 void  evry_item_changed(Evry_Item *it, int change_icon, int change_selected);
242 char *evry_util_md5_sum(const char *str);
243
244 const char *evry_file_path_get(Evry_Item_File *file);
245 const char *evry_file_url_get(Evry_Item_File *file);
246
247 int   evry_plugin_register(Evry_Plugin *p, int type, int priority);
248 void  evry_plugin_unregister(Evry_Plugin *p);
249 Evry_Plugin *evry_plugin_find(const char *name);
250 void  evry_action_register(Evry_Action *act, int priority);
251 void  evry_action_unregister(Evry_Action *act);
252 void  evry_view_register(Evry_View *view, int priority);
253 void  evry_view_unregister(Evry_View *view);
254 Evry_Action *evry_action_find(const char *name);
255
256 void  evry_history_load(void);
257 void  evry_history_unload(void);
258 History_Item *evry_history_item_add(Evry_Item *it, const char *ctxt, const char *input);
259 int   evry_history_item_usage_set(Evry_Item *it, const char *input, const char *ctxt);
260 History_Types *evry_history_types_get(Evry_Type type);
261
262 Evry_Plugin *evry_plugin_new(Evry_Plugin *base, const char *name, const char *label, const char *icon,
263                              Evry_Type item_type,
264                              Evry_Plugin *(*begin) (Evry_Plugin *p, const Evry_Item *item),
265                              void (*cleanup) (Evry_Plugin *p),
266                              int  (*fetch)   (Evry_Plugin *p, const char *input),
267                              void (*free) (Evry_Plugin *p));
268
269 void  evry_plugin_free(Evry_Plugin *p);
270
271 Evry_Action *evry_action_new(const char *name, const char *label,
272                              Evry_Type type1, Evry_Type type2,
273                              const char *icon,
274                              int  (*action)     (Evry_Action *act),
275                              int  (*check_item) (Evry_Action *act, const Evry_Item *it));
276
277 void  evry_action_free(Evry_Action *act);
278
279 int   evry_api_version_check(int version);
280
281 Evry_Type evry_type_register(const char *type);
282 const char *evry_type_get(Evry_Type type);
283
284 /*** internal ***/
285 Tab_View *evry_tab_view_new(Evry_View *view, const Evry_State *s, Evas *e);
286 void  evry_tab_view_free(Tab_View *v);
287
288 Eina_Bool evry_view_init(void);
289 void  evry_view_shutdown(void);
290
291 Eina_Bool evry_view_help_init(void);
292 void  evry_view_help_shutdown(void);
293
294 Eina_Bool evry_plug_clipboard_init(void);
295 void  evry_plug_clipboard_shutdown(void);
296
297 Eina_Bool evry_plug_text_init(void);
298 void  evry_plug_text_shutdown(void);
299
300 Eina_Bool evry_plug_collection_init(void);
301 void  evry_plug_collection_shutdown(void);
302
303 int   evry_init(void);
304 int   evry_shutdown(void);
305 Evry_Window *evry_show(E_Zone *zone, E_Zone_Edge edge, const char *params);
306 void  evry_hide(Evry_Window *win, int clear);
307
308 int   evry_plug_actions_init();
309 void  evry_plug_actions_shutdown();
310
311 Evry_Plugin *evry_aggregator_new(Evry_Window *win, int type);
312
313 void  evry_history_init(void);
314 void  evry_history_free(void);
315
316 int   evry_browse_item(Evry_Item *it);
317 int   evry_browse_back(Evry_Selector *sel);
318
319 void  evry_plugin_action(Evry_Window *win, int finished);
320
321 int   evry_state_push(Evry_Selector *sel, Eina_List *plugins);
322 int   evry_selectors_switch(Evry_Window *win,int dir, int slide);
323 int   evry_view_toggle(Evry_State *s, const char *trigger);
324
325 int evry_gadget_init(void);
326 void evry_gadget_shutdown(void);
327
328 Eina_Bool evry_plug_apps_init(E_Module *m);
329 void evry_plug_apps_shutdown(void);
330 void evry_plug_apps_save(void);
331
332 Eina_Bool evry_plug_files_init(E_Module *m);
333 void evry_plug_files_shutdown(void);
334 void evry_plug_files_save(void);
335
336 Eina_Bool evry_plug_windows_init(E_Module *m);
337 void evry_plug_windows_shutdown(void);
338 void evry_plug_windows_save(void);
339
340 Eina_Bool evry_plug_settings_init(E_Module *m);
341 void evry_plug_settings_shutdown(void);
342 void evry_plug_settings_save(void);
343
344 Eina_Bool evry_plug_calc_init(E_Module *m);
345 void evry_plug_calc_shutdown(void);
346 void evry_plug_calc_save(void);
347
348 Ecore_Event_Handler *evry_event_handler_add(int type, Eina_Bool (*func) (void *data, int type, void *event), const void *data);
349
350 extern Evry_History *evry_hist;
351 extern Evry_Config  *evry_conf;
352 extern int  _evry_events[NUM_EVRY_EVENTS];
353
354 #define EVRY_ITEM_NEW(_base, _plugin, _label, _icon_get, _free)         \
355   (_base *) evry_item_new(EVRY_ITEM(E_NEW(_base, 1)), EVRY_PLUGIN(_plugin), \
356                           _label, _icon_get, _free)
357
358 #define EVRY_ITEM_FREE(_item) evry_item_free((Evry_Item *)_item)
359 #define EVRY_ITEM_REF(_item) evry_item_ref((Evry_Item *)_item)
360
361 #define EVRY_PLUGIN_NEW(_base, _name, _icon, _item_type, _begin, _cleanup, _fetch, _free) \
362   evry_plugin_new(EVRY_PLUGIN(E_NEW(_base, 1)), _name, _(_name), _icon, _item_type, \
363                   _begin, _cleanup, _fetch, _free)
364
365 #define EVRY_ACTION_NEW(_name, _in1, _in2, _icon, _action, _check)      \
366   evry_action_new(_name, _(_name), _in1, _in2, _icon, _action, _check)
367
368 #define EVRY_PLUGIN_FREE(_p)                    \
369   if (_p) evry_plugin_free(EVRY_PLUGIN(_p))
370
371 #define EVRY_PLUGIN_UPDATE(_p, _action)                 \
372   if (_p) evry_plugin_update(EVRY_PLUGIN(_p), _action)
373
374 #define EVRY_PLUGIN_ITEMS_FREE(_p) {            \
375      Evry_Item *it;                             \
376      EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, it) \
377        evry_item_free(it); }
378
379 #define EVRY_PLUGIN_ITEMS_ADD(_plugin, _items, _input, _match_detail, _set_usage) \
380   evry_util_plugin_items_add(EVRY_PLUGIN(_plugin), _items, _input, _match_detail, _set_usage)
381
382 /*** E Module ***/
383 EAPI void *e_modapi_init     (E_Module *m);
384 EAPI int   e_modapi_shutdown (E_Module *m);
385 EAPI int   e_modapi_save     (E_Module *m);
386 EAPI E_Config_Dialog *evry_config_dialog(E_Container *con, const char *params);
387 EAPI E_Config_Dialog *evry_collection_conf_dialog(E_Container *con, const char *params);
388 EAPI extern E_Module_Api e_modapi;
389
390 /*** Common Logging  ***/
391 extern int _e_module_evry_log_dom;
392
393 #ifndef EINA_LOG_DEFAULT_COLOR
394 #define EINA_LOG_DEFAULT_COLOR EINA_COLOR_CYAN
395 #endif
396
397 #undef DBG
398 #undef INF
399 #undef WRN
400 #undef ERR
401
402 #define DBG(...) EINA_LOG_DOM_DBG(_e_module_evry_log_dom, __VA_ARGS__)
403 #define INF(...) EINA_LOG_DOM_INFO(_e_module_evry_log_dom, __VA_ARGS__)
404 #define WRN(...) EINA_LOG_DOM_WARN(_e_module_evry_log_dom, __VA_ARGS__)
405 #define ERR(...) EINA_LOG_DOM_ERR(_e_module_evry_log_dom, __VA_ARGS__)
406
407 //#define CHECK_REFS 1
408 //#define CHECK_TIME 1
409 //#undef DBG
410 //#define DBG(...) ERR(__VA_ARGS__)
411
412 #ifdef CHECK_REFS
413 extern Eina_List *_refd;
414 #endif
415
416 #ifdef CHECK_TIME
417 extern double _evry_time;
418 #endif
419
420 #endif