2007-04-24 Murray Cumming <murrayc@murrayc.com>
+ * 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 <murrayc@murrayc.com>
+
* Makefile.am:
* configure.ac:
* libmodest-dbus-client/Makefile.am:
$(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)\" \
+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
--- /dev/null
+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
*/
#include "libmodest-dbus-client.h"
+#include <dbus_api/modest-dbus-api.h> /* 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)
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");
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;
+}
+
+
#define __LIBMODEST_DBUS_CLIENT_H__
#include <libosso.h>
+#include <glib.h>
#include <stdio.h>
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__ */
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) \
--- /dev/null
+/* 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__ */
+
*/
#include "modest-dbus-callbacks.h"
+#include "modest-runtime.h"
+#include "modest-account-mgr.h"
+#include "modest-account-mgr-helpers.h"
#include <stdio.h>
/* 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;
}
#include <glib.h>
#include <libosso.h>
-
-/* 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 <dbus_api/modest-dbus-api.h>
gint modest_dbus_req_handler(const gchar * interface, const gchar * method,
GArray * arguments, gpointer data,
$(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)
+
+
--- /dev/null
+#include <libmodest-dbus-client/libmodest-dbus-client.h>
+#include <stdio.h>
+
+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;
+}