* all:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sun, 28 Jan 2007 13:50:10 +0000 (13:50 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sun, 28 Jan 2007 13:50:10 +0000 (13:50 +0000)
- move all singletons (such as account mgr, conf, widget factory)
  to ModestSingletons, and they are accessed through to
  ModestRuntime. This removes the need for many classes to
  keep the singletons in their *Private, and move around the
  same ptrs to functions.

ModestRuntime keeps maintains these singletons, and also takes
  care of the stuff that was previously in ModestDebug and
  ModestInit, and some of the other initialization in modest-main,
  which is significantly cleaned-up as well

pmo-trunk-r743

30 files changed:
src/Makefile.am
src/gtk/modest-account-view-window.c
src/gtk/modest-edit-msg-window.c
src/gtk/modest-main-window.c
src/modest-debug.c [deleted file]
src/modest-debug.h [deleted file]
src/modest-icon-factory.c
src/modest-init.c [deleted file]
src/modest-init.h [deleted file]
src/modest-main.c
src/modest-runtime.c [new file with mode: 0644]
src/modest-runtime.h [new file with mode: 0644]
src/modest-singletons.c [new file with mode: 0644]
src/modest-singletons.h [new file with mode: 0644]
src/modest-text-utils.c
src/modest-tny-account-store.c
src/modest-tny-account-store.h
src/modest-tny-folder.h
src/modest-tny-platform-factory.c
src/modest-tny-platform-factory.h
src/modest-ui-priv.h
src/modest-ui.c
src/modest-ui.h
src/modest-widget-factory.c
src/modest-widget-factory.h
src/widgets/modest-edit-msg-window.h
src/widgets/modest-main-window.h
src/widgets/modest-window-priv.h
src/widgets/modest-window.c
src/widgets/modest-window.h

index 2c5f7b1..599e017 100644 (file)
@@ -1,6 +1,6 @@
 #
 # Makefile.am
 #
 # Makefile.am
-# Time-stamp: <2007-01-24 09:06:54 (djcb)>
+# Time-stamp: <2007-01-27 18:11:31 (djcb)>
 SUBDIRS=$(MODEST_PLATFORM) widgets
 DIST_SUBDIRS = widgets gtk maemo
 
 SUBDIRS=$(MODEST_PLATFORM) widgets
 DIST_SUBDIRS = widgets gtk maemo
 
@@ -40,16 +40,12 @@ modest_SOURCES=\
        modest-cache-mgr.h\
        modest-conf.c\
        modest-conf.h \
        modest-cache-mgr.h\
        modest-conf.c\
        modest-conf.h \
-       modest-debug.c\
-       modest-debug.h\
        modest-defs.h\
        modest-error.h \
        modest-formatter.c \
        modest-formatter.h \
        modest-icon-factory.c\
        modest-icon-factory.h\
        modest-defs.h\
        modest-error.h \
        modest-formatter.c \
        modest-formatter.h \
        modest-icon-factory.c\
        modest-icon-factory.h\
-       modest-init.h\
-       modest-init.c\
        modest-local-folder-info.h \
        modest-local-folder-info.c \
        modest-mail-operation-queue.c \
        modest-local-folder-info.h \
        modest-local-folder-info.c \
        modest-mail-operation-queue.c \
@@ -63,10 +59,16 @@ modest_SOURCES=\
        modest-pair.h\
        modest-protocol-info.c\
        modest-protocol-info.h\
        modest-pair.h\
        modest-protocol-info.c\
        modest-protocol-info.h\
+       modest-runtime.c\
+       modest-runtime.h\
+       modest-singletons.c\
+       modest-singletons.h\
        modest-text-utils.c\
        modest-text-utils.h\
        modest-tny-account-store.c\
        modest-tny-account-store.h\
        modest-text-utils.c\
        modest-text-utils.h\
        modest-tny-account-store.c\
        modest-tny-account-store.h\
+       modest-tny-account.c\
+       modest-tny-account.h\
        modest-tny-folder.c \
        modest-tny-folder.h \
        modest-tny-msg-actions.c\
        modest-tny-folder.c \
        modest-tny-folder.h \
        modest-tny-msg-actions.c\
index 55000b6..aaa9655 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include <glib/gi18n.h>
  */
 
 #include <glib/gi18n.h>
+#include <modest-runtime.h>
 #include "modest-account-view-window.h"
 #include "modest-account-assistant.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-account-view-window.h"
 #include "modest-account-assistant.h"
 #include "modest-tny-platform-factory.h"
@@ -150,16 +151,13 @@ on_selection_changed (GtkTreeSelection *sel, ModestAccountViewWindow *self)
 static void
 on_remove_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
 {
 static void
 on_remove_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
 {
-       TnyPlatformFactory *fact;
        ModestAccountViewWindowPrivate *priv;
        ModestAccountMgr *account_mgr;
        const gchar *account_name;
        
        priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
        ModestAccountViewWindowPrivate *priv;
        ModestAccountMgr *account_mgr;
        const gchar *account_name;
        
        priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
-       fact = modest_tny_platform_factory_get_instance ();
-       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(fact));
 
 
+       account_mgr = modest_runtime_get_account_mgr(); 
        account_name = modest_account_view_get_selected_account (priv->account_view);
 
        if (account_name) {
        account_name = modest_account_view_get_selected_account (priv->account_view);
 
        if (account_name) {
@@ -212,15 +210,9 @@ on_add_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
 {
        GtkWidget *assistant;
        ModestAccountViewWindowPrivate *priv;
 {
        GtkWidget *assistant;
        ModestAccountViewWindowPrivate *priv;
-       TnyPlatformFactory *fact;
-       ModestAccountMgr *account_mgr;
        
        priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
        
        priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
-       fact = modest_tny_platform_factory_get_instance ();
-       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(fact));
-
-       assistant = modest_account_assistant_new (account_mgr,
+       assistant = modest_account_assistant_new (modest_runtime_get_account_mgr(),
                                                  priv->widget_factory);
        gtk_window_set_transient_for (GTK_WINDOW(assistant),
                                      GTK_WINDOW(self));
                                                  priv->widget_factory);
        gtk_window_set_transient_for (GTK_WINDOW(assistant),
                                      GTK_WINDOW(self));
index 018a4c6..705e396 100644 (file)
@@ -30,6 +30,8 @@
 #include <string.h>
 #include <tny-account-store.h>
 #include <tny-simple-list.h>
 #include <string.h>
 #include <tny-account-store.h>
 #include <tny-simple-list.h>
+#include <modest-conf.h>
+#include <modest-runtime.h>
 
 #include "modest-account-mgr.h"
 #include "modest-account-mgr-helpers.h"
 
 #include "modest-account-mgr.h"
 #include "modest-account-mgr-helpers.h"
@@ -134,27 +136,16 @@ modest_edit_msg_window_init (ModestEditMsgWindow *obj)
 static void
 save_settings (ModestEditMsgWindow *self)
 {
 static void
 save_settings (ModestEditMsgWindow *self)
 {
-       ModestWindowPrivate *parent_priv;
-       ModestConf *conf;
-
-       parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
-       conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(parent_priv->plat_factory));
-
-       modest_widget_memory_save (conf, G_OBJECT(self), "modest-edit-msg-window");
+       modest_widget_memory_save (modest_runtime_get_conf (),
+                                   G_OBJECT(self), "modest-edit-msg-window");
 }
 
 
 static void
 restore_settings (ModestEditMsgWindow *self)
 {
 }
 
 
 static void
 restore_settings (ModestEditMsgWindow *self)
 {
-       ModestWindowPrivate *parent_priv;
-       ModestConf *conf;
-
-       parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
-       conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(parent_priv->plat_factory));
-       modest_widget_memory_restore (conf, G_OBJECT(self), "modest-edit-msg-window");
+       modest_widget_memory_restore (modest_runtime_get_conf (),
+                                     G_OBJECT(self), "modest-edit-msg-window");
 }
 
 
 }
 
 
@@ -174,7 +165,7 @@ init_window (ModestEditMsgWindow *obj)
        cc_button     = gtk_button_new_with_label (_("Cc..."));
        bcc_button    = gtk_button_new_with_label (_("Bcc..."));
 
        cc_button     = gtk_button_new_with_label (_("Cc..."));
        bcc_button    = gtk_button_new_with_label (_("Bcc..."));
 
-       priv->from_field    = modest_widget_factory_get_combo_box (parent_priv->widget_factory,
+       priv->from_field    = modest_widget_factory_get_combo_box (modest_runtime_get_widget_factory(),
                                                                   MODEST_COMBO_BOX_TYPE_TRANSPORTS);
        priv->to_field      = gtk_entry_new_with_max_length (80);
        priv->cc_field      = gtk_entry_new_with_max_length (80);
                                                                   MODEST_COMBO_BOX_TYPE_TRANSPORTS);
        priv->to_field      = gtk_entry_new_with_max_length (80);
        priv->cc_field      = gtk_entry_new_with_max_length (80);
@@ -209,7 +200,6 @@ init_window (ModestEditMsgWindow *obj)
        gtk_widget_show_all (GTK_WIDGET(main_vbox));
        gtk_container_add (GTK_CONTAINER(obj), main_vbox);
 }
        gtk_widget_show_all (GTK_WIDGET(main_vbox));
        gtk_container_add (GTK_CONTAINER(obj), main_vbox);
 }
-       
 
 
 static void
 
 
 static void
@@ -229,9 +219,7 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestEditMsgWindow *self)
 
 
 ModestWindow *
 
 
 ModestWindow *
-modest_edit_msg_window_new (ModestWidgetFactory *factory,
-                           TnyAccountStore *account_store,
-                           ModestEditType type)
+modest_edit_msg_window_new (ModestEditType type)
 {
        GObject *obj;
        ModestEditMsgWindowPrivate *priv;
 {
        GObject *obj;
        ModestEditMsgWindowPrivate *priv;
@@ -239,17 +227,12 @@ modest_edit_msg_window_new (ModestWidgetFactory *factory,
        GtkActionGroup *action_group;
        GError *error = NULL;
 
        GtkActionGroup *action_group;
        GError *error = NULL;
 
-       g_return_val_if_fail (factory, NULL);
        g_return_val_if_fail (type < MODEST_EDIT_TYPE_NUM, NULL);
        
        obj = g_object_new(MODEST_TYPE_EDIT_MSG_WINDOW, NULL);
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
        g_return_val_if_fail (type < MODEST_EDIT_TYPE_NUM, NULL);
        
        obj = g_object_new(MODEST_TYPE_EDIT_MSG_WINDOW, NULL);
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE(obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
-
-       parent_priv->widget_factory = g_object_ref (factory);
-       parent_priv->account_store  = g_object_ref (account_store);
-
-       /* ****** */
+       
        parent_priv->ui_manager = gtk_ui_manager_new();
        action_group = gtk_action_group_new ("ModestEditMsgWindowActions");
 
        parent_priv->ui_manager = gtk_ui_manager_new();
        action_group = gtk_action_group_new ("ModestEditMsgWindowActions");
 
index 3ff82f4..06ab587 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <glib/gi18n.h>
 #include <gtk/gtktreeviewcolumn.h>
 
 #include <glib/gi18n.h>
 #include <gtk/gtktreeviewcolumn.h>
+#include <modest-runtime.h>
 
 #include "modest-main-window.h"
 #include "modest-window-priv.h"
 
 #include "modest-main-window.h"
 #include "modest-window-priv.h"
@@ -166,12 +167,12 @@ static ModestHeaderView*
 header_view_new (ModestMainWindow *self)
 {
        ModestHeaderView *header_view;
 header_view_new (ModestMainWindow *self)
 {
        ModestHeaderView *header_view;
-       ModestWindowPrivate *parent_priv;
-
-       parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
        
        
-       header_view = modest_widget_factory_get_header_view (parent_priv->widget_factory);
-       modest_header_view_set_style (header_view, MODEST_HEADER_VIEW_STYLE_DETAILS);
+       header_view = modest_widget_factory_get_header_view
+               (modest_runtime_get_widget_factory());
+       modest_header_view_set_style
+               (header_view, MODEST_HEADER_VIEW_STYLE_DETAILS);
+
        return header_view;
 }
 
        return header_view;
 }
 
@@ -186,9 +187,8 @@ restore_sizes (ModestMainWindow *self)
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
 
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
 
-       conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(parent_priv->plat_factory));
-
+       conf = modest_runtime_get_conf ();
+       
        modest_widget_memory_restore (conf, G_OBJECT(priv->folder_paned),
                                      "modest-folder-paned");
        modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned),
        modest_widget_memory_restore (conf, G_OBJECT(priv->folder_paned),
                                      "modest-folder-paned");
        modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned),
@@ -212,8 +212,7 @@ save_sizes (ModestMainWindow *self)
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
 
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
 
-       conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(parent_priv->plat_factory));
+       conf = modest_runtime_get_conf ();
        
        modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
        modest_widget_memory_save (conf, G_OBJECT(priv->folder_paned),
        
        modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
        modest_widget_memory_save (conf, G_OBJECT(priv->folder_paned),
@@ -255,8 +254,7 @@ on_delete_event (GtkWidget *widget, GdkEvent  *event, ModestMainWindow *self)
 
 
 ModestWindow *
 
 
 ModestWindow *
-modest_main_window_new (ModestWidgetFactory *widget_factory,
-                       TnyAccountStore *account_store)
+modest_main_window_new (void)
 {
        GObject *obj;
        ModestMainWindowPrivate *priv;
 {
        GObject *obj;
        ModestMainWindowPrivate *priv;
@@ -264,22 +262,21 @@ modest_main_window_new (ModestWidgetFactory *widget_factory,
        GtkWidget *main_vbox;
        GtkWidget *status_hbox;
        GtkWidget *header_win, *folder_win;
        GtkWidget *main_vbox;
        GtkWidget *status_hbox;
        GtkWidget *header_win, *folder_win;
+       ModestWidgetFactory *widget_factory;
        GtkActionGroup *action_group;
        GError *error = NULL;
        
        GtkActionGroup *action_group;
        GError *error = 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);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
        obj  = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
-
-       parent_priv->widget_factory = g_object_ref (widget_factory);
-       parent_priv->account_store  = g_object_ref (account_store);
-
+       
        /* ***************** */
        parent_priv->ui_manager = gtk_ui_manager_new();
        action_group = gtk_action_group_new ("ModestMainWindowActions");
 
        /* ***************** */
        parent_priv->ui_manager = gtk_ui_manager_new();
        action_group = gtk_action_group_new ("ModestMainWindowActions");
 
+       widget_factory = modest_runtime_get_widget_factory ();
+       
        /* Add common actions */
        gtk_action_group_add_actions (action_group,
                                      modest_action_entries,
        /* Add common actions */
        gtk_action_group_add_actions (action_group,
                                      modest_action_entries,
@@ -292,7 +289,7 @@ modest_main_window_new (ModestWidgetFactory *widget_factory,
        /* Load the UI definition */
        gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-ui.xml", &error);
        if (error != NULL) {
        /* Load the UI definition */
        gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-ui.xml", &error);
        if (error != NULL) {
-               g_warning ("Could not merge modest-ui.xml: %s", error->message);
+               g_printerr ("modest: could not merge modest-ui.xml: %s", error->message);
                g_error_free (error);
                error = NULL;
        }
                g_error_free (error);
                error = NULL;
        }
@@ -302,7 +299,6 @@ modest_main_window_new (ModestWidgetFactory *widget_factory,
        gtk_window_add_accel_group (GTK_WINDOW (obj), 
                                    gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
 
        gtk_window_add_accel_group (GTK_WINDOW (obj), 
                                    gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
 
-
        /* Toolbar / Menubar */
        parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
        parent_priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar");
        /* Toolbar / Menubar */
        parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
        parent_priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar");
@@ -337,7 +333,6 @@ modest_main_window_new (ModestWidgetFactory *widget_factory,
                          G_CALLBACK (on_folder_view_button_press_event),
                          obj);
 
                          G_CALLBACK (on_folder_view_button_press_event),
                          obj);
 
-
        /* paned */
        priv->folder_paned = gtk_vpaned_new ();
        priv->msg_paned = gtk_vpaned_new ();
        /* paned */
        priv->folder_paned = gtk_vpaned_new ();
        priv->msg_paned = gtk_vpaned_new ();
diff --git a/src/modest-debug.c b/src/modest-debug.c
deleted file mode 100644 (file)
index 39fdaa0..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/* 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-debug.h>
-
-/* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/
-ModestDebugFlags
-modest_debug_get_debug_flags ()
-{
-       GDebugKey debug_keys[] = {
-               { "abort-on-warning", MODEST_DEBUG_ABORT_ON_WARNING },
-               { "log-actions",      MODEST_DEBUG_LOG_ACTIONS },
-               { "debug-objects",    MODEST_DEBUG_DEBUG_OBJECTS },
-               { "debug-signals",    MODEST_DEBUG_DEBUG_SIGNALS }
-       };
-       const gchar *str;
-       ModestDebugFlags debug_flags = -1;
-
-       if (debug_flags != -1)
-               return debug_flags;
-       
-       str = g_getenv (MODEST_DEBUG);
-       
-       if (str != NULL)
-               debug_flags = g_parse_debug_string (str, debug_keys, G_N_ELEMENTS (debug_keys));
-       else
-               debug_flags = 0;
-       
-       return debug_flags;
-}
-
-
-void
-modest_debug_g_type_init (void)
-{
-       GTypeDebugFlags gflags;
-       ModestDebugFlags mflags;
-       
-       gflags = 0;
-       mflags = modest_debug_get_debug_flags ();
-
-       if (mflags & MODEST_DEBUG_DEBUG_OBJECTS)
-               gflags |= G_TYPE_DEBUG_OBJECTS;
-       if (mflags & MODEST_DEBUG_DEBUG_SIGNALS)
-               gflags |= G_TYPE_DEBUG_SIGNALS;
-       
-       g_type_init_with_debug_flags (gflags);
-
-}
-
-void
-modest_debug_logging_init (void)
-{
-       ModestDebugFlags mflags;
-       mflags = modest_debug_get_debug_flags ();
-       
-       if (mflags & MODEST_DEBUG_ABORT_ON_WARNING)
-               g_log_set_always_fatal (G_LOG_LEVEL_ERROR |
-                                       G_LOG_LEVEL_CRITICAL |
-                                       G_LOG_LEVEL_WARNING);
-}
diff --git a/src/modest-debug.h b/src/modest-debug.h
deleted file mode 100644 (file)
index be8c53d..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/* 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_DEBUG_H__
-#define __MODEST_DEBUG_H__
-
-#include <glib.h>
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define MODEST_DEBUG "MODEST_DEBUG"
-
-typedef enum {
-       MODEST_DEBUG_ABORT_ON_WARNING      = 1 << 0,
-       MODEST_DEBUG_LOG_ACTIONS           = 1 << 1, /* not in use atm */
-       MODEST_DEBUG_DEBUG_OBJECTS         = 1 << 2, /* for g_type_init */
-       MODEST_DEBUG_DEBUG_SIGNALS         = 1 << 3, /* for g_type_init */
-} ModestDebugFlags;
-
-
-/**
- * modest_debug_get_debug_flags 
- *
- * get the debug flags for modest; they are read from the MODEST_DEBUG
- * environment variable; the flags specified as strings, separated by ':'.
- * Possible values are:
- * - "abort-on-warning": abort the program when a gtk/glib/.. warning occurs.
- * useful when running in debugger
- * - "log-actions": log user actions (not in use atm)
- * - "track-object": track the use of (g)objects in the program. this option influences
- *  g_type_init_with_debug_flags
- *  - "track-signals": track the use of (g)signals in the program. this option influences
- *  g_type_init_with_debug_flags
- *  - "disable-cache": disable caching of strings and pixbuf
- * if you would want to track signals and log actions, you could do something like:
- *  MODEST_DEBUG="log-actions:track-signals" ./modest
- * NOTE that the flags will stay the same during the run of the program, even
- * if the environment variable changes.
- * 
- * Returns: the bitwise OR of the debug flags
- */
-ModestDebugFlags modest_debug_get_debug_flags  (void) G_GNUC_CONST;
-
-/**
- * modest_g_type_init
- *
- * do a g_type_init_with_debug_flags based on the modest debug flags
- */
-void modest_debug_g_type_init (void);
-
-/**
- * modest_g_type_init
- *
- * do set the logging based on the modest debug flags (ie. whether
- * we should abort when a warning occurs.
- */
-void modest_debug_logging_init (void);
-
-G_END_DECLS
-
-#endif /*__MODEST_DEBUG_H__*/
index a577cd6..d1154f7 100644 (file)
 /* modest-icon-factory.c */
 
 #include <modest-icon-factory.h>
 /* modest-icon-factory.c */
 
 #include <modest-icon-factory.h>
-#include <modest-tny-platform-factory.h>
-
-static GHashTable*
-get_icon_cache (void)
-{
-       TnyPlatformFactory *fakt;
-       ModestCacheMgr     *cache_mgr;
-
-       fakt = modest_tny_platform_factory_get_instance ();
-       
-       cache_mgr =  modest_tny_platform_factory_get_cache_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(fakt));
-
-       return modest_cache_mgr_get_cache (cache_mgr,
-                                          MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF);
-}
-
+#include <modest-runtime.h>
 
 GdkPixbuf*
 modest_icon_factory_get_icon (const gchar *name)
 
 GdkPixbuf*
 modest_icon_factory_get_icon (const gchar *name)
@@ -60,7 +44,8 @@ modest_icon_factory_get_icon (const gchar *name)
        g_return_val_if_fail (name, NULL);
 
        if (G_UNLIKELY(!icon_cache))
        g_return_val_if_fail (name, NULL);
 
        if (G_UNLIKELY(!icon_cache))
-               icon_cache = get_icon_cache ();
+               icon_cache = modest_cache_mgr_get_cache (modest_runtime_get_cache_mgr(),
+                                                        MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF);
        
        if (!icon_cache || !g_hash_table_lookup_extended (icon_cache, name, &orig_key,
                                                          (gpointer*)&pixbuf)) {
        
        if (!icon_cache || !g_hash_table_lookup_extended (icon_cache, name, &orig_key,
                                                          (gpointer*)&pixbuf)) {
diff --git a/src/modest-init.c b/src/modest-init.c
deleted file mode 100644 (file)
index a9568d5..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-/* 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 <config.h>
-#include <modest-defs.h>
-#include <widgets/modest-header-view.h>
-#include <widgets/modest-folder-view.h>
-#include <modest-tny-platform-factory.h>
-#include <modest-widget-memory.h>
-#include <modest-widget-memory-priv.h>
-#include <modest-local-folder-info.h>
-#include <modest-init.h>
-#include <glib/gstdio.h>
-#include <modest-account-mgr.h>
-#include <modest-account-mgr-helpers.h>
-
-typedef struct {
-       ModestHeaderViewColumn col;
-       guint                  width;
-} FolderCols;
-
-static const FolderCols INBOX_COLUMNS_DETAILS[] = {
-       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
-       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
-       {MODEST_HEADER_VIEW_COLUMN_FROM,    80},
-       {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
-       {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60},
-       {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
-};
-static const FolderCols INBOX_COLUMNS_TWOLINES[] = {
-       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
-       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
-       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 200}
-};
-
-static const FolderCols OUTBOX_COLUMNS_DETAILS[] = {
-        {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
-        {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
-        {MODEST_HEADER_VIEW_COLUMN_TO,    80},
-        {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
-        {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80},
-        {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
-};
-static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = {
-        {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
-        {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
-        {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,200},
-};
-        
-static const TnyFolderType LOCAL_FOLDERS[] = {
-       TNY_FOLDER_TYPE_OUTBOX,
-       TNY_FOLDER_TYPE_DRAFTS,
-       TNY_FOLDER_TYPE_SENT,
-       TNY_FOLDER_TYPE_ARCHIVE 
-};
-
-static ModestTnyPlatformFactory*
-get_platform_factory (void)
-{
-       TnyPlatformFactory *fact =
-               modest_tny_platform_factory_get_instance ();
-
-       if (!fact) {
-               g_printerr ("modest: cannot get platform factory instance\n");
-               return NULL;
-       }
-
-       return MODEST_TNY_PLATFORM_FACTORY(fact);
-}
-
-
-static ModestConf*
-get_modest_conf (void)
-{
-       ModestTnyPlatformFactory *fact =
-               get_platform_factory ();
-       ModestConf *conf =
-               modest_tny_platform_factory_get_conf_instance (fact);
-       if (!conf) {
-               g_printerr ("modest: cannot get modest conf instance\n");
-               return NULL;
-       }
-       return conf;
-}
-
-
-static ModestAccountMgr*
-get_account_mgr (void)
-{
-       ModestTnyPlatformFactory *fact =
-               get_platform_factory ();
-       ModestAccountMgr *acc_mgr =
-               modest_tny_platform_factory_get_account_mgr_instance (fact);
-       if (!acc_mgr) {
-               g_printerr ("modest: cannot get modest account mgr instance\n");
-               return NULL;
-       }
-       return acc_mgr;
-}
-
-
-/* NOTE: the exact details of this format are important, as they
- * are also used in modest-widget-memory. FIXME: make a shared function
- * for this with widget-memory
- */
-static gboolean
-save_header_settings (ModestConf *conf, TnyFolderType type,
-                     ModestHeaderViewStyle style,  const FolderCols* cols,
-                     guint col_num, gboolean overwrite)
-{
-       int i;
-       gchar *key;
-       GString *str;
-
-       g_return_val_if_fail (cols, FALSE);
-
-       key = _modest_widget_memory_get_keyname_with_double_type ("header-view",
-                                                                 type, style,
-                                                                 MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
-       /* if we're not in overwrite mode, only write stuff it
-        * there was nothing before */
-       if (!overwrite &&  modest_conf_key_exists(conf, key, NULL)) {
-               g_free (key);
-               return TRUE;
-       }
-
-       /* the format is necessarily the same as the one in modest-widget-memory */
-       str = g_string_new (NULL);
-       for (i = 0; i != col_num; ++i) 
-               g_string_append_printf (str, "%d:%d ",
-                                       cols[i].col, cols[i].width); 
-
-       modest_conf_set_string (conf, key, str->str, NULL);
-       g_free (key);
-       g_string_free (str, TRUE);
-       
-       return TRUE;
-}
-
-/* we set the the defaults here for all folder types */
-gboolean
-modest_init_header_columns (gboolean overwrite)
-{
-       ModestConf *conf;
-       int folder_type;
-
-       conf = get_modest_conf ();
-       if (!conf) {
-               g_printerr ("modest: cannot get modest conf\n");
-               return FALSE;
-       }
-       
-       for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
-            folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {          
-               
-               switch (folder_type) {
-               case TNY_FOLDER_TYPE_OUTBOX:
-               case TNY_FOLDER_TYPE_SENT:
-               case TNY_FOLDER_TYPE_DRAFTS:
-               save_header_settings (conf, folder_type,
-                                     MODEST_HEADER_VIEW_STYLE_DETAILS,
-                                     OUTBOX_COLUMNS_DETAILS,
-                                     G_N_ELEMENTS(OUTBOX_COLUMNS_DETAILS),
-                                     overwrite);
-               save_header_settings (conf, folder_type,
-                                     MODEST_HEADER_VIEW_STYLE_TWOLINES,
-                                     OUTBOX_COLUMNS_TWOLINES,
-                                     G_N_ELEMENTS(OUTBOX_COLUMNS_TWOLINES),
-                                     overwrite);
-               break;
-
-               default:
-               save_header_settings (conf, folder_type,
-                                     MODEST_HEADER_VIEW_STYLE_DETAILS,
-                                     INBOX_COLUMNS_DETAILS,
-                                     G_N_ELEMENTS(INBOX_COLUMNS_DETAILS),
-                                     overwrite);
-               save_header_settings (conf, folder_type,
-                                     MODEST_HEADER_VIEW_STYLE_TWOLINES,
-                                     INBOX_COLUMNS_TWOLINES,
-                                     G_N_ELEMENTS(INBOX_COLUMNS_TWOLINES),
-                                     overwrite);
-               };
-       }
-       return TRUE;
-}
-
-gboolean
-modest_init_local_folders  (void)
-{
-       int i;
-       gchar *maildir_path;
-       static const gchar* maildirs[] = {
-               "cur", "new", "tmp"
-       };
-       
-       maildir_path = modest_local_folder_info_get_maildir_path ();
-
-       for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
-               int j;
-               for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
-                       gchar *dir;
-                       dir = g_build_filename (maildir_path,
-                                               modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
-                                               maildirs[j],
-                                               NULL);
-                       if (g_mkdir_with_parents (dir, 0755) < 0) {
-                               g_printerr ("modest: failed to create %s\n", dir);
-                               g_free (dir);
-                               g_free (maildir_path);
-                               return FALSE;
-                       }
-                       g_free(dir);
-               }
-       }
-       
-       g_free (maildir_path);
-       return TRUE;
-}
-
-
-
-static void
-free_element (gpointer data, gpointer user_data)
-{
-       g_free (data);
-}
-
-
-gboolean
-modest_init_default_account_maybe  (void)
-{
-       ModestAccountMgr *acc_mgr;
-
-       GSList *all_accounts = NULL;
-       gchar *default_account;
-       gboolean retval = TRUE;
-       
-       acc_mgr = get_account_mgr ();
-       if (!acc_mgr) {
-               g_printerr ("modest: cannot get modest account mgr\n");
-               return FALSE;
-       }
-
-       all_accounts = modest_account_mgr_account_names (acc_mgr, NULL);
-       if (all_accounts) { /* if there are any accounts, there should be a default one */
-               default_account = 
-                       modest_account_mgr_get_default_account (acc_mgr);
-               if (!default_account) {
-                       gchar *first_account;
-                       g_printerr ("modest: no default account defined\n");
-                       first_account = (gchar*)all_accounts->data;
-                       if ((retval = modest_account_mgr_set_default_account (acc_mgr, first_account)))
-                               g_printerr ("modest: set '%s' as the default account\n",
-                                           first_account);
-                       else
-                               g_printerr ("modest: failed to set '%s' as the default account\n",
-                                           first_account);
-                       g_free (default_account);
-               }
-               g_slist_foreach (all_accounts, free_element, NULL);
-               g_slist_free    (all_accounts);
-       }
-       return retval;
-}
diff --git a/src/modest-init.h b/src/modest-init.h
deleted file mode 100644 (file)
index 7a536e5..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/* 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_INIT_H__
-#define __MODEST_INIT_H__
-
-#include <glib.h>
-#include <glib-object.h>
-
-/*
- * functions to initialize various parts of the modest system
- */
-G_BEGIN_DECLS
-
-/**
- * modest_init_header_columns:
- * @overwrite: write the setting, even if it already exists
- * 
- * will set defaults for the columns to show for folder,
- * if there are no such settings yet (in ModestWidgetMemory)
- * 
- * Returns: TRUE if succeeded, FALSE in case of error
- */
-gboolean modest_init_header_columns (gboolean overwrite);
-
-/**
- * modest_init_local_folders:
- * 
- * create the Local Folders folder under cache, if they
- * do not exist yet.
- * 
- * Returns: TRUE if the folder were already there, or
- * they were created, FALSE otherwise
- */
-gboolean modest_init_local_folders  (void);
-
-
-/**
- * modest_init_default_account_maybe:
- *
- * if there are accounts defined, but there is no default account,
- * it will be defined.
- * 
- * Returns: TRUE if there was a default account already,
- *  or one has been created or there are no accounts yet,
- *  returns FALSE in case of error
- */
-gboolean modest_init_default_account_maybe  (void);
-
-
-G_END_DECLS
-
-#endif /*__MODEST_INIT_H__*/
index efb2828..1453cff 100644 (file)
 #include <tny-list.h>
 #include <tny-simple-list.h>
 
 #include <tny-list.h>
 #include <tny-simple-list.h>
 
+#include <modest-runtime.h>
 #include <modest-defs.h>
 #include <modest-defs.h>
-#include <modest-init.h>
-#include <modest-conf.h>
-#include <modest-account-mgr.h>
 #include <modest-ui.h>
 #include <modest-ui.h>
-#include <modest-debug.h>
 #include <modest-icon-factory.h>
 #include <modest-tny-account-store.h>
 #include <modest-tny-platform-factory.h>
 #include <modest-mail-operation.h>
 
 #include <modest-icon-factory.h>
 #include <modest-tny-account-store.h>
 #include <modest-tny-platform-factory.h>
 #include <modest-mail-operation.h>
 
-#if MODEST_PLATFORM_ID==2 /* maemo */
-#include <libosso.h>
-#endif /* MODEST_PLATFORM==2 */
-
-static gboolean hildon_init (); /* NOP if HILDON is not defined */
-static int start_ui (const gchar* mailto, const gchar *cc,
-                    const gchar *bcc, const gchar* subject, const gchar *body,
-                    TnyAccountStore *account_store);
 
 
+static int start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
+                    const gchar* subject, const gchar *body);
 static int send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
                      const gchar* subject, const gchar *body);
 
 static int send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
                      const gchar* subject, const gchar *body);
 
@@ -66,8 +57,6 @@ int
 main (int argc, char *argv[])
 {
        GOptionContext     *context       = NULL;
 main (int argc, char *argv[])
 {
        GOptionContext     *context       = NULL;
-       TnyPlatformFactory *fact          = NULL;
-       TnyAccountStore    *account_store = NULL;
        
        GError *err = NULL;
        int retval  = MODEST_ERR_NONE;
        
        GError *err = NULL;
        int retval  = MODEST_ERR_NONE;
@@ -95,17 +84,10 @@ main (int argc, char *argv[])
                { NULL, 0, 0, 0, NULL, NULL, NULL }
        };
 
                { NULL, 0, 0, 0, NULL, NULL, NULL }
        };
 
-       bindtextdomain (GETTEXT_PACKAGE, MODEST_LOCALEDIR);
-       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-       textdomain (GETTEXT_PACKAGE);
-
-       modest_debug_g_type_init  ();           
-       modest_debug_logging_init ();
-       
-       g_thread_init (NULL);
-       modest_init_default_account_maybe ();
-
-       gdk_threads_init (); /* hmmm... not really needed if we're not doing  ui*/
+       if (!modest_runtime_init ()) {
+               g_printerr ("modest: cannot init runtime\n");
+               return MODEST_ERR_INIT;
+       }
        
        context = g_option_context_new (NULL);
        g_option_context_add_main_entries (context, options, NULL);
        
        context = g_option_context_new (NULL);
        g_option_context_add_main_entries (context, options, NULL);
@@ -118,23 +100,6 @@ main (int argc, char *argv[])
                goto cleanup;
        }
        g_option_context_free (context);
                goto cleanup;
        }
        g_option_context_free (context);
-
-       /* Get platform factory */      
-       fact = modest_tny_platform_factory_get_instance ();
-
-       if (!modest_init_local_folders ()) {
-               g_printerr ("modest: failed to initialize local folders, exiting\n");
-               retval = MODEST_ERR_INIT;
-               goto cleanup;
-       }
-       
-       /* Get the account store */
-       account_store = tny_platform_factory_new_account_store (fact);
-       if (!account_store) {
-               g_printerr ("modest: could not initialize a ModestTnyAccountStore instance\n");
-               retval = MODEST_ERR_RUN;
-               goto cleanup;
-        }
        
        if (!getenv("DISPLAY"))
                batch = TRUE; 
        
        if (!getenv("DISPLAY"))
                batch = TRUE; 
@@ -144,18 +109,14 @@ main (int argc, char *argv[])
                        g_printerr ("modest: failed to start graphical ui\n");
                        goto cleanup;
                }
                        g_printerr ("modest: failed to start graphical ui\n");
                        goto cleanup;
                }
-               modest_init_header_columns (factory_settings);  
-               retval = start_ui (mailto, cc, bcc, subject, body, account_store);
+               retval = start_ui (mailto, cc, bcc, subject, body);
 
        } else 
                retval = send_mail (mailto, cc, bcc, subject, body);
        
 cleanup:
 
        } else 
                retval = send_mail (mailto, cc, bcc, subject, body);
        
 cleanup:
