Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "passwdomdlg.hrc"
30 : : #include "passwdomdlg.hxx"
31 : :
32 : : #include "cuires.hrc"
33 : : #include "dialmgr.hxx"
34 : :
35 : : #include <sfx2/tabdlg.hxx>
36 : : #include <vcl/fixed.hxx>
37 : : #include <vcl/edit.hxx>
38 : : #include <vcl/button.hxx>
39 : : #include <vcl/morebtn.hxx>
40 : : #include <vcl/settings.hxx>
41 : : #include <vcl/msgbox.hxx>
42 : :
43 : :
44 : : //////////////////////////////////////////////////////////////////////
45 : :
46 : : class PasswordReenterEdit_Impl : public Edit
47 : : {
48 : : String m_aDefaultTxt;
49 : :
50 : : // disallow use of copy c-tor and assignment operator
51 : : PasswordReenterEdit_Impl( const PasswordReenterEdit_Impl & );
52 : : PasswordReenterEdit_Impl & operator = ( const PasswordReenterEdit_Impl & );
53 : :
54 : : public:
55 : : PasswordReenterEdit_Impl( Window * pParent, const ResId &rResId );
56 : : virtual ~PasswordReenterEdit_Impl();
57 : :
58 : : // Edit
59 : : virtual void Paint( const Rectangle& rRect );
60 : : };
61 : :
62 : :
63 : 0 : PasswordReenterEdit_Impl::PasswordReenterEdit_Impl( Window * pParent, const ResId &rResId ) :
64 [ # # ]: 0 : Edit( pParent, rResId )
65 : : {
66 : 0 : }
67 : :
68 : :
69 [ # # ]: 0 : PasswordReenterEdit_Impl::~PasswordReenterEdit_Impl()
70 : : {
71 [ # # ]: 0 : }
72 : :
73 : :
74 : 0 : void PasswordReenterEdit_Impl::Paint( const Rectangle& rRect )
75 : : {
76 [ # # ]: 0 : if (GetText().Len() == 0)
77 : : {
78 : 0 : Push( PUSH_TEXTCOLOR );
79 [ # # ]: 0 : SetTextColor( Color( COL_GRAY ) );
80 [ # # ]: 0 : DrawText( Point(), m_aDefaultTxt );
81 : :
82 : 0 : Pop();
83 : : }
84 : : else
85 : 0 : Edit::Paint( rRect );
86 : 0 : }
87 : :
88 : :
89 : : //////////////////////////////////////////////////////////////////////
90 : :
91 : : struct PasswordToOpenModifyDialog_Impl
92 : : {
93 : : PasswordToOpenModifyDialog * m_pParent;
94 : :
95 : : FixedLine m_aFileEncryptionFL;
96 : : FixedText m_aPasswdToOpenFT;
97 : : Edit m_aPasswdToOpenED;
98 : : FixedText m_aReenterPasswdToOpenFT;
99 : : PasswordReenterEdit_Impl m_aReenterPasswdToOpenED;
100 : : FixedText m_aPasswdNoteFT;
101 : : FixedLine m_aButtonsFL;
102 : : MoreButton m_aMoreFewerOptionsBTN;
103 : : OKButton m_aOk;
104 : : CancelButton m_aCancel;
105 : : FixedLine m_aFileSharingOptionsFL;
106 : : CheckBox m_aOpenReadonlyCB;
107 : : FixedText m_aPasswdToModifyFT;
108 : : Edit m_aPasswdToModifyED;
109 : : FixedText m_aReenterPasswdToModifyFT;
110 : : PasswordReenterEdit_Impl m_aReenterPasswdToModifyED;
111 : :
112 : : String m_aOneMismatch;
113 : : String m_aTwoMismatch;
114 : : String m_aInvalidStateForOkButton;
115 : : String m_aInvalidStateForOkButton_v2;
116 : :
117 : : bool m_bIsPasswordToModify;
118 : :
119 : :
120 : : DECL_LINK( OkBtnClickHdl, OKButton * );
121 : :
122 : : PasswordToOpenModifyDialog_Impl( PasswordToOpenModifyDialog * pParent,
123 : : sal_uInt16 nMinPasswdLen, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify );
124 : : ~PasswordToOpenModifyDialog_Impl();
125 : : };
126 : :
127 : :
128 : 0 : PasswordToOpenModifyDialog_Impl::PasswordToOpenModifyDialog_Impl(
129 : : PasswordToOpenModifyDialog * pParent,
130 : : sal_uInt16 nMinPasswdLen,
131 : : sal_uInt16 nMaxPasswdLen,
132 : : bool bIsPasswordToModify ) :
133 : : m_pParent( pParent ),
134 : 0 : m_aFileEncryptionFL ( pParent, CUI_RES( FL_FILE_ENCRYPTION ) ),
135 [ # # ]: 0 : m_aPasswdToOpenFT ( pParent, CUI_RES( FT_PASSWD_TO_OPEN ) ),
136 [ # # ]: 0 : m_aPasswdToOpenED ( pParent, CUI_RES( ED_PASSWD_TO_OPEN ) ),
137 [ # # ]: 0 : m_aReenterPasswdToOpenFT ( pParent, CUI_RES( FT_REENTER_PASSWD_TO_OPEN ) ),
138 [ # # ]: 0 : m_aReenterPasswdToOpenED ( pParent, CUI_RES( ED_REENTER_PASSWD_TO_OPEN ) ),
139 [ # # ]: 0 : m_aPasswdNoteFT ( pParent, CUI_RES( FT_PASSWD_NOTE ) ),
140 [ # # ]: 0 : m_aButtonsFL ( pParent, CUI_RES( FL_BUTTONS ) ),
141 [ # # ]: 0 : m_aMoreFewerOptionsBTN ( pParent, CUI_RES( BTN_MORE_FEWER_OPTIONS ) ),
142 [ # # ]: 0 : m_aOk ( pParent, CUI_RES( BTN_OK ) ),
143 [ # # ]: 0 : m_aCancel ( pParent, CUI_RES( BTN_CANCEL ) ),
144 [ # # ]: 0 : m_aFileSharingOptionsFL ( pParent, CUI_RES( FL_FILE_SHARING_OPTIONS ) ),
145 [ # # ]: 0 : m_aOpenReadonlyCB ( pParent, CUI_RES( CB_OPEN_READONLY ) ),
146 [ # # ]: 0 : m_aPasswdToModifyFT ( pParent, CUI_RES( FT_PASSWD_TO_MODIFY ) ),
147 [ # # ]: 0 : m_aPasswdToModifyED ( pParent, CUI_RES( ED_PASSWD_TO_MODIFY ) ),
148 [ # # ]: 0 : m_aReenterPasswdToModifyFT ( pParent, CUI_RES( FT_REENTER_PASSWD_TO_MODIFY ) ),
149 [ # # ]: 0 : m_aReenterPasswdToModifyED ( pParent, CUI_RES( ED_REENTER_PASSWD_TO_MODIFY ) ),
150 [ # # ]: 0 : m_aOneMismatch( CUI_RES( STR_ONE_PASSWORD_MISMATCH ) ),
151 [ # # ]: 0 : m_aTwoMismatch( CUI_RES( STR_TWO_PASSWORDS_MISMATCH ) ),
152 [ # # ]: 0 : m_aInvalidStateForOkButton( CUI_RES( STR_INVALID_STATE_FOR_OK_BUTTON ) ),
153 [ # # ]: 0 : m_aInvalidStateForOkButton_v2( CUI_RES( STR_INVALID_STATE_FOR_OK_BUTTON_V2 ) ),
154 [ # # ][ # # ]: 0 : m_bIsPasswordToModify( bIsPasswordToModify )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
155 : : {
156 [ # # ][ # # ]: 0 : m_aMoreFewerOptionsBTN.SetMoreText( String( CUI_RES( STR_MORE_OPTIONS ) ) );
[ # # ][ # # ]
157 [ # # ][ # # ]: 0 : m_aMoreFewerOptionsBTN.SetLessText( String( CUI_RES( STR_FEWER_OPTIONS ) ) );
[ # # ][ # # ]
158 : :
159 [ # # ]: 0 : m_aOk.SetClickHdl( LINK( this, PasswordToOpenModifyDialog_Impl, OkBtnClickHdl ) );
160 : :
161 [ # # ]: 0 : if (nMaxPasswdLen)
162 : : {
163 [ # # ]: 0 : m_aPasswdToOpenED.SetMaxTextLen( nMaxPasswdLen );
164 [ # # ]: 0 : m_aReenterPasswdToOpenED.SetMaxTextLen( nMaxPasswdLen );
165 [ # # ]: 0 : m_aPasswdToModifyED.SetMaxTextLen( nMaxPasswdLen );
166 [ # # ]: 0 : m_aReenterPasswdToModifyED.SetMaxTextLen( nMaxPasswdLen );
167 : : }
168 : :
169 : : (void) nMinPasswdLen; // currently not supported
170 : :
171 [ # # ]: 0 : m_aPasswdToOpenED.GrabFocus();
172 : :
173 [ # # ]: 0 : m_aMoreFewerOptionsBTN.Enable( bIsPasswordToModify );
174 [ # # ]: 0 : if (!bIsPasswordToModify)
175 [ # # ]: 0 : m_aMoreFewerOptionsBTN.Hide( sal_True );
176 : 0 : }
177 : :
178 : :
179 [ # # ][ # # ]: 0 : PasswordToOpenModifyDialog_Impl::~PasswordToOpenModifyDialog_Impl()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
180 : : {
181 : 0 : }
182 : :
183 : 0 : IMPL_LINK( PasswordToOpenModifyDialog_Impl, OkBtnClickHdl, OKButton *, EMPTYARG /*pBtn*/ )
184 : : {
185 [ # # ]: 0 : bool bInvalidState = !m_aOpenReadonlyCB.IsChecked() &&
186 [ # # ][ # # ]: 0 : m_aPasswdToOpenED.GetText().Len() == 0 &&
[ # # ]
187 [ # # # # ]: 0 : m_aPasswdToModifyED.GetText().Len() == 0;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
188 [ # # ]: 0 : if (bInvalidState)
189 : : {
190 : : ErrorBox aErrorBox( m_pParent, WB_OK,
191 [ # # ][ # # ]: 0 : m_bIsPasswordToModify? m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2 );
192 [ # # ][ # # ]: 0 : aErrorBox.Execute();
193 : : }
194 : : else // check for mismatched passwords...
195 : : {
196 [ # # ][ # # ]: 0 : const bool bToOpenMatch = m_aPasswdToOpenED.GetText() == m_aReenterPasswdToOpenED.GetText();
[ # # ]
197 [ # # ][ # # ]: 0 : const bool bToModifyMatch = m_aPasswdToModifyED.GetText() == m_aReenterPasswdToModifyED.GetText();
[ # # ]
198 [ # # ][ # # ]: 0 : const int nMismatch = (bToOpenMatch? 0 : 1) + (bToModifyMatch? 0 : 1);
199 [ # # ]: 0 : if (nMismatch > 0)
200 : : {
201 [ # # ][ # # ]: 0 : ErrorBox aErrorBox( m_pParent, WB_OK, nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch );
202 [ # # ]: 0 : aErrorBox.Execute();
203 : :
204 [ # # ]: 0 : Edit &rEdit = !bToOpenMatch? m_aPasswdToOpenED : m_aPasswdToModifyED;
205 [ # # ]: 0 : PasswordReenterEdit_Impl &rRepeatEdit = !bToOpenMatch? m_aReenterPasswdToOpenED : m_aReenterPasswdToModifyED;
206 [ # # ]: 0 : String aEmpty;
207 [ # # ]: 0 : if (nMismatch == 1)
208 : : {
209 [ # # ]: 0 : rEdit.SetText( aEmpty );
210 [ # # ]: 0 : rRepeatEdit.SetText( aEmpty );
211 : : }
212 [ # # ]: 0 : else if (nMismatch == 2)
213 : : {
214 [ # # ]: 0 : m_aPasswdToOpenED.SetText( aEmpty );
215 [ # # ]: 0 : m_aReenterPasswdToOpenED.SetText( aEmpty );
216 [ # # ]: 0 : m_aPasswdToModifyED.SetText( aEmpty );
217 [ # # ]: 0 : m_aReenterPasswdToModifyED.SetText( aEmpty );
218 : : }
219 [ # # ][ # # ]: 0 : rEdit.GrabFocus();
[ # # ]
220 : : }
221 : : else
222 : : {
223 : 0 : m_pParent->EndDialog( RET_OK );
224 : : }
225 : : }
226 : :
227 : 0 : return 0;
228 : : }
229 : :
230 : : //////////////////////////////////////////////////////////////////////
231 : :
232 : :
233 : 0 : PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(
234 : : Window * pParent,
235 : : sal_uInt16 nMinPasswdLen,
236 : : sal_uInt16 nMaxPasswdLen,
237 : : bool bIsPasswordToModify ) :
238 [ # # ]: 0 : SfxModalDialog( pParent, CUI_RES( RID_DLG_PASSWORD_TO_OPEN_MODIFY ) )
239 : : {
240 : : m_pImpl = std::auto_ptr< PasswordToOpenModifyDialog_Impl >(
241 [ # # ][ # # ]: 0 : new PasswordToOpenModifyDialog_Impl( this, nMinPasswdLen, nMaxPasswdLen, bIsPasswordToModify ) );
[ # # ]
242 : :
243 [ # # ]: 0 : FreeResource();
244 : 0 : }
245 : :
246 : :
247 [ # # ]: 0 : PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog()
248 : : {
249 [ # # ]: 0 : }
250 : :
251 : :
252 : 0 : String PasswordToOpenModifyDialog::GetPasswordToOpen() const
253 : : {
254 : : const bool bPasswdOk =
255 [ # # ][ # # ]: 0 : m_pImpl->m_aPasswdToOpenED.GetText().Len() > 0 &&
[ # # ]
256 [ # # ][ # # ]: 0 : m_pImpl->m_aPasswdToOpenED.GetText() == m_pImpl->m_aReenterPasswdToOpenED.GetText();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
257 [ # # ]: 0 : return bPasswdOk ? m_pImpl->m_aPasswdToOpenED.GetText() : String();
258 : : }
259 : :
260 : :
261 : 0 : String PasswordToOpenModifyDialog::GetPasswordToModify() const
262 : : {
263 : : const bool bPasswdOk =
264 [ # # ][ # # ]: 0 : m_pImpl->m_aPasswdToModifyED.GetText().Len() > 0 &&
[ # # ]
265 [ # # ][ # # ]: 0 : m_pImpl->m_aPasswdToModifyED.GetText() == m_pImpl->m_aReenterPasswdToModifyED.GetText();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
266 [ # # ]: 0 : return bPasswdOk ? m_pImpl->m_aPasswdToModifyED.GetText() : String();
267 : : }
268 : :
269 : :
270 : 0 : bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const
271 : : {
272 : 0 : return m_pImpl->m_aOpenReadonlyCB.IsChecked();
273 : : }
274 : :
275 : :
276 : : //////////////////////////////////////////////////////////////////////
277 : :
278 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|