Mercurial > pidgin.yaz
changeset 4430:801830dec409
[gaim-migrate @ 4705]
robot101 gave me a bad patch
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 26 Jan 2003 20:43:25 +0000 |
parents | bf770f11132b |
children | 50ef0203fdbf |
files | configure.ac configure.in src/aim.c src/browser.c src/gaimrc.c src/prefs.c src/sound.c src/ui.h |
diffstat | 8 files changed, 699 insertions(+), 232 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Sun Jan 26 20:41:49 2003 +0000 +++ b/configure.ac Sun Jan 26 20:43:25 2003 +0000 @@ -122,7 +122,10 @@ AC_DEFINE_UNQUOTED(STATIC_PROTO_INIT, $extern_init void static_proto_init() { $load_proto }, [Loads static protocol plugin module initialization functions.]) -AC_ARG_ENABLE(audio, [ --disable-audio compile without libao/libaudiofile for sound playing],,enable_audio=yes) +AC_ARG_ENABLE(esd, [ --disable-esd Turn off ESD (default=auto)],,enable_esd=yes) +AC_ARG_ENABLE(nas, [ --enable-nas Enable NAS (Network Audio System) support],,enable_nas=no) +AC_ARG_ENABLE(artsc, [ --disable-artsc Turn off ArtsC (default=auto)],,enable_artsc=yes) + AC_ARG_ENABLE(plugins, [ --disable-plugins compile without plugin support],,enable_plugins=yes) AC_ARG_ENABLE(perl, [ --disable-perl compile without perl scripting],,enable_perl=yes) AC_ARG_ENABLE(gtkspell, [ --disable-gtkspell compile without GtkSpell automatic spell checking],,enable_gtkspell=yes) @@ -271,28 +274,45 @@ fi fi -if test "$enable_audio" = yes ; then - AC_CHECK_HEADERS(ao/ao.h, found_ao_lib=true, found_ao_lib=false) - if test "$found_ao_lib" = "true"; then - AC_CHECK_LIB(ao, ao_initialize, found_ao_lib=true, found_ao_lib=false) - fi - - AC_CHECK_HEADERS(audiofile.h, found_af_lib=true, found_af_lib=false) - if test "$found_af_lib" = "true"; then - AC_CHECK_LIB(audiofile, afOpenFile, found_af_lib=true, found_af_lib=false) +if test "$enable_nas" = yes ; then + AC_DEFINE(NAS_SOUND, 1, [Define if we have NAS sound support.]) + SOUND_LIBS="-laudio -lXt" +fi +if test "$enable_esd" = yes ; then + AM_PATH_GESD + if test "$no_esd" != yes ; then + old_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ESD_CFLAGS" + AC_TRY_COMPILE(,[#include <esd.h>], + [ + AC_DEFINE(ESD_SOUND, 1, [Define if we have ESD sound support.]) + SOUND_LIBS="$SOUND_LIBS $ESD_LIBS" + ],[ + enable_esd=no + CFLAGS="$old_CFLAGS" + ]) + else + enable_esd=no + fi +fi +if test "x$enable_artsc" = "xyes"; then + AM_PATH_ARTSC + if test "x$no_artsc" != "xyes" ; then + old_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ARTSC_CFLAGS" + AC_TRY_COMPILE(,[#include <artsc.h>], + [ + AC_DEFINE(ARTSC_SOUND, 1, [Define if we have artsc sound support.]) + SOUND_LIBS="$SOUND_LIBS $ARTSC_LIBS" + ],[ + enable_artsc=no + CFLAGS="$old_CFLAGS" + ]) + else + enable_artsc=no fi - - if test "$found_ao_lib" = "true" -a "$found_af_lib" = "true"; then - SOUND_LIBS="-lao -laudiofile" - AC_SUBST(SOUND_LIBS) - AC_DEFINE(USE_AO, 1, [Define if we're using libao and libaudiofile for sound playing]) - enable_audio=yes - else - enable_audio=no - fi -else - enable_audio=no fi +AC_SUBST(SOUND_LIBS) if test "$ac_cv_cygwin" = yes ; then LDADD="$LDADD -static" @@ -422,16 +442,20 @@ echo Build Protocol Plugins........ : $enable_prpls echo Protocols to link statically.. : $STATIC_PRPLS echo -echo UI Library.................... : GTK 2.x +echo UI Library.................... : GTK 2.0 echo echo Build with Plugin support..... : $enable_plugins echo Build with Perl support....... : $enable_perl -echo Build with Audio support...... : $enable_audio -echo Build with GtkSpell support... : $enable_gtkspell +echo +echo Build with GtkSpell............: $enable_gtkspell echo echo Use XScreenSaver Extension.... : $enable_xss echo Use X Session Management...... : $enable_sm echo +echo Build with ESD................ : $enable_esd +echo Build with NAS................ : $enable_nas +echo Build with ArtsC.............. : $enable_artsc +echo echo Print debugging messages...... : $enable_debug echo eval eval echo Gaim will be installed in $bindir.
--- a/configure.in Sun Jan 26 20:41:49 2003 +0000 +++ b/configure.in Sun Jan 26 20:43:25 2003 +0000 @@ -112,13 +112,16 @@ AC_DEFINE_UNQUOTED(STATIC_PROTO_INIT, $extern_init void static_proto_init() { $load_proto }, [Loads static protocol plugin module initialization functions.]) -AC_ARG_ENABLE(audio, [ --disable-audio compile without libao/libaudiofile for sound playing],,enable_audio=yes) +AC_ARG_ENABLE(esd, [ --disable-esd Turn off ESD (default=auto)],,enable_esd=yes) +AC_ARG_ENABLE(nas, [ --enable-nas Enable NAS (Network Audio System) support],,enable_nas=no) +AC_ARG_ENABLE(artsc, [ --disable-artsc Turn off ArtsC (default=auto)],,enable_artsc=yes) + AC_ARG_ENABLE(plugins, [ --disable-plugins compile without plugin support],,enable_plugins=yes) AC_ARG_ENABLE(perl, [ --disable-perl compile without perl scripting],,enable_perl=yes) AC_ARG_ENABLE(gtkspell, [ --disable-gtkspell compile without GtkSpell automatic spell checking],,enable_gtkspell=yes) + AC_ARG_ENABLE(debug, [ --enable-debug compile with debugging support],,enable_debug=no) AC_ARG_ENABLE(screensaver, [ --disable-screensaver compile without X screensaver extension],,enable_xss=yes) -AC_ARG_ENABLE(sm, [ --disable-sm compile without X session management support],,enable_sm=yes) AC_ARG_WITH(krb4, [ --with-krb4=PREFIX Compile Zephyr plugin with Kerberos 4 support],kerberos="$withval",kerberos="no") if test "$enable_debug" = yes ; then @@ -245,28 +248,45 @@ fi fi -if test "$enable_audio" = yes ; then - AC_CHECK_HEADERS(ao/ao.h, found_ao_lib=true, found_ao_lib=false) - if test "$found_ao_lib" = "true"; then - AC_CHECK_LIB(ao, ao_initialize, found_ao_lib=true, found_ao_lib=false) - fi - - AC_CHECK_HEADERS(audiofile.h, found_af_lib=true, found_af_lib=false) - if test "$found_af_lib" = "true"; then - AC_CHECK_LIB(audiofile, afOpenFile, found_af_lib=true, found_af_lib=false) +if test "$enable_nas" = yes ; then + AC_DEFINE(NAS_SOUND, 1, [Define if we have NAS sound support.]) + SOUND_LIBS="-laudio -lXt" +fi +if test "$enable_esd" = yes ; then + AM_PATH_GESD + if test "$no_esd" != yes ; then + old_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ESD_CFLAGS" + AC_TRY_COMPILE(,[#include <esd.h>], + [ + AC_DEFINE(ESD_SOUND, 1, [Define if we have ESD sound support.]) + SOUND_LIBS="$SOUND_LIBS $ESD_LIBS" + ],[ + enable_esd=no + CFLAGS="$old_CFLAGS" + ]) + else + enable_esd=no + fi +fi +if test "x$enable_artsc" = "xyes"; then + AM_PATH_ARTSC + if test "x$no_artsc" != "xyes" ; then + old_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $ARTSC_CFLAGS" + AC_TRY_COMPILE(,[#include <artsc.h>], + [ + AC_DEFINE(ARTSC_SOUND, 1, [Define if we have artsc sound support.]) + SOUND_LIBS="$SOUND_LIBS $ARTSC_LIBS" + ],[ + enable_artsc=no + CFLAGS="$old_CFLAGS" + ]) + else + enable_artsc=no fi - - if test "$found_ao_lib" = "true" -a "$found_af_lib" = "true"; then - SOUND_LIBS="-lao -laudiofile" - AC_SUBST(SOUND_LIBS) - AC_DEFINE(USE_AO, 1, [Define if we're using libao and libaudiofile for sound playing]) - enable_audio=yes - else - enable_audio=no - fi -else - enable_audio=no fi +AC_SUBST(SOUND_LIBS) if test "$ac_cv_cygwin" = yes ; then LDADD="$LDADD -static" @@ -398,15 +418,18 @@ echo Build Protocol Plugins........ : $enable_prpls echo Protocols to link statically.. : $STATIC_PRPLS echo -echo UI Library.................... : GTK 2.x +echo UI Library.................... : GTK 2.0 echo echo Build with Plugin support..... : $enable_plugins echo Build with Perl support....... : $enable_perl -echo Build with Audio support...... : $enable_audio -echo Build with GtkSpell support... : $enable_gtkspell +echo +echo Build with GtkSpell............: $enable_gtkspell echo echo Use XScreenSaver Extension.... : $enable_xss -echo Use X Session Management...... : $enable_sm +echo +echo Build with ESD................ : $enable_esd +echo Build with NAS................ : $enable_nas +echo Build with ArtsC.............. : $enable_artsc echo echo Print debugging messages...... : $enable_debug echo
--- a/src/aim.c Sun Jan 26 20:41:49 2003 +0000 +++ b/src/aim.c Sun Jan 26 20:43:25 2003 +0000 @@ -896,8 +896,6 @@ gtk_main(); core_quit(); /* don't need ui_quit here because ui doesn't create anything */ - /* maybe we do now? -Robot101 */ - sound_quit(); #ifdef _WIN32 wgaim_cleanup(); #endif
--- a/src/browser.c Sun Jan 26 20:41:49 2003 +0000 +++ b/src/browser.c Sun Jan 26 20:43:25 2003 +0000 @@ -487,106 +487,263 @@ gdk_x11_xatom_to_atom (XA_STRING), 8, GDK_PROP_MODE_REPLACE, (unsigned char *)command, strlen(command)); - gdk_window_add_filter(window, (GdkFilterFunc) netscape_response_cb, window); + while (!done) { + GdkEvent *event; + + event = gdk_event_get(); + + if (!event) + continue; + + if (event->any.window != window) { + gtk_main_do_event(event); + continue; + } + + if (event->type == GDK_DESTROY && event->any.window == window) { + + /* Print to warn user... */ + debug_printf("%s: window 0x%x was destroyed.\n", progname, (unsigned int)window); + result = 6; + done = True; + } else if (event->type == GDK_PROPERTY_NOTIFY && + event->property.state == GDK_PROPERTY_NEW_VALUE && + event->property.window == window && + event->property.atom == GDKA_MOZILLA_RESPONSE) { + GdkAtom actual_type; + gint actual_format, nitems; + unsigned char *data = 0; + + result = gdk_property_get(window, GDKA_MOZILLA_RESPONSE, + gdk_x11_xatom_to_atom (XA_STRING), 0, + (65536 / sizeof(long)), + 1, &actual_type, &actual_format, &nitems, &data); + + + if (result == Success && data && *data) { + debug_printf("%s: (server sent " MOZILLA_RESPONSE_PROP + " \"%s\" to 0x%x.)\n", + progname, data, (unsigned int)window); + } + + if (result != Success) { + debug_printf("%s: failed reading " MOZILLA_RESPONSE_PROP + " from window 0x%0x.\n", progname, (unsigned int)window); + result = 6; + done = True; + } else if (!data || strlen((char *)data) < 5) { + debug_printf("%s: invalid data on " MOZILLA_RESPONSE_PROP + " property of window 0x%0x.\n", + progname, (unsigned int)window); + result = 6; + done = True; + } else if (*data == '1') { /* positive preliminary reply */ + debug_printf("%s: %s\n", progname, data + 4); + /* keep going */ + done = False; + } else if (!strncmp((char *)data, "200", 3)) { + result = 0; + done = True; + } else if (*data == '2') { + debug_printf("%s: %s\n", progname, data + 4); + result = 0; + done = True; + } else if (*data == '3') { + debug_printf("%s: internal error: " + "server wants more information? (%s)\n", progname, data); + result = 3; + done = True; + } else if (*data == '4' || *data == '5') { + debug_printf("%s: %s\n", progname, data + 4); + result = (*data - '0'); + done = True; + } else { + debug_printf("%s: unrecognised " MOZILLA_RESPONSE_PROP + " from window 0x%x: %s\n", + progname, (unsigned int)window, data); + result = 6; + done = True; + } + + if (data) + g_free(data); + } else if (event->type == GDK_PROPERTY_NOTIFY && + event->property.window == window && + event->property.state == GDK_PROPERTY_DELETE && + event->property.atom == GDKA_MOZILLA_COMMAND) { + debug_printf("%s: (server 0x%x has accepted " + MOZILLA_COMMAND_PROP ".)\n", progname, (unsigned int)window); + } + gdk_event_free(event); + } + + if (new_command) + g_free(new_command); + + return result; } -static gboolean netscape_command(const char *command) + +gboolean check_netscape(gpointer data) { - GdkWindow *window = NULL; - - if (netscape_lock) { - debug_printf("netscape_command() is currently in use.\n"); - return FALSE; - } - - netscape_lock = 1; + char *msg = data; + int status; + GdkWindow *window; mozilla_remote_init_atoms(); window = mozilla_remote_find_window(); - if (window == NULL || (GDK_WINDOW_OBJECT(window)->destroyed == TRUE)) { - debug_printf("Remote window absent or unsuitable.\n"); + if (window && (GDK_WINDOW_OBJECT(window)->destroyed == FALSE)) { + + XSelectInput(gdk_display, GDK_WINDOW_XWINDOW(window), + (PropertyChangeMask | StructureNotifyMask)); + + + mozilla_remote_obtain_lock(window); + + status = mozilla_remote_command(window, msg, False); + + if (status != 6) + mozilla_remote_free_lock(window); + netscape_lock = 0; + + g_free(msg); return FALSE; + } else + return TRUE; +} + + +static void netscape_command(char *command) +{ + int status; + pid_t pid; + GdkWindow *window; + + if (netscape_lock) + return; + + netscape_lock = 1; + + + + mozilla_remote_init_atoms(); + window = mozilla_remote_find_window(); + + if (window && (GDK_WINDOW_OBJECT(window)->destroyed == FALSE)) { + + XSelectInput(gdk_display, GDK_WINDOW_XWINDOW(window), + (PropertyChangeMask | StructureNotifyMask)); + + mozilla_remote_obtain_lock(window); + + status = mozilla_remote_command(window, command, False); + + if (status != 6) + mozilla_remote_free_lock(window); + + netscape_lock = 0; + + gdk_window_destroy(window); + } else { + pid = fork(); + if (pid == 0) { + char *args[2]; + int e; + + args[0] = g_strdup("netscape"); + args[1] = NULL; + e = execvp(args[0], args); + printf("Hello%d\n", getppid()); + + _exit(0); + } else { + char *tmp = g_strdup(command); + g_timeout_add(200, check_netscape, tmp); + } } - mozilla_remote_command(window, command, False); - - netscape_lock = 0; - return TRUE; } void open_url(GtkWidget *w, char *url) { - char *command = NULL; - GError *error = NULL; - - switch (web_browser) { - case BROWSER_NETSCAPE: { - char *args = NULL; - - if (misc_options & OPT_MISC_BROWSER_POPUP) - args = g_strdup_printf("OpenURL(%s, new-window)", url); - else - args = g_strdup_printf("OpenURL(%s)", url); - - if (netscape_command(args)) { - g_free(args); - return; + gchar *space_free_url; + + if (web_browser == BROWSER_NETSCAPE) { + char *command; + + if (misc_options & OPT_MISC_BROWSER_POPUP) + command = g_strdup_printf("OpenURL(%s, new-window)", url); + else + command = g_strdup_printf("OpenURL(%s)", url); + + netscape_command(command); + g_free(command); +/* fixme: GNOME helper * + * } else if (web_browser == BROWSER_GNOME) { * + * gnome_url_show(url); */ + } else { + pid_t pid; + + pid = fork(); + + if (pid == 0) { + /* args will be allocated below but we don't bother + * freeing it since we're just going to exec and + * exit */ + char **args=NULL; + char command[1024]; + + if (web_browser == BROWSER_OPERA) { + args = g_new(char *, 4); + args[0] = "opera"; + args[1] = "-newwindow"; + args[2] = url; + args[3] = NULL; + } else if (web_browser == BROWSER_KONQ) { + args = g_new(char *, 4); + args[0] = "kfmclient"; + args[1] = "openURL"; + args[2] = url; + args[3] = NULL; + } else if (web_browser == BROWSER_GALEON) { + args = g_new(char *, 4); + args[0] = "galeon"; + if (misc_options & OPT_MISC_BROWSER_POPUP) { + args[1] = "-w"; + args[2] = url; + args[3] = NULL; + } else { + args[1] = url; + args[2] = NULL; + } + } else if (web_browser == BROWSER_MOZILLA) { + args = g_new(char *, 4); + args[0] = "mozilla"; + args[1] = url; + args[2] = NULL; + } else if (web_browser == BROWSER_MANUAL) { + if(strcmp(web_command,"") == 0) + _exit(0); + space_free_url = g_strdelimit(url, " ", '+'); + g_snprintf(command, sizeof(command), web_command, space_free_url); + g_free(space_free_url); + args = g_strsplit(command, " ", 0); } - /* if netscape is running ... - command = g_strdup_printf("netscape -remote %s", args); */ - - command = g_strdup_printf("netscape %s", url); - g_free(args); - } break; - - case BROWSER_OPERA: - command = g_strdup_printf("opera -newwindow %s", url); - break; - - case BROWSER_KONQ: - command = g_strdup_printf("kfmclient openURL %s", url); - break; - - case BROWSER_GALEON: - command = g_strdup_printf("galeon -w %s", url); - command = g_strdup_printf("galeon %s", url); - break; - - case BROWSER_MOZILLA: - command = g_strdup_printf("mozilla %s", url); - break; - - case BROWSER_MANUAL: { - char *space_free_url = NULL; - - if (!web_command[0]) { - do_error_dialog(_("Unable to launch your browser because the 'Manual' browser command has been chosen, but no command has been set."), NULL, GAIM_ERROR); - return; - } - - space_free_url = g_strdelimit(url, " ", '+'); - command = g_strdup_printf("%s %s", web_command, space_free_url); - g_free(space_free_url); - } break; + execvp(args[0], args); + _exit(0); + } } - - if (g_spawn_command_line_async(command, &error) == FALSE) { - char *tmp = g_strdup_printf(_("There was an error launching your chosen browser: %s"), error->message); - do_error_dialog(tmp, NULL, GAIM_ERROR); - g_free(tmp); - g_error_free(error); - } - - g_free(command); } void add_bookmark(GtkWidget *w, char *url) { if (web_browser == BROWSER_NETSCAPE) { - char *command = g_strdup_printf("AddBookmark(%s)", url); + char *command = g_malloc(1024); + + g_snprintf(command, 1024, "AddBookmark(%s)", url); netscape_command(command); g_free(command);
--- a/src/gaimrc.c Sun Jan 26 20:41:49 2003 +0000 +++ b/src/gaimrc.c Sun Jan 26 20:43:25 2003 +0000 @@ -820,8 +820,8 @@ } /* this is where we do bugs and compatibility stuff */ - if (!(sound_options & (OPT_SOUND_BEEP | OPT_SOUND_NORMAL | OPT_SOUND_CMD))) - sound_options |= OPT_SOUND_NORMAL; + if (!(sound_options & (OPT_SOUND_BEEP | OPT_SOUND_ESD | OPT_SOUND_NORMAL | OPT_SOUND_NAS | OPT_SOUND_ARTSC | OPT_SOUND_CMD))) + sound_options |= OPT_SOUND_ESD | OPT_SOUND_NORMAL | OPT_SOUND_NAS | OPT_SOUND_ARTSC; if (conv_size.width == 0 && conv_size.height == 0 && @@ -1244,7 +1244,10 @@ OPT_SOUND_RECV | OPT_SOUND_SEND | OPT_SOUND_SILENT_SIGNON | - OPT_SOUND_NORMAL; + OPT_SOUND_NORMAL | + OPT_SOUND_NAS | + OPT_SOUND_ARTSC | + OPT_SOUND_ESD; #ifdef USE_SCREENSAVER report_idle = IDLE_SCREENSAVER;
--- a/src/prefs.c Sun Jan 26 20:41:49 2003 +0000 +++ b/src/prefs.c Sun Jan 26 20:43:25 2003 +0000 @@ -956,12 +956,19 @@ #ifndef _WIN32 vbox = make_frame (ret, _("Sound Method")); dd = gaim_dropdown(vbox, _("_Method"), &sound_options, OPT_SOUND_BEEP | - OPT_SOUND_NORMAL | + OPT_SOUND_ESD | OPT_SOUND_ARTSC | OPT_SOUND_NAS | OPT_SOUND_NORMAL | OPT_SOUND_CMD, _("Console beep"), OPT_SOUND_BEEP, -#ifdef USE_AO - _("Automatic"), OPT_SOUND_NORMAL, +#ifdef ESD_SOUND + "ESD", OPT_SOUND_ESD, #endif +#ifdef ARTSC_SOUND + "ArtsC", OPT_SOUND_ARTSC, +#endif +#ifdef NAS_SOUND + "NAS", OPT_SOUND_NAS, +#endif + _("Internal"), OPT_SOUND_NORMAL, _("Command"), OPT_SOUND_CMD, NULL); gtk_size_group_add_widget(sg, dd); gtk_misc_set_alignment(GTK_MISC(dd), 0, 0);
--- a/src/sound.c Sun Jan 26 20:41:49 2003 +0000 +++ b/src/sound.c Sun Jan 26 20:43:25 2003 +0000 @@ -40,10 +40,17 @@ #include <sys/types.h> #include <sys/stat.h> -#ifdef USE_AO -#include <ao/ao.h> -#include <audiofile.h> -#endif /* USE_AO */ +#ifdef ESD_SOUND +#include <esd.h> +#endif + +#ifdef ARTSC_SOUND +#include <artsc.h> +#endif + +#ifdef NAS_SOUND +#include <audio/audiolib.h> +#endif #include "gaim.h" @@ -51,10 +58,6 @@ #include "win32dep.h" #endif -#ifdef USE_AO -static gboolean ao_initialized = FALSE; -#endif /* USE_AO */ - gboolean mute_sounds = 0; /* description, option bit, default sound file * @@ -76,109 +79,370 @@ {N_("Someone says your name in chat"), OPT_SOUND_CHAT_NICK, "redalert.wav"} }; +#ifndef _WIN32 +static int check_dev(char *dev) +{ + struct stat stat_buf; + uid_t user = getuid(); + gid_t group = getgid(), other_groups[32]; + int i, numgroups; + + if ((numgroups = getgroups(32, other_groups)) == -1) + return 0; + if (stat(dev, &stat_buf)) + return 0; + if (user == stat_buf.st_uid && stat_buf.st_mode & S_IWUSR) + return 1; + if (stat_buf.st_mode & S_IWGRP) { + if (group == stat_buf.st_gid) + return 1; + for (i = 0; i < numgroups; i++) + if (other_groups[i] == stat_buf.st_gid) + return 1; + } + if (stat_buf.st_mode & S_IWOTH) + return 1; + return 0; +} + +static void play_audio_file(char *file) +{ + /* here we can assume that we can write to /dev/audio */ + char *buf; + struct stat info; + int fd = open(file, O_RDONLY); + if (fd <= 0) { + return; + } + fstat(fd, &info); + if (info.st_size < 24) + return; + buf = malloc(info.st_size + 1); + read(fd, buf, 24); + read(fd, buf, info.st_size - 24); + close(fd); + + fd = open("/dev/audio", O_WRONLY | O_EXCL | O_NDELAY); + if (fd < 0) { + free(buf); + return; + } + write(fd, buf, info.st_size - 24); + free(buf); + close(fd); +} + +static int can_play_audio() +{ + return check_dev("/dev/audio"); +} + +#ifdef ESD_SOUND + +int esd_fd; + +static int can_play_esd() +{ + esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; + + esd_fd = esd_play_stream(format, 8012, NULL, "gaim"); + + if (esd_fd < 0) { + return 0; + } + + return 1; +} + +#endif /* ESD_SOUND */ + +#ifdef ARTSC_SOUND + +/* +** This routine converts from ulaw to 16 bit linear. +** +** Craig Reese: IDA/Supercomputing Research Center +** 29 September 1989 +** +** References: +** 1) CCITT Recommendation G.711 (very difficult to follow) +** 2) MIL-STD-188-113,"Interoperability and Performance Standards +** for Analog-to_Digital Conversion Techniques," +** 17 February 1987 +** +** Input: 8 bit ulaw sample +** Output: signed 16 bit linear sample +** Z-note -- this is from libaudiofile. Thanks guys! +*/ + +static int _af_ulaw2linear(unsigned char ulawbyte) +{ + static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 }; + int sign, exponent, mantissa, sample; + + ulawbyte = ~ulawbyte; + sign = (ulawbyte & 0x80); + exponent = (ulawbyte >> 4) & 0x07; + mantissa = ulawbyte & 0x0F; + sample = exp_lut[exponent] + (mantissa << (exponent + 3)); + if (sign != 0) + sample = -sample; + + return (sample); +} + +static int play_artsc(unsigned char *data, int size) +{ + arts_stream_t stream; + guint16 *lineardata; + int result = 1; + int error; + int i; + + lineardata = g_malloc(size * 2); + + for (i = 0; i < size; i++) { + lineardata[i] = _af_ulaw2linear(data[i]); + } + + stream = arts_play_stream(8012, 16, 1, "gaim"); + + error = arts_write(stream, lineardata, size); + if (error < 0) { + result = 0; + } + + arts_close_stream(stream); + + g_free(lineardata); + + arts_free(); + + return result; +} + +static int can_play_artsc() +{ + int error; + + error = arts_init(); + if (error < 0) + return 0; + + return 1; +} + +static int artsc_play_file(char *file) +{ + struct stat stat_buf; + unsigned char *buf = NULL; + int result = 0; + int fd = -1; + + if (!can_play_artsc()) + return 0; + + fd = open(file, O_RDONLY); + if (fd < 0) + return 0; + + if (fstat(fd, &stat_buf)) { + close(fd); + return 0; + } + + if (!stat_buf.st_size) { + close(fd); + return 0; + } + + buf = g_malloc(stat_buf.st_size); + if (!buf) { + close(fd); + return 0; + } + + if (read(fd, buf, stat_buf.st_size) < 0) { + g_free(buf); + close(fd); + return 0; + } + + result = play_artsc(buf, stat_buf.st_size); + + g_free(buf); + close(fd); + return result; +} + +#endif /* ARTSC_SOUND */ + +#ifdef NAS_SOUND + +char nas_server[] = "localhost"; +AuServer *nas_serv = NULL; + +static AuBool NasEventHandler(AuServer * aud, AuEvent * ev, AuEventHandlerRec * handler) +{ + AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev; + + if (ev->type == AuEventTypeElementNotify) { + switch (event->kind) { + case AuElementNotifyKindState: + switch (event->cur_state) { + case AuStateStop: + _exit(0); + } + break; + } + } + return AuTrue; +} + + +static int play_nas(unsigned char *data, int size) +{ + AuDeviceID device = AuNone; + AuFlowID flow; + AuElement elements[3]; + int i, n, w; + + /* look for an output device */ + for (i = 0; i < AuServerNumDevices(nas_serv); i++) { + if ((AuDeviceKind(AuServerDevice(nas_serv, i)) == + AuComponentKindPhysicalOutput) && + AuDeviceNumTracks(AuServerDevice(nas_serv, i)) == 1) { + device = AuDeviceIdentifier(AuServerDevice(nas_serv, i)); + break; + } + } + + if (device == AuNone) + return 0; + + if (!(flow = AuCreateFlow(nas_serv, NULL))) + return 0; + + + AuMakeElementImportClient(&elements[0], 8012, AuFormatULAW8, 1, AuTrue, size, size / 2, 0, NULL); + AuMakeElementExportDevice(&elements[1], 0, device, 8012, AuUnlimitedSamples, 0, NULL); + AuSetElements(nas_serv, flow, AuTrue, 2, elements, NULL); + + AuStartFlow(nas_serv, flow, NULL); + + AuWriteElement(nas_serv, flow, 0, size, data, AuTrue, NULL); + + AuRegisterEventHandler(nas_serv, AuEventHandlerIDMask, 0, flow, NasEventHandler, NULL); + + while (1) { + AuHandleEvents(nas_serv); + } + + return 1; +} + +static int can_play_nas() +{ + if ((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) + return 1; + return 0; +} + +static int play_nas_file(char *file) +{ + struct stat stat_buf; + char *buf; + int ret; + int fd = open(file, O_RDONLY); + if (fd <= 0) + return 0; + + if (!can_play_nas()) + return 0; + + if (stat(file, &stat_buf)) + return 0; + + if (!stat_buf.st_size) + return 0; + + buf = malloc(stat_buf.st_size); + read(fd, buf, stat_buf.st_size); + ret = play_nas(buf, stat_buf.st_size); + free(buf); + return ret; +} + +#endif /* NAS_SOUND */ + +#endif /* !_WIN32 */ + void play_file(char *filename) { #ifndef _WIN32 -#ifdef USE_AO - int ao_driver; -#endif /* USE_AO */ - pid_t pid; + int pid; #endif - if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY)) return; /* check here in case a buddy pounce plays a file while away */ - + if (sound_options & OPT_SOUND_BEEP) { gdk_beep(); return; } -#ifndef _WIN32 - if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { - gchar *tmp = g_strdup_printf(_("Unable to play sound because the chosen filename (%s) does not exist."), filename); - do_error_dialog(tmp, NULL, GAIM_ERROR); - g_free(tmp); - return; + else if (sound_options & OPT_SOUND_NORMAL) { + debug_printf("attempting to play audio file with internal method -- this is unlikely to work\n"); } - - if (sound_options & OPT_SOUND_CMD) { - gchar *command = NULL; - GError *error = NULL; - - if (!sound_cmd[0]) { - do_error_dialog(_("Unable to play sound because the 'Command' sound method has been chosen, but no command has been set."), NULL, GAIM_ERROR); - return; - } - - command = g_strdup_printf(sound_cmd, filename); - - if (g_spawn_command_line_async(command, &error) == FALSE) { - gchar *tmp = g_strdup_printf(_("Unable to play sound because the configured sound command could not be launched: %s"), error->message); - do_error_dialog(tmp, NULL, GAIM_ERROR); - g_free(tmp); - g_error_free(error); - } - - g_free(command); - return; - } - -#ifdef USE_AO - if (!ao_initialized) { - ao_initialize(); - } - - ao_driver = ao_default_driver_id(); - - if (ao_driver == -1) { - do_error_dialog(_("Unable to play sound because no suitable driver could be found."), NULL, GAIM_ERROR); - return; - } - +#ifndef _WIN32 pid = fork(); if (pid < 0) return; else if (pid == 0) { - AFfilehandle file = afOpenFile(filename, "rb", NULL); - if(file) { - ao_device *device; - ao_sample_format format; - - int in_fmt; - int bytes_per_frame; + alarm(30); + + if ((sound_options & OPT_SOUND_CMD) && sound_cmd[0]) { + char *args[4]; + char command[4096]; - format.rate = afGetRate(file, AF_DEFAULT_TRACK); - format.channels = afGetChannels(file, AF_DEFAULT_TRACK); - afGetSampleFormat(file, AF_DEFAULT_TRACK, &in_fmt, - &format.bits); - - bytes_per_frame = format.bits * format.channels / 8; - - device = ao_open_live(ao_driver, &format, NULL); + g_snprintf(command, sizeof(command), sound_cmd, filename); - if (device) { - int frames_read; - char buf[4096]; - int buf_frames = sizeof(buf) / bytes_per_frame; + args[0] = "sh"; + args[1] = "-c"; + args[2] = command; + args[3] = NULL; + execvp(args[0], args); + _exit(0); + } +#ifdef ESD_SOUND + else if (sound_options & OPT_SOUND_ESD) { + if (esd_play_file(NULL, filename, 1)) + _exit(0); + } +#endif - while((frames_read = afReadFrames(file, AF_DEFAULT_TRACK, - buf, buf_frames))) { - if(!ao_play(device, buf, frames_read * bytes_per_frame)) - break; - } - ao_close(device); - } +#ifdef ARTSC_SOUND + else if (sound_options & OPT_SOUND_ARTSC) { + if (artsc_play_file(filename)) + _exit(0); + } +#endif - ao_shutdown(); - afCloseFile(file); +#ifdef NAS_SOUND + else if (sound_options & OPT_SOUND_NAS) { + if (play_nas_file(filename)) + _exit(0); } +#endif + + else if ((sound_options & OPT_SOUND_NORMAL) && + can_play_audio()) { + play_audio_file(filename); + _exit(0); + } + _exit(0); } -#else /* USE_AO */ - gdk_beep(); -#endif /* USE_AO */ - #else /* _WIN32 */ debug_printf("Playing %s\n", filename); if (!PlaySound(filename, 0, SND_ASYNC | SND_FILENAME)) @@ -186,21 +450,13 @@ #endif } -void sound_quit() { -#ifdef USE_AO - if (ao_initialized) { - ao_shutdown(); - } -#endif -} - extern int logins_not_muted; void play_sound(int sound) { if (mute_sounds) return; - + if ((sound == SND_BUDDY_ARRIVE) && !logins_not_muted) return;