bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / dialog / passwd.cxx
blob9ae21b08e1ed80aa6f9b57f611aa3d62b34fbf43
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 // Include ---------------------------------------------------------------
22 #include <vcl/layout.hxx>
24 #include <sfx2/passwd.hxx>
25 #include "sfxtypes.hxx"
26 #include <sfx2/sfxresid.hxx>
28 #include "dialog.hrc"
32 IMPL_LINK( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit )
34 if (mbAsciiOnly && (pEdit == mpPassword1ED || pEdit == mpPassword2ED))
36 OUString aTest( pEdit->GetText() );
37 const sal_Unicode* pTest = aTest.getStr();
38 sal_Int32 nLen = aTest.getLength();
39 OUStringBuffer aFilter( nLen );
40 bool bReset = false;
41 for( sal_Int32 i = 0; i < nLen; i++ )
43 if( *pTest > 0x007f )
44 bReset = true;
45 else
46 aFilter.append( *pTest );
47 pTest++;
49 if( bReset )
51 pEdit->SetSelection( Selection( 0, nLen ) );
52 pEdit->ReplaceSelected( aFilter.makeStringAndClear() );
56 bool bEnable = mpPassword1ED->GetText().getLength() >= mnMinLen;
57 if( mpPassword2ED->IsVisible() )
58 bEnable = (bEnable && (mpPassword2ED->GetText().getLength() >= mnMinLen));
59 mpOKBtn->Enable( bEnable );
60 return 0;
63 IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl)
65 bool bConfirmFailed = bool( mnExtras & SfxShowExtras::CONFIRM ) &&
66 ( GetConfirm() != GetPassword() );
67 if( ( mnExtras & SfxShowExtras::CONFIRM2 ) && ( GetConfirm2() != GetPassword2() ) )
68 bConfirmFailed = true;
69 if ( bConfirmFailed )
71 ScopedVclPtrInstance< MessageDialog > aBox(this, SfxResId(STR_ERROR_WRONG_CONFIRM));
72 aBox->Execute();
73 mpConfirm1ED->SetText( OUString() );
74 mpConfirm1ED->GrabFocus();
76 else
77 EndDialog( RET_OK );
78 return 0;
81 // CTOR / DTOR -----------------------------------------------------------
83 SfxPasswordDialog::SfxPasswordDialog(vcl::Window* pParent, const OUString* pGroupText)
84 : ModalDialog(pParent, "PasswordDialog", "sfx/ui/password.ui")
85 , maMinLenPwdStr(SFX2_RESSTR(STR_PASSWD_MIN_LEN))
86 , maMinLenPwdStr1(SFX2_RESSTR(STR_PASSWD_MIN_LEN1))
87 , maEmptyPwdStr(SFX2_RESSTR(STR_PASSWD_EMPTY))
88 , mnMinLen(5)
89 , mnExtras(SfxShowExtras::NONE)
90 , mbAsciiOnly(false)
92 get(mpPassword1Box, "password1frame");
93 get(mpUserFT, "userft");
94 get(mpUserED, "usered");
95 get(mpPassword1FT, "pass1ft");
96 get(mpPassword1ED, "pass1ed");
97 get(mpConfirm1FT, "confirm1ft");
98 get(mpConfirm1ED, "confirm1ed");
100 get(mpPassword2Box, "password2frame");
101 get(mpPassword2FT, "pass2ft");
102 get(mpPassword2ED, "pass2ed");
103 get(mpConfirm2FT, "confirm2ft");
104 get(mpConfirm2ED, "confirm2ed");
106 get(mpMinLengthFT, "minlenft");
108 get(mpOKBtn, "ok");
110 mpPassword1ED->SetAccessibleName(SFX2_RESSTR(STR_PASSWD));
112 Link<> aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
113 mpPassword1ED->SetModifyHdl( aLink );
114 mpPassword2ED->SetModifyHdl( aLink );
115 aLink = LINK( this, SfxPasswordDialog, OKHdl );
116 mpOKBtn->SetClickHdl( aLink );
118 if (pGroupText)
119 mpPassword1Box->set_label(*pGroupText);
121 //set the text to the password length
122 SetPasswdText();
125 SfxPasswordDialog::~SfxPasswordDialog()
127 disposeOnce();
130 void SfxPasswordDialog::dispose()
132 mpPassword1Box.clear();
133 mpUserFT.clear();
134 mpUserED.clear();
135 mpPassword1FT.clear();
136 mpPassword1ED.clear();
137 mpConfirm1FT.clear();
138 mpConfirm1ED.clear();
139 mpPassword2Box.clear();
140 mpPassword2FT.clear();
141 mpPassword2ED.clear();
142 mpConfirm2FT.clear();
143 mpConfirm2ED.clear();
144 mpMinLengthFT.clear();
145 mpOKBtn.clear();
146 ModalDialog::dispose();
149 void SfxPasswordDialog::SetPasswdText( )
151 //set the new string to the minimum password length
152 if( mnMinLen == 0 )
153 mpMinLengthFT->SetText(maEmptyPwdStr);
154 else
156 if( mnMinLen == 1 )
157 mpMinLengthFT->SetText(maMinLenPwdStr1);
158 else
160 maMainPwdStr = maMinLenPwdStr;
161 maMainPwdStr = maMainPwdStr.replaceAll( "$(MINLEN)", OUString::number((sal_Int32) mnMinLen ) );
162 mpMinLengthFT->SetText(maMainPwdStr);
169 void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
171 mnMinLen = nLen;
172 SetPasswdText();
173 EditModifyHdl( NULL );
176 void SfxPasswordDialog::ShowMinLengthText(bool bShow)
178 mpMinLengthFT->Show(bShow);
183 short SfxPasswordDialog::Execute()
185 mpUserFT->Hide();
186 mpUserED->Hide();
187 mpConfirm1FT->Hide();
188 mpConfirm1ED->Hide();
189 mpPassword1FT->Hide();
190 mpPassword2Box->Hide();
191 mpPassword2FT->Hide();
192 mpPassword2ED->Hide();
193 mpPassword2FT->Hide();
194 mpConfirm2FT->Hide();
195 mpConfirm2ED->Hide();
197 if (mnExtras != SfxShowExtras::NONE)
198 mpPassword1FT->Show();
199 if (mnExtras & SfxShowExtras::USER)
201 mpUserFT->Show();
202 mpUserED->Show();
204 if (mnExtras & SfxShowExtras::CONFIRM)
206 mpConfirm1FT->Show();
207 mpConfirm1ED->Show();
209 if (mnExtras & SfxShowExtras::PASSWORD2)
211 mpPassword2Box->Show();
212 mpPassword2FT->Show();
213 mpPassword2ED->Show();
215 if (mnExtras & SfxShowExtras::CONFIRM2)
217 mpConfirm2FT->Show();
218 mpConfirm2ED->Show();
221 return ModalDialog::Execute();
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */