2005-10-29 [paul] 1.9.15cvs126
[claws.git] / src / crash.c
index 157185f8a1224c0f7c65ab84cbd49d4aad9a8f26..b2012558b804c18b4529afe11bb5c9bfb3af3044 100644 (file)
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #      include <config.h>
 #endif
 
+#ifdef CRASH_DIALOG
+
+#include "defs.h"
+
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 #include <errno.h>
 #include <fcntl.h>
 #      include <gnu/libc-version.h>
 #endif
 
-#include "intl.h"
+#ifdef SIGTERM
+#include "main.h"
+#endif
+#include "sylpheed.h"
 #include "crash.h"
 #include "utils.h"
 #include "filesel.h"
 #include "version.h"
 #include "prefs_common.h"
 
-#if 0
-#include "gtkutils.h"
-#include "pixmaps/notice_error.xpm"
-#endif
-
 /*
- * NOTE 1: the crash dialog is called when sylpheed is not 
+ * NOTE: the crash dialog is called when sylpheed is not 
  * initialized, so do not assume settings are available.
  * for example, loading / creating pixmaps seems not 
  * to be possible.
@@ -62,7 +67,7 @@
 
 static GtkWidget       *crash_dialog_show              (const gchar *text, 
                                                         const gchar *debug_output);
-static gboolean                 crash_create_debugger_file     (void);
+static void             crash_create_debugger_file     (void);
 static void             crash_save_crash_log           (GtkButton *, const gchar *);
 static void             crash_create_bug_report        (GtkButton *, const gchar *);
 static void             crash_debug                    (unsigned long crash_pid, 
@@ -86,7 +91,7 @@ static const gchar *DEBUG_SCRIPT = "bt\nkill\nq";
  */
 void crash_install_handlers(void)
 {
-#if HAVE_GDB
+#if CRASH_DIALOG 
        sigset_t mask;
 
        if (!is_crash_dialog_allowed()) return;
@@ -114,7 +119,7 @@ void crash_install_handlers(void)
 #endif
 
        sigprocmask(SIG_UNBLOCK, &mask, 0);
-#endif /* HAVE_GDB */  
+#endif /* CRASH_DIALOG */      
 }
 
 /***/
@@ -124,18 +129,17 @@ void crash_install_handlers(void)
  */
 void crash_main(const char *arg) 
 {
-#if HAVE_GDB
+#if CRASH_DIALOG 
        gchar *text;
        gchar **tokens;
        unsigned long pid;
        GString *output;
-       extern gchar *startup_dir;
 
        crash_create_debugger_file();
        tokens = g_strsplit(arg, ",", 0);
 
        pid = atol(tokens[0]);
-       text = g_strdup_printf(_("Sylpheed process (%ld) received signal %ld"),
+       text = g_strdup_printf(_("Sylpheed-Claws process (%ld) received signal %ld"),
                               pid, atol(tokens[1]));
 
        output = g_string_new("");     
@@ -144,18 +148,22 @@ void crash_main(const char *arg)
        /*
         * try to get the settings
         */
-       prefs_common_init();
        prefs_common_read_config();
 
        crash_dialog_show(text, output->str);
        g_string_free(output, TRUE);
        g_free(text);
        g_strfreev(tokens);
-#endif /* HAVE_GDB */  
+#endif /* CRASH_DIALOG */      
 }
 
 /*!
- *\brief       (can't get pixmap working, so discarding it)
+ *\brief       show crash dialog
+ *
+ *\param       text Description
+ *\param       debug_output Output text by gdb
+ *
+ *\return      GtkWidget * Dialog widget
  */
 static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output)
 {
@@ -171,14 +179,13 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
        GtkWidget *button3;
        GtkWidget *button4;
        GtkWidget *button5;
-       GtkWidget *pixwid;
-       GdkPixmap *pix;
-       GdkBitmap *msk;
        gchar     *crash_report;
+       GtkTextBuffer *buffer;
+       GtkTextIter iter;
 
        window1 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width(GTK_CONTAINER(window1), 5);
-       gtk_window_set_title(GTK_WINDOW(window1), _("Sylpheed has crashed"));
+       gtk_window_set_title(GTK_WINDOW(window1), _("Sylpheed-Claws has crashed"));
        gtk_window_set_position(GTK_WINDOW(window1), GTK_WIN_POS_CENTER);
        gtk_window_set_modal(GTK_WINDOW(window1), TRUE);
        gtk_window_set_default_size(GTK_WINDOW(window1), 460, 272);
@@ -193,13 +200,6 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
        gtk_box_pack_start(GTK_BOX(vbox1), hbox1, FALSE, TRUE, 0);
        gtk_container_set_border_width(GTK_CONTAINER(hbox1), 4);
 
-#if 0
-       PIXMAP_CREATE(window1, pix, msk, notice_error_xpm);
-       pixwid = gtk_pixmap_new(pix, msk);
-       gtk_widget_show(pixwid);
-       gtk_box_pack_start(GTK_BOX(hbox1), pixwid, TRUE, TRUE, 0);
-#endif 
-
        label1 = gtk_label_new
            (g_strdup_printf(_("%s.\nPlease file a bug report and include the information below."), text));
        gtk_widget_show(label1);
@@ -215,15 +215,15 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
        gtk_container_add(GTK_CONTAINER(frame1), scrolledwindow1);
        gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow1), 3);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow1),
