1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "passworddlg.hxx"
23 #include <vcl/layout.hxx>
25 using namespace ::com::sun::star
;
27 PasswordDialog::PasswordDialog(vcl::Window
* _pParent
,
28 task::PasswordRequestMode nDlgMode
, ResMgr
* pResMgr
,
29 const OUString
& aDocURL
, bool bOpenToModify
, bool bIsSimplePasswordRequest
)
30 : ModalDialog(_pParent
, "PasswordDialog", "uui/ui/password.ui")
32 , aPasswdMismatch(ResId(STR_PASSWORD_MISMATCH
, *pResMgr
))
33 , nDialogMode(nDlgMode
)
34 , pResourceMgr(pResMgr
)
36 get(m_pFTPassword
, "newpassFT");
37 get(m_pEDPassword
, "newpassEntry");
38 get(m_pFTConfirmPassword
, "confirmpassFT");
39 get(m_pEDConfirmPassword
, "confirmpassEntry");
42 if( nDialogMode
== task::PasswordRequestMode_PASSWORD_REENTER
)
44 const sal_uInt16 nOpenToModifyErrStrId
= bOpenToModify
? STR_ERROR_PASSWORD_TO_MODIFY_WRONG
: STR_ERROR_PASSWORD_TO_OPEN_WRONG
;
45 const sal_uInt16 nErrStrId
= bIsSimplePasswordRequest
? STR_ERROR_SIMPLE_PASSWORD_WRONG
: nOpenToModifyErrStrId
;
46 OUString
aErrorMsg(ResId(nErrStrId
, *pResourceMgr
).toString());
47 ScopedVclPtrInstance
< MessageDialog
> aErrorBox(GetParent(), aErrorMsg
);
51 // default settings for enter password or reenter passwd...
52 OUString
aTitle(ResId(STR_TITLE_ENTER_PASSWORD
, *pResourceMgr
).toString());
53 m_pFTConfirmPassword
->Hide();
54 m_pEDConfirmPassword
->Hide();
55 m_pFTConfirmPassword
->Enable( false );
56 m_pEDConfirmPassword
->Enable( false );
58 // settings for create password
59 if (nDialogMode
== task::PasswordRequestMode_PASSWORD_CREATE
)
61 aTitle
= ResId(STR_TITLE_CREATE_PASSWORD
, *pResourceMgr
).toString();
63 m_pFTConfirmPassword
->SetText(ResId(STR_CONFIRM_SIMPLE_PASSWORD
, *pResourceMgr
).toString());
65 m_pFTConfirmPassword
->Show();
66 m_pEDConfirmPassword
->Show();
67 m_pFTConfirmPassword
->Enable( true );
68 m_pEDConfirmPassword
->Enable( true );
73 sal_uInt16 nStrId
= bOpenToModify
? STR_ENTER_PASSWORD_TO_MODIFY
: STR_ENTER_PASSWORD_TO_OPEN
;
74 m_pFTPassword
->SetText(ResId(nStrId
, *pResourceMgr
).toString());
75 m_pFTPassword
->SetText( m_pFTPassword
->GetText() + aDocURL
);
76 if (bIsSimplePasswordRequest
)
78 DBG_ASSERT( aDocURL
.isEmpty(), "A simple password request should not have a document URL! Use document password request instead." );
79 m_pFTPassword
->SetText(ResId(STR_ENTER_SIMPLE_PASSWORD
, *pResourceMgr
).toString());
82 m_pOKBtn
->SetClickHdl( LINK( this, PasswordDialog
, OKHdl_Impl
) );
85 PasswordDialog::~PasswordDialog()
90 void PasswordDialog::dispose()
92 m_pFTPassword
.clear();
93 m_pEDPassword
.clear();
94 m_pFTConfirmPassword
.clear();
95 m_pEDConfirmPassword
.clear();
97 ModalDialog::dispose();
100 IMPL_LINK_NOARG(PasswordDialog
, OKHdl_Impl
)
102 bool bEDPasswdValid
= m_pEDPassword
->GetText().getLength() >= nMinLen
;
103 bool bPasswdMismatch
= m_pEDConfirmPassword
->GetText() != m_pEDPassword
->GetText();
104 bool bValid
= (!m_pEDConfirmPassword
->IsVisible() && bEDPasswdValid
) ||
105 (m_pEDConfirmPassword
->IsVisible() && bEDPasswdValid
&& !bPasswdMismatch
);
107 if (m_pEDConfirmPassword
->IsVisible() && bPasswdMismatch
)
109 ScopedVclPtrInstance
< MessageDialog
> aErrorBox(this, aPasswdMismatch
);
110 aErrorBox
->Execute();
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */