summaryrefslogtreecommitdiff
path: root/src/bin/ethumb_client/ethumbd_client.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-15 18:10:58 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-15 18:10:58 +0000
commitd97c63e4c69d0a8c3cb29b22927b5b53c7bf46c4 (patch)
tree4309480b1cb48058bdac139f6eb14cbeaf515fd6 /src/bin/ethumb_client/ethumbd_client.c
parent028e7e9ed2ca4aad0dd04493019d495f68fa6a31 (diff)
fix directory structure: move ethumd_client out of ethumb.
it's another library, do not mix stuff as it used to be. SVN revision: 82835
Diffstat (limited to 'src/bin/ethumb_client/ethumbd_client.c')
-rw-r--r--src/bin/ethumb_client/ethumbd_client.c330
1 files changed, 330 insertions, 0 deletions
diff --git a/src/bin/ethumb_client/ethumbd_client.c b/src/bin/ethumb_client/ethumbd_client.c
new file mode 100644
index 0000000..e81fc2e
--- /dev/null
+++ b/src/bin/ethumb_client/ethumbd_client.c
@@ -0,0 +1,330 @@
1/**
2 * @file
3 *
4 * Copyright (C) 2009 by ProFUSION embedded systems
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library;
18 * if not, see <http://www.gnu.org/licenses/>.
19 *
20 * @author Rafael Antognolli <antognolli@profusion.mobi>
21 */
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <limits.h>
30
31#include <Eina.h>
32#include <Ecore_Getopt.h>
33#include <Ecore.h>
34#include <Ethumb_Client.h>
35
36const char *aspect_opt[] = { "keep", "ignore", "crop", NULL };
37const char *format_opt[] = { "png", "jpg", "eet", NULL };
38struct frame
39{
40 const char *file;
41 const char *group;
42 const char *swallow;
43};
44
45struct options
46{
47 Eina_Rectangle geometry;
48 unsigned int format, aspect;
49 char *format_str;
50 char *aspect_str;
51 char *directory;
52 char *category;
53 struct frame frame;
54 char *src_path;
55 char *src_key;
56 const char *thumb_path;
57 const char *thumb_key;
58 double video_time;
59 int page;
60};
61
62static unsigned char
63_ethumb_getopt_callback_frame_parse(const Ecore_Getopt *parser EINA_UNUSED, const Ecore_Getopt_Desc *desc EINA_UNUSED, const char *str, void *data EINA_UNUSED, Ecore_Getopt_Value *storage)
64{
65 struct frame *f = (struct frame *)storage->ptrp;
66 const char *tfile, *tgroup, *tswallow, *base, *sep;
67
68 base = str;
69 sep = strchr(base, ':');
70 if (!sep)
71 goto error;
72 tfile = eina_stringshare_add_length(base, sep - base);
73 base = sep + 1;
74
75 sep = strchr(base, ':');
76 if (!sep)
77 {
78 eina_stringshare_del(tfile);
79 goto error;
80 }
81 tgroup = eina_stringshare_add_length(base, sep - base);
82 base = sep + 1;
83 if (base[0] == '\0')
84 {
85 eina_stringshare_del(tfile);
86 eina_stringshare_del(tgroup);
87 goto error;
88 }
89 tswallow = eina_stringshare_add(base);
90
91 f->file = tfile;
92 f->group = tgroup;
93 f->swallow = tswallow;
94 return 1;
95
96 error:
97 fprintf(stderr,
98 "ERROR: invalid theme, not in format "
99 "'file:group:swallow_part': '%s'\n",
100 str);
101 return 0;
102}
103
104const Ecore_Getopt optdesc = {
105 "ethumbd_client",
106 NULL,
107 PACKAGE_VERSION,
108 "(C) 2009 - ProFUSION embedded systems",
109 "LGPL v2.1 - GNU Lesser General Public License",
110 "Thumbnails generator client using DBus and ethumbd.\n"
111 "\n"
112 "This program uses ethumbd server to create thumbnails from pictures. "
113 "It's an example of use and a test for ethumbd.\n",
114 0,
115 {
116 ECORE_GETOPT_CALLBACK_ARGS
117 ('s', "size", "thumbnail size expected.",
118 "WxH", ecore_getopt_callback_size_parse, NULL),
119 ECORE_GETOPT_CHOICE
120 ('f', "format", "file format to save.", format_opt),
121 ECORE_GETOPT_CHOICE
122 ('a', "aspect", "original image aspect ratio.", aspect_opt),
123 ECORE_GETOPT_STORE_STR
124 ('d', "directory", "directory to save thumbnails."),
125 ECORE_GETOPT_STORE_STR
126 ('c', "category", "thumbnails category."),
127 ECORE_GETOPT_CALLBACK_ARGS
128 ('t', "theme", "path to theme file, group and swallow part.",
129 "file:group:swallow_part", _ethumb_getopt_callback_frame_parse, NULL),
130 ECORE_GETOPT_STORE_STR
131 ('k', "key", "key inside eet file to read image from."),
132 ECORE_GETOPT_STORE_DOUBLE
133 ('v', "video_time", "time of video frame to use as thumbnail."),
134 ECORE_GETOPT_STORE_INT
135 ('p', "document_page", "document page to use as thumbnail."),
136 ECORE_GETOPT_LICENSE('L', "license"),
137 ECORE_GETOPT_COPYRIGHT('C', "copyright"),
138 ECORE_GETOPT_VERSION('V', "version"),
139 ECORE_GETOPT_HELP('h', "help"),
140 ECORE_GETOPT_SENTINEL
141 }
142};
143
144static void
145_thumb_report(const char *mode, const char *src_path, const char *src_key, const char *thumb_path, const char *thumb_key)
146{
147 printf("%s '%s' '%s' => '%s' '%s'\n",
148 mode,
149 src_path, src_key ? src_key : "",
150 thumb_path, thumb_key ? thumb_key : "");
151}
152
153static void
154_finished_thumb(void *data EINA_UNUSED, Ethumb_Client *client EINA_UNUSED, int id EINA_UNUSED, const char *src_path, const char *src_key, const char *thumb_path, const char *thumb_key, Eina_Bool success)
155{
156 const char *mode = success ? "GENERATED" : "FAILED";
157 _thumb_report(mode, src_path, src_key, thumb_path, thumb_key);
158 ecore_main_loop_quit();
159}
160
161static void
162_exists(void *data, Ethumb_Client *c, EINA_UNUSED Ethumb_Exists *thread, Eina_Bool exists)
163{
164 struct options *opts = data;
165 const char *thumb_path, *thumb_key;
166 long id;
167
168 if (exists)
169 {
170 ethumb_client_thumb_path_get(c, &thumb_path, &thumb_key);
171 _thumb_report
172 ("EXISTS", opts->src_path, opts->src_key, thumb_path, thumb_key);
173 ecore_main_loop_quit();
174 return;
175 }
176
177 id = ethumb_client_generate(c, _finished_thumb, NULL, NULL);
178 if (id < 0)
179 {
180 fputs("ERROR: could not request thumbnail to be generated.\n", stderr);
181 ecore_main_loop_quit();
182 return;
183 }
184 printf("request id=%ld, file='%s', key='%s'\n",
185 id, opts->src_path, opts->src_key ? opts->src_key : "");
186
187}
188
189static void
190_connected(void *data, Ethumb_Client *c, Eina_Bool success)
191{
192 struct options *opts = data;
193
194 if (!success)
195 {
196 fputs("ERROR: could not connect to DBus server.\n", stderr);
197 ecore_main_loop_quit();
198 return;
199 }
200
201 fputs("connected to DBus server, setup parameters...\n", stdout);
202
203 ethumb_client_format_set(c, opts->format);
204 ethumb_client_aspect_set(c, opts->aspect);
205
206 if (opts->directory) ethumb_client_dir_path_set(c, opts->directory);
207 if (opts->category) ethumb_client_category_set(c, opts->category);
208 if (opts->geometry.w > 0 && opts->geometry.h > 0)
209 ethumb_client_size_set(c, opts->geometry.w, opts->geometry.h);
210 if (opts->frame.file)
211 ethumb_client_frame_set
212 (c, opts->frame.file, opts->frame.group, opts->frame.swallow);
213 if (opts->video_time > 0)
214 ethumb_client_video_time_set(c, opts->video_time);
215 if (opts->page > 0)
216 ethumb_client_document_page_set(c, opts->page);
217
218 if (!ethumb_client_file_set(c, opts->src_path, opts->src_key))
219 {
220 fprintf(stderr, "ERROR: could not set file '%s', key '%s'\n",
221 opts->src_path, opts->src_key ? opts->src_key : "");
222 ecore_main_loop_quit();
223 return;
224 }
225
226 ethumb_client_thumb_path_set(c, opts->thumb_path, opts->thumb_key);
227 ethumb_client_thumb_exists(c, _exists, opts);
228}
229
230int
231main(int argc, char *argv[])
232{
233 Ethumb_Client *c;
234 Eina_Bool quit_option = 0;
235 const char *format_str = NULL, *aspect_str = NULL;
236 struct options opts = {
237 {-1, -1, -1, -1},
238 0, 0,
239 NULL, NULL, NULL, NULL,
240 {NULL, NULL, NULL},
241 NULL, NULL, NULL, NULL,
242 0.0,
243 0
244 };
245 int arg_index;
246 int i, ret = 0;
247
248 ethumb_client_init();
249 ecore_init();
250
251 Ecore_Getopt_Value values[] = {
252 ECORE_GETOPT_VALUE_PTR_CAST(opts.geometry),
253 ECORE_GETOPT_VALUE_PTR_CAST(format_str),
254 ECORE_GETOPT_VALUE_PTR_CAST(aspect_str),
255 ECORE_GETOPT_VALUE_STR(opts.directory),
256 ECORE_GETOPT_VALUE_STR(opts.category),
257 ECORE_GETOPT_VALUE_PTR_CAST(opts.frame),
258 ECORE_GETOPT_VALUE_STR(opts.src_key),
259 ECORE_GETOPT_VALUE_DOUBLE(opts.video_time),
260 ECORE_GETOPT_VALUE_INT(opts.page),
261 ECORE_GETOPT_VALUE_BOOL(quit_option),
262 ECORE_GETOPT_VALUE_BOOL(quit_option),
263 ECORE_GETOPT_VALUE_BOOL(quit_option),
264 ECORE_GETOPT_VALUE_BOOL(quit_option),
265 ECORE_GETOPT_VALUE_NONE
266 };
267
268 arg_index = ecore_getopt_parse(&optdesc, values, argc, argv);
269 if ((arg_index < 0) || (arg_index == argc))
270 {
271 if (arg_index < 0)
272 fprintf(stderr, "Could not parse arguments.\n");
273 else
274 fprintf(stderr, "Missing source file to thumbnail.\n");
275
276 ret = 1;
277 goto end;
278 }
279
280 if (quit_option)
281 {
282 ret = 0;
283 goto end;
284 }
285
286 for (i = 0; i < 3; i++)
287 if (format_opt[i] == format_str)
288 {
289 opts.format = i;
290 break;
291 }
292
293 for (i = 0; i < 3; i++)
294 if (aspect_opt[i] == aspect_str)
295 {
296 opts.aspect = i;
297 break;
298 }
299
300 opts.src_path = argv[arg_index++];
301 if (arg_index < argc)
302 {
303 opts.thumb_path = argv[arg_index++];
304 if (arg_index < argc)
305 opts.thumb_key = argv[arg_index];
306 }
307
308 c = ethumb_client_connect(_connected, &opts, NULL);
309 if (!c)
310 {
311 fputs("ERROR: could not connect to server.\n", stderr);
312 ret = 2;
313 goto end;
314 }
315
316 ecore_main_loop_begin();
317 ethumb_client_disconnect(c);
318
319 end:
320 if (opts.frame.file)
321 {
322 eina_stringshare_del(opts.frame.file);
323 eina_stringshare_del(opts.frame.group);
324 eina_stringshare_del(opts.frame.swallow);
325 }
326 ecore_shutdown();
327 ethumb_client_shutdown();
328
329 return ret;
330}