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 g_free (account_hits->store_protocol);
404 modest_account_hits_hits_list_free (account_hits->hits);
405 g_slice_free (ModestAccountHits, account_hits);
409 modest_account_hits_list_free (GList *account_hits_list)
413 if (account_hits_list == NULL) {
417 for (iter = account_hits_list; iter; iter = iter->next) {
418 modest_account_hits_free ((ModestAccountHits *) iter->data);
421 g_list_free (account_hits_list);
425 _dbus_iter_get_string_or_null (DBusMessageIter *iter)
427 const char *string = NULL;
430 dbus_message_iter_get_basic (iter, &string);
432 if (string && strlen (string)) {
433 ret = g_strdup (string);
440 _dbus_iter_get_uint64 (DBusMessageIter *iter)
446 dbus_message_iter_get_basic (iter, &ui64v);
448 ret = (guint64) ui64v;
455 _dbus_iter_get_int64 (DBusMessageIter *iter)
461 dbus_message_iter_get_basic (iter, &i64v);
469 _dbus_iter_get_boolean (DBusMessageIter *iter)
476 dbus_message_iter_get_basic (iter, &val);
478 ret = (gboolean) val;
483 /** Get the values from the complex type (SEARCH_HIT_DBUS_TYPE)
484 * in the D-Bus return message. */
485 static ModestSearchHit *
486 modest_dbus_message_iter_get_search_hit (DBusMessageIter *parent)
488 ModestSearchHit *hit;
489 DBusMessageIter child;
495 hit = g_slice_new0 (ModestSearchHit);
497 arg_type = dbus_message_iter_get_arg_type (parent);
499 if (arg_type != 'r') {
503 dbus_message_iter_recurse (parent, &child);
506 arg_type = dbus_message_iter_get_arg_type (&child);
508 if (arg_type != DBUS_TYPE_STRING) {
513 hit->msgid = _dbus_iter_get_string_or_null (&child);
515 res = dbus_message_iter_next (&child);
522 arg_type = dbus_message_iter_get_arg_type (&child);
524 if (arg_type != DBUS_TYPE_STRING) {
529 hit->subject = _dbus_iter_get_string_or_null (&child);
531 res = dbus_message_iter_next (&child);
538 arg_type = dbus_message_iter_get_arg_type (&child);
540 if (arg_type != DBUS_TYPE_STRING) {
545 hit->folder = _dbus_iter_get_string_or_null (&child);
547 res = dbus_message_iter_next (&child);
554 arg_type = dbus_message_iter_get_arg_type (&child);
556 if (arg_type != DBUS_TYPE_STRING) {
561 hit->sender = _dbus_iter_get_string_or_null (&child);
563 res = dbus_message_iter_next (&child);
570 arg_type = dbus_message_iter_get_arg_type (&child);
572 if (arg_type != DBUS_TYPE_UINT64) {
577 hit->msize = _dbus_iter_get_uint64 (&child);
579 res = dbus_message_iter_next (&child);
586 arg_type = dbus_message_iter_get_arg_type (&child);
588 if (arg_type != DBUS_TYPE_BOOLEAN) {
593 hit->has_attachment = _dbus_iter_get_boolean (&child);
595 res = dbus_message_iter_next (&child);
602 arg_type = dbus_message_iter_get_arg_type (&child);
604 if (arg_type != DBUS_TYPE_BOOLEAN) {
609 hit->is_unread = _dbus_iter_get_boolean (&child);
611 res = dbus_message_iter_next (&child);
618 arg_type = dbus_message_iter_get_arg_type (&child);
620 if (arg_type != DBUS_TYPE_INT64) {
625 hit->timestamp = _dbus_iter_get_int64 (&child);
627 res = dbus_message_iter_next (&child);
635 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
636 modest_search_hit_free (hit);
643 static ModestGetUnreadMessagesHit *
644 modest_dbus_message_iter_get_unread_messages_hit (DBusMessageIter *parent)
646 ModestGetUnreadMessagesHit *hit;
647 DBusMessageIter child;
654 arg_type = dbus_message_iter_get_arg_type (parent);
656 if (arg_type != 'r') {
660 hit = g_slice_new0 (ModestGetUnreadMessagesHit);
661 dbus_message_iter_recurse (parent, &child);
664 arg_type = dbus_message_iter_get_arg_type (&child);
666 if (arg_type != DBUS_TYPE_INT64) {
671 hit->timestamp = _dbus_iter_get_int64 (&child);
673 res = dbus_message_iter_next (&child);
680 arg_type = dbus_message_iter_get_arg_type (&child);
682 if (arg_type != DBUS_TYPE_STRING) {
687 hit->subject = _dbus_iter_get_string_or_null (&child);
689 res = dbus_message_iter_next (&child);
697 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
698 g_slice_free (ModestGetUnreadMessagesHit, hit);
706 * libmodest_dbus_client_search:
707 * @osso_ctx: A valid #osso_context_t object.
708 * @query: The term to search for.
709 * @folder: An url to specific folder or %NULL to search everywhere.
710 * @start_date: Search hits before this date will be ignored.
711 * @end_date: Search hits after this date will be ignored.
712 * @min_size: Messagers smaller then this size will be ingored.
713 * @flags: A list of flags where to search so the documentation
714 * of %ModestDBusSearchFlags for details.
715 * @hits: A pointer to a valid GList pointer that will contain the search
716 * hits (ModestSearchHit). The list and the items must be freed by the caller
717 * with modest_search_hit_list_free().
719 * This method will search the folder specified by a valid url in @folder or all
720 * known accounts (local and remote) if %NULL for matches of the search term(s)
721 * specified in @query. It is legal to specify 0 in @start_date, @end_date and
722 * @min_size to ignore these parameters during the search otherwise those message
723 * that do not meet the specifed dates or size will be ignored.
724 * Where to search, be it subject, sender or the whole body can be specified by
725 * the @flags parameter.
727 * Upon success TRUE is returned and @hits will include the search hits or the list
728 * migh be empty if none of the messages matched the search criteria. The returned
729 * list must be freed with modest_search_hit_list_free (). It is save to pass
730 * %NULL to this function so you can call this function on the result list no matter
731 * if a hit was found or not (means the list is empty - i.e. %NULL)
732 * FALSE will only be return if an error during the remote procedure call (rpc)
733 * occured or if the specified folder could not be found.
735 * NOTE: The body of a message can only be searched if it was previously downloaded by
736 * modest. This function does also not attempt do to remote searches (i.e. IMAP search).
738 * Example to search every account for message containing "no":
739 * <informalexample><programlisting>
740 * ModestDBusSearchFlags flags;
741 * osso_context_t *osso_context;
746 * [...] Initialize osso context [...]
748 * res = libmodest_dbus_client_search (osso_context,
757 * for (iter = hits; iter; iter = iter->next) {
758 * ModestSearchHit *hit = (ModestSearchHit *) iter->data;
760 * [...] Do something with the hit [...]
764 * modest_search_hit_list_free (hits);
765 * </programlisting></informalexample>
767 * Return value: TRUE if the search succeded or FALSE for an error during the search
770 libmodest_dbus_client_search (osso_context_t *osso_ctx,
776 ModestDBusSearchFlags flags,
783 DBusMessageIter iter;
784 DBusMessageIter child;
785 DBusMessage *reply = NULL;
790 dbus_int32_t flags_v;
791 dbus_uint32_t size_v;
797 con = osso_get_dbus_connection (osso_ctx);
800 g_warning ("Could not get dbus connection\n");
806 msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
809 MODEST_DBUS_METHOD_SEARCH);
812 //ULOG_ERR_F("dbus_message_new_method_call failed");
816 if (folder == NULL) {
820 sd_v = (dbus_int64_t) start_date;
821 ed_v = (dbus_int64_t) end_date;
822 flags_v = (dbus_int32_t) flags;
823 size_v = (dbus_uint32_t) min_size;
825 res = dbus_message_append_args (msg,
826 DBUS_TYPE_STRING, &query,
827 DBUS_TYPE_STRING, &folder,
828 DBUS_TYPE_INT64, &sd_v,
829 DBUS_TYPE_INT64, &ed_v,
830 DBUS_TYPE_INT32, &flags_v,
831 DBUS_TYPE_UINT32, &size_v,
834 dbus_message_set_auto_start (msg, TRUE);
836 /* Use a long timeout (2 minutes) because the search currently
837 * gets folders and messages from the servers. */
838 timeout = 120000; //milliseconds.
839 //osso_rpc_get_timeout (osso_ctx, &timeout);
841 /*printf("DEBUG: %s: Before dbus_connection_send_with_reply_and_block().\n",
843 /* TODO: Detect the timeout somehow. */
845 dbus_error_init (&err);
846 reply = dbus_connection_send_with_reply_and_block (con,
850 /* printf("DEBUG: %s: dbus_connection_send_with_reply_and_block() finished.\n",
853 dbus_message_unref (msg);
856 g_warning("%s: dbus_connection_send_with_reply_and_block() error: %s",
857 __FUNCTION__, err.message);
861 switch (dbus_message_get_type (reply)) {
863 case DBUS_MESSAGE_TYPE_ERROR:
864 dbus_set_error_from_message (&err, reply);
866 dbus_error_free (&err);
867 dbus_message_unref (reply);
870 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
871 /* ok we are good to go
872 * lets drop outa here and handle that */
875 //ULOG_WARN_F("got unknown message type as reply");
876 //retval->type = DBUS_TYPE_STRING;
877 //retval->value.s = g_strdup("Invalid return value");
879 dbus_message_unref (reply);
883 g_debug ("%s: message return", __FUNCTION__);
885 dbus_message_iter_init (reply, &iter);
886 arg_type = dbus_message_iter_get_arg_type (&iter);
888 dbus_message_iter_recurse (&iter, &child);
892 ModestSearchHit *hit;
894 hit = modest_dbus_message_iter_get_search_hit (&child);
897 *hits = g_list_prepend (*hits, hit);
900 } while (dbus_message_iter_next (&child));
902 dbus_message_unref (reply);
905 /* TODO: This is from osso source, do we need it? */
907 /* Tell TaskNavigator to show "launch banner" */
908 msg = dbus_message_new_method_call (TASK_NAV_SERVICE,
909 APP_LAUNCH_BANNER_METHOD_PATH,
910 APP_LAUNCH_BANNER_METHOD_INTERFACE,
911 APP_LAUNCH_BANNER_METHOD);
914 g_warn ("dbus_message_new_method_call failed");
919 dbus_message_append_args (msg,
924 b = dbus_connection_send (conn, msg, NULL);
927 ULOG_WARN_F("dbus_connection_send failed");
930 dbus_message_unref (msg);
937 static ModestAccountHits *
938 modest_dbus_message_iter_get_account_hits (DBusMessageIter *parent)
941 ModestAccountHits *account_hits;
945 DBusMessageIter child, traverse;
948 account_hits = g_slice_new0 (ModestAccountHits);
950 arg_type = dbus_message_iter_get_arg_type (parent);
952 if (arg_type != 'r') {
956 dbus_message_iter_recurse (parent, &child);
959 arg_type = dbus_message_iter_get_arg_type (&child);
961 if (arg_type != DBUS_TYPE_STRING) {
966 account_hits->account_id = _dbus_iter_get_string_or_null (&child);
968 res = dbus_message_iter_next (&child);
975 arg_type = dbus_message_iter_get_arg_type (&child);
977 if (arg_type != DBUS_TYPE_STRING) {
982 account_hits->account_name = _dbus_iter_get_string_or_null (&child);
984 res = dbus_message_iter_next (&child);
991 arg_type = dbus_message_iter_get_arg_type (&child);
993 if (arg_type != DBUS_TYPE_STRING) {
998 account_hits->store_protocol = _dbus_iter_get_string_or_null (&child);
1000 res = dbus_message_iter_next (&child);
1007 arg_type = dbus_message_iter_get_arg_type (&child);
1009 if (arg_type != DBUS_TYPE_INT64) {
1014 account_hits->unread_count = _dbus_iter_get_int64 (&child);
1016 res = dbus_message_iter_next (&child);
1023 dbus_message_iter_recurse (&child, &traverse);
1024 account_hits->hits = NULL;
1027 ModestGetUnreadMessagesHit *hit;
1029 hit = modest_dbus_message_iter_get_unread_messages_hit (&traverse);
1031 account_hits->hits = g_list_prepend (account_hits->hits, hit);
1033 } while (dbus_message_iter_next (&traverse));
1036 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
1037 modest_account_hits_free (account_hits);
1038 account_hits = NULL;
1041 return account_hits;
1045 libmodest_dbus_client_get_unread_messages (osso_context_t *osso_ctx,
1046 gint msgs_per_account,
1047 GList **account_hits_lists)
1051 DBusMessageIter iter;
1052 DBusMessageIter child;
1053 DBusMessage *reply = NULL;
1056 DBusConnection *con;
1058 dbus_int32_t msgs_per_account_v;
1062 if (msgs_per_account < 1) {
1066 con = osso_get_dbus_connection (osso_ctx);
1069 g_warning ("Could not get dbus connection\n");
1075 msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
1078 MODEST_DBUS_METHOD_GET_UNREAD_MESSAGES);
1081 //ULOG_ERR_F("dbus_message_new_method_call failed");
1085 msgs_per_account_v = (dbus_int32_t) msgs_per_account;
1087 res = dbus_message_append_args (msg,
1088 DBUS_TYPE_INT32, &msgs_per_account,
1091 dbus_message_set_auto_start (msg, TRUE);
1093 timeout = 120000; //milliseconds.
1095 dbus_error_init (&err);
1096 reply = dbus_connection_send_with_reply_and_block (con,
1101 dbus_message_unref (msg);
1104 g_warning("%s: dbus_connection_send_with_reply_and_block() error: %s",
1105 __FUNCTION__, err.message);
1109 switch (dbus_message_get_type (reply)) {
1111 case DBUS_MESSAGE_TYPE_ERROR:
1112 dbus_set_error_from_message (&err, reply);
1114 dbus_error_free (&err);
1115 dbus_message_unref (reply);
1118 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1119 /* ok we are good to go
1120 * lets drop outa here and handle that */
1123 //ULOG_WARN_F("got unknown message type as reply");
1124 //retval->type = DBUS_TYPE_STRING;
1125 //retval->value.s = g_strdup("Invalid return value");
1127 dbus_message_unref (reply);
1131 g_debug ("%s: message return", __FUNCTION__);
1133 dbus_message_iter_init (reply, &iter);
1134 arg_type = dbus_message_iter_get_arg_type (&iter);
1136 dbus_message_iter_recurse (&iter, &child);
1137 *account_hits_lists = NULL;
1140 ModestAccountHits *account_hits;
1142 account_hits = modest_dbus_message_iter_get_account_hits (&child);
1145 *account_hits_lists = g_list_prepend (*account_hits_lists, account_hits);
1148 } while (dbus_message_iter_next (&child));
1150 dbus_message_unref (reply);
1158 modest_folder_result_free (ModestFolderResult *item)
1160 g_free (item->folder_name);
1161 g_free (item->folder_uri);
1162 g_slice_free (ModestFolderResult, item);
1166 modest_folder_result_list_free (GList *list)
1174 for (iter = list; iter; iter = iter->next) {
1175 modest_folder_result_free ((ModestFolderResult *) iter->data);
1182 /** Get the values from the complex type (GET_FOLDERS_RESULT_DBUS_TYPE)
1183 * in the D-Bus return message. */
1184 static ModestFolderResult *
1185 modest_dbus_message_iter_get_folder_item (DBusMessageIter *parent)
1187 gboolean error = FALSE;
1188 ModestFolderResult *item = g_slice_new0 (ModestFolderResult);
1190 int arg_type = dbus_message_iter_get_arg_type (parent);
1192 if (arg_type != 'r') {
1196 DBusMessageIter child;
1197 dbus_message_iter_recurse (parent, &child);
1200 arg_type = dbus_message_iter_get_arg_type (&child);
1202 if (arg_type != DBUS_TYPE_STRING) {
1207 item->folder_name = _dbus_iter_get_string_or_null (&child);
1210 dbus_bool_t res = dbus_message_iter_next (&child);
1217 arg_type = dbus_message_iter_get_arg_type (&child);
1219 if (arg_type != DBUS_TYPE_STRING) {
1224 item->folder_uri = _dbus_iter_get_string_or_null (&child);
1229 g_warning ("%s: Error during unmarshalling", __FUNCTION__);
1230 modest_folder_result_free (item);
1238 * libmodest_dbus_client_get_folders:
1239 * @osso_ctx: A valid #osso_context_t object.
1240 * @folders: A pointer to a valid GList pointer that will contain the folder items
1241 * (ModestFolderResult). The list and the items must be freed by the caller
1242 * with modest_folder_result_list_free().
1244 * This method will obtain a list of folders in the default account.
1246 * Upon success TRUE is returned and @folders will include the folders or the list
1247 * might be empty if there are no folders. The returned
1248 * list must be freed with modest_folder_result_list_free ().
1250 * NOTE: A folder will only be retrieved if it was previously downloaded by
1251 * modest. This function does also not attempt do to remote refreshes (i.e. IMAP).
1253 * Return value: TRUE if the request succeded or FALSE for an error.
1256 libmodest_dbus_client_get_folders (osso_context_t *osso_ctx,
1259 /* Initialize output argument: */
1265 DBusConnection *con = osso_get_dbus_connection (osso_ctx);
1268 g_warning ("Could not get dbus connection\n");
1273 DBusMessage *msg = dbus_message_new_method_call (MODEST_DBUS_SERVICE,
1276 MODEST_DBUS_METHOD_GET_FOLDERS);
1279 //ULOG_ERR_F("dbus_message_new_method_call failed");
1283 dbus_message_set_auto_start (msg, TRUE);
1285 /* Use a long timeout (2 minutes) because the search currently
1286 * gets folders from the servers. */
1287 gint timeout = 120000;
1288 //osso_rpc_get_timeout (osso_ctx, &timeout);
1291 dbus_error_init (&err);
1292 DBusMessage *reply = dbus_connection_send_with_reply_and_block (con,
1297 dbus_message_unref (msg);
1300 if (reply == NULL) {
1301 g_warning("%s: dbus_connection_send_with_reply_and_block() error:\n %s",
1302 __FUNCTION__, err.message);
1306 switch (dbus_message_get_type (reply)) {
1308 case DBUS_MESSAGE_TYPE_ERROR:
1309 dbus_set_error_from_message (&err, reply);
1311 dbus_error_free (&err);
1312 dbus_message_unref (reply);
1315 case DBUS_MESSAGE_TYPE_METHOD_RETURN:
1316 /* ok we are good to go
1317 * lets drop outa here and handle that */
1320 //ULOG_WARN_F("got unknown message type as reply");
1321 //retval->type = DBUS_TYPE_STRING;
1322 //retval->value.s = g_strdup("Invalid return value");
1324 dbus_message_unref (reply);
1328 g_debug ("%s: message return", __FUNCTION__);
1330 DBusMessageIter iter;
1331 dbus_message_iter_init (reply, &iter);
1332 /* int arg_type = dbus_message_iter_get_arg_type (&iter); */
1334 DBusMessageIter child;
1335 dbus_message_iter_recurse (&iter, &child);
1338 ModestFolderResult *item = modest_dbus_message_iter_get_folder_item (&child);
1341 *folders = g_list_append (*folders, item);
1344 } while (dbus_message_iter_next (&child));
1346 dbus_message_unref (reply);
1349 /* TODO: This is from osso source, do we need it? */
1351 /* Tell TaskNavigator to show "launch banner" */
1352 msg = dbus_message_new_method_call (TASK_NAV_SERVICE,
1353 APP_LAUNCH_BANNER_METHOD_PATH,
1354 APP_LAUNCH_BANNER_METHOD_INTERFACE,
1355 APP_LAUNCH_BANNER_METHOD);
1358 g_warn ("dbus_message_new_method_call failed");
1363 dbus_message_append_args (msg,
1368 b = dbus_connection_send (conn, msg, NULL);
1371 ULOG_WARN_F("dbus_connection_send failed");
1374 dbus_message_unref (msg);