cws tl82: #i114160# SimplePasswordRequest and respective dialog

This commit is contained in:
Thomas Lange [tl]
2010-09-06 10:02:33 +02:00
parent 6d1adcc602
commit e70c93b5e5
7 changed files with 224 additions and 76 deletions

View File

@@ -519,7 +519,8 @@ executePasswordDialog(
task::PasswordRequestMode nMode,
::rtl::OUString aDocName,
bool bMSCryptoMode,
bool bIsPasswordToModify )
bool bIsPasswordToModify,
bool bIsSimplePasswordRequest )
SAL_THROW((uno::RuntimeException))
{
try
@@ -530,21 +531,36 @@ executePasswordDialog(
ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui)));
if( nMode == task::PasswordRequestMode_PASSWORD_CREATE )
{
const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
if (bIsSimplePasswordRequest)
{
std::auto_ptr< PasswordDialog > pDialog(
new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
bIsPasswordToModify, bIsSimplePasswordRequest ) );
pDialog->SetMinLen(0);
VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
std::auto_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
rInfo.SetPassword( pDialog->GetPassword() );
}
else
{
const sal_uInt16 nMaxPasswdLen = bMSCryptoMode ? 15 : 0; // 0 -> allow any length
rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
rInfo.SetPassword( pDialog->GetPasswordToOpen() );
rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
VclAbstractDialogFactory * pFact = VclAbstractDialogFactory::Create();
AbstractPasswordToOpenModifyDialog *pTmp = pFact->CreatePasswordToOpenModifyDialog( pParent, 0, nMaxPasswdLen, bIsPasswordToModify );
std::auto_ptr< AbstractPasswordToOpenModifyDialog > pDialog( pTmp );
rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
rInfo.SetPassword( pDialog->GetPasswordToOpen() );
rInfo.SetPasswordToModify( pDialog->GetPasswordToModify() );
rInfo.SetRecommendToOpenReadonly( pDialog->IsRecommendToOpenReadonly() );
}
}
else
else // enter password or reenter password
{
std::auto_ptr< PasswordDialog > pDialog(
new PasswordDialog( pParent, nMode, xManager.get(), aDocName, bIsPasswordToModify ) );
new PasswordDialog( pParent, nMode, xManager.get(), aDocName,
bIsPasswordToModify, bIsSimplePasswordRequest ) );
pDialog->SetMinLen(0);
rInfo.SetResult( pDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : ERRCODE_BUTTON_CANCEL );
rInfo.SetPassword( bIsPasswordToModify ? String() : pDialog->GetPassword() );
@@ -567,7 +583,8 @@ handlePasswordRequest_(
rContinuations,
::rtl::OUString aDocumentName,
bool bMSCryptoMode,
bool bIsPasswordToModify )
bool bIsPasswordToModify,
bool bIsSimplePasswordRequest = false )
SAL_THROW((uno::RuntimeException))
{
uno::Reference< task::XInteractionRetry > xRetry;
@@ -582,7 +599,7 @@ handlePasswordRequest_(
LoginErrorInfo aInfo;
executePasswordDialog( pParent, aInfo, nMode,
aDocumentName, bMSCryptoMode, bIsPasswordToModify );
aDocumentName, bMSCryptoMode, bIsPasswordToModify, bIsSimplePasswordRequest );
switch (aInfo.GetResult())
{
@@ -742,7 +759,8 @@ UUIInteractionHelper::handlePasswordRequest(
rRequest->getContinuations(),
rtl::OUString(),
false /* bool bMSCryptoMode */,
false /* bool bIsPasswordToModify */);
false /* bool bIsPasswordToModify */,
true /* bool bIsSimplePasswordRequest */ );
return true;
}

3
uui/source/ids.hrc Normal file → Executable file
View File

