1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
* Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <tumbler/tumbler.h>
#include <tumblerd/tumbler-cache-service.h>
#include <tumblerd/tumbler-manager.h>
#include <tumblerd/tumbler-registry.h>
#include <tumblerd/tumbler-service.h>
int
main (int argc,
char **argv)
{
TumblerProviderFactory *provider_factory;
DBusGConnection *connection;
TumblerRegistry *registry;
TumblerManager *manager;
TumblerService *service;
TumblerCacheService *cache_service;
GMainLoop *main_loop;
GError *error = NULL;
GList *providers;
GList *thumbnailers;
GList *lp;
GList *tp;
/* set the program name */
g_set_prgname (G_LOG_DOMAIN);
/* set the application name. Translators: Don't translate "Tumbler". */
g_set_application_name (_("Tumbler Thumbnailing Service"));
/* initialize the GLib type system */
g_type_init ();
/* initialize threading system */
if (!g_thread_supported ())
g_thread_init (NULL);
/* try to connect to the D-Bus session bus */
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
/* print an error and exit if the connection could not be established */
if (connection == NULL)
{
g_warning (_("Failed to connect to the D-Bus session bus: %s"), error->message);
g_error_free (error);
return EXIT_FAILURE;
}
/* create the thumbnail cache service */
cache_service = tumbler_cache_service_new (connection);
/* try to start the service and exit if that fails */
if (!tumbler_cache_service_start (cache_service, &error))
{
g_warning (_("Failed to start the thumbnail cache service: %s"), error->message);
g_error_free (error);
g_object_unref (cache_service);
dbus_g_connection_unref (connection);
return EXIT_FAILURE;
}
/* create the thumbnailer registry */
registry = tumbler_registry_new ();
/* take a reference on the provider factory */
provider_factory = tumbler_provider_factory_get_default ();
/* query all thumbnailer providers from the factory */
providers = tumbler_provider_factory_get_providers (provider_factory,
TUMBLER_TYPE_THUMBNAILER_PROVIDER);
/* iterate over all providers */
for (lp = providers; lp != NULL; lp = lp->next)
{
/* query the list of thumbnailers provided by this provider */
thumbnailers = tumbler_thumbnailer_provider_get_thumbnailers (lp->data);
/* add all thumbnailers to the registry */
for (tp = thumbnailers; tp != NULL; tp = tp->next)
{
tumbler_registry_add (registry, tp->data);
g_object_unref (tp->data);
}
/* free the thumbnailer list */
g_list_free (thumbnailers);
}
/* release all providers and free the provider list */
g_list_foreach (providers, (GFunc) g_object_unref, NULL);
g_list_free (providers);
/* drop the reference on the provider factory */
g_object_unref (provider_factory);
/* update the URI schemes / MIME types supported information */
tumbler_registry_update_supported (registry);
/* try to load specialized thumbnailers and exit if that fails */
if (!tumbler_registry_load (registry, &error))
{
g_warning (_("Failed to load specialized thumbnailers into the registry: %s"),
error->message);
g_error_free (error);
g_object_unref (registry);
g_object_unref (cache_service);
dbus_g_connection_unref (connection);
return EXIT_FAILURE;
}
/* create the thumbnailer manager service */
manager = tumbler_manager_new (connection, registry);
/* try to start the service and exit if that fails */
if (!tumbler_manager_start (manager, &error))
{
g_warning (_("Failed to start the thumbnailer manager: %s"), error->message);
g_error_free (error);
g_object_unref (manager);
g_object_unref (registry);
g_object_unref (cache_service);
dbus_g_connection_unref (connection);
return EXIT_FAILURE;
}
/* create the generic thumbnailer service */
service = tumbler_service_new (connection, registry);
/* try to start the service and exit if that fails */
if (!tumbler_service_start (service, &error))
{
g_warning (_("Failed to start the thumbnailer service: %s"), error->message);
g_error_free (error);
g_object_unref (service);
g_object_unref (manager);
g_object_unref (registry);
g_object_unref (cache_service);
dbus_g_connection_unref (connection);
return EXIT_FAILURE;
}
/* create a new main loop and run it */
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
/* shut our services down and release all objects */
g_object_unref (service);
g_object_unref (manager);
g_object_unref (registry);
g_object_unref (cache_service);
/* disconnect from the D-Bus session bus */
dbus_g_connection_unref (connection);
/* we're done, all fine */
return EXIT_SUCCESS;
}
|