bump product version to 6.3.0.0.beta1
[LibreOffice.git] / uui / source / passworddlg.cxx
blob7fa17d356cbfbb60258fd369e0c01d6f7193f4ca
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& rLocale,
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, rLocale))
42 , rResLocale(rLocale)
44 // tdf#115964 we can be launched before the parent has resized to its final size
45 m_xDialog->set_centered_on_parent(true);
47 if( nDialogMode == task::PasswordRequestMode_PASSWORD_REENTER )
49 const char* pOpenToModifyErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG;
50 const char* pErrStrId = bIsSimplePasswordRequest ? STR_ERROR_SIMPLE_PASSWORD_WRONG : pOpenToModifyErrStrId;
51 OUString aErrorMsg(Translate::get(pErrStrId, rResLocale));
52 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent,
53 VclMessageType::Warning, VclButtonsType::Ok, aErrorMsg));
54 xBox->run();
57 // default settings for enter password or reenter passwd...
58 OUString aTitle(Translate::get(STR_TITLE_ENTER_PASSWORD, rResLocale));
59 m_xFTConfirmPassword->hide();
60 m_xEDConfirmPassword->hide();
61 m_xFTConfirmPassword->set_sensitive(false);
62 m_xEDConfirmPassword->set_sensitive(false);
64 // settings for create password
65 if (nDialogMode == task::PasswordRequestMode_PASSWORD_CREATE)
67 aTitle = Translate::get(STR_TITLE_CREATE_PASSWORD, rResLocale);
69 m_xFTConfirmPassword->set_label(Translate::get(STR_CONFIRM_SIMPLE_PASSWORD, rResLocale));
71 m_xFTConfirmPassword->show();
72 m_xEDConfirmPassword->show();
73 m_xFTConfirmPassword->set_sensitive(true);
74 m_xEDConfirmPassword->set_sensitive(true);
77 m_xDialog->set_title(aTitle);
79 const char* pStrId = bOpenToModify ? STR_ENTER_PASSWORD_TO_MODIFY : STR_ENTER_PASSWORD_TO_OPEN;
80 OUString aMessage(Translate::get(pStrId, rResLocale));
81 INetURLObject url(aDocURL);
82 aMessage += url.HasError()
83 ? aDocURL : url.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous);
84 m_xFTPassword->set_label(aMessage);
86 if (bIsSimplePasswordRequest)
88 DBG_ASSERT( aDocURL.isEmpty(), "A simple password request should not have a document URL! Use document password request instead." );
89 m_xFTPassword->set_label(Translate::get(STR_ENTER_SIMPLE_PASSWORD, rResLocale));
92 m_xOKBtn->connect_clicked(LINK(this, PasswordDialog, OKHdl_Impl));
95 IMPL_LINK_NOARG(PasswordDialog, OKHdl_Impl, weld::Button&, void)
97 bool bEDPasswdValid = m_xEDPassword->get_text().getLength() >= nMinLen;
98 bool bPasswdMismatch = m_xEDConfirmPassword->get_text() != m_xEDPassword->get_text();
99 bool bValid = (!m_xEDConfirmPassword->get_visible() && bEDPasswdValid) ||
100 (m_xEDConfirmPassword->get_visible() && bEDPasswdValid && !bPasswdMismatch);
102 if (m_xEDConfirmPassword->get_visible() && bPasswdMismatch)
104 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
105 VclMessageType::Warning, VclButtonsType::Ok,
106 aPasswdMismatch));
107 xBox->run();
109 else if (bValid)
110 m_xDialog->response(RET_OK);
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */