2006-06-27 [ticho] 2.3.1cvs24
[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 *printcmd_label;
83         GtkWidget *printcmd_entry;
84         GtkWidget *exteditor_label;
85         GtkWidget *exteditor_combo;
86         GtkWidget *exteditor_entry;
87         GtkWidget *image_viewer_label;
88         GtkWidget *image_viewer_entry;
89         GtkWidget *astextviewer_label;
90         GtkWidget *astextviewer_entry;
91         GtkWidget *audio_player_label;
92         GtkWidget *audio_player_entry;
93
94         table = gtk_table_new(2, 1, FALSE);
95         gtk_widget_show(table);
96         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
97         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
98         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
99
100         vbox = gtk_vbox_new(TRUE, 0);
101         gtk_widget_show(vbox);
102         
103         gtk_table_attach(GTK_TABLE (table), vbox, 0, 1, 0, 1,
104                          (GtkAttachOptions) (GTK_SHRINK),
105                          (GtkAttachOptions) (0), 0, 0);
106
107         hint_label = gtk_label_new(_("%s will be replaced with file name / URI"));
108         gtk_label_set_justify (GTK_LABEL (hint_label), GTK_JUSTIFY_LEFT);
109         gtkut_widget_set_small_font_size (hint_label);
110         gtk_widget_show(hint_label);
111         gtk_box_pack_start(GTK_BOX (vbox),
112                            hint_label, FALSE, FALSE, 4);
113
114         table2 = gtk_table_new(6, 2, FALSE);
115         gtk_widget_show(table2);
116         gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
117         gtk_table_set_row_spacings(GTK_TABLE(table2), 4);
118         gtk_table_set_col_spacings(GTK_TABLE(table2), 8);
119         
120         gtk_table_attach(GTK_TABLE (table), table2, 0, 1, 1, 2,
121                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
122                          (GtkAttachOptions) (0), 0, 0);
123                          
124         uri_label = gtk_label_new (_("Web browser"));
125         gtk_widget_show(uri_label);
126
127         gtk_table_attach(GTK_TABLE (table2), uri_label, 0, 1, 0, 1,
128                          (GtkAttachOptions) (GTK_FILL),
129                          (GtkAttachOptions) (0), 0, 2);
130         gtk_label_set_justify(GTK_LABEL (uri_label), GTK_JUSTIFY_RIGHT);
131         gtk_misc_set_alignment(GTK_MISC (uri_label), 1, 0.5);
132
133         uri_combo = gtk_combo_new ();
134         gtk_widget_show (uri_combo);
135         gtk_table_attach (GTK_TABLE (table2), uri_combo, 1, 2, 0, 1,
136                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
137         gtkut_combo_set_items (GTK_COMBO (uri_combo),
138                                DEFAULT_BROWSER_CMD,
139                                "galeon --new-tab '%s'",
140                                "galeon '%s'",
141                                "mozilla -remote 'openurl(%s,new-window)'",
142                                "netscape -remote 'openURL(%s, new-window)'",
143                                "netscape '%s'",
144                                "gnome-moz-remote --newwin '%s'",
145                                "kfmclient openURL '%s'",
146                                "opera -newwindow '%s'",
147                                "rxvt -e w3m '%s'",
148                                "rxvt -e lynx '%s'",
149                                NULL);
150         uri_entry = GTK_COMBO (uri_combo)->entry;
151         gtk_entry_set_text(GTK_ENTRY(uri_entry), prefs_common.uri_cmd ? prefs_common.uri_cmd : "");
152         
153         printcmd_label = gtk_label_new (_("Print command"));
154         gtk_widget_show(printcmd_label);
155
156         gtk_table_attach(GTK_TABLE (table2), printcmd_label, 0, 1, 1, 2,
157                          (GtkAttachOptions) (GTK_FILL),
158                          (GtkAttachOptions) (0), 0, 2);
159         gtk_label_set_justify(GTK_LABEL (printcmd_label), GTK_JUSTIFY_RIGHT);
160         gtk_misc_set_alignment(GTK_MISC (printcmd_label), 1, 0.5);
161
162         printcmd_entry = gtk_entry_new ();
163         gtk_widget_show (printcmd_entry);
164         gtk_table_attach(GTK_TABLE (table2), printcmd_entry, 1, 2, 1, 2,
165                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
166                          (GtkAttachOptions) (0), 0, 0);
167         gtk_entry_set_text(GTK_ENTRY(printcmd_entry), prefs_common.print_cmd ? prefs_common.print_cmd : "");
168
169         exteditor_label = gtk_label_new (_("Text editor"));
170         gtk_widget_show(exteditor_label);
171
172         gtk_table_attach(GTK_TABLE (table2), exteditor_label, 0, 1, 2, 3,
173                          (GtkAttachOptions) (GTK_FILL),
174                          (GtkAttachOptions) (0), 0, 2);
175         gtk_label_set_justify(GTK_LABEL (exteditor_label), GTK_JUSTIFY_RIGHT);
176         gtk_misc_set_alignment(GTK_MISC (exteditor_label), 1, 0.5);
177
178         exteditor_combo = gtk_combo_new ();
179         gtk_widget_show (exteditor_combo);
180         gtk_table_attach (GTK_TABLE (table2), exteditor_combo, 1, 2, 2, 3,
181                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
182         gtkut_combo_set_items (GTK_COMBO (exteditor_combo),
183                                "gedit %s",
184                                "kedit %s",
185                                "nedit %s",
186                                "mgedit --no-fork %s",
187                                "emacs %s",
188                                "xemacs %s",
189                                "kterm -e jed %s",
190                                "kterm -e vi %s",
191                                NULL);
192         exteditor_entry = GTK_COMBO (exteditor_combo)->entry;
193         gtk_entry_set_text(GTK_ENTRY(exteditor_entry), 
194                            prefs_common.ext_editor_cmd ? prefs_common.ext_editor_cmd : "");
195
196         image_viewer_label = gtk_label_new (_("Image viewer"));
197         gtk_widget_show(image_viewer_label);
198
199         gtk_table_attach(GTK_TABLE (table2), image_viewer_label, 0, 1, 3, 4,
200                          (GtkAttachOptions) (GTK_FILL),
201                          (GtkAttachOptions) (0), 0, 2);
202         gtk_label_set_justify(GTK_LABEL (image_viewer_label), GTK_JUSTIFY_RIGHT);
203         gtk_misc_set_alignment(GTK_MISC (image_viewer_label), 1, 0.5);
204
205         image_viewer_entry = gtk_entry_new ();
206         gtk_widget_show(image_viewer_entry);
207         
208         gtk_table_attach(GTK_TABLE (table2), image_viewer_entry, 1, 2, 3, 4,
209                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
210                          (GtkAttachOptions) (0), 0, 0);
211         gtk_entry_set_text(GTK_ENTRY(image_viewer_entry), 
212                            prefs_common.mime_image_viewer ? prefs_common.mime_image_viewer : "");
213
214         astextviewer_label = gtk_label_new(_("View as text command"));
215         gtk_widget_show(astextviewer_label);
216
217         gtk_table_attach(GTK_TABLE (table2), astextviewer_label, 0, 1, 4, 5,
218                          (GtkAttachOptions) (GTK_FILL),
219                          (GtkAttachOptions) (0), 0, 2);
220         gtk_label_set_justify(GTK_LABEL (astextviewer_label), GTK_JUSTIFY_RIGHT);
221         gtk_misc_set_alignment(GTK_MISC (astextviewer_label), 1, 0.5);
222
223         astextviewer_entry = gtk_entry_new ();
224         gtk_widget_show(astextviewer_entry);
225         
226         gtk_table_attach(GTK_TABLE (table2), astextviewer_entry, 1, 2, 4, 5,
227                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
228                          (GtkAttachOptions) (0), 0, 0);
229         gtk_entry_set_text(GTK_ENTRY(astextviewer_entry), 
230                            prefs_common.mime_textviewer ? prefs_common.mime_textviewer : "");
231
232         audio_player_label = gtk_label_new (_("Audio player"));
233         gtk_widget_show(audio_player_label);
234
235         gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 5, 6,
236                          (GtkAttachOptions) (GTK_FILL),
237                          (GtkAttachOptions) (0), 0, 2);
238         gtk_label_set_justify(GTK_LABEL (audio_player_label), GTK_JUSTIFY_RIGHT);
239         gtk_misc_set_alignment(GTK_MISC (audio_player_label), 1, 0.5);
240
241         audio_player_entry = gtk_entry_new ();
242         gtk_widget_show(audio_player_entry);
243         
244         gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 5, 6,
245                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
246                          (GtkAttachOptions) (0), 0, 0);
247         gtk_entry_set_text(GTK_ENTRY(audio_player_entry), 
248                            prefs_common.mime_audio_player ? prefs_common.mime_audio_player : "");
249
250         prefs_ext_prog->window                  = GTK_WIDGET(window);
251         prefs_ext_prog->uri_entry               = uri_entry;
252         prefs_ext_prog->printcmd_entry          = printcmd_entry;
253         prefs_ext_prog->exteditor_entry         = exteditor_entry;
254         prefs_ext_prog->image_viewer_entry      = image_viewer_entry;
255         prefs_ext_prog->astextviewer_entry      = astextviewer_entry;
256         prefs_ext_prog->audio_player_entry      = audio_player_entry;
257
258         prefs_ext_prog->page.widget = table;
259 }
260
261 void prefs_ext_prog_save(PrefsPage *_page)
262 {
263         ExtProgPage *ext_prog = (ExtProgPage *) _page;
264
265         prefs_common.uri_cmd = gtk_editable_get_chars
266                 (GTK_EDITABLE(ext_prog->uri_entry), 0, -1);
267         prefs_common.print_cmd = gtk_editable_get_chars
268                 (GTK_EDITABLE(ext_prog->printcmd_entry), 0, -1);
269         prefs_common.ext_editor_cmd = gtk_editable_get_chars
270                 (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
271         prefs_common.mime_image_viewer = gtk_editable_get_chars
272                 (GTK_EDITABLE(ext_prog->image_viewer_entry), 0, -1);
273         prefs_common.mime_textviewer = gtk_editable_get_chars
274                 (GTK_EDITABLE(ext_prog->astextviewer_entry), 0, -1);
275         prefs_common.mime_audio_player = gtk_editable_get_chars
276                 (GTK_EDITABLE(ext_prog->audio_player_entry), 0, -1);
277 }
278
279 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)
280 {
281         /* ExtProgPage *ext_prog = (ExtProgPage *) _page; */
282
283 }
284
285 ExtProgPage *prefs_ext_prog;
286
287 void prefs_ext_prog_init(void)
288 {
289         ExtProgPage *page;
290         static gchar *path[3];
291         
292         path[0] = _("Message View");
293         path[1] = _("External Programs");
294         path[2] = NULL;
295
296         page = g_new0(ExtProgPage, 1);
297         page->page.path = path;
298         page->page.create_widget = prefs_ext_prog_create_widget;
299         page->page.destroy_widget = prefs_ext_prog_destroy_widget;
300         page->page.save_page = prefs_ext_prog_save;
301         page->page.weight = 155.0;
302         prefs_gtk_register_page((PrefsPage *) page);
303         prefs_ext_prog = page;
304 }
305
306 void prefs_ext_prog_done(void)
307 {
308         prefs_gtk_unregister_page((PrefsPage *) prefs_ext_prog);
309         g_free(prefs_ext_prog);
310 }