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 <sfx2/passwd.hxx>
21 #include <sfx2/sfxresid.hxx>
22 #include <sfx2/strings.hrc>
23 #include <rtl/ustrbuf.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/weld.hxx>
27 IMPL_LINK_NOARG(SfxPasswordDialog
, EditModifyHdl
, weld::Entry
&, void)
32 void SfxPasswordDialog::ModifyHdl()
34 bool bEnable
= m_xPassword1ED
->get_text().getLength() >= mnMinLen
;
35 if (m_xPassword2ED
->get_visible())
36 bEnable
= (bEnable
&& (m_xPassword2ED
->get_text().getLength() >= mnMinLen
));
37 m_xOKBtn
->set_sensitive(bEnable
);
40 IMPL_LINK(SfxPasswordDialog
, InsertTextHdl
, OUString
&, rTest
, bool)
45 const sal_Unicode
* pTest
= rTest
.getStr();
46 sal_Int32 nLen
= rTest
.getLength();
47 OUStringBuffer
aFilter(nLen
);
49 for (sal_Int32 i
= 0; i
< nLen
; ++i
)
54 aFilter
.append(*pTest
);
59 rTest
= aFilter
.makeStringAndClear();
64 IMPL_LINK_NOARG(SfxPasswordDialog
, OKHdl
, weld::Button
&, void)
66 bool bConfirmFailed
= bool( mnExtras
& SfxShowExtras::CONFIRM
) &&
67 ( GetConfirm() != GetPassword() );
68 if( ( mnExtras
& SfxShowExtras::CONFIRM2
) && ( m_xConfirm2ED
->get_text() != GetPassword2() ) )
69 bConfirmFailed
= true;
72 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(m_xDialog
.get(),
73 VclMessageType::Warning
, VclButtonsType::Ok
,
74 SfxResId(STR_ERROR_WRONG_CONFIRM
)));
76 m_xConfirm1ED
->set_text(OUString());
77 m_xConfirm1ED
->grab_focus();
80 m_xDialog
->response(RET_OK
);
83 // CTOR / DTOR -----------------------------------------------------------
85 SfxPasswordDialog::SfxPasswordDialog(weld::Widget
* pParent
, const OUString
* pGroupText
)
86 : GenericDialogController(pParent
, "sfx/ui/password.ui", "PasswordDialog")
87 , m_xPassword1Box(m_xBuilder
->weld_frame("password1frame"))
88 , m_xUserFT(m_xBuilder
->weld_label("userft"))
89 , m_xUserED(m_xBuilder
->weld_entry("usered"))
90 , m_xPassword1FT(m_xBuilder
->weld_label("pass1ft"))
91 , m_xPassword1ED(m_xBuilder
->weld_entry("pass1ed"))
92 , m_xConfirm1FT(m_xBuilder
->weld_label("confirm1ft"))
93 , m_xConfirm1ED(m_xBuilder
->weld_entry("confirm1ed"))
94 , m_xPassword2Box(m_xBuilder
->weld_frame("password2frame"))
95 , m_xPassword2FT(m_xBuilder
->weld_label("pass2ft"))
96 , m_xPassword2ED(m_xBuilder
->weld_entry("pass2ed"))
97 , m_xConfirm2FT(m_xBuilder
->weld_label("confirm2ft"))
98 , m_xConfirm2ED(m_xBuilder
->weld_entry("confirm2ed"))
99 , m_xMinLengthFT(m_xBuilder
->weld_label("minlenft"))
100 , m_xOKBtn(m_xBuilder
->weld_button("ok"))
101 , maMinLenPwdStr(SfxResId(STR_PASSWD_MIN_LEN
))
102 , maMinLenPwdStr1(SfxResId(STR_PASSWD_MIN_LEN1
))
103 , maEmptyPwdStr(SfxResId(STR_PASSWD_EMPTY
))
105 , mnExtras(SfxShowExtras::NONE
)
108 Link
<weld::Entry
&,void> aLink
= LINK(this, SfxPasswordDialog
, EditModifyHdl
);
109 m_xPassword1ED
->connect_changed(aLink
);
110 m_xPassword2ED
->connect_changed(aLink
);
111 Link
<OUString
&,bool> aLink2
= LINK(this, SfxPasswordDialog
, InsertTextHdl
);
112 m_xPassword1ED
->connect_insert_text(aLink2
);
113 m_xPassword2ED
->connect_insert_text(aLink2
);
114 m_xOKBtn
->connect_clicked(LINK(this, SfxPasswordDialog
, OKHdl
));
117 m_xPassword1Box
->set_label(*pGroupText
);
119 //set the text to the password length
123 void SfxPasswordDialog::SetPasswdText( )
125 //set the new string to the minimum password length
127 m_xMinLengthFT
->set_label(maEmptyPwdStr
);
131 m_xMinLengthFT
->set_label(maMinLenPwdStr1
);
134 maMainPwdStr
= maMinLenPwdStr
;
135 maMainPwdStr
= maMainPwdStr
.replaceAll( "$(MINLEN)", OUString::number(static_cast<sal_Int32
>(mnMinLen
) ) );
136 m_xMinLengthFT
->set_label(maMainPwdStr
);
142 void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen
)
149 void SfxPasswordDialog::ShowMinLengthText(bool bShow
)
151 m_xMinLengthFT
->set_visible(bShow
);
154 short SfxPasswordDialog::run()
158 m_xConfirm1FT
->hide();
159 m_xConfirm1ED
->hide();
160 m_xPassword1FT
->hide();
161 m_xPassword2Box
->hide();
162 m_xPassword2FT
->hide();
163 m_xPassword2ED
->hide();
164 m_xPassword2FT
->hide();
165 m_xConfirm2FT
->hide();
166 m_xConfirm2ED
->hide();
168 if (mnExtras
!= SfxShowExtras::NONE
)
169 m_xPassword1FT
->show();
170 if (mnExtras
& SfxShowExtras::USER
)
175 if (mnExtras
& SfxShowExtras::CONFIRM
)
177 m_xConfirm1FT
->show();
178 m_xConfirm1ED
->show();
180 if (mnExtras
& SfxShowExtras::PASSWORD2
)
182 m_xPassword2Box
->show();
183 m_xPassword2FT
->show();
184 m_xPassword2ED
->show();
186 if (mnExtras
& SfxShowExtras::CONFIRM2
)
188 m_xConfirm2FT
->show();
189 m_xConfirm2ED
->show();
192 return GenericDialogController::run();
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */