prefs_receive.c (7413B)
1 /* 2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client 3 * Copyright (C) 2005-2024 the Claws Mail team and Colin Leroy 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 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #include "defs.h" 20 21 #include <stdio.h> 22 #include <stdlib.h> 23 24 #include <glib.h> 25 #include <glib/gi18n.h> 26 #include <gtk/gtk.h> 27 #include <gdk/gdkkeysyms.h> 28 29 #include "prefs_common.h" 30 #include "prefs_receive.h" 31 #include "prefs_gtk.h" 32 #include "inc.h" 33 34 #include "gtk/gtkutils.h" 35 #include "gtk/prefswindow.h" 36 #include "gtk/menu.h" 37 38 #include "manage_window.h" 39 #include "combobox.h" 40 41 typedef struct _ReceivePage 42 { 43 PrefsPage page; 44 45 GtkWidget *window; 46 47 GtkWidget *checkbtn_incext; 48 GtkWidget *entry_incext; 49 GtkWidget *checkbtn_newmail_auto; 50 GtkWidget *checkbtn_newmail_manu; 51 GtkWidget *entry_newmail_notify_cmd; 52 GtkWidget *hbox_newmail_notify; 53 } ReceivePage; 54 55 ReceivePage *prefs_receive; 56 57 static void prefs_common_recv_dialog_newmail_notify_toggle_cb(GtkWidget *w, gpointer data) 58 { 59 gboolean toggled; 60 61 toggled = gtk_toggle_button_get_active 62 (GTK_TOGGLE_BUTTON(prefs_receive->checkbtn_newmail_manu)) || 63 gtk_toggle_button_get_active 64 (GTK_TOGGLE_BUTTON(prefs_receive->checkbtn_newmail_auto)); 65 gtk_widget_set_sensitive(prefs_receive->hbox_newmail_notify, toggled); 66 } 67 68 static void prefs_receive_create_widget(PrefsPage *_page, GtkWindow *window, 69 gpointer data) 70 { 71 ReceivePage *prefs_receive = (ReceivePage *) _page; 72 73 GtkWidget *vbox1; 74 GtkWidget *vbox2; 75 GtkWidget *checkbtn_incext; 76 GtkWidget *hbox; 77 GtkWidget *label_incext; 78 GtkWidget *entry_incext; 79 80 GtkWidget *frame; 81 GtkWidget *vbox3; 82 GtkWidget *hbox_newmail_notify; 83 GtkWidget *checkbtn_newmail_auto; 84 GtkWidget *checkbtn_newmail_manu; 85 GtkWidget *entry_newmail_notify_cmd; 86 GtkWidget *label_newmail_notify_cmd; 87 GtkWidget *label_newmail_notify_cmd_syntax; 88 89 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING); 90 gtk_widget_show (vbox1); 91 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER); 92 93 /* Use of external incorporation program */ 94 vbox2 = gtkut_get_options_frame(vbox1, &frame, _("External incorporation program")); 95 96 PACK_CHECK_BUTTON (vbox2, checkbtn_incext, 97 _("Use external program for receiving mail")); 98 99 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); 100 gtk_widget_show (hbox); 101 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); 102 SET_TOGGLE_SENSITIVITY (checkbtn_incext, hbox); 103 104 label_incext = gtk_label_new (_("Command")); 105 gtk_widget_show (label_incext); 106 gtk_box_pack_start (GTK_BOX (hbox), label_incext, FALSE, FALSE, 0); 107 108 entry_incext = gtk_entry_new (); 109 gtk_widget_show (entry_incext); 110 gtk_box_pack_start (GTK_BOX (hbox), entry_incext, TRUE, TRUE, 0); 111 112 vbox3 = gtkut_get_options_frame(vbox1, &frame, _("Run command after receiving new mail")); 113 114 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); 115 gtk_widget_show (hbox); 116 PACK_CHECK_BUTTON (hbox, checkbtn_newmail_auto, 117 _("after automatic check")); 118 PACK_CHECK_BUTTON (hbox, checkbtn_newmail_manu, 119 _("after manual check")); 120 gtk_box_pack_start (GTK_BOX(vbox3), hbox, FALSE, FALSE, 0); 121 122 hbox_newmail_notify = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); 123 gtk_widget_show (hbox_newmail_notify); 124 gtk_box_pack_start (GTK_BOX (vbox3), hbox_newmail_notify, FALSE, 125 FALSE, 0); 126 127 label_newmail_notify_cmd = gtk_label_new (_("Command to execute")); 128 gtk_label_set_justify(GTK_LABEL(label_newmail_notify_cmd), 129 GTK_JUSTIFY_RIGHT); 130 gtk_widget_show (label_newmail_notify_cmd); 131 gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 132 label_newmail_notify_cmd, FALSE, FALSE, 0); 133 134 entry_newmail_notify_cmd = gtk_entry_new (); 135 gtk_widget_show (entry_newmail_notify_cmd); 136 gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 137 entry_newmail_notify_cmd, TRUE, TRUE, 0); 138 139 label_newmail_notify_cmd_syntax = gtk_label_new (_("Use %d as number of new mails")); 140 gtk_widget_show (label_newmail_notify_cmd_syntax); 141 gtkut_widget_set_small_font_size (label_newmail_notify_cmd_syntax); 142 gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 143 label_newmail_notify_cmd_syntax, FALSE, FALSE, 0); 144 145 gtk_widget_set_sensitive(hbox_newmail_notify, 146 prefs_common.newmail_notify_auto || 147 prefs_common.newmail_notify_manu); 148 149 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_auto), 150 prefs_common.newmail_notify_auto); 151 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmail_manu), 152 prefs_common.newmail_notify_manu); 153 gtk_entry_set_text(GTK_ENTRY(entry_newmail_notify_cmd), 154 prefs_common.newmail_notify_cmd); 155 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_incext), 156 prefs_common.use_extinc); 157 158 gtk_entry_set_text(GTK_ENTRY(entry_incext), 159 prefs_common.extinc_cmd); 160 161 prefs_receive->window = GTK_WIDGET(window); 162 prefs_receive->checkbtn_incext = checkbtn_incext; 163 prefs_receive->entry_incext = entry_incext; 164 prefs_receive->checkbtn_newmail_auto = checkbtn_newmail_auto; 165 prefs_receive->checkbtn_newmail_manu = checkbtn_newmail_manu; 166 prefs_receive->entry_newmail_notify_cmd = entry_newmail_notify_cmd; 167 prefs_receive->hbox_newmail_notify = hbox_newmail_notify; 168 169 prefs_receive->page.widget = vbox1; 170 171 g_signal_connect(G_OBJECT(checkbtn_newmail_auto), "toggled", 172 G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb), 173 NULL); 174 g_signal_connect(G_OBJECT(checkbtn_newmail_manu), "toggled", 175 G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb), 176 NULL); 177 } 178 179 static void prefs_receive_save(PrefsPage *_page) 180 { 181 ReceivePage *page = (ReceivePage *) _page; 182 gchar *tmp; 183 184 prefs_common.use_extinc = gtk_toggle_button_get_active( 185 GTK_TOGGLE_BUTTON(page->checkbtn_incext)); 186 prefs_common.newmail_notify_auto = gtk_toggle_button_get_active( 187 GTK_TOGGLE_BUTTON(page->checkbtn_newmail_auto)); 188 prefs_common.newmail_notify_manu = gtk_toggle_button_get_active( 189 GTK_TOGGLE_BUTTON(page->checkbtn_newmail_manu)); 190 191 tmp = gtk_editable_get_chars(GTK_EDITABLE(page->entry_incext), 0, -1); 192 g_free(prefs_common.extinc_cmd); 193 prefs_common.extinc_cmd = tmp; 194 195 tmp = gtk_editable_get_chars(GTK_EDITABLE(page->entry_newmail_notify_cmd), 0, -1); 196 g_free(prefs_common.newmail_notify_cmd); 197 prefs_common.newmail_notify_cmd = tmp; 198 } 199 200 static void prefs_receive_destroy_widget(PrefsPage *_page) {} 201 202 void prefs_receive_init(void) 203 { 204 ReceivePage *page; 205 static gchar *path[3]; 206 207 path[0] = _("Mail Handling"); 208 path[1] = _("Receiving"); 209 path[2] = NULL; 210 211 page = g_new0(ReceivePage, 1); 212 page->page.path = path; 213 page->page.create_widget = prefs_receive_create_widget; 214 page->page.destroy_widget = prefs_receive_destroy_widget; 215 page->page.save_page = prefs_receive_save; 216 page->page.weight = 200.0; 217 prefs_gtk_register_page((PrefsPage *) page); 218 prefs_receive = page; 219 } 220 221 void prefs_receive_done(void) 222 { 223 prefs_gtk_unregister_page((PrefsPage *) prefs_receive); 224 g_free(prefs_receive); 225 }