Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / uui / source / logindlg.cxx
blob89b86de790587904e829d9b7bda852fe2bc61d9b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include <svtools/filedlg.hxx>
30 #include <vcl/msgbox.hxx>
31 #include "logindlg.hxx"
33 #include "logindlg.hrc"
34 #include "ids.hrc"
35 #include <tools/resid.hxx>
37 #ifdef UNX
38 #include <limits.h>
39 #define _MAX_PATH PATH_MAX
40 #endif
42 // LoginDialog -------------------------------------------------------
44 //............................................................................
45 //............................................................................
47 static void lcl_Move( Window &rWin, long nOffset )
49 Point aTmp( rWin.GetPosPixel() );
50 aTmp.Y() -= nOffset;
51 rWin.SetPosPixel( aTmp );
55 void LoginDialog::HideControls_Impl( sal_uInt16 nFlags )
57 bool bPathHide = sal_False;
58 bool bErrorHide = sal_False;
59 bool bAccountHide = sal_False;
60 bool bUseSysCredsHide = sal_False;
62 if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
64 aPathFT.Hide();
65 aPathED.Hide();
66 aPathBtn.Hide();
67 bPathHide = sal_True;
69 else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
71 aPathED.Enable( sal_False );
72 aPathBtn.Enable( sal_False );
75 if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
77 aNameFT.Hide();
78 aNameED.Hide();
80 else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
82 aNameED.Enable( sal_False );
85 if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
87 aPasswordFT.Hide();
88 aPasswordED.Hide();
91 if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
92 aSavePasswdBtn.Hide();
94 if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
96 aErrorInfo.Hide();
97 aErrorFT.Hide();
98 aLogin1FL.Hide();
99 bErrorHide = sal_True;
102 if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
104 aAccountFT.Hide();
105 aAccountED.Hide();
106 bAccountHide = sal_True;
109 if ( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS )
111 aUseSysCredsCB.Hide();
112 bUseSysCredsHide = sal_True;
115 if ( bErrorHide )
117 long nOffset = aRequestInfo.GetPosPixel().Y() -
118 aErrorFT.GetPosPixel().Y();
119 lcl_Move( aRequestInfo, nOffset );
120 lcl_Move( aLogin2FL, nOffset );
121 lcl_Move( aPathFT, nOffset );
122 lcl_Move( aPathED, nOffset );
123 lcl_Move( aPathBtn, nOffset );
124 lcl_Move( aNameFT, nOffset );
125 lcl_Move( aNameED, nOffset );
126 lcl_Move( aPasswordFT, nOffset );
127 lcl_Move( aPasswordED, nOffset );
128 lcl_Move( aAccountFT, nOffset );
129 lcl_Move( aAccountED, nOffset );
130 lcl_Move( aSavePasswdBtn, nOffset );
131 lcl_Move( aUseSysCredsCB, nOffset );
132 lcl_Move( aButtonsFL, nOffset );
133 lcl_Move( aOKBtn, nOffset );
134 lcl_Move( aCancelBtn, nOffset );
135 lcl_Move( aHelpBtn, nOffset );
137 Size aNewSiz = GetSizePixel();
138 aNewSiz.Height() -= nOffset;
139 SetSizePixel( aNewSiz );
142 if ( bPathHide )
144 long nOffset = aNameED.GetPosPixel().Y() -
145 aPathED.GetPosPixel().Y();
146 lcl_Move( aNameFT, nOffset );
147 lcl_Move( aNameED, nOffset );
148 lcl_Move( aPasswordFT, nOffset );
149 lcl_Move( aPasswordED, nOffset );
150 lcl_Move( aAccountFT, nOffset );
151 lcl_Move( aAccountED, nOffset );
152 lcl_Move( aSavePasswdBtn, nOffset );
153 lcl_Move( aUseSysCredsCB, nOffset );
154 lcl_Move( aButtonsFL, nOffset );
155 lcl_Move( aOKBtn, nOffset );
156 lcl_Move( aCancelBtn, nOffset );
157 lcl_Move( aHelpBtn, nOffset );
159 Size aNewSz = GetSizePixel();
160 aNewSz.Height() -= nOffset;
161 SetSizePixel( aNewSz );
164 if ( bAccountHide )
166 long nOffset = aAccountED.GetPosPixel().Y() -
167 aPasswordED.GetPosPixel().Y();
168 lcl_Move( aSavePasswdBtn, nOffset );
169 lcl_Move( aUseSysCredsCB, nOffset );
170 lcl_Move( aButtonsFL, nOffset );
171 lcl_Move( aOKBtn, nOffset );
172 lcl_Move( aCancelBtn, nOffset );
173 lcl_Move( aHelpBtn, nOffset );
175 Size aNewSz = GetSizePixel();
176 aNewSz.Height() -= nOffset;
177 SetSizePixel( aNewSz );
180 if ( bUseSysCredsHide )
182 long nOffset = aUseSysCredsCB.GetPosPixel().Y() -
183 aSavePasswdBtn.GetPosPixel().Y();
184 lcl_Move( aButtonsFL, nOffset );
185 lcl_Move( aOKBtn, nOffset );
186 lcl_Move( aCancelBtn, nOffset );
187 lcl_Move( aHelpBtn, nOffset );
189 Size aNewSz = GetSizePixel();
190 aNewSz.Height() -= nOffset;
191 SetSizePixel( aNewSz );
195 // -----------------------------------------------------------------------
196 void LoginDialog::EnableUseSysCredsControls_Impl( sal_Bool bUseSysCredsEnabled )
198 aErrorInfo.Enable( !bUseSysCredsEnabled );
199 aErrorFT.Enable( !bUseSysCredsEnabled );
200 aRequestInfo.Enable( !bUseSysCredsEnabled );
201 aPathFT.Enable( !bUseSysCredsEnabled );
202 aPathED.Enable( !bUseSysCredsEnabled );
203 aPathBtn.Enable( !bUseSysCredsEnabled );
204 aNameFT.Enable( !bUseSysCredsEnabled );
205 aNameED.Enable( !bUseSysCredsEnabled );
206 aPasswordFT.Enable( !bUseSysCredsEnabled );
207 aPasswordED.Enable( !bUseSysCredsEnabled );
208 aAccountFT.Enable( !bUseSysCredsEnabled );
209 aAccountED.Enable( !bUseSysCredsEnabled );
212 // -----------------------------------------------------------------------
214 IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl)
216 // trim the strings
217 aNameED.SetText( aNameED.GetText().EraseLeadingChars().
218 EraseTrailingChars() );
219 aPasswordED.SetText( aPasswordED.GetText().EraseLeadingChars().
220 EraseTrailingChars() );
221 EndDialog( RET_OK );
222 return 1;
225 // -----------------------------------------------------------------------
227 IMPL_LINK_NOARG(LoginDialog, PathHdl_Impl)
229 PathDialog* pDlg = new PathDialog( this, WB_3DLOOK );
230 pDlg->SetPath( aPathED.GetText() );
232 if ( pDlg->Execute() == RET_OK )
233 aPathED.SetText( pDlg->GetPath() );
235 delete pDlg;
236 return 1;
239 // -----------------------------------------------------------------------
241 IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl)
243 EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
244 return 1;
247 // -----------------------------------------------------------------------
249 LoginDialog::LoginDialog
251 Window* pParent,
252 sal_uInt16 nFlags,
253 const rtl::OUString& rServer,
254 const rtl::OUString& rRealm,
255 ResMgr* pResMgr
258 ModalDialog( pParent, ResId( DLG_UUI_LOGIN, *pResMgr ) ),
260 aErrorFT ( this, ResId( FT_LOGIN_ERROR, *pResMgr ) ),
261 aErrorInfo ( this, ResId( FT_INFO_LOGIN_ERROR, *pResMgr ) ),
262 aLogin1FL ( this, ResId( FL_LOGIN_1, *pResMgr ) ),
263 aRequestInfo ( this, ResId( FT_INFO_LOGIN_REQUEST, *pResMgr ) ),
264 aLogin2FL ( this, ResId( FL_LOGIN_2, *pResMgr ) ),
265 aPathFT ( this, ResId( FT_LOGIN_PATH, *pResMgr ) ),
266 aPathED ( this, ResId( ED_LOGIN_PATH, *pResMgr ) ),
267 aPathBtn ( this, ResId( BTN_LOGIN_PATH, *pResMgr ) ),
268 aNameFT ( this, ResId( FT_LOGIN_USERNAME, *pResMgr ) ),
269 aNameED ( this, ResId( ED_LOGIN_USERNAME, *pResMgr ) ),
270 aPasswordFT ( this, ResId( FT_LOGIN_PASSWORD, *pResMgr ) ),
271 aPasswordED ( this, ResId( ED_LOGIN_PASSWORD, *pResMgr ) ),
272 aAccountFT ( this, ResId( FT_LOGIN_ACCOUNT, *pResMgr ) ),
273 aAccountED ( this, ResId( ED_LOGIN_ACCOUNT, *pResMgr ) ),
274 aSavePasswdBtn ( this, ResId( CB_LOGIN_SAVEPASSWORD, *pResMgr ) ),
275 aUseSysCredsCB ( this, ResId( CB_LOGIN_USESYSCREDS, *pResMgr ) ),
276 aButtonsFL ( this, ResId( FL_BUTTONS, *pResMgr ) ),
277 aOKBtn ( this, ResId( BTN_LOGIN_OK, *pResMgr ) ),
278 aCancelBtn ( this, ResId( BTN_LOGIN_CANCEL, *pResMgr ) ),
279 aHelpBtn ( this, ResId( BTN_LOGIN_HELP, *pResMgr ) )
282 UniString aRequest;
283 if ((nFlags & LF_NO_ACCOUNT) != 0 && !rRealm.isEmpty())
285 aRequest = ResId(STR_LOGIN_REALM, *pResMgr).toString();
286 aRequest.SearchAndReplaceAscii("%2", rRealm);
288 else
289 aRequest = aRequestInfo.GetText();
291 if ( !( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS ) )
292 EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
294 aRequest.SearchAndReplaceAscii("%1", rServer);
295 aRequestInfo.SetText(aRequest);
297 FreeResource();
299 aPathED.SetMaxTextLen( _MAX_PATH );
300 aNameED.SetMaxTextLen( _MAX_PATH );
302 aOKBtn.SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
303 aPathBtn.SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
304 aUseSysCredsCB.SetClickHdl( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
306 HideControls_Impl( nFlags );
309 // -----------------------------------------------------------------------
311 LoginDialog::~LoginDialog()
315 // -----------------------------------------------------------------------
317 void LoginDialog::SetUseSystemCredentials( sal_Bool bUse )
319 if ( aUseSysCredsCB.IsVisible() )
321 aUseSysCredsCB.Check( bUse );
322 EnableUseSysCredsControls_Impl( bUse );
326 // -----------------------------------------------------------------------
328 void LoginDialog::ClearPassword()
330 aPasswordED.SetText( String() );
332 if ( 0 == aNameED.GetText().Len() )
333 aNameED.GrabFocus();
334 else
335 aPasswordED.GrabFocus();
338 // -----------------------------------------------------------------------
340 void LoginDialog::ClearAccount()
342 aAccountED.SetText( String() );
343 aAccountED.GrabFocus();
346 //............................................................................
347 //............................................................................
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */