kpassdlg.h
00001 // vi: ts=8 sts=4 sw=4 00002 /* This file is part of the KDE libraries 00003 Copyright (C) 1998 Pietro Iglio <iglio@fub.it> 00004 Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org> 00005 Copyright (C) 2004,2005 Andrew Coles <andrew_coles@yahoo.co.uk> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License version 2 as published by the Free Software Foundation. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 #ifndef __KPassDlg_h_included__ 00022 #define __KPassDlg_h_included__ 00023 00024 #include <tqstring.h> 00025 #include <tqlineedit.h> 00026 #include <kdialogbase.h> 00027 00028 class TQLabel; 00029 class TQGridLayout; 00030 class TQWidget; 00031 00039 class KDEUI_EXPORT KPasswordEdit 00040 : public TQLineEdit 00041 { 00042 Q_OBJECT 00043 00044 public: 00045 enum EchoModes { OneStar, ThreeStars, NoEcho }; 00046 00050 KPasswordEdit(TQWidget *parent=0, const char *name=0); 00051 // KDE4: either of the two must go! add default values for parameters 00052 00058 KPasswordEdit(EchoMode echoMode, TQWidget *parent, const char *name); 00059 00065 KPasswordEdit(EchoModes echoMode, TQWidget *parent, const char *name); 00066 00071 KPasswordEdit(TQWidget *parent, const char *name, int echoMode) KDE_DEPRECATED; 00072 00076 ~KPasswordEdit(); 00077 00082 const char *password() const { return m_Password; } 00083 00087 void erase(); 00088 00089 static const int PassLen; 00090 00100 void setMaxPasswordLength(int newLength); 00101 00106 int maxPasswordLength() const; 00107 00108 public slots: 00112 virtual void insert( const TQString &); 00113 00114 protected: 00115 virtual void keyPressEvent(TQKeyEvent *); 00116 virtual void focusInEvent(TQFocusEvent *e); 00117 virtual bool event(TQEvent *e); 00118 00119 private: 00120 void init(); 00121 void showPass(); 00122 00123 char *m_Password; 00124 int m_EchoMode, m_Length; 00125 }; 00126 00127 00166 class KDEUI_EXPORT KPasswordDialog 00167 : public KDialogBase 00168 { 00169 Q_OBJECT 00170 00171 public: 00175 enum Types { 00179 Password, 00180 00186 NewPassword 00187 }; 00188 00203 KPasswordDialog(Types type, bool enableKeep, int extraBttn, 00204 TQWidget *parent=0, const char *name=0); 00205 00210 KPasswordDialog(int type, TQString prompt, bool enableKeep=false, 00211 int extraBttn=0) KDE_DEPRECATED; 00212 // note that this implicitly deprecates the 'prompt' variants of 00213 // getPassword() below. i guess the above constructor needs to be extended. 00214 00230 KPasswordDialog(Types type, bool enableKeep, int extraBttn, const TQString& iconName, 00231 TQWidget *parent = 0, const char *name = 0); 00232 00236 virtual ~KPasswordDialog(); 00237 00241 void setPrompt(TQString prompt); 00242 00246 TQString prompt() const; 00247 00251 void setKeepWarning(TQString warn); 00252 00256 void addLine(TQString key, TQString value); 00257 00262 void setAllowEmptyPasswords(bool allowed); 00263 00268 bool allowEmptyPasswords() const; 00269 00278 void setMinimumPasswordLength(int minLength); 00279 00284 int minimumPasswordLength() const; 00285 00293 void setMaximumPasswordLength(int maxLength); 00294 00299 int maximumPasswordLength() const; 00300 00309 void setReasonablePasswordLength(int reasonableLength); 00310 00315 int reasonablePasswordLength() const; 00316 00327 void setPasswordStrengthWarningLevel(int warningLevel); 00328 00333 int passwordStrengthWarningLevel() const; 00334 00339 const char *password() const { return m_pEdit->password(); } 00340 00346 void clearPassword(); 00347 00351 bool keep() const { return m_Keep; } 00352 00365 static int getPassword(TQCString &password, TQString prompt, int *keep=0L); 00366 00377 static int getNewPassword(TQCString &password, TQString prompt); 00378 00382 static void disableCoreDumps(); 00383 00384 protected slots: 00385 void slotOk(); 00386 void slotCancel(); 00387 void slotKeep(bool); 00388 void slotLayout(); 00389 00390 protected: 00391 00397 virtual bool checkPassword(const char *) { return true; } 00398 00399 private slots: 00400 void enableOkBtn(); 00401 00402 private: 00403 void init(); 00404 void erase(); 00405 00406 int m_Keep, m_Type, m_Row; 00407 TQLabel *m_pHelpLbl; 00408 TQLabel *m_keepWarnLbl; 00409 TQGridLayout *m_pGrid; 00410 TQWidget *m_pMain; 00411 KPasswordEdit *m_pEdit, *m_pEdit2; 00412 00413 protected: 00414 virtual void virtual_hook( int id, void* data ); 00415 private: 00416 class KPasswordDialogPrivate; 00417 KPasswordDialogPrivate* const d; 00418 }; 00419 00420 00421 #endif // __KPassDlg_h_included__