login_ui.h File Reference

Login UI. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int login_ui (void)


Detailed Description

Login UI.

Definition in file login_ui.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

int login_ui ( void   ) 

Definition at line 50 of file login_ui.c.

References COLOR_BLACK, COLOR_BLUE, color_set, COLOR_WHITE, CPAIR_EDITBOX, CPAIR_LABEL, CPAIR_NORMAL, CTRL_C, draw_editbox(), ECANCELED, edit_editbox(), EDITBOX_COL, EDITBOX_STARS, EDITBOX_WIDTH, EINPROGRESS, endwin(), erase(), ESC, fetch_string_setting(), getkey(), init_editbox(), init_pair(), initscr(), KEY_DOWN, KEY_ENTER, KEY_UP, LABEL_COL, mvprintw, NULL, PASSWORD_LABEL_ROW, PASSWORD_ROW, start_color, store_setting(), strlen(), TAB, USERNAME_LABEL_ROW, and USERNAME_ROW.

Referenced by login_exec().

00050                       {
00051         char username[64];
00052         char password[64];
00053         struct edit_box username_box;
00054         struct edit_box password_box;
00055         struct edit_box *current_box = &username_box;
00056         int key;
00057         int rc = -EINPROGRESS;
00058 
00059         /* Fetch current setting values */
00060         fetch_string_setting ( NULL, &username_setting, username,
00061                                sizeof ( username ) );
00062         fetch_string_setting ( NULL, &password_setting, password,
00063                                sizeof ( password ) );
00064 
00065         /* Initialise UI */
00066         initscr();
00067         start_color();
00068         init_pair ( CPAIR_NORMAL, COLOR_WHITE, COLOR_BLACK );
00069         init_pair ( CPAIR_LABEL, COLOR_WHITE, COLOR_BLACK );
00070         init_pair ( CPAIR_EDITBOX, COLOR_WHITE, COLOR_BLUE );
00071         init_editbox ( &username_box, username, sizeof ( username ), NULL,
00072                        USERNAME_ROW, EDITBOX_COL, EDITBOX_WIDTH, 0 );
00073         init_editbox ( &password_box, password, sizeof ( password ), NULL,
00074                        PASSWORD_ROW, EDITBOX_COL, EDITBOX_WIDTH,
00075                        EDITBOX_STARS );
00076 
00077         /* Draw initial UI */
00078         erase();
00079         color_set ( CPAIR_LABEL, NULL );
00080         mvprintw ( USERNAME_LABEL_ROW, LABEL_COL, "Username:" );
00081         mvprintw ( PASSWORD_LABEL_ROW, LABEL_COL, "Password:" );
00082         color_set ( CPAIR_EDITBOX, NULL );
00083         draw_editbox ( &username_box );
00084         draw_editbox ( &password_box );
00085 
00086         /* Main loop */
00087         while ( rc == -EINPROGRESS ) {
00088 
00089                 draw_editbox ( current_box );
00090 
00091                 key = getkey();
00092                 switch ( key ) {
00093                 case KEY_DOWN:
00094                         current_box = &password_box;
00095                         break;
00096                 case KEY_UP:
00097                         current_box = &username_box;
00098                         break;
00099                 case TAB:
00100                         current_box = ( ( current_box == &username_box ) ?
00101                                         &password_box : &username_box );
00102                         break;
00103                 case KEY_ENTER:
00104                         if ( current_box == &username_box ) {
00105                                 current_box = &password_box;
00106                         } else {
00107                                 rc = 0;
00108                         }
00109                         break;
00110                 case CTRL_C:
00111                 case ESC:
00112                         rc = -ECANCELED;
00113                         break;
00114                 default:
00115                         edit_editbox ( current_box, key );
00116                         break;
00117                 }
00118         }
00119 
00120         /* Terminate UI */
00121         color_set ( CPAIR_NORMAL, NULL );
00122         erase();
00123         endwin();
00124 
00125         if ( rc != 0 )
00126                 return rc;
00127 
00128         /* Store settings */
00129         if ( ( rc = store_setting ( NULL, &username_setting, username,
00130                                     strlen ( username ) ) ) != 0 )
00131                 return rc;
00132         if ( ( rc = store_setting ( NULL, &password_setting, password,
00133                                     strlen ( password ) ) ) != 0 )
00134                 return rc;
00135 
00136         return 0;
00137 }


Generated on Tue Apr 6 20:01:51 2010 for gPXE by  doxygen 1.5.7.1