2007-10-17 [wwp] 3.0.2cvs78
[claws.git] / src / prefs_ext_prog.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2004 Hiroyuki Yamamoto & the Claws Mail team
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
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkkeysyms.h>
33
34 #include "utils.h"
35 #include "combobox.h"
36 #include "prefs_common.h"
37 #include "prefs_gtk.h"
38
39 #include "gtk/gtkutils.h"
40 #include "gtk/prefswindow.h"
41
42 #include "manage_window.h"
43
44 typedef struct _ExtProgPage
45 {
46         PrefsPage page;
47
48         GtkWidget *window;              /* do not modify */
49
50         GtkWidget *uri_label;
51         GtkWidget *uri_combo;
52         GtkWidget *uri_entry;
53         
54         GtkWidget *printcmd_label;
55         GtkWidget *printcmd_entry;
56         
57         GtkWidget *exteditor_label;
58         GtkWidget *exteditor_combo;
59         GtkWidget *exteditor_entry;
60
61         GtkWidget *astextviewer_label;
62         GtkWidget *astextviewer_entry;
63 } ExtProgPage;
64
65 static void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window, 
66                                   gpointer data)
67 {
68         ExtProgPage *prefs_ext_prog = (ExtProgPage *) _page;
69
70         GtkWidget *table;
71         GtkWidget *vbox;
72         GtkWidget *hint_label;
73         GtkWidget *table2;
74         GtkWidget *uri_label;
75         GtkWidget *uri_combo;
76         GtkWidget *uri_entry;
77         GtkWidget *exteditor_label;
78         GtkWidget *exteditor_combo;
79         GtkWidget *exteditor_entry;
80         GtkWidget *astextviewer_label;
81         GtkWidget *astextviewer_entry;
82         GtkWidget *printcmd_label;
83         GtkWidget *printcmd_entry;
84         GtkTooltips *tooltip;
85
86         tooltip = gtk_tooltips_new();
87
88         table = gtk_table_new(2, 1, FALSE);
89         gtk_widget_show(table);
90         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
91         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
92         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
93
94         vbox = gtk_vbox_new(TRUE, 0);
95         gtk_widget_show(vbox);
96         
97         gtk_table_attach(GTK_TABLE (table), vbox, 0, 1, 0, 1,
98                          (GtkAttachOptions) (GTK_SHRINK),
99                          (GtkAttachOptions) (0), 0, 0);
100
101         hint_label = gtk_label_new(_("%s will be replaced with file name / URI"));
102         gtk_label_set_justify (GTK_LABEL (hint_label), GTK_JUSTIFY_LEFT);
103         gtkut_widget_set_small_font_size (hint_label);
104         gtk_widget_show(hint_label);
105         gtk_box_pack_start(GTK_BOX (vbox),
106                            hint_label, FALSE, FALSE, 4);
107
108         table2 = gtk_table_new(6, 2, FALSE);
109         gtk_widget_show(table2);
110         gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
111         gtk_table_set_row_spacings(GTK_TABLE(table2), 4);
112         gtk_table_set_col_spacings(GTK_TABLE(table2), 8);
113         
114         gtk_table_attach(GTK_TABLE (table), table2, 0, 1, 1, 2,
115                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
116                          (GtkAttachOptions) (0), 0, 0);
117                          
118         uri_label = gtk_label_new (_("Web browser"));
119         gtk_widget_show(uri_label);
120 #ifdef MAEMO
121         gtk_widget_set_sensitive(uri_label, FALSE);
122 #endif
123         gtk_table_attach(GTK_TABLE (table2), uri_label, 0, 1, 0, 1,
124                          (GtkAttachOptions) (GTK_FILL),
125                          (GtkAttachOptions) (0), 0, 2);
126         gtk_label_set_justify(GTK_LABEL (uri_label), GTK_JUSTIFY_RIGHT);
127         gtk_misc_set_alignment(GTK_MISC (uri_label), 1, 0.5);
128
129         uri_combo = combobox_text_new(TRUE,
130                                DEFAULT_BROWSER_CMD,
131                                "galeon --new-tab '%s'",
132                                "galeon '%s'",
133                                "mozilla -remote 'openurl(%s,new-window)'",
134                                "netscape -remote 'openURL(%s, new-window)'",
135                                "netscape '%s'",
136                                "gnome-moz-remote --newwin '%s'",
137                                "kfmclient openURL '%s'",
138                                "opera -newwindow '%s'",
139                                "rxvt -e w3m '%s'",
140                                "rxvt -e lynx '%s'",
141                                NULL);
142 #ifdef MAEMO
143         gtk_widget_set_sensitive(uri_combo, FALSE);
144 #endif
145         gtk_table_attach (GTK_TABLE (table2), uri_combo, 1, 2, 0, 1,
146                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
147
148         uri_entry = GTK_BIN (uri_combo)->child;
149         gtk_entry_set_text(GTK_ENTRY(uri_entry), prefs_common.uri_cmd ? prefs_common.uri_cmd : "");
150         
151         exteditor_label = gtk_label_new (_("Text editor"));
152         gtk_widget_show(exteditor_label);
153
154         gtk_table_attach(GTK_TABLE (table2), exteditor_label, 0, 1, 1, 2,
155                          (GtkAttachOptions) (GTK_FILL),
156                          (GtkAttachOptions) (0), 0, 2);
157         gtk_label_set_justify(GTK_LABEL (exteditor_label), GTK_JUSTIFY_RIGHT);
158         gtk_misc_set_alignment(GTK_MISC (exteditor_label), 1, 0.5);
159
160         exteditor_combo = combobox_text_new(TRUE,
161                                         "gedit %s",
162                                         "kedit %s",
163                                         "mousepad %s",
164                                         "nedit %s",
165                                         "mgedit --no-fork %s",
166                                         "emacs %s",
167                                         "xemacs %s",
168                                         "kterm -e jed %s",
169                                         "kterm -e vi %s",
170                                         NULL);
171         gtk_table_attach (GTK_TABLE (table2), exteditor_combo, 1, 2, 1, 2,
172                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
173
174         exteditor_entry = GTK_BIN (exteditor_combo)->child;
175         gtk_entry_set_text(GTK_ENTRY(exteditor_entry), 
176                            prefs_common.ext_editor_cmd ? prefs_common.ext_editor_cmd : "");
177
178         astextviewer_label = gtk_label_new(_("Command for 'Display as text'"));
179         gtk_widget_show(astextviewer_label);
180
181         gtk_table_attach(GTK_TABLE (table2), astextviewer_label, 0, 1, 2, 3,
182                          (GtkAttachOptions) (GTK_FILL),
183                          (GtkAttachOptions) (0), 0, 2);
184         gtk_label_set_justify(GTK_LABEL (astextviewer_label), GTK_JUSTIFY_RIGHT);
185         gtk_misc_set_alignment(GTK_MISC (astextviewer_label), 1, 0.5);
186
187         astextviewer_entry = gtk_entry_new ();
188         gtk_widget_show(astextviewer_entry);
189         gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltip), astextviewer_entry,
190                              _("This option enables MIME parts to be displayed in the "
191                                "message view via a script when using the 'Display as text' "
192                                "contextual menu item"),
193                              NULL);
194         
195         gtk_table_attach(GTK_TABLE (table2), astextviewer_entry, 1, 2, 2, 3,
196                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
197                          (GtkAttachOptions) (0), 0, 0);
198         gtk_entry_set_text(GTK_ENTRY(astextviewer_entry), 
199                            prefs_common.mime_textviewer ? prefs_common.mime_textviewer : "");
200
201         printcmd_label = gtk_label_new (_("Print command"));
202 #if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
203         gtk_widget_show(printcmd_label);
204 #endif
205         gtk_table_attach(GTK_TABLE (table2), printcmd_label, 0, 1, 3, 4,
206                          (GtkAttachOptions) (GTK_FILL),
207                          (GtkAttachOptions) (0), 0, 2);
208         gtk_label_set_justify(GTK_LABEL (printcmd_label), GTK_JUSTIFY_RIGHT);
209         gtk_misc_set_alignment(GTK_MISC (printcmd_label), 1, 0.5);
210
211         printcmd_entry = gtk_entry_new ();
212 #if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
213         gtk_widget_show(printcmd_entry);
214 #endif
215         gtk_table_attach(GTK_TABLE (table2), printcmd_entry, 1, 2, 3, 4,
216                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
217                          (GtkAttachOptions) (0), 0, 0);
218         gtk_entry_set_text(GTK_ENTRY(printcmd_entry), prefs_common.print_cmd ? prefs_common.print_cmd : "");
219
220
221         prefs_ext_prog->window                  = GTK_WIDGET(window);
222         prefs_ext_prog->uri_entry               = uri_entry;
223         prefs_ext_prog->exteditor_entry         = exteditor_entry;
224         prefs_ext_prog->astextviewer_entry      = astextviewer_entry;
225         prefs_ext_prog->printcmd_entry          = printcmd_entry;
226
227         prefs_ext_prog->page.widget = table;
228 }
229
230 static void prefs_ext_prog_save(PrefsPage *_page)
231 {
232         ExtProgPage *ext_prog = (ExtProgPage *) _page;
233
234         prefs_common.uri_cmd = gtk_editable_get_chars
235                 (GTK_EDITABLE(ext_prog->uri_entry), 0, -1);
236         prefs_common.print_cmd = gtk_editable_get_chars
237                 (GTK_EDITABLE(ext_prog->printcmd_entry), 0, -1);
238         prefs_common.ext_editor_cmd = gtk_editable_get_chars
239                 (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
240         prefs_common.mime_textviewer = gtk_editable_get_chars
241                 (GTK_EDITABLE(ext_prog->astextviewer_entry), 0, -1);
242 }
243
244 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)
245 {
246         /* ExtProgPage *ext_prog = (ExtProgPage *) _page; */
247
248 }
249
250 ExtProgPage *prefs_ext_prog;
251
252 void prefs_ext_prog_init(void)
253 {
254         ExtProgPage *page;
255         static gchar *path[3];
256         
257         path[0] = _("Message View");
258         path[1] = _("External Programs");
259         path[2] = NULL;
260
261         page = g_new0(ExtProgPage, 1);
262         page->page.path = path;
263         page->page.create_widget = prefs_ext_prog_create_widget;
264         page->page.destroy_widget = prefs_ext_prog_destroy_widget;
265         page->page.save_page = prefs_ext_prog_save;
266         page->page.weight = 155.0;
267         prefs_gtk_register_page((PrefsPage *) page);
268         prefs_ext_prog = page;
269 }
270
271 void prefs_ext_prog_done(void)
272 {
273         prefs_gtk_unregister_page((PrefsPage *) prefs_ext_prog);
274         g_free(prefs_ext_prog);
275 }