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 "passwdomdlg.hxx"
23 #include "dialmgr.hxx"
25 #include <sfx2/tabdlg.hxx>
26 #include <vcl/fixed.hxx>
27 #include <vcl/edit.hxx>
28 #include <vcl/button.hxx>
29 #include <vcl/layout.hxx>
30 #include <vcl/settings.hxx>
32 struct PasswordToOpenModifyDialog_Impl
34 VclPtr
<PasswordToOpenModifyDialog
> m_pParent
;
36 VclPtr
<Edit
> m_pPasswdToOpenED
;
37 VclPtr
<Edit
> m_pReenterPasswdToOpenED
;
38 VclPtr
<VclExpander
> m_pOptionsExpander
;
39 VclPtr
<OKButton
> m_pOk
;
40 VclPtr
<CheckBox
> m_pOpenReadonlyCB
;
41 VclPtr
<Edit
> m_pPasswdToModifyED
;
42 VclPtr
<Edit
> m_pReenterPasswdToModifyED
;
44 OUString m_aOneMismatch
;
45 OUString m_aTwoMismatch
;
46 OUString m_aInvalidStateForOkButton
;
47 OUString m_aInvalidStateForOkButton_v2
;
49 bool m_bIsPasswordToModify
;
52 DECL_LINK( OkBtnClickHdl
, OKButton
* );
54 PasswordToOpenModifyDialog_Impl( PasswordToOpenModifyDialog
* pParent
,
55 sal_uInt16 nMinPasswdLen
, sal_uInt16 nMaxPasswdLen
, bool bIsPasswordToModify
);
58 PasswordToOpenModifyDialog_Impl::PasswordToOpenModifyDialog_Impl(
59 PasswordToOpenModifyDialog
* pParent
,
60 sal_uInt16 nMinPasswdLen
,
61 sal_uInt16 nMaxPasswdLen
,
62 bool bIsPasswordToModify
)
63 : m_pParent( pParent
)
64 , m_aOneMismatch( CUI_RES( RID_SVXSTR_ONE_PASSWORD_MISMATCH
) )
65 , m_aTwoMismatch( CUI_RES( RID_SVXSTR_TWO_PASSWORDS_MISMATCH
) )
66 , m_aInvalidStateForOkButton( CUI_RES( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON
) )
67 , m_aInvalidStateForOkButton_v2( CUI_RES( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON_V2
) )
68 , m_bIsPasswordToModify( bIsPasswordToModify
)
70 pParent
->get(m_pPasswdToOpenED
, "newpassEntry");
71 pParent
->get(m_pReenterPasswdToOpenED
, "confirmpassEntry");
72 pParent
->get(m_pOk
, "ok");
73 pParent
->get(m_pOpenReadonlyCB
, "readonly");
74 pParent
->get(m_pPasswdToModifyED
, "newpassroEntry");
75 pParent
->get(m_pReenterPasswdToModifyED
, "confirmropassEntry");
76 pParent
->get(m_pOptionsExpander
, "expander");
78 m_pOk
->SetClickHdl( LINK( this, PasswordToOpenModifyDialog_Impl
, OkBtnClickHdl
) );
82 m_pPasswdToOpenED
->SetMaxTextLen( nMaxPasswdLen
);
83 m_pReenterPasswdToOpenED
->SetMaxTextLen( nMaxPasswdLen
);
84 m_pPasswdToModifyED
->SetMaxTextLen( nMaxPasswdLen
);
85 m_pReenterPasswdToModifyED
->SetMaxTextLen( nMaxPasswdLen
);
88 (void) nMinPasswdLen
; // currently not supported
90 m_pPasswdToOpenED
->GrabFocus();
92 m_pOptionsExpander
->Enable(bIsPasswordToModify
);
93 if (!bIsPasswordToModify
)
94 m_pOptionsExpander
->Hide();
97 IMPL_LINK( PasswordToOpenModifyDialog_Impl
, OkBtnClickHdl
, OKButton
*, /*pBtn*/ )
99 bool bInvalidState
= !m_pOpenReadonlyCB
->IsChecked() &&
100 m_pPasswdToOpenED
->GetText().isEmpty() &&
101 m_pPasswdToModifyED
->GetText().isEmpty();
104 ScopedVclPtrInstance
<MessageDialog
> aErrorBox(m_pParent
,
105 m_bIsPasswordToModify
? m_aInvalidStateForOkButton
: m_aInvalidStateForOkButton_v2
);
106 aErrorBox
->Execute();
108 else // check for mismatched passwords...
110 const bool bToOpenMatch
= m_pPasswdToOpenED
->GetText() == m_pReenterPasswdToOpenED
->GetText();
111 const bool bToModifyMatch
= m_pPasswdToModifyED
->GetText() == m_pReenterPasswdToModifyED
->GetText();
112 const int nMismatch
= (bToOpenMatch
? 0 : 1) + (bToModifyMatch
? 0 : 1);
115 ScopedVclPtrInstance
< MessageDialog
> aErrorBox(m_pParent
, nMismatch
== 1 ? m_aOneMismatch
: m_aTwoMismatch
);
116 aErrorBox
->Execute();
118 Edit
* pEdit
= !bToOpenMatch
? m_pPasswdToOpenED
: m_pPasswdToModifyED
;
119 Edit
* pRepeatEdit
= !bToOpenMatch
? m_pReenterPasswdToOpenED
: m_pReenterPasswdToModifyED
;
123 pEdit
->SetText( aEmpty
);
124 pRepeatEdit
->SetText( aEmpty
);
126 else if (nMismatch
== 2)
128 m_pPasswdToOpenED
->SetText( aEmpty
);
129 m_pReenterPasswdToOpenED
->SetText( aEmpty
);
130 m_pPasswdToModifyED
->SetText( aEmpty
);
131 m_pReenterPasswdToModifyED
->SetText( aEmpty
);
137 m_pParent
->EndDialog( RET_OK
);
144 PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(
145 vcl::Window
* pParent
, sal_uInt16 nMinPasswdLen
,
146 sal_uInt16 nMaxPasswdLen
, bool bIsPasswordToModify
)
147 : SfxModalDialog( pParent
, "PasswordDialog", "cui/ui/password.ui" )
149 m_pImpl
.reset(new PasswordToOpenModifyDialog_Impl(this,
150 nMinPasswdLen
, nMaxPasswdLen
, bIsPasswordToModify
) );
154 PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog()
159 void PasswordToOpenModifyDialog::dispose()
161 SfxModalDialog::dispose();
165 OUString
PasswordToOpenModifyDialog::GetPasswordToOpen() const
167 const bool bPasswdOk
=
168 !m_pImpl
->m_pPasswdToOpenED
->GetText().isEmpty() &&
169 m_pImpl
->m_pPasswdToOpenED
->GetText() == m_pImpl
->m_pReenterPasswdToOpenED
->GetText();
170 return bPasswdOk
? m_pImpl
->m_pPasswdToOpenED
->GetText() : OUString();
174 OUString
PasswordToOpenModifyDialog::GetPasswordToModify() const
176 const bool bPasswdOk
=
177 !m_pImpl
->m_pPasswdToModifyED
->GetText().isEmpty() &&
178 m_pImpl
->m_pPasswdToModifyED
->GetText() == m_pImpl
->m_pReenterPasswdToModifyED
->GetText();
179 return bPasswdOk
? m_pImpl
->m_pPasswdToModifyED
->GetText() : OUString();
183 bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const
185 return m_pImpl
->m_pOpenReadonlyCB
->IsChecked();
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */