2004-12-30 [paul] 0.9.13cvs22.2
[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_EXPAND | 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 (uri_label), GTK_JUSTIFY_RIGHT);
125         gtk_misc_set_alignment(GTK_MISC (uri_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                                "rxvt -e w3m '%s'",
142                                "rxvt -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 ? 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 (printcmd_label), GTK_JUSTIFY_RIGHT);
154         gtk_misc_set_alignment(GTK_MISC (printcmd_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 ? 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                                "nedit %s",
180                                "mgedit --no-fork %s",
181                                "emacs %s",
182                                "xemacs %s",
183                                "kterm -e jed %s",
184                                "kterm -e vi %s",
185                                NULL);
186         exteditor_entry = GTK_COMBO (exteditor_combo)->entry;
187         gtk_entry_set_text(GTK_ENTRY(exteditor_entry), 
188                            prefs_common.ext_editor_cmd ? prefs_common.ext_editor_cmd : "");
189
190         image_viewer_label = gtk_label_new (_("Image viewer"));
191         gtk_widget_show(image_viewer_label);
192
193         gtk_table_attach(GTK_TABLE (table2), image_viewer_label, 0, 1, 3, 4,
194                          (GtkAttachOptions) (GTK_FILL),
195                          (GtkAttachOptions) (0), 0, 2);
196         gtk_label_set_justify(GTK_LABEL (image_viewer_label), GTK_JUSTIFY_RIGHT);
197         gtk_misc_set_alignment(GTK_MISC (image_viewer_label), 1, 0.5);
198
199         image_viewer_entry = gtk_entry_new ();
200         gtk_widget_show(image_viewer_entry);
201         
202         gtk_table_attach(GTK_TABLE (table2), image_viewer_entry, 1, 2, 3, 4,
203                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
204                          (GtkAttachOptions) (0), 0, 0);
205         gtk_entry_set_text(GTK_ENTRY(image_viewer_entry), 
206                            prefs_common.mime_image_viewer ? prefs_common.mime_image_viewer : "");
207
208         audio_player_label = gtk_label_new (_("Audio player"));
209         gtk_widget_show(audio_player_label);
210
211         gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 4, 5,
212                          (GtkAttachOptions) (GTK_FILL),
213                          (GtkAttachOptions) (0), 0, 2);
214         gtk_label_set_justify(GTK_LABEL (audio_player_label), GTK_JUSTIFY_RIGHT);
215         gtk_misc_set_alignment(GTK_MISC (audio_player_label), 1, 0.5);
216
217         audio_player_entry = gtk_entry_new ();
218         gtk_widget_show(audio_player_entry);
219         
220         gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 4, 5,
221                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
222                          (GtkAttachOptions) (0), 0, 0);
223         gtk_entry_set_text(GTK_ENTRY(audio_player_entry), 
224                            prefs_common.mime_audio_player ? prefs_common.mime_audio_player : "");
225
226         prefs_ext_prog->window                  = GTK_WIDGET(window);
227         prefs_ext_prog->uri_entry               = uri_entry;
228         prefs_ext_prog->printcmd_entry          = printcmd_entry;
229         prefs_ext_prog->exteditor_entry         = exteditor_entry;
230         prefs_ext_prog->image_viewer_entry      = image_viewer_entry;
231         prefs_ext_prog->audio_player_entry      = audio_player_entry;
232
233         prefs_ext_prog->page.widget = table;
234 }
235
236 void prefs_ext_prog_save(PrefsPage *_page)
237 {
238         ExtProgPage *ext_prog = (ExtProgPage *) _page;
239
240         prefs_common.uri_cmd = gtk_editable_get_chars
241                 (GTK_EDITABLE(ext_prog->uri_entry), 0, -1);
242         prefs_common.print_cmd = gtk_editable_get_chars
243                 (GTK_EDITABLE(ext_prog->printcmd_entry), 0, -1);
244         prefs_common.ext_editor_cmd = gtk_editable_get_chars
245                 (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
246         prefs_common.mime_image_viewer = gtk_editable_get_chars
247                 (GTK_EDITABLE(ext_prog->image_viewer_entry), 0, -1);
248         prefs_common.mime_audio_player = gtk_editable_get_chars
249                 (GTK_EDITABLE(ext_prog->audio_player_entry), 0, -1);
250 }
251
252 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)
253 {
254         /* ExtProgPage *ext_prog = (ExtProgPage *) _page; */
255
256 }
257
258 ExtProgPage *prefs_ext_prog;
259
260 void prefs_ext_prog_init(void)
261 {
262         ExtProgPage *page;
263         static gchar *path[3];
264         
265         path[0] = _("Message View");
266         path[1] = _("External Programs");
267         path[2] = NULL;
268
269         page = g_new0(ExtProgPage, 1);
270         page->page.path = path;
271         page->page.create_widget = prefs_ext_prog_create_widget;
272         page->page.destroy_widget = prefs_ext_prog_destroy_widget;
273         page->page.save_page = prefs_ext_prog_save;
274         page->page.weight = 45.0;
275         prefs_gtk_register_page((PrefsPage *) page);
276         prefs_ext_prog = page;
277 }
278
279 void prefs_ext_prog_done(void)
280 {
281         prefs_gtk_unregister_page((PrefsPage *) prefs_ext_prog);
282         g_free(prefs_ext_prog);
283 }