android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / dialogs / passwdomdlg.cxx
blob579af0edc9aa1c29ee70e9c39dd154842d2712cf
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() && !m_bAllowEmpty &&
28 m_xPasswdToOpenED->get_text().isEmpty() &&
29 m_xPasswdToModifyED->get_text().isEmpty();
30 if (bInvalidState)
32 m_xErrorBox.reset(Application::CreateMessageDialog(m_xDialog.get(),
33 VclMessageType::Warning, VclButtonsType::Ok,
34 m_bIsPasswordToModify? m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2));
35 m_xErrorBox->runAsync(m_xErrorBox, [](sal_Int32 /*nResult*/) {});
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 m_xErrorBox.reset(Application::CreateMessageDialog(m_xDialog.get(),
45 VclMessageType::Warning, VclButtonsType::Ok,
46 nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch));
47 m_xErrorBox->runAsync(m_xErrorBox, [this, bToOpenMatch, nMismatch](sal_Int32 /*nResult*/)
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();
64 });
66 else
68 m_xDialog->response(RET_OK);
73 IMPL_LINK(PasswordToOpenModifyDialog, ChangeHdl, weld::Entry&, rEntry, void)
75 weld::Label* pIndicator = nullptr;
76 int nLength = rEntry.get_text().getLength();
77 if (&rEntry == m_xPasswdToOpenED.get())
78 pIndicator = m_xPasswdToOpenInd.get();
79 else if (&rEntry == m_xReenterPasswdToOpenED.get())
80 pIndicator = m_xReenterPasswdToOpenInd.get();
81 else if (&rEntry == m_xPasswdToModifyED.get())
82 pIndicator = m_xPasswdToModifyInd.get();
83 else if (&rEntry == m_xReenterPasswdToModifyED.get())
84 pIndicator = m_xReenterPasswdToModifyInd.get();
85 assert(pIndicator);
86 pIndicator->set_visible(nLength >= m_nMaxPasswdLen);
89 PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(weld::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify)
90 : SfxDialogController(pParent, "cui/ui/password.ui", "PasswordDialog")
91 , m_xPasswdToOpenED(m_xBuilder->weld_entry("newpassEntry"))
92 , m_xPasswdToOpenInd(m_xBuilder->weld_label("newpassIndicator"))
93 , m_xReenterPasswdToOpenED(m_xBuilder->weld_entry("confirmpassEntry"))
94 , m_xReenterPasswdToOpenInd(m_xBuilder->weld_label("confirmpassIndicator"))
95 , m_xOptionsExpander(m_xBuilder->weld_expander("expander"))
96 , m_xOk(m_xBuilder->weld_button("ok"))
97 , m_xOpenReadonlyCB(m_xBuilder->weld_check_button("readonly"))
98 , m_xPasswdToModifyFT(m_xBuilder->weld_label("label7"))
99 , m_xPasswdToModifyED(m_xBuilder->weld_entry("newpassroEntry"))
100 , m_xPasswdToModifyInd(m_xBuilder->weld_label("newpassroIndicator"))
101 , m_xReenterPasswdToModifyFT(m_xBuilder->weld_label("label8"))
102 , m_xReenterPasswdToModifyED(m_xBuilder->weld_entry("confirmropassEntry"))
103 , m_xReenterPasswdToModifyInd(m_xBuilder->weld_label("confirmropassIndicator"))
104 , m_aOneMismatch( CuiResId( RID_CUISTR_ONE_PASSWORD_MISMATCH ) )
105 , m_aTwoMismatch( CuiResId( RID_CUISTR_TWO_PASSWORDS_MISMATCH ) )
106 , m_aInvalidStateForOkButton( CuiResId( RID_CUISTR_INVALID_STATE_FOR_OK_BUTTON ) )
107 , m_aInvalidStateForOkButton_v2( CuiResId( RID_CUISTR_INVALID_STATE_FOR_OK_BUTTON_V2 ) )
108 , m_nMaxPasswdLen(nMaxPasswdLen)
109 , m_bIsPasswordToModify( bIsPasswordToModify )
110 , m_bAllowEmpty( false )
112 m_xOk->connect_clicked(LINK(this, PasswordToOpenModifyDialog, OkBtnClickHdl));
114 if (nMaxPasswdLen)
116 OUString aIndicatorTemplate(CuiResId(RID_CUISTR_PASSWORD_LEN_INDICATOR).replaceFirst("%1", OUString::number(nMaxPasswdLen)));
117 m_xPasswdToOpenED->set_max_length( nMaxPasswdLen );
118 m_xPasswdToOpenED->connect_changed(LINK(this, PasswordToOpenModifyDialog, ChangeHdl));
119 m_xPasswdToOpenInd->set_label(aIndicatorTemplate);
120 m_xReenterPasswdToOpenED->set_max_length( nMaxPasswdLen );
121 m_xReenterPasswdToOpenED->connect_changed(LINK(this, PasswordToOpenModifyDialog, ChangeHdl));
122 m_xReenterPasswdToOpenInd->set_label(aIndicatorTemplate);
123 m_xPasswdToModifyED->set_max_length( nMaxPasswdLen );
124 m_xPasswdToModifyED->connect_changed(LINK(this, PasswordToOpenModifyDialog, ChangeHdl));
125 m_xPasswdToModifyInd->set_label(aIndicatorTemplate);
126 m_xReenterPasswdToModifyED->set_max_length( nMaxPasswdLen );
127 m_xReenterPasswdToModifyED->connect_changed(LINK(this, PasswordToOpenModifyDialog, ChangeHdl));
128 m_xReenterPasswdToModifyInd->set_label(aIndicatorTemplate);
131 m_xPasswdToOpenED->grab_focus();
133 m_xOptionsExpander->set_sensitive(bIsPasswordToModify);
134 if (!bIsPasswordToModify)
135 m_xOptionsExpander->hide();
137 m_xOpenReadonlyCB->connect_toggled(LINK(this, PasswordToOpenModifyDialog, ReadonlyOnOffHdl));
138 ReadonlyOnOffHdl(*m_xOpenReadonlyCB);
141 PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog()
143 if (m_xErrorBox)
145 m_xErrorBox->response(RET_CANCEL);
149 void PasswordToOpenModifyDialog::AllowEmpty()
151 m_bAllowEmpty = true;
154 OUString PasswordToOpenModifyDialog::GetPasswordToOpen() const
156 const bool bPasswdOk =
157 !m_xPasswdToOpenED->get_text().isEmpty() &&
158 m_xPasswdToOpenED->get_text() == m_xReenterPasswdToOpenED->get_text();
159 return bPasswdOk ? m_xPasswdToOpenED->get_text() : OUString();
163 OUString PasswordToOpenModifyDialog::GetPasswordToModify() const
165 const bool bPasswdOk =
166 !m_xPasswdToModifyED->get_text().isEmpty() &&
167 m_xPasswdToModifyED->get_text() == m_xReenterPasswdToModifyED->get_text();
168 return bPasswdOk ? m_xPasswdToModifyED->get_text() : OUString();
172 bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const
174 return m_xOpenReadonlyCB->get_active();
177 IMPL_LINK_NOARG(PasswordToOpenModifyDialog, ReadonlyOnOffHdl, weld::Toggleable&, void)
179 bool bEnable = m_xOpenReadonlyCB->get_active();
180 m_xPasswdToModifyED->set_sensitive(bEnable);
181 m_xPasswdToModifyFT->set_sensitive(bEnable);
182 m_xReenterPasswdToModifyED->set_sensitive(bEnable);
183 m_xReenterPasswdToModifyFT->set_sensitive(bEnable);
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */