Use custom get_default_font_size() and _name()
[claws.git] / src / prefs_ext_prog.c
blob8ae0eec252d8f34c791ef34018fb6679ebe3264d
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2004-2021 the Claws Mail team and Hiroyuki Yamamoto
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.
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.
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/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #include "claws-features.h"
22 #endif
24 #include "defs.h"
26 #include <stdio.h>
27 #include <stdlib.h>
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
34 #include "utils.h"
35 #include "combobox.h"
36 #include "prefs_common.h"
37 #include "prefs_gtk.h"
39 #include "gtk/gtkutils.h"
40 #include "gtk/prefswindow.h"
42 #include "manage_window.h"
44 typedef struct _ExtProgPage
46 PrefsPage page;
48 GtkWidget *window; /* do not modify */
50 GtkWidget *cmds_use_system_default_checkbtn;
51 #ifndef G_OS_WIN32
52 GtkWidget *uri_label;
53 GtkWidget *uri_combo;
54 GtkWidget *uri_entry;
55 #endif /* !G_OS_WIN32 */
57 GtkWidget *exteditor_label;
58 GtkWidget *exteditor_combo;
59 GtkWidget *exteditor_entry;
61 GtkWidget *astextviewer_label;
62 GtkWidget *astextviewer_entry;
63 } ExtProgPage;
65 static void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
66 gpointer data)
68 ExtProgPage *prefs_ext_prog = (ExtProgPage *) _page;
70 GtkWidget *table;
71 GtkWidget *vbox;
72 GtkWidget *hint_label;
73 GtkWidget *table2;
74 GtkWidget *cmds_use_system_default_checkbtn;
75 #ifndef G_OS_WIN32
76 GtkWidget *uri_label;
77 GtkWidget *uri_combo;
78 GtkWidget *uri_entry;
79 #endif /* !G_OS_WIN32 */
80 GtkWidget *exteditor_label;
81 GtkWidget *exteditor_combo;
82 GtkWidget *exteditor_entry;
84 GtkWidget *astextviewer_label;
85 GtkWidget *astextviewer_entry;
86 int i = 0;
87 gchar *tmp;
89 table = gtk_grid_new();
90 gtk_widget_show(table);
91 gtk_container_set_border_width(GTK_CONTAINER(table), 8);
92 gtk_grid_set_row_spacing(GTK_GRID(table), 4);
93 gtk_grid_set_column_spacing(GTK_GRID(table), 8);
95 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
96 gtk_widget_show(vbox);
98 gtk_grid_attach(GTK_GRID(table), vbox, 0, 0, 1, 1);
100 hint_label = gtk_label_new(_("%s will be replaced with file name / URI"));
101 gtk_label_set_justify (GTK_LABEL (hint_label), GTK_JUSTIFY_LEFT);
102 gtkut_widget_set_small_font_size (hint_label);
103 gtk_widget_show(hint_label);
104 gtk_box_pack_start(GTK_BOX (vbox),
105 hint_label, FALSE, FALSE, 4);
107 #ifdef G_OS_UNIX
108 hint_label = gtk_label_new(_("For the text editor, %w will be replaced with GtkSocket ID"));
109 gtk_label_set_justify (GTK_LABEL (hint_label), GTK_JUSTIFY_LEFT);
110 gtkut_widget_set_small_font_size (hint_label);
111 gtk_widget_show(hint_label);
112 gtk_box_pack_start(GTK_BOX (vbox),
113 hint_label, FALSE, FALSE, 4);
114 #endif
116 table2 = gtk_grid_new();
117 gtk_widget_show(table2);
118 gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
119 gtk_grid_set_row_spacing(GTK_GRID(table2), 4);
120 gtk_grid_set_column_spacing(GTK_GRID(table2), 8);
122 gtk_grid_attach(GTK_GRID(table), table2, 0, 1, 1, 1);
123 gtk_widget_set_hexpand(table2, TRUE);
124 gtk_widget_set_halign(table2, GTK_ALIGN_FILL);
126 cmds_use_system_default_checkbtn = gtk_check_button_new_with_label(
127 _("Use system defaults when possible"));
129 gtk_widget_show(cmds_use_system_default_checkbtn);
130 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cmds_use_system_default_checkbtn),
131 prefs_common.cmds_use_system_default);
132 tmp = g_find_program_in_path("xdg-open");
133 if (!tmp) {
134 g_print("xdg-open not found\n");
135 gtk_widget_set_sensitive(cmds_use_system_default_checkbtn, FALSE);
136 gtk_widget_set_sensitive(cmds_use_system_default_checkbtn, FALSE);
137 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cmds_use_system_default_checkbtn),
138 FALSE);
139 } else
140 g_free(tmp);
143 gtk_grid_attach(GTK_GRID(table2), cmds_use_system_default_checkbtn, 0, i, 2, 1);
145 #ifndef G_OS_WIN32
146 uri_label = gtk_label_new (_("Web browser"));
147 gtk_widget_show(uri_label);
148 i++;
149 gtk_label_set_justify(GTK_LABEL (uri_label), GTK_JUSTIFY_RIGHT);
150 gtk_label_set_xalign(GTK_LABEL (uri_label), 1.0);
151 gtk_grid_attach(GTK_GRID(table2), uri_label, 0, i, 1, 1);
153 uri_combo = combobox_text_new(TRUE,
154 DEFAULT_BROWSER_CMD,
155 "galeon --new-tab '%s'",
156 "galeon '%s'",
157 "mozilla -remote 'openurl(%s,new-window)'",
158 "netscape -remote 'openURL(%s, new-window)'",
159 "netscape '%s'",
160 "gnome-moz-remote --newwin '%s'",
161 "kfmclient openURL '%s'",
162 "opera -newwindow '%s'",
163 "rxvt -e w3m '%s'",
164 "rxvt -e lynx '%s'",
165 NULL);
166 gtk_grid_attach(GTK_GRID(table2), uri_combo, 1, i, 1, 1);
168 uri_entry = gtk_bin_get_child(GTK_BIN((uri_combo)));
169 gtk_entry_set_text(GTK_ENTRY(uri_entry), prefs_common.uri_cmd ? prefs_common.uri_cmd : "");
170 #endif /* !G_OS_WIN32 */
172 exteditor_label = gtk_label_new (_("Text editor"));
173 gtk_widget_show(exteditor_label);
175 i++;
176 gtk_label_set_justify(GTK_LABEL (exteditor_label), GTK_JUSTIFY_RIGHT);
177 gtk_label_set_xalign(GTK_LABEL (exteditor_label), 1.0);
178 gtk_grid_attach(GTK_GRID(table2), exteditor_label, 0, i, 1, 1);
180 exteditor_combo = combobox_text_new(TRUE,
181 "gedit %s",
182 "kedit %s",
183 "mousepad %s",
184 "nedit %s",
185 "mgedit --no-fork %s",
186 "emacs %s",
187 "xemacs %s",
188 #ifdef G_OS_UNIX
189 "gvim -f --socketid %w %s",
190 "emacsclient --parent-id %w %s",
191 #endif
192 "kterm -e jed %s",
193 "kterm -e vi %s",
194 NULL);
195 gtk_grid_attach(GTK_GRID(table2), exteditor_combo, 1, i, 1, 1);
197 exteditor_entry = gtk_bin_get_child(GTK_BIN((exteditor_combo)));
198 gtk_entry_set_text(GTK_ENTRY(exteditor_entry),
199 prefs_common.ext_editor_cmd ? prefs_common.ext_editor_cmd : "");
201 astextviewer_label = gtk_label_new(_("Command for 'Display as text'"));
202 gtk_widget_show(astextviewer_label);
204 i++;
205 gtk_label_set_justify(GTK_LABEL (astextviewer_label), GTK_JUSTIFY_RIGHT);
206 gtk_label_set_xalign(GTK_LABEL (astextviewer_label), 1.0);
207 gtk_grid_attach(GTK_GRID(table2), astextviewer_label, 0, i, 1, 1);
209 astextviewer_entry = gtk_entry_new ();
210 gtk_widget_show(astextviewer_entry);
211 CLAWS_SET_TIP(astextviewer_entry,
212 _("This option enables MIME parts to be displayed in the "
213 "message view via a script when using the 'Display as text' "
214 "contextual menu item"));
216 gtk_grid_attach(GTK_GRID(table2), astextviewer_entry, 1, i, 1, 1);
217 gtk_widget_set_hexpand(astextviewer_entry, TRUE);
218 gtk_widget_set_halign(astextviewer_entry, GTK_ALIGN_FILL);
220 gtk_entry_set_text(GTK_ENTRY(astextviewer_entry),
221 prefs_common.mime_textviewer ? prefs_common.mime_textviewer : "");
223 #ifndef G_OS_WIN32
224 SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, uri_label);
225 SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, uri_combo);
226 #endif /* !G_OS_WIN32 */
228 #if 0 /* we should do that, but it detaches the editor and breaks
229 compose.c's external composition. */
230 SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, exteditor_label);
231 SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, exteditor_combo);
232 #endif
234 prefs_ext_prog->window = GTK_WIDGET(window);
235 #ifndef G_OS_WIN32
236 prefs_ext_prog->uri_entry = uri_entry;
237 #endif
238 prefs_ext_prog->exteditor_entry = exteditor_entry;
239 prefs_ext_prog->astextviewer_entry = astextviewer_entry;
240 prefs_ext_prog->cmds_use_system_default_checkbtn = cmds_use_system_default_checkbtn;
241 prefs_ext_prog->page.widget = table;
244 static void prefs_ext_prog_save(PrefsPage *_page)
246 ExtProgPage *ext_prog = (ExtProgPage *) _page;
248 #ifndef G_OS_WIN32
249 prefs_common.uri_cmd = gtk_editable_get_chars
250 (GTK_EDITABLE(ext_prog->uri_entry), 0, -1);
251 #endif /* !G_OS_WIN32 */
252 prefs_common.ext_editor_cmd = gtk_editable_get_chars
253 (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
254 prefs_common.mime_textviewer = gtk_editable_get_chars
255 (GTK_EDITABLE(ext_prog->astextviewer_entry), 0, -1);
256 prefs_common.cmds_use_system_default = gtk_toggle_button_get_active
257 (GTK_TOGGLE_BUTTON(ext_prog->cmds_use_system_default_checkbtn));
260 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)
262 /* ExtProgPage *ext_prog = (ExtProgPage *) _page; */
266 ExtProgPage *prefs_ext_prog;
268 void prefs_ext_prog_init(void)
270 ExtProgPage *page;
271 static gchar *path[3];
273 path[0] = _("Message View");
274 path[1] = _("External Programs");
275 path[2] = NULL;
277 page = g_new0(ExtProgPage, 1);
278 page->page.path = path;
279 page->page.create_widget = prefs_ext_prog_create_widget;
280 page->page.destroy_widget = prefs_ext_prog_destroy_widget;
281 page->page.save_page = prefs_ext_prog_save;
282 page->page.weight = 155.0;
283 prefs_gtk_register_page((PrefsPage *) page);
284 prefs_ext_prog = page;
287 void prefs_ext_prog_done(void)
289 prefs_gtk_unregister_page((PrefsPage *) prefs_ext_prog);
290 g_free(prefs_ext_prog);