LibreOffice Module uui (master) 1
logindlg.cxx
Go to the documentation of this file.
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 <utility>
22#include "logindlg.hxx"
23
24#ifdef UNX
25#include <limits.h>
26#define _MAX_PATH PATH_MAX
27#endif
28
29using namespace com::sun::star;
30
32{
33}
34
35void LoginDialog::SetPassword( const OUString& rNew )
36{
37 m_xPasswordED->set_text( rNew );
38 SetRequest();
39}
40
42{
43 if ( nFlags & LoginFlags::UsernameReadonly )
44 {
45 m_xNameED->set_sensitive( false );
46 }
47
48 if ( nFlags & LoginFlags::NoSavePassword )
49 m_xSavePasswdBtn->hide();
50
51 if ( nFlags & LoginFlags::NoErrorText )
52 {
53 m_xErrorInfo->hide();
54 m_xErrorFT->hide();
55 }
56
57 if ( nFlags & LoginFlags::NoAccount )
58 {
59 m_xAccountFT->hide();
60 m_xAccountED->hide();
61 }
62
63 if ( nFlags & LoginFlags::NoUseSysCreds )
64 {
65 m_xUseSysCredsCB->hide();
66 }
67}
68
69void LoginDialog::EnableUseSysCredsControls_Impl( bool bUseSysCredsset_sensitived )
70{
71 m_xErrorInfo->set_sensitive( !bUseSysCredsset_sensitived );
72 m_xErrorFT->set_sensitive( !bUseSysCredsset_sensitived );
73 m_xRequestInfo->set_sensitive( !bUseSysCredsset_sensitived );
74 m_xNameFT->set_sensitive( !bUseSysCredsset_sensitived );
75 m_xNameED->set_sensitive( !bUseSysCredsset_sensitived );
76 m_xPasswordFT->set_sensitive( !bUseSysCredsset_sensitived );
77 m_xPasswordED->set_sensitive( !bUseSysCredsset_sensitived );
78 m_xAccountFT->set_sensitive( !bUseSysCredsset_sensitived );
79 m_xAccountED->set_sensitive( !bUseSysCredsset_sensitived );
80}
81
83{
84 bool oldPwd = !m_xPasswordED->get_text().isEmpty();
85 OUString aRequest;
86 if (m_xAccountFT->get_visible() && !m_realm.isEmpty())
87 {
88 std::unique_ptr<weld::Label> xText(m_xBuilder->weld_label(oldPwd ? OUString("wrongloginrealm") : OUString("loginrealm")));
89 aRequest = xText->get_label();
90 aRequest = aRequest.replaceAll("%2", m_realm);
91 }
92 else
93 {
94 std::unique_ptr<weld::Label> xText(m_xBuilder->weld_label(oldPwd ? OUString("wrongrequestinfo") : OUString("requestinfo")));
95 aRequest = xText->get_label();
96 }
97 aRequest = aRequest.replaceAll("%1", m_server);
98 m_xRequestInfo->set_label(aRequest);
99}
100
102{
103 // trim the strings
104 m_xNameED->set_text(comphelper::string::strip(m_xNameED->get_text(), ' '));
105 m_xPasswordED->set_text(comphelper::string::strip(m_xPasswordED->get_text(), ' '));
106 m_xDialog->response(RET_OK);
107}
108
109IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl, weld::Toggleable&, void)
110{
111 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB->get_active() );
112}
113
115 OUString aServer, OUString aRealm)
116 : GenericDialogController(pParent, "uui/ui/logindialog.ui", "LoginDialog")
117 , m_xErrorFT(m_xBuilder->weld_label("errorft"))
118 , m_xErrorInfo(m_xBuilder->weld_label("errorinfo"))
119 , m_xRequestInfo(m_xBuilder->weld_label("requestinfo"))
120 , m_xNameFT(m_xBuilder->weld_label("nameft"))
121 , m_xNameED(m_xBuilder->weld_entry("nameed"))
122 , m_xPasswordFT(m_xBuilder->weld_label("passwordft"))
123 , m_xPasswordED(m_xBuilder->weld_entry("passworded"))
124 , m_xAccountFT(m_xBuilder->weld_label("accountft"))
125 , m_xAccountED(m_xBuilder->weld_entry("accounted"))
126 , m_xSavePasswdBtn(m_xBuilder->weld_check_button("remember"))
127 , m_xUseSysCredsCB(m_xBuilder->weld_check_button("syscreds"))
128 , m_xOKBtn(m_xBuilder->weld_button("ok"))
129 , m_server(std::move(aServer)), m_realm(std::move(aRealm))
130{
131 if ( !( nFlags & LoginFlags::NoUseSysCreds ) )
133
134 SetRequest();
135
136 m_xNameED->set_max_length( _MAX_PATH );
137
138 m_xOKBtn->connect_clicked( LINK( this, LoginDialog, OKHdl_Impl ) );
139 m_xUseSysCredsCB->connect_toggled( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
140
141 HideControls_Impl( nFlags );
142}
143
145{
146 if ( m_xUseSysCredsCB->get_visible() )
147 {
148 m_xUseSysCredsCB->set_active( bUse );
150 }
151}
152
154{
155 m_xPasswordED->set_text( OUString() );
156
157 if ( m_xNameED->get_text().isEmpty() )
158 m_xNameED->grab_focus();
159 else
160 m_xPasswordED->grab_focus();
161}
162
164{
165 m_xAccountED->set_text( OUString() );
166 m_xAccountED->grab_focus();
167}
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::Label > m_xErrorInfo
Definition: logindlg.hxx:42
std::unique_ptr< weld::Label > m_xRequestInfo
Definition: logindlg.hxx:43
std::unique_ptr< weld::CheckButton > m_xUseSysCredsCB
Definition: logindlg.hxx:51
std::unique_ptr< weld::Label > m_xErrorFT
Definition: logindlg.hxx:41
void HideControls_Impl(LoginFlags nFlags)
Definition: logindlg.cxx:41
OUString m_server
Definition: logindlg.hxx:53
void SetPassword(const OUString &rNew)
Definition: logindlg.cxx:35
std::unique_ptr< weld::Button > m_xOKBtn
Definition: logindlg.hxx:52
void SetUseSystemCredentials(bool bUse)
Definition: logindlg.cxx:144
void SetRequest()
Definition: logindlg.cxx:82
virtual ~LoginDialog() override
Definition: logindlg.cxx:31
std::unique_ptr< weld::Label > m_xAccountFT
Definition: logindlg.hxx:48
OUString m_realm
Definition: logindlg.hxx:54
void EnableUseSysCredsControls_Impl(bool bUseSysCredsEnabled)
Definition: logindlg.cxx:69
std::unique_ptr< weld::Label > m_xPasswordFT
Definition: logindlg.hxx:46
std::unique_ptr< weld::Entry > m_xPasswordED
Definition: logindlg.hxx:47
std::unique_ptr< weld::Entry > m_xAccountED
Definition: logindlg.hxx:49
void ClearAccount()
Definition: logindlg.cxx:163
std::unique_ptr< weld::Label > m_xNameFT
Definition: logindlg.hxx:44
void ClearPassword()
Definition: logindlg.cxx:153
std::unique_ptr< weld::CheckButton > m_xSavePasswdBtn
Definition: logindlg.hxx:50
std::unique_ptr< weld::Entry > m_xNameED
Definition: logindlg.hxx:45
LoginDialog(weld::Window *pParent, LoginFlags nFlags, OUString aServer, OUString aRealm)
Definition: logindlg.cxx:114
std::unique_ptr< weld::Builder > m_xBuilder
IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl, weld::Button &, void)
Definition: logindlg.cxx:101
#define _MAX_PATH
Definition: logindlg.cxx:26
LoginFlags
Definition: logindlg.hxx:26
OString strip(const OString &rIn, char c)
RET_OK