summaryrefslogtreecommitdiff
path: root/src/examples/ethumb_client/ethumb_dbus.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/examples/ethumb_client/ethumb_dbus.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/examples/ethumb_client/ethumb_dbus.c')
-rw-r--r--src/examples/ethumb_client/ethumb_dbus.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/examples/ethumb_client/ethumb_dbus.c b/src/examples/ethumb_client/ethumb_dbus.c
new file mode 100644
index 0000000000..2f613e93ea
--- /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}