xref: /aoo42x/main/uui/source/logindlg.cxx (revision 859212d1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <svtools/filedlg.hxx>
25 #include <vcl/msgbox.hxx>
26 #include "logindlg.hxx"
27 
28 #ifndef UUI_LOGINDLG_HRC
29 #include "logindlg.hrc"
30 #endif
31 #ifndef UUI_IDS_HRC
32 #include "ids.hrc"
33 #endif
34 #include <tools/resid.hxx>
35 
36 #ifdef UNX
37 #include <limits.h>
38 #define _MAX_PATH PATH_MAX
39 #endif
40 
41 // LoginDialog -------------------------------------------------------
42 
43 //............................................................................
44 //............................................................................
45 
lcl_Move(Window & rWin,long nOffset)46 static void lcl_Move( Window &rWin, long nOffset )
47 {
48     Point aTmp( rWin.GetPosPixel() );
49     aTmp.Y() -= nOffset;
50     rWin.SetPosPixel( aTmp );
51 }
52 
53 
HideControls_Impl(sal_uInt16 nFlags)54 void LoginDialog::HideControls_Impl( sal_uInt16 nFlags )
55 {
56     bool bPathHide = sal_False;
57     bool bErrorHide = sal_False;
58     bool bAccountHide = sal_False;
59     bool bUseSysCredsHide = sal_False;
60 
61 	if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
62 	{
63 		aPathFT.Hide();
64 		aPathED.Hide();
65 		aPathBtn.Hide();
66 		bPathHide = sal_True;
67 	}
68 	else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
69 	{
70         aPathED.Enable( sal_False );
71         aPathBtn.Enable( sal_False );
72 	}
73 
74 	if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
75 	{
76 		aNameFT.Hide();
77 		aNameED.Hide();
78 	}
79 	else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
80 	{
81         aNameED.Enable( sal_False );
82 	}
83 
84 	if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
85 	{
86 		aPasswordFT.Hide();
87 		aPasswordED.Hide();
88 	}
89 
90 	if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
91 		aSavePasswdBtn.Hide();
92 
93 	if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
94 	{
95 		aErrorInfo.Hide();
96         aErrorFT.Hide();
97         aLogin1FL.Hide();
98 		bErrorHide = sal_True;
99 	}
100 
101 	if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
102 	{
103 		aAccountFT.Hide();
104 		aAccountED.Hide();
105 		bAccountHide = sal_True;
106 	}
107 
108 	if ( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS )
109 	{
110 		aUseSysCredsCB.Hide();
111 		bUseSysCredsHide = sal_True;
112 	}
113 
114 	if ( bErrorHide )
115 	{
116 		long nOffset = aRequestInfo.GetPosPixel().Y() -
117                        aErrorFT.GetPosPixel().Y();
118         lcl_Move( aRequestInfo, nOffset );
119         lcl_Move( aLogin2FL, nOffset );
120         lcl_Move( aPathFT, nOffset );
121         lcl_Move( aPathED, nOffset );
122         lcl_Move( aPathBtn, nOffset );
123         lcl_Move( aNameFT, nOffset );
124         lcl_Move( aNameED, nOffset );
125         lcl_Move( aPasswordFT, nOffset );
126         lcl_Move( aPasswordED, nOffset );
127         lcl_Move( aAccountFT, nOffset );
128         lcl_Move( aAccountED, nOffset );
129         lcl_Move( aSavePasswdBtn, nOffset );
130         lcl_Move( aUseSysCredsCB, nOffset );
131         lcl_Move( aButtonsFL, nOffset );
132         lcl_Move( aOKBtn, nOffset );
133         lcl_Move( aCancelBtn, nOffset );
134         lcl_Move( aHelpBtn, nOffset );
135 
136         Size aNewSiz = GetSizePixel();
137 		aNewSiz.Height() -= nOffset;
138 		SetSizePixel( aNewSiz );
139 	}
140 
141 	if ( bPathHide )
142 	{
143 		long nOffset = aNameED.GetPosPixel().Y() -
144 					   aPathED.GetPosPixel().Y();
145         lcl_Move( aNameFT, nOffset );
146         lcl_Move( aNameED, nOffset );
147         lcl_Move( aPasswordFT, nOffset );
148         lcl_Move( aPasswordED, nOffset );
149         lcl_Move( aAccountFT, nOffset );
150         lcl_Move( aAccountED, nOffset );
151         lcl_Move( aSavePasswdBtn, nOffset );
152         lcl_Move( aUseSysCredsCB, nOffset );
153         lcl_Move( aButtonsFL, nOffset );
154         lcl_Move( aOKBtn, nOffset );
155         lcl_Move( aCancelBtn, nOffset );
156         lcl_Move( aHelpBtn, nOffset );
157 
158         Size aNewSz = GetSizePixel();
159 		aNewSz.Height() -= nOffset;
160 		SetSizePixel( aNewSz );
161 	}
162 
163 	if ( bAccountHide )
164 	{
165 		long nOffset = aAccountED.GetPosPixel().Y() -
166                        aPasswordED.GetPosPixel().Y();
167         lcl_Move( aSavePasswdBtn, nOffset );
168         lcl_Move( aUseSysCredsCB, nOffset );
169         lcl_Move( aButtonsFL, nOffset );
170         lcl_Move( aOKBtn, nOffset );
171         lcl_Move( aCancelBtn, nOffset );
172         lcl_Move( aHelpBtn, nOffset );
173 
174         Size aNewSz = GetSizePixel();
175 		aNewSz.Height() -= nOffset;
176 		SetSizePixel( aNewSz );
177 	}
178 
179     if ( bUseSysCredsHide )
180 	{
181 		long nOffset = aUseSysCredsCB.GetPosPixel().Y() -
182                        aSavePasswdBtn.GetPosPixel().Y();
183         lcl_Move( aButtonsFL, nOffset );
184         lcl_Move( aOKBtn, nOffset );
185         lcl_Move( aCancelBtn, nOffset );
186         lcl_Move( aHelpBtn, nOffset );
187 
188         Size aNewSz = GetSizePixel();
189 		aNewSz.Height() -= nOffset;
190 		SetSizePixel( aNewSz );
191 	}
192 };
193 
194 // -----------------------------------------------------------------------
EnableUseSysCredsControls_Impl(sal_Bool bUseSysCredsEnabled)195 void LoginDialog::EnableUseSysCredsControls_Impl( sal_Bool bUseSysCredsEnabled )
196 {
197     aErrorInfo.Enable( !bUseSysCredsEnabled );
198     aErrorFT.Enable( !bUseSysCredsEnabled );
199     aRequestInfo.Enable( !bUseSysCredsEnabled );
200     aPathFT.Enable( !bUseSysCredsEnabled );
201     aPathED.Enable( !bUseSysCredsEnabled );
202     aPathBtn.Enable( !bUseSysCredsEnabled );
203     aNameFT.Enable( !bUseSysCredsEnabled );
204     aNameED.Enable( !bUseSysCredsEnabled );
205     aPasswordFT.Enable( !bUseSysCredsEnabled );
206     aPasswordED.Enable( !bUseSysCredsEnabled );
207     aAccountFT.Enable( !bUseSysCredsEnabled );
208     aAccountED.Enable( !bUseSysCredsEnabled );
209 }
210 
211 // -----------------------------------------------------------------------
212 
IMPL_LINK(LoginDialog,OKHdl_Impl,OKButton *,EMPTYARG)213 IMPL_LINK( LoginDialog, OKHdl_Impl, OKButton *, EMPTYARG )
214 {
215 	// trim the strings
216 	aNameED.SetText( aNameED.GetText().EraseLeadingChars().
217 		EraseTrailingChars() );
218 	aPasswordED.SetText( aPasswordED.GetText().EraseLeadingChars().
219 		EraseTrailingChars() );
220 	EndDialog( RET_OK );
221 	return 1;
222 }
223 
224 // -----------------------------------------------------------------------
225 
IMPL_LINK(LoginDialog,PathHdl_Impl,PushButton *,EMPTYARG)226 IMPL_LINK( LoginDialog, PathHdl_Impl, PushButton *, EMPTYARG )
227 {
228 	PathDialog* pDlg = new PathDialog( this, WB_3DLOOK );
229 	pDlg->SetPath( aPathED.GetText() );
230 
231 	if ( pDlg->Execute() == RET_OK )
232 		aPathED.SetText( pDlg->GetPath() );
233 
234 	delete pDlg;
235 	return 1;
236 }
237 
238 // -----------------------------------------------------------------------
239 
IMPL_LINK(LoginDialog,UseSysCredsHdl_Impl,CheckBox *,EMPTYARG)240 IMPL_LINK( LoginDialog, UseSysCredsHdl_Impl, CheckBox *, EMPTYARG )
241 {
242     EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
243 	return 1;
244 }
245 
246 // -----------------------------------------------------------------------
247 
LoginDialog(Window * pParent,sal_uInt16 nFlags,const String & rServer,const String * pRealm,ResMgr * pResMgr)248 LoginDialog::LoginDialog
249 (
250 	Window* pParent,
251 	sal_uInt16 nFlags,
252 	const String& rServer,
253 	const String* pRealm,
254 	ResMgr* pResMgr
255 ) :
256 
257 	ModalDialog( pParent, ResId( DLG_UUI_LOGIN, *pResMgr ) ),
258 
259     aErrorFT        ( this, ResId( FT_LOGIN_ERROR, *pResMgr ) ),
260     aErrorInfo      ( this, ResId( FT_INFO_LOGIN_ERROR, *pResMgr ) ),
261     aLogin1FL       ( this, ResId( FL_LOGIN_1, *pResMgr ) ),
262     aRequestInfo    ( this, ResId( FT_INFO_LOGIN_REQUEST, *pResMgr ) ),
263     aLogin2FL       ( this, ResId( FL_LOGIN_2, *pResMgr ) ),
264 	aPathFT			( this, ResId( FT_LOGIN_PATH, *pResMgr ) ),
265 	aPathED			( this, ResId( ED_LOGIN_PATH, *pResMgr ) ),
266 	aPathBtn		( this, ResId( BTN_LOGIN_PATH, *pResMgr ) ),
267 	aNameFT			( this, ResId( FT_LOGIN_USERNAME, *pResMgr ) ),
268 	aNameED			( this, ResId( ED_LOGIN_USERNAME, *pResMgr ) ),
269 	aPasswordFT		( this, ResId( FT_LOGIN_PASSWORD, *pResMgr ) ),
270 	aPasswordED		( this, ResId( ED_LOGIN_PASSWORD, *pResMgr ) ),
271 	aAccountFT		( this, ResId( FT_LOGIN_ACCOUNT, *pResMgr ) ),
272 	aAccountED		( this, ResId( ED_LOGIN_ACCOUNT, *pResMgr ) ),
273 	aSavePasswdBtn	( this, ResId( CB_LOGIN_SAVEPASSWORD, *pResMgr ) ),
274 	aUseSysCredsCB	( this, ResId( CB_LOGIN_USESYSCREDS, *pResMgr ) ),
275     aButtonsFL      ( this, ResId( FL_BUTTONS, *pResMgr ) ),
276 	aOKBtn			( this, ResId( BTN_LOGIN_OK, *pResMgr ) ),
277 	aCancelBtn		( this, ResId( BTN_LOGIN_CANCEL, *pResMgr ) ),
278 	aHelpBtn		( this, ResId( BTN_LOGIN_HELP, *pResMgr ) )
279 
280 {
281 	UniString aRequest;
282 	if ((nFlags & LF_NO_ACCOUNT) != 0 && pRealm && pRealm->Len() != 0)
283 	{
284         aRequest = ResId(STR_LOGIN_REALM, *pResMgr);
285         aRequest.SearchAndReplaceAscii("%2", *pRealm);
286 	}
287 	else
288         aRequest = aRequestInfo.GetText();
289 
290     if ( !( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS ) )
291       EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
292 
293     aRequest.SearchAndReplaceAscii("%1", rServer);
294 	aRequestInfo.SetText(aRequest);
295 
296 	FreeResource();
297 
298 	aPathED.SetMaxTextLen( _MAX_PATH );
299 	aNameED.SetMaxTextLen( _MAX_PATH );
300 
301 	aOKBtn.SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
302 	aPathBtn.SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
303 	aUseSysCredsCB.SetClickHdl( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
304 
305 	HideControls_Impl( nFlags );
306 };
307 
308 // -----------------------------------------------------------------------
309 
~LoginDialog()310 LoginDialog::~LoginDialog()
311 {
312 }
313 
314 // -----------------------------------------------------------------------
315 
SetUseSystemCredentials(sal_Bool bUse)316 void LoginDialog::SetUseSystemCredentials( sal_Bool bUse )
317 {
318     if ( aUseSysCredsCB.IsVisible() )
319     {
320         aUseSysCredsCB.Check( bUse );
321         EnableUseSysCredsControls_Impl( bUse );
322     }
323 }
324 
325 // -----------------------------------------------------------------------
326 
ClearPassword()327 void LoginDialog::ClearPassword()
328 {
329 	aPasswordED.SetText( String() );
330 
331 	if ( 0 == aNameED.GetText().Len() )
332 		aNameED.GrabFocus();
333 	else
334 		aPasswordED.GrabFocus();
335 };
336 
337 // -----------------------------------------------------------------------
338 
ClearAccount()339 void LoginDialog::ClearAccount()
340 {
341 	aAccountED.SetText( String() );
342 	aAccountED.GrabFocus();
343 };
344 
345 //............................................................................
346 //............................................................................
347