-       if (fact)
-               g_object_unref (G_OBJECT(fact));
-
-       /* this will clean up account_store as well */
-
+       if (!modest_runtime_uninit ()) 
+               g_printerr ("modest: modest_runtime_uninit failed\n");
 
        return retval;
 }
 
        return retval;
 }
@@ -163,27 +124,17 @@ cleanup:
 
 static int
 start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
 
 static int
 start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
-         const gchar* subject, const gchar *body,
-         TnyAccountStore *account_store)
+         const gchar* subject, const gchar *body)
 {
 {
-       ModestUI *modest_ui;
        ModestWindow *win = NULL;
        ModestWindow *win = NULL;
-       gint retval = 0;
+       ModestUI *modest_ui = NULL;
        
        
-       modest_ui = MODEST_UI(modest_ui_new (account_store));
-       if (!modest_ui) {
-               g_printerr ("modest: failed to initialize ui, exiting\n");
-               retval = MODEST_ERR_UI;
-               goto cleanup;
-       }
-       
-       if (!hildon_init ()) { /* NOP  if hildon is not defined */
-               g_printerr ("modest: failed to initialize hildon, exiting\n");
-               retval = MODEST_ERR_HILDON;
-               goto cleanup;
-       }
+       gint retval = 0;
+
+       modest_ui = modest_ui_new ();
 
        if (mailto||cc||bcc||subject||body) {
 
        if (mailto||cc||bcc||subject||body) {
+               g_warning ("FIXME: implement this");
 /*             ok = modest_ui_new_edit_window (modest_ui, */
 /*                                             mailto,  /\* to *\/ */
 /*                                             cc,      /\* cc *\/ */
 /*             ok = modest_ui_new_edit_window (modest_ui, */
 /*                                             mailto,  /\* to *\/ */
 /*                                             cc,      /\* cc *\/ */
@@ -195,39 +146,13 @@ start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
                win = modest_ui_main_window (modest_ui);
        
        if (win) {
                win = modest_ui_main_window (modest_ui);
        
        if (win) {
-               TnyDevice *device;
-
                gtk_widget_show_all (GTK_WIDGET (win));
                gtk_widget_show_all (GTK_WIDGET (win));
-       
-               /* Go online */
-               device = tny_account_store_get_device (account_store);
-               tny_device_force_online (device);
-               g_object_unref (G_OBJECT (device));
-
                gtk_main();
        }
                gtk_main();
        }
-cleanup:
        if (modest_ui)
        if (modest_ui)
-               g_object_unref (modest_ui);
-
-       return retval;
-}
+               g_object_unref (G_OBJECT(modest_ui));
        
        
-
-static gboolean
-hildon_init ()
-{
-#if MODEST_PLATFORM_ID==2 
-       
-       osso_context_t *osso_context =
-               osso_initialize(PACKAGE, PACKAGE_VERSION,
-                               TRUE, NULL);    
-       if (!osso_context) {
-               g_printerr ("modest: failed to acquire osso context\n");
-               return FALSE;
-       }
-#endif /* MODEST_PLATFORM_ID==2 */
-       return TRUE;
+       return retval;
 }
 
 
 }
 
 
@@ -236,24 +161,16 @@ static int
 send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
           const gchar* subject, const gchar *body)
 {
 send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
           const gchar* subject, const gchar *body)
 {
-       ModestAccountMgr *acc_mgr = NULL;
-       TnyPlatformFactory *fact = NULL;
-       TnyAccountStore *acc_store = NULL;
        ModestMailOperation *mail_operation = NULL;
        ModestMailOperation *mail_operation = NULL;
-
        TnyList *accounts = NULL;
        TnyIterator *iter = NULL;
        TnyTransportAccount *account = NULL;    
        int retval;
 
        TnyList *accounts = NULL;
        TnyIterator *iter = NULL;
        TnyTransportAccount *account = NULL;    
        int retval;
 
-       fact = modest_tny_platform_factory_get_instance ();
-       acc_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(fact));
-       acc_store = tny_platform_factory_new_account_store (fact);      
-
        accounts = TNY_LIST(tny_simple_list_new ());
        accounts = TNY_LIST(tny_simple_list_new ());
-       tny_account_store_get_accounts (TNY_ACCOUNT_STORE(acc_store), accounts,
-                                             TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
+       tny_account_store_get_accounts (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()),
+                                       accounts,
+                                       TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
 
        iter = tny_list_create_iterator(accounts);
        tny_iterator_first (iter);
 
        iter = tny_list_create_iterator(accounts);
        tny_iterator_first (iter);
@@ -264,7 +181,6 @@ send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
        }
 
        account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current(iter));
        }
 
        account = TNY_TRANSPORT_ACCOUNT (tny_iterator_get_current(iter));
-
        mail_operation = modest_mail_operation_new ();
 
        modest_mail_operation_send_new_mail (mail_operation,
        mail_operation = modest_mail_operation_new ();
 
        modest_mail_operation_send_new_mail (mail_operation,
@@ -278,7 +194,6 @@ send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
                goto cleanup;
        } else
                retval = MODEST_ERR_NONE; /* hurray! */
                goto cleanup;
        } else
                retval = MODEST_ERR_NONE; /* hurray! */
-
 cleanup:
        if (iter)
                g_object_unref (G_OBJECT (iter));
 cleanup:
        if (iter)
                g_object_unref (G_OBJECT (iter));
@@ -286,7 +201,6 @@ cleanup:
                g_object_unref (G_OBJECT (accounts));
        if (mail_operation)
                g_object_unref (G_OBJECT (mail_operation));
                g_object_unref (G_OBJECT (accounts));
        if (mail_operation)
                g_object_unref (G_OBJECT (mail_operation));
-
        return retval;
 }
 
        return retval;
 }
 
