src/mn-pi-mailbox-properties.gob (10899B) - raw
1 /* 2 * Mail Notification 3 * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 %headertop{ 21 #include <gtk/gtk.h> 22 #include "mn-authenticated-mailbox-properties.h" 23 #include "mn-pi-mailbox.h" 24 %} 25 26 %{ 27 #include <glib/gi18n.h> 28 #include "mn-mailbox-properties-dialog.h" 29 #include "mn-mailbox-properties-dialog-private.h" 30 #include "mn-mailbox-properties-private.h" 31 #include "mn-authenticated-mailbox-properties-private.h" 32 #include "mn-auth-combo-box.h" 33 #include "mn-util.h" 34 #include "mn-stock.h" 35 %} 36 37 class MN:PI:Mailbox:Properties from MN:Authenticated:Mailbox:Properties (abstract) 38 { 39 protected GtkWidget *server_entry; 40 protected GtkWidget *connection_page unrefwith g_object_unref; 41 protected GtkSizeGroup *connection_size_group = {gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL)} unrefwith g_object_unref; 42 protected GtkWidget *conn_radio[MN_PI_MAILBOX_N_CONNECTION_TYPES]; 43 protected GtkWidget *port_spin[MN_PI_MAILBOX_N_CONNECTION_TYPES]; 44 protected GtkWidget *auth_combo; 45 46 property BOOLEAN complete (override) 47 get 48 { 49 g_value_set_boolean(VAL, self_is_complete(self)); 50 }; 51 52 class_init (class) 53 { 54 MNMailboxPropertiesClass *p_class = MN_MAILBOX_PROPERTIES_CLASS(class); 55 56 p_class->stock_id = MN_STOCK_REMOTE; 57 } 58 59 init (self) 60 { 61 MNMailboxProperties *properties = MN_MAILBOX_PROPERTIES(self); 62 MNAuthenticatedMailboxProperties *auth = MN_AUTHENTICATED_MAILBOX_PROPERTIES(self); 63 GtkWidget *hbox; 64 GtkWidget *label; 65 GtkWidget *type_section; 66 GtkWidget *type_vbox; 67 int i; 68 static const struct 69 { 70 MNPIMailboxConnectionType type; 71 const char *mnemonic; 72 } connection_types[] = { 73 { MN_PI_MAILBOX_CONNECTION_TYPE_NORMAL, N_("_Standard") }, 74 { MN_PI_MAILBOX_CONNECTION_TYPE_INBAND_SSL, N_("In-_band SSL/TLS") }, 75 { MN_PI_MAILBOX_CONNECTION_TYPE_SSL, N_("SSL/TLS on s_eparate port") } 76 }; 77 78 hbox = mn_authenticated_mailbox_properties_field_new(auth, 79 _("_Server:"), 80 &label, 81 &self->server_entry); 82 83 gtk_box_pack_start(GTK_BOX(auth->account_vbox), hbox, FALSE, FALSE, 0); 84 gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->username_vbox, FALSE, FALSE, 0); 85 gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->password_vbox, FALSE, FALSE, 0); 86 87 properties->entries = mn_g_slist_append_elements(properties->entries, 88 self->server_entry, 89 auth->username_entry, 90 auth->password_entry, 91 NULL); 92 93 self->connection_page = gtk_vbox_new(FALSE, 18); 94 gtk_container_set_border_width(GTK_CONTAINER(self->connection_page), 12); 95 mn_mailbox_properties_dialog_set_help_section(self->connection_page, "mailbox-properties-connection"); 96 g_object_ref_sink(self->connection_page); 97 98 /* translators: header capitalization */ 99 type_section = mn_hig_section_new_with_box(_("Connection Type"), NULL, &type_vbox); 100 gtk_box_pack_start(GTK_BOX(self->connection_page), type_section, FALSE, FALSE, 0); 101 gtk_widget_show(type_section); 102 103 for (i = 0; i < MN_PI_MAILBOX_N_CONNECTION_TYPES; i++) 104 self_add_connection_type(self, 105 GTK_BOX(type_vbox), 106 connection_types[i].type, 107 _(connection_types[i].mnemonic)); 108 109 #if ! WITH_SSL 110 gtk_widget_set_sensitive(self->conn_radio[MN_PI_MAILBOX_CONNECTION_TYPE_INBAND_SSL], FALSE); 111 gtk_widget_set_sensitive(self->conn_radio[MN_PI_MAILBOX_CONNECTION_TYPE_SSL], FALSE); 112 #endif 113 114 /* by default, standard is enabled */ 115 gtk_widget_set_sensitive(self->port_spin[MN_PI_MAILBOX_CONNECTION_TYPE_INBAND_SSL], FALSE); 116 gtk_widget_set_sensitive(self->port_spin[MN_PI_MAILBOX_CONNECTION_TYPE_SSL], FALSE); 117 118 self_add_authentication(self); 119 120 gtk_widget_show_all(self->connection_page); 121 122 g_object_connect(self->server_entry, 123 "swapped-signal::changed", mn_mailbox_properties_notify_complete, self, 124 "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self, 125 NULL); 126 127 g_object_connect(auth->username_entry, 128 "swapped-signal::changed", mn_mailbox_properties_notify_complete, self, 129 "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self, 130 NULL); 131 } 132 133 private void 134 add_connection_type (self, 135 Gtk:Box *type_vbox (check null), 136 MNPIMailboxConnectionType type, 137 const char *mnemonic (check null)) 138 { 139 GtkWidget *hbox; 140 GtkWidget *port_label; 141 142 self->conn_radio[type] = type == 0 143 ? gtk_radio_button_new_with_mnemonic(NULL, mnemonic) 144 : gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(self->conn_radio[0]), mnemonic); 145 146 port_label = gtk_label_new(_("Port:")); 147 148 self->port_spin[type] = gtk_spin_button_new_with_range(0, 0xFFFF, 1); 149 gtk_entry_set_activates_default(GTK_ENTRY(self->port_spin[type]), TRUE); 150 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(self->port_spin[type]), TRUE); 151 152 hbox = gtk_hbox_new(FALSE, 12); 153 gtk_box_pack_start(GTK_BOX(hbox), self->conn_radio[type], FALSE, FALSE, 0); 154 gtk_box_pack_start(GTK_BOX(hbox), port_label, FALSE, FALSE, 0); 155 gtk_box_pack_start(GTK_BOX(hbox), self->port_spin[type], FALSE, FALSE, 0); 156 gtk_box_pack_start(type_vbox, hbox, FALSE, FALSE, 0); 157 gtk_widget_show_all(hbox); 158 159 gtk_size_group_add_widget(self->connection_size_group, self->conn_radio[type]); 160 161 g_signal_connect(self->conn_radio[type], "toggled", G_CALLBACK(self_radio_toggled_h), self); 162 } 163 164 private void 165 add_authentication (self) 166 { 167 GtkWidget *section; 168 GtkWidget *vbox; 169 GtkWidget *hbox; 170 GtkWidget *label; 171 172 /* translators: header capitalization */ 173 section = mn_hig_section_new_with_box(_("Authentication"), NULL, &vbox); 174 gtk_box_pack_start(GTK_BOX(self->connection_page), section, FALSE, FALSE, 0); 175 176 hbox = gtk_hbox_new(FALSE, 12); 177 label = gtk_label_new_with_mnemonic(_("_Mechanism:")); 178 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); 179 180 self->auth_combo = mn_auth_combo_box_new(); 181 gtk_label_set_mnemonic_widget(GTK_LABEL(label), self->auth_combo); 182 183 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 184 gtk_box_pack_start(GTK_BOX(hbox), self->auth_combo, TRUE, TRUE, 0); 185 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); 186 187 gtk_size_group_add_widget(self->connection_size_group, label); 188 } 189 190 private void 191 radio_toggled_h (Gtk:Toggle:Button *togglebutton (check null type), 192 gpointer user_data (check null)) 193 { 194 Self *self = user_data; 195 int i; 196 197 for (i = 0; i < MN_PI_MAILBOX_N_CONNECTION_TYPES; i++) 198 gtk_widget_set_sensitive(self->port_spin[i], GTK_WIDGET_SENSITIVE(self->conn_radio[i]) && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->conn_radio[i]))); 199 200 g_object_notify(G_OBJECT(self), "complete"); 201 } 202 203 override (MN:Mailbox:Properties) void 204 activate (MNMailboxProperties *properties) 205 { 206 Self *self = SELF(properties); 207 208 PARENT_HANDLER(properties); 209 210 gtk_notebook_insert_page(GTK_NOTEBOOK(MN_MAILBOX_PROPERTIES_DIALOG(properties->dialog)->notebook), self->connection_page, NULL, 1); 211 gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(MN_MAILBOX_PROPERTIES_DIALOG(properties->dialog)->notebook), self->connection_page, _("Connection")); 212 } 213 214 override (MN:Mailbox:Properties) void 215 deactivate (MNMailboxProperties *properties) 216 { 217 PARENT_HANDLER(properties); 218 219 gtk_notebook_remove_page(GTK_NOTEBOOK(MN_MAILBOX_PROPERTIES_DIALOG(properties->dialog)->notebook), 1); 220 } 221 222 override (MN:Mailbox:Properties) void 223 set_mailbox (MNMailboxProperties *properties, MNMailbox *mailbox) 224 { 225 Self *self = SELF(properties); 226 MNPIMailbox *pi_mailbox = MN_PI_MAILBOX(mailbox); 227 228 PARENT_HANDLER(properties, mailbox); 229 230 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->conn_radio[pi_mailbox->connection_type]), TRUE); 231 mn_auth_combo_box_set_active_mechanism(MN_AUTH_COMBO_BOX(self->auth_combo), pi_mailbox->authmech); 232 gtk_entry_set_text(GTK_ENTRY(self->server_entry), pi_mailbox->hostname); 233 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self->port_spin[pi_mailbox->connection_type]), pi_mailbox->runtime_port); 234 } 235 236 override (MN:Mailbox:Properties) MNMailbox * 237 get_mailbox (MNMailboxProperties *properties) 238 { 239 MNMailbox *mailbox; 240 MNPIMailboxConnectionType connection_type; 241 char *authmech; 242 const char *server; 243 int port; 244 245 mailbox = PARENT_HANDLER(properties); 246 247 self_get_contents(SELF(properties), 248 &connection_type, 249 &authmech, 250 &server, 251 &port); 252 253 g_object_set(mailbox, 254 MN_PI_MAILBOX_PROP_CONNECTION_TYPE(connection_type), 255 MN_PI_MAILBOX_PROP_AUTHMECH(authmech), 256 MN_PI_MAILBOX_PROP_HOSTNAME((char *) server), 257 MN_PI_MAILBOX_PROP_PORT(port), 258 NULL); 259 260 g_free(authmech); 261 262 return mailbox; 263 } 264 265 protected void 266 get_contents (self, 267 MNPIMailboxConnectionType *connection_type, 268 char **authmech, 269 const char **server, 270 int *port) 271 { 272 MNPIMailboxConnectionType _connection_type; 273 274 if (connection_type || port) 275 { 276 int i; 277 278 _connection_type = -1; 279 280 for (i = 0; i < MN_PI_MAILBOX_N_CONNECTION_TYPES; i++) 281 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->conn_radio[i]))) 282 { 283 _connection_type = i; 284 break; 285 } 286 287 g_assert(_connection_type != -1); 288 } 289 290 if (connection_type) 291 *connection_type = _connection_type; 292 if (authmech) 293 *authmech = mn_auth_combo_box_get_active_mechanism(MN_AUTH_COMBO_BOX(self->auth_combo)); 294 if (server) 295 *server = gtk_entry_get_text(GTK_ENTRY(self->server_entry)); 296 if (port) 297 *port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(self->port_spin[_connection_type])); 298 } 299 300 protected gboolean 301 is_complete (self) 302 { 303 const char *server; 304 305 if (! mn_authenticated_mailbox_properties_is_complete(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self))) 306 return FALSE; 307 308 server = gtk_entry_get_text(GTK_ENTRY(self->server_entry)); 309 if (! *server) 310 return FALSE; 311 312 #if ! WITH_SSL 313 if (! gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(MN_PI_MAILBOX_PROPERTIES(self)->conn_radio[MN_PI_MAILBOX_CONNECTION_TYPE_NORMAL]))) 314 return FALSE; 315 #endif /* WITH_SSL */ 316 317 return TRUE; 318 } 319 }