comparison src/sound.c @ 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 88d1edcd7cd6
children d50d3abb9eb7
comparison
equal deleted inserted replaced
1005:b1572ac4246c 1006:0a4d0ed65e17
84 return; 84 return;
85 write(fd, data, size); 85 write(fd, data, size);
86 close(fd); 86 close(fd);
87 } 87 }
88 88
89 static void play_audio_file(char *file)
90 {
91 /* here we can assume that we can write to /dev/audio */
92 char *buf;
93 struct stat info;
94 int fd = open(file, O_RDONLY);
95 if (fd <= 0) {
96 return;
97 }
98 fstat(fd, &info);
99 buf = malloc(info.st_size + 1);
100 read(fd, buf, 24);
101 read(fd, buf, info.st_size - 24);
102 close(fd);
103
104 fd = open("/dev/audio", O_WRONLY | O_EXCL);
105 if (fd < 0)
106 return;
107 write(fd, buf, info.st_size - 24);
108 free(buf);
109 close(fd);
110 }
111
89 static int can_play_audio() 112 static int can_play_audio()
90 { 113 {
91 return check_dev("/dev/audio"); 114 return check_dev("/dev/audio");
92 } 115 }
93 116
145 168
146 return 1; 169 return 1;
147 170
148 } 171 }
149 172
173 static int play_esd_file(char *file)
174 {
175 int esd_stat;
176 int fd = open(file, O_RDONLY);
177 if (fd <= 0)
178 return 0;
179 esd_stat = esd_play_file(NULL, file, 1);
180 return esd_stat;
181 }
182
150 static int can_play_esd() 183 static int can_play_esd()
151 { 184 {
152 esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; 185 esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO;
153 186
154 esd_fd = esd_play_stream(format, 8012, NULL, "gaim"); 187 esd_fd = esd_play_stream(format, 8012, NULL, "gaim");
237 return 0; 270 return 0;
238 } 271 }
239 272
240 #endif 273 #endif
241 274
275 void play_file(char *filename) {
276 int pid;
277
278 #ifdef _WIN32
279 return;
280 #endif
281
282 pid = fork();
283
284 if (pid < 0)
285 return;
286 else if (pid == 0) {
287 if (sound_options & OPT_SOUND_BEEP) {
288 printf("\a");
289 fflush(stdout);
290 _exit(0);
291 }
292
293 #ifdef ESD_SOUND
294 if (play_esd_file(filename))
295 _exit(0);
296 #endif
297
298 /* FIXME : NAS (does anyone use this?) */
299
300 if (can_play_audio()) {
301 play_audio_file(filename);
302 _exit(0);
303 }
304
305 _exit(0);
306 } else {
307 gtk_timeout_add(100, (GtkFunction)clean_pid, NULL);
308 }
309 }
310
242 void play(unsigned char *data, int size) 311 void play(unsigned char *data, int size)
243 { 312 {
244 int pid; 313 int pid;
245 314
246 #ifdef _WIN32 315 #ifdef _WIN32
287 } 356 }
288 } 357 }
289 358
290 extern int logins_not_muted; 359 extern int logins_not_muted;
291 360
292 #ifdef USE_GNOME
293 void gnome_play_sound(int sound)
294 #else
295 void play_sound(int sound) 361 void play_sound(int sound)
296 #endif
297 { 362 {
298 363
299 switch(sound) { 364 switch(sound) {
300 case BUDDY_ARRIVE: 365 case BUDDY_ARRIVE:
301 if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted) 366 if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted) {
302 play(BuddyArrive, sizeof(BuddyArrive)); 367 if (sound_file[BUDDY_ARRIVE]) {
368 play_file(sound_file[BUDDY_ARRIVE]);
369 } else {
370 play(BuddyArrive, sizeof(BuddyArrive));
371 }
372 }
303 break; 373 break;
304 case BUDDY_LEAVE: 374 case BUDDY_LEAVE:
305 if (sound_options & OPT_SOUND_LOGOUT) 375 if (sound_options & OPT_SOUND_LOGOUT) {
306 play(BuddyLeave, sizeof(BuddyLeave)); 376 if (sound_file[BUDDY_LEAVE]) {
377 play_file(sound_file[BUDDY_LEAVE]);
378 } else {
379 play(BuddyLeave, sizeof(BuddyLeave));
380 }
381 }
382 break;
383 case FIRST_RECEIVE:
384 if (sound_options & OPT_SOUND_FIRST_RCV) {
385 if (sound_file[FIRST_RECEIVE]) {
386 play_file(sound_file[FIRST_RECEIVE]);
387 } else {
388 play(Receive, sizeof(Receive));
389 }
390 }
391 break;
392 case RECEIVE:
393 if (sound_options & OPT_SOUND_RECV) {
394 if (sound_file[RECEIVE]) {
395 play_file(sound_file[RECEIVE]);
396 } else {
397 play(Receive, sizeof(Receive));
398 }
399 }
307 break; 400 break;
308 case SEND: 401 case SEND:
309 if (sound_options & OPT_SOUND_SEND) 402 if (sound_options & OPT_SOUND_SEND) {
310 play(Send, sizeof(Send)); 403 if (sound_file[SEND]) {
311 break; 404 play_file(sound_file[SEND]);
312 case FIRST_RECEIVE: 405 } else {
313 if (sound_options & OPT_SOUND_FIRST_RCV) 406 play(Send, sizeof(Send));
314 play(Receive, sizeof(Receive)); 407 }
315 break; 408 }
316 case RECEIVE: 409 break;
317 if (sound_options & OPT_SOUND_RECV) 410 case CHAT_JOIN:
318 play(Receive, sizeof(Receive)); 411 if (sound_options & OPT_SOUND_CHAT_JOIN) {
319 break; 412 if (sound_file[CHAT_JOIN]) {
320 case AWAY: 413 play_file(sound_file[CHAT_JOIN]);
321 if (sound_options & OPT_SOUND_WHEN_AWAY) 414 } else {
322 play(Receive, sizeof(Receive)); 415 play(BuddyArrive, sizeof(BuddyArrive));
416 }
417 }
418 break;
419 case CHAT_LEAVE:
420 if (sound_options & OPT_SOUND_CHAT_PART) {
421 if (sound_file[CHAT_LEAVE]) {
422 play_file(sound_file[CHAT_LEAVE]);
423 } else {
424 play(BuddyLeave, sizeof(BuddyLeave));
425 }
426 }
427 break;
428 case CHAT_YOU_SAY:
429 if (sound_options & OPT_SOUND_CHAT_YOU_SAY) {
430 if (sound_file[CHAT_YOU_SAY]) {
431 play_file(sound_file[CHAT_YOU_SAY]);
432 } else {
433 play(Send, sizeof(Send));
434 }
435 }
436 break;
437 case CHAT_SAY:
438 if (sound_options & OPT_SOUND_CHAT_SAY) {
439 if (sound_file[CHAT_SAY]) {
440 play_file(sound_file[CHAT_SAY]);
441 } else {
442 play(Receive, sizeof(Receive));
443 }
444 }
323 break; 445 break;
324 } 446 }
325 } 447 }
326 448
327 #ifdef USE_GNOME
328
329 #include <gnome.h>
330 void play_sound(int sound)
331 {
332
333 if (!(sound_options & OPT_SOUND_THROUGH_GNOME)) {
334 gnome_play_sound(sound);
335 return;
336 }
337
338 switch(sound) {
339 case BUDDY_ARRIVE:
340 if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted)
341 gnome_triggers_do("", "program", "gaim", "login", NULL);
342 break;
343 case BUDDY_LEAVE:
344 if (sound_options & OPT_SOUND_LOGOUT)
345 gnome_triggers_do("", "program", "gaim", "leave", NULL);
346 break;
347 case SEND:
348 if (sound_options & OPT_SOUND_SEND)
349 gnome_triggers_do("", "program", "gaim", "send", NULL);
350 break;
351 case FIRST_RECEIVE:
352 if (sound_options & OPT_SOUND_FIRST_RCV)
353 gnome_triggers_do("", "program", "gaim", "recv", NULL);
354 break;
355 case RECEIVE:
356 if (sound_options & OPT_SOUND_RECV)
357 gnome_triggers_do("", "program", "gaim", "recv", NULL);
358 break;
359 case AWAY:
360 if (sound_options & OPT_SOUND_WHEN_AWAY)
361 gnome_triggers_do("", "program", "gaim", "recv", NULL);
362 break;
363 }
364 }
365
366 #endif /* USE_GNOME */