From: Murray Cumming Date: Tue, 24 Apr 2007 13:49:14 +0000 (+0000) Subject: 2007-04-24 Murray Cumming X-Git-Tag: git_migration_finished~3805 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=ebe6325a7d8763cef1b7b508898f52a04be535d1 2007-04-24 Murray Cumming * libmodest-dbus-client/libmodest-dbus-client-1.0.pc.in: Added file to fix the build. Sorry. * src/dbus_api/Makefile.am: * src/dbus_api/modest-dbus-api.h: * src/dbus_api/modest-dbus-callbacks.h: * src/dbus_api/modest-dbus-callbacks.c: (on_send_mail), (modest_dbus_req_handler): Put constants in a separate header so it can be reused by the client library, without duplication * libmodest-dbus-client/Makefile.am: * libmodest-dbus-client/libmodest-dbus-client.c: (libmodest_dbus_client_call_helloworld), (libmodfest_dbus_client_send_mail), (libmodfest_dbus_client_mailto), (libmodfest_dbus_client_open_message): * libmodest-dbus-client/libmodest-dbus-client.h: (Partly) Implement a send_mail D-Bus method. * tests/dbus_api/Makefile.am: * tests/dbus_api/test_send_mail.c: (main): Added a test for the send_email D-Bus method. pmo-trunk-r1652 --- diff --git a/ChangeLog2 b/ChangeLog2 index f61482f..9ebb61f 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,31 @@ 2007-04-24 Murray Cumming + * libmodest-dbus-client/libmodest-dbus-client-1.0.pc.in: + Added file to fix the build. Sorry. + + * src/dbus_api/Makefile.am: + * src/dbus_api/modest-dbus-api.h: + * src/dbus_api/modest-dbus-callbacks.h: + * src/dbus_api/modest-dbus-callbacks.c: (on_send_mail), + (modest_dbus_req_handler): + Put constants in a separate header so it can be reused by the + client library, without duplication + + * libmodest-dbus-client/Makefile.am: + * libmodest-dbus-client/libmodest-dbus-client.c: + (libmodest_dbus_client_call_helloworld), + (libmodfest_dbus_client_send_mail), + (libmodfest_dbus_client_mailto), + (libmodfest_dbus_client_open_message): + * libmodest-dbus-client/libmodest-dbus-client.h: + (Partly) Implement a send_mail D-Bus method. + + * tests/dbus_api/Makefile.am: + * tests/dbus_api/test_send_mail.c: (main): Added a test for + the send_email D-Bus method. + +2007-04-24 Murray Cumming + * Makefile.am: * configure.ac: * libmodest-dbus-client/Makefile.am: diff --git a/libmodest-dbus-client/Makefile.am b/libmodest-dbus-client/Makefile.am index 7e2e8ff..13b7ffb 100644 --- a/libmodest-dbus-client/Makefile.am +++ b/libmodest-dbus-client/Makefile.am @@ -31,6 +31,7 @@ INCLUDES=\ $(MODEST_LIBTINYMAIL_GNOME_DESKTOP_CFLAGS) \ $(MODEST_LIBTINYMAIL_MAEMO_CFLAGS) \ -I$(MODEST_PLATFORM) \ + -I$(top_srcdir)/src \ -DPREFIX=\"@prefix@\" \ -DMODEST_LOCALEDIR=\"$(MODEST_LOCALEDIR)\" \ -DMODEST_PLATFORM=\"$(MODEST_PLATFORM)\" \ diff --git a/libmodest-dbus-client/README b/libmodest-dbus-client/README index e69de29..cd4379e 100644 --- a/libmodest-dbus-client/README +++ b/libmodest-dbus-client/README @@ -0,0 +1,2 @@ +This is a C convenience API for using the modest D-Bus API, without needing to use the generic D-Bus +client library directly. \ No newline at end of file diff --git a/libmodest-dbus-client/libmodest-dbus-client-1.0.pc.in b/libmodest-dbus-client/libmodest-dbus-client-1.0.pc.in new file mode 100644 index 0000000..828338f --- /dev/null +++ b/libmodest-dbus-client/libmodest-dbus-client-1.0.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libmodest-dbus-client-1.0 +Description: Some library. +Requires: glib-2.0 dbus-1 +Version: @VERSION@ +Libs: -L${libdir} -lmodest-dbus-client-1.0 +Cflags: -I${includedir}/modest-dbus-client-1.0 -I${libdir}/modest-dbus-client-1.0/include \ No newline at end of file diff --git a/libmodest-dbus-client/libmodest-dbus-client.c b/libmodest-dbus-client/libmodest-dbus-client.c index e0c4742..98522e1 100644 --- a/libmodest-dbus-client/libmodest-dbus-client.c +++ b/libmodest-dbus-client/libmodest-dbus-client.c @@ -28,9 +28,8 @@ */ #include "libmodest-dbus-client.h" +#include /* For the API strings. */ -#define MODEST_DBUS_NAME "modestemail" -#define MODEST_DBUS_EXAMPLE_MESSAGE "HelloWorld" gboolean libmodest_dbus_client_call_helloworld(osso_context_t *osso_context) @@ -38,7 +37,8 @@ libmodest_dbus_client_call_helloworld(osso_context_t *osso_context) osso_rpc_t retval; const osso_return_t ret = osso_rpc_run_with_defaults(osso_context, MODEST_DBUS_NAME, - MODEST_DBUS_EXAMPLE_MESSAGE, &retval, DBUS_TYPE_INVALID); + MODEST_DBUS_EXAMPLE_MESSAGE, &retval, + DBUS_TYPE_INVALID); if (ret != OSSO_OK) { printf("debug: osso_rpc_run() failed.\n"); @@ -51,3 +51,44 @@ libmodest_dbus_client_call_helloworld(osso_context_t *osso_context) return TRUE; } + +gboolean +libmodfest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc, + const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments) +{ + osso_rpc_t retval; + const osso_return_t ret = osso_rpc_run_with_defaults(osso_context, + MODEST_DBUS_NAME, + MODEST_DBUS_METHOD_SEND_MAIL, &retval, + DBUS_TYPE_STRING, to, + DBUS_TYPE_STRING, cc, + DBUS_TYPE_STRING, bcc, + DBUS_TYPE_STRING, subject, + DBUS_TYPE_STRING, body, + DBUS_TYPE_INVALID); + + if (ret != OSSO_OK) { + printf("debug: osso_rpc_run() failed.\n"); + return FALSE; + } else { + printf("debug: osso_rpc_run() succeeded.\n"); + } + + osso_rpc_free_val(&retval); + + return TRUE; +} + +gboolean +libmodfest_dbus_client_mailto (osso_context_t *osso_context, const gchar *mailto_uri) +{ + return FALSE; +} + +gboolean +libmodfest_dbus_client_open_message (osso_context_t *osso_context, const gchar *mail_uri) +{ + return FALSE; +} + + diff --git a/libmodest-dbus-client/libmodest-dbus-client.h b/libmodest-dbus-client/libmodest-dbus-client.h index 7d8dba7..58dcd8e 100644 --- a/libmodest-dbus-client/libmodest-dbus-client.h +++ b/libmodest-dbus-client/libmodest-dbus-client.h @@ -31,9 +31,20 @@ #define __LIBMODEST_DBUS_CLIENT_H__ #include +#include #include gboolean -libmodest_dbus_client_call_helloworld(osso_context_t *osso_context); +libmodest_dbus_client_call_helloworld (osso_context_t *osso_context); + +gboolean +libmodfest_dbus_client_send_mail (osso_context_t *osso_context, const gchar *to, const gchar *cc, + const gchar *bcc, const gchar* subject, const gchar* body, GSList *attachments); + +gboolean +libmodfest_dbus_client_mailto (osso_context_t *osso_context, const gchar *mailto_uri); + +gboolean +libmodfest_dbus_client_open_message (osso_context_t *osso_context, const gchar *mail_uri); #endif /* __LIBMODEST_DBUS_CLIENT_H__ */ diff --git a/src/dbus_api/Makefile.am b/src/dbus_api/Makefile.am index 8b8b26b..288382c 100644 --- a/src/dbus_api/Makefile.am +++ b/src/dbus_api/Makefile.am @@ -44,7 +44,8 @@ noinst_LTLIBRARIES=\ libmodest-dbus-api.la libmodest_dbus_api_la_SOURCES= \ - modest-dbus-callbacks.h modest-dbus-callbacks.c + modest-dbus-callbacks.h modest-dbus-callbacks.c \ + modest-dbus-api.h LDADD = \ $(MODEST_GSTUFF_LIBS) \ diff --git a/src/dbus_api/modest-dbus-api.h b/src/dbus_api/modest-dbus-api.h new file mode 100644 index 0000000..2415db7 --- /dev/null +++ b/src/dbus_api/modest-dbus-api.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2007, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef __MODEST_DBUS_API__ +#define __MODEST_DBUS_API__ + + +/* Note that the com.nokia service name and /com/nokia object name + * are what is assumed by the, bizarrely named, osso_rpc_run_with_defaults() function, + * so they are probably a good choice. */ +#define MODEST_DBUS_NAME "modestemail" +#define MODEST_DBUS_EXAMPLE_SERVICE "com.nokia."MODEST_DBUS_NAME +#define MODEST_DBUS_EXAMPLE_OBJECT "/com/nokia/"MODEST_DBUS_NAME +#define MODEST_DBUS_EXAMPLE_IFACE "com.nokia."MODEST_DBUS_NAME + +#define MODEST_DBUS_EXAMPLE_MESSAGE "HelloWorld" + +#define MODEST_DBUS_METHOD_SEND_MAIL "SendMail" +enum ModestDbusSendMailArguments +{ + MODEST_DEBUS_SEND_MAIL_ARG_TO, + MODEST_DEBUS_SEND_MAIL_ARG_CC, + MODEST_DEBUS_SEND_MAIL_ARG_BCC, + MODEST_DEBUS_SEND_MAIL_ARG_SUBJECT, + MODEST_DEBUS_SEND_MAIL_ARG_BODY, + /* TODO: MODEST_DEBUS_SEND_MAIL_ARG_ATTACHMENTS, */ + MODEST_DEBUS_SEND_MAIL_ARGS_COUNT +}; + +#endif /* __MODEST_DBUS_API__ */ + diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index c15f62e..a71b70b 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -28,18 +28,89 @@ */ #include "modest-dbus-callbacks.h" +#include "modest-runtime.h" +#include "modest-account-mgr.h" +#include "modest-account-mgr-helpers.h" #include /* Callback for normal D-BUS messages */ +static gint on_send_mail(GArray * arguments, gpointer data, osso_rpc_t * retval) +{ + if (arguments->len != MODEST_DEBUS_SEND_MAIL_ARGS_COUNT) + return OSSO_ERROR; + + /* Get the arguments: */ + osso_rpc_t val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_TO); + gchar *to = val.value.s; + + val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_CC); + gchar *cc = val.value.s; + + val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BCC); + gchar *bcc = val.value.s; + + val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_SUBJECT); + gchar *subject = val.value.s; + + val = g_array_index(arguments, osso_rpc_t, MODEST_DEBUS_SEND_MAIL_ARG_BODY); + gchar *body = val.value.s; + + printf(" debug: to=%s\n", to); + + /* Get the TnyTransportAccount so we can instantiate a mail operation: */ + ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr(); + gchar *account_name = modest_account_mgr_get_default_account (account_mgr); + if (!account_name) { + g_printerr ("modest: no account found\n"); + return OSSO_ERROR; + } + + TnyTransportAccount *transport_account = + TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account + (modest_runtime_get_account_store(), + account_name, + TNY_ACCOUNT_TYPE_TRANSPORT)); + if (!transport_account) { + g_printerr ("modest: no transport account found for '%s'\n", account_name); + g_free (account_name); + return OSSO_ERROR; + } + + /* Create the mail operation: */ + ModestMailOperation *mail_operation = modest_mail_operation_new (); + modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); + + /* Use the mail operation: */ + gchar * from = modest_account_mgr_get_from_string (account_mgr, + account_name); + modest_mail_operation_send_new_mail (mail_operation, + transport_account, + from, /* from */ + to, cc, bcc, subject, + body, /* plain_body */ + NULL, /* html_body */ + NULL, /* attachments_list, GSList of TnyMimePart. */ + (TnyHeaderFlags)0); + + g_object_unref (G_OBJECT (transport_account)); + g_object_unref (G_OBJECT (mail_operation)); + g_free (from); + g_free (account_name); +} + +/* Callback for normal D-BUS messages */ gint modest_dbus_req_handler(const gchar * interface, const gchar * method, GArray * arguments, gpointer data, osso_rpc_t * retval) { printf("debug: modest_dbus_req_handler()\n"); + printf("debug: method received: %s\n", method); if (g_ascii_strcasecmp(method, MODEST_DBUS_EXAMPLE_MESSAGE) == 0) { - printf("debug: method received:" MODEST_DBUS_EXAMPLE_MESSAGE "\n"); - } + + } else if (g_ascii_strcasecmp(method, MODEST_DBUS_METHOD_SEND_MAIL) == 0) { + return on_send_mail (arguments, data, retval); + } return OSSO_OK; } diff --git a/src/dbus_api/modest-dbus-callbacks.h b/src/dbus_api/modest-dbus-callbacks.h index a4db566..d88423f 100644 --- a/src/dbus_api/modest-dbus-callbacks.h +++ b/src/dbus_api/modest-dbus-callbacks.h @@ -33,15 +33,7 @@ #include #include - -/* Note that the com.nokia service name and /com/nokia object name - * are what is assumed by the, bizarrely named, osso_rpc_run_with_defaults() function, - * so they are probably a good choice. */ -#define MODEST_DBUS_NAME "modestemail" -#define MODEST_DBUS_EXAMPLE_SERVICE "com.nokia."MODEST_DBUS_NAME -#define MODEST_DBUS_EXAMPLE_OBJECT "/com/nokia/"MODEST_DBUS_NAME -#define MODEST_DBUS_EXAMPLE_IFACE "com.nokia."MODEST_DBUS_NAME -#define MODEST_DBUS_EXAMPLE_MESSAGE "HelloWorld" +#include gint modest_dbus_req_handler(const gchar * interface, const gchar * method, GArray * arguments, gpointer data, diff --git a/tests/dbus_api/Makefile.am b/tests/dbus_api/Makefile.am index 969a0b9..ee4fe56 100644 --- a/tests/dbus_api/Makefile.am +++ b/tests/dbus_api/Makefile.am @@ -16,8 +16,12 @@ objects=\ $(MODEST_LIBTINYMAIL_MAEMO_LIBS) \ ${top_srcdir}/libmodest-dbus-client/libmodest-dbus-client-1.0.la -noinst_PROGRAMS = test_hello +noinst_PROGRAMS = test_hello test_send_mail test_hello_SOURCES = test_hello.c test_hello_LDADD = $(objects) +test_send_mail_SOURCES = test_send_mail.c +test_send_mail_LDADD = $(objects) + + diff --git a/tests/dbus_api/test_send_mail.c b/tests/dbus_api/test_send_mail.c new file mode 100644 index 0000000..2d4a286 --- /dev/null +++ b/tests/dbus_api/test_send_mail.c @@ -0,0 +1,34 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + /* Initialize maemo application */ + osso_context_t * osso_context = osso_initialize( + "test_hello", "0.0.1", TRUE, NULL); + + /* Check that initialization was ok */ + if (osso_context == NULL) + { + printf("osso_initialize() failed.\n"); + return OSSO_ERROR; + } + + /* Call the function in libmodest-dbus-client: */ + const gboolean ret = libmodfest_dbus_client_send_mail (osso_context, + "murrayc@murrayc.com", /* to */ + NULL, /* cc */ + NULL, /* bcc */ + "test subject", /* subject */ + "test body\nline two", /* body */ + NULL); + if (!ret) { + printf("libmodest_dbus_client_call_helloworld() failed.\n"); + return OSSO_ERROR; + } else { + printf("libmodest_dbus_client_call_helloworld() succeeded.\n"); + } + + /* Exit */ + return 0; +}