From 1d54dd2435d706f0f82d2a81cd00c1410832a241 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Mon, 6 Nov 2006 11:50:00 +0000 Subject: [PATCH] * src/modest-tny-attachment.h: * src/modest-tny-attachment.c: (modest_tny_attachment_get_stream): replaced TnyStreamIface with TnyStream * src/gtk/modest-account-view-window.h: * src/gtk/modest-account-view-window.c: removed the ModestAccountMgr from the private structure. Added some platform factory needed calls. (modest_account_view_window_new): removed account manager from the method signature * src/gtk/modest-ui.h: * src/gtk/modest-ui.c: removed ModestAccountMgr and ModestTnyAccountStore from the private structure. (modest_ui_new): removed ModestConf from the method signature. Added some calls to the platform factory * src/gtk/modest-edit-msg-window.h: * src/gtk/modest-edit-msg-window.c: removed ModestConf from the private structure. Added ModestPlatformFactory to it. (send_mail): added some code just for testing purposes for sending mail (modest_edit_msg_window_new): modified method signature * src/gtk/modest-main-window.h: * src/gtk/modest-main-window.c: added the platform factory to the private structure. Change in the name of the widget factory. Removed ModestConf and ModestAccountMgr from it. (modest_main_window_new): removed ModestConf and ModestAccountMgr from the method signature. Added some calls to the platform factory * src/modest-tny-platform-factory.h: * src/modest-tny-platform-factory.c: New files in the repository * src/modest-mail-operation.h: * src/modest-mail-operation.c: New files in the repository * src/modest-main.c: Added some calls to the platform factory (start_ui): modified method signature, removed ModestConf (send_mail): modified method signature, removed ModestConf * src/modest-widget-factory.h: * src/modest-widget-factory.c: replaced ModestTnyAccountStore by TnyAccountStore, Removed ModestConf and ModestAccountMgr from the private structure. Added the platform factory. (modest_widget_factory_new (): modified method signature, removed all attributes. * src/modest-tny-account-store.c: replaced a call to the GNOME factory by a call to Modest factory * src/Makefile.am: added the new files pmo-trunk-r481 --- src/Makefile.am | 8 +- src/gtk/modest-account-view-window.c | 20 +-- src/gtk/modest-account-view-window.h | 3 +- src/gtk/modest-edit-msg-window.c | 64 ++++++--- src/gtk/modest-edit-msg-window.h | 3 +- src/gtk/modest-main-window.c | 101 +++++++------- src/gtk/modest-main-window.h | 5 +- src/gtk/modest-ui.c | 49 ++----- src/modest-mail-operation.c | 245 ++++++++++++++++++++++++++++++++++ src/modest-mail-operation.h | 81 +++++++++++ src/modest-main.c | 43 +++--- src/modest-tny-account-store.c | 4 +- src/modest-tny-attachment.c | 2 +- src/modest-tny-attachment.h | 2 +- src/modest-tny-platform-factory.c | 245 ++++++++++++++++++++++++++++++++++ src/modest-tny-platform-factory.h | 73 ++++++++++ src/modest-ui.h | 2 +- src/modest-widget-factory.c | 72 ++++------ src/modest-widget-factory.h | 4 +- 19 files changed, 818 insertions(+), 208 deletions(-) create mode 100644 src/modest-mail-operation.c create mode 100644 src/modest-mail-operation.h create mode 100644 src/modest-tny-platform-factory.c create mode 100644 src/modest-tny-platform-factory.h diff --git a/src/Makefile.am b/src/Makefile.am index 994d8d8..7a71d62 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -58,7 +58,11 @@ modest_SOURCES=\ 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 = \ @@ -67,6 +71,6 @@ modest_LDADD = \ $(MODEST_LIBTINYMAIL_MAEMO_LIBS) \ $(MODEST_PLATFORM_DIR)/libmodest-ui.la \ widgets/libmodest-widgets.la - + EXTRA_DIST=modest-marshal.list diff --git a/src/gtk/modest-account-view-window.c b/src/gtk/modest-account-view-window.c index 50ab756..67d6d9a 100644 --- a/src/gtk/modest-account-view-window.c +++ b/src/gtk/modest-account-view-window.c @@ -29,6 +29,7 @@ #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); @@ -45,7 +46,6 @@ enum { typedef struct _ModestAccountViewWindowPrivate ModestAccountViewWindowPrivate; struct _ModestAccountViewWindowPrivate { - ModestAccountMgr *account_mgr; ModestWidgetFactory *widget_factory; GtkWidget *edit_button, *remove_button; }; @@ -108,7 +108,6 @@ modest_account_view_window_init (ModestAccountViewWindow *obj) priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(obj); - priv->account_mgr = NULL; priv->widget_factory = NULL; } @@ -119,11 +118,6 @@ modest_account_view_window_finalize (GObject *obj) 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; @@ -169,10 +163,14 @@ on_add_button_clicked (GtkWidget *button, ModestAccountViewWindow *self) { 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)); @@ -277,20 +275,16 @@ window_vbox_new (ModestAccountViewWindow *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; diff --git a/src/gtk/modest-account-view-window.h b/src/gtk/modest-account-view-window.h index 8db09c4..57757b8 100644 --- a/src/gtk/modest-account-view-window.h +++ b/src/gtk/modest-account-view-window.h @@ -35,8 +35,7 @@ struct _ModestAccountViewWindowClass { /* 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 diff --git a/src/gtk/modest-edit-msg-window.c b/src/gtk/modest-edit-msg-window.c index ff5e5af..221bf31 100644 --- a/src/gtk/modest-edit-msg-window.c +++ b/src/gtk/modest-edit-msg-window.c @@ -32,7 +32,9 @@ #include #include #include "modest-icon-names.h" -#include +#include "modest-mail-operation.h" +#include "modest-tny-platform-factory.h" +#include static void modest_edit_msg_window_class_init (ModestEditMsgWindowClass *klass); static void modest_edit_msg_window_init (ModestEditMsgWindow *obj); @@ -48,8 +50,8 @@ enum { typedef struct _ModestEditMsgWindowPrivate ModestEditMsgWindowPrivate; struct _ModestEditMsgWindowPrivate { - ModestConf *conf; ModestWidgetFactory *factory; + TnyPlatformFactory *fact; GtkWidget *toolbar, *menubar; GtkWidget *msg_body; @@ -114,6 +116,7 @@ modest_edit_msg_window_init (ModestEditMsgWindow *obj) 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; @@ -125,9 +128,12 @@ static void 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"); } @@ -136,8 +142,12 @@ static void 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"); } @@ -235,6 +245,7 @@ send_mail (ModestEditMsgWindow *self) const gchar *from, *to, *cc, *bcc, *subject; gchar *body; ModestEditMsgWindowPrivate *priv; + TnyTransportAccount *transport_account; GtkTextBuffer *buf; GtkTextIter b, e; @@ -255,9 +266,37 @@ send_mail (ModestEditMsgWindow *self) 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); } @@ -378,9 +417,6 @@ modest_edit_msg_window_finalize (GObject *obj) 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; @@ -399,13 +435,12 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestEditMsgWindow *self) 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); @@ -414,9 +449,6 @@ modest_edit_msg_window_new (ModestConf *conf, ModestWidgetFactory *factory, 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; diff --git a/src/gtk/modest-edit-msg-window.h b/src/gtk/modest-edit-msg-window.h index 53bbd14..6210655 100644 --- a/src/gtk/modest-edit-msg-window.h +++ b/src/gtk/modest-edit-msg-window.h @@ -76,8 +76,7 @@ typedef enum _ModestEditType ModestEditType; /* 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 diff --git a/src/gtk/modest-main-window.c b/src/gtk/modest-main-window.c index 83e058b..ab4b0a5 100644 --- a/src/gtk/modest-main-window.c +++ b/src/gtk/modest-main-window.c @@ -34,9 +34,11 @@ #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); @@ -63,10 +65,9 @@ struct _ModestMainWindowPrivate { 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; @@ -131,10 +132,8 @@ modest_main_window_init (ModestMainWindow *obj) 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 @@ -142,19 +141,10 @@ modest_main_window_finalize (GObject *obj) { 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); } @@ -198,8 +188,7 @@ on_menu_accounts (ModestMainWindow *self, guint action, GtkWidget *widget) 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)); @@ -213,11 +202,14 @@ on_menu_new_message (ModestMainWindow *self, guint action, GtkWidget *widget) { 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); @@ -319,7 +311,7 @@ header_view_new (ModestMainWindow *self) 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); @@ -400,7 +392,7 @@ toolbar_new (ModestMainWindow *self) 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", @@ -414,16 +406,19 @@ toolbar_new (ModestMainWindow *self) 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"); } @@ -432,16 +427,18 @@ static void 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"); } @@ -497,8 +494,7 @@ favorites_view () GtkWidget* -modest_main_window_new (ModestConf *conf, ModestAccountMgr *account_mgr, - ModestWidgetFactory *factory) +modest_main_window_new (ModestWidgetFactory *widget_factory) { GObject *obj; ModestMainWindowPrivate *priv; @@ -507,25 +503,18 @@ modest_main_window_new (ModestConf *conf, ModestAccountMgr *account_mgr, 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); @@ -555,16 +544,16 @@ modest_main_window_new (ModestConf *conf, ModestAccountMgr *account_mgr, /* 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... */ diff --git a/src/gtk/modest-main-window.h b/src/gtk/modest-main-window.h index 94c02ac..12701db 100644 --- a/src/gtk/modest-main-window.h +++ b/src/gtk/modest-main-window.h @@ -7,8 +7,6 @@ #include #include #include -#include -#include #ifdef HAVE_CONFIG_H #include @@ -42,8 +40,7 @@ struct _ModestMainWindowClass { 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 diff --git a/src/gtk/modest-ui.c b/src/gtk/modest-ui.c index 62b06cc..3f06bad 100644 --- a/src/gtk/modest-ui.c +++ b/src/gtk/modest-ui.c @@ -40,6 +40,7 @@ #include "../modest-account-mgr.h" #include "../modest-widget-factory.h" #include "modest-main-window.h" +#include "modest-tny-platform-factory.h" /* 'private'/'protected' functions */ @@ -52,10 +53,7 @@ gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *); typedef struct _ModestUIPrivate ModestUIPrivate; struct _ModestUIPrivate { - ModestConf *conf; - ModestAccountMgr *account_mgr; ModestWidgetFactory *widget_factory; - ModestTnyAccountStore *account_store; GtkWidget *main_window; }; @@ -122,9 +120,6 @@ modest_ui_init (ModestUI *obj) 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; @@ -137,58 +132,43 @@ modest_ui_finalize (GObject *obj) 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; } @@ -215,8 +195,7 @@ modest_ui_main_window (ModestUI *modest_ui) 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); diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c new file mode 100644 index 0000000..9307a6e --- /dev/null +++ b/src/modest-mail-operation.c @@ -0,0 +1,245 @@ +/* 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 +#include + +/* '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; +} diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h new file mode 100644 index 0000000..3e483dd --- /dev/null +++ b/src/modest-mail-operation.h @@ -0,0 +1,81 @@ +/* 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 +#include +#include +/* 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__ */ + diff --git a/src/modest-main.c b/src/modest-main.c index b09bf6c..d79db1f 100644 --- a/src/modest-main.c +++ b/src/modest-main.c @@ -43,6 +43,7 @@ #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 */ @@ -60,16 +61,17 @@ 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; @@ -110,7 +112,8 @@ main (int argc, char *argv[]) } 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; @@ -125,21 +128,19 @@ main (int argc, char *argv[]) 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) { @@ -150,7 +151,7 @@ start_ui (ModestConf *conf, const gchar* mailto, const gchar *cc, const gchar *b 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; @@ -214,19 +215,21 @@ hildon_init () 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, @@ -242,23 +245,19 @@ send_mail (ModestConf *conf, const gchar* mailto, const gchar *cc, const gchar * 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; } diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index a42323c..1bcbf7e 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -36,12 +36,12 @@ #include #include #include -#include #include #include #include #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); @@ -422,7 +422,7 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) { 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); diff --git a/src/modest-tny-attachment.c b/src/modest-tny-attachment.c index 8fb8e5e..19f6562 100644 --- a/src/modest-tny-attachment.c +++ b/src/modest-tny-attachment.c @@ -254,7 +254,7 @@ modest_tny_attachment_set_stream(ModestTnyAttachment *self, TnyStreamIface *thin priv->stream = thing; } -TnyStreamIface * +TnyStream * modest_tny_attachment_get_stream (ModestTnyAttachment *self) { ModestTnyAttachmentPrivate *priv; diff --git a/src/modest-tny-attachment.h b/src/modest-tny-attachment.h index ea9bac2..57e45c7 100644 --- a/src/modest-tny-attachment.h +++ b/src/modest-tny-attachment.h @@ -82,7 +82,7 @@ const gchar *modest_tny_attachment_get_mime_type (ModestTnyAttachment *self); 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); diff --git a/src/modest-tny-platform-factory.c b/src/modest-tny-platform-factory.c new file mode 100644 index 0000000..0433614 --- /dev/null +++ b/src/modest-tny-platform-factory.c @@ -0,0 +1,245 @@ +/* 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; +} diff --git a/src/modest-tny-platform-factory.h b/src/modest-tny-platform-factory.h new file mode 100644 index 0000000..fccb773 --- /dev/null +++ b/src/modest-tny-platform-factory.h @@ -0,0 +1,73 @@ +/* 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 +/* other include files */ +#include +#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__ */ diff --git a/src/modest-ui.h b/src/modest-ui.h index 186142d..94211cf 100644 --- a/src/modest-ui.h +++ b/src/modest-ui.h @@ -77,7 +77,7 @@ GType modest_ui_get_type (void) G_GNUC_CONST; * * Returns: a new ModestUI, or NULL in case of error */ -ModestUI* modest_ui_new (ModestConf *modest_conf); +ModestUI* modest_ui_new (void); /** diff --git a/src/modest-widget-factory.c b/src/modest-widget-factory.c index 3ab285c..ddc7d29 100644 --- a/src/modest-widget-factory.c +++ b/src/modest-widget-factory.c @@ -31,6 +31,8 @@ #include #include #include +#include "modest-tny-platform-factory.h" +#include "modest-account-mgr.h" /* 'private'/'protected' functions */ static void modest_widget_factory_class_init (ModestWidgetFactoryClass *klass); @@ -74,9 +76,8 @@ enum { 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; @@ -141,9 +142,8 @@ modest_widget_factory_init (ModestWidgetFactory *obj) 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 (); @@ -160,25 +160,10 @@ modest_widget_factory_finalize (GObject *obj) 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; - } } @@ -214,12 +199,11 @@ init_signals (ModestWidgetFactory *self) 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); @@ -237,6 +221,7 @@ static gboolean init_widgets (ModestWidgetFactory *self) { ModestWidgetFactoryPrivate *priv; + priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self); /* folder view */ @@ -277,29 +262,15 @@ init_widgets (ModestWidgetFactory *self) 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); @@ -340,11 +311,15 @@ ModestAccountView* 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); } @@ -370,17 +345,20 @@ static const GSList* 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, @@ -643,8 +621,7 @@ on_online_toggle_toggled (GtkToggleButton *toggle, ModestWidgetFactory *self) 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 */ @@ -667,8 +644,7 @@ static void on_item_not_found (ModestHeaderView* header_view, ModestItemType 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) { diff --git a/src/modest-widget-factory.h b/src/modest-widget-factory.h index 25810d0..2ddc214 100644 --- a/src/modest-widget-factory.h +++ b/src/modest-widget-factory.h @@ -97,9 +97,7 @@ GType modest_widget_factory_get_type (void) G_GNUC_CONST; * * 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 -- 1.7.9.5