* Implemented Autoupdate Global setting
authorSergio Villar Senin <svillar@igalia.com>
Fri, 11 May 2007 13:32:25 +0000 (13:32 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Fri, 11 May 2007 13:32:25 +0000 (13:32 +0000)
* Fixed a compilation error in OSSO1.1 due to a change in an enum value since Bora

pmo-trunk-r1838

src/gnome/modest-gnome-global-settings-dialog.c
src/maemo/modest-maemo-global-settings-dialog.c
src/maemo/modest-main-window.c
src/modest-platform.h
src/modest-ui-actions.c
src/widgets/modest-global-settings-dialog-priv.h
src/widgets/modest-global-settings-dialog.c
src/widgets/modest-global-settings-dialog.h

index ba50f27..7549b08 100644 (file)
@@ -62,6 +62,7 @@ enum {
 
 static GtkWidget* create_updating_page  (ModestGnomeGlobalSettingsDialog *self);
 static GtkWidget* create_composing_page (ModestGnomeGlobalSettingsDialog *self);
+static ModestConnectedVia current_connection (void);
 
 typedef struct _ModestGnomeGlobalSettingsDialogPrivate ModestGnomeGlobalSettingsDialogPrivate;
 struct _ModestGnomeGlobalSettingsDialogPrivate {
@@ -109,6 +110,8 @@ modest_gnome_global_settings_dialog_class_init (ModestGnomeGlobalSettingsDialogC
        gobject_class->finalize = modest_gnome_global_settings_dialog_finalize;
 
        g_type_class_add_private (gobject_class, sizeof(ModestGnomeGlobalSettingsDialogPrivate));
+
+       MODEST_GLOBAL_SETTINGS_DIALOG_CLASS (klass)->current_connection_func = current_connection;
 }
 
 static void
@@ -282,3 +285,9 @@ create_composing_page (ModestGnomeGlobalSettingsDialog *self)
 
        return vbox;
 }
+
+static ModestConnectedVia 
+current_connection (void)
+{
+       return MODEST_CONNECTED_VIA_ANY;
+}
index dabf556..1d3d6c5 100644 (file)
 #endif /*MODEST_HILDON_VERSION_0*/
 
 #include <glib/gi18n.h>
+#include <string.h>
 #include <gtk/gtkbox.h>
 #include <gtk/gtkvbox.h>
 #include <gtk/gtknotebook.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtkcheckbutton.h>
 #include <gtk/gtkhseparator.h>
+#include "modest-runtime.h"
 #include "widgets/modest-global-settings-dialog-priv.h"
 #include "widgets/modest-combo-box.h"
 #include "maemo/modest-maemo-global-settings-dialog.h"
 #include "widgets/modest-ui-constants.h"
+#include <tny-account-store.h>
+#include <tny-maemo-conic-device.h>
 
 #define MSG_SIZE_MAX_VAL 5000
 #define MSG_SIZE_DEF_VAL 1000
@@ -62,6 +66,8 @@ static void modest_maemo_global_settings_dialog_class_init (ModestMaemoGlobalSet
 static void modest_maemo_global_settings_dialog_init       (ModestMaemoGlobalSettingsDialog *obj);
 static void modest_maemo_global_settings_dialog_finalize   (GObject *obj);
 
+static ModestConnectedVia current_connection (void);
+
 /* list my signals  */
 enum {
        /* MY_SIGNAL_1, */
@@ -125,6 +131,8 @@ modest_maemo_global_settings_dialog_class_init (ModestMaemoGlobalSettingsDialogC
        gobject_class->finalize = modest_maemo_global_settings_dialog_finalize;
 
        g_type_class_add_private (gobject_class, sizeof(ModestMaemoGlobalSettingsDialogPrivate));
+
+       MODEST_GLOBAL_SETTINGS_DIALOG_CLASS (klass)->current_connection_func = current_connection;
 }
 
 static void
@@ -147,7 +155,7 @@ modest_maemo_global_settings_dialog_init (ModestMaemoGlobalSettingsDialog *self)
        gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->vbox), MODEST_MARGIN_HALF);
 
        /* Load current config */
-       _modest_global_settings_dialog_load_conf (ppriv);
+       _modest_global_settings_dialog_load_conf (MODEST_GLOBAL_SETTINGS_DIALOG (self));
        gtk_widget_show_all (ppriv->notebook);
 }
 
@@ -295,15 +303,19 @@ on_auto_update_toggled (GtkToggleButton *togglebutton,
                        gpointer user_data)
 {
        ModestGlobalSettingsDialogPrivate *ppriv;
-       GtkWidget *caption;
+       GtkWidget *caption1, *caption2;
 
        ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data);
-       caption = gtk_widget_get_ancestor (ppriv->connect_via, HILDON_TYPE_CAPTION);
-
-       if (gtk_toggle_button_get_active (togglebutton))
-               gtk_widget_set_sensitive (caption, TRUE);
-       else
-               gtk_widget_set_sensitive (caption, FALSE);
+       caption1 = gtk_widget_get_ancestor (ppriv->connect_via, HILDON_TYPE_CAPTION);
+       caption2 = gtk_widget_get_ancestor (ppriv->update_interval, HILDON_TYPE_CAPTION);
+
+       if (gtk_toggle_button_get_active (togglebutton)) {
+               gtk_widget_set_sensitive (caption1, TRUE);
+               gtk_widget_set_sensitive (caption2, TRUE);
+       } else {
+               gtk_widget_set_sensitive (caption1, FALSE);
+               gtk_widget_set_sensitive (caption2, FALSE);
+       }
 }
 
 static gboolean