diff --git a/src/modest-runtime.c b/src/modest-runtime.c
new file mode 100644 (file)
index 0000000..5d96766
--- /dev/null
@@ -0,0 +1,490 @@
+/* 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 <config.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gstdio.h>
+#include <modest-runtime.h>
+#include <modest-defs.h>
+#include <modest-singletons.h>
+#include <widgets/modest-header-view.h>
+#include <widgets/modest-folder-view.h>
+#include <modest-tny-platform-factory.h>
+#include <modest-widget-memory.h>
+#include <modest-widget-memory-priv.h>
+#include <modest-local-folder-info.h>
+#include <modest-account-mgr.h>
+#include <modest-account-mgr-helpers.h>
+
+#if MODEST_PLATFORM_ID==2 /* maemo/hildon */
+#include <libosso.h>
+static gboolean hildon_init (void);
+#endif /* MODEST_PLATFORM_ID==2 */
+
+static gboolean init_header_columns (ModestConf *conf, gboolean overwrite);
+static gboolean init_local_folders  (void);
+static gboolean init_default_account_maybe  (ModestAccountMgr *acc_mgr);
+static void     init_i18n (void);
+static void     debug_g_type_init (void);
+static void     debug_logging_init (void);
+
+static ModestSingletons *_singletons = NULL;
+
+/*
+ * defaults for the column headers
+ */
+
+typedef struct {
+       ModestHeaderViewColumn col;
+       guint                  width;
+} FolderCols;
+
+static const FolderCols INBOX_COLUMNS_DETAILS[] = {
+       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
+       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
+       {MODEST_HEADER_VIEW_COLUMN_FROM,    80},
+       {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
+       {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60},
+       {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
+};
+static const FolderCols INBOX_COLUMNS_TWOLINES[] = {
+       {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
+       {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
+       {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 200}
+};
+
+static const FolderCols OUTBOX_COLUMNS_DETAILS[] = {
+        {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
+        {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
+        {MODEST_HEADER_VIEW_COLUMN_TO,    80},
+        {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
+        {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80},
+        {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
+};
+static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = {
+        {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
+        {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
+        {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,200},
+};
+        
+static const TnyFolderType LOCAL_FOLDERS[] = {
+       TNY_FOLDER_TYPE_OUTBOX,
+       TNY_FOLDER_TYPE_DRAFTS,
+       TNY_FOLDER_TYPE_SENT,
+       TNY_FOLDER_TYPE_ARCHIVE 
+};
+
+
+gboolean
+modest_runtime_init (void)
+{
+       ModestSingletons *my_singletons;
+       
+       if (_singletons) {
+               g_printerr ("modest: modest_runtime_init can only be called once\n");
+               return FALSE;
+       }
+       
+       init_i18n();
+       debug_g_type_init();
+       debug_logging_init();
+
+       g_thread_init(NULL);
+       gdk_threads_init (); 
+
+       my_singletons = modest_singletons_new ();
+       if (!my_singletons) {
+               g_printerr ("modest: failed to initialize singletons\n");
+               return FALSE;
+       }
+
+#if MODEST_PLATFORM_ID==2 
+       if (!hildon_init ()) {
+               modest_runtime_uninit ();
+               g_printerr ("modest: failed to initialize hildon\n");
+               return FALSE;
+       }
+#endif /* MODEST_PLATFORM_ID==2 */
+       
+       if (!init_header_columns(modest_singletons_get_conf (my_singletons),
+                                FALSE)) {
+               modest_runtime_uninit ();
+               g_printerr ("modest: failed to init header columns\n");
+               return FALSE;
+       }
+
+       if (!init_local_folders()) {
+               modest_runtime_uninit ();
+               g_printerr ("modest: failed to init local folders\n");
+               return FALSE;
+       }
+       
+       if (!init_default_account_maybe(modest_singletons_get_account_mgr (my_singletons))) {
+               modest_runtime_uninit ();
+               g_printerr ("modest: failed to init default account\n");
+               return FALSE;
+       }
+
+       /* don't initialize _singletons before all the other init stuff
+        * is done; thus, using any of the singleton stuff before
+        * runtime is fully init'ed  is avoided
+        */
+       _singletons = my_singletons;
+       
+       return TRUE;
+}
+
+
+gboolean
+modest_runtime_uninit (void)
+{
+       if (!_singletons) {
+               g_printerr ("modest: modest_runtime is not initialized\n");
+               return FALSE;
+       }
+       
+       g_object_unref (G_OBJECT(_singletons));
+       _singletons = NULL;
+
+       return TRUE;
+}
+
+
+ModestAccountMgr*
+modest_runtime_get_account_mgr   (void)
+{
+       g_return_val_if_fail (_singletons, NULL);
+       return modest_singletons_get_account_mgr (_singletons);
+}
+
+ModestTnyAccountStore*
+modest_runtime_get_account_store   (void)
+{
+       g_return_val_if_fail (_singletons, NULL);
+       return modest_singletons_get_account_store (_singletons);
+
+}
+
+ModestConf*
+modest_runtime_get_conf (void)
+{
+       g_return_val_if_fail (_singletons, NULL);
+       return modest_singletons_get_conf (_singletons);
+}
+
+
+ModestCacheMgr*
+modest_runtime_get_cache_mgr (void)
+{
+       g_return_val_if_fail (_singletons, NULL);
+       return modest_singletons_get_cache_mgr (_singletons);
+}
+
+
+ModestMailOperationQueue*
+modest_runtime_get_mail_operation_queue (void)
+{
+       g_return_val_if_fail (_singletons, NULL);
+       return modest_singletons_get_mail_operation_queue (_singletons);
+}
+
+
+ModestWidgetFactory*
+modest_runtime_get_widget_factory     (void)
+{
+       g_return_val_if_fail (_singletons, NULL);
+       return modest_singletons_get_widget_factory (_singletons);
+}
+
+
+
+/* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/
+ModestRuntimeDebugFlags
+modest_runtime_get_debug_flags ()
+{
+       GDebugKey debug_keys[] = {
+               { "abort-on-warning", MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING },
+               { "log-actions",      MODEST_RUNTIME_DEBUG_LOG_ACTIONS },
+               { "debug-objects",    MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS },
+               { "debug-signals",    MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS }
+       };
+       const gchar *str;
+       static ModestRuntimeDebugFlags debug_flags = -1;
+
+       if (debug_flags != -1)
+               return debug_flags;
+       
+       str = g_getenv (MODEST_DEBUG);
+       
+       if (str != NULL)
+               debug_flags = g_parse_debug_string (str, debug_keys, G_N_ELEMENTS (debug_keys));
+       else
+               debug_flags = 0;
+       
+       return debug_flags;
+}
+
+
+
+
+
+/* NOTE: the exact details of this format are important, as they
+ * are also used in modest-widget-memory. FIXME: make a shared function
+ * for this with widget-memory
+ */
+static gboolean
+save_header_settings (ModestConf *conf, TnyFolderType type,
+                     ModestHeaderViewStyle style,  const FolderCols* cols,
+                     guint col_num, gboolean overwrite)
+{
+       int i;
+       gchar *key;
+       GString *str;
+
+       g_return_val_if_fail (cols, FALSE);
+
+       key = _modest_widget_memory_get_keyname_with_double_type ("header-view",
+                                                                 type, style,
+                                                                 MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
+       /* if we're not in overwrite mode, only write stuff it
+        * there was nothing before */
+       if (!overwrite &&  modest_conf_key_exists(conf, key, NULL)) {
+               g_free (key);
+               return TRUE;
+       }
+
+       /* the format is necessarily the same as the one in modest-widget-memory */
+       str = g_string_new (NULL);
+       for (i = 0; i != col_num; ++i) 
+               g_string_append_printf (str, "%d:%d ",
+                                       cols[i].col, cols[i].width); 
+
+       modest_conf_set_string (conf, key, str->str, NULL);
+       g_free (key);
+       g_string_free (str, TRUE);
+       
+       return TRUE;
+}
+
+/**
+ * modest_init_header_columns:
+ * @overwrite: write the setting, even if it already exists
+ * 
+ * will set defaults for the columns to show for folder,
+ * if there are no such settings yet (in ModestWidgetMemory)
+ * 
+ * Returns: TRUE if succeeded, FALSE in case of error
+ */
+static gboolean
+init_header_columns (ModestConf *conf, gboolean overwrite)
+{
+       int folder_type;
+       
+       for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
+            folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {          
+               
+               switch (folder_type) {
+               case TNY_FOLDER_TYPE_OUTBOX:
+               case TNY_FOLDER_TYPE_SENT:
+               case TNY_FOLDER_TYPE_DRAFTS:
+               save_header_settings (conf, folder_type,
+                                     MODEST_HEADER_VIEW_STYLE_DETAILS,
+                                     OUTBOX_COLUMNS_DETAILS,
+                                     G_N_ELEMENTS(OUTBOX_COLUMNS_DETAILS),
+                                     overwrite);
+               save_header_settings (conf, folder_type,
+                                     MODEST_HEADER_VIEW_STYLE_TWOLINES,
+                                     OUTBOX_COLUMNS_TWOLINES,
+                                     G_N_ELEMENTS(OUTBOX_COLUMNS_TWOLINES),
+                                     overwrite);
+               break;
+
+               default:
+               save_header_settings (conf, folder_type,
+                                     MODEST_HEADER_VIEW_STYLE_DETAILS,
+                                     INBOX_COLUMNS_DETAILS,
+                                     G_N_ELEMENTS(INBOX_COLUMNS_DETAILS),
+                                     overwrite);
+               save_header_settings (conf, folder_type,
+                                     MODEST_HEADER_VIEW_STYLE_TWOLINES,
+                                     INBOX_COLUMNS_TWOLINES,
+                                     G_N_ELEMENTS(INBOX_COLUMNS_TWOLINES),
+                                     overwrite);
+               };
+       }
+       return TRUE;
+}
+
+/**
+ * init_local_folders:
+ * 
+ * create the Local Folders folder under cache, if they
+ * do not exist yet.
+ * 
+ * Returns: TRUE if the folder were already there, or
+ * they were created, FALSE otherwise
+ */
+static gboolean
+init_local_folders  (void)
+{
+       int i;
+       gchar *maildir_path;
+       static const gchar* maildirs[] = {
+               "cur", "new", "tmp"
+       };
+       
+       maildir_path = modest_local_folder_info_get_maildir_path ();
+
+       for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
+               int j;
+               for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
+                       gchar *dir;
+                       dir = g_build_filename (maildir_path,
+                                               modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
+                                               maildirs[j],
+                                               NULL);
+                       if (g_mkdir_with_parents (dir, 0755) < 0) {
+                               g_printerr ("modest: failed to create %s\n", dir);
+                               g_free (dir);
+                               g_free (maildir_path);
+                               return FALSE;
+                       }
+                       g_free(dir);
+               }
+       }
+       
+       g_free (maildir_path);
+       return TRUE;
+}
+
+
+
+static void
+free_element (gpointer data, gpointer user_data)
+{
+       g_free (data);
+}
+
+
+
+/**
+ * init_default_account_maybe:
+ *
+ * if there are accounts defined, but there is no default account,
+ * it will be defined.
+ * 
+ * Returns: TRUE if there was a default account already,
+ *  or one has been created or there are no accounts yet,
+ *  returns FALSE in case of error
+ */
+static gboolean
+init_default_account_maybe  (ModestAccountMgr *acc_mgr)
+{
+       GSList *all_accounts = NULL;
+       gchar *default_account;
+       gboolean retval = TRUE;
+       
+       all_accounts = modest_account_mgr_account_names (acc_mgr, NULL);
+       if (all_accounts) { /* if there are any accounts, there should be a default one */
+               default_account = 
+                       modest_account_mgr_get_default_account (acc_mgr);
+               if (!default_account) {
+                       gchar *first_account;
+                       g_printerr ("modest: no default account defined\n");
+                       first_account = (gchar*)all_accounts->data;
+                       if ((retval = modest_account_mgr_set_default_account (acc_mgr, first_account)))
+                               g_printerr ("modest: set '%s' as the default account\n",
+                                           first_account);
+                       else
+                               g_printerr ("modest: failed to set '%s' as the default account\n",
+                                           first_account);
+                       g_free (default_account);
+               }
+               g_slist_foreach (all_accounts, free_element, NULL);
+               g_slist_free    (all_accounts);
+       }
+       return retval;
+}
+
+
+
+static void
+debug_g_type_init (void)
+{
+       GTypeDebugFlags gflags;
+       ModestRuntimeDebugFlags mflags;
+       
+       gflags = 0;
+       mflags = modest_runtime_get_debug_flags ();
+
+       if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS)
+               gflags |= G_TYPE_DEBUG_OBJECTS;
+       if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS)
+               gflags |= G_TYPE_DEBUG_SIGNALS;
+       
+       g_type_init_with_debug_flags (gflags);
+
+}
+
+static void
+debug_logging_init (void)
+{
+       ModestRuntimeDebugFlags mflags;
+       mflags = modest_runtime_get_debug_flags ();
+       
+       if (mflags & MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING)
+               g_log_set_always_fatal (G_LOG_LEVEL_ERROR |
+                                       G_LOG_LEVEL_CRITICAL |
+                                       G_LOG_LEVEL_WARNING);
+}
+
+
+static void
+init_i18n (void)
+{
+       bindtextdomain (GETTEXT_PACKAGE, MODEST_LOCALEDIR);
+       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+       textdomain (GETTEXT_PACKAGE);
+
+}
+
+
+#if MODEST_PLATFORM_ID==2 
+static gboolean
+hildon_init (void)
+{
+       osso_context_t *osso_context =
+               osso_initialize(PACKAGE, PACKAGE_VERSION,
+                               TRUE, NULL);    
+       if (!osso_context) {
+               g_printerr ("modest: failed to acquire osso context\n");
+               return FALSE;
+       }
+#endif /* MODEST_PLATFORM_ID==2 */
diff --git a/src/modest-runtime.h b/src/modest-runtime.h
new file mode 100644 (file)
index 0000000..785f48e
--- /dev/null
@@ -0,0 +1,161 @@
+/* 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_RUNTIME_H__
+#define __MODEST_RUNTIME_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <modest-conf.h>
+#include <modest-account-mgr.h>
+#include <modest-cache-mgr.h>
+#include <modest-mail-operation-queue.h>
+#include <modest-tny-account-store.h>
+#include <modest-widget-factory.h>
+
+G_BEGIN_DECLS
+
+#define MODEST_DEBUG "MODEST_DEBUG"
+
+typedef enum {
+       MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING      = 1 << 0,
+       MODEST_RUNTIME_DEBUG_LOG_ACTIONS           = 1 << 1, /* not in use atm */
+       MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS         = 1 << 2, /* for g_type_init */
+       MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS         = 1 << 3, /* for g_type_init */
+} ModestRuntimeDebugFlags;
+
+/**
+ * modest_runtime_init:
+ *
+ * initialize the modest runtime system (which sets up the
+ * environment, instantiates singletons and so on)
+ * modest_runtime_init should only be called once, and
+ * when done with it, modest_runtime_uninit should be called
+ *  
+ * TRUE if this succeeded, FALSE otherwise.
+ */
+gboolean modest_runtime_init (void);
+
+
+/**
+ * modest_runtime_uinit:
+ *
+ * uninitialize the modest runtime system; free all the
+ * resources and so on.
+ *
+ * TRUE if this succeeded, FALSE otherwise
+ */
+gboolean modest_runtime_uninit (void);
+
+
+/**
+ * modest_runtime_get_debug_flags 
+ *
+ * get the debug flags for modest; they are read from the MODEST_DEBUG
+ * environment variable; the flags specified as strings, separated by ':'.
+ * Possible values are:
+ * - "abort-on-warning": abort the program when a gtk/glib/.. warning occurs.
+ * useful when running in debugger
+ * - "log-actions": log user actions (not in use atm)
+ * - "track-object": track the use of (g)objects in the program. this option influences
+ *  g_type_init_with_debug_flags
+ *  - "track-signals": track the use of (g)signals in the program. this option influences
+ *  g_type_init_with_debug_flags
+ *  - "disable-cache": disable caching of strings and pixbuf
+ * if you would want to track signals and log actions, you could do something like:
+ *  MODEST_DEBUG="log-actions:track-signals" ./modest
+ * NOTE that the flags will stay the same during the run of the program, even
+ * if the environment variable changes.
+ * 
+ * Returns: the bitwise OR of the debug flags
+ */
+ModestRuntimeDebugFlags modest_runtime_get_debug_flags  (void) G_GNUC_CONST;
+
+/**
+ * modest_runtime_get_conf:
+ * 
+ * get the ModestConf singleton instance
+ * 
+ * Returns: the ModestConf singleton
+ **/
+ModestConf*         modest_runtime_get_conf   (void);
+
+
+/**
+ * modest_runtime_get_account_mgr:
+ * 
+ * get the ModestAccountMgr singleton instance
+ * 
+ * Returns: the ModestAccountMgr singleton
+ **/
+ModestAccountMgr*         modest_runtime_get_account_mgr   (void);
+
+/**
+ * modest_runtime_get_account_store:
+ * 
+ * get the ModestTnyAccountStore singleton instance
+ *
+ * Returns: the ModestTnyAccountStore singleton
+ **/
+ModestTnyAccountStore*    modest_runtime_get_account_store (void);
+
+
+/**
+ * modest_runtime_get_cache_mgr:
+ * 
+ * get the ModestCacheMgr singleton instance
+ *
+ * Returns: the ModestCacheMgr singleton
+ **/
+ModestCacheMgr*           modest_runtime_get_cache_mgr     (void);
+
+
+/**
+ * modest_runtime_get_mail_operation_queue:
+ * 
+ * get the ModestMailOperationQueue singleton instance
+ *
+ * Returns: the ModestMailOperationQueue singleton
+ **/
+ModestMailOperationQueue* modest_runtime_get_mail_operation_queue (void);
+
+
+/**
+ * modest_runtime_get_widget_factory
+ * 
+ * get the ModestWidgetFactory singleton instance
+ *
+ * Returns: the ModestCacheMgr singleton
+ **/
+ModestWidgetFactory*      modest_runtime_get_widget_factory     (void);
+
+
+G_END_DECLS
+
+#endif /*__MODEST_RUNTIME_H__*/
diff --git a/src/modest-singletons.c b/src/modest-singletons.c
new file mode 100644 (file)
index 0000000..401e6a6
--- /dev/null
@@ -0,0 +1,243 @@
+/* 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-singletons.h"
+
+/* 'private'/'protected' functions */
+static void modest_singletons_class_init (ModestSingletonsClass *klass);
+static void modest_singletons_init       (ModestSingletons *obj);
+static void modest_singletons_finalize   (GObject *obj);
+
+typedef struct _ModestSingletonsPrivate ModestSingletonsPrivate;
+struct _ModestSingletonsPrivate {
+       ModestConf                *conf;
+       ModestAccountMgr          *account_mgr;
+       ModestTnyAccountStore     *account_store;
+       ModestCacheMgr            *cache_mgr;   
+       ModestMailOperationQueue  *mail_op_queue;
+       ModestWidgetFactory       *widget_factory;
+};
+#define MODEST_SINGLETONS_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
+                                               MODEST_TYPE_SINGLETONS, \
+                                               ModestSingletonsPrivate))
+/* globals */
+static GObjectClass *parent_class = NULL;
+
+GType
+modest_singletons_get_type (void)
+{
+       static GType my_type = 0;
+       if (!my_type) {
+               static const GTypeInfo my_info = {
+                       sizeof(ModestSingletonsClass),
+                       NULL,           /* base init */
+                       NULL,           /* base finalize */
+                       (GClassInitFunc) modest_singletons_class_init,
+                       NULL,           /* class finalize */
+                       NULL,           /* class data */
+                       sizeof(ModestSingletons),
+                       1,              /* n_preallocs */
+                       (GInstanceInitFunc) modest_singletons_init,
+                       NULL
+               };
+               my_type = g_type_register_static (G_TYPE_OBJECT,
+                                                 "ModestSingletons",
+                                                 &my_info, 0);
+       }
+       return my_type;
+}
+
+static void
+modest_singletons_class_init (ModestSingletonsClass *klass)
+{
+       GObjectClass *gobject_class;
+       gobject_class = (GObjectClass*) klass;
+
+       parent_class            = g_type_class_peek_parent (klass);
+       gobject_class->finalize = modest_singletons_finalize;
+
+       g_type_class_add_private (gobject_class, sizeof(ModestSingletonsPrivate));
+}
+
+static void
+modest_singletons_init (ModestSingletons *obj)
+{
+       ModestSingletonsPrivate *priv;
+       priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
+
+       priv->conf           = NULL;
+       priv->account_mgr    = NULL;
+       priv->account_store  = NULL;
+       priv->cache_mgr      = NULL;
+       priv->mail_op_queue  = NULL;
+       priv->widget_factory = NULL;
+       
+       priv->conf           = modest_conf_new ();
+       if (!priv->conf) {
+               g_printerr ("modest: cannot create modest conf instance\n");
+               return;
+       }
+
+       priv->account_mgr    = modest_account_mgr_new (priv->conf);
+       if (!priv->account_mgr) {
+               g_printerr ("modest: cannot create modest account mgr instance\n");
+               return;
+       }
+
+       priv->account_store  = modest_tny_account_store_new (priv->account_mgr);
+       if (!priv->account_store) {
+               g_printerr ("modest: cannot create modest tny account store instance\n");
+               return;
+       }
+
+       priv->cache_mgr     = modest_cache_mgr_new ();
+       if (!priv->cache_mgr) {
+               g_printerr ("modest: cannot create modest cache mgr instance\n");
+               return;
+       }
+
+       priv->mail_op_queue  = modest_mail_operation_queue_new ();
+       if (!priv->mail_op_queue) {
+               g_printerr ("modest: cannot create modest mail operation queue instance\n");
+               return;
+       }
+
+       /* don't initialize widget_factory here, but do it lazily, so we can
+        * instaniatie modest-singletons before gtk_init
+        */
+}
+
+static void
+modest_singletons_finalize (GObject *obj)
+{
+       ModestSingletonsPrivate *priv;
+       priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
+
+       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;
+       }
+       if (priv->account_store) {
+               g_object_unref (G_OBJECT(priv->account_store));
+               priv->account_store = NULL;
+       }
+
+       if (priv->cache_mgr) {
+               g_object_unref (G_OBJECT(priv->cache_mgr));
+               priv->cache_mgr = NULL;
+       }
+
+       if (priv->widget_factory) {
+               g_object_unref (G_OBJECT(priv->widget_factory));
+               priv->widget_factory = NULL;
+       }
+       
+       G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+ModestSingletons*
+modest_singletons_new (void)
+{
+       ModestSingletonsPrivate *priv;
+       ModestSingletons *self;
+       
+       self = MODEST_SINGLETONS(g_object_new(MODEST_TYPE_SINGLETONS, NULL));
+       priv = MODEST_SINGLETONS_GET_PRIVATE(self);
+
+       /* widget_factory will still be NULL, as it is initialized lazily */
+       if (!(priv->conf && priv->account_mgr && priv->account_store &&
+             priv->cache_mgr && priv->mail_op_queue)) {
+               g_printerr ("modest: failed to create singletons instance\n");
+               g_object_unref (G_OBJECT(self));
+               self = NULL;
+       }
+       
+       return self;
+}
+
+
+ModestConf*
+modest_singletons_get_conf (ModestSingletons *self)
+{
+       g_return_val_if_fail (self, NULL);
+       return MODEST_SINGLETONS_GET_PRIVATE(self)->conf;
+}
+
+ModestAccountMgr*
+modest_singletons_get_account_mgr (ModestSingletons *self)
+{
+       g_return_val_if_fail (self, NULL);
+       return MODEST_SINGLETONS_GET_PRIVATE(self)->account_mgr;
+}
+
+ModestTnyAccountStore*
+modest_singletons_get_account_store (ModestSingletons *self)
+{
+       g_return_val_if_fail (self, NULL);
+       return MODEST_SINGLETONS_GET_PRIVATE(self)->account_store;
+}
+
+ModestCacheMgr*
+modest_singletons_get_cache_mgr (ModestSingletons *self)
+{
+       g_return_val_if_fail (self, NULL);
+       return MODEST_SINGLETONS_GET_PRIVATE(self)->cache_mgr;
+}
+
+
+ModestMailOperationQueue*
+modest_singletons_get_mail_operation_queue (ModestSingletons *self)
+{
+       g_return_val_if_fail (self, NULL);
+       return MODEST_SINGLETONS_GET_PRIVATE(self)->mail_op_queue;
+}
+
+
+ModestWidgetFactory*
+modest_singletons_get_widget_factory (ModestSingletons *self)
+{
+       ModestSingletonsPrivate *priv;
+
+       g_return_val_if_fail (self, NULL);
+
+       priv = MODEST_SINGLETONS_GET_PRIVATE(self);
+
+       if (G_UNLIKELY(!priv->widget_factory))  
+               priv->widget_factory = modest_widget_factory_new (priv->account_store);
+       if (G_UNLIKELY(!priv->widget_factory)) {
+               g_printerr ("modest: cannot create modest widget factory instance\n");
+               return NULL;
+       }
+       return priv->widget_factory;
+}
diff --git a/src/modest-singletons.h b/src/modest-singletons.h
new file mode 100644 (file)
index 0000000..9dcdec1
--- /dev/null
@@ -0,0 +1,165 @@
+/* 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_SINGLETONS_H__
+#define __MODEST_SINGLETONS_H__
+
+#include <config.h>
+
+#include <glib-object.h>
+#include <modest-conf.h>
+#include <modest-account-mgr.h>
+#include <modest-tny-account-store.h>
+#include <modest-mail-operation-queue.h>
+#include <modest-cache-mgr.h>
+#include <modest-widget-factory.h>
+
+G_BEGIN_DECLS
+
+/* convenience macros */
+#define MODEST_TYPE_SINGLETONS             (modest_singletons_get_type())
+#define MODEST_SINGLETONS(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_SINGLETONS,ModestSingletons))
+#define MODEST_SINGLETONS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_SINGLETONS,GObject))
+#define MODEST_IS_SINGLETONS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_SINGLETONS))
+#define MODEST_IS_SINGLETONS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_SINGLETONS))
+#define MODEST_SINGLETONS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_SINGLETONS,ModestSingletonsClass))
+
+typedef struct _ModestSingletons      ModestSingletons;
+typedef struct _ModestSingletonsClass ModestSingletonsClass;
+
+struct _ModestSingletons {
+        GObject parent;
+};
+
+struct _ModestSingletonsClass {
+       GObjectClass parent_class;
+};
+
+
+/**
+ * modest_singletons_get_type:
+ * 
+ * get the GType for ModestSingletons
+ *  
+ * Returns: the GType
+ */
+GType        modest_singletons_get_type    (void) G_GNUC_CONST;
+
+
+/**
+ * modest_singletons_new:
+ * 
+ * create a new ModestSingletons instance;
+ * don't use this function directly, use the modest-runtime
+ * functions instead.
+ * 
+ * Returns: a new ModestSingletons instance, or NULL in case
+ * of any error
+ */
+ModestSingletons*    modest_singletons_new         (void);
+
+
+/**
+ * modest_singletons_get_conf:
+ * 
+ * get the ModestConf singleton instance
+ * don't use this function directly, use the modest-runtime
+ * functions instead.
+ *
+ * Returns: the ModestConf singleton
+ **/
+ModestConf*               modest_singletons_get_conf          (ModestSingletons *self);
+
+
+/**
+ * modest_singletons_get_account_mgr:
+ * 
+ * get the ModestAccountMgr singleton instance
+ * don't use this function directly, use the modest-runtime
+ * functions instead.
+ * 
+ * Returns: the ModestAccountMgr singleton
+ **/
+ModestAccountMgr*         modest_singletons_get_account_mgr   (ModestSingletons *self);
+
+
+/**
+ * modest_singletons_get_account_store:
+ * 
+ * get the ModestTnyAccountStore singleton instance
+ * don't use this function directly, use the modest-runtime
+ * functions instead.
+ *
+ * Returns: the ModestTnyAccountStore singleton
+ **/
+ModestTnyAccountStore*    modest_singletons_get_account_store (ModestSingletons *self);
+
+
+/**
+ * modest_singletons_get_cache_mgr:
+ * 
+ * get the ModestCacheMgr singleton instance
+ * don't use this function directly, use the modest-runtime
+ * functions instead.
+ *
+ * Returns: the ModestCacheMgr singleton
+ **/
+ModestCacheMgr*           modest_singletons_get_cache_mgr     (ModestSingletons *self);
+
+
+/**
+ * modest_singletons_get_mail_operation_queue:
+ * 
+ * get the ModestMailOperationQueue singleton instance
+ * don't use this function directly, use the modest-runtime
+ * functions instead.
+ *
+ * Returns: the ModestMailOperationQueue singleton
+ **/
+ModestMailOperationQueue* modest_singletons_get_mail_operation_queue (ModestSingletons *self);
+
+
+
+
+/**
+ * modest_singletons_get_widget_factory:
+ * 
+ * get the ModestWidgetFactory singleton instance
+ * don't use this function directly, use the modest-runtime
+ * functions instead.
+ *
+ * Returns: the ModestWidgetFactory singleton
+ **/
+ModestWidgetFactory* modest_singletons_get_widget_factory (ModestSingletons *self);
+
+
+G_END_DECLS
+
+#endif /* __MODEST_SINGLETONS_H__ */
+
index e5712ed..6f84320 100644 (file)
@@ -34,7 +34,8 @@
 #include <glib/gi18n.h>
 #include <regex.h>
 #include <modest-tny-platform-factory.h>
 #include <glib/gi18n.h>
 #include <regex.h>
 #include <modest-tny-platform-factory.h>
-#include "modest-text-utils.h"
+#include <modest-text-utils.h>
+#include <modest-runtime.h>
 
 
 #ifdef HAVE_CONFIG_H
 
 
 #ifdef HAVE_CONFIG_H
@@ -766,15 +767,7 @@ modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insens
 static GHashTable*
 get_display_date_cache (void)
 {
 static GHashTable*
 get_display_date_cache (void)
 {
-       TnyPlatformFactory *fakt;
-       ModestCacheMgr     *cache_mgr;
-
-       fakt = modest_tny_platform_factory_get_instance ();
-       
-       cache_mgr =  modest_tny_platform_factory_get_cache_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(fakt));
-       
-       return modest_cache_mgr_get_cache (cache_mgr,
+       return modest_cache_mgr_get_cache (modest_runtime_get_cache_mgr (),
                                           MODEST_CACHE_MGR_CACHE_TYPE_DATE_STRING);
 }
 
                                           MODEST_CACHE_MGR_CACHE_TYPE_DATE_STRING);
 }
 
index 4ecca3a..784d77a 100644 (file)
@@ -74,9 +74,9 @@ struct _ModestTnyAccountStorePrivate {
        
        GHashTable         *password_hash;
        TnyDevice          *device;
        
        GHashTable         *password_hash;
        TnyDevice          *device;
-       TnyPlatformFactory *platform_fact;
        TnySessionCamel    *tny_session_camel;
 
        TnySessionCamel    *tny_session_camel;
 
+       ModestAccountMgr   *account_mgr;
        TnyAccount         *local_folders;
 };
 
        TnyAccount         *local_folders;
 };
 
@@ -160,8 +160,7 @@ modest_tny_account_store_instance_init (ModestTnyAccountStore *obj)
                MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
 
        priv->cache_dir              = NULL;
                MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
 
        priv->cache_dir              = NULL;
-       
-       priv->platform_fact          = NULL;
+       priv->account_mgr            = NULL;
        priv->tny_session_camel      = NULL;
        priv->device                 = NULL;
        
        priv->tny_session_camel      = NULL;
        priv->device                 = NULL;
        
@@ -190,17 +189,15 @@ get_local_folders_account (ModestTnyAccountStore *self)
                g_printerr ("modest: cannot create account for local folders");
                return NULL;
        }
                g_printerr ("modest: cannot create account for local folders");
                return NULL;
        }
-
-       maildir = modest_local_folder_info_get_maildir_path ();
        
        
+       tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),priv->tny_session_camel);
+       
+       maildir = modest_local_folder_info_get_maildir_path ();
        url = camel_url_new ("maildir:", NULL);
        camel_url_set_path (url, maildir);
        url = camel_url_new ("maildir:", NULL);
        camel_url_set_path (url, maildir);