@@ -56,6 +56,7 @@
#define RID_UUI_ERRHDL (RID_UUI_START + 20)
#define DLG_UUI_MASTERPASSWORD_CRT (RID_UUI_START + 21)
#define DLG_UUI_PASSWORD (RID_UUI_START + 22)
#define STR_ERROR_SIMPLE_PASSWORD_WRONG (RID_UUI_START + 23)
#define STR_ERROR_PASSWORD_TO_OPEN_WRONG (RID_UUI_START + 24)
#define STR_ERROR_PASSWORD_TO_MODIFY_WRONG (RID_UUI_START + 25)
#define DLG_UUI_UNKNOWNAUTH (RID_UUI_START + 26)
@@ -93,6 +94,8 @@
#define STR_RENAME_OR_REPLACE (RID_UUI_START + 58)
#define STR_NAME_CLASH_RENAME_ONLY (RID_UUI_START + 59)
#define STR_SAME_NAME_USED (RID_UUI_START + 60)
#define STR_ENTER_SIMPLE_PASSWORD (RID_UUI_START + 61)
#define STR_CONFIRM_SIMPLE_PASSWORD (RID_UUI_START + 62)
#define ERRCODE_UUI_IO_ABORT (ERRCODE_AREA_UUI + 0)
#define ERRCODE_UUI_IO_ACCESSDENIED (ERRCODE_AREA_UUI + 1)

132
uui/source/passworddlg.cxx Normal file → Executable file
View File

