bump product version to 5.0.4.1
[LibreOffice.git] / uui / source / logindlg.cxx
blobca44729e15f01454a95a0592a9c73700d60a0ace
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <vcl/msgbox.hxx>
22 #include "logindlg.hxx"
24 #include "ids.hrc"
25 #include <tools/resid.hxx>
26 #include <osl/file.hxx>
28 #ifdef UNX
29 #include <limits.h>
30 #define _MAX_PATH PATH_MAX
31 #endif
33 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
34 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
35 #include <comphelper/processfactory.hxx>
37 using namespace com::sun::star;
39 LoginDialog::~LoginDialog()
41 disposeOnce();
44 void LoginDialog::dispose()
46 m_pErrorFT.clear();
47 m_pErrorInfo.clear();
48 m_pRequestInfo.clear();
49 m_pPathFT.clear();
50 m_pPathED.clear();
51 m_pPathBtn.clear();
52 m_pNameFT.clear();
53 m_pNameED.clear();
54 m_pPasswordFT.clear();
55 m_pPasswordED.clear();
56 m_pAccountFT.clear();
57 m_pAccountED.clear();
58 m_pSavePasswdBtn.clear();
59 m_pUseSysCredsCB.clear();
60 m_pOKBtn.clear();
61 ModalDialog::dispose();
64 void LoginDialog::HideControls_Impl( sal_uInt16 nFlags )
66 if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
68 m_pPathFT->Hide();
69 m_pPathED->Hide();
70 m_pPathBtn->Hide();
72 else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
74 m_pPathED->Enable( false );
75 m_pPathBtn->Enable( false );
78 if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
80 m_pNameFT->Hide();
81 m_pNameED->Hide();
83 else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
85 m_pNameED->Enable( false );
88 if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
90 m_pPasswordFT->Hide();
91 m_pPasswordED->Hide();
94 if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
95 m_pSavePasswdBtn->Hide();
97 if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
99 m_pErrorInfo->Hide();
100 m_pErrorFT->Hide();
103 if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
105 m_pAccountFT->Hide();
106 m_pAccountED->Hide();
109 if ( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS )
111 m_pUseSysCredsCB->Hide();
115 void LoginDialog::EnableUseSysCredsControls_Impl( bool bUseSysCredsEnabled )
117 m_pErrorInfo->Enable( !bUseSysCredsEnabled );
118 m_pErrorFT->Enable( !bUseSysCredsEnabled );
119 m_pRequestInfo->Enable( !bUseSysCredsEnabled );
120 m_pPathFT->Enable( !bUseSysCredsEnabled );
121 m_pPathED->Enable( !bUseSysCredsEnabled );
122 m_pPathBtn->Enable( !bUseSysCredsEnabled );
123 m_pNameFT->Enable( !bUseSysCredsEnabled );
124 m_pNameED->Enable( !bUseSysCredsEnabled );
125 m_pPasswordFT->Enable( !bUseSysCredsEnabled );
126 m_pPasswordED->Enable( !bUseSysCredsEnabled );
127 m_pAccountFT->Enable( !bUseSysCredsEnabled );
128 m_pAccountED->Enable( !bUseSysCredsEnabled );
131 IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl)
133 // trim the strings
134 m_pNameED->SetText(comphelper::string::strip(m_pNameED->GetText(), ' '));
135 m_pPasswordED->SetText(comphelper::string::strip(m_pPasswordED->GetText(), ' '));
136 EndDialog( RET_OK );
137 return 1;
140 IMPL_LINK_NOARG(LoginDialog, PathHdl_Impl)
144 uno::Reference<ui::dialogs::XFolderPicker2> xFolderPicker = ui::dialogs::FolderPicker::create(comphelper::getProcessComponentContext());
146 OUString aPath( m_pPathED->GetText() );
147 osl::FileBase::getFileURLFromSystemPath( aPath, aPath );
148 xFolderPicker->setDisplayDirectory( aPath );
150 if (xFolderPicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
152 osl::FileBase::getSystemPathFromFileURL( xFolderPicker->getDirectory(), aPath );
153 m_pPathED->SetText( aPath );
156 catch (uno::Exception & e)
158 SAL_WARN("uui", "LoginDialog::PathHdl_Impl: caught UNO exception: " << e.Message);
161 return 1;
164 IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl)
166 EnableUseSysCredsControls_Impl( m_pUseSysCredsCB->IsChecked() );
167 return 1;
170 LoginDialog::LoginDialog(vcl::Window* pParent, sal_uInt16 nFlags,
171 const OUString& rServer, const OUString& rRealm)
172 : ModalDialog(pParent, "LoginDialog", "uui/ui/logindialog.ui")
174 get(m_pErrorFT, "errorft");
175 get(m_pErrorInfo, "errorinfo");
176 get(m_pRequestInfo, "requestinfo");
177 get(m_pPathFT, "pathft");
178 get(m_pPathED, "pathed");
179 get(m_pPathBtn, "pathbtn");
180 get(m_pNameFT, "nameft");
181 get(m_pNameED, "nameed");
182 get(m_pPasswordFT, "passwordft");
183 get(m_pPasswordED, "passworded");
184 get(m_pAccountFT, "accountft");
185 get(m_pAccountED, "accounted");
186 get(m_pSavePasswdBtn, "remember");
187 get(m_pUseSysCredsCB, "syscreds");
188 get(m_pOKBtn, "ok");
190 OUString aRequest;
191 if ((nFlags & LF_NO_ACCOUNT) != 0 && !rRealm.isEmpty())
193 aRequest = get<FixedText>("loginrealm")->GetText();
194 aRequest = aRequest.replaceAll("%2", rRealm);
196 else
197 aRequest = m_pRequestInfo->GetText();
199 if ( !( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS ) )
200 EnableUseSysCredsControls_Impl( m_pUseSysCredsCB->IsChecked() );
202 aRequest = aRequest.replaceAll("%1", rServer);
203 m_pRequestInfo->SetText(aRequest);
205 m_pPathED->SetMaxTextLen( _MAX_PATH );
206 m_pNameED->SetMaxTextLen( _MAX_PATH );
208 m_pOKBtn->SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
209 m_pPathBtn->SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
210 m_pUseSysCredsCB->SetClickHdl( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
212 HideControls_Impl( nFlags );
215 void LoginDialog::SetUseSystemCredentials( bool bUse )
217 if ( m_pUseSysCredsCB->IsVisible() )
219 m_pUseSysCredsCB->Check( bUse );
220 EnableUseSysCredsControls_Impl( bUse );
224 void LoginDialog::ClearPassword()
226 m_pPasswordED->SetText( OUString() );
228 if ( m_pNameED->GetText().isEmpty() )
229 m_pNameED->GrabFocus();
230 else
231 m_pPasswordED->GrabFocus();
234 void LoginDialog::ClearAccount()
236 m_pAccountED->SetText( OUString() );
237 m_pAccountED->GrabFocus();
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */