summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-07-07 20:22:18 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-07-07 20:22:18 +0900
commitbdf252c75ec2f1411f44e5852c1de9670c90aa22 (patch)
tree5432ad506a10aecba815ee1c34358383e08452dd
parentbe6f1e29726bfdb9c7bacd4234f72d401c9863b8 (diff)
File load. Still failing for some reason. (layout)
-rw-r--r--lib/eynote.c52
-rw-r--r--lib/eynote.eo1
-rw-r--r--lib/eynote.h5
-rw-r--r--lib/eynote_data.c2
-rw-r--r--lib/eynote_hud.c67
-rw-r--r--lib/eynote_label.c15
-rw-r--r--lib/eynote_label.eo1
-rw-r--r--lib/eynote_slide.c35
-rw-r--r--lib/eynote_slide.eo1
-rw-r--r--lib/eynote_slidebg.c17
-rw-r--r--lib/eynote_slidebg.eo1
-rw-r--r--lib/eynote_widget.c11
-rw-r--r--lib/eynote_widget.eo1
-rw-r--r--lib/serializable.eo5
14 files changed, 201 insertions, 13 deletions
diff --git a/lib/eynote.c b/lib/eynote.c
index ac28706..2543223 100644
--- a/lib/eynote.c
+++ b/lib/eynote.c
@@ -234,7 +234,6 @@ EOLIAN Eina_Bool
234_eynote_efl_file_save(const Eo *obj, Eynote_Data *pd EINA_UNUSED, const char *file, 234_eynote_efl_file_save(const Eo *obj, Eynote_Data *pd EINA_UNUSED, const char *file,
235 const char *key, const char *flags EINA_UNUSED) 235 const char *key, const char *flags EINA_UNUSED)
236{ 236{
237 Eynote_Serial *data;
238 Eet_File *ef; 237 Eet_File *ef;
239 bool ok; 238 bool ok;
240 239
@@ -242,10 +241,6 @@ _eynote_efl_file_save(const Eo *obj, Eynote_Data *pd EINA_UNUSED, const char *fi
242 ok = eynote_eet_save(obj, ef, key, false); 241 ok = eynote_eet_save(obj, ef, key, false);
243 eet_close(ef); 242 eet_close(ef);
244 243
245 ef = eet_open(file, EET_FILE_MODE_READ);
246 data = eynote_eet_load(ef, key);
247 eynote_eet_dump(data);
248
249 return ok; 244 return ok;
250} 245}
251 246
@@ -265,12 +260,27 @@ _eynote_efl_file_file_get(Eo *obj EINA_UNUSED, Eynote_Data *pd, const char **fil
265EOLIAN Eina_Bool 260EOLIAN Eina_Bool
266_eynote_efl_file_file_set(Eo *obj EINA_UNUSED, Eynote_Data *pd, const char *file, const char *key) 261_eynote_efl_file_file_set(Eo *obj EINA_UNUSED, Eynote_Data *pd, const char *file, const char *key)
267{ 262{
263 Eynote_Serial *data;
264 Eynote_Slide *sl;
265 Eet_File *ef;
266 bool ok = false;
267
268 if (!key) key = "/eynote";
269
268 eina_stringshare_replace(&pd->file, file); 270 eina_stringshare_replace(&pd->file, file);
269 eina_stringshare_replace(&pd->key, key); 271 eina_stringshare_replace(&pd->key, key);
270 272
271 // DO SOMETHING NOW 273 EINA_LIST_FREE(pd->slides, sl)
272 CRI("Loading not implemented yet!"); 274 eo_del(sl);
273 return false; 275
276 ef = eet_open(file, EET_FILE_MODE_READ);
277 data = eynote_eet_load(ef, key);
278
279 eynote_eet_dump(data);
280
281 eo_do(obj, ok = serializable_deserialize(data));
282
283 return ok;
274} 284}
275 285
276EOLIAN void * 286EOLIAN void *
@@ -292,6 +302,32 @@ _eynote_serializable_serialize(const Eo *obj EINA_UNUSED, Eynote_Data *pd)
292 return data; 302 return data;
293} 303}
294 304
305EOLIAN Eina_Bool
306_eynote_serializable_deserialize(Eo *obj EINA_UNUSED, Eynote_Data *pd, void *_data)
307{
308 Eynote_Slide_Serial *sl_data;
309 Eynote_Serial *data = _data;
310 Eynote_Slide *sl;
311 Eina_List *li;
312 bool ok = true;
313
314 if (data->version != EYNOTE_FILE_VERSION)
315 {
316 ERR("Unsupported file version: %d", data->version);
317 return false;
318 }
319
320 EINA_LIST_FOREACH(data->slides, li, sl_data)
321 {
322 sl = eo_add(eynote_slide_class_get(), obj);
323 pd->slides = eina_list_append(pd->slides, sl);
324 eo_do(sl, ok = serializable_deserialize(sl_data));
325 if (!ok) break;
326 }
327
328 return ok;
329}
330
295EOLIAN void 331EOLIAN void
296_eynote_class_constructor(Eo_Class *klass) 332_eynote_class_constructor(Eo_Class *klass)
297{ 333{
diff --git a/lib/eynote.eo b/lib/eynote.eo
index a9b930f..5173a28 100644
--- a/lib/eynote.eo
+++ b/lib/eynote.eo
@@ -28,5 +28,6 @@ class Eynote(Elm.Layout, Efl.File, Serializable)
28 Efl.File.save; 28 Efl.File.save;
29 class.constructor; 29 class.constructor;
30 Serializable.serialize; 30 Serializable.serialize;
31 Serializable.deserialize;
31 } 32 }
32} 33}
diff --git a/lib/eynote.h b/lib/eynote.h
index af02085..0408cf3 100644
--- a/lib/eynote.h
+++ b/lib/eynote.h
@@ -74,4 +74,9 @@ extern int _eynote_log_dom;
74#define alloc(typ) calloc(1, sizeof(typ)) 74#define alloc(typ) calloc(1, sizeof(typ))
75#define strdupx(str) (str ? strdup(str) : NULL) 75#define strdupx(str) (str ? strdup(str) : NULL)
76 76
77
78// Until we use gettext
79#define _(a) a
80
81
77#endif // EYNOTE_H 82#endif // EYNOTE_H
diff --git a/lib/eynote_data.c b/lib/eynote_data.c
index 76d26bb..2963ae8 100644
--- a/lib/eynote_data.c
+++ b/lib/eynote_data.c
@@ -170,6 +170,8 @@ eynote_eet_save(const Eynote *obj, Eet_File *ef, const char *section, bool compr
170 if (!data) 170 if (!data)
171 return false; 171 return false;
172 172
173 eynote_eet_dump(data);
174
173 edd = _eynote_edd_get(); 175 edd = _eynote_edd_get();
174 bytes = eet_data_write(ef, edd, section, data, compress); 176 bytes = eet_data_write(ef, edd, section, data, compress);
175 _eynote_eet_free(data); 177 _eynote_eet_free(data);
diff --git a/lib/eynote_hud.c b/lib/eynote_hud.c
index a19df31..30243f4 100644
--- a/lib/eynote_hud.c
+++ b/lib/eynote_hud.c
@@ -43,7 +43,7 @@ _fsel_show_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, voi
43} 43}
44 44
45static void 45static void
46_fsel_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 46_fsel_save_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
47{ 47{
48 Eynote_Hud_Data *pd = data; 48 Eynote_Hud_Data *pd = data;
49 const char *file = event_info; 49 const char *file = event_info;
@@ -66,16 +66,69 @@ _save_clicked(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED
66 66
67 if (!pd->fsel) 67 if (!pd->fsel)
68 { 68 {
69 pd->fsel_win = elm_win_util_dialog_add(obj, "filesel", "Save to..."); 69 pd->fsel_win = elm_win_util_dialog_add(obj, "filesel", _("Save File As"));
70 pd->fsel = o = elm_fileselector_add(pd->fsel_win); 70 pd->fsel = o = elm_fileselector_add(pd->fsel_win);
71 elm_win_resize_object_add(pd->fsel_win, o); 71 elm_win_resize_object_add(pd->fsel_win, o);
72 elm_fileselector_is_save_set(o, true);
73 evas_object_event_callback_add(o, EVAS_CALLBACK_SHOW, _fsel_show_cb, pd); 72 evas_object_event_callback_add(o, EVAS_CALLBACK_SHOW, _fsel_show_cb, pd);
74 evas_object_smart_callback_add(o, "done", _fsel_done, pd); 73 evas_object_smart_callback_add(o, "done", _fsel_save_done, pd);
75 SX(o); 74 SX(o);
76 } 75 }
77 else o = pd->fsel; 76 else o = pd->fsel;
78 77
78 elm_fileselector_is_save_set(o, true);
79 elm_fileselector_button_window_title_set(o, _("Save File As"));
80 eo_do(eynote_get(pd->self), efl_file_get(&path, &key));
81 dir = strdup(path);
82 name = strrchr(dir, '/');
83 if (name)
84 {
85 *name = 0;
86 name++;
87 }
88 elm_fileselector_path_set(o, dir);
89 elm_fileselector_current_name_set(o, name);
90 free(dir);
91
92 SX(pd->fsel_win);
93
94 return EO_CALLBACK_CONTINUE;
95}
96
97static void
98_fsel_load_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
99{
100 Eynote_Hud_Data *pd = data;
101 const char *file = event_info;
102
103 H(pd->fsel_win);
104
105 if (!file)
106 return;
107
108 eo_do(eynote_get(pd->self), efl_file_set(file, NULL));
109}
110
111static Eina_Bool
112_load_clicked(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event_info EINA_UNUSED)
113{
114 Eynote_Hud_Data *pd = data;
115 const char *path, *key;
116 char *dir, *name;
117 Elm_Fileselector *o;
118
119 if (!pd->fsel)
120 {
121 pd->fsel_win = elm_win_util_dialog_add(obj, "filesel", _("Open file..."));
122 pd->fsel = o = elm_fileselector_add(pd->fsel_win);
123 elm_win_resize_object_add(pd->fsel_win, o);
124 evas_object_event_callback_add(o, EVAS_CALLBACK_SHOW, _fsel_show_cb, pd);
125 evas_object_smart_callback_add(o, "done", _fsel_load_done, pd);
126 SX(o);
127 }
128 else o = pd->fsel;
129
130 elm_fileselector_is_save_set(o, false);
131 elm_fileselector_button_window_title_set(o, _("Open file..."));
79 eo_do(eynote_get(pd->self), efl_file_get(&path, &key)); 132 eo_do(eynote_get(pd->self), efl_file_get(&path, &key));
80 dir = strdup(path); 133 dir = strdup(path);
81 name = strrchr(dir, '/'); 134 name = strrchr(dir, '/');
@@ -118,6 +171,12 @@ _items_bar_add(Eo *obj, Eynote_Hud_Data *pd)
118 171
119 o = elm_button_add(pd->items_bar); 172 o = elm_button_add(pd->items_bar);
120 elm_box_pack_end(pd->items_bar, o); 173 elm_box_pack_end(pd->items_bar, o);
174 elm_object_text_set(o, "Load");
175 eo_do(o, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _load_clicked, pd));
176 SXH(o);
177
178 o = elm_button_add(pd->items_bar);
179 elm_box_pack_end(pd->items_bar, o);
121 elm_object_text_set(o, "Save"); 180 elm_object_text_set(o, "Save");
122 eo_do(o, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _save_clicked, pd)); 181 eo_do(o, eo_event_callback_add(EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _save_clicked, pd));
123 SXH(o); 182 SXH(o);
diff --git a/lib/eynote_label.c b/lib/eynote_label.c
index c9aa5d7..9a01935 100644
--- a/lib/eynote_label.c
+++ b/lib/eynote_label.c
@@ -121,6 +121,21 @@ _eynote_label_serializable_serialize(const Eo *obj EINA_UNUSED, Eynote_Label_Dat
121 return wd_data; 121 return wd_data;
122} 122}
123 123
124EOLIAN Eina_Bool
125_eynote_label_serializable_deserialize(Eo *obj, Eynote_Label_Data *pd, void *_data)
126{
127 Eynote_Widget_Serial *wd_data = _data;
128 Eynote_Label_Serial *data = wd_data->data;
129
130 if (!data) return true;
131 _font_set(obj, pd, data->font, data->size);
132 _text_set(obj, pd, data->str, false);
133
134 eo_do_super(obj, MY_CLASS, serializable_deserialize(wd_data));
135
136 return true;
137}
138
124EOLIAN Eo_Base * 139EOLIAN Eo_Base *
125_eynote_label_eo_base_constructor(Eo *obj, Eynote_Label_Data *pd) 140_eynote_label_eo_base_constructor(Eo *obj, Eynote_Label_Data *pd)
126{ 141{
diff --git a/lib/eynote_label.eo b/lib/eynote_label.eo
index b19524a..8041f4d 100644
--- a/lib/eynote_label.eo
+++ b/lib/eynote_label.eo
@@ -7,5 +7,6 @@ class Eynote.Label(Eynote.Widget, Serializable)
7 Eynote.Widget.edit_mode.set; 7 Eynote.Widget.edit_mode.set;
8 Eynote.Widget.object.get; 8 Eynote.Widget.object.get;
9 Serializable.serialize; 9 Serializable.serialize;
10 Serializable.deserialize;
10 } 11 }
11} 12}
diff --git a/lib/eynote_slide.c b/lib/eynote_slide.c
index 754991f..18dbac2 100644
--- a/lib/eynote_slide.c
+++ b/lib/eynote_slide.c
@@ -130,4 +130,39 @@ _eynote_slide_serializable_serialize(const Eo *obj EINA_UNUSED, Eynote_Slide_Dat
130 return data; 130 return data;
131} 131}
132 132
133EOLIAN Eina_Bool
134_eynote_slide_serializable_deserialize(Eo *obj, Eynote_Slide_Data *pd, void *_data)
135{
136 Eynote_Slide_Serial *data = _data;
137 Eynote_Widget_Serial *wd_data;
138 Eina_List *li;
139 bool ok = true;
140
141 eo_do(pd->bg, ok = serializable_deserialize(data->bg));
142 if (!ok) return false;
143
144 EINA_LIST_FOREACH(data->widgets, li, wd_data)
145 {
146 const Eo_Class *klass = NULL;
147 Eynote_Widget *wd;
148
149 switch (wd_data->type)
150 {
151 case EYNOTE_WIDGET_TYPE_LABEL: klass = eynote_label_class_get(); break;
152 default: break;
153 }
154 if (!klass)
155 {
156 ERR("Could not create widget of unknown type %d", wd_data->type);
157 return false;
158 }
159 wd = eo_add(klass, obj);
160 pd->widgets = eina_list_append(pd->widgets, wd);
161 eo_do(wd, ok = serializable_deserialize(wd_data));
162 if (!ok) break;
163 }
164
165 return ok;
166}
167
133#include "eynote_slide.eo.x" 168#include "eynote_slide.eo.x"
diff --git a/lib/eynote_slide.eo b/lib/eynote_slide.eo
index bac7c45..7accc4b 100644
--- a/lib/eynote_slide.eo
+++ b/lib/eynote_slide.eo
@@ -10,5 +10,6 @@ class Eynote.Slide(Elm.Layout, Serializable)
10 implements { 10 implements {
11 Eo.Base.constructor; 11 Eo.Base.constructor;
12 Serializable.serialize; 12 Serializable.serialize;
13 Serializable.deserialize;
13 } 14 }
14} 15}
diff --git a/lib/eynote_slidebg.c b/lib/eynote_slidebg.c
index e5ff3da..ed42080 100644
--- a/lib/eynote_slidebg.c
+++ b/lib/eynote_slidebg.c
@@ -22,7 +22,8 @@ _eynote_slidebg_eo_base_constructor(Eo *obj, Eynote_SlideBg_Data *pd)
22 snprintf(path, PATH_MAX, "%s/%s.edj", E_BG_ROOT, default_name); 22 snprintf(path, PATH_MAX, "%s/%s.edj", E_BG_ROOT, default_name);
23 pd->file = eina_stringshare_add(path); 23 pd->file = eina_stringshare_add(path);
24 pd->key = eina_stringshare_add(default_key); 24 pd->key = eina_stringshare_add(default_key);
25 eo_do(obj, efl_file_set(path, default_key)); 25
26 eo_do(obj, efl_file_set(pd->file, pd->key));
26 27
27 return obj; 28 return obj;
28} 29}
@@ -39,4 +40,18 @@ _eynote_slidebg_serializable_serialize(const Eo *obj EINA_UNUSED, Eynote_SlideBg
39 return data; 40 return data;
40} 41}
41 42
43EOLIAN Eina_Bool
44_eynote_slidebg_serializable_deserialize(Eo *obj, Eynote_SlideBg_Data *pd, void *_data)
45{
46 Eynote_SlideBg_Serial *data = _data;
47 bool ok;
48
49 if (!data) return true;
50 eina_stringshare_replace(&pd->file, data->file);
51 eina_stringshare_replace(&pd->key, data->key);
52 eo_do(obj, ok = efl_file_set(pd->file, pd->key));
53
54 return ok;
55}
56
42#include "eynote_slidebg.eo.x" 57#include "eynote_slidebg.eo.x"
diff --git a/lib/eynote_slidebg.eo b/lib/eynote_slidebg.eo
index e042a2e..c94a3ac 100644
--- a/lib/eynote_slidebg.eo
+++ b/lib/eynote_slidebg.eo
@@ -3,5 +3,6 @@ class Eynote.SlideBg(Elm.Bg, Serializable)
3 implements { 3 implements {
4 Eo.Base.constructor; 4 Eo.Base.constructor;
5 Serializable.serialize; 5 Serializable.serialize;
6 Serializable.deserialize;
6 } 7 }
7} 8}
diff --git a/lib/eynote_widget.c b/lib/eynote_widget.c
index 63c30cb..ec4e223 100644
--- a/lib/eynote_widget.c
+++ b/lib/eynote_widget.c
@@ -84,6 +84,17 @@ _eynote_widget_serializable_serialize(const Eo *obj EINA_UNUSED, Eynote_Widget_D
84 return data; 84 return data;
85} 85}
86 86
87EOLIAN Eina_Bool
88_eynote_widget_serializable_deserialize(Eo *obj, Eynote_Widget_Data *pd, void *_data)
89{
90 Eynote_Widget_Serial *data = _data;
91
92 if (!data) return true;
93 _eynote_widget_position_set(obj, pd, data->row, data->col);
94
95 return true;
96}
97
87EOLIAN Eo_Base * 98EOLIAN Eo_Base *
88_eynote_widget_eo_base_constructor(Eo *obj, Eynote_Widget_Data *pd) 99_eynote_widget_eo_base_constructor(Eo *obj, Eynote_Widget_Data *pd)
89{ 100{
diff --git a/lib/eynote_widget.eo b/lib/eynote_widget.eo
index 7da6c76..6a0db98 100644
--- a/lib/eynote_widget.eo
+++ b/lib/eynote_widget.eo
@@ -19,6 +19,7 @@ class Eynote.Widget(Elm.Table, Serializable)
19 implements { 19 implements {
20 Eo.Base.constructor; 20 Eo.Base.constructor;
21 Serializable.serialize; 21 Serializable.serialize;
22 Serializable.deserialize;
22 @virtual .object.get; 23 @virtual .object.get;
23 } 24 }
24} 25}
diff --git a/lib/serializable.eo b/lib/serializable.eo
index 91c276b..e4836f4 100644
--- a/lib/serializable.eo
+++ b/lib/serializable.eo
@@ -5,5 +5,10 @@ interface Serializable {
5 return: void*(0); 5 return: void*(0);
6 params {} 6 params {}
7 } 7 }
8 deserialize {
9 [[Initialize an object given its serialized data.]]
10 return: bool;
11 params { data: void *; }
12 }
8 } 13 }
9} 14}