@@ -25,67 +25,119 @@
*
************************************************************************/
#include "passworddlg.hxx"
#include "passworddlg.hrc"
#include "ids.hrc"
#include <svtools/filedlg.hxx>
#include <vcl/msgbox.hxx>
#ifndef UUI_IDS_HRC
#include <ids.hrc>
#endif
#ifndef UUI_PASSWORDDLG_HRC
#include <passworddlg.hrc>
#endif
#include <passworddlg.hxx>
// PasswordDialog---------------------------------------------------------
using namespace ::com::sun::star;
// -----------------------------------------------------------------------
IMPL_LINK( PasswordDialog, OKHdl_Impl, OKButton *, EMPTYARG )
static void lcl_Move( Window &rWin, long nOffset )
{
EndDialog( RET_OK );
return 1;
Point aTmp( rWin.GetPosPixel() );
aTmp.Y() += nOffset;
rWin.SetPosPixel( aTmp );
}
// -----------------------------------------------------------------------
PasswordDialog::PasswordDialog(
Window* _pParent,
::com::sun::star::task::PasswordRequestMode nDlgMode,
task::PasswordRequestMode nDlgMode,
ResMgr * pResMgr,
rtl::OUString& aDocURL,
bool bOpenToModify )
bool bOpenToModify,
bool bIsSimplePasswordRequest )
:ModalDialog( _pParent, ResId( DLG_UUI_PASSWORD, *pResMgr ) )
,aFTPassword( this, ResId( FT_PASSWORD, *pResMgr ))
,aEDPassword( this, ResId( ED_PASSWORD, *pResMgr ))
,aFTConfirmPassword( this, ResId( FT_CONFIRM_PASSWORD, *pResMgr ))
,aEDConfirmPassword( this, ResId( ED_CONFIRM_PASSWORD, *pResMgr ))
,aOKBtn ( this, ResId( BTN_PASSWORD_OK, *pResMgr ))
,aCancelBtn ( this, ResId( BTN_PASSWORD_CANCEL, *pResMgr ))
,aHelpBtn ( this, ResId( BTN_PASSWORD_HELP, *pResMgr ))
,aFixedLine1( this, ResId( FL_FIXED_LINE_1, *pResMgr ))
,nMinLen(1)
,aPasswdMismatch( ResId( STR_PASSWORD_MISMATCH, *pResMgr ))
,nDialogMode( nDlgMode )
,pResourceMgr ( pResMgr )
{
if( nDialogMode == ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER )
if( nDialogMode == task::PasswordRequestMode_PASSWORD_REENTER )
{
USHORT nErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG;
const USHORT nOpenToModifyErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG;
const USHORT nErrStrId = bIsSimplePasswordRequest ? STR_ERROR_SIMPLE_PASSWORD_WRONG : nOpenToModifyErrStrId;
String aErrorMsg( ResId( nErrStrId, *pResourceMgr ));
ErrorBox aErrorBox( _pParent, WB_OK, aErrorMsg );
ErrorBox aErrorBox( this, WB_OK, aErrorMsg );
aErrorBox.Execute();
}
// default settings for enter password or reenter passwd...
String aTitle( ResId( STR_TITLE_ENTER_PASSWORD, *pResourceMgr ) );
aFTConfirmPassword.Hide();
aEDConfirmPassword.Hide();
aFTConfirmPassword.Enable( FALSE );
aEDConfirmPassword.Enable( FALSE );
// settings for create password
if (nDialogMode == task::PasswordRequestMode_PASSWORD_CREATE)
{
aTitle = String( ResId( STR_TITLE_CREATE_PASSWORD, *pResourceMgr ) );
aFTConfirmPassword.SetText( String( ResId( STR_CONFIRM_SIMPLE_PASSWORD, *pResourceMgr ) ) );
aFTConfirmPassword.Show();
aEDConfirmPassword.Show();
aFTConfirmPassword.Enable( TRUE );
aEDConfirmPassword.Enable( TRUE );
}
else
{
// shrink dialog by size of hidden controls and move rest up accordingly
long nDelta = aFixedLine1.GetPosPixel().Y() - aFTConfirmPassword.GetPosPixel().Y();
lcl_Move( aFixedLine1, -nDelta );
lcl_Move( aOKBtn, -nDelta );
lcl_Move( aCancelBtn, -nDelta );
lcl_Move( aHelpBtn, -nDelta );
Size aNewDlgSize = GetSizePixel();
aNewDlgSize.Height() -= nDelta;
SetSizePixel( aNewDlgSize );
}
SetText( aTitle );
USHORT nStrId = bOpenToModify ? STR_ENTER_PASSWORD_TO_MODIFY : STR_ENTER_PASSWORD_TO_OPEN;
aFTPassword.SetText( String( ResId( nStrId, *pResourceMgr ) ) );
aFTPassword.SetText( aFTPassword.GetText() + aDocURL );
if (bIsSimplePasswordRequest)
{
DBG_ASSERT( aDocURL.getLength() == 0, "A simple password request should not have a document URL! Use document password request instead." );
aFTPassword.SetText( String( ResId( STR_ENTER_SIMPLE_PASSWORD, *pResourceMgr ) ) );
}
FreeResource();
aFTPassword.SetText( aFTPassword.GetText() + aDocURL );
aOKBtn.SetClickHdl( LINK( this, PasswordDialog, OKHdl_Impl ) );
long nLabelWidth = aFTPassword.GetSizePixel().Width();
long nLabelHeight = aFTPassword.GetSizePixel().Height();
long nTextWidth = aFTPassword.GetCtrlTextWidth( aFTPassword.GetText() );
long nTextHeight = aFTPassword.GetTextHeight();
//
// move controls down by extra height needed for aFTPassword
// (usually only needed if a URL was provided)
//
long nLabelWidth = aFTPassword.GetSizePixel().Width();
long nLabelHeight = aFTPassword.GetSizePixel().Height();
long nTextWidth = aFTPassword.GetCtrlTextWidth( aFTPassword.GetText() );
long nTextHeight = aFTPassword.GetTextHeight();
Rectangle aLabelRect( aFTPassword.GetPosPixel(), aFTPassword.GetSizePixel() );
Rectangle aRect = aFTPassword.GetTextRect( aLabelRect, aFTPassword.GetText() );
@@ -105,13 +157,31 @@ PasswordDialog::PasswordDialog(
aNewLabelSize.Height() = nNewLabelHeight;
aFTPassword.SetPosSizePixel( aFTPassword.GetPosPixel(), aNewLabelSize );
Window* pControls[] = { &aEDPassword, &aFixedLine1, &aOKBtn, &aCancelBtn, &aHelpBtn };
const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] );
for ( int i = 0; i < nCCount; ++i )
{
Point aNewPos =(*pControls[i]).GetPosPixel();
aNewPos.Y() += nDelta;
pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() );
}
lcl_Move( aEDPassword, nDelta );
lcl_Move( aFTConfirmPassword, nDelta );
lcl_Move( aEDConfirmPassword, nDelta );
lcl_Move( aFixedLine1, nDelta );
lcl_Move( aOKBtn, nDelta );
lcl_Move( aCancelBtn, nDelta );
lcl_Move( aHelpBtn, nDelta );
}
IMPL_LINK( PasswordDialog, OKHdl_Impl, OKButton *, EMPTYARG )
{
bool bEDPasswdValid = aEDPassword.GetText().Len() >= nMinLen;
bool bPasswdMismatch = aEDConfirmPassword.GetText() != aEDPassword.GetText();
bool bValid = (!aEDConfirmPassword.IsVisible() && bEDPasswdValid) ||
(aEDConfirmPassword.IsVisible() && bEDPasswdValid && !bPasswdMismatch);
if (aEDConfirmPassword.IsVisible() && bPasswdMismatch)
{
ErrorBox aErrorBox( this, WB_OK, aPasswdMismatch );
aErrorBox.Execute();
}
else if (bValid)
EndDialog( RET_OK );
return 1;
}

