LibreOffice Module dbaccess (master) 1
ConnectionPage.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 <config_java.h>
21#include "ConnectionPage.hxx"
22#include <core_resource.hxx>
23#include <IItemSetHelper.hxx>
24#include <strings.hrc>
25#include <dsmeta.hxx>
26#if HAVE_FEATURE_JAVA
28#endif
29#include <svl/itemset.hxx>
30#include <svl/stritem.hxx>
31#include <svl/eitem.hxx>
32#include <dsitems.hxx>
33#include <helpids.h>
34#include <sqlmessage.hxx>
35#include <svl/filenotation.hxx>
36#include <com/sun/star/ucb/XProgressHandler.hpp>
38#include <o3tl/string_view.hxx>
39
40namespace dbaui
41{
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::ucb;
44 using namespace ::com::sun::star::ui::dialogs;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::container;
49 using namespace ::dbtools;
50 using namespace ::svt;
51
52 std::unique_ptr<SfxTabPage> OConnectionTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet)
53 {
54 return std::make_unique<OConnectionTabPage>(pPage, pController, *_rAttrSet);
55 }
56
57 // OConnectionTabPage
59 : OConnectionHelper(pPage, pController, "dbaccess/ui/connectionpage.ui", "ConnectionPage", _rCoreAttrs)
60 , m_xFL2(m_xBuilder->weld_label("userlabel"))
61 , m_xUserNameLabel(m_xBuilder->weld_label("userNameLabel"))
62 , m_xUserName(m_xBuilder->weld_entry("userNameEntry"))
63 , m_xPasswordRequired(m_xBuilder->weld_check_button("passCheckbutton"))
64 , m_xFL3(m_xBuilder->weld_label("JDBCLabel"))
65 , m_xJavaDriverLabel(m_xBuilder->weld_label("javaDriverLabel"))
66 , m_xJavaDriver(m_xBuilder->weld_entry("driverEntry"))
67 , m_xTestJavaDriver(m_xBuilder->weld_button("driverButton"))
68 , m_xTestConnection(m_xBuilder->weld_button("connectionButton"))
69 {
70 m_xConnectionURL->connect_changed(LINK(this, OConnectionTabPage, OnEditModified));
71 m_xJavaDriver->connect_changed(LINK(this, OConnectionTabPage, OnEditModified));
72 m_xUserName->connect_changed(LINK(this, OGenericAdministrationPage, OnControlEntryModifyHdl));
73 m_xPasswordRequired->connect_toggled(LINK(this, OGenericAdministrationPage, OnControlModifiedButtonClick));
74
75 m_xTestConnection->connect_clicked(LINK(this,OGenericAdministrationPage,OnTestConnectionButtonClickHdl));
76 m_xTestJavaDriver->connect_clicked(LINK(this,OConnectionTabPage,OnTestJavaClickHdl));
77 }
78
80 {
81 }
82
83 void OConnectionTabPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
84 {
85 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
86 bool bValid, bReadonly;
87 getFlags(_rSet, bValid, bReadonly);
88
90 OConnectionHelper::implInitControls( _rSet, _bSaveValue);
91
93 switch( eType )
94 {
96 m_xFT_Connection->set_label(DBA_RES(STR_DBASE_PATH_OR_FILE));
98 break;
100 m_xFT_Connection->set_label(DBA_RES(STR_FLAT_PATH_OR_FILE));
102 break;
104 m_xFT_Connection->set_label(DBA_RES(STR_CALC_PATH_OR_FILE));
106 break;
108 m_xFT_Connection->set_label(DBA_RES(STR_WRITER_PATH_OR_FILE));
110 break;
112 m_xFT_Connection->set_label(DBA_RES(STR_COMMONURL));
113 break;
116 m_xFT_Connection->set_label(DBA_RES(STR_MSACCESS_MDB_FILE));
118 break;
121 m_xFT_Connection->set_label(DBA_RES(STR_MYSQL_DATABASE_NAME));
123 break;
125 m_xFT_Connection->set_label(DBA_RES(STR_ORACLE_DATABASE_NAME));
127 break;
130 m_xFT_Connection->set_label(DBA_RES(STR_NAME_OF_ODBC_DATASOURCE));
132 break;
134 m_xFT_Connection->set_label(DBA_RES(STR_HOSTNAME));
136 break;
138 m_xFT_Connection->set_label(DBA_RES(STR_MOZILLA_PROFILE_NAME));
140 break;
142 m_xFT_Connection->set_label(DBA_RES(STR_THUNDERBIRD_PROFILE_NAME));
144 break;
152 m_xFT_Connection->set_label(DBA_RES(STR_NO_ADDITIONAL_SETTINGS));
153 {
154 OUString sText = m_xFT_Connection->get_label();
155 sText = sText.replaceAll("%test",m_xTestConnection->get_label());
156 sText = sText.replaceAll("~","");
157 m_xFT_Connection->set_label(sText);
158 }
159 m_xConnectionURL->hide();
160 break;
162 default:
163 m_xFT_Connection->set_label(DBA_RES(STR_COMMONURL));
164 break;
165 }
166
168 bool bShowUserAuthenfication = ( eAuthMode != AuthNone );
169 bool bShowUser = ( eAuthMode == AuthUserPwd );
170
172 m_xFL2->set_visible( bShowUserAuthenfication );
173 m_xUserNameLabel->set_visible( bShowUser && bShowUserAuthenfication );
174 m_xUserName->set_visible( bShowUser && bShowUserAuthenfication );
175 m_xPasswordRequired->set_visible( bShowUserAuthenfication );
176
177 // collect the items
178 const SfxStringItem* pUidItem = _rSet.GetItem<SfxStringItem>(DSID_USER);
179
180 const SfxStringItem* pJdbcDrvItem = _rSet.GetItem<SfxStringItem>(DSID_JDBCDRIVERCLASS);
181 const SfxStringItem* pUrlItem = _rSet.GetItem<SfxStringItem>(DSID_CONNECTURL);
182 const SfxBoolItem* pAllowEmptyPwd = _rSet.GetItem<SfxBoolItem>(DSID_PASSWORDREQUIRED);
183
184 // forward the values to the controls
185 if ( !bValid )
186 return;
187
188 m_xUserName->set_text(pUidItem->GetValue());
189 m_xPasswordRequired->set_active(pAllowEmptyPwd->GetValue());
190
191 const OUString& sUrl = pUrlItem->GetValue();
192 setURL( sUrl );
193
194 const bool bEnableJDBC = m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC;
195 if ( !pJdbcDrvItem->GetValue().getLength() )
196 {
197 OUString sDefaultJdbcDriverName = m_pCollection->getJavaDriverClass(m_eType);
198 if ( !sDefaultJdbcDriverName.isEmpty() )
199 m_xJavaDriver->set_text(sDefaultJdbcDriverName);
200 }
201 else
202 m_xJavaDriver->set_text(pJdbcDrvItem->GetValue());
203
204 m_xJavaDriverLabel->set_visible(bEnableJDBC);
205 m_xJavaDriver->set_visible(bEnableJDBC);
206 m_xTestJavaDriver->set_visible(bEnableJDBC);
207 m_xTestJavaDriver->set_sensitive( !o3tl::trim(m_xJavaDriver->get_text()).empty() );
208 m_xFL3->set_visible(bEnableJDBC);
209
211
212 m_xUserName->save_value();
213 m_xConnectionURL->save_value();
214 m_xJavaDriver->save_value();
215 m_xPasswordRequired->save_state();
216 }
217
219 {
220 bool bChangedSomething = false;
221
222 if (m_xUserName->get_value_changed_from_saved())
223 {
224 _rSet->Put(SfxStringItem(DSID_USER, m_xUserName->get_text()));
225 _rSet->Put(SfxStringItem(DSID_PASSWORD, OUString()));
226 bChangedSomething = true;
227 }
228
229 fillBool(*_rSet,m_xPasswordRequired.get(),DSID_PASSWORDREQUIRED,false, bChangedSomething);
230
232 {
233 fillString(*_rSet,m_xJavaDriver.get(), DSID_JDBCDRIVERCLASS, bChangedSomething);
234 }
235
236 fillString(*_rSet,m_xConnectionURL.get(), DSID_CONNECTURL, bChangedSomething);
237
238 return bChangedSomething;
239 }
241 {
242 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
243 bool bSuccess = false;
244#if HAVE_FEATURE_JAVA
245 try
246 {
247 if ( !o3tl::trim(m_xJavaDriver->get_text()).empty() )
248 {
249 ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() );
250 m_xJavaDriver->set_text(m_xJavaDriver->get_text().trim()); // fdo#68341
251 bSuccess = ::connectivity::existsJavaClassByName(xJVM, o3tl::trim(m_xJavaDriver->get_text()));
252 }
253 }
254 catch(Exception&)
255 {
256 }
257#endif
258
259 TranslateId pMessage = bSuccess ? STR_JDBCDRIVER_SUCCESS : STR_JDBCDRIVER_NO_SUCCESS;
260 const MessageType mt = bSuccess ? MessageType::Info : MessageType::Error;
261 OSQLMessageBox aMsg(GetFrameWeld(), DBA_RES(pMessage), OUString(), MessBoxStyle::Ok | MessBoxStyle::DefaultOk, mt);
262 aMsg.run();
263 }
265 {
266 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
267 bool bEnableTestConnection = !m_xConnectionURL->get_visible() || !m_xConnectionURL->GetTextNoPrefix().isEmpty();
269 bEnableTestConnection = bEnableTestConnection && (!o3tl::trim(m_xJavaDriver->get_text()).empty());
270 m_xTestConnection->set_sensitive(bEnableTestConnection);
271 return true;
272 }
273 IMPL_LINK(OConnectionTabPage, OnEditModified, weld::Entry&, rEdit, void)
274 {
275 if (&rEdit == m_xJavaDriver.get())
276 m_xTestJavaDriver->set_sensitive( !o3tl::trim(m_xJavaDriver->get_text()).empty() );
277
278 checkTestConnection();
279 // tell the listener we were modified
280 callModifiedHdl();
281 }
282} // namespace dbaui
283
284/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetValue() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
DATASOURCE_TYPE determineType(std::u16string_view _rDsn) const
Definition: dsntypes.cxx:299
OUString getJavaDriverClass(std::u16string_view _sURL) const
on a given string, return the Java Driver Class
Definition: dsntypes.cxx:243
static AuthenticationMode getAuthentication(const OUString &_sURL)
determines whether or not the data source requires authentication
Definition: dsmeta.cxx:158
virtual OUString getDatasourceType(const SfxItemSet &_rSet) const =0
virtual void implInitControls(const SfxItemSet &_rSet, bool _bSaveValue) override
called from within Reset and ActivatePage, use to initialize the controls with the items from the giv...
std::unique_ptr< weld::Label > m_xFT_Connection
the DSN type collection instance
std::unique_ptr< OConnectionURLEdit > m_xConnectionURL
::dbaccess::ODsnTypeCollection * m_pCollection
std::unique_ptr< weld::Button > m_xPB_Connection
void setURL(std::u16string_view _rURL)
implements the connection page of the data source properties dialog.
std::unique_ptr< weld::Label > m_xJavaDriverLabel
std::unique_ptr< weld::Button > m_xTestJavaDriver
std::unique_ptr< weld::Entry > m_xJavaDriver
virtual void implInitControls(const SfxItemSet &_rSet, bool _bSaveValue) override
called from within Reset and ActivatePage, use to initialize the controls with the items from the giv...
virtual bool checkTestConnection() override
changes the connection URL.
std::unique_ptr< weld::Label > m_xFL2
virtual ~OConnectionTabPage() override
std::unique_ptr< weld::CheckButton > m_xPasswordRequired
OConnectionTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &_rCoreAttrs)
std::unique_ptr< weld::Label > m_xUserNameLabel
std::unique_ptr< weld::Label > m_xFL3
std::unique_ptr< weld::Button > m_xTestConnection
virtual bool FillItemSet(SfxItemSet *_rCoreAttrs) override
std::unique_ptr< weld::Entry > m_xUserName
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *_rAttrSet)
static void getFlags(const SfxItemSet &_rSet, bool &_rValid, bool &_rReadonly)
analyze the invalid and the readonly flag which may be present in the set
Definition: adminpages.cxx:93
IDatabaseSettingsDialog * m_pAdminDialog
Definition: adminpages.hxx:94
static void fillString(SfxItemSet &_rSet, const weld::Entry *pEdit, TypedWhichId< SfxStringItem > _nID, bool &_bChangedSomething)
fills the String value into the item set when the value changed.
Definition: adminpages.cxx:219
static void fillBool(SfxItemSet &_rSet, const weld::CheckButton *pCheckBox, sal_uInt16 _nID, bool bOptionalBool, bool &_bChangedSomething, bool _bRevertValue=false)
fills the Boolean value into the item set when the value changed.
Definition: adminpages.cxx:190
virtual short run()
#define DBA_RES(id)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
#define DSID_PASSWORD
Definition: dsitems.hxx:42
#define DSID_CONNECTURL
Definition: dsitems.hxx:36
#define DSID_JDBCDRIVERCLASS
Definition: dsitems.hxx:48
#define DSID_USER
Definition: dsitems.hxx:41
#define DSID_PASSWORDREQUIRED
Definition: dsitems.hxx:45
OUString eType
Definition: generalpage.cxx:78
constexpr OUStringLiteral HID_DSADMIN_ORACLE_DATABASE
Definition: helpids.h:84
constexpr OUStringLiteral HID_DSADMIN_MYSQL_DATABASE
Definition: helpids.h:77
constexpr OUStringLiteral HID_DSADMIN_MOZILLA_PROFILE_NAME
Definition: helpids.h:68
constexpr OUStringLiteral HID_DSADMIN_MYSQL_ODBC_DATASOURCE
Definition: helpids.h:78
constexpr OUStringLiteral HID_DSADMIN_MSACCESS_MDB_FILE
Definition: helpids.h:80
constexpr OUStringLiteral HID_DSADMIN_LDAP_HOSTNAME
Definition: helpids.h:67
constexpr OUStringLiteral HID_DSADMIN_ODBC_DATASOURCE
Definition: helpids.h:79
constexpr OUStringLiteral HID_DSADMIN_WRITER_PATH
Definition: helpids.h:83
constexpr OUStringLiteral HID_DSADMIN_FLAT_PATH
Definition: helpids.h:81
constexpr OUStringLiteral HID_DSADMIN_THUNDERBIRD_PROFILE_NAME
Definition: helpids.h:69
constexpr OUStringLiteral HID_DSADMIN_CALC_PATH
Definition: helpids.h:82
constexpr OUStringLiteral HID_DSADMIN_DBASE_PATH
Definition: helpids.h:76
constexpr OUStringLiteral HID_DSADMIN_BROWSECONN
Definition: helpids.h:29
@ Exception
DATASOURCE_TYPE
known datasource types
Definition: dsntypes.hxx:36
@ DST_MSACCESS_2007
Definition: dsntypes.hxx:58
@ DST_MYSQL_JDBC
Definition: dsntypes.hxx:39
@ DST_CALC
Definition: dsntypes.hxx:42
@ DST_WRITER
Definition: dsntypes.hxx:65
@ DST_MOZILLA
Definition: dsntypes.hxx:48
@ DST_EVOLUTION
Definition: dsntypes.hxx:53
@ DST_MSACCESS
Definition: dsntypes.hxx:37
@ DST_MYSQL_ODBC
Definition: dsntypes.hxx:38
@ DST_JDBC
Definition: dsntypes.hxx:45
@ DST_ODBC
Definition: dsntypes.hxx:46
@ DST_MYSQL_NATIVE
Definition: dsntypes.hxx:60
@ DST_LDAP
Definition: dsntypes.hxx:50
@ DST_DBASE
Definition: dsntypes.hxx:43
@ DST_FLAT
Definition: dsntypes.hxx:44
@ DST_OUTLOOKEXP
Definition: dsntypes.hxx:52
@ DST_ORACLE_JDBC
Definition: dsntypes.hxx:40
@ DST_EVOLUTION_GROUPWISE
Definition: dsntypes.hxx:54
@ DST_OUTLOOK
Definition: dsntypes.hxx:51
@ DST_EVOLUTION_LDAP
Definition: dsntypes.hxx:55
@ DST_THUNDERBIRD
Definition: dsntypes.hxx:49
@ DST_MACAB
Definition: dsntypes.hxx:57
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
AuthenticationMode
Definition: dsmeta.hxx:37
@ AuthNone
Definition: dsmeta.hxx:38
@ AuthUserPwd
Definition: dsmeta.hxx:39
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)