summaryrefslogtreecommitdiff
path: root/src/lib/vog_event.c
blob: 69b213969a380086ee5c60e425f04389438e1f4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "vog_private.h"
#include <string.h>

void
_vog_event_game_fake_free(void *d1 EINA_UNUSED,
                          void *d2 EINA_UNUSED)
{}

void
_vog_event_game_free(void *d1,
                     void *d2)
{
   Vog *vog;
   Vog_Game *vg;

   vg = d1;
   vog = d2;

   eina_hash_del(vog->games, NULL, vg);
   vog_game_free(vg);
}

Eina_Bool
vog_event_filter_cb(void *data EINA_UNUSED,
                    Eio_File *handler EINA_UNUSED,
                    const Eina_File_Direct_Info *info EINA_UNUSED)
{
   return EINA_TRUE;
}

void
vog_event_main_cb(void *data,
                  Eio_File *handler EINA_UNUSED,
                  const Eina_File_Direct_Info *info)
{
   Vog *vog;
   Vog_Game *vg;

   vog = data;
   DBG("vog[%p] info[%p][%s]", vog, info, info->path);

   vg = vog_game_new(info->path);
   if (!vg)
     return;

   eina_hash_add(vog->games, info->path, vg);
   ecore_event_add(VOG_EVENT_GAME_ADD, vg, _vog_event_game_fake_free, NULL);
   return;
}

void
vog_event_done_cb(void *data,
                  Eio_File *handler EINA_UNUSED)
{
   Vog *vog;

   vog = data;

   DBG("vog[%p]", vog);
}

void
vog_event_error_cb(void *data,
                   Eio_File *handler EINA_UNUSED,
                   int error)
{
   Vog *vog;

   vog = data;
   ERR("vog[%p] : Failed to load desktop directory : %s", vog, strerror(error));
}

Eina_Bool
vog_event_action(void *data,
                 int type,
                 void *event)
{
   Vog *vog;
   Vog_Game *vg = NULL;
   Eio_Monitor_Event *eme;
   void *func = NULL;
   int nevt = 0;

   vog = data;
   eme = event;
   DBG("vog[%p] event[%p]", vog, eme);

   if (type == EIO_MONITOR_FILE_CREATED)
     {
        vg = vog_game_new(eme->filename);
        if (!vg)
          return EINA_TRUE;

        nevt = VOG_EVENT_GAME_ADD;
        func = _vog_event_game_fake_free;
        eina_hash_add(vog->games, eme->filename, vg);
     }
   else if (type == EIO_MONITOR_FILE_CLOSED)
     {
     }
   else if (type == EIO_MONITOR_FILE_DELETED)
     {
        vg = eina_hash_find(vog->games, eme->filename);
        if (!vg)
          return EINA_TRUE;
        DBG("vg[%p] Deleted game", vg);

        nevt = VOG_EVENT_GAME_DEL;
        func = _vog_event_game_free;
     }
   else
     return EINA_TRUE;

   ecore_event_add(nevt, vg, func, vog);
   return EINA_TRUE;
}