From fea06e5ae26e6eb48f4c2f823467433638529827 Mon Sep 17 00:00:00 2001 From: terminatorX <> Date: Mon, 16 Sep 2002 19:36:51 +0000 Subject: [PATCH] Nicer Message Dialogs - Alex --- src/tX_loaddlg.cc | 30 +++++++++++--------- src/tX_mastergui.cc | 69 +++++++++++++++++++++++++++++---------------- src/tX_mastergui.h | 2 +- src/tX_vtt.cc | 32 ++++++++++----------- src/tX_vtt.h | 2 +- src/tX_vttgui.cc | 55 +++++++++++++++++++++++++++--------- 6 files changed, 120 insertions(+), 70 deletions(-) diff --git a/src/tX_loaddlg.cc b/src/tX_loaddlg.cc index b370c88..0439edf 100644 --- a/src/tX_loaddlg.cc +++ b/src/tX_loaddlg.cc @@ -61,14 +61,19 @@ int ld_create_loaddlg(int mode, int count) if (ld_loaddlg) return(1); -// if(needinit) ld_init(); - ld_mode=mode; ld_count=count; - - ld_loaddlg=gtk_dialog_new(); + +#ifdef USE_GTK2 + ld_loaddlg=gtk_dialog_new_with_buttons("terminatorX - loading", + GTK_WINDOW(main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_NONE, NULL); +#else + ld_loaddlg=gtk_dialog_new(); +#endif ld_window=&(GTK_DIALOG(ld_loaddlg)->window); - gtk_window_set_title(ld_window, "terminatorX - Loading"); +#ifndef USE_GTK2 + gtk_window_set_title(ld_window, "terminatorX - loading"); +#endif gtk_container_set_border_width(GTK_CONTAINER(ld_window), 5); vbox=GTK_WIDGET(GTK_DIALOG(ld_loaddlg)->vbox); @@ -97,27 +102,24 @@ int ld_create_loaddlg(int mode, int count) ld_single_p=gtk_progress_bar_new(); add_widget_fix(ld_single_p); - + +#ifndef USE_GTK2 dummy=gtk_button_new_with_label("Cancel"); gtk_box_pack_start(GTK_BOX(actionarea), dummy, WID_DYN); gtk_widget_show(dummy); - - dummy=gtk_widget_get_toplevel(dummy); - - +#endif gtk_window_set_modal(ld_window, TRUE); gtk_window_set_default_size(ld_window, 400, 100); +#ifndef USE_GTK2 gtk_window_set_position(ld_window, GTK_WIN_POS_CENTER_ALWAYS); +#endif gtk_widget_realize(ld_loaddlg); gdk_window_set_decorations(gtk_widget_get_parent_window(vbox),(GdkWMDecoration) 0); - -// gtk_window_reposition(ld_window, gdk_screen_width()/2-200, gdk_screen_height()/2-50); - //gtk_window_reposition(ld_window, gdk_screen_width()/2-200, gdk_screen_height()/2-50); gtk_widget_show(ld_loaddlg); gtk_flush(); - return(0); + return 0; } char *strip_path(char *name) diff --git a/src/tX_mastergui.cc b/src/tX_mastergui.cc index fba8d64..6f02073 100644 --- a/src/tX_mastergui.cc +++ b/src/tX_mastergui.cc @@ -125,8 +125,6 @@ vtt_class *old_focus=NULL; int grab_status=0; int last_grab_status=0; -void tx_note(const char *message); - GtkTooltips *gui_tooltips=NULL; void gui_set_tooltip(GtkWidget *wid, char *tip) @@ -300,27 +298,27 @@ void load_tt_part(char * buffer) fread(idbuff, strlen(TX_SET_ID_10), 1, in); if (strncmp(idbuff, TX_SET_ID_10, strlen(TX_SET_ID_10))==0) { - if (vtt_class::load_all_10(in, buffer)) tx_note("Error while reading set."); + if (vtt_class::load_all_10(in, buffer)) tx_note("Error while reading set.", true); } else if (strncmp(idbuff, TX_SET_ID_11, strlen(TX_SET_ID_11))==0) { - if (vtt_class::load_all_11(in, buffer)) tx_note("Error while reading set."); + if (vtt_class::load_all_11(in, buffer)) tx_note("Error while reading set.", true); } else if (strncmp(idbuff, TX_SET_ID_12, strlen(TX_SET_ID_12))==0) { - if (vtt_class::load_all_12(in, buffer)) tx_note("Error while reading set."); + if (vtt_class::load_all_12(in, buffer)) tx_note("Error while reading set.", true); } else if (strncmp(idbuff, TX_SET_ID_13, strlen(TX_SET_ID_13))==0) { - if (vtt_class::load_all_13(in, buffer)) tx_note("Error while reading set."); + if (vtt_class::load_all_13(in, buffer)) tx_note("Error while reading set.", true); } else if (strncmp(idbuff, TX_SET_ID_14, strlen(TX_SET_ID_14))==0) { - if (vtt_class::load_all_14(in, buffer)) tx_note("Error while reading set."); + if (vtt_class::load_all_14(in, buffer)) tx_note("Error while reading set.", true); } else { - tx_note("Sorry, this file is not a terminatorX set-file."); + tx_note("This file is not a terminatorX set-file.", true); fclose(in); return; } @@ -339,7 +337,7 @@ void load_tt_part(char * buffer) strcpy(idbuff, "Failed to access file: \""); // I'm stealing the unrelated sting for a temp :) strcat(idbuff, globals.tables_filename); strcat(idbuff, "\""); - tx_note(idbuff); + tx_note(idbuff, true); } } @@ -452,14 +450,14 @@ void do_save_tables(GtkWidget *wid) { strcpy(idbuffer, TX_SET_ID_14); fwrite(idbuffer, strlen(idbuffer), 1, out); - if (vtt_class::save_all(out)) tx_note("Error while saving set."); + if (vtt_class::save_all(out)) tx_note("Error while saving set.", true); fclose(out); sprintf(wbuf,"terminatorX - %s", strip_path(buffer)); gtk_window_set_title(GTK_WINDOW(main_window), wbuf); } else { - tx_note("Failed to access file."); + tx_note("Failed to open file for write access.", true); } } @@ -537,15 +535,15 @@ GtkSignalFunc audio_on(GtkWidget *w, void *d) switch(res) { case ERROR_BUSY: - tx_note("Error starting engine: engine is already running."); + tx_note("Error starting engine: engine is already running.", true); break; case ERROR_AUDIO: - tx_note("Error starting engine: failed to access audiodevice."); + tx_note("Error starting engine: failed to access audiodevice.", true); break; case ERROR_TAPE: - tx_note("Error starting engine: failed to open the recording file."); + tx_note("Error starting engine: failed to open the recording file.", true); break; - default:tx_note("Error starting engine: Unknown error."); + default:tx_note("Error starting engine: Unknown error.", true); } return 0; } @@ -687,7 +685,7 @@ GtkSignalFunc seq_play(GtkWidget *w, void *) if ((sequencer.is_empty()) && (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(seq_rec_btn)))) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { - tx_note("Sequencer playback triggered - but no events\nrecorded yet - nothing to playback!\n\nTo perform live with terminatorX just activate the\naudio engine with the \"Power\" button."); + tx_note("Sequencer playback triggered - but no events recorded yet - nothing to playback!\n\nTo perform live with terminatorX just activate the audio engine with the \"Power\" button."); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); } } else { @@ -1127,9 +1125,23 @@ void note_destroy(GtkWidget *widget, GtkWidget *mbox) gtk_widget_destroy(GTK_WIDGET(mbox)); } -void tx_note(const char *message) +void tx_note(const char *message, bool isError=false) { - char buffer[4096]="\nterminatorX Note:\n\n"; + char buffer[4096]="terminatorX "; + if (isError) { + strcat(buffer, "note:\n\n"); + } else { + strcat(buffer, "error:\n\n"); + } + +#ifdef USE_GTK2 + strcat(buffer, message); + GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + isError ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message); + int result=gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +#else GtkWidget *mbox; GtkWidget *label; @@ -1140,10 +1152,10 @@ void tx_note(const char *message) mbox=gtk_dialog_new(); win=&(GTK_DIALOG(mbox)->window); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(mbox)->vbox), 2); + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(mbox)->vbox), 4); gtk_container_set_border_width(GTK_CONTAINER(mbox), 10); - label=gtk_label_new("terminatorX Note"); + label=gtk_label_new("terminatorX note"); gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0); gtk_widget_show(label); @@ -1152,10 +1164,8 @@ void tx_note(const char *message) gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), sp, TRUE, TRUE, 0); gtk_widget_show(sp); - strcpy(buffer, "\n"); - strcat(buffer, message); - strcat(buffer, "\n"); - label=gtk_label_new(buffer); + label=gtk_label_new(message); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mbox)->vbox), label, TRUE, TRUE, 0); gtk_widget_show(label); @@ -1171,11 +1181,21 @@ void tx_note(const char *message) gtk_widget_grab_default(btn); gtk_widget_show(btn); gtk_widget_show(mbox); +#endif } void tx_l_note(const char *message) { +#ifdef USE_GTK2 + char buffer[4096]="Plugin info:\n\n"; + strcat(buffer, message); + + GtkWidget *dialog=gtk_message_dialog_new(GTK_WINDOW(main_window), + GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message); + int result=gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +#else char buffer[4096]="\n Plugin Info: \n ------------ \n\n"; GtkWidget *mbox; @@ -1201,6 +1221,7 @@ void tx_l_note(const char *message) gtk_window_set_default_size(win, 200, 100); gtk_window_set_position(win, GTK_WIN_POS_CENTER_ALWAYS); gtk_widget_show(mbox); +#endif } void display_mastergui() diff --git a/src/tX_mastergui.h b/src/tX_mastergui.h index 498b463..dfe03ae 100644 --- a/src/tX_mastergui.h +++ b/src/tX_mastergui.h @@ -42,7 +42,7 @@ extern tX_seqpar_master_pitch sp_master_pitch; extern void create_mastergui(int x, int y); extern void wav_progress_update(gfloat percent); extern void note_destroy(GtkWidget *widget, GtkWidget *mbox); -extern void tx_note(const char *message); +extern void tx_note(const char *message, bool isError=false); extern void tx_l_note(const char *message); extern void display_mastergui(); extern void grab_off(); diff --git a/src/tX_vtt.cc b/src/tX_vtt.cc index 9f2d40e..f345454 100644 --- a/src/tX_vtt.cc +++ b/src/tX_vtt.cc @@ -217,9 +217,9 @@ void vtt_class :: set_name(char *newname) gui_set_name(this, name); } -int vtt_class :: load_file(char *fname) +tX_audio_error vtt_class :: load_file(char *fname) { - int res; + tX_audio_error res; int was_playing=is_playing; if (is_playing) stop(); @@ -1887,14 +1887,14 @@ int vtt_class :: load_12(FILE * input) } else { - sprintf(buffer,"Fatal Error: Couldn't find required plugin with ID [%li].", id); - tx_note(buffer); + sprintf(buffer,"Couldn't find required plugin with ID [%li].", id); + tx_note(buffer, true); res++; } break; default: - tx_note("Fatal Error loading set: unknown effect type!"); + tx_note("Fatal error loading set: unknown effect type!", true); res++; } } @@ -2044,14 +2044,14 @@ int vtt_class :: load_13(FILE * input) } else { - sprintf(buffer,"Fatal Error: Couldn't find required plugin with ID [%li].", id); - tx_note(buffer); + sprintf(buffer,"Couldn't find required plugin with ID [%li].", id); + tx_note(buffer, true); res++; } break; default: - tx_note("Fatal Error loading set: unknown effect type!"); + tx_note("Fatal error loading set: unknown effect type!", true); res++; } } @@ -2204,14 +2204,14 @@ int vtt_class :: load_14(FILE * input) } else { - sprintf(buffer,"Fatal Error: Couldn't find required plugin with ID [%li].", id); - tx_note(buffer); + sprintf(buffer,"Couldn't find required plugin with ID [%li].", id); + tx_note(buffer, true); res++; } break; default: - tx_note("Fatal Error loading set: unknown effect type!"); + tx_note("Fatal error loading set: unknown effect type!", true); res++; } } @@ -2310,7 +2310,7 @@ int vtt_class :: load_all_10(FILE* input, char *fname) ld_set_filename(ftmp); //restmp=load_wav(newvtt->filename, &newbuffer, &size); - restmp=newvtt->load_file(ftmp); + restmp=(int) newvtt->load_file(ftmp); res+=restmp; } gtk_box_pack_start(GTK_BOX(control_parent), newvtt->gui.control_box, TRUE, TRUE, 0); @@ -2364,7 +2364,7 @@ int vtt_class :: load_all_11(FILE* input, char *fname) ld_set_filename(ftmp); //restmp=load_wav(newvtt->filename, &newbuffer, &size); - restmp=newvtt->load_file(ftmp); + restmp=(int) newvtt->load_file(ftmp); res+=restmp; } gtk_box_pack_start(GTK_BOX(control_parent), newvtt->gui.control_box, TRUE, TRUE, 0); @@ -2419,7 +2419,7 @@ int vtt_class :: load_all_12(FILE* input, char *fname) ld_set_filename(ftmp); //restmp=load_wav(newvtt->filename, &newbuffer, &size); - restmp=newvtt->load_file(ftmp); + restmp=(int) newvtt->load_file(ftmp); res+=restmp; } gtk_box_pack_start(GTK_BOX(control_parent), newvtt->gui.control_box, TRUE, TRUE, 0); @@ -2473,7 +2473,7 @@ int vtt_class :: load_all_13(FILE* input, char *fname) ld_set_filename(ftmp); //restmp=load_wav(newvtt->filename, &newbuffer, &size); - restmp=newvtt->load_file(ftmp); + restmp=(int) newvtt->load_file(ftmp); res+=restmp; } gtk_box_pack_start(GTK_BOX(control_parent), newvtt->gui.control_box, TRUE, TRUE, 0); @@ -2527,7 +2527,7 @@ int vtt_class :: load_all_14(FILE* input, char *fname) ld_set_filename(ftmp); //restmp=load_wav(newvtt->filename, &newbuffer, &size); - restmp=newvtt->load_file(ftmp); + restmp=(int) newvtt->load_file(ftmp); res+=restmp; } gtk_box_pack_start(GTK_BOX(control_parent), newvtt->gui.control_box, TRUE, TRUE, 0); diff --git a/src/tX_vtt.h b/src/tX_vtt.h index 1713170..fe98a58 100644 --- a/src/tX_vtt.h +++ b/src/tX_vtt.h @@ -300,7 +300,7 @@ class vtt_class static int load_all_13(FILE *, char *fname); /* fname is for display only*/ static int load_all_14(FILE *, char *fname); /* fname is for display only*/ static int save_all(FILE *); - int load_file(char *name); + tX_audio_error load_file(char *name); void render_scratch(); void render_lp(); diff --git a/src/tX_vttgui.cc b/src/tX_vttgui.cc index dcfae11..fb73568 100644 --- a/src/tX_vttgui.cc +++ b/src/tX_vttgui.cc @@ -133,7 +133,7 @@ char global_filename_buffer[PATH_MAX]; void load_part(char *newfile, vtt_class *vtt) { - int ret=0; + tX_audio_error ret=TX_AUDIO_SUCCESS; ld_create_loaddlg(TX_LOADDLG_MODE_SINGLE, 1); ld_set_filename(newfile); @@ -146,34 +146,61 @@ void load_part(char *newfile, vtt_class *vtt) switch(ret) { case TX_AUDIO_ERR_ALLOC: - tx_note("Error loading file: failed to allocate memory"); + tx_note("Failed to load audiofile - there's not enough memory available.", true); break; case TX_AUDIO_ERR_PIPE_READ: - tx_note("Error loading file: broken pipe (File not supported/corrupt?)"); + tx_note("An error occured on reading from the piped process - probably the file format of the audiofile is not supported by this configuration - please check terminatorX' INSTALL file on howto configure terminatorX for files of this format.", true); break; case TX_AUDIO_ERR_SOX: - tx_note("Error loading file: couldn't execute sox"); + tx_note("Failed to run sox - to load the given audiofile please ensure that sox is installed correctly.", true); break; case TX_AUDIO_ERR_MPG123: - tx_note("Error loading file: couldn't execute mpg123"); + tx_note("Failed to run mpg123 - to load the given mp3 file please ensure that mpg123 (or mpg321) is installed correctly.", true); break; case TX_AUDIO_ERR_WAV_NOTFOUND: - tx_note("Error loading file: file not found"); + tx_note("Couldn't acces the audiofile - file not found.", true); break; case TX_AUDIO_ERR_NOT_16BIT: - tx_note("Error loading file: RIFF/WAV is not 16 Bit."); + tx_note("The wav file doesn't use 16 bit wide samples - please compile terminatorX with libaudiofile support to enable loading of such files.", true); break; case TX_AUDIO_ERR_NOT_MONO: - tx_note("Error loading file: RIFF/WAV is not mono"); + tx_note("The wav file is not mono - please compile terminatorX with libaudiofile support to enable loading of such files.", true); break; case TX_AUDIO_ERR_WAV_READ: - tx_note("Error loading file: RIFF/WAV corrupt?"); + tx_note("The wav file seems to be corrupt.", true); break; case TX_AUDIO_ERR_NOT_SUPPORTED: - tx_note("Error loading file: filetype not supported."); + tx_note("The file format of the audiofile is not supported - please check terminatorX' INSTALL file on howto configure terminatorX for files of this format.", true); + break; + case TX_AUDIO_ERR_MAD_OPEN: + tx_note("Failed to open this mp3 file - please ensure that the file exists and is readable.", true); + break; + case TX_AUDIO_ERR_MAD_STAT: + tx_note("Failed to 'stat' this mp3 file - please ensure that the file exists and is readable.", true); + break; + case TX_AUDIO_ERR_MAD_DECODE: + tx_note("Failed to decode the mp3 stream - file is corrupt.", true); + break; + case TX_AUDIO_ERR_MAD_MMAP: + tx_note("Failed to map the audiofile to memory - please ensure the file is readable.", true); + break; + case TX_AUDIO_ERR_MAD_MUNMAP: + tx_note("Failed to unmap audiofile.", true); + break; + case TX_AUDIO_ERR_VORBIS_OPEN: + tx_note("Failed to open ogg file - please ensure the file is an ogg stream and that it is readable.", true); + break; + case TX_AUDIO_ERR_VORBIS_NODATA: + tx_note("The vorbis codec failed to decode any data - possibly this ogg stream is corrupt.", true); + break; + case TX_AUDIO_ERR_AF_OPEN: + tx_note("Failed to open this file with libaudiofile - please check terminatorX' INSTALL file on howto configure terminatorX for files of this format.",true); + break; + case TX_AUDIO_ERR_AF_NODATA: + tx_note("libaudiofile failed to decode any data - possilby the audiofile is corrupt.", true); break; default: - tx_note("OOPS: An unknown error occured - This shouldn't happen :("); + tx_note("An unknown error occured - if this bug is reproducible please report it, thanks.", true); } } else @@ -297,7 +324,7 @@ void edit_vtt_buffer(GtkWidget *wid, vtt_class *vtt) if (vtt->samples_in_buffer == 0) { - tx_note("Nothing to edit."); + tx_note("No audiofile loaded - so there's nothing to edit.", true); } else if (strlen(globals.file_editor)>0) @@ -307,7 +334,7 @@ void edit_vtt_buffer(GtkWidget *wid, vtt_class *vtt) } else { - tx_note("No soundfile editor configured."); + tx_note("No soundfile editor has been configured - to do so enter the soundfile editor of your choice in the options dialog.", true); } } @@ -322,7 +349,7 @@ void reload_vtt_buffer(GtkWidget *wid, vtt_class *vtt) strcpy(reload_buffer, vtt->filename); load_part(reload_buffer, vtt); } - else tx_note("Nothing to reload."); + else tx_note("No audiofile loaded - so there's nothing to reload.", true); } void clone_vtt(GtkWidget *wid, vtt_class *vtt) -- 2.25.4