summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Friloux <kuri@efl.so>2014-01-02 19:06:59 +0100
committerGuillaume Friloux <kuri@efl.so>2014-01-02 19:06:59 +0100
commit2be2c827fd3e0d704e318bef04c44b8ac16f9317 (patch)
tree6e30874b8d94a4e6e94dd5b766c2d2988962e003
parent10509bc7b3803b8a807306987d6e5cca82206397 (diff)
Slowly writing loading of desktop files.
-rw-r--r--src/include/Vog.h7
-rw-r--r--src/lib/vog_event.c48
-rw-r--r--src/lib/vog_main.c58
-rw-r--r--src/lib/vog_private.h17
4 files changed, 129 insertions, 1 deletions
diff --git a/src/include/Vog.h b/src/include/Vog.h
index c29b787..9f32448 100644
--- a/src/include/Vog.h
+++ b/src/include/Vog.h
@@ -4,8 +4,15 @@
4#include <Ecore.h> 4#include <Ecore.h>
5#include <Efreet.h> 5#include <Efreet.h>
6 6
7extern int VOG_EVENT_GAME_ADD;
8extern int VOG_EVENT_GAME_DEL;
9extern int VOG_EVENT_GAME_UPD;
10
7typedef struct _Vog Vog; 11typedef struct _Vog Vog;
8 12
9int vog_init(void); 13int vog_init(void);
10int vog_shutdown(void); 14int vog_shutdown(void);
15
16Vog * vog_new(void);
17void vog_free(Vog *vog);
11#endif 18#endif
diff --git a/src/lib/vog_event.c b/src/lib/vog_event.c
new file mode 100644
index 0000000..d1ebe8d
--- /dev/null
+++ b/src/lib/vog_event.c
@@ -0,0 +1,48 @@
1#include "vog_private.h"
2
3
4Eina_Bool
5vog_event_filter_cb(void *data EINA_UNUSED,
6 Eio_File *handler EINA_UNUSED,
7 const Eina_File_Direct_Info *info EINA_UNUSED)
8{
9 return EINA_TRUE;
10}
11
12Eina_Bool
13vog_event_main_cb(void *data,
14 Eio_File *handler EINA_UNUSED,
15 const Eina_File_Direct_Info *info)
16{
17 Vog *vog;
18 Efreet_Desktop *ed;
19
20 vog = data;
21
22 DBG("vog[%p] info[%p][%s]", vog, info, info->path);
23
24 ed = efreet_desktop_get(info->path);
25 if (!ed)
26 {
27 ERR("Failed to load desktop file %s", info->path);
28 return EINA_TRUE;
29 }
30
31 return EINA_TRUE;
32}
33
34void
35vog_event_done_cb(void *data,
36 Eio_File *handler)
37{
38
39}
40
41void
42vog_event_error_cb(void *data,
43 Eio_File *handler,
44 int error)
45{
46
47}
48
diff --git a/src/lib/vog_main.c b/src/lib/vog_main.c
index 9759927..cce776f 100644
--- a/src/lib/vog_main.c
+++ b/src/lib/vog_main.c
@@ -4,7 +4,21 @@ static int _vog_init_count = 0;
4int _vog_log_dom_global = -1; 4int _vog_log_dom_global = -1;
5 5
6int VOG_EVENT_GAME_ADD = 0, 6int VOG_EVENT_GAME_ADD = 0,
7 VOG_EVENT_GAME_DEL = 0; 7 VOG_EVENT_GAME_DEL = 0,
8 VOG_EVENT_GAME_UPD = 0;
9
10void
11vog_free(Vog *vog)
12{
13 EINA_SAFETY_ON_NULL_RETURN(vog);
14
15 if (vog->ev.efc) ecore_event_handler_del(vog->ev.efc);
16 if (vog->ev.efd) ecore_event_handler_del(vog->ev.efd);
17 if (vog->ev.efm) ecore_event_handler_del(vog->ev.efm);
18 if (vog->ev.desktopdir) eio_monitor_del(vog->ev.desktopdir);
19 eina_dstringshare_replace(&vog->dir.desktop, NULL);
20 free(vog);
21}
8 22
9Vog * 23Vog *
10vog_new(void) 24vog_new(void)
@@ -18,9 +32,50 @@ vog_new(void)
18 return NULL; 32 return NULL;
19 } 33 }
20 34
35 vog->dir.desktop = eina_stringshare_add(PKG_DATA_DIR"/games/");
36 if (!vog->dir.desktop)
37 {
38 ERR("Failed to allocate vog->dir.desktop!");
39 goto vog_free;
40 }
41
42
21 /* Put inotify code */ 43 /* Put inotify code */
44 vog->ev.desktopdir = eio_monitor_add(vog->dir.desktop);
45 if (!vog->ev.desktopdir)
46 {
47 ERR("Failed to put monitor on %s", vog->dir.desktop);
48 goto vog_free_desktopdir;
49 }
50
51#define _MON(_a, _b, _c, _d) \
52 _a = ecore_event_handler_add(EIO_MONITOR_##_b, _c, _d);
53 _MON(vog->ev.efc, FILE_CREATED, vog_event_action, vog);
54 _MON(vog->ev.efd, FILE_DELETED, vog_event_action, vog);
55 _MON(vog->ev.efm, FILE_MODIFIED, vog_event_action, vog);
56#undef _MON
57
58 if ((!vog->ev.efc) || (!vog->ev.efd) || (!vog->ev.efm))
59 goto vog_events_del
60
61 eio_file_direct_ls(vog->dir.desktop,
62 vog_event_filter_cb,
63 vog_event_main_cb,
64 vog_event_done_cb,
65 vog_event_error_cb,
66 vog);
22 67
23 return vog; 68 return vog;
69vog_events_del
70 if (vog->ev.efc) ecore_event_handler_del(vog->ev.efc);
71 if (vog->ev.efd) ecore_event_handler_del(vog->ev.efd);
72 if (vog->ev.efm) ecore_event_handler_del(vog->ev.efm);
73 if (vog->ev.desktopdir) eio_monitor_del(vog->ev.desktopdir);
74vog_free_desktopdir:
75 eina_dstringshare_replace(&vog->dir.desktop, NULL);
76vog_free:
77 free(vog);
78 return NULL;
24} 79}
25 80
26int 81int
@@ -56,6 +111,7 @@ vog_init(void)
56 111
57 VOG_EVENT_GAME_ADD = ecore_event_type_new(); 112 VOG_EVENT_GAME_ADD = ecore_event_type_new();
58 VOG_EVENT_GAME_DEL = ecore_event_type_new(); 113 VOG_EVENT_GAME_DEL = ecore_event_type_new();
114 VOG_EVENT_GAME_UPD = ecore_event_type_new();
59 115
60 return _vog_init_count; 116 return _vog_init_count;
61 117
diff --git a/src/lib/vog_private.h b/src/lib/vog_private.h
index 4751c4e..5b6b4c3 100644
--- a/src/lib/vog_private.h
+++ b/src/lib/vog_private.h
@@ -2,6 +2,23 @@
2 2
3struct _Vog 3struct _Vog
4{ 4{
5 struct
6 {
7 const char *desktop;
8 } dir;
5 9
10 struct
11 {
12 Eio_Monitor *desktopdir;
13 Ecore_Event_Handler *efc,
14 *efd,
15 *efm;
16 } ev;
6 17
7} Vog; 18} Vog;
19
20
21Eina_Bool vog_event_filter_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info);
22Eina_Bool vog_event_main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info);
23void vog_event_done_cb(void *data, Eio_File *handler);
24void vog_event_error_cb(void *data, Eio_File *handler, int error);