2008-10-09 [colin] 3.6.0cvs20
[claws.git] / src / prefs_ext_prog.c
index f6d45eb..0fe8213 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2004 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ * Copyright (C) 2004 Hiroyuki Yamamoto & the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -32,6 +32,7 @@
 #include <gdk/gdkkeysyms.h>
 
 #include "utils.h"
+#include "combobox.h"
 #include "prefs_common.h"
 #include "prefs_gtk.h"
 
@@ -46,6 +47,8 @@ typedef struct _ExtProgPage
 
        GtkWidget *window;              /* do not modify */
 
+       GtkWidget *cmds_use_system_default_checkbtn;
+
        GtkWidget *uri_label;
        GtkWidget *uri_combo;
        GtkWidget *uri_entry;
@@ -57,17 +60,11 @@ typedef struct _ExtProgPage
        GtkWidget *exteditor_combo;
        GtkWidget *exteditor_entry;
 
-       GtkWidget *image_viewer_label;
-       GtkWidget *image_viewer_entry;
-       
        GtkWidget *astextviewer_label;
        GtkWidget *astextviewer_entry;
-
-       GtkWidget *audio_player_label;
-       GtkWidget *audio_player_entry;
 } ExtProgPage;
 
-void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window, 
+static void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window, 
                                  gpointer data)
 {
        ExtProgPage *prefs_ext_prog = (ExtProgPage *) _page;
@@ -76,20 +73,20 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        GtkWidget *vbox;
        GtkWidget *hint_label;
        GtkWidget *table2;
+       GtkWidget *cmds_use_system_default_checkbtn;
        GtkWidget *uri_label;
        GtkWidget *uri_combo;
        GtkWidget *uri_entry;
-       GtkWidget *printcmd_label;
-       GtkWidget *printcmd_entry;
        GtkWidget *exteditor_label;
        GtkWidget *exteditor_combo;
        GtkWidget *exteditor_entry;
-       GtkWidget *image_viewer_label;
-       GtkWidget *image_viewer_entry;
        GtkWidget *astextviewer_label;
        GtkWidget *astextviewer_entry;
-       GtkWidget *audio_player_label;
-       GtkWidget *audio_player_entry;
+       GtkWidget *printcmd_label;
+       GtkWidget *printcmd_entry;
+       CLAWS_TIP_DECL();
+       int i = 0;
+       gchar *tmp;
 
        table = gtk_table_new(2, 1, FALSE);
        gtk_widget_show(table);
@@ -99,7 +96,7 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
 
        vbox = gtk_vbox_new(TRUE, 0);
        gtk_widget_show(vbox);
-       
+
        gtk_table_attach(GTK_TABLE (table), vbox, 0, 1, 0, 1,
                         (GtkAttachOptions) (GTK_SHRINK),
                         (GtkAttachOptions) (0), 0, 0);
@@ -111,7 +108,7 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_box_pack_start(GTK_BOX (vbox),
                           hint_label, FALSE, FALSE, 4);
 
-       table2 = gtk_table_new(6, 2, FALSE);
+       table2 = gtk_table_new(7, 2, FALSE);
        gtk_widget_show(table2);
        gtk_container_set_border_width(GTK_CONTAINER(table2), 8);
        gtk_table_set_row_spacings(GTK_TABLE(table2), 4);
@@ -120,21 +117,46 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
        gtk_table_attach(GTK_TABLE (table), table2, 0, 1, 1, 2,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0);
-                        
+       
+       cmds_use_system_default_checkbtn = gtk_check_button_new_with_label(
+               _("Use system defaults when possible")); 
+       
+#ifndef MAEMO
+       gtk_widget_show(cmds_use_system_default_checkbtn);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cmds_use_system_default_checkbtn),
+                                       prefs_common.cmds_use_system_default);
+#else
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cmds_use_system_default_checkbtn),
+                                       TRUE);
+#endif
+       tmp = g_find_program_in_path("xdg-open");
+       if (!tmp) {
+               g_print("xdg-open not found\n");
+               gtk_widget_set_sensitive(cmds_use_system_default_checkbtn, FALSE);
+               gtk_widget_set_sensitive(cmds_use_system_default_checkbtn, FALSE);
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cmds_use_system_default_checkbtn),
+                                       FALSE);
+       } else
+               g_free(tmp);
+
+       
+       gtk_table_attach(GTK_TABLE (table2), cmds_use_system_default_checkbtn, 0, 2, i, i+1,
+                        (GtkAttachOptions) (GTK_FILL),
+                        (GtkAttachOptions) (0), 0, 2);
+       
        uri_label = gtk_label_new (_("Web browser"));
        gtk_widget_show(uri_label);
