src/mn-webmail-mailbox-properties.gob (6145B) - 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 %} 24 25 %{ 26 #include <glib/gi18n.h> 27 #include "mn-webmail-mailbox.h" 28 #include "mn-mailbox-properties-private.h" 29 #include "mn-authenticated-mailbox-properties-private.h" 30 #include "mn-util.h" 31 %} 32 33 class MN:Webmail:Mailbox:Properties from MN:Authenticated:Mailbox:Properties (abstract) 34 { 35 private GtkWidget *inbox_radio; 36 private GtkWidget *other_radio; 37 private GtkWidget *folder_entry; 38 39 property BOOLEAN complete (override) 40 get 41 { 42 gboolean complete; 43 44 complete = mn_authenticated_mailbox_properties_is_complete(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self)); 45 if (complete) 46 { 47 gboolean other_active; 48 const char *folder; 49 50 other_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio)); 51 folder = gtk_entry_get_text(GTK_ENTRY(selfp->folder_entry)); 52 53 if (other_active && ! *folder) 54 complete = FALSE; 55 } 56 57 g_value_set_boolean(VAL, complete); 58 }; 59 60 property STRING default_name (override) 61 get 62 { 63 const char *username; 64 gboolean other_active; 65 const char *folder; 66 MNMailboxClass *class; 67 68 username = gtk_entry_get_text(GTK_ENTRY(MN_AUTHENTICATED_MAILBOX_PROPERTIES(self)->username_entry)); 69 g_assert(*username != 0); 70 71 other_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio)); 72 folder = gtk_entry_get_text(GTK_ENTRY(selfp->folder_entry)); 73 74 class = mn_mailbox_get_class_from_name(MN_MAILBOX_PROPERTIES_CLASS(SELF_GET_CLASS(self))->type); 75 g_value_take_string(VAL, mn_webmail_mailbox_build_name(MN_WEBMAIL_MAILBOX_CLASS(class), 76 username, 77 other_active ? folder : NULL)); 78 g_type_class_unref(class); 79 }; 80 81 init (self) 82 { 83 MNMailboxProperties *properties = MN_MAILBOX_PROPERTIES(self); 84 MNAuthenticatedMailboxProperties *auth = MN_AUTHENTICATED_MAILBOX_PROPERTIES(self); 85 GtkWidget *folder_vbox; 86 GtkWidget *hbox; 87 88 gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->username_vbox, FALSE, FALSE, 0); 89 gtk_box_pack_start(GTK_BOX(auth->account_vbox), auth->password_vbox, FALSE, FALSE, 0); 90 91 /* translators: header capitalization */ 92 folder_vbox = mn_mailbox_properties_add_general_section(properties, _("Folder")); 93 94 selfp->inbox_radio = gtk_radio_button_new_with_mnemonic(NULL, _("In_box")); 95 gtk_size_group_add_widget(properties->label_size_group, selfp->inbox_radio); 96 97 gtk_box_pack_start(GTK_BOX(folder_vbox), selfp->inbox_radio, FALSE, FALSE, 0); 98 99 selfp->other_radio = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(selfp->inbox_radio), _("_Other:")); 100 gtk_size_group_add_widget(properties->label_size_group, selfp->other_radio); 101 102 selfp->folder_entry = gtk_entry_new(); 103 gtk_widget_set_sensitive(selfp->folder_entry, FALSE); 104 105 hbox = gtk_hbox_new(FALSE, 12); 106 gtk_box_pack_start(GTK_BOX(hbox), selfp->other_radio, FALSE, FALSE, 0); 107 gtk_box_pack_start(GTK_BOX(hbox), selfp->folder_entry, TRUE, TRUE, 0); 108 gtk_box_pack_start(GTK_BOX(folder_vbox), hbox, FALSE, FALSE, 0); 109 gtk_widget_show_all(folder_vbox); 110 111 properties->entries = mn_g_slist_append_elements(properties->entries, 112 auth->username_entry, 113 auth->password_entry, 114 selfp->folder_entry, 115 NULL); 116 117 g_signal_connect(selfp->inbox_radio, "toggled", G_CALLBACK(self_radio_toggled_h), self); 118 g_signal_connect(selfp->other_radio, "toggled", G_CALLBACK(self_radio_toggled_h), self); 119 120 g_object_connect(auth->username_entry, 121 "swapped-signal::changed", mn_mailbox_properties_notify_complete, self, 122 "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self, 123 NULL); 124 125 g_object_connect(selfp->folder_entry, 126 "swapped-signal::changed", mn_mailbox_properties_notify_complete, self, 127 "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self, 128 NULL); 129 } 130 131 private void 132 radio_toggled_h (GtkToggleButton *togglebutton, gpointer user_data) 133 { 134 Self *self = user_data; 135 136 gtk_widget_set_sensitive(selfp->folder_entry, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio))); 137 138 g_object_notify(G_OBJECT(self), "complete"); 139 g_object_notify(G_OBJECT(self), "default-name"); 140 } 141 142 override (MN:Mailbox:Properties) void 143 set_mailbox (MNMailboxProperties *properties, MNMailbox *mailbox) 144 { 145 Self *self = SELF(properties); 146 MNWebmailMailbox *webmail_mailbox = MN_WEBMAIL_MAILBOX(mailbox); 147 148 PARENT_HANDLER(properties, mailbox); 149 150 if (! strcmp(webmail_mailbox->folder, "Inbox")) 151 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->inbox_radio), TRUE); 152 else 153 { 154 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(selfp->other_radio), TRUE); 155 gtk_entry_set_text(GTK_ENTRY(selfp->folder_entry), webmail_mailbox->folder); 156 } 157 } 158 159 override (MN:Mailbox:Properties) MNMailbox * 160 get_mailbox (MNMailboxProperties *properties) 161 { 162 Self *self = SELF(properties); 163 MNMailbox *mailbox; 164 165 mailbox = PARENT_HANDLER(properties); 166 167 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(selfp->other_radio))) 168 g_object_set(mailbox, MN_WEBMAIL_MAILBOX_PROP_FOLDER((char *) gtk_entry_get_text(GTK_ENTRY(selfp->folder_entry))), NULL); 169 170 return mailbox; 171 } 172 }