|
@@ -66,6 +66,8 @@ struct setting_row {
|
66
|
66
|
struct setting_widget {
|
67
|
67
|
/** Settings block */
|
68
|
68
|
struct settings *settings;
|
|
69
|
+ /** Number of applicable settings */
|
|
70
|
+ unsigned int num_settings;
|
69
|
71
|
/** Index of the first visible setting, for scrolling. */
|
70
|
72
|
unsigned int first_visible;
|
71
|
73
|
/** Configuration setting */
|
|
@@ -82,9 +84,6 @@ struct setting_widget {
|
82
|
84
|
char value[256]; /* enough size for a DHCP string */
|
83
|
85
|
};
|
84
|
86
|
|
85
|
|
-/** Number of registered configuration settings */
|
86
|
|
-#define NUM_SETTINGS table_num_entries ( SETTINGS )
|
87
|
|
-
|
88
|
87
|
static void load_setting ( struct setting_widget *widget ) __nonnull;
|
89
|
88
|
static int save_setting ( struct setting_widget *widget ) __nonnull;
|
90
|
89
|
static void init_widget ( struct setting_widget *widget,
|
|
@@ -143,8 +142,14 @@ static int save_setting ( struct setting_widget *widget ) {
|
143
|
142
|
*/
|
144
|
143
|
static void init_widget ( struct setting_widget *widget,
|
145
|
144
|
struct settings *settings ) {
|
|
145
|
+ struct setting *setting;
|
|
146
|
+
|
146
|
147
|
memset ( widget, 0, sizeof ( *widget ) );
|
147
|
148
|
widget->settings = settings;
|
|
149
|
+ for_each_table_entry ( setting, SETTINGS ) {
|
|
150
|
+ if ( setting_applies ( settings, setting ) )
|
|
151
|
+ widget->num_settings++;
|
|
152
|
+ }
|
148
|
153
|
widget->first_visible = SETTINGS_LIST_ROWS;
|
149
|
154
|
reveal ( widget, 0 );
|
150
|
155
|
}
|
|
@@ -210,14 +215,18 @@ static int edit_setting ( struct setting_widget *widget, int key ) {
|
210
|
215
|
*/
|
211
|
216
|
static void select_setting ( struct setting_widget *widget,
|
212
|
217
|
unsigned int index ) {
|
213
|
|
- struct setting *all_settings = table_start ( SETTINGS );
|
214
|
218
|
unsigned int skip = offsetof ( struct setting_widget, setting );
|
215
|
219
|
|
216
|
220
|
/* Reset the widget, preserving static state. */
|
217
|
221
|
memset ( ( char * ) widget + skip, 0, sizeof ( *widget ) - skip );
|
218
|
|
- widget->setting = &all_settings[index];
|
219
|
222
|
widget->row = SETTINGS_LIST_ROW + index - widget->first_visible;
|
220
|
223
|
widget->col = SETTINGS_LIST_COL;
|
|
224
|
+ for_each_table_entry ( widget->setting, SETTINGS ) {
|
|
225
|
+ if ( ! setting_applies ( widget->settings, widget->setting ) )
|
|
226
|
+ continue;
|
|
227
|
+ if ( index-- == 0 )
|
|
228
|
+ break;
|
|
229
|
+ }
|
221
|
230
|
|
222
|
231
|
/* Read current setting value */
|
223
|
232
|
load_setting ( widget );
|
|
@@ -359,13 +368,12 @@ static void reveal ( struct setting_widget *widget, unsigned int n)
|
359
|
368
|
widget->first_visible > 0 ? "..." : " " );
|
360
|
369
|
mvaddstr ( SETTINGS_LIST_ROW + SETTINGS_LIST_ROWS,
|
361
|
370
|
SETTINGS_LIST_COL + 1,
|
362
|
|
- ( widget->first_visible + SETTINGS_LIST_ROWS < NUM_SETTINGS
|
363
|
|
- ? "..."
|
364
|
|
- : " " ) );
|
|
371
|
+ ( ( widget->first_visible + SETTINGS_LIST_ROWS )
|
|
372
|
+ < widget->num_settings ? "..." : " " ) );
|
365
|
373
|
|
366
|
374
|
/* Draw visible settings. */
|
367
|
375
|
for ( i = 0; i < SETTINGS_LIST_ROWS; i++ ) {
|
368
|
|
- if ( widget->first_visible + i < NUM_SETTINGS ) {
|
|
376
|
+ if ( ( widget->first_visible + i ) < widget->num_settings ) {
|
369
|
377
|
select_setting ( widget, widget->first_visible + i );
|
370
|
378
|
draw_setting ( widget );
|
371
|
379
|
} else {
|
|
@@ -424,7 +432,7 @@ static int main_loop ( struct settings *settings ) {
|
424
|
432
|
next = current;
|
425
|
433
|
switch ( key ) {
|
426
|
434
|
case KEY_DOWN:
|
427
|
|
- if ( next < ( NUM_SETTINGS - 1 ) )
|
|
435
|
+ if ( next < ( widget.num_settings - 1 ) )
|
428
|
436
|
reveal ( &widget, ++next );
|
429
|
437
|
break;
|
430
|
438
|
case KEY_UP:
|