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