db06a46d5964caa03421b6d04fc93009658b5c6a
[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
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         exteditor_label = gtk_label_new (_("Text editor"));
154         gtk_widget_show(exteditor_label);
155
156         gtk_table_attach(GTK_TABLE (table2), exteditor_label, 0, 1, 1, 2,
157                          (GtkAttachOptions) (GTK_FILL),
158                          (GtkAttachOptions) (0), 0, 2);
159         gtk_label_set_justify(GTK_LABEL (exteditor_label), GTK_JUSTIFY_RIGHT);
160         gtk_misc_set_alignment(GTK_MISC (exteditor_label), 1, 0.5);
161
162         exteditor_combo = gtk_combo_new ();
163         gtk_widget_show (exteditor_combo);
164         gtk_table_attach (GTK_TABLE (table2), exteditor_combo, 1, 2, 1, 2,
165                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
166         gtkut_combo_set_items (GTK_COMBO (exteditor_combo),
167                                "gedit %s",
168                                "kedit %s",
169                                "nedit %s",
170                                "mgedit --no-fork %s",
171                                "emacs %s",
172                                "xemacs %s",
173                                "kterm -e jed %s",
174                                "kterm -e vi %s",
175                                NULL);
176         exteditor_entry = GTK_COMBO (exteditor_combo)->entry;
177         gtk_entry_set_text(GTK_ENTRY(exteditor_entry), 
178                            prefs_common.ext_editor_cmd ? prefs_common.ext_editor_cmd : "");
179
180         image_viewer_label = gtk_label_new (_("Image viewer"));
181         gtk_widget_show(image_viewer_label);
182
183         gtk_table_attach(GTK_TABLE (table2), image_viewer_label, 0, 1, 2, 3,
184                          (GtkAttachOptions) (GTK_FILL),
185                          (GtkAttachOptions) (0), 0, 2);
186         gtk_label_set_justify(GTK_LABEL (image_viewer_label), GTK_JUSTIFY_RIGHT);
187         gtk_misc_set_alignment(GTK_MISC (image_viewer_label), 1, 0.5);
188
189         image_viewer_entry = gtk_entry_new ();
190         gtk_widget_show(image_viewer_entry);
191         
192         gtk_table_attach(GTK_TABLE (table2), image_viewer_entry, 1, 2, 2, 3,
193                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
194                          (GtkAttachOptions) (0), 0, 0);
195         gtk_entry_set_text(GTK_ENTRY(image_viewer_entry), 
196                            prefs_common.mime_image_viewer ? prefs_common.mime_image_viewer : "");
197
198         astextviewer_label = gtk_label_new(_("View as text command"));
199         gtk_widget_show(astextviewer_label);
200
201         gtk_table_attach(GTK_TABLE (table2), astextviewer_label, 0, 1, 3, 4,
202                          (GtkAttachOptions) (GTK_FILL),
203                          (GtkAttachOptions) (0), 0, 2);
204         gtk_label_set_justify(GTK_LABEL (astextviewer_label), GTK_JUSTIFY_RIGHT);
205         gtk_misc_set_alignment(GTK_MISC (astextviewer_label), 1, 0.5);
206
207         astextviewer_entry = gtk_entry_new ();
208         gtk_widget_show(astextviewer_entry);
209         
210         gtk_table_attach(GTK_TABLE (table2), astextviewer_entry, 1, 2, 3, 4,
211                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
212                          (GtkAttachOptions) (0), 0, 0);
213         gtk_entry_set_text(GTK_ENTRY(astextviewer_entry), 
214                            prefs_common.mime_textviewer ? prefs_common.mime_textviewer : "");
215
216         audio_player_label = gtk_label_new (_("Audio player"));
217         gtk_widget_show(audio_player_label);
218
219         gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 4, 5,
220                          (GtkAttachOptions) (GTK_FILL),
221                          (GtkAttachOptions) (0), 0, 2);
222         gtk_label_set_justify(GTK_LABEL (audio_player_label), GTK_JUSTIFY_RIGHT);
223         gtk_misc_set_alignment(GTK_MISC (audio_player_label), 1, 0.5);
224
225         audio_player_entry = gtk_entry_new ();
226         gtk_widget_show(audio_player_entry);
227         
228         gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 4, 5,
229                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
230                          (GtkAttachOptions) (0), 0, 0);
231         gtk_entry_set_text(GTK_ENTRY(audio_player_entry), 
232                            prefs_common.mime_audio_player ? prefs_common.mime_audio_player : "");
233
234         printcmd_label = gtk_label_new (_("Print command"));
235         #ifndef USE_GNOMEPRINT
236                 gtk_widget_show(printcmd_label);
237         #endif
238         gtk_table_attach(GTK_TABLE (table2), printcmd_label, 0, 1, 5, 6,
239                          (GtkAttachOptions) (GTK_FILL),
240                          (GtkAttachOptions) (0), 0, 2);
241         gtk_label_set_justify(GTK_LABEL (printcmd_label), GTK_JUSTIFY_RIGHT);
242         gtk_misc_set_alignment(GTK_MISC (printcmd_label), 1, 0.5);
243
244         printcmd_entry = gtk_entry_new ();
245         #ifndef USE_GNOMEPRINT
246                 gtk_widget_show(printcmd_entry);
247         #endif
248         gtk_table_attach(GTK_TABLE (table2), printcmd_entry, 1, 2, 5, 6,
249                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
250                          (GtkAttachOptions) (0), 0, 0);
251         gtk_entry_set_text(GTK_ENTRY(printcmd_entry), prefs_common.print_cmd ? prefs_common.print_cmd : "");
252
253
254         prefs_ext_prog->window                  = GTK_WIDGET(window);
255         prefs_ext_prog->uri_entry               = uri_entry;
256         prefs_ext_prog->exteditor_entry         = exteditor_entry;
257         prefs_ext_prog->image_viewer_entry      = image_viewer_entry;
258         prefs_ext_prog->astextviewer_entry      = astextviewer_entry;
259         prefs_ext_prog->audio_player_entry      = audio_player_entry;
260         prefs_ext_prog->printcmd_entry          = printcmd_entry;
261
262         prefs_ext_prog->page.widget = table;
263 }
264
265 void prefs_ext_prog_save(PrefsPage *_page)
266 {
267         ExtProgPage *ext_prog = (ExtProgPage *) _page;
268
269         prefs_common.uri_cmd = gtk_editable_get_chars
270                 (GTK_EDITABLE(ext_prog->uri_entry), 0, -1);
271         prefs_common.print_cmd = gtk_editable_get_chars
272                 (GTK_EDITABLE(ext_prog->printcmd_entry), 0, -1);
273         prefs_common.ext_editor_cmd = gtk_editable_get_chars
274                 (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
275         prefs_common.mime_image_viewer = gtk_editable_get_chars
276                 (GTK_EDITABLE(ext_prog->image_viewer_entry), 0, -1);
277         prefs_common.mime_textviewer = gtk_editable_get_chars
278                 (GTK_EDITABLE(ext_prog->astextviewer_entry), 0, -1);
279         prefs_common.mime_audio_player = gtk_editable_get_chars
280                 (GTK_EDITABLE(ext_prog->audio_player_entry), 0, -1);
281 }
282
283 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)
284 {
285         /* ExtProgPage *ext_prog = (ExtProgPage *) _page; */
286
287 }
288
289 ExtProgPage *prefs_ext_prog;
290
291 void prefs_ext_prog_init(void)
292 {
293         ExtProgPage *page;
294         static gchar *path[3];
295         
296         path[0] = _("Message View");
297         path[1] = _("External Programs");
298         path[2] = NULL;
299
300         page = g_new0(ExtProgPage, 1);
301         page->page.path = path;
302         page->page.create_widget = prefs_ext_prog_create_widget;
303         page->page.destroy_widget = prefs_ext_prog_destroy_widget;
304         page->page.save_page = prefs_ext_prog_save;
305         page->page.weight = 155.0;
306         prefs_gtk_register_page((PrefsPage *) page);
307         prefs_ext_prog = page;
308 }
309
310 void prefs_ext_prog_done(void)
311 {
312         prefs_gtk_unregister_page((PrefsPage *) prefs_ext_prog);
313         g_free(prefs_ext_prog);
314 }