fully implemented user menu

This commit is contained in:
Hendrik Schutter 2020-08-09 23:05:32 +02:00
parent c2ab7c1c7f
commit cf2bb664d7
3 changed files with 84 additions and 25 deletions

View File

@ -28,7 +28,6 @@ public:
bool bAbort; bool bAbort;
bool bShred; bool bShred;
bool bDelete; bool bDelete;
bool bConfirmAbort;
bool bConfirmShred; bool bConfirmShred;
bool bConfirmDelete; bool bConfirmDelete;
}; };
@ -50,6 +49,7 @@ private:
WINDOW* overview; WINDOW* overview;
WINDOW* systemview; WINDOW* systemview;
WINDOW* menuview; WINDOW* menuview;
WINDOW* dialog;
static void centerTitle(WINDOW *pwin, const char * title); static void centerTitle(WINDOW *pwin, const char * title);
static WINDOW *createOverViewWindow( int iXSize, int iYSize); static WINDOW *createOverViewWindow( int iXSize, int iYSize);
@ -57,6 +57,7 @@ private:
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity, bool bSelected); static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity, bool bSelected);
static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart); static WINDOW *createSystemStats(int iXSize, int iYSize, int iYStart);
static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate); static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate);
}; static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB);
};
#endif // TUI_H_ #endif // TUI_H_

View File

@ -70,6 +70,7 @@ void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry, struct
menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate); menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate);
wrefresh(menuview); wrefresh(menuview);
vector <Drive>::iterator it; vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{ {
@ -84,6 +85,21 @@ void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry, struct
bSelectedEntry = true; bSelectedEntry = true;
detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5, pvecDrives->at((it - pvecDrives->begin()))); detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5, pvecDrives->at((it - pvecDrives->begin())));
wrefresh(detailview); wrefresh(detailview);
if(menustate.bConfirmShred == true)
{
dialog=createDialog(70, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm SHRED", "Press ENTER for SHRED" , "Press ESC for cancel");
wrefresh(dialog);
}
else if(menustate.bConfirmDelete == true)
{
dialog=createDialog(70, 10, ((stdscrX)-(int)(stdscrX/3)-7)-(int)((stdscrX/3)+5)/2,(int)(stdscrY/2)-5, "Confirm DELETE", "Press ENTER for DELETE" , "Press ESC for cancel");
wrefresh(dialog);
}
else
{
delwin(dialog);
}
} }
WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, bSelectedEntry); WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, bSelectedEntry);
@ -296,18 +312,23 @@ WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st
{ {
mvwaddstr(newWindow,u16Line++, 3, "Press D for Delete"); mvwaddstr(newWindow,u16Line++, 3, "Press D for Delete");
} }
if (menustate.bConfirmAbort) keypad(newWindow, TRUE);
{ return newWindow;
mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Abort or ESC to return"); }
}
if (menustate.bConfirmShred) WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string task, string optionA, string optionB)
{ {
mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Shred or ESC to return"); WINDOW *newWindow;
} newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
if (menustate.bConfirmDelete)
{ wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY_SELECTED));
mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Delete or ESC to return"); box(newWindow, ACS_VLINE, ACS_HLINE);
}
centerTitle(newWindow, task.c_str());
uint16_t u16Line = 2;
mvwaddstr(newWindow,u16Line++, 3, optionA.c_str());
mvwaddstr(newWindow,u16Line++, 3, optionB.c_str());
keypad(newWindow, TRUE); keypad(newWindow, TRUE);
return newWindow; return newWindow;

View File

