Line data Source code
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 <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>
26 : #include "passwd.hrc"
27 :
28 : // class SvxPasswordDialog -----------------------------------------------
29 :
30 0 : IMPL_LINK_NOARG(SvxPasswordDialog, ButtonHdl)
31 : {
32 0 : sal_Bool bOK = sal_True;
33 0 : short nRet = RET_OK;
34 0 : String aEmpty;
35 :
36 0 : if ( aNewPasswdED.GetText() != aRepeatPasswdED.GetText() )
37 : {
38 0 : ErrorBox( this, WB_OK, aRepeatPasswdErrStr ).Execute();
39 0 : aNewPasswdED.SetText( aEmpty );
40 0 : aRepeatPasswdED.SetText( aEmpty );
41 0 : aNewPasswdED.GrabFocus();
42 0 : bOK = sal_False;
43 : }
44 :
45 0 : if ( bOK && aCheckPasswordHdl.IsSet() && !aCheckPasswordHdl.Call( this ) )
46 : {
47 0 : ErrorBox( this, WB_OK, aOldPasswdErrStr ).Execute();
48 0 : aOldPasswdED.SetText( aEmpty );
49 0 : aOldPasswdED.GrabFocus();
50 0 : bOK = sal_False;
51 : }
52 :
53 0 : if ( bOK )
54 0 : EndDialog( nRet );
55 :
56 0 : return 0;
57 : }
58 :
59 : // -----------------------------------------------------------------------
60 :
61 0 : IMPL_LINK_NOARG(SvxPasswordDialog, EditModifyHdl)
62 : {
63 0 : if ( !bEmpty )
64 : {
65 0 : String aPasswd = comphelper::string::strip(aRepeatPasswdED.GetText(), ' ');
66 0 : if ( !aPasswd.Len() && aOKBtn.IsEnabled() )
67 0 : aOKBtn.Disable();
68 0 : else if ( aPasswd.Len() && !aOKBtn.IsEnabled() )
69 0 : aOKBtn.Enable();
70 : }
71 0 : else if ( !aOKBtn.IsEnabled() )
72 0 : aOKBtn.Enable();
73 0 : return 0;
74 : }
75 :
76 : // -----------------------------------------------------------------------
77 :
78 0 : SvxPasswordDialog::SvxPasswordDialog( Window* pParent, sal_Bool bAllowEmptyPasswords, sal_Bool bDisableOldPassword ) :
79 0 : SfxModalDialog( pParent, SVX_RES( RID_SVXDLG_PASSWORD ) ),
80 0 : aOldFL ( this, SVX_RES( FL_OLD_PASSWD ) ),
81 0 : aOldPasswdFT ( this, SVX_RES( FT_OLD_PASSWD ) ),
82 0 : aOldPasswdED ( this, SVX_RES( ED_OLD_PASSWD ) ),
83 0 : aNewFL ( this, SVX_RES( FL_NEW_PASSWD ) ),
84 0 : aNewPasswdFT ( this, SVX_RES( FT_NEW_PASSWD ) ),
85 0 : aNewPasswdED ( this, SVX_RES( ED_NEW_PASSWD ) ),
86 0 : aRepeatPasswdFT ( this, SVX_RES( FT_REPEAT_PASSWD ) ),
87 0 : aRepeatPasswdED ( this, SVX_RES( ED_REPEAT_PASSWD ) ),
88 0 : aOKBtn ( this, SVX_RES( BTN_PASSWD_OK ) ),
89 0 : aEscBtn ( this, SVX_RES( BTN_PASSWD_ESC ) ),
90 0 : aHelpBtn ( this, SVX_RES( BTN_PASSWD_HELP ) ),
91 0 : aOldPasswdErrStr ( SVX_RES( STR_ERR_OLD_PASSWD ) ),
92 0 : aRepeatPasswdErrStr ( SVX_RES( STR_ERR_REPEAT_PASSWD ) ),
93 0 : bEmpty ( bAllowEmptyPasswords )
94 : {
95 0 : FreeResource();
96 :
97 0 : aOKBtn.SetClickHdl( LINK( this, SvxPasswordDialog, ButtonHdl ) );
98 0 : aRepeatPasswdED.SetModifyHdl( LINK( this, SvxPasswordDialog, EditModifyHdl ) );
99 0 : EditModifyHdl( 0 );
100 :
101 0 : if ( bDisableOldPassword )
102 : {
103 0 : aOldFL.Disable();
104 0 : aOldPasswdFT.Disable();
105 0 : aOldPasswdED.Disable();
106 0 : aNewPasswdED.GrabFocus();
107 : }
108 0 : }
109 :
110 : // -----------------------------------------------------------------------
111 :
112 0 : SvxPasswordDialog::~SvxPasswordDialog()
113 : {
114 0 : }
115 :
116 : // -----------------------------------------------------------------------
117 :
118 :
119 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|