-
        url_string = camel_url_to_string (url, 0);
        url_string = camel_url_to_string (url, 0);
-       tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
        
        
-       tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),
-                                      priv->tny_session_camel);
+       tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
        tny_account_set_name (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME); 
        tny_account_set_id (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME); 
        
        tny_account_set_name (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME); 
        tny_account_set_id (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_NAME); 
        
@@ -239,7 +236,8 @@ on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean se
 static ModestTnyAccountStore*
 get_account_store_for_account (TnyAccount *account)
 {
 static ModestTnyAccountStore*
 get_account_store_for_account (TnyAccount *account)
 {
-       return MODEST_TNY_ACCOUNT_STORE(g_object_get_data (G_OBJECT(account), "account_store"));
+       return MODEST_TNY_ACCOUNT_STORE(g_object_get_data (G_OBJECT(account),
+                                                          "account_store"));
 }
 
 
 }
 
 
@@ -310,7 +308,6 @@ static gchar*
 get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 {
        const gchar *key;
 get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 {
        const gchar *key;
-       ModestAccountMgr *account_mgr;
        const TnyAccountStore *account_store;
        ModestTnyAccountStore *self;
        ModestTnyAccountStorePrivate *priv;
        const TnyAccountStore *account_store;
        ModestTnyAccountStore *self;
        ModestTnyAccountStorePrivate *priv;
@@ -321,13 +318,10 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
        
        key           = tny_account_get_id (account);
        account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
        
        key           = tny_account_get_id (account);
        account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
-
+       
        self = MODEST_TNY_ACCOUNT_STORE (account_store);
         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
        
        self = MODEST_TNY_ACCOUNT_STORE (account_store);
         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
        
-       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(priv->platform_fact));
-       
        /* is it in the hash? if it's already there, it must be wrong... */
        pwd_ptr = (gpointer)&pwd; /* pwd_ptr so the compiler does not complained about
                                   * type-punned ptrs...*/
        /* is it in the hash? if it's already there, it must be wrong... */
        pwd_ptr = (gpointer)&pwd; /* pwd_ptr so the compiler does not complained about
                                   * type-punned ptrs...*/
@@ -338,7 +332,7 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 
        /* if the password is not already there, try ModestConf */
        if (!already_asked) {
 
        /* if the password is not already there, try ModestConf */
        if (!already_asked) {
-               pwd  = modest_account_mgr_get_string (account_mgr,
+               pwd  = modest_account_mgr_get_string (priv->account_mgr,
                                                      key, MODEST_ACCOUNT_PASSWORD,
                                                      TRUE, NULL);
                g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup (pwd));
                                                      key, MODEST_ACCOUNT_PASSWORD,
                                                      TRUE, NULL);
                g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup (pwd));
@@ -356,7 +350,7 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 
                if (!*cancel) {
                        if (remember)
 
                if (!*cancel) {
                        if (remember)
-                               modest_account_mgr_set_string (account_mgr,
+                               modest_account_mgr_set_string (priv->account_mgr,
                                                               key, MODEST_ACCOUNT_PASSWORD,
                                                               pwd,
                                                               TRUE, NULL);
                                                               key, MODEST_ACCOUNT_PASSWORD,
                                                               pwd,
                                                               TRUE, NULL);
@@ -378,14 +372,13 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 
 
 static void
 
 
 static void
-forget_password (TnyAccount *account) {
-
+forget_password (TnyAccount *account)
+{
        ModestTnyAccountStore *self;
        ModestTnyAccountStorePrivate *priv;
        const TnyAccountStore *account_store;
        gchar *pwd;
        const gchar *key;
        ModestTnyAccountStore *self;
        ModestTnyAccountStorePrivate *priv;
        const TnyAccountStore *account_store;
        gchar *pwd;
        const gchar *key;
-       ModestAccountMgr *account_mgr;
        
         account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
        self = MODEST_TNY_ACCOUNT_STORE (account_store);
        
         account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
        self = MODEST_TNY_ACCOUNT_STORE (account_store);
@@ -400,11 +393,8 @@ forget_password (TnyAccount *account) {
                g_hash_table_insert (priv->password_hash, g_strdup (key), NULL);
        }
 
                g_hash_table_insert (priv->password_hash, g_strdup (key), NULL);
        }
 
-       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(priv->platform_fact));
-
        /* Remove from configuration system */
        /* Remove from configuration system */
-       modest_account_mgr_unset (account_mgr,
+       modest_account_mgr_unset (priv->account_mgr,
                                  key, MODEST_ACCOUNT_PASSWORD,
                                  TRUE, NULL);
 }
                                  key, MODEST_ACCOUNT_PASSWORD,
                                  TRUE, NULL);
 }
@@ -522,6 +512,11 @@ modest_tny_account_store_finalize (GObject *obj)
                g_hash_table_destroy (priv->password_hash);
                priv->password_hash = NULL;
        }
                g_hash_table_destroy (priv->password_hash);
                priv->password_hash = NULL;
        }
+
+       if (priv->account_mgr) {
+               g_object_unref (priv->account_mgr);
+               priv->account_mgr = NULL;
+       }
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -532,21 +527,15 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
 
        GObject *obj;
        ModestTnyAccountStorePrivate *priv;
 
        GObject *obj;
        ModestTnyAccountStorePrivate *priv;
-       TnyPlatformFactory *pfact;
        
        g_return_val_if_fail (account_mgr, NULL);
 
        obj  = G_OBJECT(g_object_new(MODEST_TYPE_TNY_ACCOUNT_STORE, NULL));
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
 
        
        g_return_val_if_fail (account_mgr, NULL);
 
        obj  = G_OBJECT(g_object_new(MODEST_TYPE_TNY_ACCOUNT_STORE, NULL));
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
 
-       pfact = TNY_PLATFORM_FACTORY (modest_tny_platform_factory_get_instance());
-       if (!pfact) {
-               g_printerr ("modest: cannot get platform factory instance\n");
-               g_object_unref (obj);
-               return NULL;
-       } else
-               priv->platform_fact = pfact;
-
+       priv->account_mgr = account_mgr;
+       g_object_ref (G_OBJECT(priv->account_mgr));
+       
        /* The session needs the platform factory */
        priv->tny_session_camel = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
        if (!priv->tny_session_camel) {
        /* The session needs the platform factory */
        priv->tny_session_camel = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
        if (!priv->tny_session_camel) {
@@ -554,8 +543,8 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
                g_object_unref (obj);
                return NULL;
        }
                g_object_unref (obj);
                return NULL;
        }
+       
        tny_session_camel_set_ui_locker (priv->tny_session_camel, tny_gtk_lockable_new ());
        tny_session_camel_set_ui_locker (priv->tny_session_camel, tny_gtk_lockable_new ());
-       priv->local_folders = get_local_folders_account (MODEST_TNY_ACCOUNT_STORE(obj));
        /* FIXME: unref this in the end? */
        
        /* Connect signals */
        /* FIXME: unref this in the end? */
        
        /* Connect signals */
@@ -626,15 +615,12 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *account_store, TnyList
        ModestTnyAccountStore        *self;
        ModestTnyAccountStorePrivate *priv;
        GSList                       *accounts, *cursor;
        ModestTnyAccountStore        *self;
        ModestTnyAccountStorePrivate *priv;
        GSList                       *accounts, *cursor;
-       ModestAccountMgr             *account_mgr; 
        
        g_return_if_fail (account_store);
        g_return_if_fail (TNY_IS_LIST(list));
 
        self        = MODEST_TNY_ACCOUNT_STORE(account_store);
        priv        = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
        
        g_return_if_fail (account_store);
        g_return_if_fail (TNY_IS_LIST(list));
 
        self        = MODEST_TNY_ACCOUNT_STORE(account_store);
        priv        = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(priv->platform_fact));
        
        if (type == TNY_ACCOUNT_STORE_BOTH) {
                modest_tny_account_store_get_accounts (account_store, list,
        
        if (type == TNY_ACCOUNT_STORE_BOTH) {
                modest_tny_account_store_get_accounts (account_store, list,
@@ -643,11 +629,11 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *account_store, TnyList
                                                       TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
        }
 
                                                       TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
        }
 
-       accounts = modest_account_mgr_account_names (account_mgr, NULL); 
+       accounts = modest_account_mgr_account_names (priv->account_mgr, NULL); 
        for (cursor = accounts; cursor; cursor = cursor->next) {
                TnyAccount *tny_account = NULL;
                ModestAccountData *account_data =
        for (cursor = accounts; cursor; cursor = cursor->next) {
                TnyAccount *tny_account = NULL;
                ModestAccountData *account_data =
-                       modest_account_mgr_get_account_data (account_mgr, 
+                       modest_account_mgr_get_account_data (priv->account_mgr, 
                                                             (gchar*)cursor->data);
                if (account_data && account_data->enabled) {
                        tny_account = get_tny_account_from_account (self, account_data, type);
                                                             (gchar*)cursor->data);
                if (account_data && account_data->enabled) {
                        tny_account = get_tny_account_from_account (self, account_data, type);
@@ -655,13 +641,15 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *account_store, TnyList
                                tny_list_prepend (list, G_OBJECT(tny_account));
                }
                g_free (cursor->data);
                                tny_list_prepend (list, G_OBJECT(tny_account));
                }
                g_free (cursor->data);
-               modest_account_mgr_free_account_data (account_mgr, account_data);
+               modest_account_mgr_free_account_data (priv->account_mgr, account_data);
        }
        g_slist_free (accounts);
 
        /* also, add the local folder pseudo-account */
        if (type != TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) {
                if (!priv->local_folders)
        }
        g_slist_free (accounts);
 
        /* also, add the local folder pseudo-account */
        if (type != TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) {
                if (!priv->local_folders)
+                       priv->local_folders = get_local_folders_account (self);
+               if (!priv->local_folders)
                        g_printerr ("modest: no local folders account\n");
                else
                        tny_list_prepend (list, G_OBJECT(priv->local_folders));
                        g_printerr ("modest: no local folders account\n");
                else
                        tny_list_prepend (list, G_OBJECT(priv->local_folders));
@@ -695,7 +683,8 @@ modest_tny_account_store_get_device (TnyAccountStore *self)
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
 
        if (!priv->device) 
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
 
        if (!priv->device) 
-               priv->device = tny_platform_factory_new_device (priv->platform_fact);
+               priv->device = tny_platform_factory_new_device
+                       (modest_tny_platform_factory_get_instance());
        
        return g_object_ref (G_OBJECT(priv->device));
 }
        
        return g_object_ref (G_OBJECT(priv->device));
 }
@@ -751,7 +740,6 @@ tny_account_store_get_session  (TnyAccountStore *self)
 }
 
 
 }
 
 
-
 TnyAccount*
 modest_tny_account_store_get_local_folders_account    (ModestTnyAccountStore *self)
 {
 TnyAccount*
 modest_tny_account_store_get_local_folders_account    (ModestTnyAccountStore *self)
 {
@@ -760,22 +748,3 @@ modest_tny_account_store_get_local_folders_account    (ModestTnyAccountStore *se
        return MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self)->local_folders;
 }
 
        return MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self)->local_folders;
 }
 
-
-/* for now, ignore the account ===> the special folders are the same,
- * local folders for all accounts
- * this might change, ie, IMAP might have server-side sent-items
- */
-TnyFolder *
-modest_tny_account_store_get_special_folder (ModestTnyAccountStore*self, TnyAccount *account,
-                                            TnyFolderType special_type)
-{
-       g_return_val_if_fail (self, NULL);
-       g_return_val_if_fail (account, NULL);
-       g_return_val_if_fail (0 <= special_type && special_type < TNY_FOLDER_TYPE_NUM,
-                             NULL);
-       //TnyAccount *local_account =
-       //      tny_account_store_get_local_folders_account (self);
-
-       /* FIXME: implement this */
-       return NULL;
-}
index 902e58b..5bc3723 100644 (file)
@@ -99,8 +99,6 @@ ModestTnyAccountStore*    modest_tny_account_store_new (ModestAccountMgr *accoun
  */
 TnySessionCamel*    tny_account_store_get_session    (TnyAccountStore *self);
 
  */
 TnySessionCamel*    tny_account_store_get_session    (TnyAccountStore *self);
 
-
-
 /**
  * tny_account_store_get_local_folders_account 
  * @self: a ModestTnyAccountStore instance
 /**
  * tny_account_store_get_local_folders_account 
  * @self: a ModestTnyAccountStore instance
@@ -111,20 +109,6 @@ TnySessionCamel*    tny_account_store_get_session    (TnyAccountStore *self);
  */
 TnyAccount*    modest_tny_account_store_get_local_folders_account    (ModestTnyAccountStore *self);
 
  */
 TnyAccount*    modest_tny_account_store_get_local_folders_account    (ModestTnyAccountStore *self);
 
-
-/**
- * tny_account_store_get_special_folder
- * @self: a ModestTnyAccountStore instance
- * @type: some tny folder type
- * 
- * get the special (Inbox,Outbox,Sent,Draft etc.) folder for this account
- *
- * Returns: the tny folder corresponding to this special folder, or NULL
- */
-TnyFolder*    modest_tny_account_store_get_special_folder   (ModestTnyAccountStore *self,
-                                                            TnyAccount *account,
-                                                            TnyFolderType special_type);
-
 G_END_DECLS
 
 #endif /* __MODEST_TNY_ACCOUNT_STORE_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_TNY_ACCOUNT_STORE_H__ */
index c26922d..fb04340 100644 (file)
@@ -82,6 +82,7 @@ TnyFolderType  modest_tny_folder_guess_folder_type_from_name   (const gchar *fol
  */
 gboolean modest_tny_folder_is_local_folder   (const TnyFolder *folder);
 
  */
 gboolean modest_tny_folder_is_local_folder   (const TnyFolder *folder);
 
+
 /**
  * modest_tny_folder_get_local_folder_type:
  * @folder: a valid tnymail folder
 /**
  * modest_tny_folder_get_local_folder_type:
  * @folder: a valid tnymail folder
index 4b6cb25..1ca0853 100644 (file)
@@ -30,6 +30,7 @@
 /* modest-tny-platform-factory.c */
 #include <config.h>
 
 /* modest-tny-platform-factory.c */
 #include <config.h>
 
+#include <modest-runtime.h>
 #include <tny-camel-header.h>
 #include <tny-camel-mime-part.h>
 #include <tny-camel-msg.h>
 #include <tny-camel-header.h>
 #include <tny-camel-mime-part.h>
 #include <tny-camel-msg.h>
@@ -68,13 +69,7 @@ enum {
 };
 
 typedef struct _ModestTnyPlatformFactoryPrivate ModestTnyPlatformFactoryPrivate;
 };
 
 typedef struct _ModestTnyPlatformFactoryPrivate ModestTnyPlatformFactoryPrivate;
-struct _ModestTnyPlatformFactoryPrivate {
-       ModestTnyAccountStore    *account_store;
-       ModestConf               *conf;
-       ModestAccountMgr         *account_mgr;
-       ModestMailOperationQueue *mail_op_queue;
-       ModestCacheMgr           *cache_mgr;
-};
+struct _ModestTnyPlatformFactoryPrivate {};
 
 #define MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                          MODEST_TYPE_TNY_PLATFORM_FACTORY, \
 
 #define MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                          MODEST_TYPE_TNY_PLATFORM_FACTORY, \
@@ -83,9 +78,6 @@ struct _ModestTnyPlatformFactoryPrivate {
 static GObjectClass *parent_class = NULL;
 static ModestTnyPlatformFactory *singleton = NULL;
 
 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)
 {
 GType
 modest_tny_platform_factory_get_type (void)
 {
@@ -137,14 +129,7 @@ modest_tny_platform_factory_class_init (ModestTnyPlatformFactoryClass *klass)
 static void
 modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj)
 {
 static void
 modest_tny_platform_factory_init (ModestTnyPlatformFactory *obj)
 {
-       ModestTnyPlatformFactoryPrivate *priv;
-       priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(obj);
-
-       priv->account_mgr   = NULL;
-       priv->conf          = NULL;
-       priv->account_store = NULL;
-       priv->mail_op_queue = NULL;
-       priv->cache_mgr     = NULL;
+       /* empty */
 }
 
 static GObject*
 }
 
 static GObject*
@@ -169,25 +154,6 @@ modest_tny_platform_factory_constructor (GType type, guint n_construct_params,
 static void
 modest_tny_platform_factory_finalize (GObject *obj)
 {
 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 (G_OBJECT(priv->account_mgr));
-
-       if (priv->conf)
-               g_object_unref (G_OBJECT(priv->conf));
-
-       if (priv->account_store)
-               g_object_unref (G_OBJECT(priv->account_store));
-
-       if (priv->mail_op_queue)
-               g_object_unref (G_OBJECT(priv->mail_op_queue));
-
-       if (priv->cache_mgr)
-               g_object_unref (G_OBJECT(priv->cache_mgr));
-       
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
@@ -217,18 +183,8 @@ modest_tny_platform_factory_get_instance (void)
 static TnyAccountStore *
 modest_tny_platform_factory_new_account_store (TnyPlatformFactory *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_account_mgr_instance (MODEST_TNY_PLATFORM_FACTORY (self));
-
-               priv->account_store = modest_tny_account_store_new (priv->account_mgr);
-       }
-
-       return TNY_ACCOUNT_STORE (priv->account_store);
+       return TNY_ACCOUNT_STORE(modest_tny_account_store_new
+                                (modest_runtime_get_account_mgr()));
 }
 
 static TnyDevice *
 }
 
 static TnyDevice *
@@ -270,69 +226,3 @@ modest_tny_platform_factory_new_header (TnyPlatformFactory *self)
 {
        return tny_camel_header_new ();
 }
 {
        return tny_camel_header_new ();
 }
-
-
-ModestAccountMgr *
-modest_tny_platform_factory_get_account_mgr_instance (ModestTnyPlatformFactory *fact)
-{
-       ModestTnyPlatformFactoryPrivate *priv;
-
-       g_return_val_if_fail (fact, NULL);
-       
-       priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
-
-       if (!priv->account_mgr) {
-               if (!priv->conf)
-                       modest_tny_platform_factory_get_conf_instance (fact);
-               priv->account_mgr = modest_account_mgr_new (priv->conf);
-       }
-
-       return priv->account_mgr;
-}
-
-ModestConf *
-modest_tny_platform_factory_get_conf_instance (ModestTnyPlatformFactory *fact)
-{
-       ModestTnyPlatformFactoryPrivate *priv;
-       
-       g_return_val_if_fail (fact, NULL);
-       
-       priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
-
-       if (!priv->conf)
-               priv->conf = modest_conf_new ();
-
-       return priv->conf;
-}
-
-ModestMailOperationQueue*   
-modest_tny_platform_factory_get_mail_operation_queue_instance (ModestTnyPlatformFactory *fact)
-{
-       ModestTnyPlatformFactoryPrivate *priv;
-
-       g_return_val_if_fail (fact, NULL);
-       
-       priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
-
-       if (!priv->mail_op_queue)
-               priv->mail_op_queue = modest_mail_operation_queue_new ();
-
-       return priv->mail_op_queue;
-}
-
-
-
-ModestCacheMgr*
-modest_tny_platform_factory_get_cache_mgr_instance (ModestTnyPlatformFactory *fact)
-{
-       ModestTnyPlatformFactoryPrivate *priv;
-
-       g_return_val_if_fail (fact, NULL);
-       
-       priv = MODEST_TNY_PLATFORM_FACTORY_GET_PRIVATE(fact);
-
-       if (!priv->cache_mgr)
-               priv->cache_mgr = modest_cache_mgr_new ();
-               
-       return priv->cache_mgr;
-}
index 6fbe553..6932503 100644 (file)
 #define __MODEST_TNY_PLATFORM_FACTORY_H__
 
 #include <glib-object.h>
 #define __MODEST_TNY_PLATFORM_FACTORY_H__
 
 #include <glib-object.h>
-
 #include <tny-platform-factory.h>
 #include <tny-platform-factory.h>
-#include <modest-account-mgr.h>
-#include <modest-conf.h>
-#include <modest-mail-operation-queue.h>
-#include <modest-cache-mgr.h>
 
 G_BEGIN_DECLS
 
 
 G_BEGIN_DECLS
 
@@ -61,7 +56,14 @@ struct _ModestTnyPlatformFactoryClass {
        GObjectClass parent_class;
 };
 
        GObjectClass parent_class;
 };
 
-/* member functions */
+
+/**
+ * modest_tny_platform_factory_get_type:
+ * 
+ * get the GType for #ModestTnyPlatformFactory
+ *  
+ * Returns: the GType for #ModestTnyPlatformFactory
+ */
 GType        modest_tny_platform_factory_get_type    (void) G_GNUC_CONST;
 
 /**
 GType        modest_tny_platform_factory_get_type    (void) G_GNUC_CONST;
 
 /**
@@ -75,58 +77,6 @@ GType        modest_tny_platform_factory_get_type    (void) G_GNUC_CONST;
  **/
 TnyPlatformFactory*    modest_tny_platform_factory_get_instance         (void);
 
  **/
 TnyPlatformFactory*    modest_tny_platform_factory_get_instance         (void);
 
-/**
- * modest_tny_platform_factory_get_account_mgr_instance:
- * @fact: the #TnyPlatformFactory that holds the #ModestAccountMgr instance
- * 
- * Gets a new instance of a #ModestAccountMgr if it is the first call
- * to the function, or the current instantiated one otherwise. This
- * object is supposed to be a singleton
- * 
- * Returns: an instance of a #ModestAccountMgr
- **/
-ModestAccountMgr*  modest_tny_platform_factory_get_account_mgr_instance (ModestTnyPlatformFactory *fact);
-
-/**
- * modest_tny_platform_factory_get_conf_instance:
- * @fact: the #TnyPlatformFactory that holds the #ModestConf instance
- * 
- * Gets a new instance of a #ModestConf if it is the first call to the
- * function, or the current instantiated one otherwise. This object is
- * supposed to be a singleton
- * 
- * Returns: an instance of a #ModestConf
- **/
-ModestConf*     modest_tny_platform_factory_get_conf_instance (ModestTnyPlatformFactory *fact);
-
-/**
- * modest_tny_platform_factory_get_mail_operation_queue_instance:
- * @fact: the #TnyPlatformFactory that holds the #ModestMailOperationQueue instance
- * 
- * Gets a new instance of a #ModestMailOperationQueue if it is the
- * first call to the function, or the current instantiated one
- * otherwise. This object is supposed to be a singleton
- * 
- * Returns: an instance of a #ModestMailOperationQueue
- **/
-ModestMailOperationQueue*   modest_tny_platform_factory_get_mail_operation_queue_instance (ModestTnyPlatformFactory *fact);
-
-
-/**
- * modest_tny_platform_factory_get_cache_mgr_instance:
- * @fact: the #TnyPlatformFactory that holds the #ModestCacheMgr instance
- * 
- * Gets a new instance of a #ModestCacheMgr if it is the
- * first call to the function, or the current instantiated one
- * otherwise. This object is supposed to be a singleton
- * 
- * Returns: an instance of a #ModestCacheMgr.
- **/
-ModestCacheMgr*   modest_tny_platform_factory_get_cache_mgr_instance (ModestTnyPlatformFactory *fact);
-
-
-
-
 G_END_DECLS
 
 #endif /* __MODEST_TNY_PLATFORM_FACTORY_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_TNY_PLATFORM_FACTORY_H__ */
index e890ea0..ed631e0 100644 (file)
@@ -39,8 +39,6 @@ G_BEGIN_DECLS
 
 typedef struct _ModestUIPrivate ModestUIPrivate;
 struct _ModestUIPrivate {
 
 typedef struct _ModestUIPrivate ModestUIPrivate;
 struct _ModestUIPrivate {
-       ModestWidgetFactory  *widget_factory;   
-       TnyAccountStore      *account_store;
        ModestWindow         *main_window;
        GtkUIManager         *ui_manager;
 };
        ModestWindow         *main_window;
        GtkUIManager         *ui_manager;
 };
index 163e7de..37daca0 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <glib/gi18n.h>
 #include <string.h>
 
 #include <glib/gi18n.h>
 #include <string.h>
+#include <modest-runtime.h>
 #include "modest-ui-priv.h"
 #include "modest-ui.h"
 #include "modest-ui-actions.h"
 #include "modest-ui-priv.h"
 #include "modest-ui.h"
 #include "modest-ui-actions.h"
@@ -144,9 +145,7 @@ modest_ui_init (ModestUI *obj)
 
        priv = MODEST_UI_GET_PRIVATE(obj);
 
 
        priv = MODEST_UI_GET_PRIVATE(obj);
 
-       priv->widget_factory = NULL;
        priv->main_window    = NULL;
        priv->main_window    = NULL;
-       priv->account_store  = NULL;
 }
 
 
 }
 
 
