X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-maemo-global-settings-dialog.c;h=3d192eabe75ee5e23490b5ed8d61814677219db6;hp=e262409afa08b9ac7e9a08844046747b34c1226e;hb=c45f7efd716c1779f74ef6b78a507537828372a9;hpb=9370ef584b364e702445220330867f28181b480b diff --git a/src/maemo/modest-maemo-global-settings-dialog.c b/src/maemo/modest-maemo-global-settings-dialog.c index e262409..3d192ea 100644 --- a/src/maemo/modest-maemo-global-settings-dialog.c +++ b/src/maemo/modest-maemo-global-settings-dialog.c @@ -31,15 +31,8 @@ #include #endif /*HAVE_CONFIG_H*/ -#ifdef MODEST_HILDON_VERSION_0 -#include -#include -#include -#else -#include -#include -#include -#endif /*MODEST_HILDON_VERSION_0*/ +#include +#include #include #include @@ -55,12 +48,14 @@ #include "maemo/modest-maemo-global-settings-dialog.h" #include "widgets/modest-ui-constants.h" #include -#include + #define MSG_SIZE_MAX_VAL 5000 #define MSG_SIZE_DEF_VAL 1000 #define MSG_SIZE_MIN_VAL 1 +#define DEFAULT_FOCUS_WIDGET "default-focus-widget" + /* 'private'/'protected' functions */ static void modest_maemo_global_settings_dialog_class_init (ModestMaemoGlobalSettingsDialogClass *klass); static void modest_maemo_global_settings_dialog_init (ModestMaemoGlobalSettingsDialog *obj); @@ -82,11 +77,21 @@ static gboolean on_range_error (HildonNumberEditor *editor, HildonNumberEditorErrorType type, gpointer user_data); +static void on_size_notify (HildonNumberEditor *editor, + GParamSpec *arg1, + gpointer user_data); + static void on_auto_update_toggled (GtkToggleButton *togglebutton, gpointer user_data); +static gboolean on_inner_tabs_key_pressed (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data); + typedef struct _ModestMaemoGlobalSettingsDialogPrivate ModestMaemoGlobalSettingsDialogPrivate; struct _ModestMaemoGlobalSettingsDialogPrivate { + ModestPairList *connect_via_list; + gint switch_handler; }; #define MODEST_MAEMO_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_MAEMO_GLOBAL_SETTINGS_DIALOG, \ @@ -135,33 +140,130 @@ modest_maemo_global_settings_dialog_class_init (ModestMaemoGlobalSettingsDialogC MODEST_GLOBAL_SETTINGS_DIALOG_CLASS (klass)->current_connection_func = current_connection; } +typedef struct { + ModestMaemoGlobalSettingsDialog *dia; + GtkWidget *focus_widget; +} SwitchPageHelper; + +static gboolean +idle_select_default_focus (gpointer data) +{ + ModestGlobalSettingsDialogPrivate *ppriv; + ModestMaemoGlobalSettingsDialogPrivate *priv; + SwitchPageHelper *helper; + + helper = (SwitchPageHelper *) data; + priv = MODEST_MAEMO_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (helper->dia); + ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (helper->dia); + + /* Grab focus, we need to block in order to prevent a + recursive call to this callback */ + g_signal_handler_block (G_OBJECT (ppriv->notebook), priv->switch_handler); + + /* This is a GDK lock because we are an idle callback and + * the code below is or does Gtk+ code */ + + gdk_threads_enter (); /* CHECKED */ + gtk_widget_grab_focus (helper->focus_widget); + gdk_threads_leave (); /* CHECKED */ + + g_signal_handler_unblock (G_OBJECT (ppriv->notebook), priv->switch_handler); + g_free (helper); + + return FALSE; +} + + +static void +on_switch_page (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data) +{ + /* grab the focus to the default element in the current page */ + GtkWidget *selected_page = NULL, *focus_item = NULL; + SwitchPageHelper *helper; + + selected_page = gtk_notebook_get_nth_page (notebook, page_num); + focus_item = GTK_WIDGET(g_object_get_data (G_OBJECT(selected_page), DEFAULT_FOCUS_WIDGET)); + if (!focus_item) { + g_printerr ("modest: cannot get focus item\n"); + return; + } + + /* Create the helper */ + helper = g_malloc0 (sizeof (SwitchPageHelper)); + helper->dia = MODEST_MAEMO_GLOBAL_SETTINGS_DIALOG (user_data); + helper->focus_widget = focus_item; + + /* Focus the widget in an idle. We need to do this in an idle, + because this handler is executed *before* the page was + really switched, so the focus is not placed in the right + widget */ + g_idle_add (idle_select_default_focus, helper); +} + + static void modest_maemo_global_settings_dialog_init (ModestMaemoGlobalSettingsDialog *self) { + ModestMaemoGlobalSettingsDialogPrivate *priv; ModestGlobalSettingsDialogPrivate *ppriv; + priv = MODEST_MAEMO_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self); ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self); ppriv->updating_page = create_updating_page (self); ppriv->composing_page = create_composing_page (self); - + + /* Add the buttons: */ + gtk_dialog_add_button (GTK_DIALOG (self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK); + gtk_dialog_add_button (GTK_DIALOG (self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL); + + /* Set the default focusable widgets */ + g_object_set_data (G_OBJECT(ppriv->updating_page), DEFAULT_FOCUS_WIDGET, + (gpointer)ppriv->auto_update); + g_object_set_data (G_OBJECT(ppriv->composing_page), DEFAULT_FOCUS_WIDGET, + (gpointer)ppriv->msg_format); + /* Add the notebook pages: */ gtk_notebook_append_page (GTK_NOTEBOOK (ppriv->notebook), ppriv->updating_page, - gtk_label_new (_("mcen_ti_options_updating"))); + gtk_label_new (_("mcen_ti_options_updating"))); gtk_notebook_append_page (GTK_NOTEBOOK (ppriv->notebook), ppriv->composing_page, - gtk_label_new (_("mcen_ti_options_composing"))); + gtk_label_new (_("mcen_ti_options_composing"))); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), ppriv->notebook); gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (self)->vbox), MODEST_MARGIN_HALF); + gtk_window_set_default_size (GTK_WINDOW (self), 700, 300); + + g_signal_connect (G_OBJECT (self), "key-press-event", + G_CALLBACK (on_inner_tabs_key_pressed), self); + priv->switch_handler = g_signal_connect (G_OBJECT(ppriv->notebook), "switch-page", + G_CALLBACK(on_switch_page), self); + /* Load current config */ _modest_global_settings_dialog_load_conf (MODEST_GLOBAL_SETTINGS_DIALOG (self)); - gtk_widget_show_all (ppriv->notebook); + + /* Set first page */ + gtk_notebook_set_current_page (GTK_NOTEBOOK (ppriv->notebook), 0); + + hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_options_dialog", + modest_maemo_utils_get_osso_context()); } static void modest_maemo_global_settings_dialog_finalize (GObject *obj) { + ModestGlobalSettingsDialogPrivate *ppriv; + ModestMaemoGlobalSettingsDialogPrivate *priv; + + priv = MODEST_MAEMO_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (obj); + ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (obj); + + if (priv->switch_handler && ppriv->notebook) { + /* TODO: This causes a g_warning and a valgrind mem error: */ + /* g_signal_handler_disconnect (G_OBJECT (ppriv->notebook), priv->switch_handler);*/ + priv->switch_handler = 0; + } + /* free/unref instance resources here */ G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -172,7 +274,6 @@ modest_maemo_global_settings_dialog_new (void) return GTK_WIDGET(g_object_new(MODEST_TYPE_MAEMO_GLOBAL_SETTINGS_DIALOG, NULL)); } - /* * Creates the updating page */ @@ -181,10 +282,14 @@ create_updating_page (ModestMaemoGlobalSettingsDialog *self) { GtkWidget *vbox, *vbox_update, *vbox_limit, *caption; GtkSizeGroup *size_group; - ModestPairList *list; ModestGlobalSettingsDialogPrivate *ppriv; + GtkWidget *scrollwin = NULL; + GtkAdjustment *focus_adjustment = NULL; ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self); + scrollwin = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT); @@ -202,9 +307,13 @@ create_updating_page (ModestMaemoGlobalSettingsDialog *self) g_signal_connect (ppriv->auto_update, "toggled", G_CALLBACK (on_auto_update_toggled), self); /* Connected via */ - list = _modest_global_settings_dialog_get_connected_via (); - ppriv->connect_via = modest_combo_box_new (list, g_int_equal); - modest_pair_list_free (list); + + /* Note: This ModestPairList* must exist for as long as the combo + * that uses it, because the ModestComboBox uses the ID opaquely, + * so it can't know how to manage its memory. */ + ppriv->connect_via_list = _modest_global_settings_dialog_get_connected_via (); + ppriv->connect_via = modest_combo_box_new (ppriv->connect_via_list, g_int_equal); + caption = hildon_caption_new (size_group, _("mcen_fi_options_connectiontype"), ppriv->connect_via, @@ -213,9 +322,13 @@ create_updating_page (ModestMaemoGlobalSettingsDialog *self) gtk_box_pack_start (GTK_BOX (vbox_update), caption, FALSE, FALSE, MODEST_MARGIN_HALF); /* Update interval */ - list = _modest_global_settings_dialog_get_update_interval (); - ppriv->update_interval = modest_combo_box_new (list, g_int_equal); - modest_pair_list_free (list); + + /* Note: This ModestPairList* must exist for as long as the combo + * that uses it, because the ModestComboBox uses the ID opaquely, + * so it can't know how to manage its memory. */ + ppriv->update_interval_list = _modest_global_settings_dialog_get_update_interval (); + ppriv->update_interval = modest_combo_box_new (ppriv->update_interval_list, g_int_equal); + caption = hildon_caption_new (size_group, _("mcen_fi_options_updateinterval"), ppriv->update_interval, @@ -234,12 +347,13 @@ create_updating_page (ModestMaemoGlobalSettingsDialog *self) size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); /* Size limit */ - ppriv->size_limit = hildon_number_editor_new (MSG_SIZE_MIN_VAL, MSG_SIZE_MAX_VAL);; - hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (ppriv->size_limit), MSG_SIZE_DEF_VAL);; + ppriv->size_limit = hildon_number_editor_new (MSG_SIZE_MIN_VAL, MSG_SIZE_MAX_VAL); + hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (ppriv->size_limit), MSG_SIZE_DEF_VAL); g_signal_connect (ppriv->size_limit, "range_error", G_CALLBACK (on_range_error), self); + g_signal_connect (ppriv->size_limit, "notify", G_CALLBACK (on_size_notify), self); caption = hildon_caption_new (size_group, _("mcen_fi_advsetup_sizelimit"), - ppriv->size_limit, + ppriv->size_limit, NULL, HILDON_CAPTION_MANDATORY); gtk_box_pack_start (GTK_BOX (vbox_limit), caption, FALSE, FALSE, MODEST_MARGIN_HALF); @@ -255,8 +369,12 @@ create_updating_page (ModestMaemoGlobalSettingsDialog *self) /* Add to vbox */ gtk_box_pack_start (GTK_BOX (vbox), vbox_limit, FALSE, FALSE, MODEST_MARGIN_HALF); - - return vbox; + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), vbox); + focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin)); + gtk_container_set_focus_vadjustment (GTK_CONTAINER (vbox), focus_adjustment); + gtk_widget_show (scrollwin); + + return scrollwin; } /* @@ -268,7 +386,6 @@ create_composing_page (ModestMaemoGlobalSettingsDialog *self) GtkWidget *vbox; GtkSizeGroup *size_group; ModestGlobalSettingsDialogPrivate *ppriv; - ModestPairList *list; GtkWidget *caption; ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (self); @@ -276,9 +393,13 @@ create_composing_page (ModestMaemoGlobalSettingsDialog *self) vbox = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT); /* Update interval */ - list = _modest_global_settings_dialog_get_msg_formats (); - ppriv->msg_format = modest_combo_box_new (list, g_int_equal); - modest_pair_list_free (list); + + /* Note: This ModestPairList* must exist for as long as the combo + * that uses it, because the ModestComboBox uses the ID opaquely, + * so it can't know how to manage its memory. */ + ppriv->msg_format_list = _modest_global_settings_dialog_get_msg_formats (); + ppriv->msg_format = modest_combo_box_new (ppriv->msg_format_list, g_int_equal); + caption = hildon_caption_new (size_group, _("mcen_fi_options_messageformat"), ppriv->msg_format, @@ -286,15 +407,6 @@ create_composing_page (ModestMaemoGlobalSettingsDialog *self) HILDON_CAPTION_MANDATORY); gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, MODEST_MARGIN_HALF); - /* Reply */ - ppriv->include_reply = gtk_check_button_new (); - caption = hildon_caption_new (size_group, - _("mcen_va_options_include_original_inreply"), - ppriv->include_reply, - NULL, - HILDON_CAPTION_MANDATORY); - gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, MODEST_MARGIN_HALF); - return vbox; } @@ -327,28 +439,28 @@ on_range_error (HildonNumberEditor *editor, gint new_val; switch (type) { -#ifdef MODEST_HILDON_VERSION_0 +#ifdef MODEST_HAVE_HILDON0_WIDGETS 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); + msg = g_strdup_printf (dgettext("hildon-libs", "ckct_ib_maximum_value"), MSG_SIZE_MAX_VAL); new_val = MSG_SIZE_MAX_VAL; break; -#ifdef MODEST_HILDON_VERSION_0 +#ifdef MODEST_HAVE_HILDON0_WIDGETS 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); + msg = g_strdup_printf (dgettext("hildon-libs", "ckct_ib_minimum_value"), MSG_SIZE_MIN_VAL); new_val = MSG_SIZE_MIN_VAL; break; -#ifdef MODEST_HILDON_VERSION_0 +#ifdef MODEST_HAVE_HILDON0_WIDGETS case ERRONEOUS_VALUE: #else case HILDON_NUMBER_EDITOR_ERROR_ERRONEOUS_VALUE: #endif - msg = g_strdup_printf (_("ckct_ib_set_a_value_within_range"), + msg = g_strdup_printf (dgettext("hildon-libs", "ckct_ib_set_a_value_within_range"), MSG_SIZE_MIN_VAL, MSG_SIZE_MAX_VAL); /* FIXME: use the previous */ @@ -370,32 +482,42 @@ on_range_error (HildonNumberEditor *editor, return TRUE; } +static void +on_size_notify (HildonNumberEditor *editor, + GParamSpec *arg1, + gpointer user_data) +{ + ModestMaemoGlobalSettingsDialog *dialog = MODEST_MAEMO_GLOBAL_SETTINGS_DIALOG (user_data); + gint value = hildon_number_editor_get_value (editor); + + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0); +} + static ModestConnectedVia current_connection (void) { - TnyAccountStore *account_store; - TnyDevice *device; + return modest_platform_get_current_connection (); +} + +static gboolean +on_inner_tabs_key_pressed (GtkWidget *widget, + GdkEventKey *event, + gpointer user_data) +{ + ModestGlobalSettingsDialogPrivate *ppriv; gboolean retval = FALSE; - - account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()); - device = tny_account_store_get_device (account_store); - - /* Get iap id */ - const gchar *iap_id = tny_maemo_conic_device_get_current_iap_id (TNY_MAEMO_CONIC_DEVICE (device)); - if (iap_id) { - ConIcIap *iap = tny_maemo_conic_device_get_iap ( - TNY_MAEMO_CONIC_DEVICE (device), iap_id); - const gchar *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); + + ppriv = MODEST_GLOBAL_SETTINGS_DIALOG_GET_PRIVATE (user_data); + + if (widget == ppriv->notebook) { + if (event->keyval == GDK_Right) { + gtk_notebook_next_page (GTK_NOTEBOOK (ppriv->notebook)); + retval = TRUE; + } else if (event->keyval == GDK_Left) { + gtk_notebook_prev_page (GTK_NOTEBOOK (ppriv->notebook)); + retval = TRUE; + } } - g_object_unref (device); return retval; }