diff --git a/src/customers.c b/src/customers.c index 0854992..4f350bb 100644 --- a/src/customers.c +++ b/src/customers.c @@ -84,19 +84,15 @@ void customer_processes( int mode ) result_size = fread( raw_buffer, size, 1, fptr ); /* Validate csv contents. With the exception of line feeds, - * replace non printable characters with spaces and move - * to a secondary buffer. + * remove non printable characters and move to a secondary buffer. */ idx = 0; + idx2 = 0; while( idx < size ) { if( ( raw_buffer[idx] > 0x20 && raw_buffer[idx] < 0x7F ) || raw_buffer[idx] == 0x0A ) { - buffer[idx] = raw_buffer[idx]; - } - else - { - buffer[idx] = ' '; + buffer[idx2++] = raw_buffer[idx]; } idx++; } @@ -170,6 +166,9 @@ void customer_processes( int mode ) delete_customer( lines, list ); break; } + + free( raw_buffer ); + free( buffer ); } void select_customers( int count, char** customer_list_array ) diff --git a/src/gui.c b/src/gui.c index 7a8b6d4..851a2d6 100644 --- a/src/gui.c +++ b/src/gui.c @@ -144,6 +144,8 @@ const char* main_window_footer_warning_no_drive_selected = /* Oddly enough, placing extra quotes around the footer strings fixes corruption to the right * of the footer message when the terminal is resized, a quirk in ncurses? - DO NOT REMOVE THE \" */ const char* selection_footer = "J=Down K=Up Space=Select Backspace=Cancel Ctrl+C=Quit"; +const char* selection_footer_add_customer = "S=Save J=Down K=Up Space=Select Backspace=Cancel Ctrl+C=Quit"; +const char* selection_footer_add_customer_yes_no = "Save Customer Details Y/N"; const char* end_wipe_footer = "B=[Toggle between dark\\blank\\blue screen] Ctrl+C=Quit"; const char* rounds_footer = "Left=Erase Esc=Cancel Ctrl+C=Quit"; @@ -2633,11 +2635,11 @@ void nwipe_gui_config( void ) case 1: customer_processes( SELECT_CUSTOMER ); - // select_customers(); + break; case 2: - add_customer(); + nwipe_gui_add_customer(); break; case 3: @@ -3892,6 +3894,636 @@ void nwipe_gui_list( int count, char* window_title, char** list, int* selected_e } /* nwipe_gui_list */ +void nwipe_gui_add_customer( void ) +{ + /** + * Add new customer top level menu + * + */ + + extern int terminate_signal; + + /* Number of entries in the configuration menu. */ + const int count = 4; + + /* The first tabstop. */ + const int tab1 = 2; + + /* The second tabstop. */ + const int tab2 = 27; + + /* The currently selected method. */ + int focus = 0; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + char customer_name[FIELD_LENGTH] = ""; + char customer_address[FIELD_LENGTH] = ""; + char customer_contact_name[FIELD_LENGTH] = ""; + char customer_contact_phone[FIELD_LENGTH] = ""; + + /* 0 = NO = don't save, 1 = YES = save customer */ + int save = NO; + + /* 0 = Display standard dialog footer, 1 = YES = display "Save Y/N" footer */ + int yes_no = NO; + + /* variables used by libconfig for extracting data from nwipe.conf */ + config_setting_t* setting; + // const char *business_name, *business_address, *contact_name, *contact_phone, *op_tech_name; + extern config_t nwipe_cfg; + + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, selection_footer_add_customer ); + wrefresh( footer_window ); + + do + { + do + { + /* Clear the main window. */ + werase( main_window ); + + /* Change footer based on whether we are waiting for a Y/N response */ + if( yes_no == YES ) + { + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, selection_footer_add_customer_yes_no ); + wrefresh( footer_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer_add_customer_yes_no ); + } + else + { + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, selection_footer_add_customer ); + wrefresh( footer_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer_add_customer ); + } + /* Initialize the working row. */ + yy = 2; + + /* Print the options. */ + mvwprintw( main_window, yy++, tab1, " %s : %s", "Add Customer Name ", customer_name ); + mvwprintw( main_window, yy++, tab1, " %s : %s", "Add Customer Address ", customer_address ); + mvwprintw( main_window, yy++, tab1, " %s : %s", "Add Customer Contact Name ", customer_contact_name ); + mvwprintw( main_window, yy++, tab1, " %s : %s", "Add Customer Contact Phone", customer_contact_phone ); + mvwprintw( main_window, yy++, tab1, " " ); + + /* Print the cursor. */ + mvwaddch( main_window, 2 + focus, tab1, ACS_RARROW ); + + /* Add a border. */ + box( main_window, 0, 0 ); + + /* Add a title. */ + nwipe_gui_title( main_window, " PDF Report - Add New Customer " ); + + /* Refresh the window. */ + wrefresh( main_window ); + + /* Wait 250ms for input from getch, if nothing getch will then continue, + * This is necessary so that the while loop can be exited by the + * terminate_signal e.g.. the user pressing control-c to exit. + * Do not change this value, a higher value means the keys become + * sluggish, any slower and more time is spent unnecessarily looping + * which wastes CPU cycles. + */ + timeout( 250 ); /* block getch() for 250ms */ + keystroke = getch(); /* Get a keystroke. */ + timeout( -1 ); /* Switch back to blocking mode */ + + if( yes_no == NO ) + { + switch( keystroke ) + { + // Save customer + case 's': + case 'S': + break; + + case KEY_DOWN: + case 'j': + case 'J': + + if( focus < count - 1 ) + { + focus += 1; + } + break; + + case KEY_UP: + case 'k': + case 'K': + + if( focus > 0 ) + { + focus -= 1; + } + break; + + case KEY_BACKSPACE: + case KEY_BREAK: + case 27: /* ESC */ + + /* If the user has entered any text then ask if the customer entries should be saved */ + if( customer_name[0] != 0 || customer_address[0] != 0 || customer_contact_name[0] != 0 + || customer_contact_phone[0] != 0 ) + { + /* Set the footer yes/no flag */ + yes_no = YES; + } + else + { + return; + } + break; + + } /* switch */ + } + else + { + /* Waiting for a Y/N response */ + switch( keystroke ) + { + case 'y': + case 'Y': + save = 1; + break; + + case 'n': + case 'N': + return; + break; + } + } + + } while( save != YES && keystroke != 's' && keystroke != KEY_ENTER && keystroke != ' ' && keystroke != 10 + && terminate_signal != 1 ); + + if( keystroke == KEY_ENTER || keystroke == 10 || keystroke == ' ' ) + { + switch( focus ) + { + case 0: + nwipe_gui_add_customer_name( customer_name ); + keystroke = 0; + break; + + case 1: + nwipe_gui_add_customer_address( customer_address ); + keystroke = 0; + break; + + case 2: + nwipe_gui_add_customer_contact_name( customer_contact_name ); + keystroke = 0; + break; + + case 3: + nwipe_gui_add_customer_contact_phone( customer_contact_phone ); + keystroke = 0; + break; + } + } + + } while( save != YES && keystroke != 's' && keystroke != KEY_ENTER && keystroke != ' ' && keystroke != 10 + && terminate_signal != 1 ); + + /* If save customer details selected */ + if( keystroke == 's' || keystroke == 'S' || save == 1 ) + { + /* NOTE Append a csv line to /etc/nwipe/customers.csv */ + + /* NOTE ADD CODE HERE NOTE */ + } + +} /* end of nwipe_gui_add_customer( void ) */ + +void nwipe_gui_add_customer_name( char* customer_name ) +{ + /** + * Allows the user to change the customer's contact name as displayed on the PDF report. + * + * @modifies customer's contact name + * @modifies main_window + * + */ + + /* The first tabstop. */ + const int tab1 = 2; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + /* buffer index */ + int idx = 0; + + extern int terminate_signal; + + // const char* contact_name; + extern config_t nwipe_cfg; + extern char nwipe_config_file[]; + + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, rounds_footer ); + wrefresh( footer_window ); + + do + { + /* Erase the main window. */ + werase( main_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer ); + + /* Add a border. */ + box( main_window, 0, 0 ); + + /* Add a title. */ + nwipe_gui_title( main_window, " Add New Customer Name " ); + + /* Initialize the working row. */ + yy = 4; + + mvwprintw( main_window, yy++, tab1, "Enter the customer's name (business or personal name)" ); + + /* Print this line last so that the cursor is in the right place. */ + mvwprintw( main_window, 2, tab1, ">%s", customer_name ); + + /* Reveal the cursor. */ + curs_set( 1 ); + + /* Refresh the window. */ + wrefresh( main_window ); + + /* Wait 250ms for input from getch, if nothing getch will then continue, + * This is necessary so that the while loop can be exited by the + * terminate_signal e.g.. the user pressing control-c to exit. + * Do not change this value, a higher value means the keys become + * sluggish, any slower and more time is spent unnecessarily looping + * which wastes CPU cycles. + */ + timeout( 250 ); // block getch() for 250ms. + keystroke = getch(); // Get a keystroke. + timeout( -1 ); // Switch back to blocking mode. + + switch( keystroke ) + { + /* Escape key. */ + case 27: + return; + + case KEY_BACKSPACE: + case KEY_LEFT: + case 127: + + if( idx > 0 ) + { + customer_name[--idx] = 0; + } + + break; + + } /* switch keystroke */ + + if( ( keystroke >= ' ' && keystroke <= '~' ) && keystroke != '\"' && idx < FIELD_LENGTH ) + { + customer_name[idx++] = keystroke; + customer_name[idx] = 0; + mvwprintw( main_window, 2, tab1, ">%s", customer_name ); + } + + /* Hide the cursor. */ + curs_set( 0 ); + + } while( keystroke != 10 && terminate_signal != 1 ); + +} /* End of nwipe_gui_add_customer_name() */ + +void nwipe_gui_add_customer_address( char* customer_address ) +{ + /** + * Allows the user to change the customer's address as displayed on the PDF report. + * + * @modifies customer's address + * @modifies main_window + * + */ + + /* The first tabstop. */ + const int tab1 = 2; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + /* buffer index */ + int idx = 0; + + extern int terminate_signal; + + // const char* contact_name; + extern config_t nwipe_cfg; + extern char nwipe_config_file[]; + + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, rounds_footer ); + wrefresh( footer_window ); + + do + { + /* Erase the main window. */ + werase( main_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer ); + + /* Add a border. */ + box( main_window, 0, 0 ); + + /* Add a title. */ + nwipe_gui_title( main_window, " Add New Customer Address " ); + + /* Initialize the working row. */ + yy = 4; + + mvwprintw( main_window, yy++, tab1, "Enter the customer's address" ); + + /* Print this line last so that the cursor is in the right place. */ + mvwprintw( main_window, 2, tab1, ">%s", customer_address ); + + /* Reveal the cursor. */ + curs_set( 1 ); + + /* Refresh the window. */ + wrefresh( main_window ); + + /* Wait 250ms for input from getch, if nothing getch will then continue, + * This is necessary so that the while loop can be exited by the + * terminate_signal e.g.. the user pressing control-c to exit. + * Do not change this value, a higher value means the keys become + * sluggish, any slower and more time is spent unnecessarily looping + * which wastes CPU cycles. + */ + timeout( 250 ); // block getch() for 250ms. + keystroke = getch(); // Get a keystroke. + timeout( -1 ); // Switch back to blocking mode. + + switch( keystroke ) + { + /* Escape key. */ + case 27: + return; + + case KEY_BACKSPACE: + case KEY_LEFT: + case 127: + + if( idx > 0 ) + { + customer_address[--idx] = 0; + } + + break; + + } /* switch keystroke */ + + if( ( keystroke >= ' ' && keystroke <= '~' ) && keystroke != '\"' && idx < FIELD_LENGTH ) + { + customer_address[idx++] = keystroke; + customer_address[idx] = 0; + mvwprintw( main_window, 2, tab1, ">%s", customer_address ); + } + + /* Hide the cursor. */ + curs_set( 0 ); + + } while( keystroke != 10 && terminate_signal != 1 ); + +} /* End of nwipe_gui_add_customer_address() */ + +void nwipe_gui_add_customer_contact_name( char* customer_contact_name ) +{ + /** + * Allows the user to change the customer contact name as displayed on the PDF report. + * + * @modifies customer's contact name + * @modifies main_window + * + */ + + /* The first tabstop. */ + const int tab1 = 2; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + /* buffer index */ + int idx = 0; + + extern int terminate_signal; + + // const char* contact_name; + extern config_t nwipe_cfg; + extern char nwipe_config_file[]; + + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, rounds_footer ); + wrefresh( footer_window ); + + do + { + /* Erase the main window. */ + werase( main_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer ); + + /* Add a border. */ + box( main_window, 0, 0 ); + + /* Add a title. */ + nwipe_gui_title( main_window, " Add New Customer Contact Name " ); + + /* Initialize the working row. */ + yy = 4; + + mvwprintw( main_window, yy++, tab1, "Enter the customer's contact name" ); + + /* Print this line last so that the cursor is in the right place. */ + mvwprintw( main_window, 2, tab1, ">%s", customer_contact_name ); + + /* Reveal the cursor. */ + curs_set( 1 ); + + /* Refresh the window. */ + wrefresh( main_window ); + + /* Wait 250ms for input from getch, if nothing getch will then continue, + * This is necessary so that the while loop can be exited by the + * terminate_signal e.g.. the user pressing control-c to exit. + * Do not change this value, a higher value means the keys become + * sluggish, any slower and more time is spent unnecessarily looping + * which wastes CPU cycles. + */ + timeout( 250 ); // block getch() for 250ms. + keystroke = getch(); // Get a keystroke. + timeout( -1 ); // Switch back to blocking mode. + + switch( keystroke ) + { + /* Escape key. */ + case 27: + return; + + case KEY_BACKSPACE: + case KEY_LEFT: + case 127: + + if( idx > 0 ) + { + customer_contact_name[--idx] = 0; + } + + break; + + } /* switch keystroke */ + + if( ( keystroke >= ' ' && keystroke <= '~' ) && keystroke != '\"' && idx < FIELD_LENGTH ) + { + customer_contact_name[idx++] = keystroke; + customer_contact_name[idx] = 0; + mvwprintw( main_window, 2, tab1, ">%s", customer_contact_name ); + } + + /* Hide the cursor. */ + curs_set( 0 ); + + } while( keystroke != 10 && terminate_signal != 1 ); + +} /* End of nwipe_gui_add_customer_contact_name() */ + +void nwipe_gui_add_customer_contact_phone( char* customer_contact_phone ) +{ + /** + * Allows the user to change the customer contact phone as displayed on the PDF report. + * + * @modifies customer's contact phone + * @modifies main_window + * + */ + + /* The first tabstop. */ + const int tab1 = 2; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + /* buffer index */ + int idx = 0; + + extern int terminate_signal; + + // const char* contact_name; + extern config_t nwipe_cfg; + extern char nwipe_config_file[]; + + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, rounds_footer ); + wrefresh( footer_window ); + + do + { + /* Erase the main window. */ + werase( main_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer ); + + /* Add a border. */ + box( main_window, 0, 0 ); + + /* Add a title. */ + nwipe_gui_title( main_window, " Add New Customer Contact Phone " ); + + /* Initialize the working row. */ + yy = 4; + + mvwprintw( main_window, yy++, tab1, "Enter the customer's contact phone" ); + + /* Print this line last so that the cursor is in the right place. */ + mvwprintw( main_window, 2, tab1, ">%s", customer_contact_phone ); + + /* Reveal the cursor. */ + curs_set( 1 ); + + /* Refresh the window. */ + wrefresh( main_window ); + + /* Wait 250ms for input from getch, if nothing getch will then continue, + * This is necessary so that the while loop can be exited by the + * terminate_signal e.g.. the user pressing control-c to exit. + * Do not change this value, a higher value means the keys become + * sluggish, any slower and more time is spent unnecessarily looping + * which wastes CPU cycles. + */ + timeout( 250 ); // block getch() for 250ms. + keystroke = getch(); // Get a keystroke. + timeout( -1 ); // Switch back to blocking mode. + + switch( keystroke ) + { + /* Escape key. */ + case 27: + return; + + case KEY_BACKSPACE: + case KEY_LEFT: + case 127: + + if( idx > 0 ) + { + customer_contact_phone[--idx] = 0; + } + + break; + + } /* switch keystroke */ + + if( ( keystroke >= ' ' && keystroke <= '~' ) && keystroke != '\"' && idx < FIELD_LENGTH ) + { + customer_contact_phone[idx++] = keystroke; + customer_contact_phone[idx] = 0; + mvwprintw( main_window, 2, tab1, ">%s", customer_contact_phone ); + } + + /* Hide the cursor. */ + curs_set( 0 ); + + } while( keystroke != 10 && terminate_signal != 1 ); + +} /* End of nwipe_gui_add_customer_contact_phone() */ + void nwipe_gui_load( void ) { /** diff --git a/src/gui.h b/src/gui.h index a6e2305..d317fd4 100644 --- a/src/gui.h +++ b/src/gui.h @@ -61,6 +61,12 @@ void nwipe_gui_organisation_contact_name( const char* ); // Edit business conta void nwipe_gui_organisation_contact_phone( const char* ); // Edit business contact phone void nwipe_gui_organisation_op_tech_name( const char* ); // Edit the name of the operator/technician void nwipe_gui_list( int count, char* window_title, char**, int* selected_entry ); +void nwipe_gui_add_customer( void ); // Add new customer +void nwipe_gui_add_customer_name( char* ); // Add new customer name +void nwipe_gui_add_customer_address( char* ); // Add new customer address +void nwipe_gui_add_customer_contact_name( char* ); // Add new customer contact name +void nwipe_gui_add_customer_contact_phone( char* ); // Add new customer contact phone +int nwipe_gui_yes_no_footer( void ); // Change footer to yes no int spinner( nwipe_context_t** ptr, int ); // Return the next spinner character void temp1_flash( nwipe_context_t* ); // toggles term1_flash_status, which flashes the temperature @@ -89,4 +95,9 @@ void nwipe_update_speedring( nwipe_speedring_t* speedring, u64 speedring_done, t * updating */ #define GETCH_GUI_STATS_UPDATE_MS 1 /* 1 * 100 = 1/10/sec = millisecond block time for gui stats screen updates */ +#define FIELD_LENGTH 256 + +#define YES 1 +#define NO 0 + #endif /* GUI_H_ */ diff --git a/src/version.c b/src/version.c index b15fc92..f6b8f37 100644 --- a/src/version.c +++ b/src/version.c @@ -4,7 +4,7 @@ * used by configure to dynamically assign those values * to documentation files. */ -const char* version_string = "0.34.88 Development code, not for production use!"; +const char* version_string = "0.34.90 Development code, not for production use!"; const char* program_name = "nwipe"; const char* author_name = "Martijn van Brummelen"; const char* email_address = "git@brumit.nl"; @@ -14,4 +14,4 @@ Modifications to original dwipe Copyright Andy Beverley \n\ This is free software; see the source for copying conditions.\n\ There is NO warranty; not even for MERCHANTABILITY or FITNESS\n\ FOR A PARTICULAR PURPOSE.\n"; -const char* banner = "nwipe 0.34.89 Development code, not for production use!"; +const char* banner = "nwipe 0.34.90 Development code, not for production use!";