LibreOffice Module uui (master) 1
passworddlg.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 "passworddlg.hxx"
21#include <strings.hrc>
22
23#include <unotools/resmgr.hxx>
25#include <tools/urlobj.hxx>
26#include <tools/debug.hxx>
27#include <vcl/svapp.hxx>
28#include <vcl/weld.hxx>
29
30using namespace ::com::sun::star;
31
33 task::PasswordRequestMode nDialogMode, const std::locale& rResLocale,
34 const OUString& aDocURL, bool bOpenToModify, bool bIsSimplePasswordRequest)
35 : GenericDialogController(pParent, "uui/ui/password.ui", "PasswordDialog")
36 , m_xFTPassword(m_xBuilder->weld_label("newpassFT"))
37 , m_xEDPassword(m_xBuilder->weld_entry("newpassEntry"))
38 , m_xFTConfirmPassword(m_xBuilder->weld_label("confirmpassFT"))
39 , m_xEDConfirmPassword(m_xBuilder->weld_entry("confirmpassEntry"))
40 , m_xOKBtn(m_xBuilder->weld_button("ok"))
41 , nMinLen(1)
42 , aPasswdMismatch(Translate::get(STR_PASSWORD_MISMATCH, rResLocale))
43{
44 // tdf#115964 we can be launched before the parent has resized to its final size
45 m_xDialog->set_centered_on_parent(true);
46
47 if( nDialogMode == task::PasswordRequestMode_PASSWORD_REENTER )
48 {
49 TranslateId pOpenToModifyErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG;
50 TranslateId 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();
55 }
56
57 // default settings for enter password or reenter passwd...
58 OUString aTitle(Translate::get(STR_TITLE_ENTER_PASSWORD, rResLocale));
61 m_xFTConfirmPassword->set_sensitive(false);
62 m_xEDConfirmPassword->set_sensitive(false);
63
64 // settings for create password
65 if (nDialogMode == task::PasswordRequestMode_PASSWORD_CREATE)
66 {
67 aTitle = Translate::get(STR_TITLE_CREATE_PASSWORD, rResLocale);
68
69 m_xFTConfirmPassword->set_label(Translate::get(STR_CONFIRM_SIMPLE_PASSWORD, rResLocale));
70
73 m_xFTConfirmPassword->set_sensitive(true);
74 m_xEDConfirmPassword->set_sensitive(true);
75 }
76
77 m_xDialog->set_title(aTitle);
78
79 TranslateId pStrId = bOpenToModify ? STR_ENTER_PASSWORD_TO_MODIFY : STR_ENTER_PASSWORD_TO_OPEN;
80 OUString aMessage(Translate::get(pStrId, rResLocale));
81 INetURLObject url(aDocURL);
82
83 // tdf#66553 - add file name to title bar for password managers
84 OUString aFileName = url.getName(INetURLObject::LAST_SEGMENT, true,
86 if (!aFileName.isEmpty())
87 aFileName += " - " + utl::ConfigManager::getProductName();
88 m_xDialog->set_title(aTitle + " - " + aFileName);
89
90 aMessage += url.HasError()
92 m_xFTPassword->set_label(aMessage);
93
94 if (bIsSimplePasswordRequest)
95 {
96 DBG_ASSERT( aDocURL.isEmpty(), "A simple password request should not have a document URL! Use document password request instead." );
97 m_xFTPassword->set_label(Translate::get(STR_ENTER_SIMPLE_PASSWORD, rResLocale));
98 }
99
100 m_xOKBtn->connect_clicked(LINK(this, PasswordDialog, OKHdl_Impl));
101}
102
104{
105 bool bEDPasswdValid = m_xEDPassword->get_text().getLength() >= nMinLen;
106 bool bPasswdMismatch = m_xEDConfirmPassword->get_text() != m_xEDPassword->get_text();
107 bool bValid = (!m_xEDConfirmPassword->get_visible() && bEDPasswdValid) ||
108 (m_xEDConfirmPassword->get_visible() && bEDPasswdValid && !bPasswdMismatch);
109
110 if (m_xEDConfirmPassword->get_visible() && bPasswdMismatch)
111 {
112 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
113 VclMessageType::Warning, VclButtonsType::Ok,
114 aPasswdMismatch));
115 xBox->run();
116 }
117 else if (bValid)
118 m_xDialog->response(RET_OK);
119}
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
122
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool HasError() const
std::unique_ptr< weld::Button > m_xOKBtn
Definition: passworddlg.hxx:31
std::unique_ptr< weld::Entry > m_xEDConfirmPassword
Definition: passworddlg.hxx:30
PasswordDialog(weld::Window *pParent, css::task::PasswordRequestMode nDlgMode, const std::locale &rLocale, const OUString &aDocURL, bool bOpenToModify, bool bIsSimplePasswordRequest)
Definition: passworddlg.cxx:32
std::unique_ptr< weld::Label > m_xFTConfirmPassword
Definition: passworddlg.hxx:29
std::unique_ptr< weld::Label > m_xFTPassword
Definition: passworddlg.hxx:27
static OUString getProductName()
std::shared_ptr< weld::Dialog > m_xDialog
#define DBG_ASSERT(sCon, aError)
OUString get(TranslateId sContextAndId, const std::locale &loc)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
IMPL_LINK_NOARG(PasswordDialog, OKHdl_Impl, weld::Button &, void)
RET_OK