LibreOffice Module sfx2 (master) 1
passwd.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
26
28{
29 ModifyHdl();
30}
31
33{
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);
38}
39
40IMPL_LINK(SfxPasswordDialog, InsertTextHdl, OUString&, rTest, bool)
41{
42 if (!mbAsciiOnly)
43 return true;
44
45 const sal_Unicode* pTest = rTest.getStr();
46 sal_Int32 nLen = rTest.getLength();
47 OUStringBuffer aFilter(nLen);
48 bool bReset = false;
49 for (sal_Int32 i = 0; i < nLen; ++i)
50 {
51 if( *pTest > 0x007f )
52 bReset = true;
53 else
54 aFilter.append(*pTest);
55 ++pTest;
56 }
57
58 if (bReset)
59 {
60 rTest = aFilter.makeStringAndClear();
61 // upgrade from "Normal" to "Warning" if a invalid letter was
62 // discarded
63 m_xOnlyAsciiFT->set_label_type(weld::LabelType::Warning);
64 }
65
66 return true;
67}
68
70{
71 bool bConfirmFailed = bool( mnExtras & SfxShowExtras::CONFIRM ) &&
72 ( GetConfirm() != GetPassword() );
73 if( ( mnExtras & SfxShowExtras::CONFIRM2 ) && ( m_xConfirm2ED->get_text() != GetPassword2() ) )
74 bConfirmFailed = true;
75 if ( bConfirmFailed )
76 {
77 if (m_xConfirmFailedDialog)
78 m_xConfirmFailedDialog->response(RET_CANCEL);
79
80 m_xConfirmFailedDialog =
81 std::shared_ptr<weld::MessageDialog>(Application::CreateMessageDialog(m_xDialog.get(),
82 VclMessageType::Warning, VclButtonsType::Ok,
83 SfxResId(STR_ERROR_WRONG_CONFIRM)));
84 m_xConfirmFailedDialog->runAsync(m_xConfirmFailedDialog, [this](sal_uInt32 response){
85 m_xConfirm1ED->set_text(OUString());
86 m_xConfirm1ED->grab_focus();
87 m_xConfirmFailedDialog->response(response);
88 });
89 }
90 else
91 m_xDialog->response(RET_OK);
92}
93
94// CTOR / DTOR -----------------------------------------------------------
95
96SfxPasswordDialog::SfxPasswordDialog(weld::Widget* pParent, const OUString* pGroupText)
97 : GenericDialogController(pParent, "sfx/ui/password.ui", "PasswordDialog")
98 , m_xPassword1Box(m_xBuilder->weld_frame("password1frame"))
99 , m_xUserFT(m_xBuilder->weld_label("userft"))
100 , m_xUserED(m_xBuilder->weld_entry("usered"))
101 , m_xPassword1FT(m_xBuilder->weld_label("pass1ft"))
102 , m_xPassword1ED(m_xBuilder->weld_entry("pass1ed"))
103 , m_xConfirm1FT(m_xBuilder->weld_label("confirm1ft"))
104 , m_xConfirm1ED(m_xBuilder->weld_entry("confirm1ed"))
105 , m_xPassword2Box(m_xBuilder->weld_frame("password2frame"))
106 , m_xPassword2FT(m_xBuilder->weld_label("pass2ft"))
107 , m_xPassword2ED(m_xBuilder->weld_entry("pass2ed"))
108 , m_xConfirm2FT(m_xBuilder->weld_label("confirm2ft"))
109 , m_xConfirm2ED(m_xBuilder->weld_entry("confirm2ed"))
110 , m_xMinLengthFT(m_xBuilder->weld_label("minlenft"))
111 , m_xOnlyAsciiFT(m_xBuilder->weld_label("onlyascii"))
112 , m_xOKBtn(m_xBuilder->weld_button("ok"))
113 , maMinLenPwdStr(SfxResId(STR_PASSWD_MIN_LEN))
114 , maMinLenPwdStr1(SfxResId(STR_PASSWD_MIN_LEN1))
115 , maEmptyPwdStr(SfxResId(STR_PASSWD_EMPTY))
116 , mnMinLen(5)
117 , mnExtras(SfxShowExtras::NONE)
118 , mbAsciiOnly(false)
119{
120 Link<weld::Entry&,void> aLink = LINK(this, SfxPasswordDialog, EditModifyHdl);
121 m_xPassword1ED->connect_changed(aLink);
122 m_xPassword2ED->connect_changed(aLink);
123 Link<OUString&,bool> aLink2 = LINK(this, SfxPasswordDialog, InsertTextHdl);
124 m_xPassword1ED->connect_insert_text(aLink2);
125 m_xPassword2ED->connect_insert_text(aLink2);
126 m_xConfirm1ED->connect_insert_text(aLink2);
127 m_xConfirm2ED->connect_insert_text(aLink2);
128 m_xOKBtn->connect_clicked(LINK(this, SfxPasswordDialog, OKHdl));
129
130 if (pGroupText)
131 m_xPassword1Box->set_label(*pGroupText);
132
133 //set the text to the password length
135}
136
138{
139 //set the new string to the minimum password length
140 if (mnMinLen == 0)
141 m_xMinLengthFT->set_label(maEmptyPwdStr);
142 else
143 {
144 if( mnMinLen == 1 )
146 else
147 {
149 maMainPwdStr = maMainPwdStr.replaceAll( "$(MINLEN)", OUString::number(static_cast<sal_Int32>(mnMinLen) ) );
150 m_xMinLengthFT->set_label(maMainPwdStr);
151 }
152 }
153}
154
155
156void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
157{
158 mnMinLen = nLen;
160 ModifyHdl();
161}
162
164{
165 m_xMinLengthFT->set_visible(bShow);
166}
167
169{
170 mbAsciiOnly = true;
171 m_xOnlyAsciiFT->show();
172}
173
175{
176 m_xUserFT->hide();
177 m_xUserED->hide();
178 m_xConfirm1FT->hide();
179 m_xConfirm1ED->hide();
180 m_xPassword1FT->hide();
181 m_xPassword2Box->hide();
182 m_xPassword2FT->hide();
183 m_xPassword2ED->hide();
184 m_xPassword2FT->hide();
185 m_xConfirm2FT->hide();
186 m_xConfirm2ED->hide();
187
189 m_xPassword1FT->show();
191 {
192 m_xUserFT->show();
193 m_xUserED->show();
194 }
196 {
197 m_xConfirm1FT->show();
198 m_xConfirm1ED->show();
199 }
201 {
202 m_xPassword2Box->show();
203 m_xPassword2FT->show();
204 m_xPassword2ED->show();
205 }
207 {
208 m_xConfirm2FT->show();
209 m_xConfirm2ED->show();
210 }
211}
212
214{
215 PreRun();
216
217 return GenericDialogController::run();
218}
219
221{
224}
225/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< weld::Frame > m_xPassword1Box
Definition: passwd.hxx:48
std::unique_ptr< weld::Entry > m_xUserED
Definition: passwd.hxx:50
std::unique_ptr< weld::Entry > m_xConfirm1ED
Definition: passwd.hxx:54
SfxPasswordDialog(weld::Widget *pParent, const OUString *pGroupText=nullptr)
Definition: passwd.cxx:96
virtual short run() override
Definition: passwd.cxx:213
OUString maEmptyPwdStr
Definition: passwd.hxx:71
sal_uInt16 mnMinLen
Definition: passwd.hxx:73
std::unique_ptr< weld::Label > m_xPassword2FT
Definition: passwd.hxx:57
void ShowMinLengthText(bool bShow)
Definition: passwd.cxx:163
std::shared_ptr< weld::MessageDialog > m_xConfirmFailedDialog
Definition: passwd.hxx:67
SfxShowExtras mnExtras
Definition: passwd.hxx:74
void SetPasswdText()
Definition: passwd.cxx:137
std::unique_ptr< weld::Label > m_xConfirm2FT
Definition: passwd.hxx:59
std::unique_ptr< weld::Button > m_xOKBtn
Definition: passwd.hxx:65
OUString maMinLenPwdStr
Definition: passwd.hxx:69
void ModifyHdl()
Definition: passwd.cxx:32
void SetMinLen(sal_uInt16 Len)
Definition: passwd.cxx:156
std::unique_ptr< weld::Entry > m_xConfirm2ED
Definition: passwd.hxx:60
std::unique_ptr< weld::Label > m_xPassword1FT
Definition: passwd.hxx:51
std::unique_ptr< weld::Frame > m_xPassword2Box
Definition: passwd.hxx:56
std::unique_ptr< weld::Label > m_xConfirm1FT
Definition: passwd.hxx:53
OUString maMainPwdStr
Definition: passwd.hxx:72
std::unique_ptr< weld::Label > m_xUserFT
Definition: passwd.hxx:49
OUString maMinLenPwdStr1
Definition: passwd.hxx:70
std::unique_ptr< weld::Entry > m_xPassword1ED
Definition: passwd.hxx:52
std::unique_ptr< weld::Label > m_xMinLengthFT
Definition: passwd.hxx:62
std::unique_ptr< weld::Entry > m_xPassword2ED
Definition: passwd.hxx:58
std::unique_ptr< weld::Label > m_xOnlyAsciiFT
Definition: passwd.hxx:63
void AllowAsciiOnly()
Definition: passwd.cxx:168
NONE
int i
IMPL_LINK(SfxPasswordDialog, InsertTextHdl, OUString &, rTest, bool)
Definition: passwd.cxx:40
IMPL_LINK_NOARG(SfxPasswordDialog, EditModifyHdl, weld::Entry &, void)
Definition: passwd.cxx:27
SfxShowExtras
Definition: passwd.hxx:30
OUString SfxResId(TranslateId aId)
Definition: sfxresid.cxx:22
sal_uInt16 sal_Unicode
RET_OK
RET_CANCEL