~ubuntu-branches/ubuntu/natty/alsa-utils/natty

« back to all changes in this revision

Viewing changes to alsamixer/device_name.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich, Daniel T Chen
  • Date: 2009-11-06 11:29:35 UTC
  • mfrom: (2.3.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091106112935-stzy6l7u9auw6hm0
Tags: 1.0.21-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/init:
    + wait until /usr/bin and /var/lib/alsa exist
    + only display an error when dealing with alsactl if there is no card
      specified
    + Set sane level for 'Speaker' and 'Headphone', needed for Dell Mini 9
      and Dell E series
    + ute PC Beep on hda cards that support it during initial volume setup
    + update lsb header to indicate no running of the script unless the
      udev rule is run
    + Mute *Analog/Digital Control for Creative cards by default
    + Default Digital Input Source to be Digital Mic 1 so that users
      with digital mic will be able to use it out of the box
    + Make use of lsb-functions/log calls
    + Mute "IEC958 Optical Raw" by default (LP: #408370)
  - debian/rules:
    + ship udev rules file in /lib/udev/rules.d
    + Do not install start symlinks for the alsa-utils init script, it gets
      run from a udev rule
  - debian/udev.script: do not use hotplug functions
  - debian/README.init.cs4236: Include in /usr/share/doc/alsa-utils so that
    users of snd-cs4236 (e.g., ThinkPad 600) can have audible sound
  - debian/patches/unset_pulse_internal.patch: We don't want alsamixer to
    show the pulse mixer by default, since it can be controlled from
    pulseaudio itself.
  - debian/patches/fix_misspelling_speaker-test_man_page.patch: Fix
    misspelling in speaker-test(1)
  - Set sane level for headphone 1 for Dell Studio XPS with 2.6.30.
  - Remove alsaconf from build system and remove po files

[ Daniel T Chen ]
"The beginning of the great initscript-sectomy"

* debian/alsa-mixer-save.upstart: Create an upstart job specifically
  saving mixer levels to resolve race (LP: #454265)
* debian/control: Version build-dep to upstart-aware debhelper.
* debian/init:
  + Revert all initscript changes in 1.0.20-2ubuntu[456]. They were
    crackful.
  + Restore more sane behavior/compatibility with 8.10 by not mucking
    with sound card state if alsactl restore fails.
  + Don't wait for 1 second after alsactl store, which already is
    expensive. Also, if store is going to fail, this wait is useless.
* debian/preinst: Handle upgrades from upstart-unaware versions.
* debian/rules: Move the former initscript into /sbin. We now have an
  upstart job just for handling alsactl store.
* debian/NOTES:
  debian/README.Debian:
  debian/modprobe-post-install-part:
  debian/udev.script: Use the new script path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * device_name_form.c - ask for sound control device name
 
3
 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation, either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include "aconfig.h"
 
20
#include <stdlib.h>
 
21
#include <string.h>
 
22
#include CURSESINC
 
23
#include <form.h>
 
24
#include "gettext_curses.h"
 
25
#include "die.h"
 
26
#include "mem.h"
 
27
#include "utils.h"
 
28
#include "colors.h"
 
29
#include "widget.h"
 
30
#include "mixer_widget.h"
 
31
#include "card_select.h"
 
32
#include "device_name.h"
 
33
 
 
34
static struct widget form_widget;
 
35
static FIELD *fields[3];
 
36
static FORM *form;
 
37
 
 
38
static char *dup_current_name(void)
 
39
{
 
40
        int rows, cols, max, i;
 
41
        char *s;
 
42
 
 
43
        if (form_driver(form, REQ_VALIDATION) == E_OK) {
 
44
                dynamic_field_info(fields[1], &rows, &cols, &max);
 
45
                s = ccalloc(1, cols + 1);
 
46
                memcpy(s, field_buffer(fields[1], 0), cols);
 
47
                for (i = strlen(s) - 1; i >= 0 && s[i] == ' '; --i)
 
48
                        s[i] = '\0';
 
49
                return s;
 
50
        } else {
 
51
                return cstrdup("");
 
52
        }
 
53
}
 
54
 
 
55
static void on_key_enter(void)
 
56
{
 
57
        char *s;
 
58
        bool ok;
 
59
 
 
60
        s = dup_current_name();
 
61
        ok = select_card_by_name(s);
 
62
        free(s);
 
63
        if (ok) {
 
64
                form_widget.close();
 
65
                close_card_select_list();
 
66
        }
 
67
}
 
68
 
 
69
static void on_form_key(int key)
 
70
{
 
71
        static const struct {
 
72
                int key;
 
73
                int request;
 
74
        } key_map[] = {
 
75
                { KEY_LEFT, REQ_PREV_CHAR },
 
76
                { KEY_RIGHT, REQ_NEXT_CHAR },
 
77
                { KEY_HOME, REQ_BEG_FIELD },
 
78
                { KEY_BACKSPACE, REQ_DEL_PREV },
 
79
                { KEY_DC, REQ_DEL_CHAR },
 
80
                { KEY_BEG, REQ_BEG_FIELD },
 
81
                { KEY_END, REQ_END_FIELD },
 
82
        };
 
83
        unsigned int i;
 
84
 
 
85
        if (key >= 32 && key < 256) {
 
86
                form_driver(form, key);
 
87
                return;
 
88
        }
 
89
        for (i = 0; i < ARRAY_SIZE(key_map); ++i)
 
90
                if (key_map[i].key == key) {
 
91
                        form_driver(form, key_map[i].request);
 
92
                        break;
 
93
                }
 
94
}
 
95
 
 
96
static void on_handle_key(int key)
 
97
{
 
98
        switch (key) {
 
99
        case 27:
 
100
        case KEY_CANCEL:
 
101
                form_widget.close();
 
102
                break;
 
103
        case 10:
 
104
        case 13:
 
105
        case KEY_ENTER:
 
106
                on_key_enter();
 
107
                break;
 
108
        default:
 
109
                on_form_key(key);
 
110
                break;
 
111
        }
 
112
}
 
113
 
 
114
static bool create(void)
 
115
{
 
116
        const char *title;
 
117
 
 
118
        if (screen_lines < 6 || screen_cols < 36) {
 
119
                form_widget.close();
 
120
                beep();
 
121
                return FALSE;
 
122
        }
 
123
        widget_init(&form_widget,
 
124
                    6, 36, SCREEN_CENTER, SCREEN_CENTER,
 
125
                    attr_textbox, WIDGET_BORDER | WIDGET_SUBWINDOW | WIDGET_CURSOR_VISIBLE);
 
126
        title = _("Sound Card");
 
127
        mvwprintw(form_widget.window, 0, (36 - 2 - get_mbs_width(title)) / 2, " %s ", title);
 
128
 
 
129
        set_form_win(form, form_widget.window);
 
130
        set_form_sub(form, form_widget.subwindow);
 
131
        return TRUE;
 
132
}
 
133
 
 
134
static void on_window_size_changed(void)
 
135
{
 
136
        form_driver(form, REQ_VALIDATION); /* save field value */
 
137
        unpost_form(form);
 
138
 
 
139
        if (!create())
 
140
                return;
 
141
 
 
142
        /*
 
143
         * This call fails because ncurses does not allow changing options of
 
144
         * the current field, and we cannot change the current field because
 
145
         * there is only one.  The only way to make this work would be to throw
 
146
         * away and recreate all fields.
 
147
         */
 
148
        field_opts_off(fields[1], O_BLANK);
 
149
 
 
150
        post_form(form);
 
151
}
 
152
 
 
153
static void on_close(void)
 
154
{
 
155
        unpost_form(form);
 
156
        free_form(form);
 
157
        free_field(fields[0]);
 
158
        free_field(fields[1]);
 
159
        widget_free(&form_widget);
 
160
}
 
161
 
 
162
static struct widget form_widget = {
 
163
        .handle_key = on_handle_key,
 
164
        .window_size_changed = on_window_size_changed,
 
165
        .close = on_close,
 
166
};
 
167
 
 
168
void create_device_name_form(void)
 
169
{
 
170
        fields[0] = new_field(1, 32, 1, 1, 0, 0);
 
171
        if (!fields[0])
 
172
                fatal_error("cannot create field");
 
173
        field_opts_off(fields[0], O_ACTIVE);
 
174
        field_opts_off(fields[0], O_EDIT);
 
175
        set_field_fore(fields[0], attr_textbox);
 
176
        set_field_back(fields[0], attr_textbox);
 
177
        set_field_buffer(fields[0], 0, _("Device name:"));
 
178
 
 
179
        fields[1] = new_field(1, 32, 2, 1, 0, 0);
 
180
        if (!fields[1])
 
181
                fatal_error("cannot create field");
 
182
        field_opts_off(fields[1], O_AUTOSKIP);
 
183
        field_opts_off(fields[1], O_NULLOK);
 
184
        field_opts_off(fields[1], O_STATIC);
 
185
        set_field_fore(fields[1], attr_textfield);
 
186
        set_field_back(fields[1], attr_textfield);
 
187
        set_field_buffer(fields[1], 0, mixer_device_name);
 
188
 
 
189
        form = new_form(fields);
 
190
        if (!form)
 
191
                fatal_error("cannot create form");
 
192
 
 
193
        if (!create())
 
194
                return;
 
195
 
 
196
        post_form(form);
 
197
}