src/mn-autodetect-mailbox-properties.gob (7229B) - 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-mailbox-properties.h" 23 %} 24 25 %{ 26 #include <glib/gi18n.h> 27 #include "mn-mailbox-properties.h" 28 #include "mn-mailbox-properties-private.h" 29 #include "mn-util.h" 30 #include "mn-properties-dialog.h" 31 #if WITH_MBOX || WITH_MOZILLA || WITH_MH || WITH_MAILDIR || WITH_SYLPHEED 32 #include "mn-custom-vfs-mailbox.h" 33 #endif 34 #include "mn-stock.h" 35 36 static char *current_folder_uri = NULL; 37 %} 38 39 class MN:Autodetect:Mailbox:Properties from MN:Mailbox:Properties 40 { 41 private GtkWidget *location_entry; 42 private GtkWidget *chooser; 43 44 property BOOLEAN complete (override) 45 get 46 { 47 const char *location; 48 gboolean complete = FALSE; 49 50 location = gtk_entry_get_text(GTK_ENTRY(SELF(self)->_priv->location_entry)); 51 if (*location) 52 { 53 MNMailbox *mailbox; 54 55 mailbox = mn_mailbox_new_from_uri(location); 56 if (mailbox) 57 { 58 complete = TRUE; 59 g_object_unref(mailbox); 60 } 61 } 62 63 g_value_set_boolean(VAL, complete); 64 }; 65 66 property STRING default_name (override) 67 get 68 { 69 char *name = NULL; 70 MNMailbox *mailbox; 71 72 mailbox = mn_mailbox_new_from_uri(gtk_entry_get_text(GTK_ENTRY(selfp->location_entry))); 73 if (mailbox) 74 { 75 mn_mailbox_seal(mailbox); 76 name = g_strdup(mailbox->runtime_name); 77 g_object_unref(mailbox); 78 } 79 80 g_value_take_string(VAL, name); 81 }; 82 83 property INT default_check_delay (override) 84 get 85 { 86 int check_delay = -1; 87 MNMailbox *mailbox; 88 89 mailbox = mn_mailbox_new_from_uri(gtk_entry_get_text(GTK_ENTRY(selfp->location_entry))); 90 if (mailbox) 91 { 92 mn_mailbox_seal(mailbox); 93 check_delay = mailbox->runtime_check_delay; 94 g_object_unref(mailbox); 95 } 96 97 g_value_set_int(VAL, check_delay); 98 }; 99 100 class_init (class) 101 { 102 MNMailboxPropertiesClass *p_class = MN_MAILBOX_PROPERTIES_CLASS(class); 103 104 p_class->type = "custom-vfs"; 105 p_class->stock_id = MN_STOCK_UNKNOWN; 106 p_class->combo_label = _("Autodetect"); 107 } 108 109 init (self) 110 { 111 MNMailboxProperties *properties = MN_MAILBOX_PROPERTIES(self); 112 GtkWidget *location_vbox; 113 GtkWidget *outer_hbox; 114 GtkWidget *hbox; 115 GtkWidget *label; 116 GtkWidget *button; 117 118 /* translators: header capitalization */ 119 location_vbox = mn_mailbox_properties_add_general_section(properties, _("Location")); 120 121 label = gtk_label_new_with_mnemonic(_("_Location:")); 122 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); 123 124 outer_hbox = gtk_hbox_new(FALSE, 12); 125 hbox = gtk_hbox_new(FALSE, 6); 126 127 selfp->location_entry = gtk_entry_new(); 128 /* translators: header capitalization */ 129 button = gtk_button_new_with_mnemonic(_("_Browse...")); 130 131 gtk_label_set_mnemonic_widget(GTK_LABEL(label), selfp->location_entry); 132 properties->entries = g_slist_append(properties->entries, selfp->location_entry); 133 134 gtk_box_pack_start(GTK_BOX(hbox), selfp->location_entry, TRUE, TRUE, 0); 135 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); 136 137 gtk_box_pack_start(GTK_BOX(outer_hbox), label, FALSE, FALSE, 0); 138 gtk_box_pack_start(GTK_BOX(outer_hbox), hbox, TRUE, TRUE, 0); 139 gtk_box_pack_start(GTK_BOX(location_vbox), outer_hbox, FALSE, FALSE, 0); 140 141 gtk_widget_show_all(outer_hbox); 142 143 gtk_size_group_add_widget(MN_MAILBOX_PROPERTIES(self)->label_size_group, label); 144 145 g_object_connect(selfp->location_entry, 146 "swapped-signal::changed", mn_mailbox_properties_notify_complete, self, 147 "swapped-signal::changed", mn_mailbox_properties_notify_default_name, self, 148 "swapped-signal::changed", mn_mailbox_properties_notify_default_check_delay, self, 149 NULL); 150 151 g_signal_connect(button, "clicked", G_CALLBACK(self_browse_clicked_h), self); 152 } 153 154 private void 155 browse_clicked_h (GtkButton *button, gpointer user_data) 156 { 157 Self *self = user_data; 158 GtkWidget *toplevel; 159 const char *location; 160 161 if (selfp->chooser) 162 { 163 mn_window_present_from_event(GTK_WINDOW(selfp->chooser)); 164 return; 165 } 166 167 toplevel = gtk_widget_get_toplevel(GTK_WIDGET(button)); 168 /* translators: header capitalization */ 169 selfp->chooser = gtk_file_chooser_dialog_new_with_backend(_("Select a File or Folder"), 170 GTK_WINDOW(toplevel), 171 GTK_FILE_CHOOSER_ACTION_OPEN, 172 "gnome-vfs", 173 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 174 GTK_STOCK_OPEN, 1, 175 NULL); 176 mn_add_weak_pointer(&selfp->chooser); 177 178 gtk_window_set_destroy_with_parent(GTK_WINDOW(selfp->chooser), TRUE); 179 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(selfp->chooser), FALSE); 180 mn_file_chooser_dialog_allow_select_folder(GTK_FILE_CHOOSER_DIALOG(selfp->chooser), 1); 181 182 location = gtk_entry_get_text(GTK_ENTRY(selfp->location_entry)); 183 if (*location) 184 gtk_file_chooser_set_uri(GTK_FILE_CHOOSER(selfp->chooser), location); 185 else if (current_folder_uri) 186 gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER(selfp->chooser), current_folder_uri); 187 188 g_object_connect(selfp->chooser, 189 "signal::current-folder-changed", self_current_folder_changed_h, self, 190 "signal::response", self_chooser_response_h, self, 191 NULL); 192 193 gtk_widget_show(selfp->chooser); 194 } 195 196 private void 197 current_folder_changed_h (GtkFileChooser *chooser, gpointer user_data) 198 { 199 g_free(current_folder_uri); 200 current_folder_uri = gtk_file_chooser_get_current_folder_uri(chooser); 201 } 202 203 private void 204 chooser_response_h (GtkDialog *dialog, int response, gpointer user_data) 205 { 206 if (response == 1) 207 { 208 Self *self = user_data; 209 char *uri; 210 211 uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); 212 gtk_entry_set_text(GTK_ENTRY(selfp->location_entry), uri); 213 g_free(uri); 214 } 215 216 gtk_widget_destroy(GTK_WIDGET(dialog)); 217 } 218 219 override (MN:Mailbox:Properties) void 220 set_mailbox (MNMailboxProperties *properties, MNMailbox *mailbox) 221 { 222 #if WITH_MBOX || WITH_MOZILLA || WITH_MH || WITH_MAILDIR || WITH_SYLPHEED 223 g_return_if_fail(MN_IS_CUSTOM_VFS_MAILBOX(mailbox)); 224 225 gtk_entry_set_text(GTK_ENTRY(SELF(properties)->_priv->location_entry), MN_CUSTOM_VFS_MAILBOX(mailbox)->uri); 226 #else 227 g_assert_not_reached(); 228 #endif 229 } 230 231 override (MN:Mailbox:Properties) MNMailbox * 232 get_mailbox (MNMailboxProperties *properties) 233 { 234 const char *uri; 235 236 uri = gtk_entry_get_text(GTK_ENTRY(SELF(properties)->_priv->location_entry)); 237 return mn_mailbox_new_from_uri(uri); 238 } 239 }