beep.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. printf("%d\n", len);
  49. if (len > 10) {
  50. p[10] = 0;
  51. strcat(p, "...");
  52. }
  53. sprintf(buf, "notify-send \"vcc\" \"vcc: %s: %s\"", hi->usr, p);
  54. fprintf(stderr, "\a");
  55. system(buf);
  56. free(p);
  57. return HOOK_IGNORE;
  58. }
  59. int beep_init(void) {
  60. register_hook(HOOK_RECV, beep_hook);
  61. return 0;
  62. }