changeset 4325:309e8f970517

removed report_error() and reimplemented some error routines
author mf0102 <0102@gmx.at>
date Thu, 13 Mar 2008 16:31:48 +0100
parents 360c934b9330
children 3af534ed9d20
files src/audacious/main.c src/audacious/main.h src/audacious/pluginenum.c src/audacious/ui_equalizer.c src/audacious/ui_main.c
diffstat 5 files changed, 73 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/main.c	Thu Mar 13 01:43:19 2008 +0300
+++ b/src/audacious/main.c	Thu Mar 13 16:31:48 2008 +0100
@@ -1334,28 +1334,6 @@
     gtk_widget_destroy(dialog);
 }
 
-void report_error(const gchar *error_message, ...)
-{
-    gchar *buf;
-    va_list va;
-
-    va_start(va, error_message);
-    buf = g_strdup_vprintf(error_message, va);
-    va_end(va);
-
-    fprintf(stderr, buf);
-
-    if (options.headless != 1)
-    {
-        gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(err),
-                                                 buf);
-        gtk_dialog_run(GTK_DIALOG(err));
-        gtk_widget_hide(err);
-    }
-
-    g_free(buf);
-}
-
 static gboolean
 aud_headless_iteration(gpointer unused)
 {
--- a/src/audacious/main.h	Thu Mar 13 01:43:19 2008 +0300
+++ b/src/audacious/main.h	Thu Mar 13 16:31:48 2008 +0100
@@ -200,7 +200,6 @@
 void bmp_config_load(void);
 void bmp_config_free(void);
 void make_directory(const gchar * path, mode_t mode);
-void report_error(const gchar *error_message, ...);
 
 extern GCond *cond_scan;
 extern GMutex *mutex_scan;
--- a/src/audacious/pluginenum.c	Thu Mar 13 01:43:19 2008 +0300
+++ b/src/audacious/pluginenum.c	Thu Mar 13 16:31:48 2008 +0100
@@ -32,8 +32,9 @@
 #endif
 
 #include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gprintf.h>
 #include <gmodule.h>
-#include <glib/gprintf.h>
 #include <string.h>
 
 #include "main.h"
@@ -806,10 +807,18 @@
     InputPlugin *ip;
     LowlevelPlugin *lp;
     DiscoveryPlugin *dp;
+    GtkWidget *dialog;
     gint dirsel = 0, i = 0;
 
     if (!g_module_supported()) {
-        report_error("Module loading not supported! Plugins will not be loaded.\n");
+        dialog =
+            gtk_message_dialog_new (GTK_WINDOW (mainwin),
+                                    GTK_DIALOG_DESTROY_WITH_PARENT,
+                                    GTK_MESSAGE_ERROR,
+                                    GTK_BUTTONS_CLOSE,
+                                    _("Module loading not supported! Plugins will not be loaded.\n"));
+        gtk_dialog_run (GTK_DIALOG (dialog));
+        gtk_widget_destroy (dialog);
         return;
     }
 
--- a/src/audacious/ui_equalizer.c	Thu Mar 13 01:43:19 2008 +0300
+++ b/src/audacious/ui_equalizer.c	Thu Mar 13 16:31:48 2008 +0100
@@ -777,19 +777,21 @@
     gint i = 0;
     EqualizerPreset *preset = NULL;
     GList *list = NULL;
+    GtkWidget *dialog;
+    gchar *realfn;
     gchar preset_name[0xb4];
 
     vfs_fread(header, 1, 31, file);
-    if (strncmp(header, "Winamp EQ library file v1.1", 27)) return NULL;
+    if (strncmp(header, "Winamp EQ library file v1.1", 27)) goto error;
 
     AUDDBG("The EQF header is OK\n");
 
-    if(vfs_fseek(file, 0x1f, SEEK_SET) == -1) return NULL;
+    if (vfs_fseek(file, 0x1f, SEEK_SET) == -1) goto error;
 
-    while(vfs_fread(preset_name, 1, 0xb4, file) == 0xb4) {
+    while (vfs_fread(preset_name, 1, 0xb4, file) == 0xb4) {
         AUDDBG("The preset name is '%s'\n", preset_name);
         vfs_fseek(file, 0x4d, SEEK_CUR); /* unknown crap --asphyx */
-        if(vfs_fread(bands, 1, 11, file) != 11) break;
+        if (vfs_fread(bands, 1, 11, file) != 11) break;
 
         preset = equalizer_preset_new(preset_name);
         /*this was divided by 63, but shouldn't it be 64? --majeru*/
@@ -802,7 +804,22 @@
     }
     
     list = g_list_reverse(list);
+    if (list == NULL) goto error;
+
     return list;
+
+error:
+    realfn = g_filename_from_uri(file->uri, NULL, NULL);
+    dialog = gtk_message_dialog_new (GTK_WINDOW(mainwin),
+                                     GTK_DIALOG_DESTROY_WITH_PARENT,
+                                     GTK_MESSAGE_ERROR,
+                                     GTK_BUTTONS_CLOSE,
+                                     _("Error importing Winamp EQF file '%s'"),
+                                     realfn);
+    gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (dialog);
+    g_free(realfn);
+    return NULL;
 }
 
 static void
@@ -817,13 +834,17 @@
     GList *presets;
     gint i;
 
-    if((presets = import_winamp_eqf(file)) == NULL) return;
-    EqualizerPreset *preset = (EqualizerPreset*)presets->data; /* just get the first preset --asphyx */
+    if ((presets = import_winamp_eqf(file)) == NULL)
+        return;
 
-    ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, preset->preamp);
+    /* just get the first preset --asphyx */
+    EqualizerPreset *preset = (EqualizerPreset*)presets->data;
+    ui_skinned_equalizer_slider_set_position(equalizerwin_preamp,
+                                             preset->preamp);
 
     for (i = 0; i < 10; i++)
