From: Pierre Ossman Date: Fri, 1 Sep 2017 07:24:43 +0000 (+0200) Subject: Merge authentication dialogs X-Git-Tag: v1.8.90~115^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=10a48102a4a892daee8ea325f008fccf9663b236;p=tigervnc.git Merge authentication dialogs Avoid having two separate code paths for the user/password and only password dialogs. Makes it easier to extend things in the future. --- diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx index b57588de..cf6893c8 100644 --- a/vncviewer/UserDialog.cxx +++ b/vncviewer/UserDialog.cxx @@ -82,46 +82,59 @@ void UserDialog::getUserPasswd(char** user, char** password) return; } - if (!user) { - fl_message_title(_("VNC authentication")); - *password = strDup(fl_password(_("Password:"), "")); - if (!*password) - throw rfb::Exception(_("Authentication cancelled")); + Fl_Window *win; + Fl_Input *username; + Fl_Secret_Input *passwd; + Fl_Box *icon; + Fl_Button *button; - return; - } + int y; - // Largely copied from FLTK so that we get the same look and feel - // as the simpler password input. - Fl_Window *win = new Fl_Window(410, 145, _("VNC authentication")); + win = new Fl_Window(410, 145, _("VNC authentication")); win->callback(button_cb,(void *)0); - Fl_Input *username = new Fl_Input(70, 25, 300, 25, _("Username:")); - username->align(FL_ALIGN_TOP_LEFT); + y = 10; - Fl_Secret_Input *passwd = new Fl_Secret_Input(70, 70, 300, 25, _("Password:")); - passwd->align(FL_ALIGN_TOP_LEFT); - - Fl_Box *icon = new Fl_Box(10, 10, 50, 50, "?"); + icon = new Fl_Box(10, 10, 50, 50, "?"); icon->box(FL_UP_BOX); icon->labelfont(FL_TIMES_BOLD); icon->labelsize(34); icon->color(FL_WHITE); icon->labelcolor(FL_BLUE); - Fl_Button *button; + y += 5; + + if (user) { + (new Fl_Box(70, y, win->w()-70-10, 20, _("Username:"))) + ->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); + y += 20 + 5; + username = new Fl_Input(70, y, win->w()-70-10, 25); + y += 25 + 5; + } + + (new Fl_Box(70, y, win->w()-70-10, 20, _("Password:"))) + ->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); + y += 20 + 5; + passwd = new Fl_Secret_Input(70, y, win->w()-70-10, 25); + y += 25 + 5; + + y += 5; - button = new Fl_Return_Button(310, 110, 90, 25, fl_ok); + button = new Fl_Return_Button(310, y, 90, 25, fl_ok); button->align(FL_ALIGN_INSIDE|FL_ALIGN_WRAP); button->callback(button_cb, (void*)0); - button = new Fl_Button(210, 110, 90, 25, fl_cancel); + button = new Fl_Button(210, y, 90, 25, fl_cancel); button->align(FL_ALIGN_INSIDE|FL_ALIGN_WRAP); button->callback(button_cb, (void*)1); button->shortcut(FL_Escape); + y += 25 + 10; + win->end(); + win->size(win->w(), y); + win->set_modal(); ret_val = -1; @@ -130,14 +143,15 @@ void UserDialog::getUserPasswd(char** user, char** password) while (win->shown()) Fl::wait(); if (ret_val == 0) { - *user = strDup(username->value()); + if (user) + *user = strDup(username->value()); *password = strDup(passwd->value()); - } else { - *user = strDup(""); - *password = strDup(""); } delete win; + + if (ret_val != 0) + throw rfb::Exception(_("Authentication cancelled")); } bool UserDialog::showMsgBox(int flags, const char* title, const char* text)