Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / uui / source / logindlg.cxx
blob3f315bcc0f6a79b90435defd8f72a994f1589be8
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 "logindlg.hxx"
23 #include <strings.hrc>
24 #include <osl/file.hxx>
26 #ifdef UNX
27 #include <limits.h>
28 #define _MAX_PATH PATH_MAX
29 #endif
31 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
32 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
34 using namespace com::sun::star;
36 LoginDialog::~LoginDialog()
40 void LoginDialog::SetPassword( const OUString& rNew )
42 m_xPasswordED->set_text( rNew );
43 SetRequest();
46 void LoginDialog::HideControls_Impl( LoginFlags nFlags )
48 if ( nFlags & LoginFlags::NoUsername )
50 m_xNameFT->hide();
51 m_xNameED->hide();
53 else if ( nFlags & LoginFlags::UsernameReadonly )
55 m_xNameED->set_sensitive( false );
58 if ( nFlags & LoginFlags::NoPassword )
60 m_xPasswordFT->hide();
61 m_xPasswordED->hide();
64 if ( nFlags & LoginFlags::NoSavePassword )
65 m_xSavePasswdBtn->hide();
67 if ( nFlags & LoginFlags::NoErrorText )
69 m_xErrorInfo->hide();
70 m_xErrorFT->hide();
73 if ( nFlags & LoginFlags::NoAccount )
75 m_xAccountFT->hide();
76 m_xAccountED->hide();
79 if ( nFlags & LoginFlags::NoUseSysCreds )
81 m_xUseSysCredsCB->hide();
85 void LoginDialog::EnableUseSysCredsControls_Impl( bool bUseSysCredsset_sensitived )
87 m_xErrorInfo->set_sensitive( !bUseSysCredsset_sensitived );
88 m_xErrorFT->set_sensitive( !bUseSysCredsset_sensitived );
89 m_xRequestInfo->set_sensitive( !bUseSysCredsset_sensitived );
90 m_xNameFT->set_sensitive( !bUseSysCredsset_sensitived );
91 m_xNameED->set_sensitive( !bUseSysCredsset_sensitived );
92 m_xPasswordFT->set_sensitive( !bUseSysCredsset_sensitived );
93 m_xPasswordED->set_sensitive( !bUseSysCredsset_sensitived );
94 m_xAccountFT->set_sensitive( !bUseSysCredsset_sensitived );
95 m_xAccountED->set_sensitive( !bUseSysCredsset_sensitived );
98 void LoginDialog::SetRequest()
100 bool oldPwd = !m_xPasswordED->get_text().isEmpty();
101 OUString aRequest;
102 if (m_xAccountFT->get_visible() && !m_realm.isEmpty())
104 std::unique_ptr<weld::Label> xText(m_xBuilder->weld_label(oldPwd ? "wrongloginrealm" : "loginrealm"));
105 aRequest = xText->get_label();
106 aRequest = aRequest.replaceAll("%2", m_realm);
108 else
110 std::unique_ptr<weld::Label> xText(m_xBuilder->weld_label(oldPwd ? "wrongrequestinfo" : "requestinfo"));
111 aRequest = xText->get_label();
113 aRequest = aRequest.replaceAll("%1", m_server);
114 m_xRequestInfo->set_label(aRequest);
117 IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl, weld::Button&, void)
119 // trim the strings
120 m_xNameED->set_text(comphelper::string::strip(m_xNameED->get_text(), ' '));
121 m_xPasswordED->set_text(comphelper::string::strip(m_xPasswordED->get_text(), ' '));
122 m_xDialog->response(RET_OK);
125 IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl, weld::Button&, void)
127 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB->get_active() );
130 LoginDialog::LoginDialog(weld::Window* pParent, LoginFlags nFlags,
131 const OUString& rServer, const OUString& rRealm)
132 : GenericDialogController(pParent, "uui/ui/logindialog.ui", "LoginDialog")
133 , m_xErrorFT(m_xBuilder->weld_label("errorft"))
134 , m_xErrorInfo(m_xBuilder->weld_label("errorinfo"))
135 , m_xRequestInfo(m_xBuilder->weld_label("requestinfo"))
136 , m_xNameFT(m_xBuilder->weld_label("nameft"))
137 , m_xNameED(m_xBuilder->weld_entry("nameed"))
138 , m_xPasswordFT(m_xBuilder->weld_label("passwordft"))
139 , m_xPasswordED(m_xBuilder->weld_entry("passworded"))
140 , m_xAccountFT(m_xBuilder->weld_label("accountft"))
141 , m_xAccountED(m_xBuilder->weld_entry("accounted"))
142 , m_xSavePasswdBtn(m_xBuilder->weld_check_button("remember"))
143 , m_xUseSysCredsCB(m_xBuilder->weld_check_button("syscreds"))
144 , m_xOKBtn(m_xBuilder->weld_button("ok"))
145 , m_server(rServer), m_realm(rRealm)
147 if ( !( nFlags & LoginFlags::NoUseSysCreds ) )
148 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB->get_active() );
150 SetRequest();
152 m_xNameED->set_max_length( _MAX_PATH );
154 m_xOKBtn->connect_clicked( LINK( this, LoginDialog, OKHdl_Impl ) );
155 m_xUseSysCredsCB->connect_clicked( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
157 HideControls_Impl( nFlags );
160 void LoginDialog::SetUseSystemCredentials( bool bUse )
162 if ( m_xUseSysCredsCB->get_visible() )
164 m_xUseSysCredsCB->set_active( bUse );
165 EnableUseSysCredsControls_Impl( bUse );
169 void LoginDialog::ClearPassword()
171 m_xPasswordED->set_text( OUString() );
173 if ( m_xNameED->get_text().isEmpty() )
174 m_xNameED->grab_focus();
175 else
176 m_xPasswordED->grab_focus();
179 void LoginDialog::ClearAccount()
181 m_xAccountED->set_text( OUString() );
182 m_xAccountED->grab_focus();
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */