comparison pidgin-audacious.c @ 11:43cb653de212

paste template has been implemented.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 18 Sep 2008 01:55:32 +0900
parents 7c9624c8a109
children 79f081cdfb19
comparison
equal deleted inserted replaced
10:7c9624c8a109 11:43cb653de212
34 34
35 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak)); 35 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak));
36 36
37 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" 37 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious"
38 38
39 #define OPT_PIDGINAUD "/plugins/pidgin_audacious" 39 #define OPT_PIDGINAUD "/plugins/pidgin_audacious"
40 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status" 40 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status"
41 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo" 41 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo"
42 #define OPT_PROCESS_ALIAS OPT_PIDGINAUD "/process_alias" 42 #define OPT_PROCESS_ALIAS OPT_PIDGINAUD "/process_alias"
43 #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template"
43 44
44 #define SONG_TOKEN "%song" 45 #define SONG_TOKEN "%song"
45 #define NO_SONG_MESSAGE "No song being played." 46 #define NO_SONG_MESSAGE "No song being played."
46 47
47 #define BUDDY_ALIAS_MAXLEN 387 48 #define BUDDY_ALIAS_MAXLEN 387
405 406
406 static PurpleCmdRet 407 static PurpleCmdRet
407 paste_current_song(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) 408 paste_current_song(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data)
408 { 409 {
409 gint playpos = 0; 410 gint playpos = 0;
410 gchar *song = NULL, *tmp = NULL; 411 gchar *song = NULL, *tmp = NULL, *tmp2 = NULL;
411 PurpleConversationType type = purple_conversation_get_type(conv); 412 PurpleConversationType type = purple_conversation_get_type(conv);
412 size_t dummy; 413 size_t dummy;
413 414 const gchar *template = NULL;
414 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ 415
416 /* audacious isn't playing */
417 if(!audacious_remote_is_playing(session)) {
415 return PURPLE_CMD_RET_OK; 418 return PURPLE_CMD_RET_OK;
416 } 419 }
417 420
418 playpos = audacious_remote_get_playlist_pos(session); 421 playpos = audacious_remote_get_playlist_pos(session);
419 tmp = audacious_remote_get_playlist_title(session, playpos); 422 tmp = audacious_remote_get_playlist_title(session, playpos);
420 423
421 if(tmp) { 424 template = purple_prefs_get_string(OPT_PASTE_TEMPLATE);
422 if(botch_utf) // function exists 425
423 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); 426 if(template && strstr(template, SONG_TOKEN)) {
427 tmp2 = purple_strreplace(template, SONG_TOKEN, tmp);
428 g_free(tmp);
429 tmp = NULL;
430 }
431 else {
432 tmp2 = tmp;
433 }
434
435 if(tmp2) {
436 if(botch_utf) {
437 song = (gchar *) botch_utf(tmp2, strlen(tmp2), &dummy);
438 g_free(tmp2);
439 tmp2 = NULL;
440 }
424 else 441 else
425 song = g_strdup(tmp); 442 song = tmp2;
426 } 443 }
427 g_free(tmp);
428 tmp = NULL;
429 444
430 if(type == PURPLE_CONV_TYPE_CHAT) { 445 if(type == PURPLE_CONV_TYPE_CHAT) {
431 PurpleConvChat *chat = purple_conversation_get_chat_data(conv); 446 PurpleConvChat *chat = purple_conversation_get_chat_data(conv);
432 if (chat && song) 447 if (chat && song)
433 purple_conv_chat_send(chat, song); 448 purple_conv_chat_send(chat, song);
506 "Expand " SONG_TOKEN " to song info in the user info"); 521 "Expand " SONG_TOKEN " to song info in the user info");
507 purple_plugin_pref_frame_add(frame, pref); 522 purple_plugin_pref_frame_add(frame, pref);
508 523
509 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_ALIAS, 524 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_ALIAS,
510 "Expand " SONG_TOKEN " to song info in the alias"); 525 "Expand " SONG_TOKEN " to song info in the alias");
526 purple_plugin_pref_frame_add(frame, pref);
527
528 /* paste template */
529 pref = purple_plugin_pref_new_with_name_and_label(OPT_PASTE_TEMPLATE,
530 "Paste template");
511 purple_plugin_pref_frame_add(frame, pref); 531 purple_plugin_pref_frame_add(frame, pref);
512 532
513 return frame; 533 return frame;
514 } 534 }
515 535
554 /* add plugin preferences */ 574 /* add plugin preferences */
555 purple_prefs_add_none(OPT_PIDGINAUD); 575 purple_prefs_add_none(OPT_PIDGINAUD);
556 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); 576 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE);
557 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); 577 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE);
558 purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE); 578 purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE);
579 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN);
559 580
560 session = get_dbus_proxy(); 581 session = get_dbus_proxy();
561 } 582 }
562 583
563 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) 584 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info)