diff --git a/include/tui.h b/include/tui.h index 5092ada..fcc6b9a 100644 --- a/include/tui.h +++ b/include/tui.h @@ -28,7 +28,6 @@ public: bool bAbort; bool bShred; bool bDelete; - bool bConfirmAbort; bool bConfirmShred; bool bConfirmDelete; }; @@ -50,6 +49,7 @@ private: WINDOW* overview; WINDOW* systemview; WINDOW* menuview; + WINDOW* dialog; static void centerTitle(WINDOW *pwin, const char * title); 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 *createSystemStats(int iXSize, int iYSize, int iYStart); 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_ \ No newline at end of file diff --git a/src/TUI/tui.cpp b/src/TUI/tui.cpp index 0d8d52d..ad9b9c5 100644 --- a/src/TUI/tui.cpp +++ b/src/TUI/tui.cpp @@ -70,6 +70,7 @@ void TUI::updateTUI(vector * pvecDrives, int32_t i32SelectedEntry, struct menuview=createMenuView(((stdscrX)-(int)(stdscrX/3)-7), 10, (int)(stdscrX/3)+5,(stdscrY-11), menustate); wrefresh(menuview); + vector ::iterator it; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) { @@ -84,6 +85,21 @@ void TUI::updateTUI(vector * pvecDrives, int32_t i32SelectedEntry, struct bSelectedEntry = true; detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-15), (int)(stdscrX/3)+5, pvecDrives->at((it - pvecDrives->begin()))); 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); @@ -296,18 +312,23 @@ WINDOW* TUI::createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, st { mvwaddstr(newWindow,u16Line++, 3, "Press D for Delete"); } - if (menustate.bConfirmAbort) - { - mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Abort or ESC to return"); - } - if (menustate.bConfirmShred) - { - mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Shred or ESC to return"); - } - if (menustate.bConfirmDelete) - { - mvwaddstr(newWindow,u16Line++, 3, "Press Enter to confirm Delete or ESC to return"); - } + keypad(newWindow, TRUE); + return newWindow; +} + +WINDOW* TUI::createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string task, string optionA, string optionB) +{ + WINDOW *newWindow; + newWindow = newwin(iYSize, iXSize, iYStart, iXStart); + + wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY_SELECTED)); + 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); return newWindow; diff --git a/src/reHDD.cpp b/src/reHDD.cpp index 292183e..46348d6 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -37,6 +37,8 @@ reHDD::reHDD(void) { cout << "created app" << endl; i32SelectedEntry = 0; + menustate.bDelete = true; + menustate.bShred = true; } /** @@ -126,36 +128,44 @@ void reHDD::ThreadUserInput() break; case TUI::UserInput::Abort: //cout << "Abort" << endl; - handleAbort(); - + ui->updateTUI(&vecDrives, i32SelectedEntry, menustate); break; case TUI::UserInput::Delete: //cout << "Delete" << endl; - if(SELECTED_DRIVE.state == Drive::NONE) { - 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; case TUI::UserInput::Shred: //cout << "Shred" << endl; - if(SELECTED_DRIVE.state == Drive::NONE) { - 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; case TUI::UserInput::Enter: //cout << "Enter" << endl; handleEnter(); + ui->updateTUI(&vecDrives, i32SelectedEntry, menustate); break; case TUI::UserInput::ESC: //cout << "ESC" << endl; + handleESC(); + ui->updateTUI(&vecDrives, i32SelectedEntry, menustate); break; default: break; @@ -376,12 +386,10 @@ void reHDD::handleArrowKey(TUI::UserInput userInput) break; } - 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 menustate.bAbort = true; //activate abort - menustate.bConfirmAbort = false; menustate.bDelete = false; menustate.bShred = false; menustate.bConfirmDelete = false; @@ -392,7 +400,6 @@ void reHDD::handleArrowKey(TUI::UserInput userInput) { //no task for drive is running --> show more task options menustate.bAbort = false; //deactivate abort - menustate.bConfirmAbort = false; menustate.bDelete = true; menustate.bShred = true; menustate.bConfirmDelete = false; @@ -406,12 +413,24 @@ void reHDD::handleEnter() if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED) { 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 } if(SELECTED_DRIVE.state == Drive::TaskState::DELETE_SELECTED) { 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 } } @@ -422,11 +441,23 @@ void reHDD::handleESC() if(SELECTED_DRIVE.state == Drive::TaskState::SHRED_SELECTED) { 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) { 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 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; } } \ No newline at end of file