4 This file is part of PulseAudio.
6 Copyright 2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulsecore/core-util.h>
29 #include <pulsecore/module.h>
30 #include <pulsecore/log.h>
31 #include <pulsecore/namereg.h>
33 #include "module-default-device-restore-symdef.h"
35 PA_MODULE_AUTHOR("Lennart Poettering");
36 PA_MODULE_DESCRIPTION("Automatically restore the default sink and source");
37 PA_MODULE_VERSION(PACKAGE_VERSION);
38 PA_MODULE_LOAD_ONCE(TRUE);
40 #define DEFAULT_SINK_FILE "default-sink"
41 #define DEFAULT_SOURCE_FILE "default-source"
43 int pa__init(pa_module *m) {
46 /* We never overwrite manually configured settings */
48 if (m->core->default_sink_name)
49 pa_log_info("Manually configured default sink, not overwriting.");
50 else if ((f = pa_open_config_file(NULL, DEFAULT_SINK_FILE, NULL, NULL, "r"))) {
53 fgets(ln, sizeof(ln)-1, f);
58 pa_log_debug("No previous default sink setting, ignoring.");
59 else if (pa_namereg_get(m->core, ln, PA_NAMEREG_SINK, 1)) {
60 pa_namereg_set_default(m->core, ln, PA_NAMEREG_SINK);
61 pa_log_debug("Restored default sink '%s'.", ln);
63 pa_log_info("Saved default sink '%s' not existant, not restoring default sink setting.", ln);
66 if (m->core->default_source_name)
67 pa_log_info("Manually configured default source, not overwriting.");
68 else if ((f = pa_open_config_file(NULL, DEFAULT_SOURCE_FILE, NULL, NULL, "r"))) {
71 fgets(ln, sizeof(ln)-1, f);
76 pa_log_debug("No previous default source setting, ignoring.");
77 else if (pa_namereg_get(m->core, ln, PA_NAMEREG_SOURCE, 1)) {
78 pa_namereg_set_default(m->core, ln, PA_NAMEREG_SOURCE);
79 pa_log_debug("Restored default source '%s'.", ln);
81 pa_log_info("Saved default source '%s' not existant, not restoring default source setting.", ln);
87 void pa__done(pa_module*m) {
90 if ((f = pa_open_config_file(NULL, DEFAULT_SINK_FILE, NULL, NULL, "w"))) {
91 const char *n = pa_namereg_get_default_sink_name(m->core);
92 fprintf(f, "%s\n", n ? n : "");
96 if ((f = pa_open_config_file(NULL, DEFAULT_SOURCE_FILE, NULL, NULL, "w"))) {
97 const char *n = pa_namereg_get_default_source_name(m->core);
98 fprintf(f, "%s\n", n ? n : "");