nss: upgrade to release 3.73
[LibreOffice.git] / uui / source / logindlg.cxx
blob5264c26f8366e8c15dc1e5408bdc7ab5fcfaf106
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 #ifdef UNX
24 #include <limits.h>
25 #define _MAX_PATH PATH_MAX
26 #endif
28 using namespace com::sun::star;
30 LoginDialog::~LoginDialog()
34 void LoginDialog::SetPassword( const OUString& rNew )
36 m_xPasswordED->set_text( rNew );
37 SetRequest();
40 void LoginDialog::HideControls_Impl( LoginFlags nFlags )
42 if ( nFlags & LoginFlags::UsernameReadonly )
44 m_xNameED->set_sensitive( false );
47 if ( nFlags & LoginFlags::NoSavePassword )
48 m_xSavePasswdBtn->hide();
50 if ( nFlags & LoginFlags::NoErrorText )
52 m_xErrorInfo->hide();
53 m_xErrorFT->hide();
56 if ( nFlags & LoginFlags::NoAccount )
58 m_xAccountFT->hide();
59 m_xAccountED->hide();
62 if ( nFlags & LoginFlags::NoUseSysCreds )
64 m_xUseSysCredsCB->hide();
68 void LoginDialog::EnableUseSysCredsControls_Impl( bool bUseSysCredsset_sensitived )
70 m_xErrorInfo->set_sensitive( !bUseSysCredsset_sensitived );
71 m_xErrorFT->set_sensitive( !bUseSysCredsset_sensitived );
72 m_xRequestInfo->set_sensitive( !bUseSysCredsset_sensitived );
73 m_xNameFT->set_sensitive( !bUseSysCredsset_sensitived );
74 m_xNameED->set_sensitive( !bUseSysCredsset_sensitived );
75 m_xPasswordFT->set_sensitive( !bUseSysCredsset_sensitived );
76 m_xPasswordED->set_sensitive( !bUseSysCredsset_sensitived );
77 m_xAccountFT->set_sensitive( !bUseSysCredsset_sensitived );
78 m_xAccountED->set_sensitive( !bUseSysCredsset_sensitived );
81 void LoginDialog::SetRequest()
83 bool oldPwd = !m_xPasswordED->get_text().isEmpty();
84 OUString aRequest;
85 if (m_xAccountFT->get_visible() && !m_realm.isEmpty())
87 std::unique_ptr<weld::Label> xText(m_xBuilder->weld_label(oldPwd ? "wrongloginrealm" : "loginrealm"));
88 aRequest = xText->get_label();
89 aRequest = aRequest.replaceAll("%2", m_realm);
91 else
93 std::unique_ptr<weld::Label> xText(m_xBuilder->weld_label(oldPwd ? "wrongrequestinfo" : "requestinfo"));
94 aRequest = xText->get_label();
96 aRequest = aRequest.replaceAll("%1", m_server);
97 m_xRequestInfo->set_label(aRequest);
100 IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl, weld::Button&, void)
102 // trim the strings
103 m_xNameED->set_text(comphelper::string::strip(m_xNameED->get_text(), ' '));
104 m_xPasswordED->set_text(comphelper::string::strip(m_xPasswordED->get_text(), ' '));
105 m_xDialog->response(RET_OK);
108 IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl, weld::Button&, void)
110 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB->get_active() );
113 LoginDialog::LoginDialog(weld::Window* pParent, LoginFlags nFlags,
114 const OUString& rServer, const OUString& rRealm)
115 : GenericDialogController(pParent, "uui/ui/logindialog.ui", "LoginDialog")
116 , m_xErrorFT(m_xBuilder->weld_label("errorft"))
117 , m_xErrorInfo(m_xBuilder->weld_label("errorinfo"))
118 , m_xRequestInfo(m_xBuilder->weld_label("requestinfo"))
119 , m_xNameFT(m_xBuilder->weld_label("nameft"))
120 , m_xNameED(m_xBuilder->weld_entry("nameed"))
121 , m_xPasswordFT(m_xBuilder->weld_label("passwordft"))
122 , m_xPasswordED(m_xBuilder->weld_entry("passworded"))
123 , m_xAccountFT(m_xBuilder->weld_label("accountft"))
124 , m_xAccountED(m_xBuilder->weld_entry("accounted"))
125 , m_xSavePasswdBtn(m_xBuilder->weld_check_button("remember"))
126 , m_xUseSysCredsCB(m_xBuilder->weld_check_button("syscreds"))
127 , m_xOKBtn(m_xBuilder->weld_button("ok"))
128 , m_server(rServer), m_realm(rRealm)
130 if ( !( nFlags & LoginFlags::NoUseSysCreds ) )
131 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB->get_active() );
133 SetRequest();
135 m_xNameED->set_max_length( _MAX_PATH );
137 m_xOKBtn->connect_clicked( LINK( this, LoginDialog, OKHdl_Impl ) );
138 m_xUseSysCredsCB->connect_clicked( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
140 HideControls_Impl( nFlags );
143 void LoginDialog::SetUseSystemCredentials( bool bUse )
145 if ( m_xUseSysCredsCB->get_visible() )
147 m_xUseSysCredsCB->set_active( bUse );
148 EnableUseSysCredsControls_Impl( bUse );
152 void LoginDialog::ClearPassword()
154 m_xPasswordED->set_text( OUString() );
156 if ( m_xNameED->get_text().isEmpty() )
157 m_xNameED->grab_focus();
158 else
159 m_xPasswordED->grab_focus();
162 void LoginDialog::ClearAccount()
164 m_xAccountED->set_text( OUString() );
165 m_xAccountED->grab_focus();
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */