nss: upgrade to release 3.73
[LibreOffice.git] / uui / source / passworddlg.cxx
blob3e8d1550f6cd903c027f12ad3ed014f25ff5e742
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 .
20 #include "passworddlg.hxx"
21 #include <strings.hrc>
23 #include <unotools/resmgr.hxx>
24 #include <tools/urlobj.hxx>
25 #include <tools/debug.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/weld.hxx>
29 using namespace ::com::sun::star;
31 PasswordDialog::PasswordDialog(weld::Window* pParent,
32 task::PasswordRequestMode nDialogMode, const std::locale& rResLocale,
33 const OUString& aDocURL, bool bOpenToModify, bool bIsSimplePasswordRequest)
34 : GenericDialogController(pParent, "uui/ui/password.ui", "PasswordDialog")
35 , m_xFTPassword(m_xBuilder->weld_label("newpassFT"))
36 , m_xEDPassword(m_xBuilder->weld_entry("newpassEntry"))
37 , m_xFTConfirmPassword(m_xBuilder->weld_label("confirmpassFT"))
38 , m_xEDConfirmPassword(m_xBuilder->weld_entry("confirmpassEntry"))
39 , m_xOKBtn(m_xBuilder->weld_button("ok"))
40 , nMinLen(1)
41 , aPasswdMismatch(Translate::get(STR_PASSWORD_MISMATCH, rResLocale))
43 // tdf#115964 we can be launched before the parent has resized to its final size
44 m_xDialog->set_centered_on_parent(true);
46 if( nDialogMode == task::PasswordRequestMode_PASSWORD_REENTER )
48 const char* pOpenToModifyErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG;
49 const char* pErrStrId = bIsSimplePasswordRequest ? STR_ERROR_SIMPLE_PASSWORD_WRONG : pOpenToModifyErrStrId;
50 OUString aErrorMsg(Translate::get(pErrStrId, rResLocale));
51 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent,
52 VclMessageType::Warning, VclButtonsType::Ok, aErrorMsg));
53 xBox->run();
56 // default settings for enter password or reenter passwd...
57 OUString aTitle(Translate::get(STR_TITLE_ENTER_PASSWORD, rResLocale));
58 m_xFTConfirmPassword->hide();
59 m_xEDConfirmPassword->hide();
60 m_xFTConfirmPassword->set_sensitive(false);
61 m_xEDConfirmPassword->set_sensitive(false);
63 // settings for create password
64 if (nDialogMode == task::PasswordRequestMode_PASSWORD_CREATE)
66 aTitle = Translate::get(STR_TITLE_CREATE_PASSWORD, rResLocale);
68 m_xFTConfirmPassword->set_label(Translate::get(STR_CONFIRM_SIMPLE_PASSWORD, rResLocale));
70 m_xFTConfirmPassword->show();
71 m_xEDConfirmPassword->show();
72 m_xFTConfirmPassword->set_sensitive(true);
73 m_xEDConfirmPassword->set_sensitive(true);
76 m_xDialog->set_title(aTitle);
78 const char* pStrId = bOpenToModify ? STR_ENTER_PASSWORD_TO_MODIFY : STR_ENTER_PASSWORD_TO_OPEN;
79 OUString aMessage(Translate::get(pStrId, rResLocale));
80 INetURLObject url(aDocURL);
81 aMessage += url.HasError()
82 ? aDocURL : url.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
83 m_xFTPassword->set_label(aMessage);
85 if (bIsSimplePasswordRequest)
87 DBG_ASSERT( aDocURL.isEmpty(), "A simple password request should not have a document URL! Use document password request instead." );
88 m_xFTPassword->set_label(Translate::get(STR_ENTER_SIMPLE_PASSWORD, rResLocale));
91 m_xOKBtn->connect_clicked(LINK(this, PasswordDialog, OKHdl_Impl));
94 IMPL_LINK_NOARG(PasswordDialog, OKHdl_Impl, weld::Button&, void)
96 bool bEDPasswdValid = m_xEDPassword->get_text().getLength() >= nMinLen;
97 bool bPasswdMismatch = m_xEDConfirmPassword->get_text() != m_xEDPassword->get_text();
98 bool bValid = (!m_xEDConfirmPassword->get_visible() && bEDPasswdValid) ||
99 (m_xEDConfirmPassword->get_visible() && bEDPasswdValid && !bPasswdMismatch);
101 if (m_xEDConfirmPassword->get_visible() && bPasswdMismatch)
103 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
104 VclMessageType::Warning, VclButtonsType::Ok,
105 aPasswdMismatch));
106 xBox->run();
108 else if (bValid)
109 m_xDialog->response(RET_OK);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */