Branch data 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 <comphelper/string.hxx>
21 : : #include <svtools/filedlg.hxx>
22 : : #include <vcl/msgbox.hxx>
23 : : #include "logindlg.hxx"
24 : :
25 : : #include "logindlg.hrc"
26 : : #include "ids.hrc"
27 : : #include <tools/resid.hxx>
28 : :
29 : : #ifdef UNX
30 : : #include <limits.h>
31 : : #define _MAX_PATH PATH_MAX
32 : : #endif
33 : :
34 : : // LoginDialog -------------------------------------------------------
35 : :
36 : : //............................................................................
37 : : //............................................................................
38 : :
39 : 0 : static void lcl_Move( Window &rWin, long nOffset )
40 : : {
41 [ # # ]: 0 : Point aTmp( rWin.GetPosPixel() );
42 : 0 : aTmp.Y() -= nOffset;
43 [ # # ]: 0 : rWin.SetPosPixel( aTmp );
44 : 0 : }
45 : :
46 : :
47 : 0 : void LoginDialog::HideControls_Impl( sal_uInt16 nFlags )
48 : : {
49 : 0 : bool bPathHide = sal_False;
50 : 0 : bool bErrorHide = sal_False;
51 : 0 : bool bAccountHide = sal_False;
52 : 0 : bool bUseSysCredsHide = sal_False;
53 : :
54 [ # # ]: 0 : if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
55 : : {
56 : 0 : aPathFT.Hide();
57 : 0 : aPathED.Hide();
58 : 0 : aPathBtn.Hide();
59 : 0 : bPathHide = sal_True;
60 : : }
61 [ # # ]: 0 : else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
62 : : {
63 : 0 : aPathED.Enable( sal_False );
64 : 0 : aPathBtn.Enable( sal_False );
65 : : }
66 : :
67 [ # # ]: 0 : if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
68 : : {
69 : 0 : aNameFT.Hide();
70 : 0 : aNameED.Hide();
71 : : }
72 [ # # ]: 0 : else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
73 : : {
74 : 0 : aNameED.Enable( sal_False );
75 : : }
76 : :
77 [ # # ]: 0 : if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
78 : : {
79 : 0 : aPasswordFT.Hide();
80 : 0 : aPasswordED.Hide();
81 : : }
82 : :
83 [ # # ]: 0 : if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
84 : 0 : aSavePasswdBtn.Hide();
85 : :
86 [ # # ]: 0 : if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
87 : : {
88 : 0 : aErrorInfo.Hide();
89 : 0 : aErrorFT.Hide();
90 : 0 : aLogin1FL.Hide();
91 : 0 : bErrorHide = sal_True;
92 : : }
93 : :
94 [ # # ]: 0 : if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
95 : : {
96 : 0 : aAccountFT.Hide();
97 : 0 : aAccountED.Hide();
98 : 0 : bAccountHide = sal_True;
99 : : }
100 : :
101 [ # # ]: 0 : if ( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS )
102 : : {
103 : 0 : aUseSysCredsCB.Hide();
104 : 0 : bUseSysCredsHide = sal_True;
105 : : }
106 : :
107 [ # # ]: 0 : if ( bErrorHide )
108 : : {
109 [ # # ]: 0 : long nOffset = aRequestInfo.GetPosPixel().Y() -
110 [ # # ]: 0 : aErrorFT.GetPosPixel().Y();
111 [ # # ]: 0 : lcl_Move( aRequestInfo, nOffset );
112 [ # # ]: 0 : lcl_Move( aLogin2FL, nOffset );
113 [ # # ]: 0 : lcl_Move( aPathFT, nOffset );
114 [ # # ]: 0 : lcl_Move( aPathED, nOffset );
115 [ # # ]: 0 : lcl_Move( aPathBtn, nOffset );
116 [ # # ]: 0 : lcl_Move( aNameFT, nOffset );
117 [ # # ]: 0 : lcl_Move( aNameED, nOffset );
118 [ # # ]: 0 : lcl_Move( aPasswordFT, nOffset );
119 [ # # ]: 0 : lcl_Move( aPasswordED, nOffset );
120 [ # # ]: 0 : lcl_Move( aAccountFT, nOffset );
121 [ # # ]: 0 : lcl_Move( aAccountED, nOffset );
122 [ # # ]: 0 : lcl_Move( aSavePasswdBtn, nOffset );
123 [ # # ]: 0 : lcl_Move( aUseSysCredsCB, nOffset );
124 [ # # ]: 0 : lcl_Move( aButtonsFL, nOffset );
125 [ # # ]: 0 : lcl_Move( aOKBtn, nOffset );
126 [ # # ]: 0 : lcl_Move( aCancelBtn, nOffset );
127 [ # # ]: 0 : lcl_Move( aHelpBtn, nOffset );
128 : :
129 [ # # ]: 0 : Size aNewSiz = GetSizePixel();
130 : 0 : aNewSiz.Height() -= nOffset;
131 [ # # ]: 0 : SetSizePixel( aNewSiz );
132 : : }
133 : :
134 [ # # ]: 0 : if ( bPathHide )
135 : : {
136 [ # # ]: 0 : long nOffset = aNameED.GetPosPixel().Y() -
137 [ # # ]: 0 : aPathED.GetPosPixel().Y();
138 [ # # ]: 0 : lcl_Move( aNameFT, nOffset );
139 [ # # ]: 0 : lcl_Move( aNameED, nOffset );
140 [ # # ]: 0 : lcl_Move( aPasswordFT, nOffset );
141 [ # # ]: 0 : lcl_Move( aPasswordED, nOffset );
142 [ # # ]: 0 : lcl_Move( aAccountFT, nOffset );
143 [ # # ]: 0 : lcl_Move( aAccountED, nOffset );
144 [ # # ]: 0 : lcl_Move( aSavePasswdBtn, nOffset );
145 [ # # ]: 0 : lcl_Move( aUseSysCredsCB, nOffset );
146 [ # # ]: 0 : lcl_Move( aButtonsFL, nOffset );
147 [ # # ]: 0 : lcl_Move( aOKBtn, nOffset );
148 [ # # ]: 0 : lcl_Move( aCancelBtn, nOffset );
149 [ # # ]: 0 : lcl_Move( aHelpBtn, nOffset );
150 : :
151 [ # # ]: 0 : Size aNewSz = GetSizePixel();
152 : 0 : aNewSz.Height() -= nOffset;
153 [ # # ]: 0 : SetSizePixel( aNewSz );
154 : : }
155 : :
156 [ # # ]: 0 : if ( bAccountHide )
157 : : {
158 [ # # ]: 0 : long nOffset = aAccountED.GetPosPixel().Y() -
159 [ # # ]: 0 : aPasswordED.GetPosPixel().Y();
160 [ # # ]: 0 : lcl_Move( aSavePasswdBtn, nOffset );
161 [ # # ]: 0 : lcl_Move( aUseSysCredsCB, nOffset );
162 [ # # ]: 0 : lcl_Move( aButtonsFL, nOffset );
163 [ # # ]: 0 : lcl_Move( aOKBtn, nOffset );
164 [ # # ]: 0 : lcl_Move( aCancelBtn, nOffset );
165 [ # # ]: 0 : lcl_Move( aHelpBtn, nOffset );
166 : :
167 [ # # ]: 0 : Size aNewSz = GetSizePixel();
168 : 0 : aNewSz.Height() -= nOffset;
169 [ # # ]: 0 : SetSizePixel( aNewSz );
170 : : }
171 : :
172 [ # # ]: 0 : if ( bUseSysCredsHide )
173 : : {
174 [ # # ]: 0 : long nOffset = aUseSysCredsCB.GetPosPixel().Y() -
175 [ # # ]: 0 : aSavePasswdBtn.GetPosPixel().Y();
176 [ # # ]: 0 : lcl_Move( aButtonsFL, nOffset );
177 [ # # ]: 0 : lcl_Move( aOKBtn, nOffset );
178 [ # # ]: 0 : lcl_Move( aCancelBtn, nOffset );
179 [ # # ]: 0 : lcl_Move( aHelpBtn, nOffset );
180 : :
181 [ # # ]: 0 : Size aNewSz = GetSizePixel();
182 : 0 : aNewSz.Height() -= nOffset;
183 [ # # ]: 0 : SetSizePixel( aNewSz );
184 : : }
185 : 0 : };
186 : :
187 : : // -----------------------------------------------------------------------
188 : 0 : void LoginDialog::EnableUseSysCredsControls_Impl( sal_Bool bUseSysCredsEnabled )
189 : : {
190 : 0 : aErrorInfo.Enable( !bUseSysCredsEnabled );
191 : 0 : aErrorFT.Enable( !bUseSysCredsEnabled );
192 : 0 : aRequestInfo.Enable( !bUseSysCredsEnabled );
193 : 0 : aPathFT.Enable( !bUseSysCredsEnabled );
194 : 0 : aPathED.Enable( !bUseSysCredsEnabled );
195 : 0 : aPathBtn.Enable( !bUseSysCredsEnabled );
196 : 0 : aNameFT.Enable( !bUseSysCredsEnabled );
197 : 0 : aNameED.Enable( !bUseSysCredsEnabled );
198 : 0 : aPasswordFT.Enable( !bUseSysCredsEnabled );
199 : 0 : aPasswordED.Enable( !bUseSysCredsEnabled );
200 : 0 : aAccountFT.Enable( !bUseSysCredsEnabled );
201 : 0 : aAccountED.Enable( !bUseSysCredsEnabled );
202 : 0 : }
203 : :
204 : : // -----------------------------------------------------------------------
205 : :
206 : 0 : IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl)
207 : : {
208 : : // trim the strings
209 [ # # ][ # # ]: 0 : aNameED.SetText(comphelper::string::strip(aNameED.GetText(), ' '));
[ # # ][ # # ]
[ # # ]
210 [ # # ][ # # ]: 0 : aPasswordED.SetText(comphelper::string::strip(aPasswordED.GetText(), ' '));
[ # # ][ # # ]
[ # # ]
211 : 0 : EndDialog( RET_OK );
212 : 0 : return 1;
213 : : }
214 : :
215 : : // -----------------------------------------------------------------------
216 : :
217 : 0 : IMPL_LINK_NOARG(LoginDialog, PathHdl_Impl)
218 : : {
219 [ # # ]: 0 : PathDialog* pDlg = new PathDialog( this, WB_3DLOOK );
220 [ # # ][ # # ]: 0 : pDlg->SetPath( aPathED.GetText() );
221 : :
222 [ # # ]: 0 : if ( pDlg->Execute() == RET_OK )
223 [ # # ][ # # ]: 0 : aPathED.SetText( pDlg->GetPath() );
[ # # ]
224 : :
225 [ # # ]: 0 : delete pDlg;
226 : 0 : return 1;
227 : : }
228 : :
229 : : // -----------------------------------------------------------------------
230 : :
231 : 0 : IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl)
232 : : {
233 : 0 : EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
234 : 0 : return 1;
235 : : }
236 : :
237 : : // -----------------------------------------------------------------------
238 : :
239 : 0 : LoginDialog::LoginDialog
240 : : (
241 : : Window* pParent,
242 : : sal_uInt16 nFlags,
243 : : const rtl::OUString& rServer,
244 : : const rtl::OUString& rRealm,
245 : : ResMgr* pResMgr
246 : : ) :
247 : :
248 : : ModalDialog( pParent, ResId( DLG_UUI_LOGIN, *pResMgr ) ),
249 : :
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 [ # # ][ # # ]: 0 : aHelpBtn ( this, ResId( BTN_LOGIN_HELP, *pResMgr ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
270 : :
271 : : {
272 [ # # ]: 0 : UniString aRequest;
273 [ # # ][ # # ]: 0 : if ((nFlags & LF_NO_ACCOUNT) != 0 && !rRealm.isEmpty())
[ # # ]
274 : : {
275 [ # # ][ # # ]: 0 : aRequest = ResId(STR_LOGIN_REALM, *pResMgr).toString();
276 [ # # ][ # # ]: 0 : aRequest.SearchAndReplaceAscii("%2", rRealm);
[ # # ]
277 : : }
278 : : else
279 [ # # ][ # # ]: 0 : aRequest = aRequestInfo.GetText();
[ # # ]
280 : :
281 [ # # ]: 0 : if ( !( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS ) )
282 [ # # ][ # # ]: 0 : EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
283 : :
284 [ # # ][ # # ]: 0 : aRequest.SearchAndReplaceAscii("%1", rServer);
[ # # ]
285 [ # # ]: 0 : aRequestInfo.SetText(aRequest);
286 : :
287 [ # # ]: 0 : FreeResource();
288 : :
289 [ # # ]: 0 : aPathED.SetMaxTextLen( _MAX_PATH );
290 [ # # ]: 0 : aNameED.SetMaxTextLen( _MAX_PATH );
291 : :
292 [ # # ]: 0 : aOKBtn.SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
293 [ # # ]: 0 : aPathBtn.SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
294 [ # # ]: 0 : aUseSysCredsCB.SetClickHdl( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
295 : :
296 [ # # ][ # # ]: 0 : HideControls_Impl( nFlags );
297 : 0 : };
298 : :
299 : : // -----------------------------------------------------------------------
300 : :
301 [ # # ][ # # ]: 0 : LoginDialog::~LoginDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
302 : : {
303 [ # # ]: 0 : }
304 : :
305 : : // -----------------------------------------------------------------------
306 : :
307 : 0 : void LoginDialog::SetUseSystemCredentials( sal_Bool bUse )
308 : : {
309 [ # # ]: 0 : if ( aUseSysCredsCB.IsVisible() )
310 : : {
311 : 0 : aUseSysCredsCB.Check( bUse );
312 : 0 : EnableUseSysCredsControls_Impl( bUse );
313 : : }
314 : 0 : }
315 : :
316 : : // -----------------------------------------------------------------------
317 : :
318 : 0 : void LoginDialog::ClearPassword()
319 : : {
320 [ # # ]: 0 : aPasswordED.SetText( String() );
321 : :
322 [ # # ]: 0 : if ( 0 == aNameED.GetText().Len() )
323 : 0 : aNameED.GrabFocus();
324 : : else
325 : 0 : aPasswordED.GrabFocus();
326 : 0 : };
327 : :
328 : : // -----------------------------------------------------------------------
329 : :
330 : 0 : void LoginDialog::ClearAccount()
331 : : {
332 [ # # ]: 0 : aAccountED.SetText( String() );
333 : 0 : aAccountED.GrabFocus();
334 : 0 : };
335 : :
336 : : //............................................................................
337 : : //............................................................................
338 : :
339 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|