comparison libpurple/util.c @ 22000:af0426c34c27

Utility functions to set and format song information. Closes #4398.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 05 Jan 2008 11:08:48 +0000
parents 7e833250a0ef
children 83613550512b
comparison
equal deleted inserted replaced
21999:b783b67f1469 22000:af0426c34c27
4626 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */ 4626 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */
4627 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */ 4627 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */
4628 #endif /* HAVE_SIGNAL_H */ 4628 #endif /* HAVE_SIGNAL_H */
4629 #endif /* !_WIN32 */ 4629 #endif /* !_WIN32 */
4630 } 4630 }
4631
4632 void purple_util_set_current_song(const char *title, const char *artist, const char *album)
4633 {
4634 GList *list = purple_accounts_get_all();
4635 for (; list; list = list->next) {
4636 PurplePresence *presence;
4637 PurpleStatus *tune;
4638 PurpleAccount *account = list->data;
4639 if (!purple_account_get_enabled(account, purple_core_get_ui()))
4640 continue;
4641
4642 presence = purple_account_get_presence(account);
4643 tune = purple_presence_get_status(presence, "tune");
4644 if (!tune)
4645 continue;
4646 if (title) {
4647 purple_status_set_active(tune, TRUE);
4648 purple_status_set_attr_string(tune, PURPLE_TUNE_TITLE, title);
4649 purple_status_set_attr_string(tune, PURPLE_TUNE_ARTIST, artist);
4650 purple_status_set_attr_string(tune, PURPLE_TUNE_ALBUM, album);
4651 } else {
4652 purple_status_set_active(tune, FALSE);
4653 }
4654 }
4655 }
4656
4657 char * purple_util_format_song_info(const char *title, const char *artist, const char *album, gpointer unused)
4658 {
4659 GString *string;
4660 char *esc;
4661
4662 if (!title)
4663 return NULL;
4664
4665 esc = g_markup_escape_text(title, -1);
4666 string = g_string_new("");
4667 g_string_append_printf(string, "%s", esc);
4668 g_free(esc);
4669
4670 if (artist) {
4671 esc = g_markup_escape_text(artist, -1);
4672 g_string_append_printf(string, _(" - %s"), esc);
4673 g_free(esc);
4674 }
4675
4676 if (album) {
4677 esc = g_markup_escape_text(album, -1);
4678 g_string_append_printf(string, _(" (%s)"), esc);
4679 g_free(esc);
4680 }
4681
4682 return g_string_free(string, FALSE);
4683 }
4684