forked from grantrostig/file_maintenance_clipped
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathactions.cpp
More file actions
115 lines (101 loc) · 5.71 KB
/
actions.cpp
File metadata and controls
115 lines (101 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <arpa/inet.h>
#include <cassert>
#include <fstream>
#include <iostream>
#include "global_entities.h"
#include "actions.h"
#include "action_dialog.h"
#include "interaction_result.h"
// BEGIN OF SNIP TODO
// END OF SNIP
using std::cin, std::cout, std::endl, std::cerr, std::clog;
InteractionResult action_delete_all( State_menu & state ) {
cerr << "int action_delete_all( State &) {" << endl;
// TODO: delete all
state.getApplication_data_sp()->setIs_data_unsaved(true);
InteractionResult ir = action_dialog_modal_notify( state, "All user data have been removed from the memory of the application. If you save now, the saved file will be empty.");
return ir;
}
InteractionResult action_save_as_changes_to_disk( State_menu & state ) {
cerr << "int action_save_changes_to_disk( State &) " << endl;
//cerr << "saving application data: "<<state.getApplication_data()->getInt_data()<<endl;
// TODO: get file name
InteractionResult ir = action_save_changes_to_disk( state );
return ir;
}
std::streamoff size_of_data( std::iostream & stream ) {
auto old_exceptions { stream.exceptions() };
stream.exceptions(stream.exceptions()|(std::ios_base::failbit & std::ios_base::badbit));
stream.seekg( 0, std::ios_base::end ); // https://stackoverflow.com/questions/4432793/size-of-stringstream/4432843#4432843
std::streamoff size { stream.tellg() };
stream.seekg( 0, std::ios_base::beg );
stream.exceptions(old_exceptions);
return size;
}
InteractionResult action_save_changes_to_disk( State_menu & state ) {
// disk file layout: version_size char, version char*,
// adata_size uint16, adata_serialized char*,
// pdata_size uint32, pdata_serialized_char*,
InteractionResult ir {}; // to be returned
InteractionResult ir_temp {}; // temporary for handling intermediate values.
Lib_tty::InteractionIntentNav nav {};
cerr << "int action_save_changes_to_disk( State &) " << endl;
// if ( io_table_persons.rows.size() == 0 ) ir = action_dialog_modal_deny( state, "Warning: there are no data records to save, do you wish to proceed?: ");
// if ( ir.hot_key_row != proceed ) { TODO: //ir = ?; //return ir; //}
// BEGIN OF SNIP TODO
// END OF SNIP
state.getApplication_data_sp()->setIs_data_unsaved( false );
state.action_push( InteractionCategory::dialogn ); // Next 3 lines are one unit.
ir_temp = action_dialog_modal_notify( state, "All user and relevant program data have been saved to disk." );
nav = find_interaction_result_nav( ir_temp.hot_key_row, state.action_top() );
ir.navigation = nav;
return ir;
}
InteractionResult action_load_data_from_disk( State_menu & state) {
InteractionResult ir {};
if ( not state.getApplication_data_sp()->getIs_data_unsaved() ) {
// TODO: verify with user if unsaved data existing.
}
// try { // to catch IO bad() errors.
cerr << "int action_load_data_from_disk( State &) " << endl;
std::ifstream ifstream_adata_pdata { DEFAULT_FILE_NAME, std::ios_base::binary | std::ios_base::in };
if ( ifstream_adata_pdata.fail() || ifstream_adata_pdata.bad() ) {
ir = action_dialog_modal_notify( state, "Error: cannot open file, no data such file exists, or you don't have permission to read it."); // TODO: I just return after failure? Is there a subtle issue with any returned hot key? Should it be cleared?
return ir;
}
// BEGIN OF SNIP TODO
// END OF SNIP
state.getApplication_data_sp()->setIs_data_unsaved(false);
ir = action_dialog_modal_notify( state, "All user data have been loaded from disk, replacing any prior data.");
Lib_tty::InteractionIntentNav nav = find_interaction_result_nav( ir.hot_key_row, InteractionCategory::menu );
ir.navigation = nav;
return ir;
}
//also need: InteractionResult action_save_as_data_from_disk( State_menu & state) { // save to a new or existing file, which is not from the current name.
InteractionResult action_load_as_data_from_disk( State_menu & state) { // load from an existing file, which is not from the current name.
cerr << "int action_load_as_data_from_disk( State &) " << endl;
//TODO: get file name, also decide if new name and location is new default?
InteractionResult ir = action_load_data_from_disk( state );
ir = action_dialog_modal_notify( state, "All user data have been loaded from disk. Note: Please take care where you will save the data. TODO TODO!!!! !");
Lib_tty::InteractionIntentNav nav = find_interaction_result_nav( ir.hot_key_row, InteractionCategory::menu );
ir.navigation = nav;
return ir;
}
InteractionResult action_backup_data( State_menu & state ) {
cerr << "int action_backup_data( State &) " << endl;
// TODO: do something.
InteractionResult ir = action_dialog_modal_notify( state, "All user data have been backed up to disk in a backup format. Note: data have not been saved in the normal format in the normal location. Please also normally save any data you wish to save for normal use of the application!");
Lib_tty::InteractionIntentNav nav = find_interaction_result_nav( ir.hot_key_row, InteractionCategory::menu );
ir.navigation = nav;
return ir;
}
InteractionResult action_screen_size( State_menu &) {
cerr << "int action_screen_size( State &) " << endl;
// TODO: do something
return InteractionResult { {}, {}, {}, {}, Lib_tty::InteractionIntentNav::retain_menu };
}
InteractionResult action_advanced_settings_selection( State_menu &) {
cerr << "int action_advanced_settings_selection:" << endl;
// TODO: do something
return InteractionResult { {}, {}, {}, {}, Lib_tty::InteractionIntentNav::retain_menu };
}