From 247cf3031bf68e788d25e6870dcb5024850b984f Mon Sep 17 00:00:00 2001 From: PartialVolume <22084881+PartialVolume@users.noreply.github.com> Date: Thu, 13 Jul 2023 22:28:23 +0100 Subject: [PATCH] PDFGen20 Started creating new GUI dialogs. A Configuration Dialog and sub dialogs for allowing the user to enter business and customer details. Further dialog windows and code to be added... --- src/gui.c | 479 +++++++++++++++++++++++++++++++++++++++++++++++++- src/gui.h | 3 + src/version.c | 4 +- 3 files changed, 483 insertions(+), 3 deletions(-) diff --git a/src/gui.c b/src/gui.c index f4ff5f0..4ecd54c 100644 --- a/src/gui.c +++ b/src/gui.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "nwipe.h" #include "context.h" @@ -126,7 +127,8 @@ const char* options_title = " Options "; const char* stats_title = " Statistics "; /* Footer labels. */ -const char* main_window_footer = "S=Start m=Method p=PRNG v=Verify r=Rounds b=Blanking Space=Select CTRL+C=Quit"; +const char* main_window_footer = + "S=Start m=Method p=PRNG v=Verify r=Rounds b=Blanking Space=Select c=config CTRL+C=Quit"; const char* main_window_footer_warning_lower_case_s = " WARNING: To start the wipe press SHIFT+S (uppercase S) "; const char* main_window_footer_warning_no_blanking_with_ops2 = @@ -1227,6 +1229,14 @@ void nwipe_gui_select( int count, nwipe_context_t** c ) nwipe_gui_noblank(); break; + case 'c': + /* main configuration menu */ + validkeyhit = 1; + + /* Run the configuration dialog */ + nwipe_gui_config(); + break; + case 'S': /* User wants to start the wipe */ @@ -2452,6 +2462,473 @@ void nwipe_gui_method( void ) } /* nwipe_gui_method */ +void nwipe_gui_config( void ) +{ + /** + * Display the configuration Main Menu selection window + * + */ + + extern int terminate_signal; + + /* Number of entries in the configuration menu. */ + const int count = 3; + + /* The first tabstop. */ + const int tab1 = 2; + + /* The second tabstop. */ + const int tab2 = 40; + + /* The currently selected method. */ + int focus = 0; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, selection_footer ); + wrefresh( footer_window ); + + do + { + /* Clear the main window. */ + werase( main_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer ); + + /* Initialize the working row. */ + yy = 2; + + /* Print the options. */ + mvwprintw( main_window, yy++, tab1, " %s", "PDF Report - Edit Organisation" ); + mvwprintw( main_window, yy++, tab1, " %s", "PDF Report - Add Customer " ); + mvwprintw( main_window, yy++, tab1, " %s", "PDF Report - Delete Customer " ); + mvwprintw( main_window, yy++, tab1, " " ); + + /* Print the cursor. */ + mvwaddch( main_window, 2 + focus, tab1, ACS_RARROW ); + + switch( focus ) + { + case 0: + + mvwprintw( main_window, 2, tab2, "PDF Report - Edit Organisation" ); + + mvwprintw( main_window, 4, tab2, "This option allows you to edit details" ); + mvwprintw( main_window, 5, tab2, "of the organisation that is performing" ); + mvwprintw( main_window, 6, tab2, "the erasure. This includes: business " ); + mvwprintw( main_window, 7, tab2, "name, business address, contact name " ); + mvwprintw( main_window, 8, tab2, "and contact phone. " ); + break; + + case 1: + + mvwprintw( main_window, 2, tab2, "PDF Report - Add Customer " ); + + mvwprintw( main_window, 4, tab2, "This option allows you to add a new " ); + mvwprintw( main_window, 5, tab2, "customer. A customer can be optionally" ); + mvwprintw( main_window, 6, tab2, "displayed on the PDF report. Customer " ); + mvwprintw( main_window, 7, tab2, "information includes Name (This can be" ); + mvwprintw( main_window, 8, tab2, "a personal or business name), address " ); + mvwprintw( main_window, 9, tab2, "contact name and contact phone. " ); + mvwprintw( main_window, 10, tab2, " " ); + mvwprintw( main_window, 11, tab2, "Customer data is saved in: " ); + mvwprintw( main_window, 12, tab2, "/etc/nwipe/nwipe_customers.csv " ); + break; + + case 2: + + mvwprintw( main_window, 2, tab2, "PDF Report - Delete Customer " ); + + mvwprintw( main_window, 4, tab2, "This option allows you to delete a " ); + mvwprintw( main_window, 5, tab2, "customer. A customer can be optionally" ); + mvwprintw( main_window, 6, tab2, "displayed on the PDF report. Customer " ); + mvwprintw( main_window, 7, tab2, "information includes Name (This can be" ); + mvwprintw( main_window, 8, tab2, "a personal or business name), address " ); + mvwprintw( main_window, 9, tab2, "contact name and contact phone. " ); + mvwprintw( main_window, 10, tab2, " " ); + mvwprintw( main_window, 11, tab2, "Customer data is saved in: " ); + mvwprintw( main_window, 12, tab2, "/etc/nwipe/nwipe_customers.csv " ); + break; + + } /* switch */ + + /* Add a border. */ + box( main_window, 0, 0 ); + + /* Add a title. */ + nwipe_gui_title( main_window, " Configuration " ); + + /* 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 ) + { + 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: + + return; + + } /* switch */ + + } while( keystroke != KEY_ENTER && keystroke != ' ' && keystroke != 10 && terminate_signal != 1 ); + + switch( focus ) + { + case 0: + nwipe_gui_edit_organisation(); + break; + + case 1: + // nwipe_options.method = &nwipe_one; + break; + + case 2: + // nwipe_options.method = &nwipe_ops2; + break; + } + +} /* end of nwipe_config() */ + +void nwipe_gui_edit_organisation( void ) +{ + /** + * Display the list of organisation details available for editing + * + */ + + 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 = 40; + + /* The currently selected method. */ + int focus = 0; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + /* variables used by libconfig for extracting data from nwipe.conf */ + config_setting_t* setting; + const char *business_name, *business_address, *contact_name, *contact_phone; + extern config_t nwipe_cfg; + + /* Update the footer window. */ + werase( footer_window ); + nwipe_gui_title( footer_window, selection_footer ); + wrefresh( footer_window ); + + do + { + /* Clear the main window. */ + werase( main_window ); + + nwipe_gui_create_all_windows_on_terminal_resize( 0, selection_footer ); + + /* Initialize the working row. */ + yy = 2; + + /* Print the options. */ + mvwprintw( main_window, yy++, tab1, " %s", "PDF Report - Edit Business Name" ); + mvwprintw( main_window, yy++, tab1, " %s", "PDF Report - Edit Business Address" ); + mvwprintw( main_window, yy++, tab1, " %s", "PDF Report - Edit Contact Name" ); + mvwprintw( main_window, yy++, tab1, " %s", "PDF Report - Edit Contact Phone" ); + mvwprintw( main_window, yy++, tab1, " " ); + + /* Print the cursor. */ + mvwaddch( main_window, 2 + focus, tab1, ACS_RARROW ); + + /* libconfig: Locate the Organisation Details section in nwipe.conf */ + setting = config_lookup( &nwipe_cfg, "Organisation_Details" ); + + /* Retrieve data from nwipe.conf */ + if( config_setting_lookup_string( setting, "Business_Name", &business_name ) ) + { + mvwprintw( main_window, 2, tab2, ": %s", business_name ); + } + else + { + mvwprintw( main_window, 2, tab2, ": [Error] Cannot retrieve from nwipe.conf" ); + } + + /* Retrieve data from nwipe.conf */ + if( config_setting_lookup_string( setting, "Business_Address", &business_address ) ) + { + mvwprintw( main_window, 3, tab2, ": %s", business_address ); + } + else + { + mvwprintw( main_window, 3, tab2, ": [Error] Cannot retrieve from nwipe.conf" ); + } + + /* Retrieve data from nwipe.conf */ + if( config_setting_lookup_string( setting, "Contact_Name", &contact_name ) ) + { + mvwprintw( main_window, 4, tab2, ": %s", contact_name ); + } + else + { + mvwprintw( main_window, 4, tab2, ": [Error] Cannot retrieve from nwipe.conf" ); + } + + /* Retrieve data from nwipe.conf */ + if( config_setting_lookup_string( setting, "Contact_Phone", &contact_phone ) ) + { + mvwprintw( main_window, 5, tab2, ": %s", contact_phone ); + } + else + { + mvwprintw( main_window, 5, tab2, ": [Error] Cannot retrieve from nwipe.conf" ); + } + + /* Add a border. */ + box( main_window, 0, 0 ); + + /* Add a title. */ + nwipe_gui_title( main_window, " PDF Report - Edit Organisation " ); + + /* 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 ) + { + 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: + + return; + + } /* switch */ + + } while( keystroke != KEY_ENTER && keystroke != ' ' && keystroke != 10 && terminate_signal != 1 ); + + switch( focus ) + { + case 0: + nwipe_gui_organisation_business_name(); + // nwipe_options.method = &nwipe_zero; + break; + + case 1: + nwipe_options.method = &nwipe_one; + break; + + case 2: + nwipe_options.method = &nwipe_ops2; + break; + } + +} /* end of nwipe_gui_edit_organisation( void ) */ + +void nwipe_gui_organisation_business_name( void ) +{ + /** + * Allows the user to change the organisation business name as displayed on the PDF report. + * + * @modifies business_name in nwipe.conf + * @modifies main_window + * + */ + + /* The first tabstop. */ + const int tab1 = 2; + + /* The current working row. */ + int yy; + + /* Input buffer. */ + int keystroke; + + /* buffer */ + char buffer[256] = ""; + + /* buffer index */ + int idx = 0; + + extern int terminate_signal; + + /* variables used by libconfig for inserting data into nwipe.conf */ + config_setting_t* setting; + const char* business_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, " Edit Organisation Business Name " ); + + /* Initialize the working row. */ + yy = 4; + + mvwprintw( main_window, yy++, tab1, "Enter the business name of the organisation performing the erasure" ); + + /* Print this line last so that the cursor is in the right place. */ + mvwprintw( main_window, 2, tab1, ">%s", buffer ); + + /* 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 ) + { + buffer[--idx] = 0; + } + + break; + + } /* switch keystroke */ + + if( ( keystroke >= ' ' && keystroke <= '~' ) && keystroke != '\"' && idx < 255 ) + { + buffer[idx++] = keystroke; + buffer[idx] = 0; + mvwprintw( main_window, 2, tab1, ">%s", buffer ); + } + + /* Hide the cursor. */ + curs_set( 0 ); + + } while( keystroke != 10 && terminate_signal != 1 ); + + /* libconfig: Locate the Organisation Details section in nwipe.conf */ + if( !( setting = config_lookup( &nwipe_cfg, "Organisation_Details.Business_Name" ) ) ) + { + nwipe_log( NWIPE_LOG_ERROR, "Failed to locate [Organisation_Details.Business_Name] in %s", nwipe_config_file ); + } + + /* libconfig: Write the new business name */ + if( config_setting_set_string( setting, buffer ) == CONFIG_FALSE ) + { + nwipe_log( NWIPE_LOG_ERROR, + "Failed to write [%s] to [Organisation_Details.Business_Name] in %s", + buffer, + nwipe_config_file ); + } + + /* Write out the new configuration. */ + if( config_write_file( &nwipe_cfg, nwipe_config_file ) == CONFIG_FALSE ) + { + nwipe_log( NWIPE_LOG_ERROR, "Failed to write organisation business name to %s", nwipe_config_file ); + } + else + { + nwipe_log( NWIPE_LOG_INFO, "[Success] Business name written to %s", nwipe_config_file ); + } + +} /* End of nwipe_gui_organisation_business_name() */ + void nwipe_gui_load( void ) { /** diff --git a/src/gui.h b/src/gui.h index c2fb50a..cc1e85d 100644 --- a/src/gui.h +++ b/src/gui.h @@ -53,6 +53,9 @@ void nwipe_gui_prng( void ); // Change the prng option. void nwipe_gui_rounds( void ); // Change the rounds option. void nwipe_gui_verify( void ); // Change the verify option. void nwipe_gui_noblank( void ); // Change the noblank option. +void nwipe_gui_config( void ); // Change the nwipe settings +void nwipe_gui_edit_organisation( void ); // Edit organisation details +void nwipe_gui_organisation_business_name( void ); // Edit organisation business name 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 diff --git a/src/version.c b/src/version.c index 418fcc0..588f641 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.87 Development code, not for production use!"; +const char* version_string = "0.34.88 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.87 Development code, not for production use!"; +const char* banner = "nwipe 0.34.88 Development code, not for production use!";