-                                      GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+                                      GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 
-       text1 = gtk_text_new(NULL, NULL);
-       gtk_text_set_editable(GTK_TEXT(text1), FALSE);
+       text1 = gtk_text_view_new();
+       gtk_text_view_set_editable(GTK_TEXT_VIEW(text1), FALSE);
        gtk_widget_show(text1);
        gtk_container_add(GTK_CONTAINER(scrolledwindow1), text1);
        
        crash_report = g_strdup_printf(
-               "Sylpheed version %s\nGTK+ version %d.%d.%d\nFeatures:%s\nOperating system: %s\nC Library: %s\n--\n%s",
+               "Sylpheed-Claws version %s\nGTK+ version %d.%d.%d\nFeatures:%s\nOperating system: %s\nC Library: %s\n--\n%s",
                VERSION,
                gtk_major_version, gtk_minor_version, gtk_micro_version,
                get_compiled_in_features(),
@@ -231,7 +231,9 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
                get_lib_version(),
                debug_output);
 
-       gtk_text_insert(GTK_TEXT(text1), NULL, NULL, NULL, crash_report, -1);
+       buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text1));
+       gtk_text_buffer_get_start_iter(buffer, &iter);
+       gtk_text_buffer_insert(buffer, &iter, crash_report, -1);
 
        hbuttonbox3 = gtk_hbutton_box_new();
        gtk_widget_show(hbuttonbox3);
@@ -256,16 +258,14 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
        gtk_container_add(GTK_CONTAINER(hbuttonbox4), button5);
        GTK_WIDGET_SET_FLAGS(button5, GTK_CAN_DEFAULT);
        
