X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-connection-specific-smtp-window.c;h=21722157a981b80d3198d757fb2169e696f02589;hp=4b95597d697329d38b6990559418f70f4f8862b7;hb=448d8d5a3f665e689ceeed19ade2f33a0091a289;hpb=e45956ba0bdb6990bef41af14ea36977aec7b811 diff --git a/src/hildon2/modest-connection-specific-smtp-window.c b/src/hildon2/modest-connection-specific-smtp-window.c index 4b95597..2172215 100644 --- a/src/hildon2/modest-connection-specific-smtp-window.c +++ b/src/hildon2/modest-connection-specific-smtp-window.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -63,8 +64,8 @@ struct _ModestConnectionSpecificSmtpWindowPrivate { GtkTreeView *treeview; GtkTreeModel *model; - GtkWidget *button_edit; - + GtkWidget *no_connection_label; + GtkWidget *pannable; ModestAccountMgr *account_manager; }; @@ -110,32 +111,35 @@ enum MODEL_COLS { }; -void update_model_server_names (ModestConnectionSpecificSmtpWindow *self); +static void update_model_server_names (ModestConnectionSpecificSmtpWindow *self); static void modest_connection_specific_smtp_window_finalize (GObject *object) { ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (object); - + /* Free all the data items from the treemodel: */ GtkTreeIter iter; gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter); while (valid) { ModestServerAccountSettings *server_settings = NULL; - + gtk_tree_model_get (priv->model, &iter, MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings, -1); - + if (server_settings) g_object_unref (server_settings); - + /* Get next row: */ valid = gtk_tree_model_iter_next (priv->model, &iter); } - + g_object_unref (G_OBJECT (priv->model)); - + + g_object_unref (priv->treeview); + g_object_unref (priv->no_connection_label); + G_OBJECT_CLASS (modest_connection_specific_smtp_window_parent_class)->finalize (object); } @@ -161,6 +165,7 @@ void modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSpecificSmtpWindow *self, ModestAccountMgr *account_manager) { + gboolean empty = TRUE; #ifdef MODEST_HAVE_CONIC ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self); @@ -182,6 +187,9 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp /* printf("debug: list_iaps=%p, list_iaps size = %d\n", list_iaps, g_slist_length(list_iaps)); */ GSList* iter = list_iaps; + if (list_iaps != NULL) + empty = FALSE; + while (iter) { ConIcIap *iap = (ConIcIap*)iter->data; if (iap) { @@ -209,7 +217,8 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1); - g_free (server_account_name); + if (server_account_name) + g_free (server_account_name); } iter = g_slist_next (iter); @@ -222,10 +231,25 @@ modest_connection_specific_smtp_window_fill_with_connections (ModestConnectionSp update_model_server_names (self); #endif /*MODEST_HAVE_CONIC */ + + GtkWidget *child; + child = gtk_bin_get_child (GTK_BIN (priv->pannable)); + if (child) { + gtk_container_remove (GTK_CONTAINER (priv->pannable), child); + } + + if (empty) { + hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (priv->pannable), + priv->no_connection_label); + gtk_widget_show (priv->no_connection_label); + } else { + gtk_container_add (GTK_CONTAINER (priv->pannable), GTK_WIDGET (priv->treeview)); + gtk_widget_show (GTK_WIDGET (priv->treeview)); + } } static void -on_button_edit (ModestConnectionSpecificSmtpWindow *self) +edit_account (ModestConnectionSpecificSmtpWindow *self, GtkTreePath *path) { ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self); ModestAccountMgr *mgr = modest_runtime_get_account_mgr (); @@ -234,10 +258,8 @@ on_button_edit (ModestConnectionSpecificSmtpWindow *self) gchar *connection_name = NULL; gchar *server_account_name = NULL; ModestServerAccountSettings *server_settings = NULL; - GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); GtkTreeIter iter; - GtkTreeModel *model = 0; - if (gtk_tree_selection_get_selected (sel, &model, &iter)) { + if (gtk_tree_model_get_iter (priv->model, &iter, path)) { gtk_tree_model_get (priv->model, &iter, MODEL_COL_ID, &id, MODEL_COL_NAME, &connection_name, @@ -307,17 +329,10 @@ on_button_edit (ModestConnectionSpecificSmtpWindow *self) } static void -on_selection_changed (GtkTreeSelection *sel, ModestConnectionSpecificSmtpWindow *self) +on_row_activated (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, + ModestConnectionSpecificSmtpWindow *self) { - ModestConnectionSpecificSmtpWindowPrivate *priv = - CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self); - - GtkTreeModel *model = NULL; - GtkTreeIter iter; - const gboolean has_selection = - gtk_tree_selection_get_selected (sel, &model, &iter); - - gtk_widget_set_sensitive (priv->button_edit, has_selection); + edit_account (self, path); } static void @@ -325,16 +340,15 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow { ModestWindowMgr *mgr; - /* Specify a default size, because the GtkTreeView's default requested size - * is not big enough: */ - gtk_window_set_default_size (GTK_WINDOW (self), 500, 300); - + /* Specify a default size */ + gtk_window_set_default_size (GTK_WINDOW (self), -1, 320); + /* This seems to be necessary to make the window show at the front with decoration. * If we use property type=GTK_WINDOW_TOPLEVEL instead of the default GTK_WINDOW_POPUP+decoration, * then the window will be below the others. */ gtk_window_set_type_hint (GTK_WINDOW (self), GDK_WINDOW_TYPE_HINT_DIALOG); - + ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self); @@ -346,13 +360,13 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER)); /* Setup the tree view: */ - priv->treeview = GTK_TREE_VIEW (hildon_gtk_tree_view_new_with_model (HILDON_UI_MODE_EDIT, priv->model)); + priv->treeview = GTK_TREE_VIEW (hildon_gtk_tree_view_new_with_model (HILDON_UI_MODE_NORMAL, priv->model)); + g_object_ref_sink (G_OBJECT (priv->treeview)); + + /* No connections label */ + priv->no_connection_label = gtk_label_new (_("mcen_ia_optionalsmtp_noconnection")); + g_object_ref_sink (G_OBJECT (priv->no_connection_label)); - /* Show the column headers, - * which does not seem to be the default on Maemo. - */ - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(priv->treeview), TRUE); - /* name column: * The ID model column in not shown in the view. */ GtkTreeViewColumn *view_column = gtk_tree_view_column_new (); @@ -360,21 +374,18 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow gtk_tree_view_column_pack_start(view_column, renderer, TRUE); gtk_tree_view_column_set_attributes (view_column, renderer, "text", MODEL_COL_NAME, NULL); - gtk_tree_view_column_set_title (view_column, _("mcen_ia_optionalsmtp_connection_name")); gtk_tree_view_append_column (priv->treeview, view_column); - /* server name column: */ view_column = gtk_tree_view_column_new (); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start(view_column, renderer, TRUE); gtk_tree_view_column_set_attributes (view_column, renderer, "text", MODEL_COL_SERVER_NAME, NULL); - gtk_tree_view_column_set_title (view_column, _("mcen_ia_optionalsmtp_servername")); gtk_tree_view_append_column (priv->treeview, view_column); - + /* The application must call modest_connection_specific_smtp_window_fill_with_connections(). */ - + GtkWidget *vbox = GTK_DIALOG(self)->vbox; //gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT); @@ -382,6 +393,7 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow /* TODO: For some reason this label does not wrap. It is truncated. */ GtkWidget *label = gtk_label_new(_("mcen_ia_optionalsmtp_note")); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); /* So that it is shown without being truncated: */ /* gtk_label_set_max_width_chars (GTK_LABEL (label), 20); */ /* The documentation for gtk_label_set_line_wrap() says that we must @@ -390,26 +402,17 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow /* gtk_widget_set_size_request (label, 400, -1); */ gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, MODEST_MARGIN_HALF); - + /* Put the treeview in a pannable and add it to the box: */ - GtkWidget *pannable = hildon_pannable_area_new (); - g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL); - gtk_container_set_border_width (GTK_CONTAINER (pannable), MODEST_MARGIN_DEFAULT); - gtk_widget_show (pannable); - gtk_container_add (GTK_CONTAINER (pannable), GTK_WIDGET (priv->treeview)); - gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (pannable), TRUE, TRUE, MODEST_MARGIN_HALF); - gtk_widget_show (GTK_WIDGET (priv->treeview)); + priv->pannable = hildon_pannable_area_new (); + g_object_set (G_OBJECT (priv->pannable), "initial-hint", TRUE, NULL); + gtk_container_set_border_width (GTK_CONTAINER (priv->pannable), MODEST_MARGIN_DEFAULT); + gtk_widget_show (priv->pannable); + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->pannable), TRUE, TRUE, MODEST_MARGIN_HALF); gtk_widget_show (vbox); - - /* Hack: we use the response apply to identify the click on the edit button */ - priv->button_edit = gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_edit"), GTK_RESPONSE_APPLY); - - /* Disable the Edit button when nothing is selected: */ - GtkTreeSelection *sel = gtk_tree_view_get_selection (priv->treeview); - g_signal_connect (sel, "changed", - G_CALLBACK(on_selection_changed), self); - on_selection_changed (sel, self); - + + g_signal_connect (G_OBJECT (priv->treeview), "row-activated", G_CALLBACK (on_row_activated), self); + /* When this window is shown, hibernation should not be possible, * because there is no sensible way to save the state: */ mgr = modest_runtime_get_window_mgr (); @@ -420,10 +423,6 @@ modest_connection_specific_smtp_window_init (ModestConnectionSpecificSmtpWindow gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_optionalsmtp_servers")); g_signal_connect (self, "response", G_CALLBACK (on_response), NULL); - - hildon_help_dialog_help_enable (GTK_DIALOG(self), - "email_connectionsspecificsmtpconf", - modest_maemo_utils_get_osso_context()); } ModestConnectionSpecificSmtpWindow* @@ -471,7 +470,7 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe priv->account_manager, name_start, TRUE /* server account. */); g_assert (server_account_name); g_free (name_start); - + modest_server_account_settings_set_account_name (server_settings, server_account_name); success = modest_account_mgr_save_server_settings (mgr, server_settings); if (success) { @@ -481,15 +480,15 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe if (account) g_object_unref (account); } - + /* associate the specific server account with this connection for this account: */ success = success && modest_account_mgr_set_connection_specific_smtp ( priv->account_manager, id, server_account_name); - + /* Save the new name in the treemodel, so it can be edited again later: */ gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, MODEL_COL_SERVER_ACCOUNT_NAME, server_account_name, -1); - + } else { modest_account_mgr_save_server_settings (mgr, server_settings); } @@ -500,49 +499,50 @@ modest_connection_specific_smtp_window_save_server_accounts (ModestConnectionSpe gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, MODEL_COL_SERVER_ACCOUNT_NAME, NULL, -1); } - + g_free (connection_name); g_free (id); g_free (server_account_name); g_free (server_name); - + if (!success) return FALSE; - + /* Get next row: */ valid = gtk_tree_model_iter_next (priv->model, &iter); } - + update_model_server_names (self); - + return TRUE; } -void update_model_server_names (ModestConnectionSpecificSmtpWindow *self) +static void +update_model_server_names (ModestConnectionSpecificSmtpWindow *self) { ModestConnectionSpecificSmtpWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_WINDOW_GET_PRIVATE (self); GtkTreeIter iter; gboolean valid = gtk_tree_model_get_iter_first (priv->model, &iter); while (valid) { - + gchar *server_account_name = NULL; ModestServerAccountSettings *server_settings = NULL; gtk_tree_model_get (priv->model, &iter, MODEL_COL_SERVER_ACCOUNT_NAME, &server_account_name, MODEL_COL_SERVER_ACCOUNT_SETTINGS, &server_settings, - -1); + -1); if (server_settings && modest_server_account_settings_get_hostname (server_settings) && (modest_server_account_settings_get_hostname (server_settings) [0] != '\0')) { gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, MODEL_COL_SERVER_NAME, modest_server_account_settings_get_hostname (server_settings), -1); } else if (server_account_name) { - - /* Get the server hostname and show it in the treemodel: */ - gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager, + + /* Get the server hostname and show it in the treemodel: */ + gchar *hostname = modest_account_mgr_get_server_account_hostname (priv->account_manager, server_account_name); - gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, + gtk_list_store_set (GTK_LIST_STORE (priv->model), &iter, MODEL_COL_SERVER_NAME, hostname, -1); g_free (hostname); @@ -551,7 +551,7 @@ void update_model_server_names (ModestConnectionSpecificSmtpWindow *self) MODEL_COL_SERVER_NAME, _("mcen_ia_optionalsmtp_notdefined"), -1); } - + /* Get next row: */ valid = gtk_tree_model_iter_next (priv->model, &iter); } @@ -562,18 +562,6 @@ on_response (GtkDialog *dialog, gint response, gpointer user_data) { - switch (response) { - case GTK_RESPONSE_APPLY: - /* We use it for the edit button */ - on_button_edit (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog)); - g_signal_stop_emission_by_name (dialog, "response"); - break; - case GTK_RESPONSE_CLOSE: - case GTK_RESPONSE_NONE: - case GTK_RESPONSE_DELETE_EVENT: - /* Generated as a response to delete-event, i.e, - pressin Esc, or by pressing the Close button */ - modest_connection_specific_smtp_window_save_server_accounts (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog)); - gtk_widget_destroy (GTK_WIDGET (dialog)); - } + modest_connection_specific_smtp_window_save_server_accounts (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog)); + gtk_widget_destroy (GTK_WIDGET (dialog)); }