]>
code.delx.au - pulseaudio/blob - src/modules/module-default-device-restore.c
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
)
39 #define DEFAULT_SINK_FILE "default-sink"
40 #define DEFAULT_SOURCE_FILE "default-source"
42 int pa__init(pa_module
*m
) {
45 /* We never overwrite manually configured settings */
47 if (m
->core
->default_sink_name
)
48 pa_log_info("Manually configured default sink, not overwriting.");
49 else if ((f
= pa_open_config_file(NULL
, DEFAULT_SINK_FILE
, NULL
, NULL
, "r"))) {
52 fgets(ln
, sizeof(ln
)-1, f
);
57 pa_log_debug("No previous default sink setting, ignoring.");
58 else if (pa_namereg_get(m
->core
, ln
, PA_NAMEREG_SINK
, 1)) {
59 pa_namereg_set_default(m
->core
, ln
, PA_NAMEREG_SINK
);
60 pa_log_debug("Restored default sink '%s'.", ln
);
62 pa_log_info("Saved default sink '%s' not existant, not restoring default sink setting.", ln
);
65 if (m
->core
->default_source_name
)
66 pa_log_info("Manually configured default source, not overwriting.");
67 else if ((f
= pa_open_config_file(NULL
, DEFAULT_SOURCE_FILE
, NULL
, NULL
, "r"))) {
70 fgets(ln
, sizeof(ln
)-1, f
);
75 pa_log_debug("No previous default source setting, ignoring.");
76 else if (pa_namereg_get(m
->core
, ln
, PA_NAMEREG_SOURCE
, 1)) {
77 pa_namereg_set_default(m
->core
, ln
, PA_NAMEREG_SOURCE
);
78 pa_log_debug("Restored default source '%s'.", ln
);
80 pa_log_info("Saved default source '%s' not existant, not restoring default source setting.", ln
);
86 void pa__done(pa_module
*m
) {
89 if ((f
= pa_open_config_file(NULL
, DEFAULT_SINK_FILE
, NULL
, NULL
, "w"))) {
90 const char *n
= pa_namereg_get_default_sink_name(m
->core
);
91 fprintf(f
, "%s\n", n
? n
: "");
95 if ((f
= pa_open_config_file(NULL
, DEFAULT_SOURCE_FILE
, NULL
, NULL
, "w"))) {
96 const char *n
= pa_namereg_get_default_source_name(m
->core
);
97 fprintf(f
, "%s\n", n
? n
: "");