@@ -315,15 +327,27 @@ on_range_error (HildonNumberEditor *editor,
        gint new_val;
 
        switch (type) {
+#ifdef MODEST_HILDON_VERSION_0
        case MAXIMUM_VALUE_EXCEED:
+#else
+       case HILDON_NUMBER_EDITOR_ERROR_MAXIMUM_VALUE_EXCEED:
+#endif
                msg = g_strdup_printf (_("ckct_ib_maximum_value"), MSG_SIZE_MAX_VAL);
                new_val = MSG_SIZE_MAX_VAL;
                break;
+#ifdef MODEST_HILDON_VERSION_0
        case MINIMUM_VALUE_EXCEED:
+#else
+       case HILDON_NUMBER_EDITOR_ERROR_MINIMUM_VALUE_EXCEED:
+#endif
                msg = g_strdup_printf (_("ckct_ib_minimum_value"), MSG_SIZE_MIN_VAL);
                new_val = MSG_SIZE_MIN_VAL;
                break;
+#ifdef MODEST_HILDON_VERSION_0
        case ERRONEOUS_VALUE:
+#else
+       case HILDON_NUMBER_EDITOR_ERROR_ERRONEOUS_VALUE:
+#endif
                msg = g_strdup_printf (_("ckct_ib_set_a_value_within_range"), 
                                       MSG_SIZE_MIN_VAL, 
                                       MSG_SIZE_MAX_VAL);
@@ -345,3 +369,32 @@ on_range_error (HildonNumberEditor *editor,
 
        return TRUE;
 }
+
+static ModestConnectedVia
+current_connection (void)
+{
+       TnyAccountStore *account_store;
+       TnyDevice *device;
+       gboolean retval;
+       const gchar *bearer_type, *iap_id;
+       ConIcIap *iap;
+       
+       account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
+       device = tny_account_store_get_device (account_store);
+
+       /* Get iap id */
+       iap_id = tny_maemo_conic_device_get_current_iap_id (TNY_MAEMO_CONIC_DEVICE (device));
+       iap = tny_maemo_conic_device_get_iap (TNY_MAEMO_CONIC_DEVICE (device), iap_id);
+       bearer_type = con_ic_iap_get_bearer_type (iap);
+               
+       if (!strcmp (bearer_type, CON_IC_BEARER_WLAN_INFRA) ||
+           !strcmp (bearer_type, CON_IC_BEARER_WLAN_ADHOC))
+               retval = MODEST_CONNECTED_VIA_WLAN;
+       else
+               retval = MODEST_CONNECTED_VIA_ANY;
+
+       g_object_unref (iap);
+       g_object_unref (device);
+
+       return retval;
+}
index b2aa04f..4fecac8 100644 (file)
@@ -317,12 +317,12 @@ restore_settings (ModestMainWindow *self)
 
        conf = modest_runtime_get_conf ();
        
+       modest_widget_memory_restore (conf, G_OBJECT(self), 
+                                     MODEST_CONF_MAIN_WINDOW_KEY);
        modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
                                      MODEST_CONF_MAIN_PANED_KEY);
        modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
                                      MODEST_CONF_HEADER_VIEW_KEY);
-       modest_widget_memory_restore (conf, G_OBJECT(self), 
-                                     MODEST_CONF_MAIN_WINDOW_KEY);
 }
 
 
index e6f94bd..8bea9e5 100644 (file)
@@ -201,7 +201,15 @@ gboolean modest_platform_connect_and_wait (GtkWindow *parent_window);
  **/
 gboolean modest_platform_set_update_interval (guint minutes);
 
