modest-tny-store-actions.h\
modest-ui.h \
modest-marshal.c \
- modest-marshal.h
+ modest-marshal.h \
+ modest-mail-operation.c \
+ modest-mail-operation.h \
+ modest-tny-platform-factory.c \
+ modest-tny-platform-factory.h
modest_LDADD = \
$(MODEST_LIBTINYMAIL_MAEMO_LIBS) \
$(MODEST_PLATFORM_DIR)/libmodest-ui.la \
widgets/libmodest-widgets.la
-
+
EXTRA_DIST=modest-marshal.list
#include "modest-account-view-window.h"
#include "modest-account-assistant.h"
+#include "modest-tny-platform-factory.h"
/* 'private'/'protected' functions */
static void modest_account_view_window_class_init (ModestAccountViewWindowClass *klass);
typedef struct _ModestAccountViewWindowPrivate ModestAccountViewWindowPrivate;
struct _ModestAccountViewWindowPrivate {
- ModestAccountMgr *account_mgr;
ModestWidgetFactory *widget_factory;
GtkWidget *edit_button, *remove_button;
};
priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(obj);
- priv->account_mgr = NULL;
priv->widget_factory = NULL;
}
priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(obj);
- if (priv->account_mgr) {
- g_object_unref (G_OBJECT(priv->account_mgr));
- priv->account_mgr = NULL;
- }
-
if (priv->widget_factory) {
g_object_unref (G_OBJECT(priv->widget_factory));
priv->widget_factory = NULL;
{
GtkWidget *assistant;
ModestAccountViewWindowPrivate *priv;
+ TnyPlatformFactory *fact;
+ ModestAccountMgr *account_mgr;
priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
+ fact = modest_tny_platform_factory_get_instance ();
+ account_mgr = modest_tny_platform_factory_get_modest_account_mgr_instance (fact);
- assistant = modest_account_assistant_new (priv->account_mgr,
+ assistant = modest_account_assistant_new (account_mgr,
priv->widget_factory);
gtk_window_set_transient_for (GTK_WINDOW(assistant),
GTK_WINDOW(self));
GtkWidget*
-modest_account_view_window_new (ModestAccountMgr *account_mgr, ModestWidgetFactory *factory)
+modest_account_view_window_new (ModestWidgetFactory *factory)
{
GObject *obj;
ModestAccountViewWindowPrivate *priv;
- g_return_val_if_fail (account_mgr, NULL);
g_return_val_if_fail (factory, NULL);
obj = g_object_new(MODEST_TYPE_ACCOUNT_VIEW_WINDOW, NULL);
priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(obj);
- g_object_ref (G_OBJECT(account_mgr));
- priv->account_mgr = account_mgr;
-
g_object_ref (G_OBJECT(factory));
priv->widget_factory = factory;
/* member functions */
GType modest_account_view_window_get_type (void) G_GNUC_CONST;
-GtkWidget* modest_account_view_window_new (ModestAccountMgr *account_mgr,
- ModestWidgetFactory *factory);
+GtkWidget* modest_account_view_window_new (ModestWidgetFactory *factory);
G_END_DECLS
#include <modest-widget-memory.h>
#include <modest-widget-factory.h>
#include "modest-icon-names.h"
-#include <modest-tny-transport-actions.h>
+#include "modest-mail-operation.h"
+#include "modest-tny-platform-factory.h"
+#include <tny-simple-list.h>
static void modest_edit_msg_window_class_init (ModestEditMsgWindowClass *klass);
static void modest_edit_msg_window_init (ModestEditMsgWindow *obj);
typedef struct _ModestEditMsgWindowPrivate ModestEditMsgWindowPrivate;
struct _ModestEditMsgWindowPrivate {
- ModestConf *conf;
ModestWidgetFactory *factory;
+ TnyPlatformFactory *fact;
GtkWidget *toolbar, *menubar;
GtkWidget *msg_body;
ModestEditMsgWindowPrivate *priv;
priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
+ priv->fact = modest_tny_platform_factory_get_instance ();
priv->factory = NULL;
priv->toolbar = NULL;
priv->menubar = NULL;
save_settings (ModestEditMsgWindow *self)
{
ModestEditMsgWindowPrivate *priv;
+ ModestConf *conf;
+
priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(self);
- modest_widget_memory_save_settings (priv->conf,
- GTK_WIDGET(self),
+ conf = modest_tny_platform_factory_get_modest_conf_instance (priv->fact);
+
+ modest_widget_memory_save_settings (conf, GTK_WIDGET(self),
"modest-edit-msg-window");
}
restore_settings (ModestEditMsgWindow *self)
{
ModestEditMsgWindowPrivate *priv;
+ ModestConf *conf;
+
priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(self);
- modest_widget_memory_restore_settings (priv->conf, GTK_WIDGET(self),
+ conf = modest_tny_platform_factory_get_modest_conf_instance (priv->fact);
+
+ modest_widget_memory_restore_settings (conf, GTK_WIDGET(self),
"modest-edit-msg-window");
}
const gchar *from, *to, *cc, *bcc, *subject;
gchar *body;
ModestEditMsgWindowPrivate *priv;
+ TnyTransportAccount *transport_account;
GtkTextBuffer *buf;
GtkTextIter b, e;
body = gtk_text_buffer_get_text (buf, &b, &e,
FALSE); /* free this one */
-// modest_tny_transport_actions_send_message (transport_account,
-// from, to, cc, bcc,
-// subject, *body, NULL);
+ /* FIXME: Code added just for testing. The transport_account
+ should be provided by the account manager, maybe using
+ _get_current_account () or _get_default_account
+ (TRANSPORT_ACCOUNT). These methods do not exist currently. */
+ {
+ TnyList *accounts;
+ TnyIterator *iter;
+ TnyAccountStore *account_store;
+
+ accounts = TNY_LIST(tny_simple_list_new ());
+ account_store = tny_platform_factory_new_account_store (priv->fact);
+ tny_account_store_get_accounts (account_store, accounts,
+ TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
+
+ iter = tny_list_create_iterator(accounts);
+ tny_iterator_first (iter);
+ if (tny_iterator_is_done (iter)) {
+ g_printerr("modest: no transport accounts defined\n");
+ goto cleanup;
+ }
+
+ transport_account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current(iter));
+
+ }
+ /*****/
+ modest_mail_operation_send_mail (transport_account,
+ from, to, cc, bcc,
+ subject, body, NULL);
+
+ cleanup:
+
g_free (body);
}
priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
- g_object_unref (G_OBJECT(priv->conf));
- priv->conf = NULL;
-
g_object_unref (G_OBJECT(priv->factory));
priv->factory = NULL;
GtkWidget*
-modest_edit_msg_window_new (ModestConf *conf, ModestWidgetFactory *factory,
+modest_edit_msg_window_new (ModestWidgetFactory *factory,
ModestEditType type, TnyMsgIface *msg)
{
GObject *obj;
ModestEditMsgWindowPrivate *priv;
- g_return_val_if_fail (conf, NULL);
g_return_val_if_fail (factory, NULL);
g_return_val_if_fail (type < MODEST_EDIT_TYPE_NUM, NULL);
g_return_val_if_fail (!(type==MODEST_EDIT_TYPE_NEW && msg), NULL);
obj = g_object_new(MODEST_TYPE_EDIT_MSG_WINDOW, NULL);
priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
- g_object_ref (G_OBJECT(conf));
- priv->conf = conf;
-
g_object_ref (factory);
priv->factory = factory;
/* member functions */
GType modest_edit_msg_window_get_type (void) G_GNUC_CONST;
-GtkWidget* modest_edit_msg_window_new (ModestConf *conf,
- ModestWidgetFactory *factory,
+GtkWidget* modest_edit_msg_window_new (ModestWidgetFactory *factory,
ModestEditType type,
TnyMsgIface *msg);
G_END_DECLS
#include "modest-main-window.h"
#include "modest-account-view-window.h"
+#include "modest-account-mgr.h"
+#include "modest-conf.h"
#include "modest-edit-msg-window.h"
#include "modest-icon-names.h"
-
+#include "modest-tny-platform-factory.h"
/* 'private'/'protected' functions */
static void modest_main_window_class_init (ModestMainWindowClass *klass);
GtkWidget *msg_paned;
GtkWidget *main_paned;
- ModestWidgetFactory *factory;
- ModestConf *conf;
- ModestAccountMgr *account_mgr;
-
+ ModestWidgetFactory *widget_factory;
+ TnyPlatformFactory *factory;
+
ModestHeaderView *header_view;
ModestFolderView *folder_view;
ModestMsgView *msg_preview;
ModestMainWindowPrivate *priv;
priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
-
- priv->factory = NULL;
- priv->conf = NULL;
- priv->account_mgr = NULL;
+
+ priv->factory = modest_tny_platform_factory_get_instance ();
}
static void
{
ModestMainWindowPrivate *priv;
priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
- if (priv->factory) {
- g_object_unref (G_OBJECT(priv->factory));
- priv->factory = NULL;
+ if (priv->widget_factory) {
+ g_object_unref (G_OBJECT(priv->widget_factory));
+ priv->widget_factory = NULL;
}
- if (priv->conf) {
- g_object_unref (G_OBJECT(priv->conf));
- priv->conf = NULL;
- }
-
- if (priv->account_mgr) {
- g_object_unref (G_OBJECT(priv->account_mgr));
- priv->account_mgr = NULL;
- }
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
g_return_if_fail (self);
priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
- account_win = modest_account_view_window_new (priv->account_mgr,
- priv->factory);
+ account_win = modest_account_view_window_new (priv->widget_factory);
gtk_window_set_transient_for (GTK_WINDOW(account_win),
GTK_WINDOW(self));
{
GtkWidget *msg_win;
ModestMainWindowPrivate *priv;
+ ModestConf *conf;
+ TnyAccountStore *account_store;
- priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+ conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory);
+ account_store = tny_platform_factory_new_account_store (priv->factory);
- msg_win = modest_edit_msg_window_new (priv->conf,
- priv->factory,
+ msg_win = modest_edit_msg_window_new (priv->widget_factory,
MODEST_EDIT_TYPE_NEW,
NULL);
gtk_widget_show (msg_win);
for (i = 0 ; i != sizeof(cols) / sizeof(ModestHeaderViewColumn); ++i)
columns = g_slist_append (columns, GINT_TO_POINTER(cols[i]));
- header_view = modest_widget_factory_get_header_view (priv->factory);
+ header_view = modest_widget_factory_get_header_view (priv->widget_factory);
modest_header_view_set_columns (header_view, columns);
g_slist_free (columns);
for (i = 0 ; i != sizeof(button_ids) / sizeof(ModestToolbarButton); ++i)
buttons = g_slist_append (buttons, GINT_TO_POINTER(button_ids[i]));
- toolbar = modest_widget_factory_get_main_toolbar (priv->factory, buttons);
+ toolbar = modest_widget_factory_get_main_toolbar (priv->widget_factory, buttons);
g_slist_free (buttons);
g_signal_connect (G_OBJECT(toolbar), "button_clicked",
static void
restore_sizes (ModestMainWindow *self)
{
- ModestMainWindowPrivate *priv;
- priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+ ModestConf *conf;
+ ModestMainWindowPrivate *priv;
- modest_widget_memory_restore_settings (priv->conf,GTK_WIDGET(self),
+ priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+ conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory);
+
+ modest_widget_memory_restore_settings (conf,GTK_WIDGET(self),
"modest-main-window");
- modest_widget_memory_restore_settings (priv->conf, GTK_WIDGET(priv->folder_paned),
+ modest_widget_memory_restore_settings (conf, GTK_WIDGET(priv->folder_paned),
"modest-folder-paned");
- modest_widget_memory_restore_settings (priv->conf, GTK_WIDGET(priv->msg_paned),
+ modest_widget_memory_restore_settings (conf, GTK_WIDGET(priv->msg_paned),
"modest-msg-paned");
- modest_widget_memory_restore_settings (priv->conf, GTK_WIDGET(priv->main_paned),
+ modest_widget_memory_restore_settings (conf, GTK_WIDGET(priv->main_paned),
"modest-main-paned");
}
save_sizes (ModestMainWindow *self)
{
ModestMainWindowPrivate *priv;
+ ModestConf *conf;
priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+ conf = modest_tny_platform_factory_get_modest_conf_instance (priv->factory);
- modest_widget_memory_save_settings (priv->conf,GTK_WIDGET(self),
+ modest_widget_memory_save_settings (conf,GTK_WIDGET(self),
"modest-main-window");
- modest_widget_memory_save_settings (priv->conf, GTK_WIDGET(priv->folder_paned),
+ modest_widget_memory_save_settings (conf, GTK_WIDGET(priv->folder_paned),
"modest-folder-paned");
- modest_widget_memory_save_settings (priv->conf, GTK_WIDGET(priv->msg_paned),
+ modest_widget_memory_save_settings (conf, GTK_WIDGET(priv->msg_paned),
"modest-msg-paned");
- modest_widget_memory_save_settings (priv->conf, GTK_WIDGET(priv->main_paned),
+ modest_widget_memory_save_settings (conf, GTK_WIDGET(priv->main_paned),
"modest-main-paned");
}
GtkWidget*
-modest_main_window_new (ModestConf *conf, ModestAccountMgr *account_mgr,
- ModestWidgetFactory *factory)
+modest_main_window_new (ModestWidgetFactory *widget_factory)
{
GObject *obj;
ModestMainWindowPrivate *priv;
GtkWidget *status_hbox;
GtkWidget *header_win, *folder_win, *favorites_win;
- g_return_val_if_fail (factory, NULL);
- g_return_val_if_fail (conf, NULL);
+ g_return_val_if_fail (widget_factory, NULL);
obj = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
- g_object_ref (factory);
- priv->factory = factory;
-
- g_object_ref (conf);
- priv->conf = conf;
-
- g_object_ref (account_mgr);
- priv->account_mgr = account_mgr;
+ g_object_ref (widget_factory);
+ priv->widget_factory = widget_factory;
/* widgets from factory */
- priv->folder_view = modest_widget_factory_get_folder_view (factory);
+ priv->folder_view = modest_widget_factory_get_folder_view (widget_factory);
priv->header_view = header_view_new (MODEST_MAIN_WINDOW(obj));
- priv->msg_preview = modest_widget_factory_get_msg_preview (factory);
+ priv->msg_preview = modest_widget_factory_get_msg_preview (widget_factory);
folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view),
FALSE);
/* status bar / progress */
status_hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX(status_hbox),
- modest_widget_factory_get_folder_info_label (factory),
+ modest_widget_factory_get_folder_info_label (widget_factory),
FALSE,FALSE, 6);
gtk_box_pack_start (GTK_BOX(status_hbox),
- modest_widget_factory_get_status_bar(factory),
+ modest_widget_factory_get_status_bar(widget_factory),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX(status_hbox),
- modest_widget_factory_get_progress_bar(factory),
+ modest_widget_factory_get_progress_bar(widget_factory),
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX(status_hbox),
- modest_widget_factory_get_online_toggle(factory),
+ modest_widget_factory_get_online_toggle(widget_factory),
FALSE, FALSE, 0);
/* putting it all together... */
#include <gtk/gtkwindow.h>
#include <glib/gi18n.h>
#include <modest-widget-factory.h>
-#include <modest-conf.h>
-#include <modest-account-mgr.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
GType modest_main_window_get_type (void) G_GNUC_CONST;
-GtkWidget* modest_main_window_new (ModestConf *conf, ModestAccountMgr *account_mgr,
- ModestWidgetFactory *factory);
+GtkWidget* modest_main_window_new (ModestWidgetFactory *factory);
G_END_DECLS
#include "../modest-account-mgr.h"
#include "../modest-widget-factory.h"
#include "modest-main-window.h"
+#include "modest-tny-platform-factory.h"
/* 'private'/'protected' functions */
typedef struct _ModestUIPrivate ModestUIPrivate;
struct _ModestUIPrivate {
- ModestConf *conf;
- ModestAccountMgr *account_mgr;
ModestWidgetFactory *widget_factory;
- ModestTnyAccountStore *account_store;
GtkWidget *main_window;
};
priv = MODEST_UI_GET_PRIVATE(obj);
- priv->account_store = NULL;
- priv->account_mgr = NULL;
- priv->conf = NULL;
priv->widget_factory = NULL;
priv->main_window = NULL;
ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
- if (priv->account_store) {
- g_object_unref (G_OBJECT(priv->account_store));
- priv->account_store = NULL;
- }
-
- if (priv->account_mgr) {
- g_object_unref (G_OBJECT(priv->account_mgr));
- priv->account_mgr = NULL;
- }
-
if (priv->widget_factory) {
g_object_unref (G_OBJECT(priv->widget_factory));
priv->widget_factory = NULL;
}
-
- if (priv->conf) {
- g_object_unref (G_OBJECT(priv->conf));
- priv->conf = NULL;
- }
}
ModestUI*
-modest_ui_new (ModestConf *modest_conf)
+modest_ui_new (void)
{
GObject *obj;
ModestUIPrivate *priv;
-
- g_return_val_if_fail (modest_conf, NULL);
+ TnyPlatformFactory *fact;
+ ModestAccountMgr *account_mgr;
+ TnyAccountStore *account_store;
obj = g_object_new(MODEST_TYPE_UI, NULL);
priv = MODEST_UI_GET_PRIVATE(obj);
- g_object_ref (G_OBJECT(modest_conf));
- priv->conf = modest_conf;
+ /* Get the platform-dependent instances */
+ fact = modest_tny_platform_factory_get_instance ();
- priv->account_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (priv->conf));
- if (!priv->account_mgr) {
+ account_mgr = modest_tny_platform_factory_get_modest_account_mgr_instance (fact);
+ if (!account_mgr) {
g_printerr ("modest: could not create ModestAccountMgr instance\n");
g_object_unref (obj);
return NULL;
}
- priv->account_store = modest_tny_account_store_new (priv->account_mgr);
- if (!priv->account_store) {
+ account_store = tny_platform_factory_new_account_store (fact);
+ if (!account_store) {
g_printerr ("modest: could not initialze ModestTnyAccountStore instance\n");
return NULL;
}
- priv->widget_factory = modest_widget_factory_new (
- priv->conf, priv->account_store, priv->account_mgr);
- if (!priv->account_store) {
+ priv->widget_factory = modest_widget_factory_new ();
+ if (!priv->widget_factory) {
g_printerr ("modest: could not initialize widget factory\n");
return NULL;
}
if (!priv->main_window) {
priv->main_window =
- modest_main_window_new (priv->conf, priv->account_mgr,
- priv->widget_factory);
+ modest_main_window_new (priv->widget_factory);
g_signal_connect (G_OBJECT(priv->main_window), "destroy",
G_CALLBACK(on_main_window_destroy), modest_ui);
--- /dev/null
+/* Copyright (c) 2006, 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.
+ */
+
+#include "modest-mail-operation.h"
+/* include other impl specific header files */
+#include <string.h>
+#include <tny-mime-part.h>
+
+/* 'private'/'protected' functions */
+static void modest_mail_operation_class_init (ModestMailOperationClass *klass);
+static void modest_mail_operation_init (ModestMailOperation *obj);
+static void modest_mail_operation_finalize (GObject *obj);
+/* list my signals */
+enum {
+ /* MY_SIGNAL_1, */
+ /* MY_SIGNAL_2, */
+ LAST_SIGNAL
+};
+
+typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate;
+struct _ModestMailOperationPrivate {
+};
+#define MODEST_MAIL_OPERATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+ MODEST_TYPE_MAIL_OPERATION, \
+ ModestMailOperationPrivate))
+/* globals */
+static GObjectClass *parent_class = NULL;
+
+/* uncomment the following if you have defined any signals */
+/* static guint signals[LAST_SIGNAL] = {0}; */
+
+GType
+modest_mail_operation_get_type (void)
+{
+ static GType my_type = 0;
+ if (!my_type) {
+ static const GTypeInfo my_info = {
+ sizeof(ModestMailOperationClass),
+ NULL, /* base init */
+ NULL, /* base finalize */
+ (GClassInitFunc) modest_mail_operation_class_init,
+ NULL, /* class finalize */
+ NULL, /* class data */
+ sizeof(ModestMailOperation),
+ 1, /* n_preallocs */
+ (GInstanceInitFunc) modest_mail_operation_init,
+ NULL
+ };
+ my_type = g_type_register_static (G_TYPE_OBJECT,
+ "ModestMailOperation",
+ &my_info, 0);
+ }
+ return my_type;
+}
+
+static void
+modest_mail_operation_class_init (ModestMailOperationClass *klass)
+{
+ GObjectClass *gobject_class;
+ gobject_class = (GObjectClass*) klass;
+
+ parent_class = g_type_class_peek_parent (klass);
+ gobject_class->finalize = modest_mail_operation_finalize;
+
+ g_type_class_add_private (gobject_class, sizeof(ModestMailOperationPrivate));
+
+ /* signal definitions go here, e.g.: */
+/* signals[MY_SIGNAL_1] = */
+/* g_signal_new ("my_signal_1",....); */
+/* signals[MY_SIGNAL_2] = */
+/* g_signal_new ("my_signal_2",....); */
+/* etc. */
+}
+
+static void
+modest_mail_operation_init (ModestMailOperation *obj)
+{
+/* initialize this object, eg.: */
+/* priv->frobnicate_mode = FALSE; */
+}
+
+static void
+modest_mail_operation_finalize (GObject *obj)
+{
+/* free/unref instance resources here */
+ G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+ModestMailOperation*
+modest_mail_operation_new (void)
+{
+ return MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL));
+}
+
+
+static gboolean
+is_ascii(const gchar *s)
+{
+ while (s[0]) {
+ if (s[0] & 128 || s[0] < 32)
+ return FALSE;
+ s++;
+ }
+ return TRUE;
+}
+
+static char *
+get_content_type(const gchar *s)
+{
+ GString *type;
+
+ type = g_string_new("text/plain");
+ if (!is_ascii(s)) {
+ if (g_utf8_validate(s, -1, NULL)) {
+ g_string_append(type, "; charset=\"utf-8\"");
+ } else {
+ /* it should be impossible to reach this, but better safe than sorry */
+ g_warning("invalid utf8 in message");
+ g_string_append(type, "; charset=\"latin1\"");
+ }
+ }
+ return g_string_free(type, FALSE);
+}
+
+ModestMailOperation*
+modest_mail_operation_send_mail (TnyTransportAccount *transport_account,
+ const gchar *from,
+ const gchar *to,
+ const gchar *cc,
+ const gchar *bcc,
+ const gchar *subject,
+ const gchar *body,
+ const GList *attachments_list)
+{
+ ModestMailOperation *mail_operation;
+ TnyMsg *new_msg;
+ TnyHeader *headers;
+ TnyStream *text_body_stream, *attachment_stream;
+ ModestTnyAttachment *attachment;
+ GList *pos;
+ gchar *content_type;
+ const gchar *attachment_content_type;
+ const gchar *attachment_filename;
+
+ /* TODO: better error handling management. Do it inside the
+ ModestMailOperation, for example set operation state to
+ failed or something like this and fill a GError with a
+ short description */
+ if (to == NULL || body == NULL)
+ return NULL;
+
+ mail_operation = modest_mail_operation_new ();
+ new_msg = TNY_MSG (tny_camel_msg_new ());
+ headers = TNY_HEADER (tny_camel_header_new ());
+ text_body_stream = TNY_STREAM (tny_camel_stream_new
+ (camel_stream_mem_new_with_buffer
+ (body, strlen(body))));
+
+ /* IMPORTANT: set the header before assign values to it */
+ tny_msg_set_header (new_msg, headers);
+ tny_header_set_from (TNY_HEADER (headers), from);
+ tny_header_set_to (TNY_HEADER (headers), to);
+ tny_header_set_cc (TNY_HEADER (headers), cc);
+ tny_header_set_bcc (TNY_HEADER (headers), bcc);
+ tny_header_set_subject (TNY_HEADER (headers), subject);
+
+ content_type = get_content_type(body);
+
+ if (attachments_list == NULL) {
+ tny_stream_reset (text_body_stream);
+ tny_mime_part_construct_from_stream (TNY_MIME_PART(new_msg),
+ text_body_stream, content_type);
+ tny_stream_reset (text_body_stream);
+ } else {
+ TnyMimePart *text_body_part;
+
+ text_body_part =
+ TNY_MIME_PART (tny_camel_mime_part_new (camel_mime_part_new()));
+ tny_stream_reset (text_body_stream);
+ tny_mime_part_construct_from_stream (text_body_part,
+ text_body_stream,
+ content_type);
+ tny_stream_reset (text_body_stream);
+ tny_msg_add_part (new_msg, text_body_part);
+ g_object_unref (G_OBJECT(text_body_part));
+ }
+
+ for (pos = (GList *)attachments_list;
+ pos;
+ pos = pos->next) {
+ TnyMimePart *attachment_part;
+
+ attachment = pos->data;
+ attachment_filename = modest_tny_attachment_get_name (attachment);
+ attachment_stream = modest_tny_attachment_get_stream (attachment);
+ attachment_part = TNY_MIME_PART (tny_camel_mime_part_new (camel_mime_part_new()));
+
+ attachment_content_type = modest_tny_attachment_get_mime_type (attachment);
+
+ tny_mime_part_construct_from_stream (attachment_part,
+ attachment_stream,
+ attachment_content_type);
+ tny_stream_reset (attachment_stream);
+
+ tny_mime_part_set_filename (attachment_part, attachment_filename);
+
+ tny_msg_add_part (new_msg, attachment_part);
+ g_object_unref(G_OBJECT(attachment_part));
+ }
+
+ tny_transport_account_send (transport_account, new_msg);
+
+ g_object_unref (G_OBJECT(text_body_stream));
+ g_object_unref (G_OBJECT(headers));
+ g_object_unref (G_OBJECT(new_msg));
+ g_free(content_type);
+
+ return mail_operation;
+}
--- /dev/null
+/* Copyright (c) 2006, 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_MAIL_OPERATION_H__
+#define __MODEST_MAIL_OPERATION_H__
+
+#include <glib-object.h>
+#include <tny-transport-account.h>
+#include <modest-tny-attachment.h>
+/* other include files */
+
+G_BEGIN_DECLS
+
+/* convenience macros */
+#define MODEST_TYPE_MAIL_OPERATION (modest_mail_operation_get_type())
+#define MODEST_MAIL_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_MAIL_OPERATION,ModestMailOperation))
+#define MODEST_MAIL_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_MAIL_OPERATION,GObject))
+#define MODEST_IS_MAIL_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_MAIL_OPERATION))
+#define MODEST_IS_MAIL_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_MAIL_OPERATION))
+#define MODEST_MAIL_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_MAIL_OPERATION,ModestMailOperationClass))
+
+typedef struct _ModestMailOperation ModestMailOperation;
+typedef struct _ModestMailOperationClass ModestMailOperationClass;
+
+struct _ModestMailOperation {
+ GObject parent;
+ /* insert public members, if any */
+};
+
+struct _ModestMailOperationClass {
+ GObjectClass parent_class;
+ /* insert signal callback declarations, eg. */
+ /* void (* my_event) (ModestMailOperation* obj); */
+};
+
+/* member functions */
+GType modest_mail_operation_get_type (void) G_GNUC_CONST;
+
+/* typical parameter-less _new function */
+ModestMailOperation* modest_mail_operation_new (void);
+
+/* fill in other public functions, eg.: */
+ModestMailOperation* modest_mail_operation_send_mail (TnyTransportAccount *transport_account,
+ const gchar *from,
+ const gchar *to,
+ const gchar *cc,
+ const gchar *bcc,
+ const gchar *subject,
+ const gchar *body,
+ const GList *attachments_list);
+
+G_END_DECLS
+
+#endif /* __MODEST_MAIL_OPERATION_H__ */
+
#include "modest-icon-factory.h"
#include "modest-tny-transport-actions.h"
#include "modest-tny-account-store.h"
+#include "modest-tny-platform-factory.h"
#ifdef MODEST_ENABLE_HILDON /* Hildon includes */
static gboolean hildon_init (); /* NOP if HILDON is not defined */
-static int start_ui (ModestConf *conf, const gchar* mailto, const gchar *cc,
+static int start_ui (const gchar* mailto, const gchar *cc,
const gchar *bcc, const gchar* subject, const gchar *body);
-static int send_mail (ModestConf *conf, const gchar* mailto, const gchar *cc, const gchar *bcc,
+static int send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
const gchar* subject, const gchar *body);
int
main (int argc, char *argv[])
{
GOptionContext *context = NULL;
+ TnyPlatformFactory *fact = NULL;
ModestConf *modest_conf = NULL;
GError *err = NULL;
}
g_option_context_free (context);
- modest_conf = MODEST_CONF(modest_conf_new());
+ fact = modest_tny_platform_factory_get_instance ();
+ modest_conf = modest_tny_platform_factory_get_modest_conf_instance (fact);
if (!modest_conf) {
g_printerr ("modest: failed to initialize config system, exiting\n");
retval = MODEST_ERR_CONF;
if (!batch) {
gtk_init (&argc, &argv);
- retval = start_ui (modest_conf, mailto, cc, bcc, subject, body);
+ retval = start_ui (mailto, cc, bcc, subject, body);
} else
- retval = send_mail (modest_conf, mailto, cc, bcc, subject, body);
+ retval = send_mail (mailto, cc, bcc, subject, body);
cleanup:
- if (modest_conf)
- g_object_unref (G_OBJECT(modest_conf));
return retval;
}
static int
-start_ui (ModestConf *conf, const gchar* mailto, const gchar *cc, const gchar *bcc,
+start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
const gchar* subject, const gchar *body)
{
GtkWidget *win;
#endif
- modest_ui = MODEST_UI(modest_ui_new (conf));
+ modest_ui = MODEST_UI(modest_ui_new ());
if (!modest_ui) {
g_printerr ("modest: failed to initialize ui, exiting\n");
retval = MODEST_ERR_UI;
static int
-send_mail (ModestConf *conf, const gchar* mailto, const gchar *cc, const gchar *bcc,
+send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
const gchar* subject, const gchar *body)
{
ModestAccountMgr *acc_mgr = NULL;
- ModestTnyAccountStore *acc_store = NULL;
+ TnyPlatformFactory *fact = NULL;
+ TnyAccountStore *acc_store = NULL;
TnyList *accounts = NULL;
TnyIterator *iter = NULL;
TnyTransportAccount *account = NULL;
int retval;
-
- acc_mgr = modest_account_mgr_new (conf);
- acc_store = modest_tny_account_store_new (acc_mgr);
+
+ fact = modest_tny_platform_factory_get_instance ();
+ acc_mgr = modest_tny_platform_factory_get_modest_account_mgr_instance (fact);
+ acc_store = tny_platform_factory_new_account_store (fact);
accounts = TNY_LIST(tny_simple_list_new ());
tny_account_store_get_accounts (TNY_ACCOUNT_STORE(acc_store), accounts,
account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current(iter));
- if (!modest_tny_transport_actions_send_message (account,
- "<>", mailto, cc, bcc, subject, body,
- NULL)) {
+ if (!modest_mail_operation_send_mail (account,
+ "djcb@djcbsoftware.nl", mailto, cc, bcc, subject, body,
+ NULL)) {
retval = MODEST_ERR_SEND;
goto cleanup;
} else
retval = MODEST_ERR_NONE; /* hurray! */
-
+
cleanup:
if (iter)
g_object_unref (G_OBJECT(iter));
if (accounts)
g_object_unref (G_OBJECT(accounts));
- if (acc_store)
- g_object_unref (G_OBJECT(acc_store));
- if (acc_mgr)
- g_object_unref (G_OBJECT(acc_mgr));
return retval;
}
#include <tny-device.h>
#include <tny-gnome-device.h>
#include <tny-account-store.h>
-#include <tny-gnome-platform-factory.h>
#include <tny-camel-transport-account.h>
#include <tny-camel-store-account.h>
#include <modest-marshal.h>
#include "modest-account-mgr.h"
#include "modest-tny-account-store.h"
+#include "modest-tny-platform-factory.h"
/* 'private'/'protected' functions */
static void modest_tny_account_store_class_init (ModestTnyAccountStoreClass *klass);
priv->store_lock = g_mutex_new ();
/* FIXME: don't use GNOME */
- pfact = TNY_PLATFORM_FACTORY (tny_gnome_platform_factory_get_instance());
+ pfact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance());
if (!pfact) {
g_printerr ("modest: cannot create platform factory\n");
g_object_unref (obj);
priv->stream = thing;
}
-TnyStreamIface *
+TnyStream *
modest_tny_attachment_get_stream (ModestTnyAttachment *self)
{
ModestTnyAttachmentPrivate *priv;
void modest_tny_attachment_guess_mime_type (ModestTnyAttachment *self);
-TnyStreamIface * modest_tny_attachment_get_stream (ModestTnyAttachment *self);
+TnyStream * modest_tny_attachment_get_stream (ModestTnyAttachment *self);
void modest_tny_attachment_free_list(GList *list);
--- /dev/null
+/* Copyright (c) 2006, 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.
+ */
+
+/* modest-tny-platform-factory.c */
+
+#include "modest-tny-platform-factory.h"
+#include "modest-tny-account-store.h"
+
+/* 'private'/'protected' functions */
+static void modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass);
+static void modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj);
+static void modest_tny_platform_factory_finalize (GObject *obj);
+static GObject *modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
+ GObjectConstructParam *construct_params);
+static void tny_platform_factory_init (gpointer g, gpointer iface_data);
+static TnyAccountStore *modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self);
+static TnyDevice *modest_tny_platform_factory_new_device (TnyPlatformFactory *self);
+static TnyMsgView *modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self);
+/* list my signals */
+enum {
+ /* MY_SIGNAL_1, */
+ /* MY_SIGNAL_2, */
+ LAST_SIGNAL
+};
+
+typedef struct _ModestTnyPlatformFactoryPrivate ModestTnyPlatformFactoryPrivate;
+struct _ModestTnyPlatformFactoryPrivate {
+ ModestTnyAccountStore *account_store;
+ ModestConf *conf;
+ ModestAccountMgr *account_mgr;
+};
+#define MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+ MODEST_TYPE_TNY_PLATFORM_FACTORY, \
+ ModestTnyPlatformFactoryPrivate))
+/* globals */
+static GObjectClass *parent_class = NULL;
+static ModestTnyPlatformFactory *singleton = NULL;
+
+/* uncomment the following if you have defined any signals */
+/* static guint signals[LAST_SIGNAL] = {0}; */
+
+GType
+modest_tny_platform_factory_get_type (void)
+{
+ static GType my_type = 0;
+ if (!my_type) {
+ static const GTypeInfo my_info = {
+ sizeof(ModestTnyPlatformFactoryClass),
+ NULL, /* base init */
+ NULL, /* base finalize */
+ (GClassInitFunc) modest_tny_platform_factory_class_init,
+ NULL, /* class finalize */
+ NULL, /* class data */
+ sizeof(ModestTnyPlatformFactory),
+ 1, /* n_preallocs */
+ (GInstanceInitFunc) modest_tny_platform_factory_init,
+ NULL
+ };
+
+ static const GInterfaceInfo tny_platform_factory_info = {
+ (GInterfaceInitFunc) tny_platform_factory_init, /* interface_init */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
+ };
+
+ my_type = g_type_register_static (G_TYPE_OBJECT,
+ "ModestTnyPlatformFactory",
+ &my_info, 0);
+
+ g_type_add_interface_static (my_type, TNY_TYPE_PLATFORM_FACTORY,
+ &tny_platform_factory_info);
+ }
+ return my_type;
+}
+
+static void
+modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ gobject_class = (GObjectClass*) klass;
+ parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->finalize = modest_tny_platform_factory_finalize;
+ gobject_class->constructor = modest_tny_platform_factory_constructor;
+
+ g_type_class_add_private (gobject_class, sizeof(ModestTnyPlatformFactoryPrivate));
+}
+
+static void
+modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj)
+{
+ /* Empty implementation */
+}
+
+static GObject*
+modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *object;
+
+ if (!singleton) {
+ object = G_OBJECT_CLASS (parent_class)->constructor (type,
+ n_construct_params, construct_params);
+
+ singleton = MODEST_TNY_PLATFORM_FACTORY (object);
+ } else {
+ object = G_OBJECT (singleton);
+ g_object_freeze_notify (G_OBJECT (singleton));
+ }
+
+ return object;
+}
+
+static void
+modest_tny_platform_factory_finalize (GObject *obj)
+{
+ ModestTnyPlatformFactoryPrivate *priv;
+
+ priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(obj);
+
+ if (priv->account_mgr) {
+ g_object_unref (priv->account_mgr);
+ priv->account_mgr = NULL;
+ }
+
+ if (priv->conf) {
+ g_object_unref (priv->conf);
+ priv->conf = NULL;
+ }
+
+ if (priv->account_store) {
+ g_object_unref (priv->account_store);
+ priv->account_store = NULL;
+ }
+
+ G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+static void
+tny_platform_factory_init (gpointer g, gpointer iface_data)
+{
+ TnyPlatformFactoryIface *klass = (TnyPlatformFactoryIface *)g;
+
+ klass->new_account_store_func = modest_tny_platform_factory_new_account_store;
+ klass->new_device_func = modest_tny_platform_factory_new_device;
+ klass->new_msg_view_func = modest_tny_platform_factory_new_msg_view;
+
+ return;
+}
+
+TnyPlatformFactory *
+modest_tny_platform_factory_get_instance (void)
+{
+ ModestTnyPlatformFactory *self = g_object_new (MODEST_TYPE_TNY_PLATFORM_FACTORY, NULL);
+
+ return TNY_PLATFORM_FACTORY (self);
+}
+
+static TnyAccountStore *
+modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self)
+{
+ ModestTnyPlatformFactoryPrivate *priv;
+
+ priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(self);
+
+ if (!priv->account_store) {
+ if (!priv->account_mgr)
+ modest_tny_platform_factory_get_modest_account_mgr_instance (self);
+
+ priv->account_store = modest_tny_account_store_new (priv->account_mgr);
+ }
+
+ return TNY_ACCOUNT_STORE (priv->account_store);
+}
+
+static TnyDevice *
+modest_tny_platform_factory_new_device (TnyPlatformFactory *self)
+{
+ /* FIXME: do not use GNOME */
+ return TNY_DEVICE (tny_gnome_device_new ());
+}
+
+static TnyMsgView*
+modest_tny_platform_factory_new_msg_view (TnyPlatformFactory *self)
+{
+ /* TODO */
+ return NULL;
+}
+
+ModestAccountMgr *
+modest_tny_platform_factory_get_modest_account_mgr_instance (TnyPlatformFactory *fact)
+{
+ ModestTnyPlatformFactoryPrivate *priv;
+
+ priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
+
+ if (!priv->account_mgr) {
+ if (!priv->conf)
+ modest_tny_platform_factory_get_modest_conf_instance (fact);
+
+ priv->account_mgr = modest_account_mgr_new (priv->conf);
+ }
+
+ return priv->account_mgr;
+}
+
+ModestConf *
+modest_tny_platform_factory_get_modest_conf_instance (TnyPlatformFactory *fact)
+{
+ ModestTnyPlatformFactoryPrivate *priv;
+
+ priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
+
+ if (!priv->conf)
+ priv->conf = modest_conf_new ();
+
+ return priv->conf;
+}
--- /dev/null
+/* Copyright (c) 2006, 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.
+ */
+
+/* modest-tny-platform-factory.h */
+
+#ifndef __MODEST_TNY_PLATFORM_FACTORY_H__
+#define __MODEST_TNY_PLATFORM_FACTORY_H__
+
+#include <glib-object.h>
+/* other include files */
+#include <tny-platform-factory.h>
+#include "modest-account-mgr.h"
+#include "modest-conf.h"
+
+G_BEGIN_DECLS
+
+/* convenience macros */
+#define MODEST_TYPE_TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_type())
+#define MODEST_TNY_PLATFORM_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_TNY_PLATFORM_FACTORY,ModestTnyPlatformFactory))
+#define MODEST_TNY_PLATFORM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_TNY_PLATFORM_FACTORY,GObject))
+#define MODEST_IS_TNY_PLATFORM_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_TNY_PLATFORM_FACTORY))
+#define MODEST_IS_TNY_PLATFORM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_TNY_PLATFORM_FACTORY))
+#define MODEST_TNY_PLATFORM_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_TNY_PLATFORM_FACTORY,ModestTnyPlatformFactoryClass))
+
+typedef struct _ModestTnyPlatformFactory ModestTnyPlatformFactory;
+typedef struct _ModestTnyPlatformFactoryClass ModestTnyPlatformFactoryClass;
+
+struct _ModestTnyPlatformFactory {
+ GObject parent;
+};
+
+struct _ModestTnyPlatformFactoryClass {
+ GObjectClass parent_class;
+};
+
+/* member functions */
+GType modest_tny_platform_factory_get_type (void) G_GNUC_CONST;
+
+TnyPlatformFactory* modest_tny_platform_factory_get_instance (void);
+
+ModestAccountMgr* modest_tny_platform_factory_get_modest_account_mgr_instance (TnyPlatformFactory *fact);
+ModestConf* modest_tny_platform_factory_get_modest_conf_instance (TnyPlatformFactory *fact);
+
+
+G_END_DECLS
+
+#endif /* __MODEST_TNY_PLATFORM_FACTORY_H__ */
*
* Returns: a new ModestUI, or NULL in case of error
*/
-ModestUI* modest_ui_new (ModestConf *modest_conf);
+ModestUI* modest_ui_new (void);
/**
#include <modest-protocol-mgr.h>
#include <tny-account-store.h>
#include <tny-device.h>
+#include "modest-tny-platform-factory.h"
+#include "modest-account-mgr.h"
/* 'private'/'protected' functions */
static void modest_widget_factory_class_init (ModestWidgetFactoryClass *klass);
typedef struct _ModestWidgetFactoryPrivate ModestWidgetFactoryPrivate;
struct _ModestWidgetFactoryPrivate {
- ModestTnyAccountStore *account_store;
- ModestAccountMgr *account_mgr;
- ModestConf *conf;
+ TnyPlatformFactory *fact;
+ TnyAccountStore *account_store;
ModestProtocolMgr *proto_mgr;
ModestHeaderView *header_view;
ModestWidgetFactoryPrivate *priv;
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
- priv->conf = NULL;
- priv->account_mgr = NULL;
- priv->account_store = NULL;
+ priv->fact = modest_tny_platform_factory_get_instance ();
+ priv->account_store = tny_platform_factory_new_account_store (priv->fact);
priv->proto_mgr = modest_protocol_mgr_new ();
priv->progress_bar = gtk_progress_bar_new ();
ModestWidgetFactoryPrivate *priv;
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
- if (priv->account_mgr) {
- g_object_unref (G_OBJECT(priv->account_mgr));
- priv->account_mgr = NULL;
- }
-
- if (priv->conf) {
- g_object_unref (G_OBJECT(priv->conf));
- priv->conf = NULL;
- }
-
if (priv->proto_mgr) {
g_object_unref (G_OBJECT(priv->proto_mgr));
priv->proto_mgr = NULL;
}
-
- if (priv->account_store) {
- g_object_unref (G_OBJECT(priv->account_store));
- priv->account_store = NULL;
- }
}
G_CALLBACK(on_msg_attachment_clicked), self);
/* account store */
- g_signal_connect (G_OBJECT(priv->account_store), "password_requested",
+ g_signal_connect (G_OBJECT (priv->account_store), "password_requested",
G_CALLBACK(on_password_requested), self);
/* FIXME: const casting is evil ==> tinymail */
- device = (TnyDevice*)tny_account_store_get_device
- (TNY_ACCOUNT_STORE(priv->account_store));
+ device = (TnyDevice*) tny_account_store_get_device (priv->account_store);
if (device) {
g_signal_connect (G_OBJECT(device), "connection_changed",
G_CALLBACK(on_connection_changed), self);
init_widgets (ModestWidgetFactory *self)
{
ModestWidgetFactoryPrivate *priv;
+
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self);
/* folder view */
ModestWidgetFactory*
-modest_widget_factory_new (ModestConf *conf,
- ModestTnyAccountStore *account_store,
- ModestAccountMgr *account_mgr)
+modest_widget_factory_new (void)
{
GObject *obj;
ModestWidgetFactoryPrivate *priv;
+ ModestAccountMgr *account_mgr;
- g_return_val_if_fail (account_store, NULL);
- g_return_val_if_fail (account_mgr, NULL);
- g_return_val_if_fail (conf, NULL);
-
- obj = g_object_new(MODEST_TYPE_WIDGET_FACTORY, NULL);
+ obj = g_object_new (MODEST_TYPE_WIDGET_FACTORY, NULL);
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
- g_object_ref (G_OBJECT(conf));
- priv->conf = conf;
-
- g_object_ref (G_OBJECT(account_mgr));
- priv->account_mgr = account_mgr;
-
- g_object_ref (G_OBJECT(account_store));
- priv->account_store = account_store;
-
if (!init_widgets (MODEST_WIDGET_FACTORY(obj))) {
g_printerr ("modest: widget factory failed to init widgets\n");
g_object_unref (obj);
modest_widget_factory_get_account_view (ModestWidgetFactory *self)
{
ModestWidgetFactoryPrivate *priv;
+ ModestAccountMgr *account_mgr;
g_return_val_if_fail (self, NULL);
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self);
+
+ account_mgr =
+ modest_tny_platform_factory_get_modest_account_mgr_instance (priv->fact);
- return modest_account_view_new (priv->account_mgr);
+ return modest_account_view_new (account_mgr);
}
get_transports (ModestWidgetFactory *self)
{
ModestWidgetFactoryPrivate *priv;
+ ModestAccountMgr *account_mgr;
GSList *transports = NULL;
GSList *cursor, *accounts;
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self);
- cursor = accounts = modest_account_mgr_account_names (priv->account_mgr, NULL);
+ account_mgr =
+ modest_tny_platform_factory_get_modest_account_mgr_instance (priv->fact);
+ cursor = accounts = modest_account_mgr_account_names (account_mgr, NULL);
while (cursor) {
ModestAccountData *data;
gchar *account_name = (gchar*)cursor->data;
- data = modest_account_mgr_get_account_data (priv->account_mgr, account_name);
+ data = modest_account_mgr_get_account_data (account_mgr, account_name);
if (data && data->transport_account) {
gchar *display_name = g_strdup_printf ("%s (%s)", data->email, account_name);
ModestPair *pair = modest_pair_new ((gpointer)account_name,
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self);
online = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(priv->online_toggle));
- device = tny_account_store_get_device
- (TNY_ACCOUNT_STORE(priv->account_store));
+ device = tny_account_store_get_device (priv->account_store);
/* FIXME: const casting should not be necessary ==> tinymail */
if (online) /* we're moving to online state */
ModestWidgetFactoryPrivate *priv;
priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self);
- device = tny_account_store_get_device
- (TNY_ACCOUNT_STORE(priv->account_store));
+ device = tny_account_store_get_device (priv->account_store);
online = tny_device_is_online (device);
if (online) {
*
* Returns: a new ModestWidgetFactory, or NULL in case of error
*/
-ModestWidgetFactory* modest_widget_factory_new (ModestConf *conf,
- ModestTnyAccountStore *acc_store,
- ModestAccountMgr *account_mgr);
+ModestWidgetFactory* modest_widget_factory_new (void);
/**
* modest_widget_factory_get_folder_view
* @self: a ModestWidgetFactory instance