@@ -155,50 +154,26 @@ modest_ui_finalize (GObject *obj)
 {
        ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
        
 {
        ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
        
-       if (priv->widget_factory) {
-               g_object_unref (G_OBJECT(priv->widget_factory));
-               priv->widget_factory = NULL;
-       }
-
        if (priv->ui_manager) {
                g_object_unref (G_OBJECT(priv->ui_manager));
                priv->ui_manager = NULL;
        }
 
        if (priv->ui_manager) {
                g_object_unref (G_OBJECT(priv->ui_manager));
                priv->ui_manager = NULL;
        }
 
+       priv->main_window = NULL;
+
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
 
 ModestUI*
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
 
 ModestUI*
-modest_ui_new (TnyAccountStore *account_store)
+modest_ui_new (void)
 {
        GObject *obj;
        ModestUIPrivate *priv;
 {
        GObject *obj;
        ModestUIPrivate *priv;
-       TnyPlatformFactory *fact;
-       ModestAccountMgr *account_mgr;
 
        obj  = g_object_new(MODEST_TYPE_UI, NULL);
        priv = MODEST_UI_GET_PRIVATE(obj);
 
        obj  = g_object_new(MODEST_TYPE_UI, NULL);
        priv = MODEST_UI_GET_PRIVATE(obj);
-
-       /* Get the platform-dependent instances */
-       fact = modest_tny_platform_factory_get_instance ();
        
        
-       priv->account_store = account_store;
-
-       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(fact));
-       if (!account_mgr) {
-               g_printerr ("modest: could not create ModestAccountMgr instance\n");
-               g_object_unref (obj);
-               return NULL;
-        }
-
-       priv->widget_factory = modest_widget_factory_new ();
-       if (!priv->widget_factory) {
-               g_printerr ("modest: could not initialize widget factory\n");
-               return NULL;
-       }
-
        /* Register our own icons as stock icons in order to
           use them with the UI manager */
        register_stock_icons ();
        /* Register our own icons as stock icons in order to
           use them with the UI manager */
        register_stock_icons ();
@@ -224,11 +199,7 @@ modest_ui_main_window (ModestUI *self)
        priv = MODEST_UI_GET_PRIVATE(self);
 
        if (!priv->main_window) {
        priv = MODEST_UI_GET_PRIVATE(self);
 
        if (!priv->main_window) {
-
-               /* Create main window */
-               priv->main_window = modest_main_window_new (priv->widget_factory,
-                                                           priv->account_store);
-
+               priv->main_window = modest_main_window_new ();
                connect_signals (self);
        }
                
                connect_signals (self);
        }
                
@@ -248,9 +219,7 @@ modest_ui_edit_window (ModestUI *self, ModestEditType edit_type)
        priv = MODEST_UI_GET_PRIVATE(self);
 
        /* Create window */
        priv = MODEST_UI_GET_PRIVATE(self);
 
        /* Create window */
-       edit_window = modest_edit_msg_window_new (priv->widget_factory, 
-                                                 priv->account_store,
-                                                 edit_type);
+       edit_window = modest_edit_msg_window_new (edit_type);
        
        /* Connect Edit Window signals */
 /*     connect_edit_window_signals (self); */
        
        /* Connect Edit Window signals */
 /*     connect_edit_window_signals (self); */
@@ -342,14 +311,18 @@ connect_signals (ModestUI *self)
        ModestHeaderView *header_view;
        ModestMsgView *msg_view;
        GtkWidget *toggle;
        ModestHeaderView *header_view;
        ModestMsgView *msg_view;
        GtkWidget *toggle;
+       ModestWidgetFactory *widget_factory;
        
        priv = MODEST_UI_GET_PRIVATE(self);
 
        
        priv = MODEST_UI_GET_PRIVATE(self);
 
-       folder_view = modest_widget_factory_get_folder_view (priv->widget_factory);
-       header_view = modest_widget_factory_get_header_view (priv->widget_factory);
-       msg_view    = modest_widget_factory_get_msg_preview (priv->widget_factory);
-       toggle      = modest_widget_factory_get_online_toggle (priv->widget_factory);
-       device      = tny_account_store_get_device (priv->account_store);
+       widget_factory = modest_runtime_get_widget_factory (); 
+       
+       folder_view = modest_widget_factory_get_folder_view (widget_factory);
+       header_view = modest_widget_factory_get_header_view (widget_factory);
+       msg_view    = modest_widget_factory_get_msg_preview (widget_factory);
+       toggle      = modest_widget_factory_get_online_toggle (widget_factory);
+       device      = tny_account_store_get_device
+               (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()));
 
        /* folder view */
        g_signal_connect (G_OBJECT(folder_view), "folder_selection_changed",
 
        /* folder view */
        g_signal_connect (G_OBJECT(folder_view), "folder_selection_changed",
@@ -438,10 +411,9 @@ _modest_ui_actions_on_delete (GtkWidget *widget,
        TnyIterator *iter;
        GtkTreeModel *model;
 
        TnyIterator *iter;
        GtkTreeModel *model;
 
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+       widget_factory = modest_runtime_get_widget_factory ();
        header_view = modest_widget_factory_get_header_view (widget_factory);
        header_list = modest_header_view_get_selected_headers (header_view);
        header_view = modest_widget_factory_get_header_view (widget_factory);
        header_list = modest_header_view_get_selected_headers (header_view);
-       g_object_unref (G_OBJECT(widget_factory));
        
        if (header_list) {
                iter = tny_list_create_iterator (header_list);
        
        if (header_list) {
                iter = tny_list_create_iterator (header_list);
@@ -492,14 +464,10 @@ _modest_ui_actions_on_quit (GtkWidget *widget,
 
 void
 _modest_ui_actions_on_accounts (GtkWidget *widget, 
 
 void
 _modest_ui_actions_on_accounts (GtkWidget *widget, 
-                              ModestMainWindow *main_window)
+                               ModestMainWindow *main_window)
 {
        GtkWidget *account_win;
 {
        GtkWidget *account_win;
-       ModestWidgetFactory *widget_factory;
-
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       account_win = modest_account_view_window_new (widget_factory);
-       g_object_unref (G_OBJECT(widget_factory));
+       account_win = modest_account_view_window_new (modest_runtime_get_widget_factory());
 
        gtk_window_set_transient_for (GTK_WINDOW (account_win),
                                      GTK_WINDOW (main_window));
 
        gtk_window_set_transient_for (GTK_WINDOW (account_win),
                                      GTK_WINDOW (main_window));
@@ -512,27 +480,14 @@ _modest_ui_actions_on_new_msg (GtkWidget *widget,
                               ModestMainWindow *main_window)
 {
        ModestWindow *msg_win;
                               ModestMainWindow *main_window)
 {
        ModestWindow *msg_win;
-       ModestWidgetFactory *widget_factory;
-       TnyAccountStore *account_store;
-
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       account_store = modest_window_get_account_store (MODEST_WINDOW (main_window));
-       msg_win = modest_edit_msg_window_new (widget_factory, 
-                                             account_store,
-                                             MODEST_EDIT_TYPE_NEW);
-       g_object_unref (G_OBJECT (widget_factory));
-       g_object_unref (G_OBJECT (account_store));
-
+       msg_win = modest_edit_msg_window_new (MODEST_EDIT_TYPE_NEW);
        gtk_widget_show_all (GTK_WIDGET (msg_win));
 }
 
 static void
 reply_forward_func (gpointer data, gpointer user_data)
 {
        gtk_widget_show_all (GTK_WIDGET (msg_win));
 }
 
 static void
 reply_forward_func (gpointer data, gpointer user_data)
 {
-       ModestWidgetFactory *widget_factory;
-       //TnyHeader *new_header;
        TnyMsg *msg, *new_msg;
        TnyMsg *msg, *new_msg;
-       TnyAccountStore *account_store;
        GetMsgAsyncHelper *helper;
        ReplyForwardHelper *rf_helper;
        ModestWindow *msg_win;
        GetMsgAsyncHelper *helper;
        ReplyForwardHelper *rf_helper;
        ModestWindow *msg_win;
@@ -570,21 +525,9 @@ reply_forward_func (gpointer data, gpointer user_data)
                g_warning ("Unable to create a message");
                goto cleanup;
        }
                g_warning ("Unable to create a message");
                goto cleanup;
        }
-
-/*     /\* Set from *\/ */
-/*     new_header = tny_msg_get_header (new_msg); */
-/*     tny_header_set_from (new_header, rf_helper->from); */
-/*     g_object_unref (G_OBJECT (new_header)); */
                
        /* Show edit window */
                
        /* Show edit window */
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (helper->main_window));
-       account_store = modest_window_get_account_store (MODEST_WINDOW (helper->main_window));
-       msg_win = modest_edit_msg_window_new (widget_factory, 
-                                             account_store,
-                                             MODEST_EDIT_TYPE_NEW);
-       g_object_unref (G_OBJECT (widget_factory));
-       g_object_unref (G_OBJECT (account_store));
-
+       msg_win = modest_edit_msg_window_new (MODEST_EDIT_TYPE_NEW);
        modest_edit_msg_window_set_msg (MODEST_EDIT_MSG_WINDOW (msg_win),
                                        new_msg);
        gtk_widget_show_all (GTK_WIDGET (msg_win));
        modest_edit_msg_window_set_msg (MODEST_EDIT_MSG_WINDOW (msg_win),
                                        new_msg);
        gtk_widget_show_all (GTK_WIDGET (msg_win));
@@ -607,23 +550,18 @@ reply_forward (GtkWidget *widget,
 {
        ModestHeaderView *header_view;
        ModestAccountMgr *account_mgr;
 {
        ModestHeaderView *header_view;
        ModestAccountMgr *account_mgr;
-       ModestWidgetFactory *widget_factory;
        TnyList *header_list;
        guint reply_forward_type;
        ModestConf *conf;       
        ModestAccountData *default_account_data;
        TnyList *header_list;
        guint reply_forward_type;
        ModestConf *conf;       
        ModestAccountData *default_account_data;
-       TnyPlatformFactory *plat_factory;
        TnyHeader *header;
        TnyFolder *folder;
        gchar *from, *key, *default_account_name;
        GetMsgAsyncHelper *helper;
        ReplyForwardHelper *rf_helper;
 
        TnyHeader *header;
        TnyFolder *folder;
        gchar *from, *key, *default_account_name;
        GetMsgAsyncHelper *helper;
        ReplyForwardHelper *rf_helper;
 
-       /* Get ModestConf */
-       plat_factory = modest_tny_platform_factory_get_instance ();
-       conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(plat_factory));
-
+       conf = modest_runtime_get_conf ();
+       
        /* Get reply or forward type */
        key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE, 
                               (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE);
        /* Get reply or forward type */
        key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE, 
                               (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE);
@@ -631,11 +569,8 @@ reply_forward (GtkWidget *widget,
        g_free (key);
 
        /* Get the list of headers */
        g_free (key);
 
        /* Get the list of headers */
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       header_view = modest_widget_factory_get_header_view (widget_factory);
-       header_list = modest_header_view_get_selected_headers (header_view);
-       g_object_unref (G_OBJECT(widget_factory));
-
+       header_view = modest_widget_factory_get_header_view (modest_runtime_get_widget_factory());
+       header_list = modest_header_view_get_selected_headers (header_view);    
        if (!header_list)
                return;
 
        if (!header_list)
                return;
 
@@ -643,8 +578,7 @@ reply_forward (GtkWidget *widget,
           same folder and that we reply all of them from the
           same account. In fact the interface currently only
           allows single selection */
           same folder and that we reply all of them from the
           same account. In fact the interface currently only
           allows single selection */
-       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(plat_factory));
+       account_mgr = modest_runtime_get_account_mgr();
        default_account_name = modest_account_mgr_get_default_account (account_mgr);
        default_account_data = 
                modest_account_mgr_get_account_data (account_mgr,
        default_account_name = modest_account_mgr_get_default_account (account_mgr);
        default_account_data = 
                modest_account_mgr_get_account_data (account_mgr,
@@ -701,11 +635,9 @@ _modest_ui_actions_on_next (GtkWidget *widget,
                           ModestMainWindow *main_window)
 {
        ModestHeaderView *header_view;
                           ModestMainWindow *main_window)
 {
        ModestHeaderView *header_view;
-       ModestWidgetFactory *widget_factory;
 
 
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       header_view = modest_widget_factory_get_header_view (widget_factory);
-       g_object_unref (G_OBJECT(widget_factory));
+       header_view = modest_widget_factory_get_header_view
+               (modest_runtime_get_widget_factory());
 
        modest_header_view_select_next (header_view);
 }
 
        modest_header_view_select_next (header_view);
 }
@@ -714,19 +646,14 @@ void
 _modest_ui_actions_toggle_view (GtkWidget *widget,
                                ModestMainWindow *main_window)
 {
 _modest_ui_actions_toggle_view (GtkWidget *widget,
                                ModestMainWindow *main_window)
 {
-       ModestHeaderView *header_view;
-       ModestWidgetFactory *widget_factory;
        ModestConf *conf;
        ModestConf *conf;
-       TnyPlatformFactory *plat_factory;
+       ModestHeaderView *header_view;
 
 
-       /* Get ModestConf */
-       plat_factory = modest_tny_platform_factory_get_instance ();
-       conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(plat_factory));
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       header_view = modest_widget_factory_get_header_view (widget_factory);
-       g_object_unref (G_OBJECT(widget_factory));
+       header_view = modest_widget_factory_get_header_view
+               (modest_runtime_get_widget_factory());
 
 
+       conf = modest_runtime_get_conf ();
+       
        /* what is saved/restored is depending on the style; thus; we save with
         * old style, then update the style, and restore for this new style*/
        modest_widget_memory_save (conf, G_OBJECT(header_view), "header-view");
        /* what is saved/restored is depending on the style; thus; we save with
         * old style, then update the style, and restore for this new style*/
        modest_widget_memory_save (conf, G_OBJECT(header_view), "header-view");
@@ -748,7 +675,6 @@ static void
 read_msg_func (gpointer data, gpointer user_data)
 {
        ModestMsgView *msg_view;
 read_msg_func (gpointer data, gpointer user_data)
 {
        ModestMsgView *msg_view;
-       ModestWidgetFactory *widget_factory;
        TnyMsg *msg;
        TnyHeader *header;
        GetMsgAsyncHelper *helper;
        TnyMsg *msg;
        TnyHeader *header;
        GetMsgAsyncHelper *helper;
@@ -764,9 +690,8 @@ read_msg_func (gpointer data, gpointer user_data)
        g_object_unref (G_OBJECT (header));
 
        /* Set message on msg view */
        g_object_unref (G_OBJECT (header));
 
        /* Set message on msg view */
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (helper->main_window));
-       msg_view = modest_widget_factory_get_msg_preview (widget_factory);
-       g_object_unref (G_OBJECT(widget_factory));
+       msg_view = modest_widget_factory_get_msg_preview
+               (modest_runtime_get_widget_factory());
        modest_msg_view_set_message (msg_view, msg);
 }
 
        modest_msg_view_set_message (msg_view, msg);
 }
 
@@ -788,11 +713,8 @@ get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
 
        if (*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) {
                ModestHeaderView *header_view;
 
        if (*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) {
                ModestHeaderView *header_view;
-               ModestWidgetFactory *widget_factory;
-
-               widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (helper->main_window));
-               header_view = modest_widget_factory_get_header_view (widget_factory);
-               g_object_unref (G_OBJECT (widget_factory));
+               header_view = modest_widget_factory_get_header_view
+                       (modest_runtime_get_widget_factory());
                _modest_ui_actions_on_item_not_found (header_view,
                                                      MODEST_ITEM_TYPE_MESSAGE,
                                                      helper->main_window);
                _modest_ui_actions_on_item_not_found (header_view,
                                                      MODEST_ITEM_TYPE_MESSAGE,
                                                      helper->main_window);
@@ -832,9 +754,8 @@ _modest_ui_actions_on_header_selected (ModestHeaderView *folder_view,
        /* when there's no header, clear the msgview */
        if (!header) {
                ModestMsgView *msg_view;
        /* when there's no header, clear the msgview */
        if (!header) {
                ModestMsgView *msg_view;
-               ModestWidgetFactory *widget_factory;
-               widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-               msg_view       = modest_widget_factory_get_msg_preview (widget_factory);
+               msg_view       = modest_widget_factory_get_msg_preview
+                       (modest_runtime_get_widget_factory());
                modest_msg_view_set_message (msg_view, NULL);
                return;
        }
                modest_msg_view_set_message (msg_view, NULL);
                return;
        }
@@ -866,26 +787,21 @@ _modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
                                               ModestMainWindow *main_window)
 {
        GtkLabel *folder_info_label;
                                               ModestMainWindow *main_window)
 {
        GtkLabel *folder_info_label;
-       TnyPlatformFactory *factory;
        gchar *txt;     
        ModestConf *conf;
        ModestHeaderView *header_view;
        gchar *txt;     
        ModestConf *conf;
        ModestHeaderView *header_view;
-       ModestWidgetFactory *widget_factory;
 
 
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
        folder_info_label = 
        folder_info_label = 
-               GTK_LABEL (modest_widget_factory_get_folder_info_label (widget_factory));
+               GTK_LABEL (modest_widget_factory_get_folder_info_label
+                          (modest_runtime_get_widget_factory()));
 
        if (!folder) {
                gtk_label_set_label (GTK_LABEL(folder_info_label), "");
                return;
        }
 
        if (!folder) {
                gtk_label_set_label (GTK_LABEL(folder_info_label), "");
                return;
        }
-
-       factory = modest_tny_platform_factory_get_instance ();
-       header_view = modest_widget_factory_get_header_view (widget_factory);
-       conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(factory));
-       g_object_unref (G_OBJECT (widget_factory));
+       
+       header_view = modest_widget_factory_get_header_view (modest_runtime_get_widget_factory());
+       conf = modest_runtime_get_conf ();
 
        if (!selected) { /* the folder was unselected; save it's settings  */
                modest_widget_memory_save (conf, G_OBJECT (header_view),
 
        if (!selected) { /* the folder was unselected; save it's settings  */
                modest_widget_memory_save (conf, G_OBJECT (header_view),
@@ -970,9 +886,8 @@ statusbar_push (ModestWidgetFactory *factory, guint context_id, const gchar *msg
 /****************************************************************************/
 
 void
 /****************************************************************************/
 
 void
-_modest_ui_actions_on_connection_changed (TnyDevice *device, 
-                                        gboolean online,
-                                        ModestMainWindow *main_window)
+_modest_ui_actions_on_connection_changed (TnyDevice *device, gboolean online,
+                                         ModestMainWindow *main_window)
 {
        GtkWidget *online_toggle;
        ModestHeaderView *header_view;
 {
        GtkWidget *online_toggle;
        ModestHeaderView *header_view;
@@ -980,7 +895,7 @@ _modest_ui_actions_on_connection_changed (TnyDevice *device,
 
        g_return_if_fail (main_window);
        
 
        g_return_if_fail (main_window);
        
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
+       widget_factory = modest_runtime_get_widget_factory ();
        header_view   = modest_widget_factory_get_header_view (widget_factory);
        online_toggle = modest_widget_factory_get_online_toggle (widget_factory);
 
        header_view   = modest_widget_factory_get_header_view (widget_factory);
        online_toggle = modest_widget_factory_get_online_toggle (widget_factory);
 
@@ -991,8 +906,7 @@ _modest_ui_actions_on_connection_changed (TnyDevice *device,
 
        statusbar_push (widget_factory, 0, 
                        online ? _("Modest went online") : _("Modest went offline"));
 
        statusbar_push (widget_factory, 0, 
                        online ? _("Modest went online") : _("Modest went offline"));
-       g_object_unref (G_OBJECT (widget_factory));
-
+       
        /* If Modest has became online and the header view has a
           header selected then show it */
        if (online) {
        /* If Modest has became online and the header view has a
           header selected then show it */
        if (online) {
@@ -1009,14 +923,9 @@ _modest_ui_actions_on_online_toggle_toggled (GtkToggleButton *toggle,
 {
        gboolean online;
        TnyDevice *device;
 {
        gboolean online;
        TnyDevice *device;
-       TnyPlatformFactory *factory;
-       TnyAccountStore *account_store;
 
 
-       /* Get device. Do not ask the platform factory for it, because
-          it returns always a new one */
-       factory = modest_tny_platform_factory_get_instance ();
-       account_store = tny_platform_factory_new_account_store (factory);
-       device = tny_account_store_get_device (account_store);
+       device = tny_account_store_get_device
+               (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()));
 
        online  = gtk_toggle_button_get_active (toggle);
 
 
        online  = gtk_toggle_button_get_active (toggle);
 
@@ -1097,12 +1006,10 @@ _modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
                                            ModestMainWindow *main_window)
 {
        GtkWidget *progress_bar;
                                            ModestMainWindow *main_window)
 {
        GtkWidget *progress_bar;
-       ModestWidgetFactory *widget_factory;
        char* txt;
        
        char* txt;
        
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       progress_bar = modest_widget_factory_get_progress_bar (widget_factory);
-
+       progress_bar = modest_widget_factory_get_progress_bar
+               (modest_runtime_get_widget_factory());
        if (total != 0)
                gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress_bar),
                                               (gdouble)num/(gdouble)total);
        if (total != 0)
                gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress_bar),
                                               (gdouble)num/(gdouble)total);
@@ -1113,10 +1020,7 @@ _modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
        gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress_bar), txt);
        g_free (txt);
        
        gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress_bar), txt);
        g_free (txt);
        
-       statusbar_push (widget_factory, 0, msg);
-       
-       /* Free */
-       g_object_unref (G_OBJECT (widget_factory));
+       statusbar_push (modest_runtime_get_widget_factory(), 0, msg);
 }
 
 
 }
 
 
@@ -1126,11 +1030,7 @@ _modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview,
                                      const gchar* link,
                                      ModestMainWindow *main_window)
 {
                                      const gchar* link,
                                      ModestMainWindow *main_window)
 {
-       ModestWidgetFactory *widget_factory;
-
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       statusbar_push (widget_factory, 0, link);
-       g_object_unref (G_OBJECT (widget_factory));     
+       statusbar_push (modest_runtime_get_widget_factory(), 0, link);
 
        /* TODO: do something */
 }      
 
        /* TODO: do something */
 }      
@@ -1142,14 +1042,9 @@ _modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview,
                                        ModestMainWindow *main_window)
 {
        gchar *msg;
                                        ModestMainWindow *main_window)
 {
        gchar *msg;
-       ModestWidgetFactory *widget_factory;
 
        msg = g_strdup_printf (_("Opening %s..."), link);
 
        msg = g_strdup_printf (_("Opening %s..."), link);
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       statusbar_push (widget_factory, 0, msg);
-
-       g_object_unref (G_OBJECT (widget_factory));     
-
+       statusbar_push (modest_runtime_get_widget_factory(), 0, msg);
        g_free (msg);
 
        /* TODO: do something */
        g_free (msg);
 
        /* TODO: do something */
@@ -1161,14 +1056,11 @@ _modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview,
                                              ModestMainWindow *main_window)
 {
        gchar *msg;
                                              ModestMainWindow *main_window)
 {
        gchar *msg;
-       ModestWidgetFactory *widget_factory;
        
        msg = g_strdup_printf (_("Opening attachment %d..."), index);
        
        msg = g_strdup_printf (_("Opening attachment %d..."), index);
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       statusbar_push (widget_factory, 0, msg);
+       statusbar_push (modest_runtime_get_widget_factory(), 0, msg);
        
        g_free (msg);
        
        g_free (msg);
-       g_object_unref (G_OBJECT (widget_factory));
        /* TODO: do something */
 }
 
        /* TODO: do something */
 }
 
@@ -1188,13 +1080,11 @@ _modest_ui_actions_on_send (GtkWidget *widget,
        {
                TnyList *accounts;
                TnyIterator *iter;
        {
                TnyList *accounts;
                TnyIterator *iter;
-               TnyAccountStore *account_store;
-
+               
                accounts = TNY_LIST(tny_simple_list_new ());
                accounts = TNY_LIST(tny_simple_list_new ());
-               account_store = modest_window_get_account_store (MODEST_WINDOW (edit_window));
-               tny_account_store_get_accounts (account_store, accounts,
+               tny_account_store_get_accounts (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()),
+                                               accounts,
                                                TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
                                                TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
-               g_object_unref (G_OBJECT (account_store));
 
                iter = tny_list_create_iterator(accounts);
                tny_iterator_first (iter);
 
                iter = tny_list_create_iterator(accounts);
                tny_iterator_first (iter);
@@ -1279,12 +1169,11 @@ _modest_ui_actions_on_new_folder (GtkWidget *widget,
 {
        TnyFolder *parent_folder;
        ModestFolderView *folder_view;
 {
        TnyFolder *parent_folder;
        ModestFolderView *folder_view;
-       ModestWidgetFactory *widget_factory;
 
 
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       folder_view = modest_widget_factory_get_folder_view (widget_factory);
+       folder_view = modest_widget_factory_get_folder_view
+               (modest_runtime_get_widget_factory());
        parent_folder = modest_folder_view_get_selected (folder_view);
        parent_folder = modest_folder_view_get_selected (folder_view);
-
+       
        if (parent_folder) {
                gchar *folder_name;
 
        if (parent_folder) {
                gchar *folder_name;
 
@@ -1308,7 +1197,6 @@ _modest_ui_actions_on_new_folder (GtkWidget *widget,
                }
                g_object_unref (parent_folder);
        }
                }
                g_object_unref (parent_folder);
        }
-       g_object_unref (G_OBJECT (widget_factory));
 }
 
 void 
 }
 
 void 
@@ -1317,10 +1205,8 @@ _modest_ui_actions_on_rename_folder (GtkWidget *widget,
 {
        TnyFolder *folder;
        ModestFolderView *folder_view;
 {
        TnyFolder *folder;
        ModestFolderView *folder_view;
-       ModestWidgetFactory *widget_factory;
-
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       folder_view = modest_widget_factory_get_folder_view (widget_factory);
+       
+       folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory());
        folder = modest_folder_view_get_selected (folder_view);
 
        if (folder) {
        folder = modest_folder_view_get_selected (folder_view);
 
        if (folder) {
@@ -1340,7 +1226,6 @@ _modest_ui_actions_on_rename_folder (GtkWidget *widget,
                }
                g_object_unref (folder);
        }
                }
                g_object_unref (folder);
        }
-       g_object_unref (G_OBJECT (widget_factory));
 }
 
 static void
 }
 
 static void
@@ -1349,11 +1234,9 @@ delete_folder (ModestMainWindow *main_window,
 {
        TnyFolder *folder;
        ModestFolderView *folder_view;
 {
        TnyFolder *folder;
        ModestFolderView *folder_view;
-       ModestWidgetFactory *widget_factory;
        ModestMailOperation *mail_op;
        ModestMailOperation *mail_op;
-                       
-       widget_factory = modest_window_get_widget_factory (MODEST_WINDOW (main_window));
-       folder_view = modest_widget_factory_get_folder_view (widget_factory);
+       
+       folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory());
        folder = modest_folder_view_get_selected (folder_view);
 
        mail_op = modest_mail_operation_new ();
        folder = modest_folder_view_get_selected (folder_view);
 
        mail_op = modest_mail_operation_new ();
index 0d109ca..60bc4a7 100644 (file)
@@ -74,7 +74,7 @@ GType        modest_ui_get_type        (void) G_GNUC_CONST;
  *  
  * Returns: a new ModestUI, or NULL in case of error
  */
  *  
  * Returns: a new ModestUI, or NULL in case of error
  */
-ModestUI*     modest_ui_new            (TnyAccountStore *account_store);
+ModestUI*     modest_ui_new            (void);
 
 
 /**
 
 
 /**
index c066feb..3b61c6b 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <modest-account-mgr.h>
 #include <modest-account-mgr-helpers.h>
 
 #include <modest-account-mgr.h>
 #include <modest-account-mgr-helpers.h>
+#include <modest-runtime.h>
 
 #include "modest-mail-operation.h"
 #include "widgets/modest-header-view-priv.h"
 
 #include "modest-mail-operation.h"
 #include "widgets/modest-header-view-priv.h"
@@ -60,10 +61,9 @@ enum {
 };
 
 typedef struct _ModestWidgetFactoryPrivate ModestWidgetFactoryPrivate;
 };
 
 typedef struct _ModestWidgetFactoryPrivate ModestWidgetFactoryPrivate;
-struct _ModestWidgetFactoryPrivate {
-       
-       TnyPlatformFactory          *fact;
-       TnyAccountStore             *account_store;
+struct _ModestWidgetFactoryPrivate {   
+
+       ModestTnyAccountStore       *account_store;
        
        ModestHeaderView            *header_view;
        ModestFolderView            *folder_view;
        
        ModestHeaderView            *header_view;
        ModestFolderView            *folder_view;
@@ -125,9 +125,8 @@ modest_widget_factory_init (ModestWidgetFactory *obj)
 {
        ModestWidgetFactoryPrivate *priv;
        priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
 {
        ModestWidgetFactoryPrivate *priv;
        priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
-
-       priv->fact          = modest_tny_platform_factory_get_instance ();
-       priv->account_store = tny_platform_factory_new_account_store (priv->fact);
+       
+       priv->account_store = NULL;
        
        priv->progress_bar = gtk_progress_bar_new ();
        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(priv->progress_bar),
        
        priv->progress_bar = gtk_progress_bar_new ();
        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(priv->progress_bar),
@@ -141,9 +140,8 @@ modest_widget_factory_init (ModestWidgetFactory *obj)
 static void
 modest_widget_factory_finalize (GObject *obj)
 {
 static void
 modest_widget_factory_finalize (GObject *obj)
 {
-       ModestWidgetFactoryPrivate *priv;
-       priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
-
+       /* no need to unref account_store; we don't own the reference */
+       
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
@@ -159,29 +157,29 @@ init_widgets (ModestWidgetFactory *self)
        /* folder view */
        query = tny_folder_store_query_new ();
        tny_folder_store_query_add_item (query, NULL, TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
        /* folder view */
        query = tny_folder_store_query_new ();
        tny_folder_store_query_add_item (query, NULL, TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
-       if (!(priv->folder_view =
-             MODEST_FOLDER_VIEW(modest_folder_view_new (MODEST_TNY_ACCOUNT_STORE (priv->account_store),
-                                                        query)))) {
+
+       priv->folder_view =  MODEST_FOLDER_VIEW(modest_folder_view_new (priv->account_store,query));
+       if (!priv->folder_view) {
                g_printerr ("modest: cannot instantiate folder view\n");
                return FALSE;
                g_printerr ("modest: cannot instantiate folder view\n");
                return FALSE;
-       }
+       }       
        g_object_unref (G_OBJECT (query));
        g_object_unref (G_OBJECT (query));
-
+       
        /* header view */
        /* header view */
-       if (!(priv->header_view =
-             MODEST_HEADER_VIEW(modest_header_view_new (NULL,MODEST_HEADER_VIEW_STYLE_DETAILS)))) {
+       priv->header_view =
+               MODEST_HEADER_VIEW(modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_DETAILS));
+       if (!priv->header_view) {
                g_printerr ("modest: cannot instantiate header view\n");
                return FALSE;
        }
                
        /* msg preview */
                g_printerr ("modest: cannot instantiate header view\n");
                return FALSE;
        }
                
        /* msg preview */
-       if (!(priv->msg_preview = MODEST_MSG_VIEW(modest_msg_view_new (NULL)))) {
+       priv->msg_preview = MODEST_MSG_VIEW(modest_msg_view_new (NULL));
+       if (!priv->msg_preview) {
                g_printerr ("modest: cannot instantiate header view\n");
                return FALSE;
        }
 
                g_printerr ("modest: cannot instantiate header view\n");
                return FALSE;
        }
 
-
-
        /* online/offline combo */
        priv->online_toggle = gtk_toggle_button_new ();
 
        /* online/offline combo */
        priv->online_toggle = gtk_toggle_button_new ();
 
@@ -189,21 +187,23 @@ init_widgets (ModestWidgetFactory *self)
           the current folder */
        priv->folder_info_label = gtk_label_new (NULL);
        
           the current folder */
        priv->folder_info_label = gtk_label_new (NULL);
        
-/*     init_signals (self); */
-       
        return TRUE;
 }
 
 
 ModestWidgetFactory*
        return TRUE;
 }
 
 
 ModestWidgetFactory*
-modest_widget_factory_new (void)
+modest_widget_factory_new (ModestTnyAccountStore *account_store)
 {
        GObject *obj;
        ModestWidgetFactoryPrivate *priv;
 
 {
        GObject *obj;
        ModestWidgetFactoryPrivate *priv;
 
+       g_return_val_if_fail (account_store, NULL);
+       
        obj  = g_object_new (MODEST_TYPE_WIDGET_FACTORY, NULL); 
        priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
        
        obj  = g_object_new (MODEST_TYPE_WIDGET_FACTORY, NULL); 
        priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(obj);
        
+       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);
        if (!init_widgets (MODEST_WIDGET_FACTORY(obj))) {
                g_printerr ("modest: widget factory failed to init widgets\n");
                g_object_unref (obj);
@@ -243,15 +243,7 @@ modest_widget_factory_get_msg_preview (ModestWidgetFactory *self)
 ModestAccountView*
 modest_widget_factory_get_account_view (ModestWidgetFactory *self)
 {
 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_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(priv->fact));
-       return modest_account_view_new (account_mgr);
+       return modest_account_view_new (modest_runtime_get_account_mgr());
 }
 
 
 }
 
 
@@ -283,9 +275,7 @@ get_transports (ModestWidgetFactory *self)
        
        priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self);
 
        
        priv = MODEST_WIDGET_FACTORY_GET_PRIVATE(self);
 
-       account_mgr =
-               modest_tny_platform_factory_get_account_mgr_instance
-               (MODEST_TNY_PLATFORM_FACTORY(priv->fact));
+       account_mgr = modest_runtime_get_account_mgr();
        cursor = accounts = modest_account_mgr_account_names (account_mgr, NULL);
        while (cursor) {
                ModestAccountData *data;
        cursor = accounts = modest_account_mgr_account_names (account_mgr, NULL);
        while (cursor) {
                ModestAccountData *data;
index b88f83d..7c0db2e 100644 (file)
@@ -53,13 +53,10 @@ typedef struct _ModestWidgetFactoryClass ModestWidgetFactoryClass;
 
 struct _ModestWidgetFactory {
         GObject parent;
 
 struct _ModestWidgetFactory {
         GObject parent;
-       /* insert public members, if any */
 };
 
 struct _ModestWidgetFactoryClass {
        GObjectClass parent_class;
 };
 
 struct _ModestWidgetFactoryClass {
        GObjectClass parent_class;
-       /* insert signal callback declarations, eg. */
-       /* void (* my_event) (ModestWidgetFactory* obj); */
 };
 
 
 };
 
 
@@ -85,12 +82,15 @@ GType        modest_widget_factory_get_type    (void) G_GNUC_CONST;
 
 /**
  * modest_widget_factory_new
 
 /**
  * modest_widget_factory_new
- *
+ * @account_store: a valid ModestTnyAccountStore instance
+ * 
  * instantiates a ModestWidgetFactory
  *
  * Returns: a new ModestWidgetFactory, or NULL in case of error
  */
  * instantiates a ModestWidgetFactory
  *
  * Returns: a new ModestWidgetFactory, or NULL in case of error
  */
-ModestWidgetFactory*      modest_widget_factory_new   (void);
+ModestWidgetFactory*      modest_widget_factory_new   (ModestTnyAccountStore *account_store);
+
+
 /**
  * modest_widget_factory_get_folder_view
  * @self: a ModestWidgetFactory instance
 /**
  * modest_widget_factory_get_folder_view
  * @self: a ModestWidgetFactory instance
@@ -130,7 +130,7 @@ ModestHeaderView*    modest_widget_factory_get_header_view (ModestWidgetFactory
  *
  * Returns: a header tree view, or NULL in case of error
  */
  *
  * Returns: a header tree view, or NULL in case of error
  */
-ModestMsgView*           modest_widget_factory_get_msg_preview (ModestWidgetFactory *self);
+ModestMsgView*        modest_widget_factory_get_msg_preview (ModestWidgetFactory *self);
 
 
 /**
 
 
 /**
index 7922b9d..756b02c 100644 (file)
@@ -31,8 +31,7 @@
 #define __MODEST_EDIT_MSG_WINDOW_H__
 
 #include <tny-msg.h>
 #define __MODEST_EDIT_MSG_WINDOW_H__
 
 #include <tny-msg.h>
-#include "modest-window.h"
-#include "modest-widget-factory.h"
+#include <modest-window.h>
 
 G_BEGIN_DECLS
 
 
 G_BEGIN_DECLS
 
@@ -58,8 +57,7 @@ struct _ModestEditMsgWindowClass {
        /* void (* my_event) (ModestEditMsgWindow* obj); */
 };
 
        /* void (* my_event) (ModestEditMsgWindow* obj); */
 };
 
-
-typedef enum _ModestEditType {
+typedef enum  {
        MODEST_EDIT_TYPE_NEW,
        MODEST_EDIT_TYPE_REPLY,
        MODEST_EDIT_TYPE_FORWARD,
        MODEST_EDIT_TYPE_NEW,
        MODEST_EDIT_TYPE_REPLY,
        MODEST_EDIT_TYPE_FORWARD,
@@ -71,15 +69,27 @@ typedef enum _ModestEditType {
 typedef struct _MsgData {
        gchar *from, *to, *cc, *bcc, *subject, *body;
 } MsgData;
 typedef struct _MsgData {
        gchar *from, *to, *cc, *bcc, *subject, *body;
 } MsgData;
-/* typedef enum _ModestEditType ModestEditType; */
 
 
 
 
-/* member functions */
+/**
+ * modest_edit_msg_window_get_type:
+ * 
+ * get the GType for the #ModestEditMsgWindow class
+ *
+ * Returns: a GType for #ModestEditMsgWindow
+ */
 GType        modest_edit_msg_window_get_type    (void) G_GNUC_CONST;
 
 GType        modest_edit_msg_window_get_type    (void) G_GNUC_CONST;
 
-ModestWindow*   modest_edit_msg_window_new         (ModestWidgetFactory *factory,
-                                                   TnyAccountStore *account_store,
-                                                   ModestEditType type);
+
+/**
+ * modest_edit_msg_window_new:
+ * 
+ * instantiates a new #ModestEditMsgWindow widget
+ *
+ * Returns: a new #ModestEditMsgWindow, or NULL in case of error
+ */
+ModestWindow*   modest_edit_msg_window_new         (ModestEditType type);
+
 
 /**
  * modest_edit_msg_window_set_msg:
 
 /**
  * modest_edit_msg_window_set_msg:
@@ -94,7 +104,7 @@ void         modest_edit_msg_window_set_msg     (ModestEditMsgWindow *self,
 
 /**
  * modest_edit_msg_window_get_msg_data:
 
 /**
  * modest_edit_msg_window_get_msg_data:
- * @edit_window: a #ModestEditMsgWindow
+ * @self: a #ModestEditMsgWindow
  * 
  * gets the message data already present in the edit message
  * window. The message data must be freed with
  * 
  * gets the message data already present in the edit message
  * window. The message data must be freed with
@@ -102,18 +112,17 @@ void         modest_edit_msg_window_set_msg     (ModestEditMsgWindow *self,
  * 
  * Returns: the message data
  **/
  * 
  * Returns: the message data
  **/
-MsgData *               modest_edit_msg_window_get_msg_data          (ModestEditMsgWindow *edit_window);
+MsgData *               modest_edit_msg_window_get_msg_data          (ModestEditMsgWindow *self);
 
 /**
  * modest_edit_msg_window_free_msg_data:
 
 /**
  * modest_edit_msg_window_free_msg_data:
- * @edit_window: a #ModestEditMsgWindow
+ * @self: a #ModestEditMsgWindow
  * @data: 
  * 
  * frees the message data passed as argument
  **/
  * @data: 
  * 
  * frees the message data passed as argument
  **/
-void                    modest_edit_msg_window_free_msg_data         (ModestEditMsgWindow *edit_window,
+void                    modest_edit_msg_window_free_msg_data         (ModestEditMsgWindow *self,
                                                                      MsgData *data);
                                                                      MsgData *data);
-
 G_END_DECLS
 
 #endif /* __MODEST_EDIT_MSG_WINDOW_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_EDIT_MSG_WINDOW_H__ */
index a77688f..15e2251 100644 (file)
@@ -56,34 +56,24 @@ struct _ModestMainWindowClass {
        ModestWindowClass parent_class;
 };
 
        ModestWindowClass parent_class;
 };
 
-/* member functions */
-GType modest_main_window_get_type (void) G_GNUC_CONST;
-
-
-ModestWindow* modest_main_window_new (ModestWidgetFactory *factory,
-                                     TnyAccountStore *account_store);
-
 /**
 /**
- * modest_main_window_get_widget_factory:
- * @edit_window: a #ModestMainWindow
- * 
- * gets a new reference to the #ModestWidgetFactory associated with
- * the main window
+ * modest_main_window_get_type:
  * 
  * 
- * Returns: the widget factory
- **/
-ModestWidgetFactory *   modest_main_window_get_widget_factory    (ModestMainWindow *main_window);
+ * get the GType for the ModestMainWindow class
+ *
+ * Returns: a GType for ModestMainWindow
+ */
+GType modest_main_window_get_type (void) G_GNUC_CONST;
+
 
 /**
 
 /**
- * modest_main_window_get_account_store:
- * @edit_window: a #ModestMainWindow
+ * modest_main_window_new
  * 
  * 
- * gets a new reference to the account store associated with the main
- * window
- * 
- * Returns: the account store
- **/
-TnyAccountStore *       modest_main_window_get_account_store     (ModestMainWindow *main_window);
+ * instantiates a new ModestMainWindow widget
+ *
+ * Returns: a new ModestMainWindow, or NULL in case of error
+ */
+ModestWindow* modest_main_window_new (void);
 
 G_END_DECLS
 
 
 G_END_DECLS
 
index 32760b8..4d8f5c1 100644 (file)
@@ -39,13 +39,7 @@ G_BEGIN_DECLS
 
 typedef struct _ModestWindowPrivate ModestWindowPrivate;
 struct _ModestWindowPrivate {
 
 typedef struct _ModestWindowPrivate ModestWindowPrivate;
 struct _ModestWindowPrivate {
-
-       ModestWidgetFactory  *widget_factory;
-       TnyPlatformFactory   *plat_factory;
-
-       TnyAccountStore      *account_store;
        GtkUIManager         *ui_manager;
        GtkUIManager         *ui_manager;
-
        GtkWidget            *toolbar;
        GtkWidget            *menubar;
 };
        GtkWidget            *toolbar;
        GtkWidget            *menubar;
 };
index daa61b0..6132053 100644 (file)
@@ -96,10 +96,7 @@ modest_window_init (ModestWindow *obj)
 
        priv = MODEST_WINDOW_GET_PRIVATE(obj);
 
 
        priv = MODEST_WINDOW_GET_PRIVATE(obj);
 
-       priv->plat_factory  = modest_tny_platform_factory_get_instance ();
        priv->ui_manager    = NULL;
        priv->ui_manager    = NULL;
-       priv->account_store = NULL;
-
        priv->toolbar       = NULL;
        priv->menubar       = NULL;
 }
        priv->toolbar       = NULL;
        priv->menubar       = NULL;
 }
@@ -115,34 +112,6 @@ modest_window_finalize (GObject *obj)
                g_object_unref (G_OBJECT(priv->ui_manager));
                priv->ui_manager = NULL;
        }
                g_object_unref (G_OBJECT(priv->ui_manager));
                priv->ui_manager = NULL;
        }
-       if (priv->account_store) {
-               g_object_unref (G_OBJECT(priv->account_store));
-               priv->account_store = NULL;
-       }
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
-
-TnyAccountStore * 
-modest_window_get_account_store (ModestWindow *window)
-{
-       ModestWindowPrivate *priv;
-       
-       g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
-
-       priv = MODEST_WINDOW_GET_PRIVATE (window);
-
-       return g_object_ref (priv->account_store);
-}
-
-ModestWidgetFactory *
-modest_window_get_widget_factory (ModestWindow *window)
-{
-       ModestWindowPrivate *priv;
-       
-       g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
-
-       priv = MODEST_WINDOW_GET_PRIVATE (window);
-
-       return g_object_ref (priv->widget_factory);
-}
index fa574fe..b32a7f5 100644 (file)
@@ -76,29 +76,6 @@ struct _ModestWindowClass {
 /* member functions */
 GType        modest_window_get_type    (void) G_GNUC_CONST;
 
 /* member functions */
 GType        modest_window_get_type    (void) G_GNUC_CONST;
 
-/**
- * modest_window_get_account_store:
- * @window: a #ModestWindow
- * 
- * gets a new reference to the account store associated with the main
- * window. The caller must free the returned instance
- * 
- * Returns: the account store
- **/
-TnyAccountStore*        modest_window_get_account_store     (ModestWindow *window);
-
-/**
- * modest_window_get_widget_factory:
- * @window: a #ModestWindow
- * 
- * gets a reference to the #ModestWidgetFactory associated with the
- * Modest Window. The caller must free the returned instance
- * 
- * Returns: the widget factory
- **/
-ModestWidgetFactory*    modest_window_get_widget_factory    (ModestWindow *window);
-
-
 G_END_DECLS
 
 #endif /* __MODEST_WINDOW_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_WINDOW_H__ */