2 * proc_files.c - shows ALSA system information files
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/>.
23 #include "gettext_curses.h"
30 #include "proc_files.h"
32 static struct widget proc_widget;
33 static ITEM *items[7];
34 static unsigned int items_count;
37 static void on_menu_key(int key)
43 { KEY_DOWN, REQ_DOWN_ITEM },
44 { KEY_UP, REQ_UP_ITEM },
45 { KEY_HOME, REQ_FIRST_ITEM },
46 { KEY_NPAGE, REQ_SCR_DPAGE },
47 { KEY_PPAGE, REQ_SCR_UPAGE },
48 { KEY_BEG, REQ_FIRST_ITEM },
49 { KEY_END, REQ_LAST_ITEM },
53 for (i = 0; i < ARRAY_SIZE(key_map); ++i)
54 if (key_map[i].key == key) {
55 menu_driver(menu, key_map[i].request);
60 static void on_handle_key(int key)
72 item = current_item(menu);
74 show_textfile(item_name(item));
82 static bool create(void)
87 if (screen_lines < 3 || screen_cols < 20) {
92 scale_menu(menu, &rows, &columns);
95 if (rows > screen_lines)
97 if (columns > screen_cols)
98 columns = screen_cols;
100 widget_init(&proc_widget, rows, columns, SCREEN_CENTER, SCREEN_CENTER,
101 attr_menu, WIDGET_BORDER | WIDGET_SUBWINDOW);
103 title = _("Select File");
104 mvwprintw(proc_widget.window, 0, (columns - 2 - get_mbs_width(title)) / 2, " %s ", title);
105 set_menu_win(menu, proc_widget.window);
106 set_menu_sub(menu, proc_widget.subwindow);
110 static void on_window_size_changed(void)
118 static void on_close(void)
124 for (i = 0; i < items_count; ++i)
126 widget_free(&proc_widget);
129 static void add_item(const char *file_name)
131 if (access(file_name, F_OK) == 0) {
132 items[items_count] = new_item(file_name, NULL);
133 if (!items[items_count])
134 fatal_error("cannot create menu item");
136 assert(items_count < ARRAY_SIZE(items));
140 static struct widget proc_widget = {
141 .handle_key = on_handle_key,
142 .window_size_changed = on_window_size_changed,
146 void create_proc_files_list(void)
149 add_item("/proc/asound/version");
150 add_item("/proc/asound/cards");
151 add_item("/proc/asound/devices");
152 add_item("/proc/asound/oss/devices");
153 add_item("/proc/asound/timers");
154 add_item("/proc/asound/pcm");
155 items[items_count] = NULL;
157 menu = new_menu(items);
159 fatal_error("cannot create menu");
160 set_menu_fore(menu, attr_menu_selected);
161 set_menu_back(menu, attr_menu);
162 set_menu_mark(menu, NULL);
163 menu_opts_off(menu, O_SHOWDESC);