1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/string.hxx>
21 #include <svtools/filedlg.hxx>
22 #include <vcl/msgbox.hxx>
23 #include "logindlg.hxx"
25 #include "logindlg.hrc"
27 #include <tools/resid.hxx>
31 #define _MAX_PATH PATH_MAX
34 // LoginDialog -------------------------------------------------------
36 //............................................................................
37 //............................................................................
39 static void lcl_Move( Window
&rWin
, long nOffset
)
41 Point
aTmp( rWin
.GetPosPixel() );
43 rWin
.SetPosPixel( aTmp
);
47 void LoginDialog::HideControls_Impl( sal_uInt16 nFlags
)
49 bool bPathHide
= sal_False
;
50 bool bErrorHide
= sal_False
;
51 bool bAccountHide
= sal_False
;
52 bool bUseSysCredsHide
= sal_False
;
54 if ( ( nFlags
& LF_NO_PATH
) == LF_NO_PATH
)
61 else if ( ( nFlags
& LF_PATH_READONLY
) == LF_PATH_READONLY
)
63 aPathED
.Enable( sal_False
);
64 aPathBtn
.Enable( sal_False
);
67 if ( ( nFlags
& LF_NO_USERNAME
) == LF_NO_USERNAME
)
72 else if ( ( nFlags
& LF_USERNAME_READONLY
) == LF_USERNAME_READONLY
)
74 aNameED
.Enable( sal_False
);
77 if ( ( nFlags
& LF_NO_PASSWORD
) == LF_NO_PASSWORD
)
83 if ( ( nFlags
& LF_NO_SAVEPASSWORD
) == LF_NO_SAVEPASSWORD
)
84 aSavePasswdBtn
.Hide();
86 if ( ( nFlags
& LF_NO_ERRORTEXT
) == LF_NO_ERRORTEXT
)
91 bErrorHide
= sal_True
;
94 if ( ( nFlags
& LF_NO_ACCOUNT
) == LF_NO_ACCOUNT
)
98 bAccountHide
= sal_True
;
101 if ( ( nFlags
& LF_NO_USESYSCREDS
) == LF_NO_USESYSCREDS
)
103 aUseSysCredsCB
.Hide();
104 bUseSysCredsHide
= sal_True
;
109 long nOffset
= aRequestInfo
.GetPosPixel().Y() -
110 aErrorFT
.GetPosPixel().Y();
111 lcl_Move( aRequestInfo
, nOffset
);
112 lcl_Move( aLogin2FL
, nOffset
);
113 lcl_Move( aPathFT
, nOffset
);
114 lcl_Move( aPathED
, nOffset
);
115 lcl_Move( aPathBtn
, nOffset
);
116 lcl_Move( aNameFT
, nOffset
);
117 lcl_Move( aNameED
, nOffset
);
118 lcl_Move( aPasswordFT
, nOffset
);
119 lcl_Move( aPasswordED
, nOffset
);
120 lcl_Move( aAccountFT
, nOffset
);
121 lcl_Move( aAccountED
, nOffset
);
122 lcl_Move( aSavePasswdBtn
, nOffset
);
123 lcl_Move( aUseSysCredsCB
, nOffset
);
124 lcl_Move( aButtonsFL
, nOffset
);
125 lcl_Move( aOKBtn
, nOffset
);
126 lcl_Move( aCancelBtn
, nOffset
);
127 lcl_Move( aHelpBtn
, nOffset
);
129 Size aNewSiz
= GetSizePixel();
130 aNewSiz
.Height() -= nOffset
;
131 SetSizePixel( aNewSiz
);
136 long nOffset
= aNameED
.GetPosPixel().Y() -
137 aPathED
.GetPosPixel().Y();
138 lcl_Move( aNameFT
, nOffset
);
139 lcl_Move( aNameED
, nOffset
);
140 lcl_Move( aPasswordFT
, nOffset
);
141 lcl_Move( aPasswordED
, nOffset
);
142 lcl_Move( aAccountFT
, nOffset
);
143 lcl_Move( aAccountED
, nOffset
);
144 lcl_Move( aSavePasswdBtn
, nOffset
);
145 lcl_Move( aUseSysCredsCB
, nOffset
);
146 lcl_Move( aButtonsFL
, nOffset
);
147 lcl_Move( aOKBtn
, nOffset
);
148 lcl_Move( aCancelBtn
, nOffset
);
149 lcl_Move( aHelpBtn
, nOffset
);
151 Size aNewSz
= GetSizePixel();
152 aNewSz
.Height() -= nOffset
;
153 SetSizePixel( aNewSz
);
158 long nOffset
= aAccountED
.GetPosPixel().Y() -
159 aPasswordED
.GetPosPixel().Y();
160 lcl_Move( aSavePasswdBtn
, nOffset
);
161 lcl_Move( aUseSysCredsCB
, nOffset
);
162 lcl_Move( aButtonsFL
, nOffset
);
163 lcl_Move( aOKBtn
, nOffset
);
164 lcl_Move( aCancelBtn
, nOffset
);
165 lcl_Move( aHelpBtn
, nOffset
);
167 Size aNewSz
= GetSizePixel();
168 aNewSz
.Height() -= nOffset
;
169 SetSizePixel( aNewSz
);
172 if ( bUseSysCredsHide
)
174 long nOffset
= aUseSysCredsCB
.GetPosPixel().Y() -
175 aSavePasswdBtn
.GetPosPixel().Y();
176 lcl_Move( aButtonsFL
, nOffset
);
177 lcl_Move( aOKBtn
, nOffset
);
178 lcl_Move( aCancelBtn
, nOffset
);
179 lcl_Move( aHelpBtn
, nOffset
);
181 Size aNewSz
= GetSizePixel();
182 aNewSz
.Height() -= nOffset
;
183 SetSizePixel( aNewSz
);
187 // -----------------------------------------------------------------------
188 void LoginDialog::EnableUseSysCredsControls_Impl( sal_Bool bUseSysCredsEnabled
)
190 aErrorInfo
.Enable( !bUseSysCredsEnabled
);
191 aErrorFT
.Enable( !bUseSysCredsEnabled
);
192 aRequestInfo
.Enable( !bUseSysCredsEnabled
);
193 aPathFT
.Enable( !bUseSysCredsEnabled
);
194 aPathED
.Enable( !bUseSysCredsEnabled
);
195 aPathBtn
.Enable( !bUseSysCredsEnabled
);
196 aNameFT
.Enable( !bUseSysCredsEnabled
);
197 aNameED
.Enable( !bUseSysCredsEnabled
);
198 aPasswordFT
.Enable( !bUseSysCredsEnabled
);
199 aPasswordED
.Enable( !bUseSysCredsEnabled
);
200 aAccountFT
.Enable( !bUseSysCredsEnabled
);
201 aAccountED
.Enable( !bUseSysCredsEnabled
);
204 // -----------------------------------------------------------------------
206 IMPL_LINK_NOARG(LoginDialog
, OKHdl_Impl
)
209 aNameED
.SetText(comphelper::string::strip(aNameED
.GetText(), ' '));
210 aPasswordED
.SetText(comphelper::string::strip(aPasswordED
.GetText(), ' '));
215 // -----------------------------------------------------------------------
217 IMPL_LINK_NOARG(LoginDialog
, PathHdl_Impl
)
219 PathDialog
* pDlg
= new PathDialog( this, WB_3DLOOK
);
220 pDlg
->SetPath( aPathED
.GetText() );
222 if ( pDlg
->Execute() == RET_OK
)
223 aPathED
.SetText( pDlg
->GetPath() );
229 // -----------------------------------------------------------------------
231 IMPL_LINK_NOARG(LoginDialog
, UseSysCredsHdl_Impl
)
233 EnableUseSysCredsControls_Impl( aUseSysCredsCB
.IsChecked() );
237 // -----------------------------------------------------------------------
239 LoginDialog::LoginDialog
243 const rtl::OUString
& rServer
,
244 const rtl::OUString
& rRealm
,
248 ModalDialog( pParent
, ResId( DLG_UUI_LOGIN
, *pResMgr
) ),
250 aErrorFT ( this, ResId( FT_LOGIN_ERROR
, *pResMgr
) ),
251 aErrorInfo ( this, ResId( FT_INFO_LOGIN_ERROR
, *pResMgr
) ),
252 aLogin1FL ( this, ResId( FL_LOGIN_1
, *pResMgr
) ),
253 aRequestInfo ( this, ResId( FT_INFO_LOGIN_REQUEST
, *pResMgr
) ),
254 aLogin2FL ( this, ResId( FL_LOGIN_2
, *pResMgr
) ),
255 aPathFT ( this, ResId( FT_LOGIN_PATH
, *pResMgr
) ),
256 aPathED ( this, ResId( ED_LOGIN_PATH
, *pResMgr
) ),
257 aPathBtn ( this, ResId( BTN_LOGIN_PATH
, *pResMgr
) ),
258 aNameFT ( this, ResId( FT_LOGIN_USERNAME
, *pResMgr
) ),
259 aNameED ( this, ResId( ED_LOGIN_USERNAME
, *pResMgr
) ),
260 aPasswordFT ( this, ResId( FT_LOGIN_PASSWORD
, *pResMgr
) ),
261 aPasswordED ( this, ResId( ED_LOGIN_PASSWORD
, *pResMgr
) ),
262 aAccountFT ( this, ResId( FT_LOGIN_ACCOUNT
, *pResMgr
) ),
263 aAccountED ( this, ResId( ED_LOGIN_ACCOUNT
, *pResMgr
) ),
264 aSavePasswdBtn ( this, ResId( CB_LOGIN_SAVEPASSWORD
, *pResMgr
) ),
265 aUseSysCredsCB ( this, ResId( CB_LOGIN_USESYSCREDS
, *pResMgr
) ),
266 aButtonsFL ( this, ResId( FL_BUTTONS
, *pResMgr
) ),
267 aOKBtn ( this, ResId( BTN_LOGIN_OK
, *pResMgr
) ),
268 aCancelBtn ( this, ResId( BTN_LOGIN_CANCEL
, *pResMgr
) ),
269 aHelpBtn ( this, ResId( BTN_LOGIN_HELP
, *pResMgr
) )
273 if ((nFlags
& LF_NO_ACCOUNT
) != 0 && !rRealm
.isEmpty())
275 aRequest
= ResId(STR_LOGIN_REALM
, *pResMgr
).toString();
276 aRequest
.SearchAndReplaceAscii("%2", rRealm
);
279 aRequest
= aRequestInfo
.GetText();
281 if ( !( ( nFlags
& LF_NO_USESYSCREDS
) == LF_NO_USESYSCREDS
) )
282 EnableUseSysCredsControls_Impl( aUseSysCredsCB
.IsChecked() );
284 aRequest
.SearchAndReplaceAscii("%1", rServer
);
285 aRequestInfo
.SetText(aRequest
);
289 aPathED
.SetMaxTextLen( _MAX_PATH
);
290 aNameED
.SetMaxTextLen( _MAX_PATH
);
292 aOKBtn
.SetClickHdl( LINK( this, LoginDialog
, OKHdl_Impl
) );
293 aPathBtn
.SetClickHdl( LINK( this, LoginDialog
, PathHdl_Impl
) );
294 aUseSysCredsCB
.SetClickHdl( LINK( this, LoginDialog
, UseSysCredsHdl_Impl
) );
296 HideControls_Impl( nFlags
);
299 // -----------------------------------------------------------------------
301 LoginDialog::~LoginDialog()
305 // -----------------------------------------------------------------------
307 void LoginDialog::SetUseSystemCredentials( sal_Bool bUse
)
309 if ( aUseSysCredsCB
.IsVisible() )
311 aUseSysCredsCB
.Check( bUse
);
312 EnableUseSysCredsControls_Impl( bUse
);
316 // -----------------------------------------------------------------------
318 void LoginDialog::ClearPassword()
320 aPasswordED
.SetText( String() );
322 if ( 0 == aNameED
.GetText().Len() )
325 aPasswordED
.GrabFocus();
328 // -----------------------------------------------------------------------
330 void LoginDialog::ClearAccount()
332 aAccountED
.SetText( String() );
333 aAccountED
.GrabFocus();
336 //............................................................................
337 //............................................................................
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */