*/
#include "modest-singletons.h"
+#include "modest-runtime.h"
/* 'private'/'protected' functions */
static void modest_singletons_class_init (ModestSingletonsClass *klass);
struct _ModestSingletonsPrivate {
ModestConf *conf;
ModestAccountMgr *account_mgr;
- ModestTnyAccountStore *account_store;
+ ModestEmailClipboard *email_clipboard;
ModestCacheMgr *cache_mgr;
ModestMailOperationQueue *mail_op_queue;
- ModestWidgetFactory *widget_factory;
+ TnyPlatformFactory *platform_fact;
+ TnyDevice *device;
+ ModestWindowMgr *window_mgr;
};
#define MODEST_SINGLETONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MODEST_TYPE_SINGLETONS, \
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 = NULL;
+ priv->account_mgr = NULL;
+ priv->email_clipboard = NULL;
+ priv->cache_mgr = NULL;
+ priv->mail_op_queue = NULL;
+ priv->platform_fact = NULL;
+ priv->device = NULL;
+ priv->window_mgr = NULL;
priv->conf = modest_conf_new ();
if (!priv->conf) {
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");
+ priv->email_clipboard = modest_email_clipboard_new ();
+ if (!priv->email_clipboard) {
+ g_printerr ("modest: cannot create modest email clipboard instance\n");
return;
}
+ priv->platform_fact = modest_tny_platform_factory_get_instance ();
+ if (!priv->platform_fact) {
+ g_printerr ("modest: cannot create platform factory instance\n");
+ return;
+ }
+
+ priv->device = tny_platform_factory_new_device (priv->platform_fact);
+ if (!priv->device) {
+ g_printerr ("modest: cannot create tny device 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;
}
- /* don't initialize widget_factory here, but do it lazily, so we can
- * instaniatie modest-singletons before gtk_init
- */
+ priv->window_mgr = modest_window_mgr_new ();
+ if (!priv->window_mgr) {
+ g_printerr ("modest: cannot create modest window manager instance\n");
+ return;
+ }
}
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->window_mgr) {
+ modest_runtime_verify_object_last_ref(priv->window_mgr,"");
+ g_object_unref (G_OBJECT(priv->window_mgr));
+ priv->window_mgr = NULL;
}
- if (priv->account_store) {
- g_object_unref (G_OBJECT(priv->account_store));
- priv->account_store = NULL;
+
+ if (priv->email_clipboard) {
+ modest_runtime_verify_object_last_ref(priv->email_clipboard,"");
+ g_object_unref (G_OBJECT(priv->email_clipboard));
+ priv->email_clipboard = NULL;
}
if (priv->cache_mgr) {
+ modest_runtime_verify_object_last_ref(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;
+ if (priv->device) {
+ modest_runtime_verify_object_last_ref(priv->device,"");
+ g_object_unref (G_OBJECT(priv->device));
+ priv->device = NULL;
+ }
+
+ if (priv->platform_fact) {
+ modest_runtime_verify_object_last_ref(priv->platform_fact,"");
+ g_object_unref (G_OBJECT(priv->platform_fact));
+ priv->platform_fact = NULL;
+ }
+
+ if (priv->mail_op_queue) {
+ modest_runtime_verify_object_last_ref(priv->mail_op_queue,"");
+ g_object_unref (G_OBJECT(priv->mail_op_queue));
+ priv->mail_op_queue = NULL;
+ }
+
+ /* It is important that the account manager is uninitialized after
+ * the mail op queue is uninitialized because the mail op queue
+ * cancells any mail operations which in turn access the account
+ * manager (see modest_mail_operation_notify_end()). */
+ if (priv->account_mgr) {
+ modest_runtime_verify_object_last_ref(priv->account_mgr,"");
+ g_object_unref (G_OBJECT(priv->account_mgr));
+ priv->account_mgr = NULL;
+ }
+
+ if (priv->conf) {
+ modest_runtime_verify_object_last_ref(priv->conf,"");
+ g_object_unref (G_OBJECT(priv->conf));
+ priv->conf = NULL;
}
G_OBJECT_CLASS(parent_class)->finalize (obj);
{
ModestSingletonsPrivate *priv;
ModestSingletons *self;
+ static gboolean invoked = FALSE;
+
+ if (invoked) {
+ g_printerr ("modest: modest_singletons_new may only be called once\n");
+ g_assert (!invoked); /* abort */
+ return NULL; /* g_assert may be NOP */
+ }
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");
+ if (!(priv->conf && priv->account_mgr && priv->email_clipboard &&
+ priv->cache_mgr && priv->mail_op_queue && priv->device && priv->platform_fact)) {
+ g_printerr ("modest: failed to create singletons object\n");
g_object_unref (G_OBJECT(self));
self = NULL;
}
-
+
+ invoked = TRUE;
return self;
}
return MODEST_SINGLETONS_GET_PRIVATE(self)->account_mgr;
}
-ModestTnyAccountStore*
-modest_singletons_get_account_store (ModestSingletons *self)
+ModestEmailClipboard*
+modest_singletons_get_email_clipboard (ModestSingletons *self)
{
g_return_val_if_fail (self, NULL);
- return MODEST_SINGLETONS_GET_PRIVATE(self)->account_store;
+ return MODEST_SINGLETONS_GET_PRIVATE(self)->email_clipboard;
}
ModestCacheMgr*
return MODEST_SINGLETONS_GET_PRIVATE(self)->cache_mgr;
}
-
ModestMailOperationQueue*
modest_singletons_get_mail_operation_queue (ModestSingletons *self)
{
return MODEST_SINGLETONS_GET_PRIVATE(self)->mail_op_queue;
}
-
-ModestWidgetFactory*
-modest_singletons_get_widget_factory (ModestSingletons *self)
+TnyDevice*
+modest_singletons_get_device (ModestSingletons *self)
{
- ModestSingletonsPrivate *priv;
-
g_return_val_if_fail (self, NULL);
+ return MODEST_SINGLETONS_GET_PRIVATE(self)->device;
+}
- 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;
+TnyPlatformFactory*
+modest_singletons_get_platform_factory (ModestSingletons *self)
+{
+ g_return_val_if_fail (self, NULL);
+ return MODEST_SINGLETONS_GET_PRIVATE(self)->platform_fact;
+}
+
+ModestWindowMgr*
+modest_singletons_get_window_mgr (ModestSingletons *self)
+{
+ g_return_val_if_fail (self, NULL);
+ return MODEST_SINGLETONS_GET_PRIVATE(self)->window_mgr;
}