@ -37,6 +37,8 @@ reHDD::reHDD(void)
{ {
cout << "created app" << endl; cout << "created app" << endl;
i32SelectedEntry = 0; i32SelectedEntry = 0;
menustate.bDelete = true;
menustate.bShred = true;
} }
/** /**
@ -126,36 +128,44 @@ void reHDD::ThreadUserInput()
break; break;
case TUI::UserInput::Abort: case TUI::UserInput::Abort:
//cout << "Abort" << endl; //cout << "Abort" << endl;
handleAbort(); handleAbort();
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
break; break;
case TUI::UserInput::Delete: case TUI::UserInput::Delete:
//cout << "Delete" << endl; //cout << "Delete" << endl;
if(SELECTED_DRIVE.state == Drive::NONE) if(SELECTED_DRIVE.state == Drive::NONE)
{ {
SELECTED_DRIVE.state = Drive::DELETE_SELECTED; SELECTED_DRIVE.state = Drive::DELETE_SELECTED;
menustate.bAbort = false;
menustate.bDelete = false;
menustate.bShred = false;
menustate.bConfirmDelete = true;
menustate.bConfirmShred = false;
} }
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
break; break;
case TUI::UserInput::Shred: case TUI::UserInput::Shred:
//cout << "Shred" << endl; //cout << "Shred" << endl;
if(SELECTED_DRIVE.state == Drive::NONE) if(SELECTED_DRIVE.state == Drive::NONE)
{ {
SELECTED_DRIVE.state = Drive::SHRED_SELECTED; SELECTED_DRIVE.state = Drive::SHRED_SELECTED;
menustate.bAbort = false;
menustate.bDelete = false;
menustate.bShred = false;
menustate.bConfirmDelete = false;
menustate.bConfirmShred = true;
} }
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
break; break;
case TUI::UserInput::Enter: case TUI::UserInput::Enter:
//cout << "Enter" << endl; //cout << "Enter" << endl;
handleEnter(); handleEnter();
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
break; break;
case TUI::UserInput::ESC: case TUI::UserInput::ESC:
//cout << "ESC" << endl; //cout << "ESC" << endl;
handleESC();
ui->updateTUI(&vecDrives, i32SelectedEntry, menustate);
break; break;
default: default:
break; break;
@ -376,12 +386,10 @@ void reHDD::handleArrowKey(TUI::UserInput userInput)
break; break;
} }
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_ACTIVE || SELECTED_DRIVE.state == Drive::TaskState::DELETE_ACTIVE) if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_ACTIVE || SELECTED_DRIVE.state == Drive::TaskState::DELETE_ACTIVE)
{ {
//task for drive is running --> don´t show more task options //task for drive is running --> don´t show more task options
menustate.bAbort = true; //activate abort menustate.bAbort = true; //activate abort
menustate.bConfirmAbort = false;
menustate.bDelete = false; menustate.bDelete = false;
menustate.bShred = false; menustate.bShred = false;
menustate.bConfirmDelete = false; menustate.bConfirmDelete = false;
@ -392,7 +400,6 @@ void reHDD::handleArrowKey(TUI::UserInput userInput)
{ {
//no task for drive is running --> show more task options //no task for drive is running --> show more task options
menustate.bAbort = false; //deactivate abort menustate.bAbort = false; //deactivate abort
menustate.bConfirmAbort = false;
menustate.bDelete = true; menustate.bDelete = true;
menustate.bShred = true; menustate.bShred = true;
menustate.bConfirmDelete = false; menustate.bConfirmDelete = false;
@ -406,12 +413,24 @@ void reHDD::handleEnter()
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED) if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED)
{ {
SELECTED_DRIVE.state = Drive::TaskState::SHRED_ACTIVE; SELECTED_DRIVE.state = Drive::TaskState::SHRED_ACTIVE;
//task for drive is running --> don´t show more task options
menustate.bAbort = true; //activate abort
menustate.bDelete = false;
menustate.bShred = false;
menustate.bConfirmDelete = false;
menustate.bConfirmShred = false;
//TODO start shredding //TODO start shredding
} }
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED) if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED)
{ {
SELECTED_DRIVE.state = Drive::TaskState::DELETE_ACTIVE; SELECTED_DRIVE.state = Drive::TaskState::DELETE_ACTIVE;
//task for drive is running --> don´t show more task options
menustate.bAbort = true; //activate abort
menustate.bDelete = false;
menustate.bShred = false;
menustate.bConfirmDelete = false;
menustate.bConfirmShred = false;
//TODO start deleting //TODO start deleting
} }
} }
@ -422,11 +441,23 @@ void reHDD::handleESC()
if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED) if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED)
{ {
SELECTED_DRIVE.state = Drive::TaskState::NONE; SELECTED_DRIVE.state = Drive::TaskState::NONE;
//task for drive is selected --> remove selection
menustate.bAbort = false; //activate abort
menustate.bDelete = true;
menustate.bShred = true;
menustate.bConfirmDelete = false;
menustate.bConfirmShred = false;
} }
if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED) if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED)
{ {
SELECTED_DRIVE.state = Drive::TaskState::NONE; SELECTED_DRIVE.state = Drive::TaskState::NONE;
//task for drive is selected --> remove selection
menustate.bAbort = false; //activate abort
menustate.bDelete = true;
menustate.bShred = true;
menustate.bConfirmDelete = false;
menustate.bConfirmShred = false;
} }
} }
@ -436,5 +467,11 @@ void reHDD::handleAbort()
{ {
// TODO cancle shred or delete // TODO cancle shred or delete
SELECTED_DRIVE.state = Drive::NONE; SELECTED_DRIVE.state = Drive::NONE;
//task for drive is running --> remove selection
menustate.bAbort = false; //activate abort
menustate.bDelete = true;
menustate.bShred = true;
menustate.bConfirmDelete = false;
menustate.bConfirmShred = false;
} }
} }