Mercurial > pidgin-audacious
comparison pidgin-audacious.c @ 19:12d809123d69
- revised signed_on_cb() so that it calls purple_util_set_current_song().
- new debug macros.
- removed watchdog_func().
- added connect_purple_signals().
- renamed is_app_running() as is_app_playing().
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Sat, 04 Oct 2008 12:06:45 +0900 |
| parents | dc3aa0bf24c0 |
| children | 4aa711530489 |
comparison
equal
deleted
inserted
replaced
| 18:dc3aa0bf24c0 | 19:12d809123d69 |
|---|---|
| 31 #include "version.h" | 31 #include "version.h" |
| 32 #include "cmds.h" | 32 #include "cmds.h" |
| 33 #include "savedstatuses.h" | 33 #include "savedstatuses.h" |
| 34 | 34 |
| 35 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" | 35 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" |
| 36 | 36 #define PLUGIN_NAME "Pidgin-Audacious" |
| 37 #define OPT_PIDGINAUD "/plugins/pidgin_audacious" | 37 #define OPT_PIDGINAUD "/plugins/pidgin_audacious" |
| 38 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status" | 38 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status" |
| 39 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo" | 39 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo" |
| 40 #define OPT_SONG_TEMPLATE OPT_PIDGINAUD "/song_template" | 40 #define OPT_SONG_TEMPLATE OPT_PIDGINAUD "/song_template" |
| 41 #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template" | 41 #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template" |
| 42 #define OPT_LOG_OUTPUT OPT_PIDGINAUD "/log_output" | |
| 42 | 43 |
| 43 #define DEFAULT_SONG_TEMPLATE "%artist - %title" | 44 #define DEFAULT_SONG_TEMPLATE "%artist - %title" |
| 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 DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) | 48 #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) |
| 48 | 49 |
| 49 #define aud_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, \ | 50 #define aud_debug(fmt, ...) do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, "%s():%4d: " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0); |
| 50 "Pidgin-Audacious", \ | 51 |
| 51 fmt, ## __VA_ARGS__); | 52 #define aud_error(fmt, ...) do { if(purple_prefs_get_bool(OPT_LOG_OUTPUT)) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, "%s():%4d: " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); } while(0); |
| 52 #define aud_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, \ | 53 |
| 53 "Pidgin-Audacious", \ | |
| 54 fmt, ## __VA_ARGS__); | |
| 55 /* xxx move up */ | 54 /* xxx move up */ |
| 56 #define TITLE "%title" | 55 #define TITLE "%title" |
| 57 #define ARTIST "%artist" | 56 #define ARTIST "%artist" |
| 58 #define ALBUM "%album" | 57 #define ALBUM "%album" |
| 59 #define GENRE "%genre" | 58 #define GENRE "%genre" |
| 78 /* prototypes */ | 77 /* prototypes */ |
| 79 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak)); | 78 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak)); |
| 80 static void aud_process(gchar *aud_info); | 79 static void aud_process(gchar *aud_info); |
| 81 static void track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data); | 80 static void track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data); |
| 82 static void status_signal_cb(DBusGProxy *player_proxy, gint status, gpointer data); | 81 static void status_signal_cb(DBusGProxy *player_proxy, gint status, gpointer data); |
| 83 static gboolean is_app_running(void); | 82 static gboolean is_app_playing(void); |
| 84 static GHashTable *get_song_table(void); | 83 static GHashTable *get_song_table(void); |
| 85 static song_tuple *get_song_tuple(GHashTable *table); | 84 static song_tuple *get_song_tuple(GHashTable *table); |
| 85 static void signed_on_cb(PurpleConnection *gc, void *data); | |
| 86 static void prefs_cb(const char *name, PurplePrefType type, gconstpointer value, gpointer data); | |
| 86 | 87 |
| 87 | 88 |
| 88 /* implementation */ | 89 /* implementation */ |
| 89 | 90 |
| 90 static DBusGProxy * | 91 static DBusGProxy * |
| 126 "StatusChange", | 127 "StatusChange", |
| 127 G_CALLBACK(status_signal_cb), | 128 G_CALLBACK(status_signal_cb), |
| 128 NULL, NULL); | 129 NULL, NULL); |
| 129 } | 130 } |
| 130 | 131 |
| 132 static void | |
| 133 connect_purple_signals(PurplePlugin *plugin) | |
| 134 { | |
| 135 purple_signal_connect(purple_connections_get_handle(), | |
| 136 "signed-on", | |
| 137 plugin, | |
| 138 PURPLE_CALLBACK(signed_on_cb), | |
| 139 NULL); | |
| 140 | |
| 141 purple_signal_connect(purple_savedstatuses_get_handle(), | |
| 142 "savedstatus-changed", | |
| 143 plugin, | |
| 144 PURPLE_CALLBACK(signed_on_cb), | |
| 145 NULL); | |
| 146 | |
| 147 purple_prefs_connect_callback(purple_prefs_get_handle(), | |
| 148 OPT_PIDGINAUD, | |
| 149 prefs_cb, | |
| 150 NULL); | |
| 151 } | |
| 152 | |
| 131 static GHashTable * | 153 static GHashTable * |
| 132 get_song_table(void) | 154 get_song_table(void) |
| 133 { | 155 { |
| 134 GHashTable *table = NULL; | 156 GHashTable *table = NULL; |
| 135 | 157 |
| 136 status_signal_cb(NULL, -1, NULL); | 158 if(is_app_playing()) { |
| 137 | |
| 138 if(is_app_running()) { | |
| 139 dbus_g_proxy_call(session, | 159 dbus_g_proxy_call(session, |
| 140 "GetMetadata", | 160 "GetMetadata", |
| 141 NULL, | 161 NULL, |
| 142 G_TYPE_INVALID, | 162 G_TYPE_INVALID, |
| 143 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, | 163 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, |
| 261 | 281 |
| 262 } | 282 } |
| 263 } | 283 } |
| 264 | 284 |
| 265 | 285 |
| 266 #if 0 | |
| 267 static gboolean | |
| 268 watchdog_func(void) | |
| 269 { | |
| 270 gint playpos = 0; | |
| 271 gchar *song = NULL, *tmp = NULL; | |
| 272 | |
| 273 gboolean rv = TRUE; | |
| 274 size_t dummy; | |
| 275 | |
| 276 if(!session) { | |
| 277 session = get_dbus_session(); | |
| 278 } | |
| 279 | |
| 280 aud_debug("session = %p\n", session); | |
| 281 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); | |
| 282 | |
| 283 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ | |
| 284 aud_process(NULL); | |
| 285 purple_util_set_current_song(NULL, NULL, NULL); | |
| 286 return rv; | |
| 287 } | |
| 288 | |
| 289 playpos = audacious_remote_get_playlist_pos(session); | |
| 290 tmp = audacious_remote_get_playlist_title(session, playpos); | |
| 291 if(tmp) { | |
| 292 if(botch_utf) /* if function exists */ | |
| 293 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); | |
| 294 else | |
| 295 song = g_strdup(tmp); | |
| 296 } | |
| 297 g_free(tmp); | |
| 298 tmp = NULL; | |
| 299 | |
| 300 aud_process(song); | |
| 301 g_free(song); | |
| 302 song = NULL; | |
| 303 | |
| 304 /* preliminary support for purple_util_set_current_song() */ | |
| 305 gchar *artist = NULL, *title = NULL, *album = NULL; | |
| 306 | |
| 307 artist = audacious_get_tuple_field_data(session, "artist", playpos); | |
| 308 title = audacious_get_tuple_field_data(session, "title", playpos); | |
| 309 album = audacious_get_tuple_field_data(session, "album", playpos); | |
| 310 | |
| 311 purple_util_set_current_song(title ? title : "", | |
| 312 artist ? artist : "", | |
| 313 album ? album : ""); | |
| 314 | |
| 315 g_free(artist); | |
| 316 g_free(title); | |
| 317 g_free(album); | |
| 318 | |
| 319 return rv; | |
| 320 } | |
| 321 #endif | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 static void | 286 static void |
| 328 aud_process_status(PurpleConnection *gc, gchar *aud_info) | 287 aud_process_status(PurpleConnection *gc, gchar *aud_info) |
| 329 { | 288 { |
| 330 gchar *new = NULL, *key = NULL; | 289 gchar *new = NULL, *key = NULL; |
| 331 const gchar *current, *seed, *pushed, *proto; | 290 const gchar *current, *seed, *pushed, *proto; |
| 525 removeval(gpointer data) | 484 removeval(gpointer data) |
| 526 { | 485 { |
| 527 g_free(data); | 486 g_free(data); |
| 528 } | 487 } |
| 529 | 488 |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 static PurpleCmdRet | 489 static PurpleCmdRet |
| 535 paste_current_song(PurpleConversation *conv, const gchar *cmd, | 490 paste_current_song(PurpleConversation *conv, const gchar *cmd, |
| 536 gchar **args, gchar **error, void *data) | 491 gchar **args, gchar **error, void *data) |
| 537 { | 492 { |
| 538 gchar *song = NULL, *tmp = NULL, *tmp2 = NULL; | 493 gchar *song = NULL, *tmp = NULL, *tmp2 = NULL; |
| 539 PurpleConversationType type = purple_conversation_get_type(conv); | 494 PurpleConversationType type = purple_conversation_get_type(conv); |
| 540 size_t dummy; | 495 size_t dummy; |
| 541 const gchar *template = NULL; | 496 const gchar *template = NULL; |
| 542 | 497 |
| 543 /* audacious isn't playing */ | 498 /* audacious isn't playing */ |
| 544 if(!is_app_running()) { | 499 if(!is_app_playing()) { |
| 545 return PURPLE_CMD_RET_OK; | 500 return PURPLE_CMD_RET_OK; |
| 546 } | 501 } |
| 547 | 502 |
| 548 /* dbus lookup */ | 503 /* dbus lookup */ |
| 549 GHashTable *table = get_song_table(); | 504 GHashTable *table = get_song_table(); |
| 586 | 541 |
| 587 g_free(song); | 542 g_free(song); |
| 588 return PURPLE_CMD_RET_OK; | 543 return PURPLE_CMD_RET_OK; |
| 589 } | 544 } |
| 590 | 545 |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 static gboolean | 546 static gboolean |
| 596 is_app_running(void) | 547 is_app_playing(void) |
| 597 { | 548 { |
| 598 gchar *player_name = g_strconcat("org.mpris.", "audacious", NULL); | 549 gchar *player_name = g_strconcat("org.mpris.", "audacious", NULL); |
| 599 | 550 |
| 600 #if 0 | 551 #if 0 |
| 601 if(g_strcasecmp(pidginmpris->player_name, player_name) != 0) { | 552 if(g_strcasecmp(pidginmpris->player_name, player_name) != 0) { |
| 625 { | 576 { |
| 626 gchar *song_info = NULL; | 577 gchar *song_info = NULL; |
| 627 GHashTable *table = NULL; | 578 GHashTable *table = NULL; |
| 628 song_tuple *tuple = NULL; | 579 song_tuple *tuple = NULL; |
| 629 | 580 |
| 581 aud_debug("called\n"); | |
| 582 | |
| 630 table = get_song_table(); | 583 table = get_song_table(); |
| 631 tuple = get_song_tuple(table); | 584 tuple = get_song_tuple(table); |
| 585 g_hash_table_destroy(table); | |
| 586 | |
| 587 /* set current song */ | |
| 588 purple_util_set_current_song(tuple->title ? tuple->title : "", | |
| 589 tuple->artist ? tuple->artist : "", | |
| 590 tuple->album ? tuple->album : ""); | |
| 632 | 591 |
| 633 song_info = format_song_info(tuple); | 592 song_info = format_song_info(tuple); |
| 634 free_song_tuple(tuple); | 593 free_song_tuple(tuple); |
| 635 g_hash_table_destroy(table); | 594 |
| 636 | 595 aud_process(song_info); |
| 637 if(song_info) | |
| 638 aud_process(song_info); | |
| 639 | |
| 640 g_free(song_info); | 596 g_free(song_info); |
| 641 } | 597 } |
| 642 | 598 |
| 643 | 599 |
| 644 static void prefs_cb(const char *name, PurplePrefType type, | 600 static void |
| 601 prefs_cb(const char *name, PurplePrefType type, | |
| 645 gconstpointer value, gpointer data) | 602 gconstpointer value, gpointer data) |
| 646 { | 603 { |
| 647 aud_debug("settings change detected at %s\n", name); | 604 aud_debug("settings change detected at %s\n", name); |
| 648 signed_on_cb(NULL, NULL); | 605 signed_on_cb(NULL, NULL); |
| 649 } | 606 } |
| 666 | 623 |
| 667 /* connect to mpris signals */ | 624 /* connect to mpris signals */ |
| 668 connect_dbus_signals(); | 625 connect_dbus_signals(); |
| 669 | 626 |
| 670 /* connect to purple signals */ | 627 /* connect to purple signals */ |
| 671 purple_signal_connect(purple_connections_get_handle(), | 628 connect_purple_signals(plugin); |
| 672 "signed-on", | |
| 673 plugin, | |
| 674 PURPLE_CALLBACK(signed_on_cb), | |
| 675 NULL); | |
| 676 | |
| 677 purple_signal_connect(purple_savedstatuses_get_handle(), | |
| 678 "savedstatus-changed", | |
| 679 plugin, | |
| 680 PURPLE_CALLBACK(signed_on_cb), | |
| 681 NULL); | |
| 682 | |
| 683 purple_prefs_connect_callback(purple_prefs_get_handle(), | |
| 684 OPT_PIDGINAUD, | |
| 685 prefs_cb, | |
| 686 NULL); | |
| 687 | 629 |
| 688 status_signal_cb(NULL, -1, NULL); | 630 status_signal_cb(NULL, -1, NULL); |
| 689 | 631 |
| 690 | 632 |
| 691 /* register /song command */ | 633 /* register /song command */ |
| 775 0, /**< flags */ | 717 0, /**< flags */ |
| 776 NULL, /**< deps */ | 718 NULL, /**< deps */ |
| 777 PURPLE_PRIORITY_DEFAULT, /**< priority */ | 719 PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 778 PIDGINAUD_PLUGIN_ID, /**< id */ | 720 PIDGINAUD_PLUGIN_ID, /**< id */ |
| 779 "Pidgin-Audacious", /**< name */ | 721 "Pidgin-Audacious", /**< name */ |
| 780 "3.0.0d2", /**< version */ | 722 "3.0.0d1", /**< version */ |
| 781 "Automatically updates your Pidgin status info with the currently " | 723 "Automatically updates your Pidgin status info with the currently " |
| 782 "playing music in Audacious.", /** summary */ | 724 "playing music in Audacious.", /** summary */ |
| 783 "Automatically updates your Pidgin status info with the currently " | 725 "Automatically updates your Pidgin status info with the currently " |
| 784 "playing music in Audacious.", /** desc */ | 726 "playing music in Audacious.", /** desc */ |
| 785 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ | 727 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ |
| 802 purple_prefs_add_none(OPT_PIDGINAUD); | 744 purple_prefs_add_none(OPT_PIDGINAUD); |
| 803 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); | 745 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); |
| 804 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); | 746 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); |
| 805 purple_prefs_add_string(OPT_SONG_TEMPLATE, DEFAULT_SONG_TEMPLATE); | 747 purple_prefs_add_string(OPT_SONG_TEMPLATE, DEFAULT_SONG_TEMPLATE); |
| 806 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); | 748 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); |
| 749 purple_prefs_add_bool(OPT_LOG_OUTPUT, TRUE); | |
| 807 | 750 |
| 808 } | 751 } |
| 809 | 752 |
| 810 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) | 753 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) |
