1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include "logindlg.hxx"
26 #define _MAX_PATH PATH_MAX
29 using namespace com::sun::star
;
31 LoginDialog::~LoginDialog()
35 void LoginDialog::SetPassword( const OUString
& rNew
)
37 m_xPasswordED
->set_text( rNew
);
41 void LoginDialog::HideControls_Impl( LoginFlags nFlags
)
43 if ( nFlags
& LoginFlags::UsernameReadonly
)
45 m_xNameED
->set_sensitive( false );
48 if ( nFlags
& LoginFlags::NoSavePassword
)
49 m_xSavePasswdBtn
->hide();
51 if ( nFlags
& LoginFlags::NoErrorText
)
57 if ( nFlags
& LoginFlags::NoAccount
)
63 if ( nFlags
& LoginFlags::NoUseSysCreds
)
65 m_xUseSysCredsCB
->hide();
69 void LoginDialog::EnableUseSysCredsControls_Impl( bool bUseSysCredsset_sensitived
)
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
);
82 void LoginDialog::SetRequest()
84 bool oldPwd
= !m_xPasswordED
->get_text().isEmpty();
86 if (m_xAccountFT
->get_visible() && !m_realm
.isEmpty())
88 std::unique_ptr
<weld::Label
> xText(m_xBuilder
->weld_label(oldPwd
? "wrongloginrealm" : "loginrealm"));
89 aRequest
= xText
->get_label();
90 aRequest
= aRequest
.replaceAll("%2", m_realm
);
94 std::unique_ptr
<weld::Label
> xText(m_xBuilder
->weld_label(oldPwd
? "wrongrequestinfo" : "requestinfo"));
95 aRequest
= xText
->get_label();
97 aRequest
= aRequest
.replaceAll("%1", m_server
);
98 m_xRequestInfo
->set_label(aRequest
);
101 IMPL_LINK_NOARG(LoginDialog
, OKHdl_Impl
, weld::Button
&, void)
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
);
109 IMPL_LINK_NOARG(LoginDialog
, UseSysCredsHdl_Impl
, weld::Toggleable
&, void)
111 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB
->get_active() );
114 LoginDialog::LoginDialog(weld::Window
* pParent
, LoginFlags nFlags
,
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
))
131 if ( !( nFlags
& LoginFlags::NoUseSysCreds
) )
132 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB
->get_active() );
136 m_xNameED
->set_max_length( _MAX_PATH
);
138 m_xOKBtn
->connect_clicked( LINK( this, LoginDialog
, OKHdl_Impl
) );
139 m_xUseSysCredsCB
->connect_toggled( LINK( this, LoginDialog
, UseSysCredsHdl_Impl
) );
141 HideControls_Impl( nFlags
);
144 void LoginDialog::SetUseSystemCredentials( bool bUse
)
146 if ( m_xUseSysCredsCB
->get_visible() )
148 m_xUseSysCredsCB
->set_active( bUse
);
149 EnableUseSysCredsControls_Impl( bUse
);
153 void LoginDialog::ClearPassword()
155 m_xPasswordED
->set_text( OUString() );
157 if ( m_xNameED
->get_text().isEmpty() )
158 m_xNameED
->grab_focus();
160 m_xPasswordED
->grab_focus();
163 void LoginDialog::ClearAccount()
165 m_xAccountED
->set_text( OUString() );
166 m_xAccountED
->grab_focus();
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */