bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / dialogs / passwdomdlg.cxx
blobf7b359bac237c9da84932ccb3361377e6877ebb7
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 <vcl/svapp.hxx>
21 #include <passwdomdlg.hxx>
22 #include <strings.hrc>
23 #include <dialmgr.hxx>
25 IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, weld::Button&, void)
27 bool bInvalidState = !m_xOpenReadonlyCB->get_active() &&
28 m_xPasswdToOpenED->get_text().isEmpty() &&
29 m_xPasswdToModifyED->get_text().isEmpty();
30 if (bInvalidState)
32 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(m_xDialog.get(),
33 VclMessageType::Warning, VclButtonsType::Ok,
34 m_bIsPasswordToModify? m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2));
35 xErrorBox->run();
37 else // check for mismatched passwords...
39 const bool bToOpenMatch = m_xPasswdToOpenED->get_text() == m_xReenterPasswdToOpenED->get_text();
40 const bool bToModifyMatch = m_xPasswdToModifyED->get_text() == m_xReenterPasswdToModifyED->get_text();
41 const int nMismatch = (bToOpenMatch? 0 : 1) + (bToModifyMatch? 0 : 1);
42 if (nMismatch > 0)
44 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(m_xDialog.get(),
45 VclMessageType::Warning, VclButtonsType::Ok,
46 nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch));
47 xErrorBox->run();
49 weld::Entry* pEdit = !bToOpenMatch ? m_xPasswdToOpenED.get() : m_xPasswdToModifyED.get();
50 weld::Entry* pRepeatEdit = !bToOpenMatch? m_xReenterPasswdToOpenED.get() : m_xReenterPasswdToModifyED.get();
51 if (nMismatch == 1)
53 pEdit->set_text( "" );
54 pRepeatEdit->set_text( "" );
56 else if (nMismatch == 2)
58 m_xPasswdToOpenED->set_text( "" );
59 m_xReenterPasswdToOpenED->set_text( "" );
60 m_xPasswdToModifyED->set_text( "" );
61 m_xReenterPasswdToModifyED->set_text( "" );
63 pEdit->grab_focus();
65 else
67 m_xDialog->response(RET_OK);
72 PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(weld::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify)
73 : SfxDialogController(pParent, "cui/ui/password.ui", "PasswordDialog")
74 , m_xPasswdToOpenED(m_xBuilder->weld_entry("newpassEntry"))
75 , m_xReenterPasswdToOpenED(m_xBuilder->weld_entry("confirmpassEntry"))
76 , m_xOptionsExpander(m_xBuilder->weld_expander("expander"))
77 , m_xOk(m_xBuilder->weld_button("ok"))
78 , m_xOpenReadonlyCB(m_xBuilder->weld_check_button("readonly"))
79 , m_xPasswdToModifyFT(m_xBuilder->weld_label("label7"))
80 , m_xPasswdToModifyED(m_xBuilder->weld_entry("newpassroEntry"))
81 , m_xReenterPasswdToModifyFT(m_xBuilder->weld_label("label8"))
82 , m_xReenterPasswdToModifyED(m_xBuilder->weld_entry("confirmropassEntry"))
83 , m_aOneMismatch( CuiResId( RID_SVXSTR_ONE_PASSWORD_MISMATCH ) )
84 , m_aTwoMismatch( CuiResId( RID_SVXSTR_TWO_PASSWORDS_MISMATCH ) )
85 , m_aInvalidStateForOkButton( CuiResId( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON ) )
86 , m_aInvalidStateForOkButton_v2( CuiResId( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON_V2 ) )
87 , m_bIsPasswordToModify( bIsPasswordToModify )
89 m_xOk->connect_clicked(LINK(this, PasswordToOpenModifyDialog, OkBtnClickHdl));
91 if (nMaxPasswdLen)
93 m_xPasswdToOpenED->set_max_length( nMaxPasswdLen );
94 m_xReenterPasswdToOpenED->set_max_length( nMaxPasswdLen );
95 m_xPasswdToModifyED->set_max_length( nMaxPasswdLen );
96 m_xReenterPasswdToModifyED->set_max_length( nMaxPasswdLen );
99 m_xPasswdToOpenED->grab_focus();
101 m_xOptionsExpander->set_sensitive(bIsPasswordToModify);
102 if (!bIsPasswordToModify)
103 m_xOptionsExpander->hide();
105 m_xOpenReadonlyCB->connect_clicked(LINK(this, PasswordToOpenModifyDialog, ReadonlyOnOffHdl));
106 ReadonlyOnOffHdl(*m_xOpenReadonlyCB);
109 OUString PasswordToOpenModifyDialog::GetPasswordToOpen() const
111 const bool bPasswdOk =
112 !m_xPasswdToOpenED->get_text().isEmpty() &&
113 m_xPasswdToOpenED->get_text() == m_xReenterPasswdToOpenED->get_text();
114 return bPasswdOk ? m_xPasswdToOpenED->get_text() : OUString();
118 OUString PasswordToOpenModifyDialog::GetPasswordToModify() const
120 const bool bPasswdOk =
121 !m_xPasswdToModifyED->get_text().isEmpty() &&
122 m_xPasswdToModifyED->get_text() == m_xReenterPasswdToModifyED->get_text();
123 return bPasswdOk ? m_xPasswdToModifyED->get_text() : OUString();
127 bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const
129 return m_xOpenReadonlyCB->get_active();
132 IMPL_LINK_NOARG(PasswordToOpenModifyDialog, ReadonlyOnOffHdl, weld::Button&, void)
134 bool bEnable = m_xOpenReadonlyCB->get_active();
135 m_xPasswdToModifyED->set_sensitive(bEnable);
136 m_xPasswdToModifyFT->set_sensitive(bEnable);
137 m_xReenterPasswdToModifyED->set_sensitive(bEnable);
138 m_xReenterPasswdToModifyFT->set_sensitive(bEnable);
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */