Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 1 | /* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | #include <assert.h> |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include <FL/fl_ask.H> |
| 24 | |
| 25 | #include <rfb/util.h> |
| 26 | #include <rfb/Password.h> |
| 27 | #include <rfb/Exception.h> |
| 28 | |
| 29 | #include "i18n.h" |
| 30 | #include "parameters.h" |
| 31 | #include "UserDialog.h" |
| 32 | |
| 33 | using namespace rfb; |
| 34 | |
| 35 | UserDialog::UserDialog() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | UserDialog::~UserDialog() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | void UserDialog::getUserPasswd(char** user, char** password) |
| 44 | { |
| 45 | CharArray passwordFileStr(passwordFile.getData()); |
| 46 | |
| 47 | assert(password); |
| 48 | |
| 49 | if (!user && passwordFileStr.buf[0]) { |
| 50 | ObfuscatedPasswd obfPwd(256); |
| 51 | FILE* fp; |
| 52 | |
| 53 | fp = fopen(passwordFileStr.buf, "r"); |
| 54 | if (!fp) |
| 55 | throw rfb::Exception(_("Opening password file failed")); |
| 56 | |
| 57 | obfPwd.length = fread(obfPwd.buf, 1, obfPwd.length, fp); |
| 58 | fclose(fp); |
| 59 | |
| 60 | PlainPasswd passwd(obfPwd); |
| 61 | *password = passwd.takeBuf(); |
| 62 | |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | if (!user) { |
| 67 | *password = strDup(fl_password(_("VNC authentication"), "")); |
| 68 | if (!*password) |
| 69 | throw rfb::Exception(_("Authentication cancelled")); |
| 70 | |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | fl_alert(_("NOT IMPLEMENTED!")); |
| 75 | |
| 76 | *user = strDup(""); |
| 77 | *password = strDup(""); |
| 78 | } |
| 79 | |
| 80 | bool UserDialog::showMsgBox(int flags, const char* title, const char* text) |
| 81 | { |
Pierre Ossman | 20ae1c8 | 2011-05-17 11:43:47 +0000 | [diff] [blame^] | 82 | // FLTK doesn't give us a flexible choice of the icon, so we ignore those |
| 83 | // bits for now. |
| 84 | |
| 85 | // FIXME: Filter out % from input text |
| 86 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 87 | fl_message_title(title); |
Pierre Ossman | 20ae1c8 | 2011-05-17 11:43:47 +0000 | [diff] [blame^] | 88 | |
| 89 | switch (flags & 0xf) { |
| 90 | case M_OKCANCEL: |
| 91 | return fl_choice(text, NULL, fl_ok, fl_cancel) == 1; |
| 92 | case M_YESNO: |
| 93 | return fl_choice(text, NULL, fl_yes, fl_no) == 1; |
| 94 | case M_OK: |
| 95 | default: |
| 96 | if (((flags & 0xf0) == M_ICONERROR) || |
| 97 | ((flags & 0xf0) == M_ICONWARNING)) |
| 98 | fl_alert(text); |
| 99 | else |
| 100 | fl_message(text); |
| 101 | return true; |
| 102 | } |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 103 | |
| 104 | return false; |
| 105 | } |