Bugfix for 80400, introduction of connection policies
authorPhilip Van Hoof <philip@codeminded.be>
Mon, 31 Mar 2008 10:32:37 +0000 (10:32 +0000)
committerPhilip Van Hoof <philip@codeminded.be>
Mon, 31 Mar 2008 10:32:37 +0000 (10:32 +0000)
pmo-trunk-r4353

src/Makefile.am
src/modest-default-connection-policy.c [new file with mode: 0644]
src/modest-default-connection-policy.h [new file with mode: 0644]
src/modest-tny-account.c

index adc3006..ab62fb8 100644 (file)
@@ -128,7 +128,9 @@ modest_SOURCES=\
        modest-utils.h \
        modest-widget-memory-priv.h \
        modest-widget-memory.c \
        modest-utils.h \
        modest-widget-memory-priv.h \
        modest-widget-memory.c \
-       modest-widget-memory.h 
+       modest-widget-memory.h \
+       modest-default-connection-policy.c \
+       modest-default-connection-policy.h 
 
 if MODEST_USE_DUMMY_ADDRESS_BOOK
 modest_SOURCES += modest-address-book-dummy.c
 
 if MODEST_USE_DUMMY_ADDRESS_BOOK
 modest_SOURCES += modest-address-book-dummy.c
diff --git a/src/modest-default-connection-policy.c b/src/modest-default-connection-policy.c
new file mode 100644 (file)
index 0000000..eac9e22
--- /dev/null
@@ -0,0 +1,123 @@
+/* Your copyright here */
+
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+#define MODEST_DEFAULT_CONNECTION_POLICY_C
+gboolean exiting = FALSE;
+#include <modest-default-connection-policy.h>
+#undef MODEST_DEFAULT_CONNECTION_POLICY_C
+
+#include <tny-account.h>
+
+static GObjectClass *parent_class = NULL;
+
+static void
+modest_default_connection_policy_set_current (TnyConnectionPolicy *self, TnyAccount *account, TnyFolder *folder)
+{
+       return;
+}
+
+static void
+modest_default_connection_policy_on_connect (TnyConnectionPolicy *self, TnyAccount *account)
+{
+       return;
+}
+
+static void
+modest_default_connection_policy_on_connection_broken (TnyConnectionPolicy *self, TnyAccount *account)
+{
+       return;
+}
+
+static void
+modest_default_connection_policy_on_disconnect (TnyConnectionPolicy *self, TnyAccount *account)
+{
+       tny_account_cancel (account);
+       return;
+}
+
+static void
+modest_default_connection_policy_finalize (GObject *object)
+{
+       parent_class->finalize (object);
+}
+
+static void
+modest_default_connection_policy_instance_init (GTypeInstance *instance, gpointer g_class)
+{
+}
+
+static void
+tny_connection_policy_init (TnyConnectionPolicyIface *klass)
+{
+       klass->on_connect= modest_default_connection_policy_on_connect;
+       klass->on_connection_broken= modest_default_connection_policy_on_connection_broken;
+       klass->on_disconnect= modest_default_connection_policy_on_disconnect;
+       klass->set_current= modest_default_connection_policy_set_current;
+}
+
+static void
+modest_default_connection_policy_class_init (ModestDefaultConnectionPolicyClass *klass)
+{
+       GObjectClass *object_class;
+
+       parent_class = g_type_class_peek_parent (klass);
+       object_class = (GObjectClass*) klass;
+       object_class->finalize = modest_default_connection_policy_finalize;
+}
+
+
+
+/**
+ * modest_default_connection_policy_new:
+ * 
+ * A connection policy
+ *
+ * Return value: A new #TnyConnectionPolicy instance 
+ **/
+TnyConnectionPolicy*
+modest_default_connection_policy_new (void)
+{
+       return TNY_CONNECTION_POLICY (g_object_new (MODEST_TYPE_DEFAULT_CONNECTION_POLICY, NULL));
+}
+
+GType
+modest_default_connection_policy_get_type (void)
+{
+       static GType type = 0;
+       if (G_UNLIKELY(type == 0))
+       {
+               static const GTypeInfo info = 
+               {
+                       sizeof (ModestDefaultConnectionPolicyClass),
+                       NULL,   /* base_init */
+                       NULL,   /* base_finalize */
+                       (GClassInitFunc) modest_default_connection_policy_class_init,   /* class_init */
+                       NULL,   /* class_finalize */
+                       NULL,   /* class_data */
+                       sizeof (ModestDefaultConnectionPolicy),
+                       0,      /* n_preallocs */
+                       modest_default_connection_policy_instance_init,    /* instance_init */
+                       NULL
+               };
+
+
+               static const GInterfaceInfo tny_connection_policy_info = 
+               {
+                       (GInterfaceInitFunc) tny_connection_policy_init, /* interface_init */
+                       NULL,         /* interface_finalize */
+                       NULL          /* interface_data */
+               };
+
+               type = g_type_register_static (G_TYPE_OBJECT,
+                       "ModestDefaultConnectionPolicy",
+                       &info, 0);
+
+               g_type_add_interface_static (type, TNY_TYPE_CONNECTION_POLICY,
+                       &tny_connection_policy_info);
+
+       }
+       return type;
+}
diff --git a/src/modest-default-connection-policy.h b/src/modest-default-connection-policy.h
new file mode 100644 (file)
index 0000000..ee8c4b4
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef MODEST_DEFAULT_CONNECTION_POLICY_H
+#define MODEST_DEFAULT_CONNECTION_POLICY_H
+
+#include <glib-object.h>
+
+#include <tny-connection-policy.h>
+
+G_BEGIN_DECLS
+
+#define MODEST_TYPE_DEFAULT_CONNECTION_POLICY             (modest_default_connection_policy_get_type ())
+#define MODEST_DEFAULT_CONNECTION_POLICY(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), MODEST_TYPE_DEFAULT_CONNECTION_POLICY, ModestDefaultConnectionPolicy))
+#define MODEST_DEFAULT_CONNECTION_POLICY_CLASS(vtable)    (G_TYPE_CHECK_CLASS_CAST ((vtable), MODEST_TYPE_DEFAULT_CONNECTION_POLICY, ModestDefaultConnectionPolicyClass))
+#define MODEST_IS_DEFAULT_CONNECTION_POLICY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MODEST_TYPE_DEFAULT_CONNECTION_POLICY))
+#define MODEST_IS_DEFAULT_CONNECTION_POLICY_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), MODEST_TYPE_DEFAULT_CONNECTION_POLICY))
+#define MODEST_DEFAULT_CONNECTION_POLICY_GET_CLASS(inst)  (G_TYPE_INSTANCE_GET_CLASS ((inst), MODEST_TYPE_DEFAULT_CONNECTION_POLICY, ModestDefaultConnectionPolicyClass))
+
+typedef struct _ModestDefaultConnectionPolicy ModestDefaultConnectionPolicy;
+typedef struct _ModestDefaultConnectionPolicyClass ModestDefaultConnectionPolicyClass;
+
+
+struct _ModestDefaultConnectionPolicy
+{
+       GObject parent;
+
+};
+
+struct _ModestDefaultConnectionPolicyClass
+{
+       GObjectClass parent_class;
+};
+
+GType modest_default_connection_policy_get_type (void);
+TnyConnectionPolicy* modest_default_connection_policy_new (void);
+
+G_END_DECLS
+
+#endif
index 679884a..2496a16 100644 (file)
@@ -31,6 +31,7 @@
 #include <modest-tny-platform-factory.h>
 #include <modest-tny-account.h>
 #include <modest-tny-account-store.h>
 #include <modest-tny-platform-factory.h>
 #include <modest-tny-account.h>
 #include <modest-tny-account-store.h>
+#include <modest-default-connection-policy.h>
 #include <modest-tny-local-folders-account.h>
 #include <modest-runtime.h>
 #include <tny-simple-list.h>
 #include <modest-tny-local-folders-account.h>
 #include <modest-runtime.h>
 #include <tny-simple-list.h>
@@ -433,7 +434,9 @@ modest_tny_account_new_from_server_account_name (ModestAccountMgr *account_mgr,
                tny_account_set_pass_func (tny_account,
                                           get_pass_func ? get_pass_func: get_pass_dummy);
        }
                tny_account_set_pass_func (tny_account,
                                           get_pass_func ? get_pass_func: get_pass_dummy);
        }
-       
+
+       tny_account_set_connection_policy (tny_account, modest_default_connection_policy_new ());
+
        g_object_unref (server_settings);
        
        return tny_account;
        g_object_unref (server_settings);
        
        return tny_account;
@@ -532,6 +535,8 @@ modest_tny_account_update_from_account (TnyAccount *tny_account,
                                          forget_pass_func ? forget_pass_func : forget_pass_dummy);
        tny_account_set_pass_func (tny_account,
                                   get_pass_func ? get_pass_func: get_pass_dummy);
                                          forget_pass_func ? forget_pass_func : forget_pass_dummy);
        tny_account_set_pass_func (tny_account,
                                   get_pass_func ? get_pass_func: get_pass_dummy);
+
+       tny_account_set_connection_policy (tny_account, modest_default_connection_policy_new ());
        
        /* The callback will have an error for you if the reconnect
         * failed. Please handle it (this is TODO). */
        
        /* The callback will have an error for you if the reconnect
         * failed. Please handle it (this is TODO). */
@@ -619,7 +624,9 @@ modest_tny_account_new_from_account (ModestAccountMgr *account_mgr,
                                          forget_pass_func ? forget_pass_func : forget_pass_dummy);
        tny_account_set_pass_func (tny_account,
                                   get_pass_func ? get_pass_func: get_pass_dummy);
                                          forget_pass_func ? forget_pass_func : forget_pass_dummy);
        tny_account_set_pass_func (tny_account,
                                   get_pass_func ? get_pass_func: get_pass_dummy);
-       
+
+       tny_account_set_connection_policy (tny_account, modest_default_connection_policy_new ());
+
         modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account,
                                                                              account_name);
        g_object_unref (server_settings);
         modest_tny_account_set_parent_modest_account_name_for_server_account (tny_account,
                                                                              account_name);
        g_object_unref (server_settings);
@@ -811,7 +818,9 @@ modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySess
        
        tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
        tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
        
        tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
        tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
-       
+
+       tny_account_set_connection_policy (TNY_ACCOUNT (tny_account), modest_default_connection_policy_new ()); 
+
        modest_tny_account_set_parent_modest_account_name_for_server_account (
                TNY_ACCOUNT (tny_account), id);
        
        modest_tny_account_set_parent_modest_account_name_for_server_account (
                TNY_ACCOUNT (tny_account), id);
        
@@ -881,7 +890,9 @@ modest_tny_account_new_for_per_account_local_outbox_folder (ModestAccountMgr *ac
        
        tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
        tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
        
        tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
        tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
-       
+
+       tny_account_set_connection_policy (TNY_ACCOUNT (tny_account), modest_default_connection_policy_new ());
+
        /* Make this think that it belongs to the modest local-folders parent account: */
        modest_tny_account_set_parent_modest_account_name_for_server_account (
                TNY_ACCOUNT (tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
        /* Make this think that it belongs to the modest local-folders parent account: */
        modest_tny_account_set_parent_modest_account_name_for_server_account (
                TNY_ACCOUNT (tny_account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID);