summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-10-22 15:48:06 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-10-22 15:48:06 +0900
commit3815fa9fac7f9469ed7c027d62171989174eb003 (patch)
treeed60df2fbba4273ff79b9bc687c55a69db0f57d7
parentc0371bf865653b43e0590127d0717d3e96211eed (diff)
bla bla bla. refactor fs
-rw-r--r--lib/eynote.c149
-rw-r--r--lib/eynote.h1
-rw-r--r--lib/eynote_fileselector.eo28
-rw-r--r--lib/eynote_image.c10
-rw-r--r--lib/eynote_widget.c17
5 files changed, 87 insertions, 118 deletions
diff --git a/lib/eynote.c b/lib/eynote.c
index 230e746..f9124a6 100644
--- a/lib/eynote.c
+++ b/lib/eynote.c
@@ -24,7 +24,7 @@ typedef struct
24 bool flipping; 24 bool flipping;
25} Eynote_Data; 25} Eynote_Data;
26 26
27static struct { 27static const struct {
28 Eynote_Widget_Type type; 28 Eynote_Widget_Type type;
29 const char *cursor; 29 const char *cursor;
30} _cursors[] = { 30} _cursors[] = {
@@ -270,55 +270,40 @@ _eynote_slide_add(Eo *obj, Eynote_Data *pd EINA_UNUSED, const char *model)
270 return sl; 270 return sl;
271} 271}
272 272
273// Fucking fileselector
274static const char *
275_save_path_get(char *path)
276{
277 const char *dir;
278 struct stat st;
279
280 dir = elm_app_data_dir_get();
281 if (!stat(dir, &st))
282 return dir;
283 dir = getenv("HOME");
284 if (!stat(dir, &st))
285 return dir;
286 getcwd(path, PATH_MAX);
287 return path;
288}
289
290static Eina_Bool 273static Eina_Bool
291_fs_filter_ppte(const char *path, Eina_Bool dir, void *data) 274_fs_save_done(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
292{ 275{
276 Eina_Stringshare *path = event_info;
293 Eynote_Data *pd = data; 277 Eynote_Data *pd = data;
294 const char *ext;
295 (void) pd;
296 278
297 if (dir) return true; 279 _keys_grab(pd, true);
298 if (!path) return false;
299 ext = strrchr(path, '.');
300 if (!ext) return false;
301 return (!strcmp(ext, ".ppte"));
302}
303 280
304static Eina_Bool 281 eina_stringshare_refplace(&pd->file, path);
305_fs_filter_all(const char *path EINA_UNUSED, Eina_Bool dir EINA_UNUSED, void *data EINA_UNUSED) 282 eo_do(pd->self, efl_file_save(pd->file, NULL, NULL));
306{ 283
284 eo_del(obj);
307 return true; 285 return true;
308} 286}
309 287
310static void 288static Eina_Bool
311_fs_save_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info) 289_fs_open_done(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
312{ 290{
313 const char *path = event_info; 291 Eina_Stringshare *path = event_info;
314 Eynote_Data *pd = data; 292 Eynote_Data *pd = data;
315 293
316 eo_del(eo_parent(obj));
317 _keys_grab(pd, true); 294 _keys_grab(pd, true);
318 if (!path) return;
319 295
320 eina_stringshare_replace(&pd->file, path); 296 eo_do(pd->self, efl_file_set(path, NULL));
321 eo_do(pd->self, efl_file_save(pd->file, pd->key, NULL)); 297
298 eo_del(obj);
299 return true;
300}
301
302static Eina_Bool
303_fs_cancelled(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
304{
305 eo_del(obj);
306 return true;
322} 307}
323 308
324static void 309static void
@@ -326,42 +311,15 @@ _eynote_save(Eynote_Data *pd, bool saveas)
326{ 311{
327 if (saveas || !pd->file) 312 if (saveas || !pd->file)
328 { 313 {
329 // Fucking hacks around fileselector issues 314 Eynote_Fileselector *fs;
330 char path[PATH_MAX];
331 Elm_Fileselector *fs;
332 Eo *parent, *tbl, *rect;
333 int w, h;
334 315
335 _keys_grab(pd, false); 316 _keys_grab(pd, false);
336 317 fs = eo_add(eynote_fileselector_class_get(), pd->self);
337 parent = elm_popup_add(pd->self); 318 eo_do(fs,
338 elm_popup_allow_events_set(parent, true); 319 eo_event_callback_add(EYNOTE_FILESELECTOR_EVENT_DONE, _fs_save_done, pd);
339 elm_object_part_text_set(parent, "title,text", _("Save as...")); 320 eo_event_callback_add(EYNOTE_FILESELECTOR_EVENT_CANCELLED, _fs_cancelled, pd);
340 321 );
341 tbl = elm_table_add(parent);
342 rect = elm_bg_add(parent);
343 evas_object_geometry_get(pd->self, NULL, NULL, &w, &h);
344 evas_object_size_hint_min_set(rect, 0.8 * w, 0.8 * h);
345 elm_table_pack(tbl, rect, 0, 0, 1, 1);
346 elm_object_content_set(parent, tbl);
347
348 fs = elm_fileselector_add(parent);
349 elm_table_pack(tbl, fs, 0, 0, 1, 1);
350
351 elm_fileselector_buttons_ok_cancel_set(fs, true);
352 elm_fileselector_is_save_set(fs, true);
353 elm_fileselector_custom_filter_append(fs, _fs_filter_ppte, pd, _("Eynote Presentations"));
354 elm_fileselector_custom_filter_append(fs, _fs_filter_all, pd, _("All files"));
355 //elm_fileselector_mime_types_filter_append(fs, "*", _("All files"));
356 elm_fileselector_current_name_set(fs, _("presentation.ppte"));
357 elm_fileselector_path_set(fs, _save_path_get(path));
358 elm_fileselector_folder_only_set(fs, false);
359 evas_object_smart_callback_add(fs, "done", _fs_save_done, pd);
360
361 SX(fs); 322 SX(fs);
362 SX(rect);
363 SX(tbl);
364 SX(parent);
365 } 323 }
366 else 324 else
367 { 325 {
@@ -370,54 +328,19 @@ _eynote_save(Eynote_Data *pd, bool saveas)
370} 328}
371 329
372static void 330static void
373_fs_open_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
374{
375 const char *path = event_info;
376 Eynote_Data *pd = data;
377
378 eo_del(eo_parent(obj));
379 _keys_grab(pd, true);
380 if (!path) return;
381
382 eo_do(pd->self, efl_file_set(path, pd->key));
383}
384
385static void
386_eynote_open(Eynote_Data *pd) 331_eynote_open(Eynote_Data *pd)
387{ 332{
388 char path[PATH_MAX]; 333 Eynote_Fileselector *fs;
389 Elm_Fileselector *fs;
390 Eo *parent, *tbl, *rect;
391 int w, h;
392 334
393 _keys_grab(pd, false); 335 _keys_grab(pd, false);
394 336
395 parent = elm_popup_add(pd->self); 337 fs = eo_add(eynote_fileselector_class_get(), pd->self);
396 elm_popup_allow_events_set(parent, true); 338 eo_do(fs,
397 elm_object_part_text_set(parent, "title,text", _("Open note...")); 339 eynote_fileselector_save_mode_set(false);
398 340 eo_event_callback_add(EYNOTE_FILESELECTOR_EVENT_DONE, _fs_open_done, pd);
399 tbl = elm_table_add(parent); 341 eo_event_callback_add(EYNOTE_FILESELECTOR_EVENT_CANCELLED, _fs_cancelled, pd);
400 rect = elm_bg_add(parent); 342 );
401 evas_object_geometry_get(pd->self, NULL, NULL, &w, &h);
402 evas_object_size_hint_min_set(rect, 0.8 * w, 0.8 * h);
403 elm_table_pack(tbl, rect, 0, 0, 1, 1);
404 elm_object_content_set(parent, tbl);
405
406 fs = elm_fileselector_add(parent);
407 elm_table_pack(tbl, fs, 0, 0, 1, 1);
408
409 elm_fileselector_buttons_ok_cancel_set(fs, true);
410 elm_fileselector_is_save_set(fs, true);
411 elm_fileselector_custom_filter_append(fs, _fs_filter_ppte, pd, _("Eynote Presentations"));
412 elm_fileselector_custom_filter_append(fs, _fs_filter_all, pd, _("All files"));
413 elm_fileselector_path_set(fs, _save_path_get(path));
414 elm_fileselector_folder_only_set(fs, false);
415 evas_object_smart_callback_add(fs, "done", _fs_open_done, pd);
416
417 SX(fs); 343 SX(fs);
418 SX(rect);
419 SX(tbl);
420 SX(parent);
421} 344}
422 345
423EOLIAN void 346EOLIAN void
@@ -470,7 +393,7 @@ _mouse_wheel(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void
470 if (ev->z < 0) 393 if (ev->z < 0)
471 eo_do(pd->self, eynote_slide_prev(false)); 394 eo_do(pd->self, eynote_slide_prev(false));
472 else 395 else
473 eo_do(pd->self, eynote_slide_next(false)); 396 eo_do(pd->self, eynote_slide_next(false));
474} 397}
475 398
476static void 399static void
diff --git a/lib/eynote.h b/lib/eynote.h
index 0b28d3d..2e0c436 100644
--- a/lib/eynote.h
+++ b/lib/eynote.h
@@ -19,6 +19,7 @@ typedef struct _Config_Value Config_Value;
19#include "eynote_slidebg.eo.h" 19#include "eynote_slidebg.eo.h"
20#include "eynote_slide.eo.h" 20#include "eynote_slide.eo.h"
21#include "eynote_image.eo.h" 21#include "eynote_image.eo.h"
22#include "eynote_fileselector.eo.h"
22#include "eynote.eo.h" 23#include "eynote.eo.h"
23 24
24#include "eynote_data.h" 25#include "eynote_data.h"
diff --git a/lib/eynote_fileselector.eo b/lib/eynote_fileselector.eo
new file mode 100644
index 0000000..d578aa9
--- /dev/null
+++ b/lib/eynote_fileselector.eo
@@ -0,0 +1,28 @@
1class Eynote.Fileselector(Elm.Popup)
2{
3 methods {
4 @property file_path {
5 get {}
6 set {}
7 values { path: const(char)*; }
8 }
9 @property save_mode {
10 get {}
11 set {}
12 values { enable: bool; }
13 }
14 @property title {
15 get {}
16 set {}
17 values { str: const(char)*; }
18 }
19 }
20 implements {
21 Eo.Base.constructor;
22 Eo.Base.destructor;
23 }
24 events {
25 done;
26 cancelled;
27 }
28}
diff --git a/lib/eynote_image.c b/lib/eynote_image.c
index 9b295b9..2242dce 100644
--- a/lib/eynote_image.c
+++ b/lib/eynote_image.c
@@ -38,6 +38,16 @@ _eynote_image_eo_base_constructor(Eo *obj, Eynote_Image_Data *pd)
38 pd->self = obj; 38 pd->self = obj;
39 X(obj); 39 X(obj);
40 40
41 pd->image = elm_image_add(pd->self);
42 elm_image_aspect_fixed_set(pd->image, true);
43 elm_image_editable_set(pd->image, false); // we do it manually
44 elm_image_no_scale_set(pd->image, false);
45 elm_image_resizable_set(pd->image, true, true);
46 elm_image_smooth_set(pd->image, true);
47 X(pd->image);
48
49 elm_table_pack(obj, pd->image, 0, 0, 1, 1);
50
41 return obj; 51 return obj;
42} 52}
43 53
diff --git a/lib/eynote_widget.c b/lib/eynote_widget.c
index d55e3f3..7f827d2 100644
--- a/lib/eynote_widget.c
+++ b/lib/eynote_widget.c
@@ -129,11 +129,14 @@ _mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void
129 if (!pd->move.moving) 129 if (!pd->move.moving)
130 { 130 {
131 double snap_dist; 131 double snap_dist;
132 int x, y, w, h; 132 int x, y, w, h, gw, gh;
133
134 gw = eynote_config_geti(pd->self, eynote_config_grid_w);
135 gh = eynote_config_geti(pd->self, eynote_config_grid_h);
136 if (!gw || !gh) return;
133 137
134 evas_object_geometry_get(slide, NULL, NULL, &w, &h); 138 evas_object_geometry_get(slide, NULL, NULL, &w, &h);
135 snap_dist = hypot((double) w / eynote_config_geti(pd->self, eynote_config_grid_w), 139 snap_dist = hypot((double) w / gw, (double) h / gh);
136 (double) h / eynote_config_geti(pd->self, eynote_config_grid_h));
137 140
138 if (hypot(ev->cur.canvas.x - pd->move.orig_x, 141 if (hypot(ev->cur.canvas.x - pd->move.orig_x,
139 ev->cur.canvas.y - pd->move.orig_y) > snap_dist) 142 ev->cur.canvas.y - pd->move.orig_y) > snap_dist)
@@ -188,14 +191,18 @@ EOLIAN static void
188_eynote_widget_position_set(Eo *obj, Eynote_Widget_Data *pd, int col, int row) 191_eynote_widget_position_set(Eo *obj, Eynote_Widget_Data *pd, int col, int row)
189{ 192{
190 Evas_Object *parent; 193 Evas_Object *parent;
191 int x, y, w, h; 194 int x, y, w, h, gw, gh;
195
196 gw = eynote_config_geti(pd->self, eynote_config_grid_w);
197 gh = eynote_config_geti(pd->self, eynote_config_grid_h);
198 if (!gw || !gh) return;
192 199
193 eo_do(obj, parent = eo_parent_get()); 200 eo_do(obj, parent = eo_parent_get());
194 evas_object_geometry_get(parent, &x, &y, &w, &h); 201 evas_object_geometry_get(parent, &x, &y, &w, &h);
195 202
196 pd->col = col; 203 pd->col = col;
197 pd->row = row; 204 pd->row = row;
198 evas_object_move(obj, x + col * w / eynote_config_geti(pd->self, eynote_config_grid_w), y + row * h / eynote_config_geti(pd->self, eynote_config_grid_h)); 205 evas_object_move(obj, x + col * w / gw, y + row * h / gh);
199} 206}
200 207
201EOLIAN static void 208EOLIAN static void