summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Friloux <kuri@efl.so>2014-01-26 19:30:48 +0100
committerGuillaume Friloux <kuri@efl.so>2014-01-26 19:30:48 +0100
commit9f64736b0563b2fa453b59eeab2712a4b8d0e2f8 (patch)
tree88f42c800a383906c173caf8c4f3090723dc9720
parent64f06a459a73f9d627ee86fbfb04a3f4dcc7d335 (diff)
Make libVOG able to detect deletion of games.HEADmaster
Added few GUI stuff (not working).
-rw-r--r--configure.ac2
-rw-r--r--src/bin/launcher.h9
-rw-r--r--src/bin/main.c42
-rw-r--r--src/include/Vog.h3
-rw-r--r--src/lib/vog_event.c94
-rw-r--r--src/lib/vog_main.c78
-rw-r--r--src/lib/vog_private.h2
7 files changed, 188 insertions, 42 deletions
diff --git a/configure.ac b/configure.ac
index 923d4ab..f9bc1b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,7 @@ PKG_CHECK_MODULES(LIBS, [$LIBS_REQUIRES], [build_libs=yes], [build_libs=no])
52 52
53build_vog= 53build_vog=
54if test "x${build_libs}" = "xyes"; then 54if test "x${build_libs}" = "xyes"; then
55 BIN_REQUIRES="${LIBS_REQUIRES}" 55 BIN_REQUIRES="${LIBS_REQUIRES} elementary"
56 PKG_CHECK_MODULES(BIN, [$BIN_REQUIRES], [build_vog=yes], [build_vog=no]) 56 PKG_CHECK_MODULES(BIN, [$BIN_REQUIRES], [build_vog=yes], [build_vog=no])
57else 57else
58 build_vog=no 58 build_vog=no
diff --git a/src/bin/launcher.h b/src/bin/launcher.h
index f36f010..0afe070 100644
--- a/src/bin/launcher.h
+++ b/src/bin/launcher.h
@@ -1,6 +1,7 @@
1#include <Eina.h> 1#include <Eina.h>
2#include <Ecore.h> 2#include <Ecore.h>
3#include <Vog.h> 3#include <Vog.h>
4#include <Elementary.h>
4 5
5typedef struct _Launcher 6typedef struct _Launcher
6{ 7{
@@ -10,6 +11,14 @@ typedef struct _Launcher
10 { 11 {
11 Ecore_Event_Handler *vega; /* VOG_EVENT_GAME_ADD */ 12 Ecore_Event_Handler *vega; /* VOG_EVENT_GAME_ADD */
12 } ev; 13 } ev;
14
15 struct
16 {
17 Evas_Object *win,
18 *bg,
19 *table,
20 *sc;
21 } gui;
13} Launcher; 22} Launcher;
14 23
15int l_log_dom_global; 24int l_log_dom_global;
diff --git a/src/bin/main.c b/src/bin/main.c
index 814c0ad..5c37f2a 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -1,5 +1,14 @@
1#include "launcher.h" 1#include "launcher.h"
2 2
3static void
4launcher_quit(void *data EINA_UNUSED,
5 Evas_Object *obj EINA_UNUSED,
6 void *event_info EINA_UNUSED)
7{
8 elm_exit();
9}
10
11
3Eina_Bool 12Eina_Bool
4launcher_game_add(void *data, 13launcher_game_add(void *data,
5 int type EINA_UNUSED, 14 int type EINA_UNUSED,
@@ -16,7 +25,8 @@ launcher_game_add(void *data,
16 return EINA_TRUE; 25 return EINA_TRUE;
17} 26}
18 27
19int main(int argc EINA_UNUSED, char **argv EINA_UNUSED) 28EAPI_MAIN int
29elm_main(int argc, char **argv)
20{ 30{
21 Launcher *launcher; 31 Launcher *launcher;
22 32
@@ -31,10 +41,38 @@ int main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
31 launcher->ev.vega = ecore_event_handler_add(VOG_EVENT_GAME_ADD, 41 launcher->ev.vega = ecore_event_handler_add(VOG_EVENT_GAME_ADD,
32 launcher_game_add, 42 launcher_game_add,
33 launcher); 43 launcher);
34 ecore_main_loop_begin();
35 44
45 launcher->gui.win = elm_win_util_standard_add("Vog", "Vog");
46 evas_object_smart_callback_add(launcher->gui.win, "delete,request",
47 launcher_quit, launcher);
48
49 launcher->gui.bg = elm_bg_add(launcher->gui.win);
50 evas_object_size_hint_weight_set(launcher->gui.bg,
51 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
52 elm_win_resize_object_add(launcher->gui.win, launcher->gui.bg);
53 evas_object_show(launcher->gui.bg);
54
55 launcher->gui.sc = elm_scroller_add(launcher->gui.win);
56 elm_scroller_bounce_set(launcher->gui.sc, EINA_TRUE, EINA_FALSE);
57 elm_scroller_policy_set(launcher->gui.sc,
58 ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
59 evas_object_size_hint_weight_set(launcher->gui.sc,
60 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61 evas_object_size_hint_fill_set(launcher->gui.sc,
62 EVAS_HINT_FILL, EVAS_HINT_FILL);
63
64 launcher->gui.table = elm_table_add(launcher->gui.win);
65 elm_win_resize_object_add(launcher->gui.win, launcher->gui.table);
66 evas_object_show(launcher->gui.table);
67 elm_table_padding_set(launcher->gui.table, 5, 5);
68 elm_table_homogeneous_set(launcher->gui.table, EINA_TRUE);
69
70 evas_object_show(launcher->gui.win);
71 elm_run();
72 elm_shutdown();
36 vog_shutdown(); 73 vog_shutdown();
37 ecore_shutdown(); 74 ecore_shutdown();
38 eina_shutdown(); 75 eina_shutdown();
39 return 0; 76 return 0;
40} 77}
78ELM_MAIN()
diff --git a/src/include/Vog.h b/src/include/Vog.h
index 37b3695..23e68bc 100644
--- a/src/include/Vog.h
+++ b/src/include/Vog.h
@@ -26,4 +26,7 @@ int vog_shutdown(void);
26 26
27Vog * vog_new(void); 27Vog * vog_new(void);
28void vog_free(Vog *vog); 28void vog_free(Vog *vog);
29
30Vog_Game * vog_game_new(const char *path);
31void vog_game_free(Vog_Game *vg);
29#endif 32#endif
diff --git a/src/lib/vog_event.c b/src/lib/vog_event.c
index 603556a..69b2139 100644
--- a/src/lib/vog_event.c
+++ b/src/lib/vog_event.c
@@ -2,10 +2,24 @@
2#include <string.h> 2#include <string.h>
3 3
4void 4void
5_vog_event_game_free(void *d1 EINA_UNUSED, 5_vog_event_game_fake_free(void *d1 EINA_UNUSED,
6 void *d2 EINA_UNUSED) 6 void *d2 EINA_UNUSED)
7{} 7{}
8 8
9void
10_vog_event_game_free(void *d1,
11 void *d2)
12{
13 Vog *vog;
14 Vog_Game *vg;
15
16 vg = d1;
17 vog = d2;
18
19 eina_hash_del(vog->games, NULL, vg);
20 vog_game_free(vg);
21}
22
9Eina_Bool 23Eina_Bool
10vog_event_filter_cb(void *data EINA_UNUSED, 24vog_event_filter_cb(void *data EINA_UNUSED,
11 Eio_File *handler EINA_UNUSED, 25 Eio_File *handler EINA_UNUSED,
@@ -21,42 +35,17 @@ vog_event_main_cb(void *data,
21{ 35{
22 Vog *vog; 36 Vog *vog;
23 Vog_Game *vg; 37 Vog_Game *vg;
24 Efreet_Desktop *ed;
25 38
26 vog = data; 39 vog = data;
27
28 DBG("vog[%p] info[%p][%s]", vog, info, info->path); 40 DBG("vog[%p] info[%p][%s]", vog, info, info->path);
29 41
30 ed = efreet_desktop_get(info->path); 42 vg = vog_game_new(info->path);
31 if (!ed)
32 {
33 ERR("Failed to load desktop file %s", info->path);
34 return;
35 }
36
37 vg = calloc(1, sizeof(Vog_Game));
38 if (!vg) 43 if (!vg)
39 { 44 return;
40 ERR("Failed to allocate Vog_Game structure");
41 goto ed_free;
42 }
43
44 vg->ed = ed;
45 vg->name = strdup(ed->name);
46 if (!vg->name)
47 {
48 ERR("Failed to allocate vg->name");
49 goto vg_free;
50 }
51
52 ecore_event_add(VOG_EVENT_GAME_ADD, vg, _vog_event_game_free, NULL);
53 45
46 eina_hash_add(vog->games, info->path, vg);
47 ecore_event_add(VOG_EVENT_GAME_ADD, vg, _vog_event_game_fake_free, NULL);
54 return; 48 return;
55
56vg_free:
57 free(vg);
58ed_free:
59 efreet_desktop_free(ed);
60} 49}
61 50
62void 51void
@@ -82,9 +71,46 @@ vog_event_error_cb(void *data,
82} 71}
83 72
84Eina_Bool 73Eina_Bool
85vog_event_action(void *data EINA_UNUSED, 74vog_event_action(void *data,
86 int type EINA_UNUSED, 75 int type,
87 void *event EINA_UNUSED) 76 void *event)
88{ 77{
78 Vog *vog;
79 Vog_Game *vg = NULL;
80 Eio_Monitor_Event *eme;
81 void *func = NULL;
82 int nevt = 0;
83
84 vog = data;
85 eme = event;
86 DBG("vog[%p] event[%p]", vog, eme);
87
88 if (type == EIO_MONITOR_FILE_CREATED)
89 {
90 vg = vog_game_new(eme->filename);
91 if (!vg)
92 return EINA_TRUE;
93
94 nevt = VOG_EVENT_GAME_ADD;
95 func = _vog_event_game_fake_free;
96 eina_hash_add(vog->games, eme->filename, vg);
97 }
98 else if (type == EIO_MONITOR_FILE_CLOSED)
99 {
100 }
101 else if (type == EIO_MONITOR_FILE_DELETED)
102 {
103 vg = eina_hash_find(vog->games, eme->filename);
104 if (!vg)
105 return EINA_TRUE;
106 DBG("vg[%p] Deleted game", vg);
107
108 nevt = VOG_EVENT_GAME_DEL;
109 func = _vog_event_game_free;
110 }
111 else
112 return EINA_TRUE;
113
114 ecore_event_add(nevt, vg, func, vog);
89 return EINA_TRUE; 115 return EINA_TRUE;
90} 116}
diff --git a/src/lib/vog_main.c b/src/lib/vog_main.c
index 2326f2e..f3fe6e9 100644
--- a/src/lib/vog_main.c
+++ b/src/lib/vog_main.c
@@ -7,15 +7,79 @@ int VOG_EVENT_GAME_ADD = 0,
7 VOG_EVENT_GAME_DEL = 0, 7 VOG_EVENT_GAME_DEL = 0,
8 VOG_EVENT_GAME_UPD = 0; 8 VOG_EVENT_GAME_UPD = 0;
9 9
10static void
11_vog_games_free_cb(void *data)
12{
13 Vog_Game *vg;
14
15 EINA_SAFETY_ON_NULL_RETURN(data);
16
17 vg = data;
18 vog_game_free(vg);
19}
20
21void
22vog_game_free(Vog_Game *vg)
23{
24 EINA_SAFETY_ON_NULL_RETURN(vg);
25
26 free((char *)vg->name);
27 free((char *)vg->description);
28 eina_stringshare_replace(&vg->genre, NULL);
29 efreet_desktop_free(vg->ed);
30 free(vg);
31}
32
33Vog_Game *
34vog_game_new(const char *path)
35{
36 Vog_Game *vg;
37 Efreet_Desktop *ed;
38
39 EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL);
40
41 ed = efreet_desktop_get(path);
42 if (!ed)
43 {
44 ERR("Failed to load desktop file %s", path);
45 return NULL;
46 }
47
48 vg = calloc(1, sizeof(Vog_Game));
49 if (!vg)
50 {
51 ERR("Failed to allocate Vog_Game structure");
52 goto ed_free;
53 }
54
55
56 vg->ed = ed;
57 vg->name = strdup(ed->name);
58 if (!vg->name)
59 {
60 ERR("Failed to allocate vg->name");
61 goto vg_free;
62 }
63
64 return vg;
65
66vg_free:
67 free(vg);
68ed_free:
69 efreet_desktop_free(ed);
70return NULL;
71}
72
10void 73void
11vog_free(Vog *vog) 74vog_free(Vog *vog)
12{ 75{
13 EINA_SAFETY_ON_NULL_RETURN(vog); 76 EINA_SAFETY_ON_NULL_RETURN(vog);
14 77
15 if (vog->ev.efc) ecore_event_handler_del(vog->ev.efc); 78 eina_hash_free(vog->games);
16 if (vog->ev.efd) ecore_event_handler_del(vog->ev.efd); 79 ecore_event_handler_del(vog->ev.efc);
17 if (vog->ev.efm) ecore_event_handler_del(vog->ev.efm); 80 ecore_event_handler_del(vog->ev.efd);
18 if (vog->ev.desktopdir) eio_monitor_del(vog->ev.desktopdir); 81 ecore_event_handler_del(vog->ev.efm);
82 eio_monitor_del(vog->ev.desktopdir);
19 eina_stringshare_replace(&vog->dir.desktop, NULL); 83 eina_stringshare_replace(&vog->dir.desktop, NULL);
20 free(vog); 84 free(vog);
21} 85}
@@ -52,12 +116,16 @@ vog_new(void)
52 _a = ecore_event_handler_add(EIO_MONITOR_##_b, _c, _d); 116 _a = ecore_event_handler_add(EIO_MONITOR_##_b, _c, _d);
53 _MON(vog->ev.efc, FILE_CREATED, vog_event_action, vog); 117 _MON(vog->ev.efc, FILE_CREATED, vog_event_action, vog);
54 _MON(vog->ev.efd, FILE_DELETED, vog_event_action, vog); 118 _MON(vog->ev.efd, FILE_DELETED, vog_event_action, vog);
55 _MON(vog->ev.efm, FILE_MODIFIED, vog_event_action, vog); 119 _MON(vog->ev.efm, FILE_CLOSED, vog_event_action, vog);
56#undef _MON 120#undef _MON
57 121
58 if ((!vog->ev.efc) || (!vog->ev.efd) || (!vog->ev.efm)) 122 if ((!vog->ev.efc) || (!vog->ev.efd) || (!vog->ev.efm))
59 goto vog_events_del; 123 goto vog_events_del;
60 124
125 vog->games = eina_hash_string_superfast_new(_vog_games_free_cb);
126 if (!vog->games)
127 goto vog_events_del;
128
61 eio_file_direct_ls(vog->dir.desktop, 129 eio_file_direct_ls(vog->dir.desktop,
62 vog_event_filter_cb, 130 vog_event_filter_cb,
63 vog_event_main_cb, 131 vog_event_main_cb,
diff --git a/src/lib/vog_private.h b/src/lib/vog_private.h
index 37018e9..58b50fc 100644
--- a/src/lib/vog_private.h
+++ b/src/lib/vog_private.h
@@ -2,6 +2,8 @@
2 2
3struct _Vog 3struct _Vog
4{ 4{
5 Eina_Hash *games;
6
5 struct 7 struct
6 { 8 {
7 const char *desktop; 9 const char *desktop;