efl

Форк
0
/
ethumb_dbus.c 
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_H
25
#include "config.h"
26
#endif
27
#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

37
static int _waiting_count = 0;
38

39
static void
40
_on_server_die_cb(void *data EINA_UNUSED, Ethumb_Client *client EINA_UNUSED)
41
{
42
   ecore_main_loop_quit();
43
}
44

45
static void
46
_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
{
48
   fprintf(stderr, ">>> %hhu file ready: %s; thumb ready: %s; id = %d\n", success, file, thumb_path, id);
49
   _waiting_count--;
50
   if (_waiting_count == 0)
51
     ecore_main_loop_quit();
52
}
53

54
static void
55
_request_thumbnails(Ethumb_Client *client, void *data)
56
{
57
   const char *path = data;
58
   Eina_File_Direct_Info *info;
59
   Eina_Iterator *itr;
60

61
   itr = eina_file_stat_ls(path);
62
   if (!itr)
63
     {
64
	fprintf(stderr, "ERROR: could not open directory: %s\n", path);
65
	return;
66
     }
67

68
   ethumb_client_format_set(client, ETHUMB_THUMB_JPEG);
69
   ethumb_client_aspect_set(client, ETHUMB_THUMB_CROP);
70
   ethumb_client_crop_align_set(client, 0.2, 0.2);
71
   ethumb_client_size_set(client, 192, 192);
72
   ethumb_client_category_set(client, "custom");
73

74
   EINA_ITERATOR_FOREACH(itr, info)
75
     {
76
	if (info->type != EINA_FILE_REG)
77
	  continue;
78
	ethumb_client_file_set(client, info->path, NULL);
79
        printf("request: %s\n", info->path);
80
	ethumb_client_generate(client, _queue_add_cb, NULL, NULL);
81
        _waiting_count++;
82
     }
83
   eina_iterator_free(itr);
84
}
85

86
static void
87
_connect_cb(void *data, Ethumb_Client *client, Eina_Bool success)
88
{
89
   fprintf(stderr, "connected: %d\n", success);
90
   if (!success)
91
     {
92
	ecore_main_loop_quit();
93
	return;
94
     }
95

96
   _request_thumbnails(client, data);
97
}
98

99
int
100
main(int argc, char *argv[])
101
{
102
   Ethumb_Client *client;
103

104
   if (argc < 2)
105
     {
106
	fprintf(stderr, "ERROR: directory not specified.\n");
107
	fprintf(stderr, "usage:\n\tethumb_dbus <images directory>\n");
108
	return -2;
109
     }
110

111
   ethumb_client_init();
112
   client = ethumb_client_connect(_connect_cb, argv[1], NULL);
113
   if (!client)
114
     {
115
	fprintf(stderr, "ERROR: couldn't connect to server.\n");
116
	ethumb_client_shutdown();
117
	return -1;
118
     }
119
   ethumb_client_on_server_die_callback_set(client, _on_server_die_cb, NULL, NULL);
120

121
   fprintf(stderr, "*** debug\n");
122
   ecore_main_loop_begin();
123

124
   ethumb_client_disconnect(client);
125

126
   ethumb_client_shutdown();
127

128
   return 0;
129
}
130

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.