00001 // -*- c++ -*- 00002 // 00003 // $Id: passworddialog.h 2360 2009-06-11 15:06:24Z rafi $ 00004 // 00005 // Copyright (C) 2008, 2009 Rafael Ostertag 00006 // 00007 // This file is part of YAPET. 00008 // 00009 // YAPET is free software: you can redistribute it and/or modify it under the 00010 // terms of the GNU General Public License as published by the Free Software 00011 // Foundation, either version 3 of the License, or (at your option) any later 00012 // version. 00013 // 00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY 00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00017 // details. 00018 // 00019 // You should have received a copy of the GNU General Public License along with 00020 // YAPET. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 00023 #ifndef _PASSWORDDIALOG_H 00024 #define _PASSWORDDIALOG_H 00025 00026 #ifdef HAVE_CONFIG_H 00027 # include <config.h> 00028 #endif 00029 00030 #ifdef HAVE_NCURSES_H 00031 # include <ncurses.h> 00032 #else // HAVE_NCURSES_H 00033 # ifdef HAVE_CURSES_H 00034 # include <curses.h> 00035 # else 00036 # error "Neither curses.h nor ncurses.h available" 00037 # endif // HAVE_CURSES_H 00038 #endif // HAVE_NCURSES_H 00039 #include "curswa.h" // Leave this here. It depends on the above includes. 00040 00041 #ifdef HAVE_STRING 00042 # include <string> 00043 #endif 00044 00045 #include <key.h> 00046 00047 #include <basewindow.h> 00048 #include <button.h> 00049 #include <passwordwidget.h> 00050 00057 enum PWTYPE { 00062 NEW_PW, 00066 EXISTING_PW 00067 }; 00068 00082 class PasswordDialog : protected YAPETUI::BaseWindow { 00083 private: 00084 enum { 00085 HEIGHT_NEW = 9, 00086 HEIGHT_EX = 7 00087 }; 00088 00089 WINDOW* window; 00090 YAPETUI::PasswordWidget* pwidget1; 00091 YAPETUI::PasswordWidget* pwidget2; 00092 YAPETUI::Button* okbutton; 00093 YAPETUI::Button* cancelbutton; 00094 PWTYPE pwtype; 00095 YAPET::Key* key; 00096 00097 std::string filename; 00098 00099 inline PasswordDialog(const PasswordDialog&) {} 00100 inline const PasswordDialog& operator=(const PasswordDialog&) { return *this; } 00101 00102 inline int getWidth() const { 00103 return maxX() - 8; 00104 } 00105 00106 inline int getHeight() const { 00107 if (pwtype == NEW_PW) 00108 return HEIGHT_NEW; 00109 else 00110 return HEIGHT_EX; 00111 } 00112 00113 inline int getStartX() const { 00114 return maxX()/2 - getWidth()/2; 00115 } 00116 00117 inline int getStartY() const { 00118 return maxY()/2 - getHeight()/2; 00119 } 00120 00121 void createWindow() throw(YAPETUI::UIException); 00122 00123 public: 00136 PasswordDialog(PWTYPE pt, std::string fn) throw(YAPETUI::UIException); 00137 ~PasswordDialog(); 00138 00145 void run() throw(YAPETUI::UIException); 00160 YAPET::Key* getKey() const { return key; } 00161 void resize() throw(YAPETUI::UIException); 00162 void refresh() throw(YAPETUI::UIException); 00163 }; 00164 00165 #endif // _PASSWORDDIALOG_H