-
-       gtk_table_attach(GTK_TABLE (table2), uri_label, 0, 1, 0, 1,
+#ifdef MAEMO
+       gtk_widget_set_sensitive(uri_label, FALSE);
+#endif
+       i++;
+       gtk_table_attach(GTK_TABLE (table2), uri_label, 0, 1, i, i+1,
                         (GtkAttachOptions) (GTK_FILL),
                         (GtkAttachOptions) (0), 0, 2);
        gtk_label_set_justify(GTK_LABEL (uri_label), GTK_JUSTIFY_RIGHT);
        gtk_misc_set_alignment(GTK_MISC (uri_label), 1, 0.5);
 
-       uri_combo = gtk_combo_new ();
-       gtk_widget_show (uri_combo);
-       gtk_table_attach (GTK_TABLE (table2), uri_combo, 1, 2, 0, 1,
-                         GTK_EXPAND | GTK_FILL, 0, 0, 0);
-       gtkut_combo_set_items (GTK_COMBO (uri_combo),
+       uri_combo = combobox_text_new(TRUE,
                               DEFAULT_BROWSER_CMD,
                               "galeon --new-tab '%s'",
                               "galeon '%s'",
@@ -147,74 +169,48 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
                               "rxvt -e w3m '%s'",
                               "rxvt -e lynx '%s'",
                               NULL);
-       uri_entry = GTK_COMBO (uri_combo)->entry;
+#ifdef MAEMO
+       gtk_widget_set_sensitive(uri_combo, FALSE);
+#endif
+       gtk_table_attach (GTK_TABLE (table2), uri_combo, 1, 2, i, i+1,
+                         GTK_EXPAND | GTK_FILL, 0, 0, 0);
+
+       uri_entry = gtk_bin_get_child(GTK_BIN((uri_combo)));
        gtk_entry_set_text(GTK_ENTRY(uri_entry), prefs_common.uri_cmd ? prefs_common.uri_cmd : "");
        
-       printcmd_label = gtk_label_new (_("Print command"));
-       gtk_widget_show(printcmd_label);
-
-       gtk_table_attach(GTK_TABLE (table2), printcmd_label, 0, 1, 1, 2,
-                        (GtkAttachOptions) (GTK_FILL),
-                        (GtkAttachOptions) (0), 0, 2);
-       gtk_label_set_justify(GTK_LABEL (printcmd_label), GTK_JUSTIFY_RIGHT);
-       gtk_misc_set_alignment(GTK_MISC (printcmd_label), 1, 0.5);
-
-       printcmd_entry = gtk_entry_new ();
-       gtk_widget_show (printcmd_entry);
-       gtk_table_attach(GTK_TABLE (table2), printcmd_entry, 1, 2, 1, 2,
-                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-                        (GtkAttachOptions) (0), 0, 0);
-       gtk_entry_set_text(GTK_ENTRY(printcmd_entry), prefs_common.print_cmd ? prefs_common.print_cmd : "");
-
        exteditor_label = gtk_label_new (_("Text editor"));
        gtk_widget_show(exteditor_label);
 
-       gtk_table_attach(GTK_TABLE (table2), exteditor_label, 0, 1, 2, 3,
+       i++;
+       gtk_table_attach(GTK_TABLE (table2), exteditor_label, 0, 1, i, i+1,
                         (GtkAttachOptions) (GTK_FILL),
                         (GtkAttachOptions) (0), 0, 2);
        gtk_label_set_justify(GTK_LABEL (exteditor_label), GTK_JUSTIFY_RIGHT);
        gtk_misc_set_alignment(GTK_MISC (exteditor_label), 1, 0.5);
 
-       exteditor_combo = gtk_combo_new ();
-       gtk_widget_show (exteditor_combo);
-       gtk_table_attach (GTK_TABLE (table2), exteditor_combo, 1, 2, 2, 3,
+       exteditor_combo = combobox_text_new(TRUE,
+                                       "gedit %s",
+                                       "kedit %s",
+                                       "mousepad %s",
+                                       "nedit %s",
+                                       "mgedit --no-fork %s",
+                                       "emacs %s",
+                                       "xemacs %s",
+                                       "kterm -e jed %s",
+                                       "kterm -e vi %s",
+                                       NULL);
+       gtk_table_attach (GTK_TABLE (table2), exteditor_combo, 1, 2, i, i+1,
                          GTK_EXPAND | GTK_FILL, 0, 0, 0);
-       gtkut_combo_set_items (GTK_COMBO (exteditor_combo),
-                              "gedit %s",
-                              "kedit %s",
-                              "nedit %s",
-                              "mgedit --no-fork %s",
-                              "emacs %s",
-                              "xemacs %s",
-                              "kterm -e jed %s",
-                              "kterm -e vi %s",
-                              NULL);
-       exteditor_entry = GTK_COMBO (exteditor_combo)->entry;
+
+       exteditor_entry = gtk_bin_get_child(GTK_BIN((exteditor_combo)));
        gtk_entry_set_text(GTK_ENTRY(exteditor_entry), 
                           prefs_common.ext_editor_cmd ? prefs_common.ext_editor_cmd : "");
 
-       image_viewer_label = gtk_label_new (_("Image viewer"));
-       gtk_widget_show(image_viewer_label);
-
-       gtk_table_attach(GTK_TABLE (table2), image_viewer_label, 0, 1, 3, 4,
-                        (GtkAttachOptions) (GTK_FILL),
-                        (GtkAttachOptions) (0), 0, 2);
-       gtk_label_set_justify(GTK_LABEL (image_viewer_label), GTK_JUSTIFY_RIGHT);
-       gtk_misc_set_alignment(GTK_MISC (image_viewer_label), 1, 0.5);
-
-       image_viewer_entry = gtk_entry_new ();
-       gtk_widget_show(image_viewer_entry);
-       
-       gtk_table_attach(GTK_TABLE (table2), image_viewer_entry, 1, 2, 3, 4,
-                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
-                        (GtkAttachOptions) (0), 0, 0);
-       gtk_entry_set_text(GTK_ENTRY(image_viewer_entry), 
-                          prefs_common.mime_image_viewer ? prefs_common.mime_image_viewer : "");
-
-       astextviewer_label = gtk_label_new(_("View as text command"));
+       astextviewer_label = gtk_label_new(_("Command for 'Display as text'"));
        gtk_widget_show(astextviewer_label);
 
-       gtk_table_attach(GTK_TABLE (table2), astextviewer_label, 0, 1, 4, 5,
+       i++;
+       gtk_table_attach(GTK_TABLE (table2), astextviewer_label, 0, 1, i, i+1,
                         (GtkAttachOptions) (GTK_FILL),
                         (GtkAttachOptions) (0), 0, 2);
        gtk_label_set_justify(GTK_LABEL (astextviewer_label), GTK_JUSTIFY_RIGHT);
@@ -222,43 +218,55 @@ void prefs_ext_prog_create_widget(PrefsPage *_page, GtkWindow *window,
 
        astextviewer_entry = gtk_entry_new ();
        gtk_widget_show(astextviewer_entry);
+       CLAWS_SET_TIP(astextviewer_entry,
+                            _("This option enables MIME parts to be displayed in the "
+                              "message view via a script when using the 'Display as text' "
+                              "contextual menu item"));
        
-       gtk_table_attach(GTK_TABLE (table2), astextviewer_entry, 1, 2, 4, 5,
+       gtk_table_attach(GTK_TABLE (table2), astextviewer_entry, 1, 2, i, i+1,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0);
        gtk_entry_set_text(GTK_ENTRY(astextviewer_entry), 
                           prefs_common.mime_textviewer ? prefs_common.mime_textviewer : "");
 
-       audio_player_label = gtk_label_new (_("Audio player"));
-       gtk_widget_show(audio_player_label);
-
-       gtk_table_attach(GTK_TABLE (table2), audio_player_label, 0, 1, 5, 6,
+       printcmd_label = gtk_label_new (_("Print command"));
+#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
+       gtk_widget_show(printcmd_label);
+#endif
+       i++;
+       gtk_table_attach(GTK_TABLE (table2), printcmd_label, 0, 1, i, i+1,
                         (GtkAttachOptions) (GTK_FILL),
                         (GtkAttachOptions) (0), 0, 2);
-       gtk_label_set_justify(GTK_LABEL (audio_player_label), GTK_JUSTIFY_RIGHT);
-       gtk_misc_set_alignment(GTK_MISC (audio_player_label), 1, 0.5);
+       gtk_label_set_justify(GTK_LABEL (printcmd_label), GTK_JUSTIFY_RIGHT);
+       gtk_misc_set_alignment(GTK_MISC (printcmd_label), 1, 0.5);
 
-       audio_player_entry = gtk_entry_new ();
-       gtk_widget_show(audio_player_entry);
-       
-       gtk_table_attach(GTK_TABLE (table2), audio_player_entry, 1, 2, 5, 6,
+       printcmd_entry = gtk_entry_new ();
+#if !defined(USE_GNOMEPRINT) && !GTK_CHECK_VERSION(2,10,0)
+       gtk_widget_show(printcmd_entry);
+#endif
+       gtk_table_attach(GTK_TABLE (table2), printcmd_entry, 1, 2, i, i+1,
                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                         (GtkAttachOptions) (0), 0, 0);
-       gtk_entry_set_text(GTK_ENTRY(audio_player_entry), 
-                          prefs_common.mime_audio_player ? prefs_common.mime_audio_player : "");
+       gtk_entry_set_text(GTK_ENTRY(printcmd_entry), prefs_common.print_cmd ? prefs_common.print_cmd : "");
+
+       SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, uri_label);
+       SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, uri_combo);
+#if 0 /* we should do that, but it detaches the editor and breaks
+        compose.c's external composition. */
+       SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, exteditor_label);
+       SET_TOGGLE_SENSITIVITY_REVERSE (cmds_use_system_default_checkbtn, exteditor_combo);
+#endif
 
        prefs_ext_prog->window                  = GTK_WIDGET(window);
        prefs_ext_prog->uri_entry               = uri_entry;
-       prefs_ext_prog->printcmd_entry          = printcmd_entry;
        prefs_ext_prog->exteditor_entry         = exteditor_entry;
-       prefs_ext_prog->image_viewer_entry      = image_viewer_entry;
        prefs_ext_prog->astextviewer_entry      = astextviewer_entry;
-       prefs_ext_prog->audio_player_entry      = audio_player_entry;
-
+       prefs_ext_prog->printcmd_entry          = printcmd_entry;
+       prefs_ext_prog->cmds_use_system_default_checkbtn = cmds_use_system_default_checkbtn;
        prefs_ext_prog->page.widget = table;
 }
 
-void prefs_ext_prog_save(PrefsPage *_page)
+static void prefs_ext_prog_save(PrefsPage *_page)
 {
        ExtProgPage *ext_prog = (ExtProgPage *) _page;
 
@@ -268,12 +276,10 @@ void prefs_ext_prog_save(PrefsPage *_page)
                (GTK_EDITABLE(ext_prog->printcmd_entry), 0, -1);
        prefs_common.ext_editor_cmd = gtk_editable_get_chars
                (GTK_EDITABLE(ext_prog->exteditor_entry), 0, -1);
-       prefs_common.mime_image_viewer = gtk_editable_get_chars
-               (GTK_EDITABLE(ext_prog->image_viewer_entry), 0, -1);
        prefs_common.mime_textviewer = gtk_editable_get_chars
                (GTK_EDITABLE(ext_prog->astextviewer_entry), 0, -1);
-       prefs_common.mime_audio_player = gtk_editable_get_chars
-               (GTK_EDITABLE(ext_prog->audio_player_entry), 0, -1);
+       prefs_common.cmds_use_system_default = gtk_toggle_button_get_active
+               (GTK_TOGGLE_BUTTON(ext_prog->cmds_use_system_default_checkbtn));
 }
 
 static void prefs_ext_prog_destroy_widget(PrefsPage *_page)