1 /* Copyright (c) 2006, 2008 Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "asdbus-bindings.h"
32 #include <glib-object.h>
33 #include "modest-runtime.h"
34 #include "modest-protocol.h"
35 #include "modest-protocol-registry.h"
36 #include "modest-account-mgr.h"
40 void recipient_iter (const GValue *value, gpointer user_data)
42 AsDbusRecipient *recipient = g_new0 (AsDbusRecipient, 1);
43 g_return_if_fail (dbus_g_type_is_struct (G_VALUE_TYPE (value)));
44 g_return_if_fail (3 >= dbus_g_type_get_struct_size (G_VALUE_TYPE (value)));
45 g_return_if_fail (G_TYPE_STRING == dbus_g_type_get_struct_member_type (G_VALUE_TYPE (value), 1));
46 g_return_if_fail (G_TYPE_STRING == dbus_g_type_get_struct_member_type (G_VALUE_TYPE (value), 2));
47 g_return_if_fail (dbus_g_type_struct_get (value,
48 1, &recipient->display_name,
49 2, &recipient->email_address,
51 *((GList **)user_data) = g_list_append (*((GList **)user_data), recipient);
56 void response_iter (const GValue *value, gpointer user_data)
58 GValue recipients = {0,};
59 g_return_if_fail (dbus_g_type_is_struct (G_VALUE_TYPE (value)));
60 g_return_if_fail (4 >= dbus_g_type_get_struct_size (G_VALUE_TYPE (value)));
61 g_return_if_fail (dbus_g_type_is_collection (dbus_g_type_get_struct_member_type (G_VALUE_TYPE (value), 3)));
62 g_return_if_fail (dbus_g_type_struct_get_member (value, 3, g_value_init (&recipients, dbus_g_type_get_struct_member_type (G_VALUE_TYPE (value), 3))));
63 dbus_g_type_collection_value_iterate (&recipients, recipient_iter, user_data);
67 /* assuming g_type_init is already called */
68 GList * asdbus_resolve_recipients (const gchar *name)
71 DBusGConnection *bus = NULL;
73 DBusGProxy *asdbus = NULL;
74 GValueArray* reply = NULL;
75 ModestProtocol *protocol = NULL;
76 ModestProtocolType protocol_type;
78 protocol = modest_protocol_registry_get_protocol_by_name (
79 modest_runtime_get_protocol_registry (),
80 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS, // MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS ?
82 protocol_type = modest_protocol_get_type_id (protocol);
83 if (!modest_account_mgr_singleton_protocol_exists(modest_runtime_get_account_mgr(), protocol_type)) {
87 const gchar *names[2];
91 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
93 /** FIXME: proper log */
94 g_printerr ("Failed to open connection to bus: %s\n", error->message);
99 asdbus = dbus_g_proxy_new_for_name (bus, "com.nokia.asdbus", "/com/nokia/asdbus", "com.nokia.asdbus");
101 if (!com_nokia_asdbus_resolve_recipients (asdbus, names, &reply, &error)) {
102 g_printerr ("com_nokia_asdbus_many_args failed: %s\n", error->message);
103 g_error_free (error);
107 if (!reply) goto CLEANUP;
108 if (2 != reply->n_values) goto CLEANUP;
109 if (G_TYPE_INT != G_VALUE_TYPE (&reply->values[0])) goto CLEANUP;
110 if (!dbus_g_type_is_collection (G_VALUE_TYPE (&reply->values[1]))) goto CLEANUP;
112 dbus_g_type_collection_value_iterate (&reply->values[1], response_iter, &result);
115 g_value_array_free (reply);
116 g_object_unref (asdbus);