Line data Source code
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_features.h>
21 : #include "ConnectionPage.hxx"
22 : #include "dbu_dlg.hrc"
23 : #include "dsmeta.hxx"
24 : #if HAVE_FEATURE_JAVA
25 : #include <jvmaccess/virtualmachine.hxx>
26 : #endif
27 : #include <svl/itemset.hxx>
28 : #include <unotools/pathoptions.hxx>
29 : #include <svl/stritem.hxx>
30 : #include <svl/eitem.hxx>
31 : #include <svl/intitem.hxx>
32 : #include <unotools/moduleoptions.hxx>
33 : #include "dsitems.hxx"
34 : #include "dbaccess_helpid.hrc"
35 : #include "localresaccess.hxx"
36 : #include <osl/process.h>
37 : #include <vcl/msgbox.hxx>
38 : #include "dbadmin.hxx"
39 : #include <comphelper/types.hxx>
40 : #include <vcl/stdtext.hxx>
41 : #include "sqlmessage.hxx"
42 : #include "odbcconfig.hxx"
43 : #include "dsselect.hxx"
44 : #include <svl/filenotation.hxx>
45 : #include "dbustrings.hrc"
46 : #include <com/sun/star/sdbc/XRow.hpp>
47 : #include <com/sun/star/awt/XWindow.hpp>
48 : #include <com/sun/star/task/XInteractionHandler.hpp>
49 : #include <com/sun/star/ucb/XProgressHandler.hpp>
50 : #include <com/sun/star/sdbc/XConnection.hpp>
51 : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
52 : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
53 : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
54 : #include "UITools.hxx"
55 : #include <unotools/localfilehelper.hxx>
56 : #include <unotools/ucbhelper.hxx>
57 : #include <ucbhelper/commandenvironment.hxx>
58 : #include "finteraction.hxx"
59 : #include <connectivity/CommonTools.hxx>
60 : #include <sfx2/docfilt.hxx>
61 : #include "dsnItem.hxx"
62 : #if defined(WNT)
63 : #define _ADO_DATALINK_BROWSE_
64 : #endif
65 :
66 : #ifdef _ADO_DATALINK_BROWSE_
67 : #include <vcl/sysdata.hxx>
68 : #include "adodatalinks.hxx"
69 : #endif //_ADO_DATALINK_BROWSE_
70 :
71 :
72 : namespace dbaui
73 : {
74 : using namespace ::com::sun::star::uno;
75 : using namespace ::com::sun::star::ucb;
76 : using namespace ::com::sun::star::ui::dialogs;
77 : using namespace ::com::sun::star::sdbc;
78 : using namespace ::com::sun::star::beans;
79 : using namespace ::com::sun::star::lang;
80 : using namespace ::com::sun::star::container;
81 : using namespace ::dbtools;
82 : using namespace ::svt;
83 :
84 0 : VclPtr<SfxTabPage> OConnectionTabPage::Create( vcl::Window* pParent, const SfxItemSet* _rAttrSet )
85 : {
86 0 : return VclPtr<OConnectionTabPage>::Create( pParent, *_rAttrSet );
87 : }
88 :
89 : // OConnectionTabPage
90 0 : OConnectionTabPage::OConnectionTabPage(vcl::Window* pParent, const SfxItemSet& _rCoreAttrs)
91 0 : :OConnectionHelper(pParent, "ConnectionPage", "dbaccess/ui/connectionpage.ui", _rCoreAttrs)
92 : {
93 0 : get(m_pFL2, "userlabel");
94 0 : get(m_pUserNameLabel, "userNameLabel");
95 0 : get(m_pUserName, "userNameEntry");
96 0 : get(m_pPasswordRequired, "passCheckbutton");
97 0 : get(m_pFL3, "JDBCLabel");
98 0 : get(m_pJavaDriverLabel, "javaDriverLabel");
99 0 : get(m_pJavaDriver, "driverEntry");
100 0 : get(m_pTestJavaDriver, "driverButton");
101 0 : get(m_pTestConnection, "connectionButton");
102 :
103 0 : m_pConnectionURL->SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
104 0 : m_pJavaDriver->SetModifyHdl(getControlModifiedLink());
105 0 : m_pJavaDriver->SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified));
106 0 : m_pUserName->SetModifyHdl(getControlModifiedLink());
107 0 : m_pPasswordRequired->SetClickHdl(getControlModifiedLink());
108 :
109 0 : m_pTestConnection->SetClickHdl(LINK(this,OGenericAdministrationPage,OnTestConnectionClickHdl));
110 0 : m_pTestJavaDriver->SetClickHdl(LINK(this,OConnectionTabPage,OnTestJavaClickHdl));
111 0 : }
112 :
113 0 : OConnectionTabPage::~OConnectionTabPage()
114 : {
115 0 : disposeOnce();
116 0 : }
117 :
118 0 : void OConnectionTabPage::dispose()
119 : {
120 0 : m_pFL2.clear();
121 0 : m_pUserNameLabel.clear();
122 0 : m_pUserName.clear();
123 0 : m_pPasswordRequired.clear();
124 0 : m_pFL3.clear();
125 0 : m_pJavaDriverLabel.clear();
126 0 : m_pJavaDriver.clear();
127 0 : m_pTestJavaDriver.clear();
128 0 : m_pTestConnection.clear();
129 0 : OConnectionHelper::dispose();
130 0 : }
131 :
132 0 : void OConnectionTabPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
133 : {
134 : // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
135 : bool bValid, bReadonly;
136 0 : getFlags(_rSet, bValid, bReadonly);
137 :
138 0 : m_eType = m_pAdminDialog->getDatasourceType(_rSet);
139 0 : OConnectionHelper::implInitControls( _rSet, _bSaveValue);
140 :
141 0 : ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType);
142 0 : switch( eType )
143 : {
144 : case ::dbaccess::DST_DBASE:
145 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_DBASE_PATH_OR_FILE)));
146 0 : m_pConnectionURL->SetHelpId(HID_DSADMIN_DBASE_PATH);
147 0 : break;
148 : case ::dbaccess::DST_FLAT:
149 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_FLAT_PATH_OR_FILE)));
150 0 : m_pConnectionURL->SetHelpId(HID_DSADMIN_FLAT_PATH);
151 0 : break;
152 : case ::dbaccess::DST_CALC:
153 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_CALC_PATH_OR_FILE)));
154 0 : m_pConnectionURL->SetHelpId(HID_DSADMIN_CALC_PATH);
155 0 : break;
156 : case ::dbaccess::DST_ADO:
157 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_COMMONURL)));
158 0 : break;
159 : case ::dbaccess::DST_MSACCESS:
160 : case ::dbaccess::DST_MSACCESS_2007:
161 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_MSACCESS_MDB_FILE)));
162 0 : m_pConnectionURL->SetHelpId(HID_DSADMIN_MSACCESS_MDB_FILE);
163 0 : break;
164 : case ::dbaccess::DST_MYSQL_NATIVE:
165 : case ::dbaccess::DST_MYSQL_JDBC:
166 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_MYSQL_DATABASE_NAME)));
167 0 : m_pConnectionURL->SetHelpId( HID_DSADMIN_MYSQL_DATABASE );
168 0 : break;
169 : case ::dbaccess::DST_ORACLE_JDBC:
170 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_ORACLE_DATABASE_NAME)));
171 0 : m_pConnectionURL->SetHelpId(HID_DSADMIN_ORACLE_DATABASE);
172 0 : break;
173 : case ::dbaccess::DST_MYSQL_ODBC:
174 : case ::dbaccess::DST_ODBC:
175 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_NAME_OF_ODBC_DATASOURCE)));
176 0 : m_pConnectionURL->SetHelpId( eType == ::dbaccess::DST_MYSQL_ODBC ? HID_DSADMIN_MYSQL_ODBC_DATASOURCE : HID_DSADMIN_ODBC_DATASOURCE);
177 0 : break;
178 : case ::dbaccess::DST_LDAP:
179 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_HOSTNAME)));
180 0 : m_pConnectionURL->SetHelpId( HID_DSADMIN_LDAP_HOSTNAME );
181 0 : break;
182 : case ::dbaccess::DST_MOZILLA:
183 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_MOZILLA_PROFILE_NAME)));
184 0 : m_pConnectionURL->SetHelpId( HID_DSADMIN_MOZILLA_PROFILE_NAME );
185 0 : break;
186 : case ::dbaccess::DST_THUNDERBIRD:
187 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_THUNDERBIRD_PROFILE_NAME)));
188 0 : m_pConnectionURL->SetHelpId( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME );
189 0 : break;
190 : case ::dbaccess::DST_OUTLOOK:
191 : case ::dbaccess::DST_OUTLOOKEXP:
192 : case ::dbaccess::DST_EVOLUTION:
193 : case ::dbaccess::DST_EVOLUTION_GROUPWISE:
194 : case ::dbaccess::DST_EVOLUTION_LDAP:
195 : case ::dbaccess::DST_KAB:
196 : case ::dbaccess::DST_MACAB:
197 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_NO_ADDITIONAL_SETTINGS)));
198 : {
199 0 : OUString sText = m_pFT_Connection->GetText();
200 0 : sText = sText.replaceAll("%test",m_pTestConnection->GetText());
201 0 : OUString sTemp;
202 0 : sText = sText.replaceAll("~",sTemp);
203 0 : m_pFT_Connection->SetText(sText);
204 : }
205 0 : m_pConnectionURL->Hide();
206 0 : break;
207 : case ::dbaccess::DST_JDBC:
208 : default:
209 0 : m_pFT_Connection->SetText(OUString(ModuleRes(STR_COMMONURL)));
210 0 : break;
211 : }
212 :
213 : ;
214 0 : AuthenticationMode eAuthMode( DataSourceMetaData::getAuthentication( m_eType ) );
215 0 : bool bShowUserAuthenfication = ( eAuthMode != AuthNone );
216 0 : bool bShowUser = ( eAuthMode == AuthUserPwd );
217 :
218 0 : m_pPB_Connection->SetHelpId(HID_DSADMIN_BROWSECONN);
219 0 : m_pFL2->Show( bShowUserAuthenfication );
220 0 : m_pUserNameLabel->Show( bShowUser && bShowUserAuthenfication );
221 0 : m_pUserName->Show( bShowUser && bShowUserAuthenfication );
222 0 : m_pPasswordRequired->Show( bShowUserAuthenfication );
223 0 : if ( !bShowUser && bShowUserAuthenfication )
224 0 : m_pPasswordRequired->SetPosPixel(m_pUserNameLabel->GetPosPixel());
225 :
226 : // collect the items
227 0 : SFX_ITEMSET_GET(_rSet, pUidItem, SfxStringItem, DSID_USER, true);
228 :
229 0 : SFX_ITEMSET_GET(_rSet, pJdbcDrvItem, SfxStringItem, DSID_JDBCDRIVERCLASS, true);
230 0 : SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, true);
231 0 : SFX_ITEMSET_GET(_rSet, pAllowEmptyPwd, SfxBoolItem, DSID_PASSWORDREQUIRED, true);
232 :
233 : // forward the values to the controls
234 0 : if ( bValid )
235 : {
236 0 : m_pUserName->SetText(pUidItem->GetValue());
237 0 : m_pPasswordRequired->Check(pAllowEmptyPwd->GetValue());
238 :
239 0 : OUString sUrl = pUrlItem->GetValue();
240 0 : setURL( sUrl );
241 :
242 0 : const bool bEnableJDBC = m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC;
243 0 : if ( !pJdbcDrvItem->GetValue().getLength() )
244 : {
245 0 : OUString sDefaultJdbcDriverName = m_pCollection->getJavaDriverClass(m_eType);
246 0 : if ( !sDefaultJdbcDriverName.isEmpty() )
247 : {
248 0 : m_pJavaDriver->SetText(sDefaultJdbcDriverName);
249 0 : m_pJavaDriver->SetModifyFlag();
250 0 : }
251 : }
252 : else
253 0 : m_pJavaDriver->SetText(pJdbcDrvItem->GetValue());
254 :
255 0 : m_pJavaDriverLabel->Show(bEnableJDBC);
256 0 : m_pJavaDriver->Show(bEnableJDBC);
257 0 : m_pTestJavaDriver->Show(bEnableJDBC);
258 0 : m_pTestJavaDriver->Enable( !m_pJavaDriver->GetText().trim().isEmpty() );
259 0 : m_pFL3->Show(bEnableJDBC);
260 :
261 0 : checkTestConnection();
262 :
263 0 : m_pUserName->ClearModifyFlag();
264 0 : m_pConnectionURL->ClearModifyFlag();
265 0 : m_pJavaDriver->ClearModifyFlag();
266 : }
267 0 : }
268 :
269 0 : bool OConnectionTabPage::FillItemSet(SfxItemSet* _rSet)
270 : {
271 0 : bool bChangedSomething = false;
272 :
273 0 : if (m_pUserName->IsValueChangedFromSaved())
274 : {
275 0 : _rSet->Put(SfxStringItem(DSID_USER, m_pUserName->GetText()));
276 0 : _rSet->Put(SfxStringItem(DSID_PASSWORD, OUString()));
277 0 : bChangedSomething = true;
278 : }
279 :
280 0 : fillBool(*_rSet,m_pPasswordRequired,DSID_PASSWORDREQUIRED,bChangedSomething);
281 :
282 0 : if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
283 : {
284 0 : fillString(*_rSet,m_pJavaDriver, DSID_JDBCDRIVERCLASS, bChangedSomething);
285 : }
286 :
287 0 : fillString(*_rSet,m_pConnectionURL, DSID_CONNECTURL, bChangedSomething);
288 :
289 0 : return bChangedSomething;
290 : }
291 0 : IMPL_LINK(OConnectionTabPage, OnTestJavaClickHdl, PushButton*, /*_pButton*/)
292 : {
293 : OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
294 0 : bool bSuccess = false;
295 : #if HAVE_FEATURE_JAVA
296 : try
297 : {
298 0 : if ( !m_pJavaDriver->GetText().trim().isEmpty() )
299 : {
300 0 : ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() );
301 0 : m_pJavaDriver->SetText(m_pJavaDriver->GetText().trim()); // fdo#68341
302 0 : bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_pJavaDriver->GetText().trim());
303 : }
304 : }
305 0 : catch(Exception&)
306 : {
307 : }
308 : #endif
309 :
310 0 : const sal_uInt16 nMessage = bSuccess ? STR_JDBCDRIVER_SUCCESS : STR_JDBCDRIVER_NO_SUCCESS;
311 0 : const OSQLMessageBox::MessageType mt = bSuccess ? OSQLMessageBox::Info : OSQLMessageBox::Error;
312 0 : ScopedVclPtrInstance< OSQLMessageBox > aMsg( this, OUString( ModuleRes( nMessage ) ), OUString(), WB_OK | WB_DEF_OK, mt );
313 0 : aMsg->Execute();
314 0 : return 0L;
315 : }
316 0 : bool OConnectionTabPage::checkTestConnection()
317 : {
318 : OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
319 0 : bool bEnableTestConnection = !m_pConnectionURL->IsVisible() || !m_pConnectionURL->GetTextNoPrefix().isEmpty();
320 0 : if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC )
321 0 : bEnableTestConnection = bEnableTestConnection && (!m_pJavaDriver->GetText().trim().isEmpty());
322 0 : m_pTestConnection->Enable(bEnableTestConnection);
323 0 : return true;
324 : }
325 0 : IMPL_LINK(OConnectionTabPage, OnEditModified, Edit*, _pEdit)
326 : {
327 0 : if ( _pEdit == m_pJavaDriver )
328 0 : m_pTestJavaDriver->Enable( !m_pJavaDriver->GetText().trim().isEmpty() );
329 :
330 0 : checkTestConnection();
331 : // tell the listener we were modified
332 0 : callModifiedHdl();
333 0 : return 0L;
334 : }
335 36 : } // namespace dbaui
336 :
337 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|