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 "passwdomdlg.hrc"
21 : #include "passwdomdlg.hxx"
22 :
23 : #include "cuires.hrc"
24 : #include "dialmgr.hxx"
25 :
26 : #include <sfx2/tabdlg.hxx>
27 : #include <vcl/fixed.hxx>
28 : #include <vcl/edit.hxx>
29 : #include <vcl/button.hxx>
30 : #include <vcl/morebtn.hxx>
31 : #include <vcl/settings.hxx>
32 : #include <vcl/msgbox.hxx>
33 :
34 :
35 : //////////////////////////////////////////////////////////////////////
36 :
37 : class PasswordReenterEdit_Impl : public Edit
38 : {
39 : String m_aDefaultTxt;
40 :
41 : // disallow use of copy c-tor and assignment operator
42 : PasswordReenterEdit_Impl( const PasswordReenterEdit_Impl & );
43 : PasswordReenterEdit_Impl & operator = ( const PasswordReenterEdit_Impl & );
44 :
45 : public:
46 : PasswordReenterEdit_Impl( Window * pParent, const ResId &rResId );
47 : virtual ~PasswordReenterEdit_Impl();
48 :
49 : // Edit
50 : virtual void Paint( const Rectangle& rRect );
51 : };
52 :
53 :
54 0 : PasswordReenterEdit_Impl::PasswordReenterEdit_Impl( Window * pParent, const ResId &rResId ) :
55 0 : Edit( pParent, rResId )
56 : {
57 0 : }
58 :
59 :
60 0 : PasswordReenterEdit_Impl::~PasswordReenterEdit_Impl()
61 : {
62 0 : }
63 :
64 :
65 0 : void PasswordReenterEdit_Impl::Paint( const Rectangle& rRect )
66 : {
67 0 : if (GetText().Len() == 0)
68 : {
69 0 : Push( PUSH_TEXTCOLOR );
70 0 : SetTextColor( Color( COL_GRAY ) );
71 0 : DrawText( Point(), m_aDefaultTxt );
72 :
73 0 : Pop();
74 : }
75 : else
76 0 : Edit::Paint( rRect );
77 0 : }
78 :
79 :
80 : //////////////////////////////////////////////////////////////////////
81 :
82 : struct PasswordToOpenModifyDialog_Impl
83 : {
84 : PasswordToOpenModifyDialog * m_pParent;
85 :
86 : FixedLine m_aFileEncryptionFL;
87 : FixedText m_aPasswdToOpenFT;
88 : Edit m_aPasswdToOpenED;
89 : FixedText m_aReenterPasswdToOpenFT;
90 : PasswordReenterEdit_Impl m_aReenterPasswdToOpenED;
91 : FixedText m_aPasswdNoteFT;
92 : FixedLine m_aButtonsFL;
93 : MoreButton m_aMoreFewerOptionsBTN;
94 : OKButton m_aOk;
95 : CancelButton m_aCancel;
96 : FixedLine m_aFileSharingOptionsFL;
97 : CheckBox m_aOpenReadonlyCB;
98 : FixedText m_aPasswdToModifyFT;
99 : Edit m_aPasswdToModifyED;
100 : FixedText m_aReenterPasswdToModifyFT;
101 : PasswordReenterEdit_Impl m_aReenterPasswdToModifyED;
102 :
103 : String m_aOneMismatch;
104 : String m_aTwoMismatch;
105 : String m_aInvalidStateForOkButton;
106 : String m_aInvalidStateForOkButton_v2;
107 :
108 : bool m_bIsPasswordToModify;
109 :
110 :
111 : DECL_LINK( OkBtnClickHdl, OKButton * );
112 :
113 : PasswordToOpenModifyDialog_Impl( PasswordToOpenModifyDialog * pParent,
114 : sal_uInt16 nMinPasswdLen, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify );
115 : ~PasswordToOpenModifyDialog_Impl();
116 : };
117 :
118 :
119 0 : PasswordToOpenModifyDialog_Impl::PasswordToOpenModifyDialog_Impl(
120 : PasswordToOpenModifyDialog * pParent,
121 : sal_uInt16 nMinPasswdLen,
122 : sal_uInt16 nMaxPasswdLen,
123 : bool bIsPasswordToModify ) :
124 : m_pParent( pParent ),
125 0 : m_aFileEncryptionFL ( pParent, CUI_RES( FL_FILE_ENCRYPTION ) ),
126 0 : m_aPasswdToOpenFT ( pParent, CUI_RES( FT_PASSWD_TO_OPEN ) ),
127 0 : m_aPasswdToOpenED ( pParent, CUI_RES( ED_PASSWD_TO_OPEN ) ),
128 0 : m_aReenterPasswdToOpenFT ( pParent, CUI_RES( FT_REENTER_PASSWD_TO_OPEN ) ),
129 0 : m_aReenterPasswdToOpenED ( pParent, CUI_RES( ED_REENTER_PASSWD_TO_OPEN ) ),
130 0 : m_aPasswdNoteFT ( pParent, CUI_RES( FT_PASSWD_NOTE ) ),
131 0 : m_aButtonsFL ( pParent, CUI_RES( FL_BUTTONS ) ),
132 0 : m_aMoreFewerOptionsBTN ( pParent, CUI_RES( BTN_MORE_FEWER_OPTIONS ) ),
133 0 : m_aOk ( pParent, CUI_RES( BTN_OK ) ),
134 0 : m_aCancel ( pParent, CUI_RES( BTN_CANCEL ) ),
135 0 : m_aFileSharingOptionsFL ( pParent, CUI_RES( FL_FILE_SHARING_OPTIONS ) ),
136 0 : m_aOpenReadonlyCB ( pParent, CUI_RES( CB_OPEN_READONLY ) ),
137 0 : m_aPasswdToModifyFT ( pParent, CUI_RES( FT_PASSWD_TO_MODIFY ) ),
138 0 : m_aPasswdToModifyED ( pParent, CUI_RES( ED_PASSWD_TO_MODIFY ) ),
139 0 : m_aReenterPasswdToModifyFT ( pParent, CUI_RES( FT_REENTER_PASSWD_TO_MODIFY ) ),
140 0 : m_aReenterPasswdToModifyED ( pParent, CUI_RES( ED_REENTER_PASSWD_TO_MODIFY ) ),
141 0 : m_aOneMismatch( CUI_RES( STR_ONE_PASSWORD_MISMATCH ) ),
142 0 : m_aTwoMismatch( CUI_RES( STR_TWO_PASSWORDS_MISMATCH ) ),
143 0 : m_aInvalidStateForOkButton( CUI_RES( STR_INVALID_STATE_FOR_OK_BUTTON ) ),
144 0 : m_aInvalidStateForOkButton_v2( CUI_RES( STR_INVALID_STATE_FOR_OK_BUTTON_V2 ) ),
145 0 : m_bIsPasswordToModify( bIsPasswordToModify )
146 : {
147 0 : m_aMoreFewerOptionsBTN.SetMoreText( String( CUI_RES( STR_MORE_OPTIONS ) ) );
148 0 : m_aMoreFewerOptionsBTN.SetLessText( String( CUI_RES( STR_FEWER_OPTIONS ) ) );
149 :
150 0 : m_aOk.SetClickHdl( LINK( this, PasswordToOpenModifyDialog_Impl, OkBtnClickHdl ) );
151 :
152 0 : if (nMaxPasswdLen)
153 : {
154 0 : m_aPasswdToOpenED.SetMaxTextLen( nMaxPasswdLen );
155 0 : m_aReenterPasswdToOpenED.SetMaxTextLen( nMaxPasswdLen );
156 0 : m_aPasswdToModifyED.SetMaxTextLen( nMaxPasswdLen );
157 0 : m_aReenterPasswdToModifyED.SetMaxTextLen( nMaxPasswdLen );
158 : }
159 :
160 : (void) nMinPasswdLen; // currently not supported
161 :
162 0 : m_aPasswdToOpenED.GrabFocus();
163 :
164 0 : m_aMoreFewerOptionsBTN.Enable( bIsPasswordToModify );
165 0 : if (!bIsPasswordToModify)
166 0 : m_aMoreFewerOptionsBTN.Hide( sal_True );
167 0 : }
168 :
169 :
170 0 : PasswordToOpenModifyDialog_Impl::~PasswordToOpenModifyDialog_Impl()
171 : {
172 0 : }
173 :
174 0 : IMPL_LINK( PasswordToOpenModifyDialog_Impl, OkBtnClickHdl, OKButton *, EMPTYARG /*pBtn*/ )
175 : {
176 0 : bool bInvalidState = !m_aOpenReadonlyCB.IsChecked() &&
177 0 : m_aPasswdToOpenED.GetText().Len() == 0 &&
178 0 : m_aPasswdToModifyED.GetText().Len() == 0;
179 0 : if (bInvalidState)
180 : {
181 : ErrorBox aErrorBox( m_pParent, WB_OK,
182 0 : m_bIsPasswordToModify? m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2 );
183 0 : aErrorBox.Execute();
184 : }
185 : else // check for mismatched passwords...
186 : {
187 0 : const bool bToOpenMatch = m_aPasswdToOpenED.GetText() == m_aReenterPasswdToOpenED.GetText();
188 0 : const bool bToModifyMatch = m_aPasswdToModifyED.GetText() == m_aReenterPasswdToModifyED.GetText();
189 0 : const int nMismatch = (bToOpenMatch? 0 : 1) + (bToModifyMatch? 0 : 1);
190 0 : if (nMismatch > 0)
191 : {
192 0 : ErrorBox aErrorBox( m_pParent, WB_OK, nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch );
193 0 : aErrorBox.Execute();
194 :
195 0 : Edit &rEdit = !bToOpenMatch? m_aPasswdToOpenED : m_aPasswdToModifyED;
196 0 : PasswordReenterEdit_Impl &rRepeatEdit = !bToOpenMatch? m_aReenterPasswdToOpenED : m_aReenterPasswdToModifyED;
197 0 : String aEmpty;
198 0 : if (nMismatch == 1)
199 : {
200 0 : rEdit.SetText( aEmpty );
201 0 : rRepeatEdit.SetText( aEmpty );
202 : }
203 0 : else if (nMismatch == 2)
204 : {
205 0 : m_aPasswdToOpenED.SetText( aEmpty );
206 0 : m_aReenterPasswdToOpenED.SetText( aEmpty );
207 0 : m_aPasswdToModifyED.SetText( aEmpty );
208 0 : m_aReenterPasswdToModifyED.SetText( aEmpty );
209 : }
210 0 : rEdit.GrabFocus();
211 : }
212 : else
213 : {
214 0 : m_pParent->EndDialog( RET_OK );
215 : }
216 : }
217 :
218 0 : return 0;
219 : }
220 :
221 : //////////////////////////////////////////////////////////////////////
222 :
223 :
224 0 : PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(
225 : Window * pParent,
226 : sal_uInt16 nMinPasswdLen,
227 : sal_uInt16 nMaxPasswdLen,
228 : bool bIsPasswordToModify ) :
229 0 : SfxModalDialog( pParent, CUI_RES( RID_DLG_PASSWORD_TO_OPEN_MODIFY ) )
230 : {
231 : m_pImpl = std::auto_ptr< PasswordToOpenModifyDialog_Impl >(
232 0 : new PasswordToOpenModifyDialog_Impl( this, nMinPasswdLen, nMaxPasswdLen, bIsPasswordToModify ) );
233 :
234 0 : FreeResource();
235 0 : }
236 :
237 :
238 0 : PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog()
239 : {
240 0 : }
241 :
242 :
243 0 : String PasswordToOpenModifyDialog::GetPasswordToOpen() const
244 : {
245 : const bool bPasswdOk =
246 0 : m_pImpl->m_aPasswdToOpenED.GetText().Len() > 0 &&
247 0 : m_pImpl->m_aPasswdToOpenED.GetText() == m_pImpl->m_aReenterPasswdToOpenED.GetText();
248 0 : return bPasswdOk ? m_pImpl->m_aPasswdToOpenED.GetText() : String();
249 : }
250 :
251 :
252 0 : String PasswordToOpenModifyDialog::GetPasswordToModify() const
253 : {
254 : const bool bPasswdOk =
255 0 : m_pImpl->m_aPasswdToModifyED.GetText().Len() > 0 &&
256 0 : m_pImpl->m_aPasswdToModifyED.GetText() == m_pImpl->m_aReenterPasswdToModifyED.GetText();
257 0 : return bPasswdOk ? m_pImpl->m_aPasswdToModifyED.GetText() : String();
258 : }
259 :
260 :
261 0 : bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const
262 : {
263 0 : return m_pImpl->m_aOpenReadonlyCB.IsChecked();
264 3 : }
265 :
266 :
267 : //////////////////////////////////////////////////////////////////////
268 :
269 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|