From f6a280e1bb6130bc5fa47d5d992dda2ef8e68bb1 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Thu, 27 Oct 2011 01:18:54 +0200 Subject: [PATCH] =?UTF-8?q?Fonctionne=20@=20home=20mais=20trop=20sp=C3=A9c?= =?UTF-8?q?ifique,=20il=20faut=20ajouter=20des=20fonctions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- C_Language/weechat_plugins/currentsong.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/C_Language/weechat_plugins/currentsong.c b/C_Language/weechat_plugins/currentsong.c index 7470f7e..46843d9 100644 --- a/C_Language/weechat_plugins/currentsong.c +++ b/C_Language/weechat_plugins/currentsong.c @@ -4,6 +4,7 @@ #include #include +#define TAILLE_BUFFER_CURRENT_SONG 100 WEECHAT_PLUGIN_NAME("currentsong"); WEECHAT_PLUGIN_DESCRIPTION("Affiche la musique en cours en utilisant mpc"); WEECHAT_PLUGIN_AUTHOR("Karchnu "); @@ -22,10 +23,17 @@ int cb_currentsong_plugin(void *data, struct t_gui_buffer *buffer, int argc, cha int p[2]; //char local_buffer[100]; char * song; - char * cmd[] = { "mpc", "-h" , "192.168.0.100",(char *)0 }; - song = malloc(200*sizeof(char)); + char affichage[TAILLE_BUFFER_CURRENT_SONG + 10]; + int i; + char * cmd[] = { "mpc", "-h" , "192.168.0.100","current", (char *)0 }; + song = malloc(TAILLE_BUFFER_CURRENT_SONG*sizeof(char)); if(song == NULL) return WEECHAT_RC_ERROR; + for(i = 0 ; i < TAILLE_BUFFER_CURRENT_SONG ; i++) + song[i] = '\0'; + for(i = 0 ; i < TAILLE_BUFFER_CURRENT_SONG + 10 ; i++) + affichage[i] = '\0'; + pipe(p); if(fork() == 0) { @@ -34,15 +42,13 @@ int cb_currentsong_plugin(void *data, struct t_gui_buffer *buffer, int argc, cha dup2(p[1],1); execvp("mpc", cmd); } - close(p[1]); - read(p[0], song, 200); + read(p[0], song, TAILLE_BUFFER_CURRENT_SONG); close(p[0]); - - if(buffer) - weechat_printf (buffer, "J'écoute : %s %s", - weechat_color ("yellow,red"), - song); + sprintf(affichage,"/me ♪ %s", song); + //sprintf(affichage,"/me ♪ %s%s", weechat_color ("_red"), song); // Ne s'affiche pas correctement chez les autres + weechat_utf8_normalize(affichage, '?'); // Pour ne pas avoir de caractères non-lisibles + weechat_command(buffer,affichage); free(song); return WEECHAT_RC_OK;