summaryrefslogtreecommitdiff
path: root/src/bin/ecore_evas
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-04-07 16:48:49 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-04-07 17:59:45 +0900
commite9cd81683996802f2ed95fce5a1a8dedb6f2f5e5 (patch)
tree62b07d08c2828b9135726dd00b4d6b024aaebcbf /src/bin/ecore_evas
parent18d5e04bb50182c5ce613fee98a0b746f8694327 (diff)
ecore_evas_convert: Implement hacky solution for Ctrl+C
Problem: evas_object_image_save() can't be interrupted. But, with ETC1/ETC2 encoding, it might be terribly long and the user has no way to cancel encoding (except SIGKILL). The proper solution would be to tell evas that the save operation has been cancelled. And run that in a thread, in a non-blocking way. I guess Efl.File.async could be used for that, which means maybe also introduce Efl.File.async_cancel? This will have to wait for EFL 1.15 I'm afraid. Note: edje_cc still can't be cancelled during ETC encoding.
Diffstat (limited to 'src/bin/ecore_evas')
-rw-r--r--src/bin/ecore_evas/ecore_evas_convert.c65
1 files changed, 58 insertions, 7 deletions
diff --git a/src/bin/ecore_evas/ecore_evas_convert.c b/src/bin/ecore_evas/ecore_evas_convert.c
index 8cf613e211..d23d3579ed 100644
--- a/src/bin/ecore_evas/ecore_evas_convert.c
+++ b/src/bin/ecore_evas/ecore_evas_convert.c
@@ -36,6 +36,54 @@ const Ecore_Getopt optdesc = {
36 } 36 }
37}; 37};
38 38
39struct Save_Job {
40 const char *output;
41 const char *flags;
42 Ecore_Thread *th;
43 Evas_Object *im;
44 int ret, cancel;
45};
46
47static void
48_save_do(void *data, Ecore_Thread *thread EINA_UNUSED)
49{
50 struct Save_Job *job = data;
51
52 job->ret = 0;
53 if (!evas_object_image_save(job->im, job->output, NULL, job->flags))
54 {
55 EINA_LOG_ERR("Could not convert file to '%s'.", job->output);
56 job->ret = 1;
57 }
58}
59
60static void
61_save_end(void *data EINA_UNUSED, Ecore_Thread *thread EINA_UNUSED)
62{
63 ecore_main_loop_quit();
64}
65
66static Eina_Bool
67exit_func(void *data, int ev_type EINA_UNUSED, void *ev)
68{
69 Ecore_Event_Signal_Exit *e = ev;
70 struct Save_Job *job = data;
71 if (!job->cancel && !e->quit && !e->terminate)
72 {
73 // this won't do anything, really...
74 fprintf(stderr, "Cancellation requested. Press Ctrl+C again to kill.\n");
75 fflush(stderr);
76 job->cancel = 1;
77 ecore_thread_cancel(job->th);
78 }
79 else
80 {
81 fprintf(stderr, "Terminated.");
82 exit(1);
83 }
84 return ECORE_CALLBACK_RENEW;
85}
86
39int 87int
40main(int argc, char *argv[]) 88main(int argc, char *argv[])
41{ 89{
@@ -49,6 +97,7 @@ main(int argc, char *argv[])
49 Eina_Bool compress = 1; 97 Eina_Bool compress = 1;
50 Eina_Bool quit_option = EINA_FALSE; 98 Eina_Bool quit_option = EINA_FALSE;
51 Eina_Strbuf *flags = NULL; 99 Eina_Strbuf *flags = NULL;
100 struct Save_Job job = {0};
52 101
53 Ecore_Getopt_Value values[] = { 102 Ecore_Getopt_Value values[] = {
54 ECORE_GETOPT_VALUE_INT(quality), 103 ECORE_GETOPT_VALUE_INT(quality),
@@ -107,14 +156,16 @@ main(int argc, char *argv[])
107 goto end; 156 goto end;
108 } 157 }
109 158
110 if (!evas_object_image_save(im, argv[arg_index + 1], NULL, 159 // NOTE: DO NOT DO THIS AT HOME -- HACK for Ctrl+C
111 eina_strbuf_string_get(flags))) 160 // This makes Ctrl+C work but the Evas Object may not be deleted cleanly
112 { 161 job.output = argv[arg_index + 1];
113 EINA_LOG_ERR("Could not convert file to '%s'.", argv[arg_index + 1]); 162 job.flags = eina_strbuf_string_get(flags);
114 goto end; 163 job.im = im;
115 } 164 job.th = ecore_thread_run(_save_do, _save_end, _save_end, &job);
165 ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, &job);
166 ecore_main_loop_begin();
116 167
117 r = 0; 168 r = job.ret;
118 169
119 end: 170 end:
120 if (flags) eina_strbuf_free(flags); 171 if (flags) eina_strbuf_free(flags);