-GtkWidget* modest_platform_get_global_settings_dialog ();
+/**
+ * modest_platform_get_global_settings_dialog:
+ * @void: 
+ * 
+ * returns the global settings dialog
+ * 
+ * Return value: a new #ModestGlobalSettingsDialog dialog
+ **/
+GtkWidget* modest_platform_get_global_settings_dialog (void);
 
 G_END_DECLS
 
index aeef9aa..61c76ac 100644 (file)
@@ -2531,17 +2531,12 @@ modest_ui_actions_on_settings (GtkAction *action,
                               ModestWindow *win)
 {
        GtkWidget *dialog;
-       gint response;
 
        dialog = modest_platform_get_global_settings_dialog ();
        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
        gtk_widget_show (dialog);
 
-       response = gtk_dialog_run (GTK_DIALOG (dialog));
-
-       if (response == GTK_RESPONSE_ACCEPT) {
-               g_message ("YES");
-       }
+       gtk_dialog_run (GTK_DIALOG (dialog));
 
        gtk_widget_destroy (dialog);
 }
index ca1f6f5..de50041 100644 (file)
@@ -71,9 +71,6 @@ ModestPairList*   _modest_global_settings_dialog_get_connected_via   (void);
 ModestPairList*   _modest_global_settings_dialog_get_update_interval (void);
 ModestPairList*   _modest_global_settings_dialog_get_msg_formats     (void);
 
-void     _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *priv);
-gboolean _modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv);
-
 G_END_DECLS
 
 #endif /* __MODEST_GLOBAL_SETTINGS_DIALOG_PRIV_H__ */
index 47ff698..f77fc94 100644 (file)
@@ -63,6 +63,8 @@ static void on_response (GtkDialog *dialog,
 static void get_current_settings (ModestGlobalSettingsDialogPrivate *priv, 
                                  ModestGlobalSettingsState *state);
 
+static ModestConnectedVia current_connection_default (void);
+
 /* list my signals  */
 enum {
        /* MY_SIGNAL_1, */
@@ -110,6 +112,8 @@ modest_global_settings_dialog_class_init (ModestGlobalSettingsDialogClass *klass
        gobject_class->finalize = modest_global_settings_dialog_finalize;
 
        g_type_class_add_private (gobject_class, sizeof(ModestGlobalSettingsDialogPrivate));
+
+       klass->current_connection_func = current_connection_default;
 }
 
 static void
@@ -237,13 +241,15 @@ _modest_global_settings_dialog_get_msg_formats (void)
 }
 
 void   
-_modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialogPrivate *priv)
+_modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialog *self)
 {
        ModestConf *conf;
        gboolean checked;
        gint combo_id, value;
        GError *error = NULL;
+       ModestGlobalSettingsDialogPrivate *priv;
 
+       priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
        conf = modest_runtime_get_conf ();
 
        /* Autoupdate */
@@ -357,11 +363,14 @@ get_current_settings (ModestGlobalSettingsDialogPrivate *priv,
 }
 
 gboolean
-_modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *priv)
+_modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialog *self)
 {
        ModestConf *conf;
        ModestGlobalSettingsState current_state;
        GError *error = NULL;
+       ModestGlobalSettingsDialogPrivate *priv;
+
+       priv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self);
 
        conf = modest_runtime_get_conf ();
 
@@ -385,6 +394,48 @@ _modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialogPrivate *pri
                             MODEST_TNY_MSG_REPLY_TYPE_CITE, NULL);
        RETURN_FALSE_ON_ERROR(error);
 
+       /* Apply changes */
+       if (priv->initial_state.auto_update != current_state.auto_update || 
+           priv->initial_state.connect_via != current_state.connect_via ||
+           priv->initial_state.update_interval != current_state.update_interval) {
+
+               TnyAccountStore *account_store;
+               TnyDevice *device;
+
+               if (!current_state.auto_update) {
+                       modest_platform_set_update_interval (0);
+                       /* To avoid a new indentation level */
+                       goto exit;
+               }
+
+               account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
+               device = tny_account_store_get_device (account_store);
+
+               if (tny_device_is_online (device)) {
+                       /* If connected via any then set update interval */
+                       if (current_state.connect_via == MODEST_CONNECTED_VIA_ANY) {
+                               modest_platform_set_update_interval (current_state.update_interval);
+                       } else {
+                               /* Set update interval only if we
+                                  selected the same connect_via
+                                  method than the one already used by
+                                  the device */
+                               ModestConnectedVia connect_via = 
+                                       MODEST_GLOBAL_SETTINGS_DIALOG_GET_CLASS(self)->current_connection_func ();
+                               
+                               if (current_state.connect_via == connect_via)
+                                       modest_platform_set_update_interval (current_state.update_interval);
+                               else
+                                       modest_platform_set_update_interval (0);
+                       }
+               } else {
+                       /* Disable autoupdate in offline mode */
+                       modest_platform_set_update_interval (0);
+               }
+               g_object_unref (device);                
+       }
+
+exit:
        return TRUE;
 }
 
