/* Reboot menu. Shouldn't there be a better place for this? */ #include #include #include #include #include #include "etree.h" #include "global.h" #include "server.h" #include "sysmon.h" #include "window.h" /*************************************************************************/ void reboot_menu(int quick) { WINDOW *w; int width = quick ? 42 : 37; int sel = 0, yn = 0, c; const char *opts[] = { "(Cancel)", "Bahamut", "palantir" }; Server *serv; ETree arg, *argptr = &arg; w = newwin(7, width, (scrheight-7)/2, (scrwidth-width)/2); if (!w) { beep(); return; } keypad(w, TRUE); wattrset(w, A_BOLD); box(w, 0, 0); mvwaddstr(w, 1, 1, "Which server do you want to "); init_pair(63, COLOR_RED, COLOR_BLACK); wattrset(w, COLOR_PAIR(63) | A_BOLD); if (quick) waddstr(w, "hard-reboot"); else waddstr(w, "reboot"); wattrset(w, A_BOLD); waddstr(w, "?"); wattrset(w, COLOR_PAIR(63) | A_BOLD); mvwaddstr(w, 3, (width-8)/2, "(Cancel)"); wattrset(w, A_BOLD); mvwaddstr(w, 4, (width-8)/2, "Bahamut"); mvwaddstr(w, 5, (width-8)/2, "palantir"); wrefresh(w); while ((c = wgetch(w)) != '\r' && c != '\n' && c != ERR) { if (c == KEY_UP) { wattrset(w, A_BOLD); mvwaddstr(w, sel+3, (width-8)/2, opts[sel]); sel = (sel+2) % 3; wattrset(w, COLOR_PAIR(63) | A_BOLD); mvwaddstr(w, sel+3, (width-8)/2, opts[sel]); } else if (c == KEY_DOWN) { wattrset(w, A_BOLD); mvwaddstr(w, sel+3, (width-8)/2, opts[sel]); sel = (sel+1) % 3; wattrset(w, COLOR_PAIR(63) | A_BOLD); mvwaddstr(w, sel+3, (width-8)/2, opts[sel]); } } if (c == ERR || sel == 0) { werase(w); wnoutrefresh(w); delwin(w); screen_refresh(); return; } wattrset(w, A_BOLD); werase(w); box(w, 0, 0); mvwaddstr(w, 1, 1, "Do you really want to "); if (quick) waddstr(w, "hard-reboot "); else waddstr(w, "reboot "); waddstr(w, "server"); mvwaddstr(w, 2, (width-strlen(opts[sel])-1)/2, opts[sel]); waddch(w, '?'); mvwaddstr(w, 4, (width-3)/2, "Yes"); wattrset(w, COLOR_PAIR(63) | A_BOLD); mvwaddstr(w, 5, (width-3)/2, "No"); while ((c = wgetch(w)) != '\r' && c != '\n' && c != ERR) { if (c == KEY_UP || c == KEY_DOWN) { wattrset(w, A_BOLD); mvwaddstr(w, 5-yn, (width-3)/2, yn ? "Yes" : "No"); yn = 1-yn; wattrset(w, COLOR_PAIR(63) | A_BOLD); mvwaddstr(w, 5-yn, (width-3)/2, yn ? "Yes" : "No"); } } werase(w); wnoutrefresh(w); delwin(w); screen_refresh(); if (c == ERR || sel == 0) return; serv = server_find(opts[sel]); if (!serv) { beep(); return; } arg.type = ET_INT; arg.u.intval = quick; if (!server_query(serv, Q_REBOOT, 1, &argptr)) { beep(); return; } } /*************************************************************************/