1 /* Copyright (c) 2007, 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.
30 #include "libmodest-dbus-client.h"
31 #include "libmodest-dbus-api.h" /* For the API strings. */
33 //#define DBUS_API_SUBJECT_TO_CHANGE 1
34 #include <dbus/dbus.h>
35 #include <dbus/dbus-glib-lowlevel.h>
40 /** Get a comma-separated list of attachement URI strings,
41 * from a list of strings.
43 static gchar* get_attachments_string (GSList *attachments)
48 gchar *attachments_str = g_strdup("");
50 GSList *iter = attachments;
56 escaped = g_uri_escape_string ((const gchar *) (iter->data), NULL, TRUE);
57 tmp = g_strconcat(attachments_str, ",", escaped, NULL);
59 g_free(attachments_str);
60 attachments_str = tmp;
62 iter = g_slist_next(iter);
64 return attachments_str;
68 * libmodest_dbus_client_mail_to:
69 * @osso_context: a valid #osso_context_t object.
70 * @mailto_uri: A mailto URI.
72 * This function will try to do a remote procedure call (rpc)
73 * into modest (or start it if necessary) and open a composer
74 * window with the supplied parameters prefilled.
76 * Return value: Whether or not the rpc call to modest
80 libmodest_dbus_client_mail_to (osso_context_t *osso_context, const gchar *mailto_uri)
82 osso_rpc_t retval = { 0 };
83 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
85 MODEST_DBUS_METHOD_MAIL_TO, &retval,
86 DBUS_TYPE_STRING, mailto_uri,
90 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
93 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
96 osso_rpc_free_val(&retval);
102 * libmodest_dbus_client_compose_mail:
103 * @osso_context: a valid #osso_context_t object.
104 * @to: The Recipients (From: line)
105 * @cc: Recipients for carbon copies
106 * @bcc: Recipients for blind carbon copies
107 * @subject: Subject line
108 * @body: The actual body of the mail to compose.
109 * @attachments: Additional list of attachments. A list of URI strings.
111 * This function will try to do a remote procedure call (rpc)
112 * into modest (or start it if necessary) and open a composer
113 * window with the supplied parameters prefilled.
115 * Return value: Whether or not the rpc call to modest
119 libmodest_dbus_client_compose_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc,
120 const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments)
122 osso_rpc_t retval = { 0 };
124 gchar *attachments_str = get_attachments_string(attachments);
126 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
128 MODEST_DBUS_METHOD_COMPOSE_MAIL, &retval,
129 DBUS_TYPE_STRING, to,
130 DBUS_TYPE_STRING, cc,
131 DBUS_TYPE_STRING, bcc,
132 DBUS_TYPE_STRING, subject,
133 DBUS_TYPE_STRING, body,
134 DBUS_TYPE_STRING, attachments_str,
137 g_free (attachments_str);
139 if (ret != OSSO_OK) {
140 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
143 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
146 osso_rpc_free_val(&retval);
153 * libmodest_dbus_client_open_message:
154 * @osso_context: a valid #osso_context_t object.
155 * @msg_uri: A valid url to a mail
157 * This method will try to find the message supplied
158 * by @msg_uri and open it for display if found.
159 * It will use remote procedure calls (rpc) over
162 * Return value: TRUE on successs, FALSE on error
165 libmodest_dbus_client_open_message (osso_context_t *osso_context, const gchar *mail_uri)
167 osso_rpc_t retval = { 0 };
168 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
170 MODEST_DBUS_METHOD_OPEN_MESSAGE, &retval,
171 DBUS_TYPE_STRING, mail_uri,
174 if (ret != OSSO_OK) {
175 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
178 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
181 osso_rpc_free_val(&retval);
187 libmodest_dbus_client_send_and_receive (osso_context_t *osso_context)
189 osso_rpc_t retval = { 0 };
190 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
192 MODEST_DBUS_METHOD_SEND_RECEIVE, &retval,
195 if (ret != OSSO_OK) {
196 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
199 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
202 osso_rpc_free_val(&retval);
208 libmodest_dbus_client_send_and_receive_full (osso_context_t *osso_context,
209 const gchar *account,
212 osso_rpc_t retval = { 0 };
213 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
215 MODEST_DBUS_METHOD_SEND_RECEIVE_FULL, &retval,
216 DBUS_TYPE_STRING, account,
217 DBUS_TYPE_BOOLEAN, manual,
220 if (ret != OSSO_OK) {
221 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
224 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
227 osso_rpc_free_val(&retval);
233 libmodest_dbus_client_update_folder_counts (osso_context_t *osso_context,
234 const gchar *account)
236 osso_rpc_t retval = { 0 };
237 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
239 MODEST_DBUS_METHOD_UPDATE_FOLDER_COUNTS, &retval,
240 DBUS_TYPE_STRING, account,
243 if (ret != OSSO_OK) {
244 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
247 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
250 osso_rpc_free_val(&retval);
256 libmodest_dbus_client_open_default_inbox (osso_context_t *osso_context)
258 osso_rpc_t retval = { 0 };
259 const osso_return_t ret = osso_rpc_run_with_defaults(osso_context,
261 MODEST_DBUS_METHOD_OPEN_DEFAULT_INBOX, &retval,
264 if (ret != OSSO_OK) {
265 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
268 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
271 osso_rpc_free_val(&retval);
277 libmodest_dbus_client_open_account (osso_context_t *osso_context,
278 const gchar *account_id)
280 osso_rpc_t retval = { 0 };
281 const osso_return_t ret =
282 osso_rpc_run_with_defaults(osso_context,
284 MODEST_DBUS_METHOD_OPEN_ACCOUNT, &retval,
285 DBUS_TYPE_STRING, account_id,
288 if (ret != OSSO_OK) {
289 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
292 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
295 osso_rpc_free_val(&retval);
301 libmodest_dbus_client_open_edit_accounts_dialog (osso_context_t *osso_context)
303 osso_rpc_t retval = { 0 };
304 const osso_return_t ret =
305 osso_rpc_run_with_defaults(osso_context,
307 MODEST_DBUS_METHOD_OPEN_EDIT_ACCOUNTS_DIALOG, &retval,
310 if (ret != OSSO_OK) {
311 printf("debug: %s: osso_rpc_run() failed.\n", __FUNCTION__);
314 printf("debug: %s: osso_rpc_run() succeeded.\n", __FUNCTION__);
317 osso_rpc_free_val(&retval);
323 * libmodest_dbus_client_delete_message:
324 * @osso_context: a valid #osso_context_t object.
325 * @msg_uri: A valid url to a mail
327 * This method will try to find the message supplied
328 * by @msg_uri and if found delete it. It will use
329 * remote procedure calls (rpc) over dbus to do so.
331 * Return value: TRUE on successs, FALSE on error
334 libmodest_dbus_client_delete_message (osso_context_t *osso_ctx,
337 osso_rpc_t retval = { 0 };
340 ret = osso_rpc_run_with_defaults (osso_ctx,
342 MODEST_DBUS_METHOD_DELETE_MESSAGE, &retval,
343 DBUS_TYPE_STRING, msg_uri,
346 if (ret != OSSO_OK) {
347 g_debug ("debug: osso_rpc_run() failed.\n");
349 g_debug ("debug: osso_rpc_run() succeeded.\n");
352 osso_rpc_free_val (&retval);
354 return ret == OSSO_OK;
358 modest_search_hit_free (ModestSearchHit *hit)
361 g_slice_free (ModestSearchHit, hit);
365 modest_search_hit_list_free (GList *hits)
373 for (iter = hits; iter; iter = iter->next) {
374 modest_search_hit_free ((ModestSearchHit *) iter->data);
381 modest_account_hits_hits_list_free (GList *account_hits_hits_list)
385 if (account_hits_hits_list == NULL) {
389 for (iter = account_hits_hits_list; iter; iter = iter->next) {
390 ModestGetUnreadMessagesHit *hit = (ModestGetUnreadMessagesHit *) iter->data;
391 g_free (hit->subject);
392 g_slice_free (ModestGetUnreadMessagesHit, hit);
395 g_list_free (account_hits_hits_list);
399 modest_account_hits_free (ModestAccountHits *account_hits)
401 g_free (account_hits->account_id);
402 g_free (account_hits->account_name);
403 modest_account_hits_hits_list_free (account_hits->hits);
404 g_slice_free (ModestAccountHits, account_hits);
408 modest_account_hits_list_free (GList *account_hits_list)
412 if (account_hits_list == NULL) {
416 for (iter = account_hits_list; iter; iter = iter->next) {
417 modest_account_hits_free ((ModestAccountHits *) iter->data);
420 g_list_free (account_hits_list);
424 _dbus_iter_get_string_or_null (DBusMessageIter *iter)
426 const char *string = NULL;
429 dbus_message_iter_get_basic (iter, &string);
431 if (string && strlen (string)) {
432 ret = g_strdup (string);
439 _dbus_iter_get_uint64 (DBusMessageIter *iter)
445 dbus_message_iter_get_basic (iter, &ui64v);
447 ret = (guint64) ui64v;
454 _dbus_iter_get_int64 (DBusMessageIter *iter)
460 dbus_message_iter_get_basic (iter, &i64v);
468 _dbus_iter_get_boolean (DBusMessageIter *iter)
475 dbus_message_iter_get_basic (iter, &val);
477 ret = (gboolean) val;
482 /** Get the values from the complex type (SEARCH_HIT_DBUS_TYPE)
483 * in the D-Bus return message. */
484 static ModestSearchHit *
485 modest_dbus_message_iter_get_search_hit (DBusMessageIter *parent)
487 ModestSearchHit *hit;
488 DBusMessageIter child;
494 hit = g_slice_new0 (ModestSearchHit);
496 arg_type = dbus_message_iter_get_arg_type (parent);
498 if (arg_type != 'r') {
502 dbus_message_iter_recurse (parent, &child);
505 arg_type = dbus_message_iter_get_arg_type (&child);
507 if (arg_type != DBUS_TYPE_STRING) {
512 hit->msgid = _dbus_iter_get_string_or_null (&child);
514 res = dbus_message_iter_next (&child);
521 arg_type = dbus_message_iter_get_arg_type (&child);
523 if (arg_type != DBUS_TYPE_STRING) {
528 hit->subject = _dbus_iter_get_string_or_null (&child);
530 res = dbus_message_iter_next (&child);
537 arg_type = dbus_message_iter_get_arg_type (&child);
539 if (arg_type != DBUS_TYPE_STRING) {
544 hit->folder = _dbus_iter_get_string_or_null (&child);
546 res = dbus_message_iter_next (&child);
553 arg_type = dbus_message_iter_get_arg_type (&child);
555 if (arg_type != DBUS_TYPE_STRING) {
560 hit->sender = _dbus_iter_get_string_or_null (&child);
562 res = dbus_message_iter_next (&child);
569 arg_type = dbus_message_iter_get_arg_type (&child);
571 if (arg_type != DBUS_TYPE_UINT64) {
576 hit->msize = _dbus_iter_get_uint64 (&child);
578 res = dbus_message_iter_next (&child);
585 arg_type = dbus_message_iter_get_arg_type (&child);
587 if (arg_type != DBUS_TYPE_BOOLEAN) {
592 hit->has_attachment = _dbus_iter_get_boolean (&child);
594 res = dbus_message_iter_next (&child);
601 arg_type = dbus_message_iter_get_arg_type (&child);
603 if (arg_type != DBUS_TYPE_BOOLEAN) {
608 hit->is_unread = _dbus_iter_get_boolean (&child);
610 res = dbus_message_iter_next (&child);
617 arg_type = dbus_message_iter_get_arg_type (&child);
619 if (arg_type != DBUS_TYPE_INT64) {
624 hit->timestamp = _dbus_iter_get_int64 (&child);
626 res = dbus_message_iter_next (&child);
634 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
635 modest_search_hit_free (hit);
642 static ModestGetUnreadMessagesHit *
643 modest_dbus_message_iter_get_unread_messages_hit (DBusMessageIter *parent)
645 ModestGetUnreadMessagesHit *hit;
646 DBusMessageIter child;
653 arg_type = dbus_message_iter_get_arg_type (parent);
655 if (arg_type != 'r') {
659 hit = g_slice_new0 (ModestGetUnreadMessagesHit);
660 dbus_message_iter_recurse (parent, &child);
663 arg_type = dbus_message_iter_get_arg_type (&child);
665 if (arg_type != DBUS_TYPE_INT64) {
670 hit->timestamp = _dbus_iter_get_int64 (&child);
672 res = dbus_message_iter_next (&child);
679 arg_type = dbus_message_iter_get_arg_type (&child);
681 if (arg_type != DBUS_TYPE_STRING) {
686 hit->subject = _dbus_iter_get_string_or_null (&child);
688 res = dbus_message_iter_next (&child);
696 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
697 g_slice_free (ModestGetUnreadMessagesHit, hit);
705 * libmodest_dbus_client_search:
706 * @osso_ctx: A valid #osso_context_t object.
707 * @query: The term to search for.
708 * @folder: An url to specific folder or %NULL to search everywhere.
709 * @start_date: Search hits before this date will be ignored.
710 * @end_date: Search hits after this date will be ignored.
711 * @min_size: Messagers smaller then this size will be ingored.
712 * @flags: A list of flags where to search so the documentation
713 * of %ModestDBusSearchFlags for details.
714 * @hits: A pointer to a valid GList pointer that will contain the search
715 * hits (ModestSearchHit). The list and the items must be freed by the caller
716 * with modest_search_hit_list_free().
718 * This method will search the folder specified by a valid url in @folder or all
719 * known accounts (local and remote) if %NULL for matches of the search term(s)
720 * specified in @query. It is legal to specify 0 in @start_date, @end_date and
721 * @min_size to ignore these parameters during the search otherwise those message
722 * that do not meet the specifed dates or size will be ignored.
723 * Where to search, be it subject, sender or the whole body can be specified by
724 * the @flags parameter.
726 * Upon success TRUE is returned and @hits will include the search hits or the list
727 * migh be empty if none of the messages matched the search criteria. The returned
728 * list must be freed with modest_search_hit_list_free (). It is save to pass
729 * %NULL to this function so you can call this function on the result list no matter
730 * if a hit was found or not (means the list is empty - i.e. %NULL)
731 * FALSE will only be return if an error during the remote procedure call (rpc)
732 * occured or if the specified folder could not be found.
734 * NOTE: The body of a message can only be searched if it was previously downloaded by
735 * modest. This function does also not attempt do to remote searches (i.e. IMAP search).
737 * Example to search every account for message containing "no":
738 * <informalexample><programlisting>
739 * ModestDBusSearchFlags flags;
740 * osso_context_t *osso_context;
745 * [...] Initialize osso context [...]
747 * res = libmodest_dbus_client_search (osso_context,
756 * for (iter = hits; iter; iter = iter->next) {
757 * ModestSearchHit *hit = (ModestSearchHit *) iter->data;
759 * [...] Do something with the hit [...]
763 * modest_search_hit_list_free (hits);
764 * </programlisting></informalexample>
766 * Return value: TRUE if the search succeded or FALSE for an error during the search
769 libmodest_dbus_client_search (osso_context_t *osso_ctx,
775 ModestDBusSearchFlags flags,
782 DBusMessageIter iter;
783 DBusMessageIter child;
784 DBusMessage *reply = NULL;
789 dbus_int32_t flags_v;
790 dbus_uint32_t size_v;
796 con = osso_get_dbus_connection (osso_ctx);
799 g_warning ("Could not get dbus connection\n");
805 msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
808 MODEST_DBUS_METHOD_SEARCH);
811 //ULOG_ERR_F("dbus_message_new_method_call failed");
815 if (folder == NULL) {
819 sd_v = (dbus_int64_t) start_date;
820 ed_v = (dbus_int64_t) end_date;
821 flags_v = (dbus_int32_t) flags;
822 size_v = (dbus_uint32_t) min_size;
824 res = dbus_message_append_args (msg,
825 DBUS_TYPE_STRING, &query,
826 DBUS_TYPE_STRING, &folder,
827 DBUS_TYPE_INT64, &sd_v,
828 DBUS_TYPE_INT64, &ed_v,
829 DBUS_TYPE_INT32, &flags_v,
830 DBUS_TYPE_UINT32, &size_v,
833 dbus_message_set_auto_start (msg, TRUE);
835 /* Use a long timeout (2 minutes) because the search currently
836 * gets folders and messages from the servers. */
837 timeout = 120000; //milliseconds.
838 //osso_rpc_get_timeout (osso_ctx, &timeout);
840 /*printf("DEBUG: %s: Before dbus_connection_send_with_reply_and_block().\n",
842 /* TODO: Detect the timeout somehow. */
844 dbus_error_init (&err);
845 reply = dbus_connection_send_with_reply_and_block (con,
849 /* printf("DEBUG: %s: dbus_connection_send_with_reply_and_block() finished.\n",
852 dbus_message_unref (msg);
855 g_warning("%s: dbus_connection_send_with_reply_and_block() error: %s",
856 __FUNCTION__, err.message);
860 switch (dbus_message_get_type (reply)) {
862 case DBUS_MESSAGE_TYPE_ERROR:
863 dbus_set_error_from_message (&err, reply);
865 dbus_error_free (&err);
866 dbus_message_unref (reply);
869 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
870 /* ok we are good to go
871 * lets drop outa here and handle that */
874 //ULOG_WARN_F("got unknown message type as reply");
875 //retval->type = DBUS_TYPE_STRING;
876 //retval->value.s = g_strdup("Invalid return value");
878 dbus_message_unref (reply);
882 g_debug ("%s: message return", __FUNCTION__);
884 dbus_message_iter_init (reply, &iter);
885 arg_type = dbus_message_iter_get_arg_type (&iter);
887 dbus_message_iter_recurse (&iter, &child);
891 ModestSearchHit *hit;
893 hit = modest_dbus_message_iter_get_search_hit (&child);
896 *hits = g_list_prepend (*hits, hit);
899 } while (dbus_message_iter_next (&child));
901 dbus_message_unref (reply);
904 /* TODO: This is from osso source, do we need it? */
906 /* Tell TaskNavigator to show "launch banner" */
907 msg = dbus_message_new_method_call (TASK_NAV_SERVICE,
908 APP_LAUNCH_BANNER_METHOD_PATH,
909 APP_LAUNCH_BANNER_METHOD_INTERFACE,
910 APP_LAUNCH_BANNER_METHOD);
913 g_warn ("dbus_message_new_method_call failed");
918 dbus_message_append_args (msg,
923 b = dbus_connection_send (conn, msg, NULL);
926 ULOG_WARN_F("dbus_connection_send failed");
929 dbus_message_unref (msg);
936 static ModestAccountHits *
937 modest_dbus_message_iter_get_account_hits (DBusMessageIter *parent)
940 ModestAccountHits *account_hits;
944 DBusMessageIter child, traverse;
947 account_hits = g_slice_new0 (ModestAccountHits);
949 arg_type = dbus_message_iter_get_arg_type (parent);
951 if (arg_type != 'r') {
955 dbus_message_iter_recurse (parent, &child);
958 arg_type = dbus_message_iter_get_arg_type (&child);
960 if (arg_type != DBUS_TYPE_STRING) {
965 account_hits->account_id = _dbus_iter_get_string_or_null (&child);
967 res = dbus_message_iter_next (&child);
974 arg_type = dbus_message_iter_get_arg_type (&child);
976 if (arg_type != DBUS_TYPE_STRING) {
981 account_hits->account_name = _dbus_iter_get_string_or_null (&child);
983 res = dbus_message_iter_next (&child);
990 dbus_message_iter_recurse (&child, &traverse);
991 account_hits->hits = NULL;
994 ModestGetUnreadMessagesHit *hit;
996 hit = modest_dbus_message_iter_get_unread_messages_hit (&traverse);
998 account_hits->hits = g_list_prepend (account_hits->hits, hit);
1000 } while (dbus_message_iter_next (&traverse));
1003 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
1004 modest_account_hits_free (account_hits);
1005 account_hits = NULL;
1008 return account_hits;
1012 libmodest_dbus_client_get_unread_messages (osso_context_t *osso_ctx,
1013 gint msgs_per_account,
1014 GList **account_hits_lists)
1018 DBusMessageIter iter;
1019 DBusMessageIter child;
1020 DBusMessage *reply = NULL;
1023 DBusConnection *con;
1025 dbus_int32_t msgs_per_account_v;
1029 if (msgs_per_account < 1) {
1033 con = osso_get_dbus_connection (osso_ctx);
1036 g_warning ("Could not get dbus connection\n");
1042 msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
1045 MODEST_DBUS_METHOD_GET_UNREAD_MESSAGES);
1048 //ULOG_ERR_F("dbus_message_new_method_call failed");
1052 msgs_per_account_v = (dbus_int32_t) msgs_per_account;
1054 res = dbus_message_append_args (msg,
1055 DBUS_TYPE_INT32, &msgs_per_account,
1058 dbus_message_set_auto_start (msg, TRUE);
1060 timeout = 120000; //milliseconds.
1062 dbus_error_init (&err);
1063 reply = dbus_connection_send_with_reply_and_block (con,
1068 dbus_message_unref (msg);
1071 g_warning("%s: dbus_connection_send_with_reply_and_block() error: %s",
1072 __FUNCTION__, err.message);
1076 switch (dbus_message_get_type (reply)) {
1078 case DBUS_MESSAGE_TYPE_ERROR:
1079 dbus_set_error_from_message (&err, reply);
1081 dbus_error_free (&err);
1082 dbus_message_unref (reply);
1085 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1086 /* ok we are good to go
1087 * lets drop outa here and handle that */
1090 //ULOG_WARN_F("got unknown message type as reply");
1091 //retval->type = DBUS_TYPE_STRING;
1092 //retval->value.s = g_strdup("Invalid return value");
1094 dbus_message_unref (reply);
1098 g_debug ("%s: message return", __FUNCTION__);
1100 dbus_message_iter_init (reply, &iter);
1101 arg_type = dbus_message_iter_get_arg_type (&iter);
1103 dbus_message_iter_recurse (&iter, &child);
1104 *account_hits_lists = NULL;
1107 ModestAccountHits *account_hits;
1109 account_hits = modest_dbus_message_iter_get_account_hits (&child);
1112 *account_hits_lists = g_list_prepend (*account_hits_lists, account_hits);
1115 } while (dbus_message_iter_next (&child));
1117 dbus_message_unref (reply);
1125 modest_folder_result_free (ModestFolderResult *item)
1127 g_free (item->folder_name);
1128 g_free (item->folder_uri);
1129 g_slice_free (ModestFolderResult, item);
1133 modest_folder_result_list_free (GList *list)
1141 for (iter = list; iter; iter = iter->next) {
1142 modest_folder_result_free ((ModestFolderResult *) iter->data);
1149 /** Get the values from the complex type (GET_FOLDERS_RESULT_DBUS_TYPE)
1150 * in the D-Bus return message. */
1151 static ModestFolderResult *
1152 modest_dbus_message_iter_get_folder_item (DBusMessageIter *parent)
1154 gboolean error = FALSE;
1155 ModestFolderResult *item = g_slice_new0 (ModestFolderResult);
1157 int arg_type = dbus_message_iter_get_arg_type (parent);
1159 if (arg_type != 'r') {
1163 DBusMessageIter child;
1164 dbus_message_iter_recurse (parent, &child);
1167 arg_type = dbus_message_iter_get_arg_type (&child);
1169 if (arg_type != DBUS_TYPE_STRING) {
1174 item->folder_name = _dbus_iter_get_string_or_null (&child);
1177 dbus_bool_t res = dbus_message_iter_next (&child);
1184 arg_type = dbus_message_iter_get_arg_type (&child);
1186 if (arg_type != DBUS_TYPE_STRING) {
1191 item->folder_uri = _dbus_iter_get_string_or_null (&child);
1196 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
1197 modest_folder_result_free (item);
1205 * libmodest_dbus_client_get_folders:
1206 * @osso_ctx: A valid #osso_context_t object.
1207 * @folders: A pointer to a valid GList pointer that will contain the folder items
1208 * (ModestFolderResult). The list and the items must be freed by the caller
1209 * with modest_folder_result_list_free().
1211 * This method will obtain a list of folders in the default account.
1213 * Upon success TRUE is returned and @folders will include the folders or the list
1214 * might be empty if there are no folders. The returned
1215 * list must be freed with modest_folder_result_list_free ().
1217 * NOTE: A folder will only be retrieved if it was previously downloaded by
1218 * modest. This function does also not attempt do to remote refreshes (i.e. IMAP).
1220 * Return value: TRUE if the request succeded or FALSE for an error.
1223 libmodest_dbus_client_get_folders (osso_context_t *osso_ctx,
1226 /* Initialize output argument: */
1232 DBusConnection *con = osso_get_dbus_connection (osso_ctx);
1235 g_warning ("Could not get dbus connection\n");
1240 DBusMessage *msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
1243 MODEST_DBUS_METHOD_GET_FOLDERS);
1246 //ULOG_ERR_F("dbus_message_new_method_call failed");
1250 dbus_message_set_auto_start (msg, TRUE);
1252 /* Use a long timeout (2 minutes) because the search currently
1253 * gets folders from the servers. */
1254 gint timeout = 120000;
1255 //osso_rpc_get_timeout (osso_ctx, &timeout);
1258 dbus_error_init (&err);
1259 DBusMessage *reply = dbus_connection_send_with_reply_and_block (con,
1264 dbus_message_unref (msg);
1267 if (reply == NULL) {
1268 g_warning("%s: dbus_connection_send_with_reply_and_block() error:\n %s",
1269 __FUNCTION__, err.message);
1273 switch (dbus_message_get_type (reply)) {
1275 case DBUS_MESSAGE_TYPE_ERROR:
1276 dbus_set_error_from_message (&err, reply);
1278 dbus_error_free (&err);
1279 dbus_message_unref (reply);
1282 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1283 /* ok we are good to go
1284 * lets drop outa here and handle that */
1287 //ULOG_WARN_F("got unknown message type as reply");
1288 //retval->type = DBUS_TYPE_STRING;
1289 //retval->value.s = g_strdup("Invalid return value");
1291 dbus_message_unref (reply);
1295 g_debug ("%s: message return", __FUNCTION__);
1297 DBusMessageIter iter;
1298 dbus_message_iter_init (reply, &iter);
1299 /* int arg_type = dbus_message_iter_get_arg_type (&iter); */
1301 DBusMessageIter child;
1302 dbus_message_iter_recurse (&iter, &child);
1305 ModestFolderResult *item = modest_dbus_message_iter_get_folder_item (&child);
1308 *folders = g_list_append (*folders, item);
1311 } while (dbus_message_iter_next (&child));
1313 dbus_message_unref (reply);
1316 /* TODO: This is from osso source, do we need it? */
1318 /* Tell TaskNavigator to show "launch banner" */
1319 msg = dbus_message_new_method_call (TASK_NAV_SERVICE,
1320 APP_LAUNCH_BANNER_METHOD_PATH,
1321 APP_LAUNCH_BANNER_METHOD_INTERFACE,
1322 APP_LAUNCH_BANNER_METHOD);
1325 g_warn ("dbus_message_new_method_call failed");
1330 dbus_message_append_args (msg,
1335 b = dbus_connection_send (conn, msg, NULL);
1338 ULOG_WARN_F("dbus_connection_send failed");
1341 dbus_message_unref (msg);