#include "modest-formatter.h"
#include "modest-text-utils.h"
#include "modest-tny-platform-factory.h"
+#include <modest-runtime.h>
typedef struct _ModestFormatterPrivate ModestFormatterPrivate;
struct _ModestFormatterPrivate {
TnyMsg *new_msg = NULL;
gchar *body_text = NULL, *txt = NULL;
ModestFormatterPrivate *priv;
- TnyPlatformFactory *fact;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (header, NULL);
g_return_val_if_fail (func, NULL);
/* Build new part */
- fact = modest_tny_platform_factory_get_instance ();
- new_msg = tny_platform_factory_new_msg (fact);
+ new_msg = tny_platform_factory_new_msg (modest_runtime_get_platform_factory());
if (body)
body_text = extract_text (self, body);
ModestFormatterPrivate *priv;
TnyPlatformFactory *fact;
- fact = modest_tny_platform_factory_get_instance ();
+ fact = modest_runtime_get_platform_factory ();
/* Build new part */
new_msg = tny_platform_factory_new_msg (fact);
body_part = tny_platform_factory_new_mime_part (fact);
static TnyMsg *
create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, guint type)
{
- TnyPlatformFactory *fact;
TnyMsg *new_msg;
TnyHeader *new_header, *header;
gchar *new_subject;
g_object_unref (G_OBJECT(body));
/* Fill the header */
- fact = modest_tny_platform_factory_get_instance ();
- new_header = TNY_HEADER (tny_platform_factory_new_header (fact));
+ new_header = TNY_HEADER (tny_platform_factory_new_header
+ (modest_runtime_get_platform_factory()));
tny_msg_set_header (new_msg, new_header);
tny_header_set_from (new_header, from);
tny_header_set_replyto (new_header, from);
const gchar *attachment_content_type;
const gchar *attachment_filename;
TnyStream *attachment_stream;
- TnyPlatformFactory *fact;
- fact = modest_tny_platform_factory_get_instance ();
for (pos = (GList *)attachments_list; pos; pos = pos->next) {
old_attachment = pos->data;
attachment_filename = tny_mime_part_get_filename (old_attachment);
attachment_stream = tny_mime_part_get_stream (old_attachment);
- attachment_part = tny_platform_factory_new_mime_part (fact);
+ attachment_part = tny_platform_factory_new_mime_part
+ (modest_runtime_get_platform_factory());
attachment_content_type = tny_mime_part_get_content_type (old_attachment);
}
+TnyPlatformFactory*
+modest_runtime_get_platform_factory (void)
+{
+ g_return_val_if_fail (_singletons, NULL);
+ return modest_singletons_get_platform_factory (_singletons);
+}
+
+
ModestTnySendQueue*
#include <modest-mail-operation-queue.h>
#include <modest-tny-account-store.h>
#include <modest-tny-send-queue.h>
+#include <tny-platform-factory.h>
G_BEGIN_DECLS
*
* get the ModestCacheMgr singleton instance
*
- * Returns: the ModestCacheMgr singleton. This should NOT be unref'd.
+ * Returns: the #ModestCacheMgr singleton. This should NOT be unref'd.
**/
ModestCacheMgr* modest_runtime_get_cache_mgr (void);
/**
- * modest_runtime_get_cache_mgr:
+ * modest_runtime_get_device:
+ *
+ * get the #TnyDevice singleton instance
+ *
+ * Returns: the #TnyDevice singleton. This should NOT be unref'd.
+ **/
+TnyDevice* modest_runtime_get_device (void);
+
+
+/**
+ * modest_runtime_get_platform_factory:
*
- * get the TnyDevice singleton instance
+ * get the #TnyPlatformFactory singleton instance
*
- * Returns: the TnyDevice singleton. This should NOT be unref'd.
+ * Returns: the #TnyPlatformFactory singleton. This should NOT be unref'd.
**/
-TnyDevice* modest_runtime_get_device (void);
+TnyPlatformFactory* modest_runtime_get_platform_factory (void);
+
g_printerr ("modest: cannot create modest account mgr 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->account_store = modest_tny_account_store_new (priv->account_mgr);
+ priv->account_store = modest_tny_account_store_new (priv->account_mgr, priv->device);
if (!priv->account_store) {
g_printerr ("modest: cannot create modest tny account store instance\n");
return;
if (!priv->mail_op_queue) {
g_printerr ("modest: cannot create modest mail operation queue 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;
- }
-
-
+ }
}
#include <tny-account-store.h>
#include <tny-store-account.h>
#include <tny-transport-account.h>
-#include <tny-device.h>
#include <tny-simple-list.h>
#include <tny-account-store.h>
#include <tny-camel-transport-account.h>
#include <tny-camel-imap-store-account.h>
#include <tny-camel-pop-store-account.h>
+#include <modest-runtime.h>
#include <modest-marshal.h>
#include <modest-protocol-info.h>
#include <modest-local-folder-info.h>
struct _ModestTnyAccountStorePrivate {
gchar *cache_dir;
GHashTable *password_hash;
- TnyDevice *device;
ModestAccountMgr *account_mgr;
TnySessionCamel *session;
+ TnyDevice *device;
/* we cache them here */
GSList *store_accounts;
priv->cache_dir = NULL;
priv->account_mgr = NULL;
- priv->device = NULL;
priv->session = NULL;
+ priv->device = NULL;
priv->password_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
GSList *cursor = accounts;
while (cursor) {
g_object_unref (G_OBJECT(cursor->data));
+/* if (G_IS_OBJECT(cursor->data)) */
+/* g_warning ("BUG: account %s still holds refs", */
+/* tny_account_get_id (TNY_ACCOUNT(cursor->data))); */
cursor = cursor->next;
}
g_slist_free (accounts);
account_list_free (priv->transport_accounts);
priv->transport_accounts = NULL;
-
g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
account);
}
priv->account_mgr = NULL;
}
+ if (priv->device) {
+ g_object_unref (G_OBJECT(priv->device));
+ priv->device = NULL;
+ }
+
/* this includes the local folder */
account_list_free (priv->store_accounts);
priv->store_accounts = NULL;
camel_object_unref (CAMEL_OBJECT(priv->session));
priv->session = NULL;
}
-
- /* the device should be unref'ed *AFTER* the session */
- if (priv->device) {
- g_object_unref (G_OBJECT(priv->device));
- priv->device = NULL;
- }
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
ModestTnyAccountStore*
-modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
+modest_tny_account_store_new (ModestAccountMgr *account_mgr, TnyDevice *device) {
GObject *obj;
ModestTnyAccountStorePrivate *priv;
TnyList *list;
g_return_val_if_fail (account_mgr, NULL);
+ g_return_val_if_fail (device, NULL);
obj = G_OBJECT(g_object_new(MODEST_TYPE_TNY_ACCOUNT_STORE, NULL));
priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj);
priv->account_mgr = account_mgr;
g_object_ref (G_OBJECT(priv->account_mgr));
+ priv->device = device;
+ g_object_ref (priv->device);
+
priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ());
priv->transport_accounts = get_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
else
get_cached_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
- } else
+ } else {
g_return_if_reached (); /* incorrect req type */
+ return;
+ }
}
{
ModestTnyAccountStorePrivate *priv;
- priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
-
- if (!priv->device)
- priv->device = tny_platform_factory_new_device
- (modest_tny_platform_factory_get_instance());
+ g_return_val_if_fail (self, NULL);
- return g_object_ref (G_OBJECT(priv->device));
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ if (priv->device)
+ return g_object_ref (G_OBJECT(priv->device));
+ else
+ return NULL;
}
*
* Returns: newly created account store or NULL in case of error
*/
-ModestTnyAccountStore* modest_tny_account_store_new (ModestAccountMgr *account_mgr);
+ModestTnyAccountStore* modest_tny_account_store_new (ModestAccountMgr *account_mgr,
+ TnyDevice *device);
/**
gchar *content_type;
/* Create new msg */
- fact = modest_tny_platform_factory_get_instance ();
+ fact = modest_runtime_get_platform_factory ();
new_msg = tny_platform_factory_new_msg (fact);
header = tny_platform_factory_new_header (fact);
{
TnyMimePart *text_body_part = NULL;
TnyStream *text_body_stream;
- TnyPlatformFactory *fact;
-
- fact = modest_tny_platform_factory_get_instance ();
/* Create the stream */
text_body_stream = TNY_STREAM (tny_camel_stream_new
/* Create body part if needed */
if (has_attachments)
- text_body_part = tny_platform_factory_new_mime_part (fact);
+ text_body_part = tny_platform_factory_new_mime_part
+ (modest_runtime_get_platform_factory ());
else
text_body_part = TNY_MIME_PART(msg);
const gchar *attachment_content_type;
const gchar *attachment_filename;
TnyStream *attachment_stream;
- TnyPlatformFactory *fact;
- fact = modest_tny_platform_factory_get_instance ();
for (pos = (GList *)attachments_list; pos; pos = pos->next) {
old_attachment = pos->data;
attachment_filename = tny_mime_part_get_filename (old_attachment);
attachment_stream = tny_mime_part_get_stream (old_attachment);
- attachment_part = tny_platform_factory_new_mime_part (fact);
+ attachment_part = tny_platform_factory_new_mime_part (
+ modest_runtime_get_platform_factory());
attachment_content_type = tny_mime_part_get_content_type (old_attachment);
modest_tny_platform_factory_new_account_store (TnyPlatformFactory *self)
{
return TNY_ACCOUNT_STORE(modest_tny_account_store_new
- (modest_runtime_get_account_mgr()));
+ (modest_runtime_get_account_mgr(),
+ modest_runtime_get_device()));
}
static TnyDevice *
void
modest_ui_actions_on_send_receive (GtkWidget *widget, ModestWindow *win)
{
- TnyDevice *device;
- TnyAccountStore *account_store;
gchar *account_name;
TnyAccount *tny_account;
ModestTnySendQueue *send_queue;
- /* Get device. Do not ask the platform factory for it, because
- it returns always a new one */
- account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
- device = tny_account_store_get_device (account_store);
-
account_name =
g_strdup(modest_window_get_active_account(MODEST_WINDOW(win)));
if (!account_name)
g_printerr ("modest: cannot get account\n");
return;
}
-
+
tny_account =
modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
- account_name, TNY_ACCOUNT_TYPE_TRANSPORT);
+ account_name,
+ TNY_ACCOUNT_TYPE_TRANSPORT);
if (!tny_account) {
g_printerr ("modest: cannot get tny transport account\n");
return;
GtkWidget *dialog;
gchar *txt, *item;
gboolean online;
- TnyDevice *device;
- TnyAccountStore *account_store;
item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
- /* Get device. Do not ask the platform factory for it, because
- it returns always a new one */
- account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
- device = tny_account_store_get_device (account_store);
-
if (g_main_depth > 0)
gdk_threads_enter ();
- online = tny_device_is_online (device);
+ online = tny_device_is_online (modest_runtime_get_device());
if (online) {
/* already online -- the item is simply not there... */
gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- tny_device_force_online (device);
+ tny_device_force_online (modest_runtime_get_device());
}
}
gtk_widget_destroy (dialog);