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>
21 #include "logindlg.hxx"
23 #include <strings.hrc>
24 #include <osl/file.hxx>
28 #define _MAX_PATH PATH_MAX
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
);
46 void LoginDialog::HideControls_Impl( LoginFlags nFlags
)
48 if ( nFlags
& LoginFlags::UsernameReadonly
)
50 m_xNameED
->set_sensitive( false );
53 if ( nFlags
& LoginFlags::NoSavePassword
)
54 m_xSavePasswdBtn
->hide();
56 if ( nFlags
& LoginFlags::NoErrorText
)
62 if ( nFlags
& LoginFlags::NoAccount
)
68 if ( nFlags
& LoginFlags::NoUseSysCreds
)
70 m_xUseSysCredsCB
->hide();
74 void LoginDialog::EnableUseSysCredsControls_Impl( bool bUseSysCredsset_sensitived
)
76 m_xErrorInfo
->set_sensitive( !bUseSysCredsset_sensitived
);
77 m_xErrorFT
->set_sensitive( !bUseSysCredsset_sensitived
);
78 m_xRequestInfo
->set_sensitive( !bUseSysCredsset_sensitived
);
79 m_xNameFT
->set_sensitive( !bUseSysCredsset_sensitived
);
80 m_xNameED
->set_sensitive( !bUseSysCredsset_sensitived
);
81 m_xPasswordFT
->set_sensitive( !bUseSysCredsset_sensitived
);
82 m_xPasswordED
->set_sensitive( !bUseSysCredsset_sensitived
);
83 m_xAccountFT
->set_sensitive( !bUseSysCredsset_sensitived
);
84 m_xAccountED
->set_sensitive( !bUseSysCredsset_sensitived
);
87 void LoginDialog::SetRequest()
89 bool oldPwd
= !m_xPasswordED
->get_text().isEmpty();
91 if (m_xAccountFT
->get_visible() && !m_realm
.isEmpty())
93 std::unique_ptr
<weld::Label
> xText(m_xBuilder
->weld_label(oldPwd
? "wrongloginrealm" : "loginrealm"));
94 aRequest
= xText
->get_label();
95 aRequest
= aRequest
.replaceAll("%2", m_realm
);
99 std::unique_ptr
<weld::Label
> xText(m_xBuilder
->weld_label(oldPwd
? "wrongrequestinfo" : "requestinfo"));
100 aRequest
= xText
->get_label();
102 aRequest
= aRequest
.replaceAll("%1", m_server
);
103 m_xRequestInfo
->set_label(aRequest
);
106 IMPL_LINK_NOARG(LoginDialog
, OKHdl_Impl
, weld::Button
&, void)
109 m_xNameED
->set_text(comphelper::string::strip(m_xNameED
->get_text(), ' '));
110 m_xPasswordED
->set_text(comphelper::string::strip(m_xPasswordED
->get_text(), ' '));
111 m_xDialog
->response(RET_OK
);
114 IMPL_LINK_NOARG(LoginDialog
, UseSysCredsHdl_Impl
, weld::Button
&, void)
116 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB
->get_active() );
119 LoginDialog::LoginDialog(weld::Window
* pParent
, LoginFlags nFlags
,
120 const OUString
& rServer
, const OUString
& rRealm
)
121 : GenericDialogController(pParent
, "uui/ui/logindialog.ui", "LoginDialog")
122 , m_xErrorFT(m_xBuilder
->weld_label("errorft"))
123 , m_xErrorInfo(m_xBuilder
->weld_label("errorinfo"))
124 , m_xRequestInfo(m_xBuilder
->weld_label("requestinfo"))
125 , m_xNameFT(m_xBuilder
->weld_label("nameft"))
126 , m_xNameED(m_xBuilder
->weld_entry("nameed"))
127 , m_xPasswordFT(m_xBuilder
->weld_label("passwordft"))
128 , m_xPasswordED(m_xBuilder
->weld_entry("passworded"))
129 , m_xAccountFT(m_xBuilder
->weld_label("accountft"))
130 , m_xAccountED(m_xBuilder
->weld_entry("accounted"))
131 , m_xSavePasswdBtn(m_xBuilder
->weld_check_button("remember"))
132 , m_xUseSysCredsCB(m_xBuilder
->weld_check_button("syscreds"))
133 , m_xOKBtn(m_xBuilder
->weld_button("ok"))
134 , m_server(rServer
), m_realm(rRealm
)
136 if ( !( nFlags
& LoginFlags::NoUseSysCreds
) )
137 EnableUseSysCredsControls_Impl( m_xUseSysCredsCB
->get_active() );
141 m_xNameED
->set_max_length( _MAX_PATH
);
143 m_xOKBtn
->connect_clicked( LINK( this, LoginDialog
, OKHdl_Impl
) );
144 m_xUseSysCredsCB
->connect_clicked( LINK( this, LoginDialog
, UseSysCredsHdl_Impl
) );
146 HideControls_Impl( nFlags
);
149 void LoginDialog::SetUseSystemCredentials( bool bUse
)
151 if ( m_xUseSysCredsCB
->get_visible() )
153 m_xUseSysCredsCB
->set_active( bUse
);
154 EnableUseSysCredsControls_Impl( bUse
);
158 void LoginDialog::ClearPassword()
160 m_xPasswordED
->set_text( OUString() );
162 if ( m_xNameED
->get_text().isEmpty() )
163 m_xNameED
->grab_focus();
165 m_xPasswordED
->grab_focus();
168 void LoginDialog::ClearAccount()
170 m_xAccountED
->set_text( OUString() );
171 m_xAccountED
->grab_focus();
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */