2
* device_name_form.c - ask for sound control device name
3
* Copyright (c) Clemens Ladisch <clemens@ladisch.de>
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.
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.
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/>.
24
#include "gettext_curses.h"
30
#include "mixer_widget.h"
31
#include "card_select.h"
32
#include "device_name.h"
34
static struct widget form_widget;
35
static FIELD *fields[3];
38
static char *dup_current_name(void)
40
int rows, cols, max, i;
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)
55
static void on_key_enter(void)
60
s = dup_current_name();
61
ok = select_card_by_name(s);
65
close_card_select_list();
69
static void on_form_key(int key)
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 },
85
if (key >= 32 && key < 256) {
86
form_driver(form, key);
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);
96
static void on_handle_key(int key)
114
static bool create(void)
118
if (screen_lines < 6 || screen_cols < 36) {
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);
129
set_form_win(form, form_widget.window);
130
set_form_sub(form, form_widget.subwindow);
134
static void on_window_size_changed(void)
136
form_driver(form, REQ_VALIDATION); /* save field value */
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.
148
field_opts_off(fields[1], O_BLANK);
153
static void on_close(void)
157
free_field(fields[0]);
158
free_field(fields[1]);
159
widget_free(&form_widget);
162
static struct widget form_widget = {
163
.handle_key = on_handle_key,
164
.window_size_changed = on_window_size_changed,
168
void create_device_name_form(void)
170
fields[0] = new_field(1, 32, 1, 1, 0, 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:"));
179
fields[1] = new_field(1, 32, 2, 1, 0, 0);
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);
189
form = new_form(fields);
191
fatal_error("cannot create form");