efl
129 строк · 3.4 Кб
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* gcc -o ethumb_dbus ethumb_dbus.c `pkg-config --libs --cflags eina ecore ethumb ethumb_client`
21*
22* @author Rafael Antognolli <antognolli@profusion.mobi>
23*/
24#ifdef HAVE_CONFIG_H25#include "config.h"26#endif27#include <stdio.h>28#include <stdlib.h>29#include <string.h>30#include <limits.h>31#include <Ethumb.h>32#include <Ethumb_Client.h>33#include <Eina.h>34#include <Ecore_Getopt.h>35#include <Ecore.h>36
37static int _waiting_count = 0;38
39static void40_on_server_die_cb(void *data EINA_UNUSED, Ethumb_Client *client EINA_UNUSED)41{
42ecore_main_loop_quit();43}
44
45static void46_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)47{
48fprintf(stderr, ">>> %hhu file ready: %s; thumb ready: %s; id = %d\n", success, file, thumb_path, id);49_waiting_count--;50if (_waiting_count == 0)51ecore_main_loop_quit();52}
53
54static void55_request_thumbnails(Ethumb_Client *client, void *data)56{
57const char *path = data;58Eina_File_Direct_Info *info;59Eina_Iterator *itr;60
61itr = eina_file_stat_ls(path);62if (!itr)63{64fprintf(stderr, "ERROR: could not open directory: %s\n", path);65return;66}67
68ethumb_client_format_set(client, ETHUMB_THUMB_JPEG);69ethumb_client_aspect_set(client, ETHUMB_THUMB_CROP);70ethumb_client_crop_align_set(client, 0.2, 0.2);71ethumb_client_size_set(client, 192, 192);72ethumb_client_category_set(client, "custom");73
74EINA_ITERATOR_FOREACH(itr, info)75{76if (info->type != EINA_FILE_REG)77continue;78ethumb_client_file_set(client, info->path, NULL);79printf("request: %s\n", info->path);80ethumb_client_generate(client, _queue_add_cb, NULL, NULL);81_waiting_count++;82}83eina_iterator_free(itr);84}
85
86static void87_connect_cb(void *data, Ethumb_Client *client, Eina_Bool success)88{
89fprintf(stderr, "connected: %d\n", success);90if (!success)91{92ecore_main_loop_quit();93return;94}95
96_request_thumbnails(client, data);97}
98
99int
100main(int argc, char *argv[])101{
102Ethumb_Client *client;103
104if (argc < 2)105{106fprintf(stderr, "ERROR: directory not specified.\n");107fprintf(stderr, "usage:\n\tethumb_dbus <images directory>\n");108return -2;109}110
111ethumb_client_init();112client = ethumb_client_connect(_connect_cb, argv[1], NULL);113if (!client)114{115fprintf(stderr, "ERROR: couldn't connect to server.\n");116ethumb_client_shutdown();117return -1;118}119ethumb_client_on_server_die_callback_set(client, _on_server_die_cb, NULL, NULL);120
121fprintf(stderr, "*** debug\n");122ecore_main_loop_begin();123
124ethumb_client_disconnect(client);125
126ethumb_client_shutdown();127
128return 0;129}
130