move External Program prefs to Other Prefs
[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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <gtk/gtk.h>
31 #include <gdk/gdkkeysyms.h>
32
33 #include "intl.h"
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 *audio_player_label;
64         GtkWidget *audio_player_entry;
65 } ExtProgPage;
66
67 void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window, 
68                                   gpointer data)
69 {
70         ExtProgPage *prefs_ext_prog = (ExtProgPage *) _page;
71
72         GtkWidget *table;
73         GtkWidget *vbox;
74         GtkWidget *hint_label;
75         GtkWidget *table2;
76         GtkWidget *uri_label;
77         GtkWidget *uri_combo;
78         GtkWidget *uri_entry;
79         GtkWidget *printcmd_label;
80         GtkWidget *printcmd_entry;
81         GtkWidget *exteditor_label;
82         GtkWidget *exteditor_combo;
83         GtkWidget *exteditor_entry;
84         GtkWidget *image_viewer_label;
85         GtkWidget *image_viewer_entry;
86         GtkWidget *audio_player_label;
87         GtkWidget *audio_player_entry;
88
89         table = gtk_table_new(2, 1, FALSE);
90         gtk_widget_show(table);
91         gtk_container_set_border_width(GTK_CONTAINER(table), 8);
92         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
93         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
94
95         vbox = gtk_vbox_new(TRUE, 0);
96         gtk_widget_show(vbox);
97         
98         gtk_table_attach(GTK_TABLE (table), vbox, 0, 1, 0, 1,
99                          (GtkAttachOptions) (GTK_SHRINK),
100                          (GtkAttachOptions) (0), 0, 0);
101
102         hint_label = gtk_label_new(_("%s will be replaced with file name / URI"));
103         gtk_widget_show(hint_label);
104         gtk_box_pack_start(GTK_BOX (vbox), 
105                            hint_label, FALSE, FALSE, 4);
106         gtk_label_set_justify(GTK_LABEL (hint_label), GTK_JUSTIFY_LEFT);
107                 
108         table2 = gtk_table_new(5, 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_FILL),
116                          (GtkAttachOptions) (0), 0, 0);
117                          
118         uri_label = gtk_label_new (_("Web browser"));
119         gtk_widget_show(uri_label);
120
121         gtk_table_attach(GTK_TABLE (table2), uri_label, 0, 1, 0, 1,
122                          (GtkAttachOptions) (GTK_FILL),
123                          (GtkAttachOptions) (0), 0, 2);
124         gtk_label_set_justify(GTK_LABEL (hint_label), GTK_JUSTIFY_RIGHT);
125         gtk_misc_set_alignment(GTK_MISC (hint_label), 1, 0.5);
126
127         uri_combo = gtk_combo_new ();
128         gtk_widget_show (uri_combo);
129         gtk_table_attach (GTK_TABLE (table2), uri_combo, 1, 2, 0, 1,
130                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
131         gtkut_combo_set_items (GTK_COMBO (uri_combo),
132                                DEFAULT_BROWSER_CMD,
133                                "galeon --new-tab '%s'",
134                                "galeon '%s'",
135                                "mozilla -remote 'openurl(%s,new-window)'",
136                                "netscape -remote 'openURL(%s, new-window)'",
137                                "netscape '%s'",
138                                "gnome-moz-remote --newwin '%s'",
139                                "kfmclient openURL '%s'",
140                                "opera -newwindow '%s'",
141                                "kterm -e w3m '%s'",
142                                "kterm -e lynx '%s'",
143                                NULL);
144         uri_entry = GTK_COMBO (uri_combo)->entry;
145         gtk_entry_set_text(GTK_ENTRY(uri_entry), prefs_common.uri_cmd);
146         
147         printcmd_label = gtk_label_new (_("Print command"));
148         gtk_widget_show(printcmd_label);
149
150         gtk_table_attach(GTK_TABLE (table2), printcmd_label, 0, 1, 1, 2,
151                          (GtkAttachOptions) (GTK_FILL),
152                          (GtkAttachOptions) (0), 0, 2);
153         gtk_label_set_justify(GTK_LABEL (hint_label), GTK_JUSTIFY_RIGHT);
154         gtk_misc_set_alignment(GTK_MISC (hint_label), 1, 0.5);
155
156         printcmd_entry = gtk_entry_new ();
157         gtk_widget_show (printcmd_entry);
158         gtk_table_attach(GTK_TABLE (table2), printcmd_entry, 1, 2, 1, 2,
159                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
160                          (GtkAttachOptions) (0), 0, 0);
161         gtk_entry_set_text(GTK_ENTRY(printcmd_entry), prefs_common.print_cmd);
162
163         exteditor_label = gtk_label_new (_("Text editor"));
164         gtk_widget_show(exteditor_label);
165
166         gtk_table_attach(GTK_TABLE (table2), exteditor_label, 0, 1, 2, 3,
167                          (GtkAttachOptions) (GTK_FILL),
168                          (GtkAttachOptions) (0), 0, 2);
169         gtk_label_set_justify(GTK_LABEL (exteditor_label), GTK_JUSTIFY_RIGHT);
170         gtk_misc_set_alignment(GTK_MISC (exteditor_label), 1, 0.5);
171
172         exteditor_combo = gtk_combo_new ();
173         gtk_widget_show (exteditor_combo);
174         gtk_table_attach (GTK_TABLE (table2), exteditor_combo, 1, 2, 2, 3,
175                           GTK_EXPAND | GTK_FILL, 0, 0, 0);
176         gtkut_combo_set_items (GTK_COMBO (exteditor_combo),
177                                "gedit %s",
178                                "kedit %s",
179                                "mgedit --no-fork %s",
180                                "emacs %s",
181                                "xemacs %s",
182                                "kterm -e jed %s",
183                                "kterm -e vi %s",
184                                NULL);
185         exteditor_entry = GTK_COMBO (exteditor_combo)->entry;
186         gtk_entry_set_text(GTK_ENTRY(exteditor_entry), 
187                            prefs_common.ext_editor_cmd);
188
189         image_viewer_label = gtk_label_new (_("Image viewer"));
190         gtk_widget_show(image_viewer_label);
191
192         gtk_table_attach(GTK_TABLE (table2), image_viewer_label, 0, 1, 3, 4,
193                          (GtkAttachOptions) (GTK_FILL),
194                          (GtkAttachOptions) (0), 0, 2);
195         gtk_label_set_justify(GTK_LABEL (image_viewer_label), GTK_JUSTIFY_RIGHT);
196         gtk_misc_set_alignment(GTK_MISC (image_viewer_label), 1, 0.5);
197
198         image_viewer_entry = gtk_entry_new ();
199         gtk_widget_show(image_viewer_entry);
200         
201         gtk_table_attach(GTK_TABLE (table2), image_viewer_entry, 1, 2, 3, 4,
202                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
203                          (GtkAttachOptions) (0), 0, 0);
204         gtk_entry_set_text(GTK_ENTRY(image_viewer_entry), 
205                            prefs_common.mime_image_viewer);
206
207         audio_player_label = gtk_label_new (_("Audio player"));
208         gtk_widget_show(audio_player_label);
209
210         gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 4, 5,
211                          (GtkAttachOptions) (GTK_FILL),
212                          (GtkAttachOptions) (0), 0, 2);
213         gtk_label_set_justify(GTK_LABEL (audio_player_label), GTK_JUSTIFY_RIGHT);
214         gtk_misc_set_alignment(GTK_MISC (audio_player_label), 1, 0.5);
215
216         audio_player_entry = gtk_entry_new ();
217         gtk_widget_show(audio_player_entry);
218         
219         gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 4, 5,
220                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
221                          (GtkAttachOptions) (0), 0, 0);
222         gtk_entry_set_text(GTK_ENTRY(audio_player_entry), 
223                            prefs_common.mime_audio_player);
224
225         prefs_ext_prog->window                  = GTK_WIDGET(window);
226         prefs_ext_prog->uri_entry               = uri_entry;
227         prefs_ext_prog->printcmd_entry          = printcmd_entry;
228         prefs_ext_prog->exteditor_entry         = exteditor_entry;
229         prefs_ext_prog->image_viewer_entry      = image_viewer_entry;
230         prefs_ext_prog->audio_player_entry      = audio_player_entry;
231
232         prefs_ext_prog->page.widget = table;
233 }
234
235 void prefs_ext_prog_save(PrefsPage *_page)
236 {
237         ExtProgPage *ext_prog = (ExtProgPage *) _page;
238
239         prefs_common.uri_cmd = gtk_editable_get_chars
240                 (GTK_EDITABLE(ext_prog->uri_entry), 0, -1);
241         prefs_common.print_cmd = gtk_editable_get_chars
242                 (GTK_EDITABLE(ext_prog->printcmd_entry), 0, -1);
243         prefs_common.ext_editor_cmd = gtk_editable_get_chars
244                 (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
245         prefs_common.mime_image_viewer = gtk_editable_get_chars
246                 (GTK_EDITABLE(ext_prog->image_viewer_entry), 0, -1);
247         prefs_common.mime_audio_player = gtk_editable_get_chars
248                 (GTK_EDITABLE(ext_prog->audio_player_entry), 0, -1);
249 }
250
251 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)
252 {
253         /* ExtProgPage *ext_prog = (ExtProgPage *) _page; */
254
255 }
256
257 ExtProgPage *prefs_ext_prog;
258
259 void prefs_ext_prog_init(void)
260 {
261         ExtProgPage *page;
262
263         page = g_new0(ExtProgPage, 1);
264         page->page.path = _("Message View/External Programs");
265         page->page.create_widget = prefs_ext_prog_create_widget;
266         page->page.destroy_widget = prefs_ext_prog_destroy_widget;
267         page->page.save_page = prefs_ext_prog_save;
268         page->page.weight = 45.0;
269         prefs_gtk_register_page((PrefsPage *) page);
270         prefs_ext_prog = page;
271 }
272
273 void prefs_ext_prog_done(void)
274 {
275         prefs_gtk_unregister_page((PrefsPage *) prefs_ext_prog);
276         g_free(prefs_ext_prog);
277 }