keyclick: Add a callback so screens can cancel a click. Add a generic list callback...
[maemo-rb.git] / apps / menus / radio_menu.c
blob8ab7151c3ed22b38db6b3a92147b0a3fda4f97c1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2003 Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdio.h>
23 #include "config.h"
24 #include "menu.h"
25 #include "icon.h"
26 #include "radio.h"
27 #include "lang.h"
28 #include "settings.h"
29 #include "presets.h"
30 #include "exported_menus.h"
31 #include "sound_menu.h" /* recording_menu() */
32 #include "talk.h"
34 #ifdef HAVE_RECORDING
35 #include "recording.h" /* recording_screen() */
37 #if defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC
38 #define FM_RECORDING_SCREEN
39 static int fm_recording_screen(void)
41 bool ret;
43 /* switch recording source to FMRADIO for the duration */
44 int rec_source = global_settings.rec_source;
45 global_settings.rec_source = AUDIO_SRC_FMRADIO;
46 ret = recording_screen(true);
48 /* safe to reset as changing sources is prohibited here */
49 global_settings.rec_source = rec_source;
51 return ret;
54 MENUITEM_FUNCTION(recscreen_item, 0, ID2P(LANG_RECORDING),
55 fm_recording_screen, NULL, NULL, Icon_Recording);
56 #endif /* defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC */
58 #if defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC
59 #define FM_RECORDING_SETTINGS
60 static int fm_recording_settings(void)
62 bool ret = recording_menu(true);
64 #if CONFIG_CODEC != SWCODEC
65 if (!ret)
67 struct audio_recording_options rec_options;
68 rec_init_recording_options(&rec_options);
69 rec_options.rec_source = AUDIO_SRC_LINEIN;
70 rec_set_recording_options(&rec_options);
72 #endif
74 return ret;
77 MENUITEM_FUNCTION(recsettings_item, 0, ID2P(LANG_RECORDING_SETTINGS),
78 fm_recording_settings, NULL, NULL, Icon_Recording);
79 #endif /* defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC */
80 #endif /* HAVE_RECORDING */
82 #ifndef FM_PRESET
83 MENUITEM_FUNCTION(radio_presets_item, 0, ID2P(LANG_PRESET),
84 handle_radio_presets, NULL, NULL, Icon_NOICON);
85 #endif
86 #ifndef FM_PRESET_ADD
87 MENUITEM_FUNCTION(radio_addpreset_item, 0, ID2P(LANG_FM_ADD_PRESET),
88 handle_radio_add_preset, NULL, NULL, Icon_NOICON);
89 #endif
91 MENUITEM_FUNCTION(presetload_item, 0, ID2P(LANG_FM_PRESET_LOAD),
92 preset_list_load, NULL, NULL, Icon_NOICON);
93 MENUITEM_FUNCTION(presetsave_item, 0, ID2P(LANG_FM_PRESET_SAVE),
94 preset_list_save, NULL, NULL, Icon_NOICON);
95 MENUITEM_FUNCTION(presetclear_item, 0, ID2P(LANG_FM_PRESET_CLEAR),
96 preset_list_clear, NULL, NULL, Icon_NOICON);
98 MENUITEM_SETTING(set_region, &global_settings.fm_region, NULL);
99 MENUITEM_SETTING(force_mono, &global_settings.fm_force_mono, NULL);
101 #ifndef FM_MODE
102 extern int radio_mode;
103 static char* get_mode_text(int selected_item, void * data, char *buffer)
105 (void)selected_item;
106 (void)data;
107 snprintf(buffer, MAX_PATH, "%s %s", str(LANG_MODE),
108 radio_mode ? str(LANG_PRESET) :
109 str(LANG_RADIO_SCAN_MODE));
110 return buffer;
112 static int mode_speak_item(int selected_item, void * data)
114 (void)selected_item;
115 (void)data;
116 long talk_ids[4];
117 talk_ids[0] = LANG_MODE;
118 talk_ids[1] = radio_mode ? LANG_PRESET : LANG_RADIO_SCAN_MODE;
119 talk_ids[2] = TALK_FINAL_ID;
120 talk_idarray(talk_ids, true);
121 return 0;
123 static int toggle_radio_mode(void)
125 radio_mode = (radio_mode == RADIO_SCAN_MODE) ?
126 RADIO_PRESET_MODE : RADIO_SCAN_MODE;
127 return 0;
129 MENUITEM_FUNCTION_DYNTEXT(radio_mode_item, 0,
130 toggle_radio_mode, NULL,
131 get_mode_text, mode_speak_item,
132 NULL, NULL, Icon_NOICON);
133 #endif
135 MENUITEM_FUNCTION(scan_presets_item, MENU_FUNC_USEPARAM,
136 ID2P(LANG_FM_SCAN_PRESETS),
137 presets_scan, NULL, NULL, Icon_NOICON);
139 MAKE_MENU(radio_settings_menu, ID2P(LANG_FM_MENU), NULL,
140 Icon_Radio_screen,
141 #ifndef FM_PRESET
142 &radio_presets_item,
143 #endif
144 #ifndef FM_PRESET_ADD
145 &radio_addpreset_item,
146 #endif
147 &presetload_item, &presetsave_item, &presetclear_item,
148 &force_mono,
149 #ifndef FM_MODE
150 &radio_mode_item,
151 #endif
152 &set_region, &sound_settings,
153 #ifdef FM_RECORDING_SCREEN
154 &recscreen_item,
155 #endif
156 #ifdef FM_RECORDING_SETTINGS
157 &recsettings_item,
158 #endif
159 &scan_presets_item);