-       gtk_signal_connect(GTK_OBJECT(window1), "delete_event",
-                          GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
-       gtk_signal_connect(GTK_OBJECT(button3),   "clicked",
-                          GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
-       gtk_signal_connect(GTK_OBJECT(button4), "clicked",
-                          GTK_SIGNAL_FUNC(crash_save_crash_log),
-                          crash_report);
-       gtk_signal_connect(GTK_OBJECT(button5), "clicked",
-                          GTK_SIGNAL_FUNC(crash_create_bug_report),
-                          NULL);
+       g_signal_connect(G_OBJECT(window1), "delete_event",
+                        G_CALLBACK(gtk_main_quit), NULL);
+       g_signal_connect(G_OBJECT(button3),   "clicked",
+                        G_CALLBACK(gtk_main_quit), NULL);
+       g_signal_connect(G_OBJECT(button4), "clicked",
+                        G_CALLBACK(crash_save_crash_log), crash_report);
+       g_signal_connect(G_OBJECT(button5), "clicked",
+                        G_CALLBACK(crash_create_bug_report), NULL);
 
        gtk_widget_show(window1);
 
@@ -279,7 +279,7 @@ static GtkWidget *crash_dialog_show(const gchar *text, const gchar *debug_output
  *             all the other options (creating temp files) looked too 
  *             convoluted.
  */
-static gboolean crash_create_debugger_file(void)
+static void crash_create_debugger_file(void)
 {
        gchar *filespec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, DEBUGGERRC, NULL);
        
@@ -299,8 +299,8 @@ static void crash_save_crash_log(GtkButton *button, const gchar *text)
 
        timer = time(NULL);
        lt = localtime(&timer);
-       strftime(buf, sizeof buf, "sylpheed-crash-log-%y-%m-%d-%H-%M-%S.txt", lt);
-       if (NULL != (filename = filesel_select_file(_("Save crash information"), buf))
+       strftime(buf, sizeof buf, "sylpheed-crash-log-%Y-%m-%d-%H-%M-%S.txt", lt);
+       if (NULL != (filename = filesel_select_file_save(_("Save crash information"), buf))
        &&  *filename)
                str_write_to_file(text, filename);
        g_free(filename);       
@@ -311,8 +311,7 @@ static void crash_save_crash_log(GtkButton *button, const gchar *text)
  */
 static void crash_create_bug_report(GtkButton *button, const gchar *data)
 {
-       open_uri("http://sourceforge.net/tracker/?func=add&group_id=25528&atid=384598",
-                prefs_common.uri_cmd);
+       open_uri(BUGZILLA_URI, prefs_common.uri_cmd);
 }
 
 /*!
@@ -346,7 +345,7 @@ static void crash_debug(unsigned long crash_pid,
                *argptr++ = "-x";
                *argptr++ = filespec;
                *argptr++ = exe_image;
-               *argptr++ = g_strdup_printf("%d", crash_pid);
+               *argptr++ = g_strdup_printf("%ld", crash_pid);
                *argptr   = NULL;
 
                /*
@@ -398,29 +397,20 @@ static void crash_debug(unsigned long crash_pid,
 static const gchar *get_compiled_in_features(void)
 {
        return g_strdup_printf("%s",
-#if HAVE_GDK_IMLIB
-                  " gdk_imlib"
-#endif
-#if HAVE_GDK_PIXBUF
-                  " gdk-pixbuf"
-#endif
 #if USE_THREADS
                   " gthread"
 #endif
 #if INET6
                   " IPv6"
 #endif
-#if HAVE_LIBCOMPFACE
-                  " libcompface"
-#endif
-#if HAVE_LIBJCONV
-                  " libjconv"
+#if HAVE_ICONV
+                  " iconv"
 #endif
-#if USE_GPGME
-                  " GPGME"
+#if HAVE_LIBCOMPFACE
+                  " compface"
 #endif
-#if USE_SSL
-                  " SSL"
+#if USE_OPENSSL
+                  " OpenSSL"
 #endif
 #if USE_LDAP
                   " LDAP"
@@ -430,6 +420,12 @@ static const gchar *get_compiled_in_features(void)
 #endif
 #if USE_ASPELL
                   " GNU/aspell"
+#endif
+#if HAVE_LIBETPAN
+                  " libetpan"
+#endif
+#if USE_GNOMEPRINT
+                  " libgnomeprint"
 #endif
        "");
 }
@@ -489,10 +485,9 @@ static void crash_handler(int sig)
        static volatile unsigned long crashed_ = 0;
 
        /*
-        * let's hope startup_dir and argv0 aren't trashed.
+        * let's hope argv0 aren't trashed.
         * both are defined in main.c.
         */
-       extern gchar *startup_dir;
        extern gchar *argv0;
 
 
@@ -504,6 +499,11 @@ static void crash_handler(int sig)
 
        crashed_++;
 
+#ifdef SIGTERM
+       if (sig == SIGTERM) 
+               clean_quit(NULL);
+#endif
+
        /*
         * gnome ungrabs focus, and flushes gdk. mmmh, good idea.
         */
@@ -523,11 +523,11 @@ static void crash_handler(int sig)
                args[0] = argv0; 
                args[1] = "--debug";
                args[2] = "--crash";
-               sprintf(buf, "%ld,%d,%s", getppid(), sig, argv0);
+               sprintf(buf, "%d,%d,%s", getppid(), sig, argv0);
                args[3] = buf;
                args[4] = NULL;
 
-               chdir(startup_dir);
+               chdir(sylpheed_get_startup_dir());
                setgid(getgid());
                setuid(getuid());
                execvp(argv0, args);
@@ -548,6 +548,7 @@ static void crash_cleanup_exit(void)
 {
        extern gchar *get_socket_name(void);
        const char *filename = get_socket_name();
-       unlink(filename);
+       g_unlink(filename);
 }
 
+#endif