-        ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i],  preset->bands[i]);
+        ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i],
+                                                 preset->bands[i]);
 
     g_list_foreach(presets, free_cb, NULL);
     g_list_free(presets);
@@ -1003,18 +1024,33 @@
     }
 }
 
+static VFSFile *
+open_vfs_file(const gchar *filename, const gchar *mode)
+{
+    VFSFile *file;
+    GtkWidget *dialog;
+
+    if (!(file = vfs_fopen(filename, mode))) {
+        dialog = gtk_message_dialog_new (GTK_WINDOW (mainwin),
+                                         GTK_DIALOG_DESTROY_WITH_PARENT,
+                                         GTK_MESSAGE_ERROR,
+                                         GTK_BUTTONS_CLOSE,
+                                         "Error loading file '%s'",
+                                         filename);
+        gtk_dialog_run (GTK_DIALOG (dialog));
+        gtk_widget_destroy (dialog);
+    }
+
+    return file;
+}
+
 static void
 load_winamp_file(const gchar * filename)
 {
     VFSFile *file;
-    gchar *tmp;
 
-    if (!(file = vfs_fopen(filename, "rb"))) {
-        tmp = g_strconcat("Failed to load WinAmp file: ",filename,"\n",NULL);
-        report_error(tmp);
-        g_free(tmp);
+    if (!(file = open_vfs_file(filename, "rb")))
         return;
-    }
 
     equalizerwin_read_winamp_eqf(file);
     vfs_fclose(file);
@@ -1024,15 +1060,11 @@
 import_winamp_file(const gchar * filename)
 {
     VFSFile *file;
-    gchar *tmp;
     GList *list;
 
-    if (!(file = vfs_fopen(filename, "rb")) || (list = import_winamp_eqf(file)) == NULL) {
-        tmp = g_strconcat("Failed to import WinAmp file: ",filename,"\n",NULL);
-        report_error(tmp);
-        g_free(tmp);
+    if (!(file = open_vfs_file(filename, "rb")) ||
+        !(list = import_winamp_eqf(file)))
         return;
-    }
 
     equalizer_presets = g_list_concat(equalizer_presets, list);
     equalizerwin_write_preset_file(equalizer_presets, "eq.preset");
@@ -1069,14 +1101,9 @@
     gchar name[257];
     gint i;
     guchar bands[11];
-    gchar *tmp;
 
-    if (!(file = vfs_fopen(filename, "wb"))) {
-        tmp = g_strconcat("Failed to save WinAmp file: ",filename,"\n",NULL);
-        report_error(tmp);
-        g_free(tmp);
+    if (!(file = open_vfs_file(filename, "wb")))
         return;
-    }
 
     vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file);
 
--- a/src/audacious/ui_main.c	Thu Mar 13 01:43:19 2008 +0300
+++ b/src/audacious/ui_main.c	Thu Mar 13 16:31:48 2008 +0100
@@ -114,7 +114,6 @@
 };
 
 GtkWidget *mainwin = NULL;
-GtkWidget *err = NULL; /* an error dialog for miscellaneous error messages */
 
 static gint balance;
 
@@ -1025,11 +1024,19 @@
 {
     GtkWidget *vbox, *hbox_new, *hbox_total;
     GtkWidget *time_entry, *label, *bbox, *jump, *cancel;
+    GtkWidget *dialog;
     guint tindex;
     gchar time_str[10];
 
     if (!playback_get_playing()) {
-        report_error("JIT can't be launched when no track is being played.\n");
+        dialog =
+            gtk_message_dialog_new (GTK_WINDOW (mainwin),
+                                    GTK_DIALOG_DESTROY_WITH_PARENT,
+                                    GTK_MESSAGE_ERROR,
+                                    GTK_BUTTONS_CLOSE,
+                                    _("Can't jump to time when no track is being played.\n"));
+        gtk_dialog_run (GTK_DIALOG (dialog));
+        gtk_widget_destroy (dialog);
         return;
     }
 
@@ -2466,14 +2473,6 @@
     mainwin_stime_sec = ui_skinned_textbox_new(SKINNED_WINDOW(mainwin)->fixed, 147, 4, 10, FALSE, SKIN_TEXT);
     g_signal_connect(mainwin_stime_sec, "button-press-event", G_CALLBACK(change_timer_mode_cb), NULL);
 
-    err = gtk_message_dialog_new(GTK_WINDOW(mainwin), GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_MODAL,
-                                 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error in Audacious."));
-
-
-    gtk_window_set_position(GTK_WINDOW(err), GTK_WIN_POS_CENTER);
-    /* Dang well better set an error message or you'll see this */
-    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(err),
-                                             "Boo! Bad stuff! Booga Booga!");
 
     hook_associate("playback audio error", (void *) mainwin_stop_pushed, NULL);
     hook_associate("playback audio error", (void *) run_no_output_device_dialog, NULL);