diff options
author | Cedric BAIL <cedric.bail@free.fr> | 2011-06-29 17:30:19 +0000 |
---|---|---|
committer | Cedric BAIL <cedric.bail@free.fr> | 2011-06-29 17:30:19 +0000 |
commit | 45d0b3400740927e68f28fc6f5c1db65c9a48743 (patch) | |
tree | 1800308f9304f34de5db9bdeceeaa3e50e54d0c2 /legacy/emotion/src/lib/emotion_smart.c | |
parent | 73edb0433fe2696d2eaf9b51340de94f6f9cfc45 (diff) |
emotion: restore/save last know position for file.
SVN revision: 60825
Diffstat (limited to '')
-rw-r--r-- | legacy/emotion/src/lib/emotion_smart.c | 216 |
1 files changed, 185 insertions, 31 deletions
diff --git a/legacy/emotion/src/lib/emotion_smart.c b/legacy/emotion/src/lib/emotion_smart.c index c9451d30de..c84d60c513 100644 --- a/legacy/emotion/src/lib/emotion_smart.c +++ b/legacy/emotion/src/lib/emotion_smart.c | |||
@@ -2,9 +2,11 @@ | |||
2 | #include "Emotion.h" | 2 | #include "Emotion.h" |
3 | 3 | ||
4 | #ifdef HAVE_EIO | 4 | #ifdef HAVE_EIO |
5 | # include <math.h> | ||
5 | # include <Eio.h> | 6 | # include <Eio.h> |
6 | #else | 7 | #else |
7 | # ifdef HAVE_XATTR | 8 | # ifdef HAVE_XATTR |
9 | # include <math.h> | ||
8 | # include <sys/xattr.h> | 10 | # include <sys/xattr.h> |
9 | # endif | 11 | # endif |
10 | #endif | 12 | #endif |
@@ -45,6 +47,7 @@ typedef struct _Smart_Data Smart_Data; | |||
45 | 47 | ||
46 | struct _Smart_Data | 48 | struct _Smart_Data |
47 | { | 49 | { |
50 | EINA_REFCOUNT; | ||
48 | Emotion_Video_Module *module; | 51 | Emotion_Video_Module *module; |
49 | void *video; | 52 | void *video; |
50 | 53 | ||
@@ -80,6 +83,8 @@ struct _Smart_Data | |||
80 | #ifdef HAVE_EIO | 83 | #ifdef HAVE_EIO |
81 | Eio_File *load_xattr; | 84 | Eio_File *load_xattr; |
82 | Eio_File *save_xattr; | 85 | Eio_File *save_xattr; |
86 | |||
87 | const char *time_seek; | ||
83 | #endif | 88 | #endif |
84 | 89 | ||
85 | Emotion_Module_Options module_options; | 90 | Emotion_Module_Options module_options; |
@@ -172,16 +177,45 @@ _emotion_image_data_zero(Evas_Object *img) | |||
172 | evas_object_image_data_set(img, data); | 177 | evas_object_image_data_set(img, data); |
173 | } | 178 | } |
174 | 179 | ||
180 | static void | ||
181 | _emotion_module_close(Emotion_Video_Module *mod, void *video) | ||
182 | { | ||
183 | if (!mod) return; | ||
184 | if (mod->plugin->close && video) | ||
185 | mod->plugin->close(mod, video); | ||
186 | /* FIXME: we can't go dlclosing here as a thread still may be running from | ||
187 | * the module - this in theory will leak- but it shouldnt be too bad and | ||
188 | * mean that once a module is dlopened() it cant be closed - its refcount | ||
189 | * will just keep going up | ||
190 | */ | ||
191 | } | ||
192 | |||
193 | static void | ||
194 | _smart_data_free(Smart_Data *sd) | ||
195 | { | ||
196 | if (sd->video) sd->module->file_close(sd->video); | ||
197 | _emotion_module_close(sd->module, sd->video); | ||
198 | evas_object_del(sd->obj); | ||
199 | eina_stringshare_del(sd->file); | ||
200 | free(sd->module_name); | ||
201 | if (sd->job) ecore_job_del(sd->job); | ||
202 | free(sd->progress.info); | ||
203 | free(sd->ref.file); | ||
204 | free(sd); | ||
205 | |||
206 | ecore_shutdown(); | ||
207 | } | ||
208 | |||
175 | EAPI Eina_Bool | 209 | EAPI Eina_Bool |
176 | _emotion_module_register(const char *name, Emotion_Module_Open open, Emotion_Module_Close close) | 210 | _emotion_module_register(const char *name, Emotion_Module_Open mod_open, Emotion_Module_Close mod_close) |
177 | { | 211 | { |
178 | Eina_Emotion_Plugins *plugin; | 212 | Eina_Emotion_Plugins *plugin; |
179 | 213 | ||
180 | plugin = malloc(sizeof (Eina_Emotion_Plugins)); | 214 | plugin = malloc(sizeof (Eina_Emotion_Plugins)); |
181 | if (!plugin) return EINA_FALSE; | 215 | if (!plugin) return EINA_FALSE; |
182 | 216 | ||
183 | plugin->open = open; | 217 | plugin->open = mod_open; |
184 | plugin->close = close; | 218 | plugin->close = mod_close; |
185 | 219 | ||
186 | return eina_hash_add(_backends, name, plugin); | 220 | return eina_hash_add(_backends, name, plugin); |
187 | } | 221 | } |
@@ -241,19 +275,6 @@ _emotion_module_open(const char *name, Evas_Object *obj, Emotion_Video_Module ** | |||
241 | return NULL; | 275 | return NULL; |
242 | } | 276 | } |
243 | 277 | ||
244 | static void | ||
245 | _emotion_module_close(Emotion_Video_Module *mod, void *video) | ||
246 | { | ||
247 | if (!mod) return; | ||
248 | if (mod->plugin->close && video) | ||
249 | mod->plugin->close(mod, video); | ||
250 | /* FIXME: we can't go dlclosing here as a thread still may be running from | ||
251 | * the module - this in theory will leak- but it shouldnt be too bad and | ||
252 | * mean that once a module is dlopened() it cant be closed - its refcount | ||
253 | * will just keep going up | ||
254 | */ | ||
255 | } | ||
256 | |||
257 | /*******************************/ | 278 | /*******************************/ |
258 | /* Externally accessible calls */ | 279 | /* Externally accessible calls */ |
259 | /*******************************/ | 280 | /*******************************/ |
@@ -315,8 +336,6 @@ emotion_object_init(Evas_Object *obj, const char *module_filename) | |||
315 | sd->seek_pos = 0; | 336 | sd->seek_pos = 0; |
316 | sd->len = 0; | 337 | sd->len = 0; |
317 | 338 | ||
318 | ecore_init(); | ||
319 | |||
320 | _emotion_module_close(sd->module, sd->video); | 339 | _emotion_module_close(sd->module, sd->video); |
321 | sd->module = NULL; | 340 | sd->module = NULL; |
322 | sd->video = NULL; | 341 | sd->video = NULL; |
@@ -1002,6 +1021,147 @@ emotion_object_vis_supported(const Evas_Object *obj, Emotion_Vis visualization) | |||
1002 | return sd->module->vis_supported(sd->video, visualization); | 1021 | return sd->module->vis_supported(sd->video, visualization); |
1003 | } | 1022 | } |
1004 | 1023 | ||
1024 | #ifdef HAVE_EIO | ||
1025 | static void | ||
1026 | _eio_load_xattr_cleanup(Smart_Data *sd) | ||
1027 | { | ||
1028 | sd->load_xattr = NULL; | ||
1029 | |||
1030 | EINA_REFCOUNT_UNREF(sd) | ||
1031 | _smart_data_free(sd); | ||
1032 | } | ||
1033 | |||
1034 | static void | ||
1035 | _eio_load_xattr_done(void *data, Eio_File *handler __UNUSED__, const char *xattr_data, unsigned int xattr_size) | ||
1036 | { | ||
1037 | Smart_Data *sd = data; | ||
1038 | |||
1039 | if (xattr_size < 128 && xattr_data[xattr_size] == '\0') | ||
1040 | { | ||
1041 | long long int m = 0; | ||
1042 | long int e = 0; | ||
1043 | |||
1044 | eina_convert_atod(xattr_data, xattr_size, &m, &e); | ||
1045 | emotion_object_position_set(evas_object_smart_parent_get(sd->obj), ldexp((double)m, e)); | ||
1046 | } | ||
1047 | |||
1048 | _eio_load_xattr_cleanup(sd); | ||
1049 | } | ||
1050 | |||
1051 | static void | ||
1052 | _eio_load_xattr_error(void *data, Eio_File *handler __UNUSED__, int err __UNUSED__) | ||
1053 | { | ||
1054 | Smart_Data *sd = data; | ||
1055 | |||
1056 | _eio_load_xattr_cleanup(sd); | ||
1057 | } | ||
1058 | #endif | ||
1059 | |||
1060 | EAPI void | ||
1061 | emotion_object_last_position_load(Evas_Object *obj) | ||
1062 | { | ||
1063 | Smart_Data *sd; | ||
1064 | const char *tmp; | ||
1065 | |||
1066 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | ||
1067 | if (!sd->file) return ; | ||
1068 | |||
1069 | if (!strncmp(sd->file, "file://", 7)) | ||
1070 | tmp = sd->file + 7; | ||
1071 | else if (!strstr(sd->file, "://")) | ||
1072 | tmp = sd->file; | ||
1073 | else | ||
1074 | return ; | ||
1075 | |||
1076 | #ifdef HAVE_EIO | ||
1077 | if (sd->load_xattr) return ; | ||
1078 | |||
1079 | EINA_REFCOUNT_REF(sd); | ||
1080 | |||
1081 | sd->load_xattr = eio_file_xattr_get(tmp, "user.e.time_seek", _eio_load_xattr_done, _eio_load_xattr_error, sd); | ||
1082 | #else | ||
1083 | # ifdef HAVE_XATTR | ||
1084 | { | ||
1085 | char double_to_string[128]; | ||
1086 | ssize_t sz; | ||
1087 | long long int m = 0; | ||
1088 | long int e = 0; | ||
1089 | |||
1090 | sz = getxattr(tmp, "user.e.time_seek", double_to_string, 128); | ||
1091 | if (sz <= 0 || sz > 128 || double_to_string[sz] != '\0') | ||
1092 | return ; | ||
1093 | |||
1094 | eina_convert_atod(double_to_string, 128, &m, &e); | ||
1095 | emotion_object_position_set(obj, ldexp((double)m, e)); | ||
1096 | } | ||
1097 | # endif | ||
1098 | #endif | ||
1099 | } | ||
1100 | |||
1101 | #ifdef HAVE_EIO | ||
1102 | static void | ||
1103 | _eio_save_xattr_cleanup(Smart_Data *sd) | ||
1104 | { | ||
1105 | sd->save_xattr = NULL; | ||
1106 | eina_stringshare_del(sd->time_seek); | ||
1107 | sd->time_seek = NULL; | ||
1108 | |||
1109 | EINA_REFCOUNT_UNREF(sd) | ||
1110 | _smart_data_free(sd); | ||
1111 | } | ||
1112 | |||
1113 | static void | ||
1114 | _eio_save_xattr_done(void *data, Eio_File *handler __UNUSED__) | ||
1115 | { | ||
1116 | Smart_Data *sd = data; | ||
1117 | |||
1118 | _eio_save_xattr_cleanup(sd); | ||
1119 | } | ||
1120 | |||
1121 | static void | ||
1122 | _eio_save_xattr_error(void *data, Eio_File *handler __UNUSED__, int err __UNUSED__) | ||
1123 | { | ||
1124 | Smart_Data *sd = data; | ||
1125 | |||
1126 | _eio_save_xattr_cleanup(sd); | ||
1127 | } | ||
1128 | #endif | ||
1129 | |||
1130 | EAPI void | ||
1131 | emotion_object_last_position_save(Evas_Object *obj) | ||
1132 | { | ||
1133 | Smart_Data *sd; | ||
1134 | const char *tmp; | ||
1135 | char double_to_string[128]; | ||
1136 | |||
1137 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | ||
1138 | if (!sd->file) return ; | ||
1139 | |||
1140 | if (!strncmp(sd->file, "file://", 7)) | ||
1141 | tmp = sd->file + 7; | ||
1142 | else if (!strstr(sd->file, "://")) | ||
1143 | tmp = sd->file; | ||
1144 | else | ||
1145 | return ; | ||
1146 | |||
1147 | eina_convert_dtoa(emotion_object_position_get(obj), double_to_string); | ||
1148 | |||
1149 | #ifdef HAVE_EIO | ||
1150 | if (sd->save_xattr) return ; | ||
1151 | |||
1152 | EINA_REFCOUNT_REF(sd); | ||
1153 | |||
1154 | sd->time_seek = eina_stringshare_add(double_to_string); | ||
1155 | sd->save_xattr = eio_file_xattr_set(tmp, "user.e.time_seek", | ||
1156 | sd->time_seek, eina_stringshare_strlen(sd->time_seek) + 1, 0, | ||
1157 | _eio_save_xattr_done, _eio_save_xattr_error, sd); | ||
1158 | #else | ||
1159 | # ifdef HAVE_XATTR | ||
1160 | setxattr(tmp, "user.e.time_seek", double_to_string, strlen(double_to_string), 0); | ||
1161 | # endif | ||
1162 | #endif | ||
1163 | } | ||
1164 | |||
1005 | EAPI Eina_Bool | 1165 | EAPI Eina_Bool |
1006 | emotion_object_extension_can_play_fast_get(const Evas_Object *obj, const char *file) | 1166 | emotion_object_extension_can_play_fast_get(const Evas_Object *obj, const char *file) |
1007 | { | 1167 | { |
@@ -1257,14 +1417,14 @@ _emotion_title_set(Evas_Object *obj, char *title) | |||
1257 | } | 1417 | } |
1258 | 1418 | ||
1259 | EAPI void | 1419 | EAPI void |
1260 | _emotion_progress_set(Evas_Object *obj, char *info, double stat) | 1420 | _emotion_progress_set(Evas_Object *obj, char *info, double st) |
1261 | { | 1421 | { |
1262 | Smart_Data *sd; | 1422 | Smart_Data *sd; |
1263 | 1423 | ||
1264 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); | 1424 | E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME); |
1265 | free(sd->progress.info); | 1425 | free(sd->progress.info); |
1266 | sd->progress.info = strdup(info); | 1426 | sd->progress.info = strdup(info); |
1267 | sd->progress.stat = stat; | 1427 | sd->progress.stat = st; |
1268 | evas_object_smart_callback_call(obj, SIG_PROGRESS_CHANGE, NULL); | 1428 | evas_object_smart_callback_call(obj, SIG_PROGRESS_CHANGE, NULL); |
1269 | } | 1429 | } |
1270 | 1430 | ||
@@ -1581,6 +1741,7 @@ _smart_add(Evas_Object * obj) | |||
1581 | 1741 | ||
1582 | sd = calloc(1, sizeof(Smart_Data)); | 1742 | sd = calloc(1, sizeof(Smart_Data)); |
1583 | if (!sd) return; | 1743 | if (!sd) return; |
1744 | EINA_REFCOUNT_INIT(sd); | ||
1584 | sd->obj = evas_object_image_add(evas_object_evas_get(obj)); | 1745 | sd->obj = evas_object_image_add(evas_object_evas_get(obj)); |
1585 | evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, sd); | 1746 | evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, sd); |
1586 | evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, sd); | 1747 | evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, sd); |
@@ -1596,6 +1757,8 @@ _smart_add(Evas_Object * obj) | |||
1596 | evas_object_image_data_set(obj, pixel); | 1757 | evas_object_image_data_set(obj, pixel); |
1597 | } | 1758 | } |
1598 | evas_object_smart_data_set(obj, sd); | 1759 | evas_object_smart_data_set(obj, sd); |
1760 | |||
1761 | ecore_init(); | ||
1599 | } | 1762 | } |
1600 | 1763 | ||
1601 | static void | 1764 | static void |
@@ -1605,17 +1768,8 @@ _smart_del(Evas_Object * obj) | |||
1605 | 1768 | ||
1606 | sd = evas_object_smart_data_get(obj); | 1769 | sd = evas_object_smart_data_get(obj); |
1607 | if (!sd) return; | 1770 | if (!sd) return; |
1608 | if (sd->video) sd->module->file_close(sd->video); | 1771 | EINA_REFCOUNT_UNREF(sd) |
1609 | _emotion_module_close(sd->module, sd->video); | 1772 | _smart_data_free(sd); |
1610 | evas_object_del(sd->obj); | ||
1611 | eina_stringshare_del(sd->file); | ||
1612 | free(sd->module_name); | ||
1613 | if (sd->job) ecore_job_del(sd->job); | ||
1614 | free(sd->progress.info); | ||
1615 | free(sd->ref.file); | ||
1616 | free(sd); | ||
1617 | |||
1618 | ecore_shutdown(); | ||
1619 | } | 1773 | } |
1620 | 1774 | ||
1621 | static void | 1775 | static void |