Browse Source

Alert when saving settings fails

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
65e97c4f22
1 changed files with 27 additions and 5 deletions
  1. 27
    5
      src/hci/tui/settings_ui.c

+ 27
- 5
src/hci/tui/settings_ui.c View File

16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
  */
17
  */
18
 
18
 
19
+#include <unistd.h>
19
 #include <string.h>
20
 #include <string.h>
20
 #include <curses.h>
21
 #include <curses.h>
21
 #include <console.h>
22
 #include <console.h>
35
 #define CPAIR_NORMAL	1
36
 #define CPAIR_NORMAL	1
36
 #define CPAIR_SELECT	2
37
 #define CPAIR_SELECT	2
37
 #define CPAIR_EDIT	3
38
 #define CPAIR_EDIT	3
39
+#define CPAIR_ALERT	4
38
 
40
 
39
 /* Screen layout */
41
 /* Screen layout */
40
 #define SETTINGS_LIST_ROW	3
42
 #define SETTINGS_LIST_ROW	3
41
 #define SETTINGS_LIST_COL	1
43
 #define SETTINGS_LIST_COL	1
44
+#define ALERT_ROW		20
42
 
45
 
43
 /** Layout of text within a setting widget */
46
 /** Layout of text within a setting widget */
44
 struct setting_row {
47
 struct setting_row {
107
  * @v widget		Setting widget
110
  * @v widget		Setting widget
108
  */
111
  */
109
 static int save_setting ( struct setting_widget *widget ) {
112
 static int save_setting ( struct setting_widget *widget ) {
110
-	widget->editing = 0;
111
 	return widget->setting->type->set ( widget->context, widget->setting,
113
 	return widget->setting->type->set ( widget->context, widget->setting,
112
 					    widget->value );
114
 					    widget->value );
113
 }
115
 }
203
 		       ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
205
 		       ( SETTINGS_LIST_ROW + index ), SETTINGS_LIST_COL );
204
 }
206
 }
205
 
207
 
208
+static void alert ( const char *fmt, ... ) {
209
+	char buf[COLS];
210
+	va_list args;
211
+	size_t len;
212
+
213
+	va_start ( args, fmt );
214
+	len = vsnprintf ( buf, sizeof ( buf ), fmt, args );
215
+	va_end ( args );
216
+
217
+	color_set ( CPAIR_ALERT, NULL );
218
+	mvprintw ( ALERT_ROW, ( ( COLS - len ) / 2 ), "%s", buf );
219
+	sleep ( 2 );
220
+	color_set ( CPAIR_NORMAL, NULL );
221
+	move ( ALERT_ROW, 0 );
222
+	clrtoeol();
223
+}
224
+
206
 static void main_loop ( struct config_context *context ) {
225
 static void main_loop ( struct config_context *context ) {
207
 	struct setting_widget widget;
226
 	struct setting_widget widget;
208
 	unsigned int current = 0;
227
 	unsigned int current = 0;
231
 			switch ( key ) {
250
 			switch ( key ) {
232
 			case 0x0a: /* Enter */
251
 			case 0x0a: /* Enter */
233
 				if ( ( rc = save_setting ( &widget ) ) != 0 ) {
252
 				if ( ( rc = save_setting ( &widget ) ) != 0 ) {
234
-					
253
+					alert ( " Could not set %s: %s ",
254
+						widget.setting->name,
255
+						strerror ( -rc ) );
235
 				}
256
 				}
236
-				break;
257
+				/* Fall through */
237
 			case 0x03: /* Ctrl-C */
258
 			case 0x03: /* Ctrl-C */
238
 				load_setting ( &widget );
259
 				load_setting ( &widget );
239
 				break;
260
 				break;
274
 	initscr();
295
 	initscr();
275
 	start_color();
296
 	start_color();
276
 	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
297
 	init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLUE );
277
-	init_pair ( CPAIR_SELECT, COLOR_WHITE, COLOR_RED );
278
-	init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_GREEN );
298
+	init_pair ( CPAIR_SELECT, COLOR_BLACK, COLOR_WHITE );
299
+	init_pair ( CPAIR_EDIT, COLOR_BLACK, COLOR_CYAN );
300
+	init_pair ( CPAIR_ALERT, COLOR_WHITE, COLOR_RED );
279
 	color_set ( CPAIR_NORMAL, NULL );
301
 	color_set ( CPAIR_NORMAL, NULL );
280
 	erase();
302
 	erase();
281
 	
303
 	

Loading…
Cancel
Save