beep.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* vcc/plugins/beep/beep.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <vcc/vcc.h>
  22. #include <vcc/pretty.h>
  23. #include <vcc/plugin.h>
  24. #include <vcc/version.h>
  25. int beep_init(void);
  26. struct cmdtable beep_cmdtab[] = {
  27. { NULL, NULL, NULL }
  28. };
  29. struct plugin plg_beep = {
  30. .state = 0,
  31. .name = "beep",
  32. .descr = "Beep when you have a new message. ",
  33. .init = beep_init,
  34. .cmdtab = beep_cmdtab
  35. };
  36. #define this_plg (&plg_beep)
  37. char *beep_hook(struct hook_info *hi) {
  38. char buf[128];
  39. char *p;
  40. int len;
  41. if (unlikely(!(p = strdup(hi->msg)))) {
  42. fprintf(stderr, "*** malloc() failed\n");
  43. return HOOK_FAILED;
  44. }
  45. /* '\n' */
  46. len = strlen(p);
  47. p[len - 1] = 0;
  48. if (len > 10) {
  49. p[10] = 0;
  50. strcat(p, "...");
  51. }
  52. sprintf(buf, "notify-send \"vcc\" \"vcc: %s: %s\"", hi->usr, p);
  53. fprintf(stderr, "\a");
  54. system(buf);
  55. free(p);
  56. return HOOK_IGNORE;
  57. }
  58. int beep_init(void) {
  59. register_hook(HOOK_RECV, beep_hook);
  60. return 0;
  61. }