Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / dialog / passwd.cxx
blob5d186ba0a5be1ad57563241848d8c4acd0f4c63e
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 <comphelper/string.hxx>
21 #include <tools/shl.hxx>
22 #include <vcl/msgbox.hxx>
23 #include "svx/passwd.hxx"
24 #include <svx/dialmgr.hxx>
25 #include <svx/dialogs.hrc>
27 // class SvxPasswordDialog -----------------------------------------------
29 IMPL_LINK_NOARG(SvxPasswordDialog, ButtonHdl)
31 bool bOK = true;
32 short nRet = RET_OK;
33 OUString aEmpty;
35 if ( m_pNewPasswdED->GetText() != m_pRepeatPasswdED->GetText() )
37 ErrorBox( this, WB_OK, aRepeatPasswdErrStr ).Execute();
38 m_pNewPasswdED->SetText( aEmpty );
39 m_pRepeatPasswdED->SetText( aEmpty );
40 m_pNewPasswdED->GrabFocus();
41 bOK = false;
44 if ( bOK && aCheckPasswordHdl.IsSet() && !aCheckPasswordHdl.Call( this ) )
46 ErrorBox( this, WB_OK, aOldPasswdErrStr ).Execute();
47 m_pOldPasswdED->SetText( aEmpty );
48 m_pOldPasswdED->GrabFocus();
49 bOK = false;
52 if ( bOK )
53 EndDialog( nRet );
55 return 0;
60 IMPL_LINK_NOARG(SvxPasswordDialog, EditModifyHdl)
62 if ( !bEmpty )
64 OUString aPasswd = comphelper::string::strip(m_pRepeatPasswdED->GetText(), ' ');
65 if ( aPasswd.isEmpty() && m_pOKBtn->IsEnabled() )
66 m_pOKBtn->Disable();
67 else if ( !aPasswd.isEmpty() && !m_pOKBtn->IsEnabled() )
68 m_pOKBtn->Enable();
70 else if ( !m_pOKBtn->IsEnabled() )
71 m_pOKBtn->Enable();
72 return 0;
77 SvxPasswordDialog::SvxPasswordDialog(Window* pParent, bool bAllowEmptyPasswords, bool bDisableOldPassword)
78 : SfxModalDialog(pParent, "PasswordDialog", "svx/ui/passwd.ui")
79 , aOldPasswdErrStr(SVX_RESSTR(RID_SVXSTR_ERR_OLD_PASSWD))
80 , aRepeatPasswdErrStr(SVX_RESSTR(RID_SVXSTR_ERR_REPEAT_PASSWD ))
81 , bEmpty(bAllowEmptyPasswords)
83 get(m_pOldFL, "oldpass");
84 get(m_pOldPasswdFT, "oldpassL");
85 get(m_pOldPasswdED, "oldpassEntry");
86 get(m_pNewPasswdED, "newpassEntry");
87 get(m_pRepeatPasswdED, "confirmpassEntry");
88 get(m_pOKBtn, "ok");
90 m_pOKBtn->SetClickHdl( LINK( this, SvxPasswordDialog, ButtonHdl ) );
91 m_pRepeatPasswdED->SetModifyHdl( LINK( this, SvxPasswordDialog, EditModifyHdl ) );
92 EditModifyHdl( 0 );
94 if ( bDisableOldPassword )
96 m_pOldFL->Disable();
97 m_pOldPasswdFT->Disable();
98 m_pOldPasswdED->Disable();
99 m_pNewPasswdED->GrabFocus();
105 SvxPasswordDialog::~SvxPasswordDialog()
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */