Mercurial > pidgin
changeset 1006:0a4d0ed65e17
[gaim-migrate @ 1016]
wow, configurable sounds. this should be neat. too bad the UI isn't done yet. but at least you can have them configured. oh yeah, this means we don't need gaim.soundlist anymore, since i removed the option to go through gnome for sounds. (there were only two advantages to having them go through gnome, and making them configurable was the primary one). anyway, i also changed some of the installation script stuff so that now everything (including the panel) should go through the $(whateverdir) makefile variables, so it should be easier to make packages in chrooted environments
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 19 Oct 2000 10:42:46 +0000 |
parents | b1572ac4246c |
children | 3fd7b1e320d1 |
files | Makefile.am pixmaps/Makefile.am sounds/Makefile.am src/buddy_chat.c src/gaim.h src/gaimrc.c src/prefs.c src/server.c src/sound.c |
diffstat | 9 files changed, 287 insertions(+), 128 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.am Thu Oct 19 00:59:20 2000 +0000 +++ b/Makefile.am Thu Oct 19 10:42:46 2000 +0000 @@ -34,13 +34,16 @@ endif -if GNOMEBITS - -bitssysconf = `@GNOME_CONFIG@ --sysconfdir` -bitssounddir = $(bitssysconf)/sound/events -bitssound_DATA = gaim.soundlist - -endif +# we used to have gnome-configurable sound events, but now we can configure them +# ourselves. isn't that lovely +# +#if GNOMEBITS +# +#bitssysconf = `@GNOME_CONFIG@ --sysconfdir` +#bitssounddir = $(bitssysconf)/sound/events +#bitssound_DATA = gaim.soundlist +# +#endif pixmapdir = $(datadir)/gnome/apps/Internet pixmap_DATA = gaim.desktop
--- a/pixmaps/Makefile.am Thu Oct 19 00:59:20 2000 +0000 +++ b/pixmaps/Makefile.am Thu Oct 19 10:42:46 2000 +0000 @@ -111,25 +111,7 @@ pixmap_DATA = gaim.xpm if GNOMEAPPLET -#gnomesysconf = `@GNOME_CONFIG@ --sysconfdir` gnomedata = `@GNOME_CONFIG@ --datadir` gaimpixmapdir = $(gnomedata)/pixmaps gaimpixmap_DATA = gaim.xpm -gaimgnomedir = $(gnomedata)/pixmaps/gaim/gnome -#gaimgnome_DATA = -#gaimgnomepixmapsdir = $(gnomedata)/pixmaps/gaim -#gaimgnomepixmaps_DATA = gnome/penguin-online.png gnome/penguin-offline.png \ -# gnome/penguin-connect.png gnome/devil-offline.png \ -# gnome/devil-connect.png gnome/devil-online.png endif - -if DISTRIB -pixmapdistribdir = $(datadir)/pixmaps -pixmapdistrib_DATA = gaim.xpm -#gnomedistribdir = $(datadir)/pixmaps/gaim/gnome -#gnomedistrib_DATA = -#gnomepixmapdistribdir = $(datadir)/pixmaps/gaim -#gnomepixmapdistrib_DATA = gnome/penguin-online.png gnome/penguin-offline.png \ -# gnome/penguin-connect.png gnome/devil-offline.png \ -# gnome/devil-connect.png gnome/devil-online.png -endif
--- a/sounds/Makefile.am Thu Oct 19 00:59:20 2000 +0000 +++ b/sounds/Makefile.am Thu Oct 19 10:42:46 2000 +0000 @@ -21,19 +21,19 @@ Receive.h: au2h Receive.au ./au2h Receive.au Receive.h -if GNOMEAPPLET -gnomedata = `@GNOME_CONFIG@ --datadir` -gaimsoundsdir = $(gnomedata)/sounds/gaim -gaimsounds_DATA = $(EXTRA_DIST) -endif - -if DISTRIB -gaimdistribdir = $(datadir)/sounds/gaim -gaimdistrib_DATA = $(EXTRA_DIST) -endif - -if GNOMEBITS -bitsdata = `@GNOME_CONFIG@ --datadir` -bitssoundsdir = $(bitsdata)/sounds/gaim -bitssounds_DATA = $(EXTRA_DIST) -endif +#if GNOMEAPPLET +#gnomedata = `@GNOME_CONFIG@ --datadir` +#gaimsoundsdir = $(gnomedata)/sounds/gaim +#gaimsounds_DATA = $(EXTRA_DIST) +#endif +# +#if DISTRIB +#gaimdistribdir = $(datadir)/sounds/gaim +#gaimdistrib_DATA = $(EXTRA_DIST) +#endif +# +#if GNOMEBITS +#bitsdata = `@GNOME_CONFIG@ --datadir` +#bitssoundsdir = $(bitsdata)/sounds/gaim +#bitssounds_DATA = $(EXTRA_DIST) +#endif
--- a/src/buddy_chat.c Thu Oct 19 00:59:20 2000 +0000 +++ b/src/buddy_chat.c Thu Oct 19 10:42:46 2000 +0000 @@ -340,12 +340,12 @@ if (!strcasecmp(str, normalize(b->gc->username))) { sprintf(debug_buff, "%s %s\n", normalize(who), normalize(b->gc->username)); debug_print(debug_buff); - if (b->makesound && (sound_options & OPT_SOUND_CHAT_SAY)) - play_sound(SEND); + if (b->makesound && (sound_options & OPT_SOUND_CHAT_YOU_SAY)) + play_sound(CHAT_YOU_SAY); flag |= WFLAG_SEND; } else { if (b->makesound && (sound_options & OPT_SOUND_CHAT_SAY)) - play_sound(RECEIVE); + play_sound(CHAT_SAY); flag |= WFLAG_RECV; } g_free(str); @@ -440,7 +440,7 @@ update_chat_list(b); if (b->makesound && (sound_options & OPT_SOUND_CHAT_JOIN)) - play_sound(BUDDY_ARRIVE); + play_sound(CHAT_JOIN); if (display_options & OPT_DISP_CHAT_LOGON) { g_snprintf(tmp, sizeof(tmp), _("<B>%s entered the room.</B>"), name); @@ -467,8 +467,8 @@ names = names->next; } - if (b->makesound && (sound_options & OPT_SOUND_CHAT_JOIN)) - play_sound(BUDDY_LEAVE); + if (b->makesound && (sound_options & OPT_SOUND_CHAT_PART)) + play_sound(CHAT_LEAVE); if (display_options & OPT_DISP_CHAT_LOGON) { g_snprintf(tmp, sizeof(tmp), _("<B>%s left the room.</B>"), buddy);
--- a/src/gaim.h Thu Oct 19 00:59:20 2000 +0000 +++ b/src/gaim.h Thu Oct 19 10:42:46 2000 +0000 @@ -438,10 +438,14 @@ #define BUDDY_ARRIVE 0 #define BUDDY_LEAVE 1 -#define SEND 2 -#define RECEIVE 3 -#define FIRST_RECEIVE 4 -#define AWAY 5 +#define RECEIVE 2 +#define FIRST_RECEIVE 3 +#define SEND 4 +#define CHAT_JOIN 5 +#define CHAT_LEAVE 6 +#define CHAT_YOU_SAY 7 +#define CHAT_SAY 8 +#define NUM_SOUNDS 9 #ifdef USE_APPLET @@ -543,6 +547,9 @@ #define OPT_SOUND_CHAT_JOIN 0x00000100 #define OPT_SOUND_CHAT_SAY 0x00000200 #define OPT_SOUND_BEEP 0x00000400 +#define OPT_SOUND_CHAT_PART 0x00000800 +#define OPT_SOUND_CHAT_YOU_SAY 0x00001000 +extern char *sound_file[NUM_SOUNDS]; extern int font_options; #define OPT_FONT_BOLD 0x00000001
--- a/src/gaimrc.c Thu Oct 19 00:59:20 2000 +0000 +++ b/src/gaimrc.c Thu Oct 19 10:42:46 2000 +0000 @@ -52,6 +52,7 @@ char login_host[512]; int login_port; char latest_ver[25]; +char *sound_file[NUM_SOUNDS]; struct parse { char option[256]; @@ -149,6 +150,8 @@ return 4; } else if (!strcmp(tag, "chat")) { return 5; + } else if (!strcmp(tag, "sound_files")) { + return 6; } return -1; @@ -666,6 +669,49 @@ } +static void gaimrc_read_sounds(FILE *f) +{ + int i; + char buf[2048]; + struct parse *p; + + buf[0] = 0; + + for (i = 0; i < NUM_SOUNDS; i++) + sound_file[i] = NULL; + + while (buf[0] != '}') { + if (buf[0] == '#') + continue; + + if (!fgets(buf, sizeof(buf), f)) + return; + + p = parse_line(buf); + + sscanf(p->option, "sound%c", &i); + i -= 'A'; + + if (p->value[0][0]) + sound_file[i] = g_strdup(p->value[0]); + else + sound_file[i] = NULL; + } +} + +static void gaimrc_write_sounds(FILE *f) +{ + int i; + fprintf(f, "sound_files {\n"); + for (i = 0; i < NUM_SOUNDS; i++) + if (sound_file[i]) + fprintf(f, "\tsound%c { %s }\n", i + 'A', sound_file[i]); + else + fprintf(f, "\tsound%c { }\n", i + 'A'); + fprintf(f, "}\n"); +} + + void set_defaults(int saveinfo) { if (!saveinfo) @@ -709,6 +755,9 @@ if (!saveinfo) { + int i; + for (i = 0; i < 7; i++) + sound_file[i] = NULL; font_options = 0; sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND | OPT_SOUND_SILENT_SIGNON; report_idle = IDLE_GAIM; @@ -777,6 +826,9 @@ case 5: gaimrc_read_chat(f); break; + case 6: + gaimrc_read_sounds(f); + break; default: /* NOOP */ break; @@ -803,6 +855,7 @@ fprintf(f, "# .gaimrc v%d\n", 3); gaimrc_write_users(f); gaimrc_write_options(f); + gaimrc_write_sounds(f); gaimrc_write_away(f); #ifdef GAIM_PLUGINS gaimrc_write_plugins(f);
--- a/src/prefs.c Thu Oct 19 00:59:20 2000 +0000 +++ b/src/prefs.c Thu Oct 19 10:42:46 2000 +0000 @@ -1305,9 +1305,6 @@ gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); gtk_widget_show(label); -#ifdef USE_GNOME - gaim_button(_("Sounds go through GNOME"), &sound_options, OPT_SOUND_THROUGH_GNOME, box); -#endif gaim_button(_("No sounds when you log in"), &sound_options, OPT_SOUND_SILENT_SIGNON, box); gaim_button(_("Sounds while away"), &sound_options, OPT_SOUND_WHEN_AWAY, box); gaim_button(_("Beep instead of playing sound"), &sound_options, OPT_SOUND_BEEP, box); @@ -1315,6 +1312,39 @@ gtk_widget_show(prefdialog); } +static GtkWidget *sndent[NUM_SOUNDS]; + +static void sel_sound(GtkWidget *button, int snd) { + do_error_dialog("This isn't implemented yet! Ain't that a pisser? That's what you get for using CVS, I guess. So you have two options now: 1. Implement it yourself (this message should be pretty damn easy to find in the code), or 2. Hand-edit ~/.gaimrc. I suggest 2.", "Implement me!"); +} + +static void sound_entry(char *label, int opt, GtkWidget *box, int snd) { + GtkWidget *hbox; + GtkWidget *entry; + GtkWidget *button; + + hbox = gtk_hbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); + gtk_widget_show(hbox); + + gaim_button(label, &sound_options, opt, hbox); + + button = gtk_button_new_with_label(_("Choose")); + gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); + gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(sel_sound), (void *)snd); + gtk_widget_show(button); + + entry = gtk_entry_new(); + gtk_entry_set_editable(GTK_ENTRY(entry), FALSE); + if (sound_file[snd]) + gtk_entry_set_text(GTK_ENTRY(entry), sound_file[snd]); + else + gtk_entry_set_text(GTK_ENTRY(entry), "(default)"); + gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); + sndent[snd] = entry; + gtk_widget_show(entry); +} + static void event_page() { GtkWidget *parent; @@ -1336,23 +1366,25 @@ gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 5); gtk_widget_show(label); - gaim_button(_("Sound when buddy logs in"), &sound_options, OPT_SOUND_LOGIN, box); - gaim_button(_("Sound when buddy logs out"), &sound_options, OPT_SOUND_LOGOUT, box); + sound_entry(_("Sound when buddy logs in"), OPT_SOUND_LOGIN, box, BUDDY_ARRIVE); + sound_entry(_("Sound when buddy logs out"), OPT_SOUND_LOGOUT, box, BUDDY_LEAVE); sep = gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 5); gtk_widget_show(sep); - gaim_button(_("Sound when message is received"), &sound_options, OPT_SOUND_RECV, box); - gaim_button(_("Sound when message is first received"), &sound_options, OPT_SOUND_FIRST_RCV, box); - gaim_button(_("Sound when message is sent"), &sound_options, OPT_SOUND_SEND, box); + sound_entry(_("Sound when message is received"), OPT_SOUND_RECV, box, RECEIVE); + sound_entry(_("Sound when message is first received"), OPT_SOUND_FIRST_RCV, box, FIRST_RECEIVE); + sound_entry(_("Sound when message is sent"), OPT_SOUND_SEND, box, SEND); sep = gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX(box), sep, FALSE, FALSE, 5); gtk_widget_show(sep); - gaim_button(_("Sound in chat rooms when people enter/leave"), &sound_options, OPT_SOUND_CHAT_JOIN, box); - gaim_button(_("Sound in chat rooms when people talk"), &sound_options, OPT_SOUND_CHAT_SAY, box); + sound_entry(_("Sound in chat rooms when people enter"), OPT_SOUND_CHAT_JOIN, box, CHAT_JOIN); + sound_entry(_("Sound in chat rooms when people leave"), OPT_SOUND_CHAT_PART, box, CHAT_LEAVE); + sound_entry(_("Sound in chat rooms when you talk"), OPT_SOUND_CHAT_YOU_SAY, box, CHAT_YOU_SAY); + sound_entry(_("Sound in chat rooms when others talk"), OPT_SOUND_CHAT_SAY, box, CHAT_SAY); gtk_widget_show(prefdialog); }
--- a/src/server.c Thu Oct 19 00:59:20 2000 +0000 +++ b/src/server.c Thu Oct 19 10:42:46 2000 +0000 @@ -144,7 +144,7 @@ * the buddy list/UI needs to be really changed before this gets fixed*/ struct gaim_connection *g = connections->data; - if (g->prpl && g->prpl->get_info) + if (g && g->prpl && g->prpl->get_info) (*g->prpl->get_info)(g, name); } @@ -153,7 +153,7 @@ /* FIXME: see the serv_get_info comment above :-P */ struct gaim_connection *g = connections->data; - if (g->prpl && g->prpl->get_info) + if (g && g->prpl && g->prpl->get_info) (*g->prpl->get_away_msg)(g, name); } @@ -162,7 +162,7 @@ /* FIXME: see the serv_get_info comment above :-P */ struct gaim_connection *g = connections->data; - if (g->prpl && g->prpl->get_dir) + if (g && g->prpl && g->prpl->get_dir) (*g->prpl->get_dir)(g, name); } @@ -172,7 +172,7 @@ /* FIXME */ struct gaim_connection *g = connections->data; - if (g->prpl && g->prpl->set_dir) + if (g && g->prpl && g->prpl->set_dir) (*g->prpl->set_dir)(g, first, middle, last, maiden, city, state, country, web); } @@ -182,7 +182,7 @@ /* FIXME */ struct gaim_connection *g = connections->data; - if (g->prpl && g->prpl->dir_search) + if (g && g->prpl && g->prpl->dir_search) (*g->prpl->dir_search)(g, first, middle, last, maiden, city, state, country, email); } @@ -277,7 +277,7 @@ { /* FIXME */ struct gaim_connection *g = connections->data; - if (g->protocol == PROTO_TOC) { + if (g && g->protocol == PROTO_TOC) { char buf[MSG_LEN]; int at; GList *list; @@ -392,7 +392,7 @@ { /* FIXME */ struct gaim_connection *g = connections->data; - if (g->protocol == PROTO_TOC) { + if (g && g->protocol == PROTO_TOC) { char *buf = g_malloc(BUF_LONG); char *buf2 = g_malloc(MSG_LEN); serv_build_config(buf, BUF_LONG / 2, FALSE); @@ -486,7 +486,7 @@ } if (cnv != NULL) { if (sound_options & OPT_SOUND_WHEN_AWAY) - play_sound(AWAY); + play_sound(RECEIVE); write_to_conv(cnv, message, away | WFLAG_RECV, NULL); }
--- a/src/sound.c Thu Oct 19 00:59:20 2000 +0000 +++ b/src/sound.c Thu Oct 19 10:42:46 2000 +0000 @@ -86,6 +86,29 @@ close(fd); } +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); + 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); + if (fd < 0) + return; + write(fd, buf, info.st_size - 24); + free(buf); + close(fd); +} + static int can_play_audio() { return check_dev("/dev/audio"); @@ -147,6 +170,16 @@ } +static int play_esd_file(char *file) +{ + int esd_stat; + int fd = open(file, O_RDONLY); + if (fd <= 0) + return 0; + esd_stat = esd_play_file(NULL, file, 1); + return esd_stat; +} + static int can_play_esd() { esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; @@ -239,6 +272,42 @@ #endif +void play_file(char *filename) { + int pid; + +#ifdef _WIN32 + return; +#endif + + pid = fork(); + + if (pid < 0) + return; + else if (pid == 0) { + if (sound_options & OPT_SOUND_BEEP) { + printf("\a"); + fflush(stdout); + _exit(0); + } + +#ifdef ESD_SOUND + if (play_esd_file(filename)) + _exit(0); +#endif + + /* FIXME : NAS (does anyone use this?) */ + + if (can_play_audio()) { + play_audio_file(filename); + _exit(0); + } + + _exit(0); + } else { + gtk_timeout_add(100, (GtkFunction)clean_pid, NULL); + } +} + void play(unsigned char *data, int size) { int pid; @@ -289,78 +358,91 @@ extern int logins_not_muted; -#ifdef USE_GNOME -void gnome_play_sound(int sound) -#else void play_sound(int sound) -#endif { switch(sound) { case BUDDY_ARRIVE: - if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted) - play(BuddyArrive, sizeof(BuddyArrive)); + if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted) { + if (sound_file[BUDDY_ARRIVE]) { + play_file(sound_file[BUDDY_ARRIVE]); + } else { + play(BuddyArrive, sizeof(BuddyArrive)); + } + } break; case BUDDY_LEAVE: - if (sound_options & OPT_SOUND_LOGOUT) - play(BuddyLeave, sizeof(BuddyLeave)); + if (sound_options & OPT_SOUND_LOGOUT) { + if (sound_file[BUDDY_LEAVE]) { + play_file(sound_file[BUDDY_LEAVE]); + } else { + play(BuddyLeave, sizeof(BuddyLeave)); + } + } + break; + case FIRST_RECEIVE: + if (sound_options & OPT_SOUND_FIRST_RCV) { + if (sound_file[FIRST_RECEIVE]) { + play_file(sound_file[FIRST_RECEIVE]); + } else { + play(Receive, sizeof(Receive)); + } + } + break; + case RECEIVE: + if (sound_options & OPT_SOUND_RECV) { + if (sound_file[RECEIVE]) { + play_file(sound_file[RECEIVE]); + } else { + play(Receive, sizeof(Receive)); + } + } break; case SEND: - if (sound_options & OPT_SOUND_SEND) - play(Send, sizeof(Send)); + if (sound_options & OPT_SOUND_SEND) { + if (sound_file[SEND]) { + play_file(sound_file[SEND]); + } else { + play(Send, sizeof(Send)); + } + } break; - case FIRST_RECEIVE: - if (sound_options & OPT_SOUND_FIRST_RCV) - play(Receive, sizeof(Receive)); + case CHAT_JOIN: + if (sound_options & OPT_SOUND_CHAT_JOIN) { + if (sound_file[CHAT_JOIN]) { + play_file(sound_file[CHAT_JOIN]); + } else { + play(BuddyArrive, sizeof(BuddyArrive)); + } + } break; - case RECEIVE: - if (sound_options & OPT_SOUND_RECV) - play(Receive, sizeof(Receive)); + case CHAT_LEAVE: + if (sound_options & OPT_SOUND_CHAT_PART) { + if (sound_file[CHAT_LEAVE]) { + play_file(sound_file[CHAT_LEAVE]); + } else { + play(BuddyLeave, sizeof(BuddyLeave)); + } + } break; - case AWAY: - if (sound_options & OPT_SOUND_WHEN_AWAY) - play(Receive, sizeof(Receive)); + case CHAT_YOU_SAY: + if (sound_options & OPT_SOUND_CHAT_YOU_SAY) { + if (sound_file[CHAT_YOU_SAY]) { + play_file(sound_file[CHAT_YOU_SAY]); + } else { + play(Send, sizeof(Send)); + } + } + break; + case CHAT_SAY: + if (sound_options & OPT_SOUND_CHAT_SAY) { + if (sound_file[CHAT_SAY]) { + play_file(sound_file[CHAT_SAY]); + } else { + play(Receive, sizeof(Receive)); + } + } break; } } -#ifdef USE_GNOME - -#include <gnome.h> -void play_sound(int sound) -{ - - if (!(sound_options & OPT_SOUND_THROUGH_GNOME)) { - gnome_play_sound(sound); - return; - } - - switch(sound) { - case BUDDY_ARRIVE: - if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted) - gnome_triggers_do("", "program", "gaim", "login", NULL); - break; - case BUDDY_LEAVE: - if (sound_options & OPT_SOUND_LOGOUT) - gnome_triggers_do("", "program", "gaim", "leave", NULL); - break; - case SEND: - if (sound_options & OPT_SOUND_SEND) - gnome_triggers_do("", "program", "gaim", "send", NULL); - break; - case FIRST_RECEIVE: - if (sound_options & OPT_SOUND_FIRST_RCV) - gnome_triggers_do("", "program", "gaim", "recv", NULL); - break; - case RECEIVE: - if (sound_options & OPT_SOUND_RECV) - gnome_triggers_do("", "program", "gaim", "recv", NULL); - break; - case AWAY: - if (sound_options & OPT_SOUND_WHEN_AWAY) - gnome_triggers_do("", "program", "gaim", "recv", NULL); - break; - } -} - -#endif /* USE_GNOME */