gboolean finch_sound_is_enabled(void) { const char *pref = make_pref("/method"); const char *method = purple_prefs_get_string(pref); if (!method) return FALSE; if (strcmp(method, "nosound") == 0) return FALSE; if (purple_prefs_get_int(make_pref("/volume")) <= 0) return FALSE; return TRUE; }
static void load_pref_window(const char * profile) { gint i; finch_sound_set_active_profile(profile); gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->method), (gchar *)purple_prefs_get_string(make_pref("/method"))); gnt_entry_set_text(GNT_ENTRY(pref_dialog->command), purple_prefs_get_path(make_pref("/command"))); gnt_check_box_set_checked(GNT_CHECK_BOX(pref_dialog->conv_focus), purple_prefs_get_bool(make_pref("/conv_focus"))); gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->while_status), GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status"))); gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100)); for (i = 0; i < PURPLE_NUM_SOUNDS; i++) { FinchSoundEvent * event = &sounds[i]; gchar *boolpref; gchar *filepref, *basename = NULL; const char * profile = finch_sound_get_active_profile(); filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", profile, event->pref); g_free(event->file); event->file = g_strdup(purple_prefs_get_path(filepref)); g_free(filepref); if (event->label == NULL) { continue; } boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", profile, event->pref); gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 0, event->label); gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 1, event->file[0] ? (basename = g_path_get_basename(event->file)) : _("(default)")); g_free(basename); gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), purple_prefs_get_bool(boolpref)); g_free(boolpref); } gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles), (gchar *)finch_sound_get_active_profile()); gnt_widget_draw(pref_dialog->window); }
static void test_cb(GntWidget *button, gpointer null) { PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); FinchSoundEvent * event = &sounds[id]; char *enabled, *file, *tmpfile, *volpref; gboolean temp_value; int volume; enabled = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), event->pref); file = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), event->pref); volpref = g_strdup(make_pref("/volume")); temp_value = purple_prefs_get_bool(enabled); tmpfile = g_strdup(purple_prefs_get_path(file)); volume = purple_prefs_get_int(volpref); purple_prefs_set_path(file, event->file); if (!temp_value) purple_prefs_set_bool(enabled, TRUE); purple_prefs_set_int(volpref, gnt_slider_get_value(GNT_SLIDER(pref_dialog->volume))); purple_sound_play_event(id, NULL); if (!temp_value) purple_prefs_set_bool(enabled, FALSE); purple_prefs_set_path(file, tmpfile); purple_prefs_set_int(volpref, volume); g_free(enabled); g_free(file); g_free(tmpfile); g_free(volpref); }
static void save_cb(GntWidget *button, gpointer win) { GList * itr; purple_prefs_set_string(make_pref("/method"), gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->method))); purple_prefs_set_path(make_pref("/command"), gnt_entry_get_text(GNT_ENTRY(pref_dialog->command))); purple_prefs_set_bool(make_pref("/conv_focus"), gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus))); purple_prefs_set_int("/purple/sound/while_status", GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status)))); for (itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events)); itr; itr = itr->next) { FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(itr->data)]; char * filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), event->pref); char * boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), event->pref); purple_prefs_set_bool(boolpref, gnt_tree_get_choice(GNT_TREE(pref_dialog->events), itr->data)); purple_prefs_set_path(filepref, event->file ? event->file : ""); g_free(filepref); g_free(boolpref); } gnt_widget_destroy(GNT_WIDGET(win)); }
/* This gets called when the active profile changes */ static void initialize_profile(const char *name, PurplePrefType type, gconstpointer val, gpointer null) { FinchSoundEvent *event; if (purple_prefs_exists(make_pref(""))) return; purple_prefs_add_none(make_pref("")); purple_prefs_add_none(make_pref("/enabled")); purple_prefs_add_none(make_pref("/file")); for (event = sounds; event - sounds < PURPLE_NUM_SOUNDS; event++) { char pref[512]; g_snprintf(pref, sizeof(pref), "/enabled/%s", event->pref); purple_prefs_add_bool(make_pref(pref), FALSE); g_snprintf(pref, sizeof(pref), "/file/%s", event->pref); purple_prefs_add_path(make_pref(pref), ""); } purple_prefs_add_bool(make_pref("/conv_focus"), FALSE); purple_prefs_add_bool(make_pref("/mute"), FALSE); purple_prefs_add_path(make_pref("/command"), ""); purple_prefs_add_string(make_pref("/method"), "automatic"); }
/* * play a sound event for a conversation, honoring make_sound flag * of conversation and checking for focus if conv_focus pref is set */ static void play_conv_event(PurpleConversation *conv, PurpleSoundEventID event) { /* If we should not play the sound for some reason, then exit early */ if (conv != NULL) { FinchConv *gntconv; gboolean has_focus; gntconv = FINCH_CONV(conv); has_focus = purple_conversation_has_focus(conv); if ((gntconv->flags & FINCH_CONV_NO_SOUND) || (has_focus && !purple_prefs_get_bool(make_pref("/conv_focus")))) { return; } } purple_sound_play_event(event, conv ? purple_conversation_get_account(conv) : NULL); }
static void finch_sound_play_file(const char *filename) { const char *method; #ifdef USE_GSTREAMER float volume; char *uri; GstElement *sink = NULL; GstElement *play = NULL; GstBus *bus = NULL; #endif if (purple_prefs_get_bool(make_pref("/mute"))) return; method = purple_prefs_get_string(make_pref("/method")); if (!strcmp(method, "nosound")) { return; } else if (!strcmp(method, "beep")) { beep(); return; } if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { purple_debug_error("gntsound", "sound file (%s) does not exist.\n", filename); return; } #ifndef _WIN32 if (!strcmp(method, "custom")) { const char *sound_cmd; char *command; char *esc_filename; GError *error = NULL; sound_cmd = purple_prefs_get_path(make_pref("/command")); if (!sound_cmd || *sound_cmd == '\0') { purple_debug_error("gntsound", "'Command' sound method has been chosen, " "but no command has been set."); return; } esc_filename = g_shell_quote(filename); if (strstr(sound_cmd, "%s")) command = purple_strreplace(sound_cmd, "%s", esc_filename); else command = g_strdup_printf("%s %s", sound_cmd, esc_filename); if (!g_spawn_command_line_async(command, &error)) { purple_debug_error("gntsound", "sound command could not be launched: %s\n", error->message); g_error_free(error); } g_free(esc_filename); g_free(command); return; } #ifdef USE_GSTREAMER if (gst_init_failed) /* Perhaps do beep instead? */ return; volume = (float)(CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100)) / 50; if (!strcmp(method, "automatic")) { if (purple_running_gnome()) { sink = gst_element_factory_make("gconfaudiosink", "sink"); } if (!sink) sink = gst_element_factory_make("autoaudiosink", "sink"); if (!sink) { purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); return; } } else if (!strcmp(method, "esd")) { sink = gst_element_factory_make("esdsink", "sink"); if (!sink) { purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); return; } } else if (!strcmp(method, "alsa")) { sink = gst_element_factory_make("alsasink", "sink"); if (!sink) { purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); return; } } else { purple_debug_error("sound", "Unknown sound method '%s'\n", method); return; } play = gst_element_factory_make("playbin", "play"); if (play == NULL) { return; } uri = g_strdup_printf("file://%s", filename); g_object_set(G_OBJECT(play), "uri", uri, "volume", volume, "audio-sink", sink, NULL); bus = gst_pipeline_get_bus(GST_PIPELINE(play)); gst_bus_add_watch(bus, bus_call, play); gst_element_set_state(play, GST_STATE_PLAYING); gst_object_unref(bus); g_free(uri); #else /* USE_GSTREAMER */ beep(); return; #endif /* USE_GSTREAMER */ #else /* _WIN32 */ purple_debug_info("sound", "Playing %s\n", filename); { wchar_t *wc_filename = g_utf8_to_utf16(filename, -1, NULL, NULL, NULL); if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME)) purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n"); g_free(wc_filename); } #endif /* _WIN32 */ }