LibreOffice Module cui (master)  1
passwdomdlg.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 <vcl/svapp.hxx>
21 #include <passwdomdlg.hxx>
22 #include <strings.hrc>
23 #include <dialmgr.hxx>
24 
26 {
27  bool bInvalidState = !m_xOpenReadonlyCB->get_active() &&
28  m_xPasswdToOpenED->get_text().isEmpty() &&
29  m_xPasswdToModifyED->get_text().isEmpty();
30  if (bInvalidState)
31  {
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();
36  }
37  else // check for mismatched passwords...
38  {
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)
43  {
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();
48 
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)
52  {
53  pEdit->set_text( "" );
54  pRepeatEdit->set_text( "" );
55  }
56  else if (nMismatch == 2)
57  {
58  m_xPasswdToOpenED->set_text( "" );
59  m_xReenterPasswdToOpenED->set_text( "" );
60  m_xPasswdToModifyED->set_text( "" );
61  m_xReenterPasswdToModifyED->set_text( "" );
62  }
63  pEdit->grab_focus();
64  }
65  else
66  {
67  m_xDialog->response(RET_OK);
68  }
69  }
70 }
71 
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 )
88 {
89  m_xOk->connect_clicked(LINK(this, PasswordToOpenModifyDialog, OkBtnClickHdl));
90 
91  if (nMaxPasswdLen)
92  {
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 );
97  }
98 
99  m_xPasswdToOpenED->grab_focus();
100 
101  m_xOptionsExpander->set_sensitive(bIsPasswordToModify);
102  if (!bIsPasswordToModify)
103  m_xOptionsExpander->hide();
104 
105  m_xOpenReadonlyCB->connect_clicked(LINK(this, PasswordToOpenModifyDialog, ReadonlyOnOffHdl));
106  ReadonlyOnOffHdl(*m_xOpenReadonlyCB);
107 }
108 
110 {
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();
115 }
116 
117 
119 {
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();
124 }
125 
126 
128 {
129  return m_xOpenReadonlyCB->get_active();
130 }
131 
133 {
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);
139 }
140 
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Entry > m_xPasswdToOpenED
Definition: passwdomdlg.hxx:27
std::unique_ptr< weld::CheckButton > m_xOpenReadonlyCB
Definition: passwdomdlg.hxx:31
std::unique_ptr< weld::Entry > m_xReenterPasswdToModifyED
Definition: passwdomdlg.hxx:35
std::unique_ptr< weld::Expander > m_xOptionsExpander
Definition: passwdomdlg.hxx:29
virtual void set_text(const OUString &rText)=0
std::unique_ptr< weld::Button > m_xOk
Definition: passwdomdlg.hxx:30
IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, weld::Button &, void)
Definition: passwdomdlg.cxx:25
bool IsRecommendToOpenReadonly() const
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
OUString GetPasswordToOpen() const
std::unique_ptr< weld::Entry > m_xPasswdToModifyED
Definition: passwdomdlg.hxx:33
PasswordToOpenModifyDialog(const PasswordToOpenModifyDialog &)=delete
std::unique_ptr< weld::Entry > m_xReenterPasswdToOpenED
Definition: passwdomdlg.hxx:28
OUString GetPasswordToModify() const
virtual void grab_focus()=0
RET_OK
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)