@@ -422,13 +473,14 @@ on_response (GtkDialog *dialog,
                if (changed) {
                        gboolean saved;
 
-                       saved = _modest_global_settings_dialog_save_conf (priv);
-                       if (saved)
+                       saved = _modest_global_settings_dialog_save_conf (MODEST_GLOBAL_SETTINGS_DIALOG (dialog));
+                       if (saved) {
                                modest_platform_run_information_dialog (GTK_WINDOW (user_data),
                                                                        _("mcen_ib_advsetup_settings_saved"));
-                       else
+                       } else {
                                modest_platform_run_information_dialog (GTK_WINDOW (user_data),
                                                                        _("mail_ib_setting_failed"));
+                       }
                }
        } else {
                if (changed) {
@@ -441,3 +493,10 @@ on_response (GtkDialog *dialog,
                }
        }
 }
+
+static ModestConnectedVia 
+current_connection_default (void)
+{
+       g_warning ("You must implement %s", __FUNCTION__);
+       g_return_val_if_reached (-1);
+}
index d1338ef..c734faf 100644 (file)
@@ -44,6 +44,21 @@ G_BEGIN_DECLS
 #define MODEST_IS_GLOBAL_SETTINGS_DIALOG_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_GLOBAL_SETTINGS_DIALOG))
 #define MODEST_GLOBAL_SETTINGS_DIALOG_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_GLOBAL_SETTINGS_DIALOG,ModestGlobalSettingsDialogClass))
 
+/* Global settings */
+typedef enum _ModestConnectedVia {
+       MODEST_CONNECTED_VIA_WLAN = 1,
+       MODEST_CONNECTED_VIA_ANY,
+} ModestConnectedVia;
+
+typedef enum _ModestUpdateInterval {
+       MODEST_UPDATE_INTERVAL_5_MIN = 5,
+       MODEST_UPDATE_INTERVAL_10_MIN = 10,
+       MODEST_UPDATE_INTERVAL_15_MIN = 15,
+       MODEST_UPDATE_INTERVAL_30_MIN = 30,
+       MODEST_UPDATE_INTERVAL_1_HOUR = 60,
+       MODEST_UPDATE_INTERVAL_2_HOUR = 120
+} ModestUpdateInterval;
+
 typedef struct _ModestGlobalSettingsDialog      ModestGlobalSettingsDialog;
 typedef struct _ModestGlobalSettingsDialogClass ModestGlobalSettingsDialogClass;
 
@@ -53,26 +68,21 @@ struct _ModestGlobalSettingsDialog {
 
 struct _ModestGlobalSettingsDialogClass {
        GtkDialogClass parent_class;
-};
 
-/* Global settings */
-typedef enum _ModestConnectedVia {
-       MODEST_CONNECTED_VIA_WLAN,
-       MODEST_CONNECTED_VIA_ANY
-} ModestConnectedVia;
-
-typedef enum _ModestUpdateInterval {
-       MODEST_UPDATE_INTERVAL_5_MIN,
-       MODEST_UPDATE_INTERVAL_10_MIN,
-       MODEST_UPDATE_INTERVAL_15_MIN,
-       MODEST_UPDATE_INTERVAL_30_MIN,
-       MODEST_UPDATE_INTERVAL_1_HOUR,
-       MODEST_UPDATE_INTERVAL_2_HOUR
-} ModestUpdateInterval;
+       /* Returns the current connection method. Assumes that the device is online */
+       ModestConnectedVia (*current_connection_func) (void);
+};
 
 /* member functions */
 GType        modest_global_settings_dialog_get_type    (void) G_GNUC_CONST;
 
+/* Do *NOT* use this functions directly. They must be only used by
+   subclasses. We put them here and not in the -priv header file
+   because recursive dependencies */
+void     _modest_global_settings_dialog_load_conf (ModestGlobalSettingsDialog *self);
+gboolean _modest_global_settings_dialog_save_conf (ModestGlobalSettingsDialog *self);
+
+
 G_END_DECLS
 
 #endif /* __MODEST_GLOBAL_SETTINGS_DIALOG_H__ */