18
uui/source/passworddlg.hrc Normal file → Executable file
View File

@@ -29,12 +29,18 @@
#define PASSWORDDLG_HRC
// local identifiers
#define BTN_PASSWORD_OK 1
#define ED_PASSWORD 2
#define FT_PASSWORD 3
#define FL_FIXED_LINE_1 4
#define BTN_PASSWORD_HELP 5
#define BTN_PASSWORD_CANCEL 6
#define BTN_PASSWORD_OK 1
#define ED_PASSWORD 2
#define FT_PASSWORD 3
#define FT_CONFIRM_PASSWORD 4
#define ED_CONFIRM_PASSWORD 5
#define FL_FIXED_LINE_1 6
#define BTN_PASSWORD_HELP 7
#define BTN_PASSWORD_CANCEL 8
#define STR_TITLE_CREATE_PASSWORD 9
#define STR_TITLE_ENTER_PASSWORD 10
#define STR_PASSWORD_MISMATCH 11
#endif // PASSWORDDLG_HRC

10
uui/source/passworddlg.hxx Normal file → Executable file
View File

@@ -37,21 +37,28 @@
#include <vcl/fixed.hxx>
//============================================================================
class PasswordDialog : public ModalDialog
{
FixedText aFTPassword;
Edit aEDPassword;
FixedText aFTConfirmPassword;
Edit aEDConfirmPassword;
OKButton aOKBtn;
CancelButton aCancelBtn;
HelpButton aHelpBtn;
FixedLine aFixedLine1;
USHORT nMinLen;
String aPasswdMismatch;
DECL_LINK( OKHdl_Impl, OKButton * );
public:
PasswordDialog( Window* pParent, ::com::sun::star::task::PasswordRequestMode nDlgMode, ResMgr * pResMgr, ::rtl::OUString& aDocURL, bool bOpenToModify = false );
PasswordDialog( Window* pParent, ::com::sun::star::task::PasswordRequestMode nDlgMode, ResMgr * pResMgr, ::rtl::OUString& aDocURL,
bool bOpenToModify = false, bool bIsSimplePasswordRequest = false );
void SetMinLen( USHORT nMin ) { nMinLen = nMin; }
String GetPassword() const { return aEDPassword.GetText(); }
private:
@@ -60,3 +67,4 @@ private:
};
#endif // PASSWORDDLG_HXX

86
uui/source/passworddlg.src Normal file → Executable file
View File

@@ -41,48 +41,61 @@ ModalDialog DLG_UUI_PASSWORD
Moveable = TRUE ;
OutputSize = TRUE ;
SVLook = TRUE ;
Size = MAP_APPFONT( 145, 91 );
Text [ en-US ] = "Enter password";
Size = MAP_APPFONT( 165, 95 );
FixedText FT_PASSWORD
{
Pos = MAP_APPFONT( 3, 4 );
Size = MAP_APPFONT( 139, 28 );
Pos = MAP_APPFONT( 3, 6 );
Size = MAP_APPFONT( 159, 8 );
WordBreak = TRUE;
};
Edit ED_PASSWORD
{
Pos = MAP_APPFONT( 3, 51 );
Size = MAP_APPFONT( 139, 13 );
Pos = MAP_APPFONT( 3, 17 );
Size = MAP_APPFONT( 159, 12 );
Border = TRUE ;
PassWord = TRUE ;
};
FixedText FT_CONFIRM_PASSWORD
{
Pos = MAP_APPFONT( 3, 34 );
Size = MAP_APPFONT( 159, 8 );
WordBreak = TRUE;
};
Edit ED_CONFIRM_PASSWORD
{
Pos = MAP_APPFONT( 3, 45 );
Size = MAP_APPFONT( 159, 12 );
Border = TRUE ;
PassWord = TRUE ;
};
FixedLine FL_FIXED_LINE_1
{
Pos = MAP_APPFONT( 0, 66 );
Size = MAP_APPFONT( 145, 6 );
};
OKButton BTN_PASSWORD_OK
{
Pos = MAP_APPFONT( 27, 72 );
Size = MAP_APPFONT( 37, 15 );
DefButton = TRUE ;
DefButton = TRUE;
};
CancelButton BTN_PASSWORD_CANCEL
{
Pos = MAP_APPFONT( 66, 72 );
Size = MAP_APPFONT( 37, 15 );
Pos = MAP_APPFONT( 0, 63 );
Size = MAP_APPFONT( 165, 8 );
};
HelpButton BTN_PASSWORD_HELP
{
Pos = MAP_APPFONT( 105, 72 );
Size = MAP_APPFONT( 37, 15 );
Pos = MAP_APPFONT( 3, 76 );
Size = MAP_APPFONT( 50, 14 );
};
OKButton BTN_PASSWORD_OK
{
Pos = MAP_APPFONT( 59, 76 );
Size = MAP_APPFONT( 50, 14 );
DefButton = TRUE ;
};
CancelButton BTN_PASSWORD_CANCEL
{
Pos = MAP_APPFONT( 112, 76 );
Size = MAP_APPFONT( 50, 14 );
};
String STR_ENTER_PASSWORD_TO_OPEN
@@ -94,5 +107,30 @@ ModalDialog DLG_UUI_PASSWORD
{
Text [ en-US ] = "Enter password to modify file: \n";
};
String STR_ENTER_SIMPLE_PASSWORD
{
Text [ en-US ] = "Enter password: ";
};
String STR_CONFIRM_SIMPLE_PASSWORD
{
Text [ en-US ] = "Confirm password: ";
};
String STR_TITLE_CREATE_PASSWORD
{
Text [ en-US ] = "Set Password";
};
String STR_TITLE_ENTER_PASSWORD
{
Text [ en-US ] = "Enter Password";
};
String STR_PASSWORD_MISMATCH
{
Text [ en-US ] = "The confirmation password did not match the password. Set the password again by entering the same password in both boxes." ;
};
};

View File

@@ -46,6 +46,11 @@ String STR_ERROR_MASTERPASSWORD_WRONG
Text [ en-US ] = "Caution: If you forget the master password, you will be unable to access any of the information protected by it. Passwords are case-sensitive.";
};
String STR_ERROR_SIMPLE_PASSWORD_WRONG
{
Text [ en-US ] = "The password is incorrect.";
};
String STR_ERROR_PASSWORDS_NOT_IDENTICAL
{
Text [ en-US ] = "The password confirmation does not match.";