00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "../intl.h"
00021 #include "passworddialog.h"
00022 #include "messagebox.h"
00023
00024 void
00025 PasswordDialog::createWindow() throw(YAPETUI::UIException) {
00026 if (window != NULL)
00027 throw YAPETUI::UIException(_("May you consider deleting the window before reallocating"));
00028
00029 window = newwin(getHeight(), getWidth(), getStartY(), getStartX());
00030 if (window == NULL)
00031 throw YAPETUI::UIException(_("Error creating password dialog"));
00032
00033 pwidget1 = new YAPETUI::PasswordWidget(getStartX() + 1,
00034 getStartY() + 3,
00035 getWidth() - 2);
00036 if (pwtype == NEW_PW)
00037 pwidget2 = new YAPETUI::PasswordWidget(getStartX() + 1,
00038 getStartY() + 5,
00039 getWidth()-2);
00040
00041 okbutton = new YAPETUI::Button(_("OK"),
00042 getStartX() + 1,
00043 getStartY() + getHeight() - 2);
00044
00045 cancelbutton = new YAPETUI::Button(_("Cancel"),
00046 getStartX() + okbutton->getLength() + 2,
00047 getStartY() + getHeight() - 2);
00048
00049 }
00050
00051 PasswordDialog::PasswordDialog(PWTYPE pt, std::string fn)
00052 throw(YAPETUI::UIException) : window(NULL),
00053 pwidget1(NULL),
00054 pwidget2(NULL),
00055 okbutton(NULL),
00056 cancelbutton(NULL),
00057 pwtype(pt),
00058 key(NULL),
00059 filename(fn){
00060 createWindow();
00061 }
00062
00063 PasswordDialog::~PasswordDialog() {
00064 delete pwidget1;
00065 if (pwtype == NEW_PW)
00066 delete pwidget2;
00067 delete okbutton;
00068 delete cancelbutton;
00069 wclear(window);
00070 delwin(window);
00071 }
00072
00073 void
00074 PasswordDialog::run() throw(YAPETUI::UIException) {
00075 refresh();
00076 while (true) {
00077 int ch = 0;
00078 #ifdef HAVE_WRESIZE
00079 while ( (ch = pwidget1->focus()) == KEY_RESIZE)
00080 YAPETUI::BaseWindow::resizeAll();
00081 #else // HAVE_WRESIZE
00082 pwidget1->focus();
00083 #endif // HAVE_WRESIZE
00084
00085
00086 if (pwtype == NEW_PW) {
00087 #ifdef HAVE_WRESIZE
00088 while ( (ch = pwidget2->focus()) == KEY_RESIZE)
00089 YAPETUI::BaseWindow::resizeAll();
00090 #else // HAVE_WRESIZE
00091 pwidget2->focus();
00092 #endif // HAVE_WRESIZE
00093 }
00094
00095 #ifdef HAVE_WRESIZE
00096 while ( (ch = okbutton->focus()) == KEY_RESIZE)
00097 YAPETUI::BaseWindow::resizeAll();
00098 #else // HAVE_WRESIZE
00099 ch = okbutton->focus();
00100 #endif // HAVE_WRESIZE
00101 if (ch == '\n') {
00102 if (pwtype == NEW_PW) {
00103 if (pwidget1->getText() == pwidget2->getText()) {
00104 key = new YAPET::Key(pwidget1->getText().c_str());
00105 return;
00106 } else {
00107 YAPETUI::MessageBox* errmsg = NULL;
00108 try {
00109 errmsg = new YAPETUI::MessageBox(_("E R R O R"), _("Passwords do not match"));
00110 errmsg->run();
00111 delete errmsg;
00112 } catch(YAPETUI::UIException&) {
00113 if (errmsg == NULL)
00114 delete errmsg;
00115 }
00116 pwidget1->setText("");
00117 pwidget2->setText("");
00118 refresh();
00119 continue;
00120 }
00121 } else {
00122 key = new YAPET::Key(pwidget1->getText().c_str());
00123 pwidget1->clearText();
00124 return;
00125 }
00126 }
00127 #ifdef HAVE_WRESIZE
00128 while ( (ch = cancelbutton->focus()) == KEY_RESIZE)
00129 YAPETUI::BaseWindow::resizeAll();
00130 #else // HAVE_WRESIZE
00131 ch = cancelbutton->focus();
00132 #endif // HAVE_WRESIZE
00133 if (ch == '\n')
00134 return;
00135 }
00136
00137 }
00138
00139 void
00140 PasswordDialog::resize() throw(YAPETUI::UIException) {
00141 int retval = delwin(window);
00142 if (retval == ERR)
00143 throw YAPETUI::UIException(_("Error deleting password dialog window"));
00144
00145 pwidget1->clearText();
00146 delete pwidget1;
00147 if (pwtype == NEW_PW) {
00148 pwidget2->clearText();
00149 delete pwidget2;
00150 }
00151 delete okbutton;
00152 delete cancelbutton;
00153
00154 window = NULL;
00155 pwidget1 = NULL;
00156 pwidget2 = NULL;
00157 okbutton = NULL;
00158 cancelbutton = NULL;
00159
00160 createWindow();
00161 }
00162
00163 void
00164 PasswordDialog::refresh() throw(YAPETUI::UIException) {
00165 YAPETUI::Colors::setcolor(window, YAPETUI::MESSAGEBOX);
00166 int retval = werase(window);
00167 if (retval == ERR)
00168 throw YAPETUI::UIException(_("Error clearing password dialog"));
00169
00170 retval = box(window, 0, 0);
00171 if (retval == ERR)
00172 throw YAPETUI::UIException(_("Error adding box"));
00173
00174 retval = mymvwaddstr(window, 0, 2, _("P A S S W O R D"));
00175 if (retval == ERR)
00176 throw YAPETUI::UIException(_("Error setting title"));
00177
00178
00179 retval = mymvwaddstr(window, 2, 1, filename.c_str());
00180 if (retval == ERR)
00181 throw YAPETUI::UIException(_("Error setting label"));
00182
00183 if (pwtype == NEW_PW) {
00184 retval = mymvwaddstr(window, 1, 1, _("Enter new password for"));
00185 if (retval == ERR)
00186 throw YAPETUI::UIException(_("Error setting label"));
00187
00188 retval = mymvwaddstr(window, 4, 1, _("Confirm password"));
00189 if (retval == ERR)
00190 throw YAPETUI::UIException(_("Error setting label"));
00191 } else {
00192 retval = mymvwaddstr(window, 1, 1, _("Enter password for"));
00193 if (retval == ERR)
00194 throw YAPETUI::UIException(_("Error setting label"));
00195 }
00196
00197 retval = wrefresh(window);
00198 if (retval == ERR)
00199 throw YAPETUI::UIException(_("Error refreshing password dialog"));
00200
00201 pwidget1->refresh();
00202 if (pwtype == NEW_PW)
00203 pwidget2->refresh();
00204 okbutton->refresh();
00205 cancelbutton->refresh();
00206 }