Merged pidgin/main into default
[pidgin-git.git] / libpurple / purple-client.c
blob54cff691924cf47a2861d93925122ba0cc2e6b6a
1 /*
2 * purple
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #ifndef DBUS_API_SUBJECT_TO_CHANGE
24 #define DBUS_API_SUBJECT_TO_CHANGE
25 #endif
27 #include <dbus/dbus-glib.h>
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include "dbus-purple.h"
32 #include "purple-client.h"
34 static DBusGConnection *bus;
35 static DBusGProxy *purple_proxy;
37 static GList *garray_int_to_glist(GArray *array)
39 GList *list = NULL;
40 gsize i;
42 for (i = 0; i < array->len; i++)
43 list = g_list_append(list, GINT_TO_POINTER(g_array_index(array,gint,i)));
45 g_array_free(array, TRUE);
46 return list;
49 static GSList *garray_int_to_gslist(GArray *array)
51 GSList *list = NULL;
52 gsize i;
54 for (i = 0; i < array->len; i++)
55 list = g_slist_append(list, GINT_TO_POINTER(g_array_index(array,gint,i)));
57 g_array_free(array, TRUE);
58 return list;
61 #include "purple-client-bindings.ch"
63 static void lose(const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
64 static void lose_gerror(const char *prefix, GError *error) G_GNUC_NORETURN;
66 static void
67 lose(const char *str, ...)
69 va_list args;
71 va_start(args, str);
73 vfprintf(stderr, str, args);
74 fputc('\n', stderr);
76 va_end(args);
78 exit(1);
81 static void
82 lose_gerror(const char *prefix, GError *error)
84 lose("%s: %s", prefix, error->message);
87 void purple_init(void)
89 GError *error = NULL;
91 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
92 if (!bus)
93 lose_gerror ("Couldn't connect to session bus", error);
95 purple_proxy = dbus_g_proxy_new_for_name (bus,
96 PURPLE_DBUS_SERVICE,
97 PURPLE_DBUS_PATH,
98 PURPLE_DBUS_INTERFACE);
100 if (!purple_proxy)
101 lose_gerror ("Couldn't connect to the Purple Service", error);