only store card profile if flagged for that

This commit is contained in:
Lennart Poettering 2009-03-23 19:31:36 +01:00
parent 124de50ef8
commit 08154554b0
5 changed files with 17 additions and 6 deletions

View file

@ -161,6 +161,9 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
if (!(card = pa_idxset_get_by_index(c->cards, idx))) if (!(card = pa_idxset_get_by_index(c->cards, idx)))
return; return;
if (!card->save_profile)
return;
pa_strlcpy(entry.profile, card->active_profile ? card->active_profile->name : "", sizeof(entry.profile)); pa_strlcpy(entry.profile, card->active_profile ? card->active_profile->name : "", sizeof(entry.profile));
if ((old = read_entry(u, card->name))) { if ((old = read_entry(u, card->name))) {

View file

@ -143,7 +143,8 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
c->active_profile = NULL; c->active_profile = NULL;
if (data->active_profile && c->profiles) if (data->active_profile && c->profiles)
c->active_profile = pa_hashmap_get(c->profiles, data->active_profile); if ((c->active_profile = pa_hashmap_get(c->profiles, data->active_profile)))
c->save_profile = data->save_profile;
if (!c->active_profile && c->profiles) { if (!c->active_profile && c->profiles) {
void *state = NULL; void *state = NULL;
@ -209,7 +210,7 @@ void pa_card_free(pa_card *c) {
pa_xfree(c); pa_xfree(c);
} }
int pa_card_set_profile(pa_card *c, const char *name) { int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
pa_card_profile *profile; pa_card_profile *profile;
pa_assert(c); pa_assert(c);
@ -224,8 +225,10 @@ int pa_card_set_profile(pa_card *c, const char *name) {
if (!(profile = pa_hashmap_get(c->profiles, name))) if (!(profile = pa_hashmap_get(c->profiles, name)))
return -1; return -1;
if (c->active_profile == profile) if (c->active_profile == profile) {
c->save_profile = c->save_profile || save;
return 0; return 0;
}
if (c->set_profile(c, profile) < 0) if (c->set_profile(c, profile) < 0)
return -1; return -1;
@ -235,6 +238,7 @@ int pa_card_set_profile(pa_card *c, const char *name) {
pa_log_info("Changed profile of card %u \"%s\" to %s", c->index, c->name, profile->name); pa_log_info("Changed profile of card %u \"%s\" to %s", c->index, c->name, profile->name);
c->active_profile = profile; c->active_profile = profile;
c->save_profile = save;
return 0; return 0;
} }

View file

@ -63,6 +63,8 @@ struct pa_card {
pa_hashmap *profiles; pa_hashmap *profiles;
pa_card_profile *active_profile; pa_card_profile *active_profile;
pa_bool_t save_profile;
void *userdata; void *userdata;
int (*set_profile)(pa_card *c, pa_card_profile *profile); int (*set_profile)(pa_card *c, pa_card_profile *profile);
@ -80,6 +82,8 @@ typedef struct pa_card_new_data {
char *active_profile; char *active_profile;
pa_bool_t namereg_fail:1; pa_bool_t namereg_fail:1;
pa_bool_t save_profile:1;
} pa_card_new_data; } pa_card_new_data;
pa_card_profile *pa_card_profile_new(const char *name, const char *description, size_t extra); pa_card_profile *pa_card_profile_new(const char *name, const char *description, size_t extra);
@ -93,7 +97,7 @@ void pa_card_new_data_done(pa_card_new_data *data);
pa_card *pa_card_new(pa_core *c, pa_card_new_data *data); pa_card *pa_card_new(pa_core *c, pa_card_new_data *data);
void pa_card_free(pa_card *c); void pa_card_free(pa_card *c);
int pa_card_set_profile(pa_card *c, const char *name); int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save);
int pa_card_suspend(pa_card *c, pa_bool_t suspend); int pa_card_suspend(pa_card *c, pa_bool_t suspend);

View file

@ -1454,7 +1454,7 @@ static int pa_cli_command_card_profile(pa_core *c, pa_tokenizer *t, pa_strbuf *b
return -1; return -1;
} }
if (pa_card_set_profile(card, p) < 0) { if (pa_card_set_profile(card, p, TRUE) < 0) {
pa_strbuf_printf(buf, "Failed to set card profile to '%s'.\n", p); pa_strbuf_printf(buf, "Failed to set card profile to '%s'.\n", p);
return -1; return -1;
} }

View file

@ -4119,7 +4119,7 @@ static void command_set_card_profile(pa_pdispatch *pd, uint32_t command, uint32_
CHECK_VALIDITY(c->pstream, card, tag, PA_ERR_NOENTITY); CHECK_VALIDITY(c->pstream, card, tag, PA_ERR_NOENTITY);
if (pa_card_set_profile(card, profile) < 0) { if (pa_card_set_profile(card, profile, TRUE) < 0) {
pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID); pa_pstream_send_error(c->pstream, tag, PA_ERR_INVALID);
return; return;
} }