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 <vcl/msgbox.hxx>
22 : #include "logindlg.hxx"
23 :
24 : #include "logindlg.hrc"
25 : #include "ids.hrc"
26 : #include <tools/resid.hxx>
27 : #include <osl/file.hxx>
28 :
29 : #ifdef UNX
30 : #include <limits.h>
31 : #define _MAX_PATH PATH_MAX
32 : #endif
33 :
34 : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
35 : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
36 : #include <comphelper/processfactory.hxx>
37 :
38 : using namespace com::sun::star;
39 :
40 0 : static void lcl_Move( Window &rWin, long nOffset )
41 : {
42 0 : Point aTmp( rWin.GetPosPixel() );
43 0 : aTmp.Y() -= nOffset;
44 0 : rWin.SetPosPixel( aTmp );
45 0 : }
46 :
47 :
48 0 : void LoginDialog::HideControls_Impl( sal_uInt16 nFlags )
49 : {
50 0 : bool bPathHide = sal_False;
51 0 : bool bErrorHide = sal_False;
52 0 : bool bAccountHide = sal_False;
53 0 : bool bUseSysCredsHide = sal_False;
54 :
55 0 : if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
56 : {
57 0 : aPathFT.Hide();
58 0 : aPathED.Hide();
59 0 : aPathBtn.Hide();
60 0 : bPathHide = sal_True;
61 : }
62 0 : else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
63 : {
64 0 : aPathED.Enable( sal_False );
65 0 : aPathBtn.Enable( sal_False );
66 : }
67 :
68 0 : if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
69 : {
70 0 : aNameFT.Hide();
71 0 : aNameED.Hide();
72 : }
73 0 : else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
74 : {
75 0 : aNameED.Enable( sal_False );
76 : }
77 :
78 0 : if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
79 : {
80 0 : aPasswordFT.Hide();
81 0 : aPasswordED.Hide();
82 : }
83 :
84 0 : if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
85 0 : aSavePasswdBtn.Hide();
86 :
87 0 : if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
88 : {
89 0 : aErrorInfo.Hide();
90 0 : aErrorFT.Hide();
91 0 : aLogin1FL.Hide();
92 0 : bErrorHide = sal_True;
93 : }
94 :
95 0 : if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
96 : {
97 0 : aAccountFT.Hide();
98 0 : aAccountED.Hide();
99 0 : bAccountHide = sal_True;
100 : }
101 :
102 0 : if ( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS )
103 : {
104 0 : aUseSysCredsCB.Hide();
105 0 : bUseSysCredsHide = sal_True;
106 : }
107 :
108 0 : if ( bErrorHide )
109 : {
110 0 : long nOffset = aRequestInfo.GetPosPixel().Y() -
111 0 : aErrorFT.GetPosPixel().Y();
112 0 : lcl_Move( aRequestInfo, nOffset );
113 0 : lcl_Move( aLogin2FL, nOffset );
114 0 : lcl_Move( aPathFT, nOffset );
115 0 : lcl_Move( aPathED, nOffset );
116 0 : lcl_Move( aPathBtn, nOffset );
117 0 : lcl_Move( aNameFT, nOffset );
118 0 : lcl_Move( aNameED, nOffset );
119 0 : lcl_Move( aPasswordFT, nOffset );
120 0 : lcl_Move( aPasswordED, nOffset );
121 0 : lcl_Move( aAccountFT, nOffset );
122 0 : lcl_Move( aAccountED, nOffset );
123 0 : lcl_Move( aSavePasswdBtn, nOffset );
124 0 : lcl_Move( aUseSysCredsCB, nOffset );
125 0 : lcl_Move( aButtonsFL, nOffset );
126 0 : lcl_Move( aOKBtn, nOffset );
127 0 : lcl_Move( aCancelBtn, nOffset );
128 0 : lcl_Move( aHelpBtn, nOffset );
129 :
130 0 : Size aNewSiz = GetSizePixel();
131 0 : aNewSiz.Height() -= nOffset;
132 0 : SetSizePixel( aNewSiz );
133 : }
134 :
135 0 : if ( bPathHide )
136 : {
137 0 : long nOffset = aNameED.GetPosPixel().Y() -
138 0 : aPathED.GetPosPixel().Y();
139 0 : lcl_Move( aNameFT, nOffset );
140 0 : lcl_Move( aNameED, nOffset );
141 0 : lcl_Move( aPasswordFT, nOffset );
142 0 : lcl_Move( aPasswordED, nOffset );
143 0 : lcl_Move( aAccountFT, nOffset );
144 0 : lcl_Move( aAccountED, nOffset );
145 0 : lcl_Move( aSavePasswdBtn, nOffset );
146 0 : lcl_Move( aUseSysCredsCB, nOffset );
147 0 : lcl_Move( aButtonsFL, nOffset );
148 0 : lcl_Move( aOKBtn, nOffset );
149 0 : lcl_Move( aCancelBtn, nOffset );
150 0 : lcl_Move( aHelpBtn, nOffset );
151 :
152 0 : Size aNewSz = GetSizePixel();
153 0 : aNewSz.Height() -= nOffset;
154 0 : SetSizePixel( aNewSz );
155 : }
156 :
157 0 : if ( bAccountHide )
158 : {
159 0 : long nOffset = aAccountED.GetPosPixel().Y() -
160 0 : aPasswordED.GetPosPixel().Y();
161 0 : lcl_Move( aSavePasswdBtn, nOffset );
162 0 : lcl_Move( aUseSysCredsCB, nOffset );
163 0 : lcl_Move( aButtonsFL, nOffset );
164 0 : lcl_Move( aOKBtn, nOffset );
165 0 : lcl_Move( aCancelBtn, nOffset );
166 0 : lcl_Move( aHelpBtn, nOffset );
167 :
168 0 : Size aNewSz = GetSizePixel();
169 0 : aNewSz.Height() -= nOffset;
170 0 : SetSizePixel( aNewSz );
171 : }
172 :
173 0 : if ( bUseSysCredsHide )
174 : {
175 0 : long nOffset = aUseSysCredsCB.GetPosPixel().Y() -
176 0 : aSavePasswdBtn.GetPosPixel().Y();
177 0 : lcl_Move( aButtonsFL, nOffset );
178 0 : lcl_Move( aOKBtn, nOffset );
179 0 : lcl_Move( aCancelBtn, nOffset );
180 0 : lcl_Move( aHelpBtn, nOffset );
181 :
182 0 : Size aNewSz = GetSizePixel();
183 0 : aNewSz.Height() -= nOffset;
184 0 : SetSizePixel( aNewSz );
185 : }
186 0 : };
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 0 : IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl)
205 : {
206 : // trim the strings
207 0 : aNameED.SetText(comphelper::string::strip(aNameED.GetText(), ' '));
208 0 : aPasswordED.SetText(comphelper::string::strip(aPasswordED.GetText(), ' '));
209 0 : EndDialog( RET_OK );
210 0 : return 1;
211 : }
212 :
213 0 : IMPL_LINK_NOARG(LoginDialog, PathHdl_Impl)
214 : {
215 : try
216 : {
217 0 : uno::Reference<ui::dialogs::XFolderPicker2> xFolderPicker = ui::dialogs::FolderPicker::create(comphelper::getProcessComponentContext());
218 :
219 0 : OUString aPath( aPathED.GetText() );
220 0 : osl::FileBase::getFileURLFromSystemPath( aPath, aPath );
221 0 : xFolderPicker->setDisplayDirectory( aPath );
222 :
223 0 : if (xFolderPicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
224 : {
225 0 : osl::FileBase::getSystemPathFromFileURL( xFolderPicker->getDirectory(), aPath );
226 0 : aPathED.SetText( aPath );
227 0 : }
228 : }
229 0 : catch (uno::Exception & e)
230 : {
231 : SAL_WARN("uui", "LoginDialog::PathHdl_Impl: caught UNO exception: " << e.Message);
232 : }
233 :
234 0 : return 1;
235 : }
236 :
237 0 : IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl)
238 : {
239 0 : EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
240 0 : return 1;
241 : }
242 :
243 0 : LoginDialog::LoginDialog
244 : (
245 : Window* pParent,
246 : sal_uInt16 nFlags,
247 : const OUString& rServer,
248 : const OUString& rRealm,
249 : ResMgr* pResMgr
250 : ) :
251 :
252 : ModalDialog( pParent, ResId( DLG_UUI_LOGIN, *pResMgr ) ),
253 :
254 : aErrorFT ( this, ResId( FT_LOGIN_ERROR, *pResMgr ) ),
255 : aErrorInfo ( this, ResId( FT_INFO_LOGIN_ERROR, *pResMgr ) ),
256 : aLogin1FL ( this, ResId( FL_LOGIN_1, *pResMgr ) ),
257 : aRequestInfo ( this, ResId( FT_INFO_LOGIN_REQUEST, *pResMgr ) ),
258 : aLogin2FL ( this, ResId( FL_LOGIN_2, *pResMgr ) ),
259 : aPathFT ( this, ResId( FT_LOGIN_PATH, *pResMgr ) ),
260 : aPathED ( this, ResId( ED_LOGIN_PATH, *pResMgr ) ),
261 : aPathBtn ( this, ResId( BTN_LOGIN_PATH, *pResMgr ) ),
262 : aNameFT ( this, ResId( FT_LOGIN_USERNAME, *pResMgr ) ),
263 : aNameED ( this, ResId( ED_LOGIN_USERNAME, *pResMgr ) ),
264 : aPasswordFT ( this, ResId( FT_LOGIN_PASSWORD, *pResMgr ) ),
265 : aPasswordED ( this, ResId( ED_LOGIN_PASSWORD, *pResMgr ) ),
266 : aAccountFT ( this, ResId( FT_LOGIN_ACCOUNT, *pResMgr ) ),
267 : aAccountED ( this, ResId( ED_LOGIN_ACCOUNT, *pResMgr ) ),
268 : aSavePasswdBtn ( this, ResId( CB_LOGIN_SAVEPASSWORD, *pResMgr ) ),
269 : aUseSysCredsCB ( this, ResId( CB_LOGIN_USESYSCREDS, *pResMgr ) ),
270 : aButtonsFL ( this, ResId( FL_BUTTONS, *pResMgr ) ),
271 : aOKBtn ( this, ResId( BTN_LOGIN_OK, *pResMgr ) ),
272 : aCancelBtn ( this, ResId( BTN_LOGIN_CANCEL, *pResMgr ) ),
273 0 : aHelpBtn ( this, ResId( BTN_LOGIN_HELP, *pResMgr ) )
274 :
275 : {
276 0 : OUString aRequest;
277 0 : if ((nFlags & LF_NO_ACCOUNT) != 0 && !rRealm.isEmpty())
278 : {
279 0 : aRequest = OUString(ResId(STR_LOGIN_REALM, *pResMgr));
280 0 : aRequest = aRequest.replaceAll("%2", rRealm);
281 : }
282 : else
283 0 : aRequest = aRequestInfo.GetText();
284 :
285 0 : if ( !( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS ) )
286 0 : EnableUseSysCredsControls_Impl( aUseSysCredsCB.IsChecked() );
287 :
288 0 : aRequest = aRequest.replaceAll("%1", rServer);
289 0 : aRequestInfo.SetText(aRequest);
290 :
291 0 : FreeResource();
292 :
293 0 : aPathED.SetMaxTextLen( _MAX_PATH );
294 0 : aNameED.SetMaxTextLen( _MAX_PATH );
295 :
296 0 : aOKBtn.SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
297 0 : aPathBtn.SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
298 0 : aUseSysCredsCB.SetClickHdl( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
299 :
300 0 : HideControls_Impl( nFlags );
301 0 : };
302 :
303 0 : LoginDialog::~LoginDialog()
304 : {
305 0 : }
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 0 : void LoginDialog::ClearPassword()
317 : {
318 0 : aPasswordED.SetText( String() );
319 :
320 0 : if ( aNameED.GetText().isEmpty() )
321 0 : aNameED.GrabFocus();
322 : else
323 0 : aPasswordED.GrabFocus();
324 0 : };
325 :
326 0 : void LoginDialog::ClearAccount()
327 : {
328 0 : aAccountED.SetText( String() );
329 0 : aAccountED.GrabFocus();
330 36 : };
331 :
332 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|