2006-06-28 [paul] 2.3.1cvs29
[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 Sylpheed-Claws 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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 "prefs_common.h"
36 #include "prefs_gtk.h"
37
38 #include "gtk/gtkutils.h"
39 #include "gtk/prefswindow.h"
40
41 #include "manage_window.h"
42
43 typedef struct _ExtProgPage
44 {
45         PrefsPage page;
46
47         GtkWidget *window;              /* do not modify */
48
49         GtkWidget *uri_label;
50         GtkWidget *uri_combo;
51         GtkWidget *uri_entry;
52         
53         GtkWidget *printcmd_label;
54         GtkWidget *printcmd_entry;
55         
56         GtkWidget *exteditor_label;
57         GtkWidget *exteditor_combo;
58         GtkWidget *exteditor_entry;
59
60         GtkWidget *image_viewer_label;
61         GtkWidget *image_viewer_entry;
62         
63         GtkWidget *astextviewer_label;
64         GtkWidget *astextviewer_entry;
65
66         GtkWidget *audio_player_label;
67         GtkWidget *audio_player_entry;
68 } ExtProgPage;
69
70 void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window, 
71                                   gpointer data)
72 {
73         ExtProgPage *prefs_ext_prog = (ExtProgPage *) _page;
74
75         GtkWidget *table;
76         GtkWidget *vbox;
77         GtkWidget *hint_label;
78         GtkWidget *table2;
79         GtkWidget *uri_label;
80         GtkWidget *uri_combo;
81         GtkWidget *uri_entry;
82         GtkWidget *exteditor_label;
83         GtkWidget *exteditor_combo;
84         GtkWidget *exteditor_entry;
85         GtkWidget *image_viewer_label;
86         GtkWidget *image_viewer_entry;
87         GtkWidget *astextviewer_label;
88         GtkWidget *astextviewer_entry;
89         GtkWidget *audio_player_label;
90         GtkWidget *audio_player_entry;
91         GtkWidget *printcmd_label;
92         GtkWidget *printcmd_entry;
93         GtkTooltips *tooltip;
94
95         tooltip = gtk_tooltips_new();
96
97         table = gtk_table_new(2, 1, FALSE);
98         gtk_widget_show(table);
99         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
100         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
101         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
102
103         vbox = gtk_vbox_new(TRUE, 0);
104         gtk_widget_show(vbox);
105         
106         gtk_table_attach(GTK_TABLE (table), vbox, 0, 1, 0, 1,
107                          (GtkAttachOptions) (GTK_SHRINK),
108                          (GtkAttachOptions) (0), 0, 0);
109
110         hint_label = gtk_label_new(_("%s will be replaced with file name / URI"));
111         gtk_label_set_justify (GTK_LABEL (hint_label), GTK_JUSTIFY_LEFT);
112         gtkut_widget_set_small_font_size (hint_label);
113         gtk_widget_show(hint_label);
114         gtk_box_pack_start(GTK_BOX (vbox),
115                            hint_label, FALSE, FALSE, 4);
116
117         table2 = gtk_table_new(6, 2, FALSE);
118         gtk_widget_show(table2);
119         gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
120         gtk_table_set_row_spacings(GTK_TABLE(table2), 4);
121         gtk_table_set_col_spacings(GTK_TABLE(table2), 8);
122         
123         gtk_table_attach(GTK_TABLE (table), table2, 0, 1, 1, 2,
124                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
125                          (GtkAttachOptions) (0), 0, 0);
126                          
127         uri_label = gtk_label_new (_("Web browser"));
128         gtk_widget_show(uri_label);
129
130         gtk_table_attach(GTK_TABLE (table2), uri_label, 0, 1, 0, 1,
131                          (GtkAttachOptions) (GTK_FILL),
132                          (GtkAttachOptions) (0), 0, 2);
133         gtk_label_set_justify(GTK_LABEL (uri_label), GTK_JUSTIFY_RIGHT);
134         gtk_misc_set_alignment(GTK_MISC (uri_label), 1, 0.5);
135
136         uri_combo = gtk_combo_new ();
137         gtk_widget_show (uri_combo);
138         gtk_table_attach (GTK_TABLE (table2), uri_combo, 1, 2, 0, 1,
139                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
140         gtkut_combo_set_items (GTK_COMBO (uri_combo),
141                                DEFAULT_BROWSER_CMD,
142                                "galeon --new-tab '%s'",
143                                "galeon '%s'",
144                                "mozilla -remote 'openurl(%s,new-window)'",
145                                "netscape -remote 'openURL(%s, new-window)'",
146                                "netscape '%s'",
147                                "gnome-moz-remote --newwin '%s'",
148                                "kfmclient openURL '%s'",
149                                "opera -newwindow '%s'",
150                                "rxvt -e w3m '%s'",
151                                "rxvt -e lynx '%s'",
152                                NULL);
153         uri_entry = GTK_COMBO (uri_combo)->entry;
154         gtk_entry_set_text(GTK_ENTRY(uri_entry), prefs_common.uri_cmd ? prefs_common.uri_cmd : "");
155         
156         exteditor_label = gtk_label_new (_("Text editor"));
157         gtk_widget_show(exteditor_label);
158
159         gtk_table_attach(GTK_TABLE (table2), exteditor_label, 0, 1, 1, 2,
160                          (GtkAttachOptions) (GTK_FILL),
161                          (GtkAttachOptions) (0), 0, 2);
162         gtk_label_set_justify(GTK_LABEL (exteditor_label), GTK_JUSTIFY_RIGHT);
163         gtk_misc_set_alignment(GTK_MISC (exteditor_label), 1, 0.5);
164
165         exteditor_combo = gtk_combo_new ();
166         gtk_widget_show (exteditor_combo);
167         gtk_table_attach (GTK_TABLE (table2), exteditor_combo, 1, 2, 1, 2,
168                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
169         gtkut_combo_set_items (GTK_COMBO (exteditor_combo),
170                                "gedit %s",
171                                "kedit %s",
172                                "nedit %s",
173                                "mgedit --no-fork %s",
174                                "emacs %s",
175                                "xemacs %s",
176                                "kterm -e jed %s",
177                                "kterm -e vi %s",
178                                NULL);
179         exteditor_entry = GTK_COMBO (exteditor_combo)->entry;
180         gtk_entry_set_text(GTK_ENTRY(exteditor_entry), 
181                            prefs_common.ext_editor_cmd ? prefs_common.ext_editor_cmd : "");
182
183         image_viewer_label = gtk_label_new (_("Image viewer"));
184         gtk_widget_show(image_viewer_label);
185
186         gtk_table_attach(GTK_TABLE (table2), image_viewer_label, 0, 1, 2, 3,
187                          (GtkAttachOptions) (GTK_FILL),
188                          (GtkAttachOptions) (0), 0, 2);
189         gtk_label_set_justify(GTK_LABEL (image_viewer_label), GTK_JUSTIFY_RIGHT);
190         gtk_misc_set_alignment(GTK_MISC (image_viewer_label), 1, 0.5);
191
192         image_viewer_entry = gtk_entry_new ();
193         gtk_widget_show(image_viewer_entry);
194         
195         gtk_table_attach(GTK_TABLE (table2), image_viewer_entry, 1, 2, 2, 3,
196                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
197                          (GtkAttachOptions) (0), 0, 0);
198         gtk_entry_set_text(GTK_ENTRY(image_viewer_entry), 
199                            prefs_common.mime_image_viewer ? prefs_common.mime_image_viewer : "");
200
201         astextviewer_label = gtk_label_new(_("Command for 'Display as text'"));
202         gtk_widget_show(astextviewer_label);
203
204         gtk_table_attach(GTK_TABLE (table2), astextviewer_label, 0, 1, 3, 4,
205                          (GtkAttachOptions) (GTK_FILL),
206                          (GtkAttachOptions) (0), 0, 2);
207         gtk_label_set_justify(GTK_LABEL (astextviewer_label), GTK_JUSTIFY_RIGHT);
208         gtk_misc_set_alignment(GTK_MISC (astextviewer_label), 1, 0.5);
209
210         astextviewer_entry = gtk_entry_new ();
211         gtk_widget_show(astextviewer_entry);
212         gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltip), astextviewer_entry,
213                              _("This option enables MIME parts to be displayed in the "
214                                "message view via a script when using the 'Display as text' "
215                                "contextual menu item"),
216                              NULL);
217         
218         gtk_table_attach(GTK_TABLE (table2), astextviewer_entry, 1, 2, 3, 4,
219                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
220                          (GtkAttachOptions) (0), 0, 0);
221         gtk_entry_set_text(GTK_ENTRY(astextviewer_entry), 
222                            prefs_common.mime_textviewer ? prefs_common.mime_textviewer : "");
223
224         audio_player_label = gtk_label_new (_("Audio player"));
225         gtk_widget_show(audio_player_label);
226
227         gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 4, 5,
228                          (GtkAttachOptions) (GTK_FILL),
229                          (GtkAttachOptions) (0), 0, 2);
230         gtk_label_set_justify(GTK_LABEL (audio_player_label), GTK_JUSTIFY_RIGHT);
231         gtk_misc_set_alignment(GTK_MISC (audio_player_label), 1, 0.5);
232
233         audio_player_entry = gtk_entry_new ();
234         gtk_widget_show(audio_player_entry);
235         
236         gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 4, 5,
237                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
238                          (GtkAttachOptions) (0), 0, 0);
239         gtk_entry_set_text(GTK_ENTRY(audio_player_entry), 
240                            prefs_common.mime_audio_player ? prefs_common.mime_audio_player : "");
241
242         printcmd_label = gtk_label_new (_("Print command"));
243         #ifndef USE_GNOMEPRINT
244                 gtk_widget_show(printcmd_label);
245         #endif
246         gtk_table_attach(GTK_TABLE (table2), printcmd_label, 0, 1, 5, 6,
247                          (GtkAttachOptions) (GTK_FILL),
248                          (GtkAttachOptions) (0), 0, 2);
249         gtk_label_set_justify(GTK_LABEL (printcmd_label), GTK_JUSTIFY_RIGHT);
250         gtk_misc_set_alignment(GTK_MISC (printcmd_label), 1, 0.5);
251
252         printcmd_entry = gtk_entry_new ();
253         #ifndef USE_GNOMEPRINT
254                 gtk_widget_show(printcmd_entry);
255         #endif
256         gtk_table_attach(GTK_TABLE (table2), printcmd_entry, 1, 2, 5, 6,
257                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
258                          (GtkAttachOptions) (0), 0, 0);
259         gtk_entry_set_text(GTK_ENTRY(printcmd_entry), prefs_common.print_cmd ? prefs_common.print_cmd : "");
260
261
262         prefs_ext_prog->window                  = GTK_WIDGET(window);
263         prefs_ext_prog->uri_entry               = uri_entry;
264         prefs_ext_prog->exteditor_entry         = exteditor_entry;
265         prefs_ext_prog->image_viewer_entry      = image_viewer_entry;
266         prefs_ext_prog->astextviewer_entry      = astextviewer_entry;
267         prefs_ext_prog->audio_player_entry      = audio_player_entry;
268         prefs_ext_prog->printcmd_entry          = printcmd_entry;
269
270         prefs_ext_prog->page.widget = table;
271 }
272
273 void prefs_ext_prog_save(PrefsPage *_page)
274 {
275         ExtProgPage *ext_prog = (ExtProgPage *) _page;
276
277         prefs_common.uri_cmd = gtk_editable_get_chars
278                 (GTK_EDITABLE(ext_prog->uri_entry), 0, -1);
279         prefs_common.print_cmd = gtk_editable_get_chars
280                 (GTK_EDITABLE(ext_prog->printcmd_entry), 0, -1);
281         prefs_common.ext_editor_cmd = gtk_editable_get_chars
282                 (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
283         prefs_common.mime_image_viewer = gtk_editable_get_chars
284                 (GTK_EDITABLE(ext_prog->image_viewer_entry), 0, -1);
285         prefs_common.mime_textviewer = gtk_editable_get_chars
286                 (GTK_EDITABLE(ext_prog->astextviewer_entry), 0, -1);
287         prefs_common.mime_audio_player = gtk_editable_get_chars
288                 (GTK_EDITABLE(ext_prog->audio_player_entry), 0, -1);
289 }
290
291 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)
292 {
293         /* ExtProgPage *ext_prog = (ExtProgPage *) _page; */
294
295 }
296
297 ExtProgPage *prefs_ext_prog;
298
299 void prefs_ext_prog_init(void)
300 {
301         ExtProgPage *page;
302         static gchar *path[3];
303         
304         path[0] = _("Message View");
305         path[1] = _("External Programs");
306         path[2] = NULL;
307
308         page = g_new0(ExtProgPage, 1);
309         page->page.path = path;
310         page->page.create_widget = prefs_ext_prog_create_widget;
311         page->page.destroy_widget = prefs_ext_prog_destroy_widget;
312         page->page.save_page = prefs_ext_prog_save;
313         page->page.weight = 155.0;
314         prefs_gtk_register_page((PrefsPage *) page);
315         prefs_ext_prog = page;
316 }
317
318 void prefs_ext_prog_done(void)
319 {
320         prefs_gtk_unregister_page((PrefsPage *) prefs_ext_prog);
321         g_free(prefs_ext_prog);
322 }