1/* 2 * proc_files.c - shows ALSA system information files 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 <assert.h> 21#include <menu.h> 22#include <unistd.h> 23#include "gettext_curses.h" 24#include "utils.h" 25#include "die.h" 26#include "mem.h" 27#include "colors.h" 28#include "widget.h" 29#include "textbox.h" 30#include "proc_files.h" 31#include "menu_widget.h" 32 33static struct widget proc_widget; 34static ITEM *items[7]; 35static unsigned int items_count; 36static MENU *menu; 37 38static void on_handle_key(int key) 39{ 40 ITEM *item; 41 42 switch (menu_widget_handle_key(menu, key)) { 43 case KEY_ENTER: 44 item = current_item(menu); 45 if (item) 46 show_textfile(item_name(item)); 47 break; 48 case KEY_CANCEL: 49 proc_widget.close(); 50 break; 51 } 52} 53 54static void create(void) 55{ 56 menu_widget_create(&proc_widget, menu, _("Select File")); 57} 58 59static void on_close(void) 60{ 61 unsigned int i; 62 63 unpost_menu(menu); 64 free_menu(menu); 65 for (i = 0; i < items_count; ++i) 66 free_item(items[i]); 67 widget_free(&proc_widget); 68} 69 70static void add_item(const char *file_name) 71{ 72 if (access(file_name, F_OK) == 0) { 73 items[items_count] = new_item(file_name, NULL); 74 if (!items[items_count]) 75 fatal_error("cannot create menu item"); 76 ++items_count; 77 assert(items_count < ARRAY_SIZE(items)); 78 } 79} 80 81static struct widget proc_widget = { 82 .handle_key = on_handle_key, 83 .window_size_changed = create, 84 .close = on_close, 85}; 86 87void create_proc_files_list(void) 88{ 89 items_count = 0; 90 add_item("/proc/asound/version"); 91 add_item("/proc/asound/cards"); 92 add_item("/proc/asound/devices"); 93 add_item("/proc/asound/oss/devices"); 94 add_item("/proc/asound/timers"); 95 add_item("/proc/asound/pcm"); 96 items[items_count] = NULL; 97 98 menu = new_menu(items); 99 if (!menu) 100 fatal_error("cannot create menu"); 101 set_menu_fore(menu, attrs.menu_selected); 102 set_menu_back(menu, attrs.menu); 103 set_menu_mark(menu, NULL); 104 menu_opts_off(menu, O_SHOWDESC); 105 106 create(); 107} 108