summaryrefslogtreecommitdiff
path: root/src/examples/ethumb_client
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/ethumb_client')
-rw-r--r--src/examples/ethumb_client/Makefile.am58
-rw-r--r--src/examples/ethumb_client/ethumb_dbus.c128
2 files changed, 186 insertions, 0 deletions
diff --git a/src/examples/ethumb_client/Makefile.am b/src/examples/ethumb_client/Makefile.am
new file mode 100644
index 0000000..a7f81e1
--- /dev/null
+++ b/src/examples/ethumb_client/Makefile.am
@@ -0,0 +1,58 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I$(top_srcdir)/src/lib/eina \
5-I$(top_builddir)/src/lib/eina \
6-I$(top_srcdir)/src/lib/eo \
7-I$(top_builddir)/src/lib/eo \
8-I$(top_srcdir)/src/lib/ecore \
9-I$(top_builddir)/src/lib/ecore \
10-I$(top_srcdir)/src/lib/ecore_evas \
11-I$(top_builddir)/src/lib/ecore_evas \
12-I$(top_srcdir)/src/lib/ecore_file \
13-I$(top_builddir)/src/lib/ecore_file \
14-I$(top_srcdir)/src/lib/evas \
15-I$(top_builddir)/src/lib/evas \
16-I$(top_srcdir)/src/lib/edje \
17-I$(top_builddir)/src/lib/edje \
18-I$(top_srcdir)/src/lib/ethumb \
19-I$(top_builddir)/src/lib/ethumb \
20-I$(top_srcdir)/src/lib/ethumb_client \
21-I$(top_builddir)/src/lib/ethumb_client \
22@ETHUMB_CLIENT_CFLAGS@
23
24LDADD = \
25$(top_builddir)/src/lib/eina/libeina.la \
26$(top_builddir)/src/lib/eo/libeo.la \
27$(top_builddir)/src/lib/ecore/libecore.la \
28$(top_builddir)/src/lib/ecore_evas/libecore_evas.la \
29$(top_builddir)/src/lib/ecore_file/libecore_file.la \
30$(top_builddir)/src/lib/evas/libevas.la \
31$(top_builddir)/src/lib/edje/libedje.la \
32$(top_builddir)/src/lib/ethumb/libethumb.la \
33$(top_builddir)/src/lib/ethumb_client/libethumb_client.la \
34@ETHUMB_CLIENT_LDFLAGS@
35
36EXTRA_PROGRAMS = \
37ethumb_dbus
38
39SRCS = \
40ethumb_dbus.c
41
42examples: $(EXTRA_PROGRAMS)
43
44clean-local:
45 rm -f $(EXTRA_PROGRAMS)
46
47install-examples:
48 mkdir -p $(datadir)/ethumb_client/examples
49 $(install_sh_DATA) -c $(SRCS) $(datadir)/ethumb_client/examples
50
51uninstall-local:
52 for f in $(SRCS); do \
53 rm -f $(datadir)/ethumb_client/examples/$$f ; \
54 done
55
56if ALWAYS_BUILD_EXAMPLES
57noinst_PROGRAMS = $(EXTRA_PROGRAMS)
58endif
diff --git a/src/examples/ethumb_client/ethumb_dbus.c b/src/examples/ethumb_client/ethumb_dbus.c
new file mode 100644
index 0000000..2f613e9
--- /dev/null
+++ b/src/examples/ethumb_client/ethumb_dbus.c
@@ -0,0 +1,128 @@
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#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <limits.h>
29#include <dirent.h>
30#include <Ethumb.h>
31#include <Ethumb_Client.h>
32#include <Eina.h>
33#include <Ecore_Getopt.h>
34#include <Ecore.h>
35
36static int _waiting_count = 0;
37
38static void
39_on_server_die_cb(void *data EINA_UNUSED, Ethumb_Client *client EINA_UNUSED)
40{
41 ecore_main_loop_quit();
42}
43
44static void
45_queue_add_cb(void *data EINA_UNUSED, Ethumb_Client *client EINA_UNUSED, int id, const char *file, const char *key EINA_UNUSED, const char *thumb_path, const char *thumb_key EINA_UNUSED, Eina_Bool success)
46{
47 fprintf(stderr, ">>> %hhu file ready: %s; thumb ready: %s; id = %d\n", success, file, thumb_path, id);
48 _waiting_count--;
49 if (_waiting_count == 0)
50 ecore_main_loop_quit();
51}
52
53static void
54_request_thumbnails(Ethumb_Client *client, void *data)
55{
56 const char *path = data;
57 Eina_File_Direct_Info *info;
58 Eina_Iterator *itr;
59
60 itr = eina_file_stat_ls(path);
61 if (!itr)
62 {
63 fprintf(stderr, "ERROR: could not open directory: %s\n", path);
64 return;
65 }
66
67 ethumb_client_format_set(client, ETHUMB_THUMB_JPEG);
68 ethumb_client_aspect_set(client, ETHUMB_THUMB_CROP);
69 ethumb_client_crop_align_set(client, 0.2, 0.2);
70 ethumb_client_size_set(client, 192, 192);
71 ethumb_client_category_set(client, "custom");
72
73 EINA_ITERATOR_FOREACH(itr, info)
74 {
75 if (info->type != EINA_FILE_REG)
76 continue;
77 ethumb_client_file_set(client, info->path, NULL);
78 printf("request: %s\n", info->path);
79 ethumb_client_generate(client, _queue_add_cb, NULL, NULL);
80 _waiting_count++;
81 }
82 eina_iterator_free(itr);
83}
84
85static void
86_connect_cb(void *data, Ethumb_Client *client, Eina_Bool success)
87{
88 fprintf(stderr, "connected: %d\n", success);
89 if (!success)
90 {
91 ecore_main_loop_quit();
92 return;
93 }
94
95 _request_thumbnails(client, data);
96}
97
98int
99main(int argc, char *argv[])
100{
101 Ethumb_Client *client;
102
103 if (argc < 2)
104 {
105 fprintf(stderr, "ERROR: directory not specified.\n");
106 fprintf(stderr, "usage:\n\tethumb_dbus <images directory>\n");
107 return -2;
108 }
109
110 ethumb_client_init();
111 client = ethumb_client_connect(_connect_cb, argv[1], NULL);
112 if (!client)
113 {
114 fprintf(stderr, "ERROR: couldn't connect to server.\n");
115 ethumb_client_shutdown();
116 return -1;
117 }
118 ethumb_client_on_server_die_callback_set(client, _on_server_die_cb, NULL, NULL);
119
120 fprintf(stderr, "*** debug\n");
121 ecore_main_loop_begin();
122
123 ethumb_client_disconnect(client);
124
125 ethumb_client_shutdown();
126
127 return 0;
128}