1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "ConnectionPage.hxx"
31 #include "ConnectionPage.hrc"
32 #include "dbu_dlg.hrc"
34 #include <svl/itemset.hxx>
35 #include <unotools/pathoptions.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/eitem.hxx>
38 #include <svl/intitem.hxx>
39 #include <unotools/moduleoptions.hxx>
40 #include "dsitems.hxx"
41 #include "dbaccess_helpid.hrc"
42 #include "localresaccess.hxx"
43 #include <osl/process.h>
44 #include <vcl/msgbox.hxx>
45 #include "dbadmin.hxx"
46 #include <comphelper/types.hxx>
47 #include <vcl/stdtext.hxx>
48 #include "sqlmessage.hxx"
49 #include "odbcconfig.hxx"
50 #include "dsselect.hxx"
51 #include <svl/filenotation.hxx>
52 #include "dbustrings.hrc"
53 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
54 #include <com/sun/star/sdbc/XRow.hpp>
55 #include <com/sun/star/awt/XWindow.hpp>
56 #include <com/sun/star/task/XInteractionHandler.hpp>
57 #include <com/sun/star/ucb/XProgressHandler.hpp>
58 #include <com/sun/star/sdbc/XConnection.hpp>
59 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
60 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
61 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
62 #include "UITools.hxx"
63 #include <unotools/localfilehelper.hxx>
64 #include <unotools/ucbhelper.hxx>
65 #include <ucbhelper/commandenvironment.hxx>
66 #include "finteraction.hxx"
67 #include <connectivity/CommonTools.hxx>
68 #include <sfx2/docfilt.hxx>
69 #include "dsnItem.hxx"
71 #define _ADO_DATALINK_BROWSE_
74 #ifdef _ADO_DATALINK_BROWSE_
75 #include <vcl/sysdata.hxx>
76 #include "adodatalinks.hxx"
77 #endif //_ADO_DATALINK_BROWSE_
79 #include "AutoControls.hrc"
81 //.........................................................................
84 //.........................................................................
85 using namespace ::com::sun::star::uno
;
86 using namespace ::com::sun::star::ucb
;
87 using namespace ::com::sun::star::ui::dialogs
;
88 using namespace ::com::sun::star::sdbc
;
89 using namespace ::com::sun::star::beans
;
90 using namespace ::com::sun::star::lang
;
91 using namespace ::com::sun::star::container
;
92 using namespace ::dbtools
;
93 using namespace ::svt
;
95 SfxTabPage
* OConnectionTabPage::Create( Window
* pParent
, const SfxItemSet
& _rAttrSet
)
97 return ( new OConnectionTabPage( pParent
, _rAttrSet
) );
99 //========================================================================
100 //= OConnectionTabPage
101 //========================================================================
102 DBG_NAME(OConnectionTabPage
)
103 OConnectionTabPage::OConnectionTabPage(Window
* pParent
, const SfxItemSet
& _rCoreAttrs
)
104 :OConnectionHelper(pParent
, ModuleRes(PAGE_CONNECTION
), _rCoreAttrs
)
105 ,m_bUserGrabFocus(sal_True
)
106 ,m_aFL1(this, ModuleRes(FL_SEPARATOR1
))
107 ,m_aFL2(this, ModuleRes(FL_SEPARATOR2
))
108 ,m_aUserNameLabel(this, ModuleRes(FT_USERNAME
))
109 ,m_aUserName(this, ModuleRes(ET_USERNAME
))
110 ,m_aPasswordRequired(this, ModuleRes(CB_PASSWORD_REQUIRED
))
111 ,m_aFL3(this, ModuleRes(FL_SEPARATOR3
))
112 ,m_aJavaDriverLabel(this, ModuleRes(FT_JDBCDRIVERCLASS
))
113 ,m_aJavaDriver(this, ModuleRes(ET_JDBCDRIVERCLASS
))
114 ,m_aTestJavaDriver(this, ModuleRes(PB_TESTDRIVERCLASS
))
115 ,m_aTestConnection(this, ModuleRes(PB_TESTCONNECTION
))
117 DBG_CTOR(OConnectionTabPage
,NULL
);
118 m_aConnectionURL
.SetModifyHdl(LINK(this, OConnectionTabPage
, OnEditModified
));
119 m_aJavaDriver
.SetModifyHdl(getControlModifiedLink());
120 m_aJavaDriver
.SetModifyHdl(LINK(this, OConnectionTabPage
, OnEditModified
));
121 m_aUserName
.SetModifyHdl(getControlModifiedLink());
122 m_aPasswordRequired
.SetClickHdl(getControlModifiedLink());
124 m_aTestConnection
.SetClickHdl(LINK(this,OGenericAdministrationPage
,OnTestConnectionClickHdl
));
125 m_aTestJavaDriver
.SetClickHdl(LINK(this,OConnectionTabPage
,OnTestJavaClickHdl
));
129 LayoutHelper::fitSizeRightAligned( m_aTestConnection
);
132 // -----------------------------------------------------------------------
133 OConnectionTabPage::~OConnectionTabPage()
135 DBG_DTOR(OConnectionTabPage
,NULL
);
138 // -----------------------------------------------------------------------
139 void OConnectionTabPage::implInitControls(const SfxItemSet
& _rSet
, sal_Bool _bSaveValue
)
141 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
142 sal_Bool bValid
, bReadonly
;
143 getFlags(_rSet
, bValid
, bReadonly
);
145 m_eType
= m_pAdminDialog
->getDatasourceType(_rSet
);
146 OConnectionHelper::implInitControls( _rSet
, _bSaveValue
);
148 LocalResourceAccess
aLocRes( PAGE_CONNECTION
, RSC_TABPAGE
);
149 ::dbaccess::DATASOURCE_TYPE eType
= m_pCollection
->determineType(m_eType
);
152 case ::dbaccess::DST_DBASE
:
153 m_aFT_Connection
.SetText(String(ModuleRes(STR_DBASE_PATH_OR_FILE
)));
154 m_aConnectionURL
.SetHelpId(HID_DSADMIN_DBASE_PATH
);
156 case ::dbaccess::DST_FLAT
:
157 m_aFT_Connection
.SetText(String(ModuleRes(STR_FLAT_PATH_OR_FILE
)));
158 m_aConnectionURL
.SetHelpId(HID_DSADMIN_FLAT_PATH
);
160 case ::dbaccess::DST_CALC
:
161 m_aFT_Connection
.SetText(String(ModuleRes(STR_CALC_PATH_OR_FILE
)));
162 m_aConnectionURL
.SetHelpId(HID_DSADMIN_CALC_PATH
);
164 case ::dbaccess::DST_ADO
:
165 m_aFT_Connection
.SetText(String(ModuleRes(STR_COMMONURL
)));
167 case ::dbaccess::DST_MSACCESS
:
168 case ::dbaccess::DST_MSACCESS_2007
:
169 m_aFT_Connection
.SetText(String(ModuleRes(STR_MSACCESS_MDB_FILE
)));
170 m_aConnectionURL
.SetHelpId(HID_DSADMIN_MSACCESS_MDB_FILE
);
172 case ::dbaccess::DST_MYSQL_NATIVE
:
173 case ::dbaccess::DST_MYSQL_JDBC
:
174 m_aFT_Connection
.SetText(String(ModuleRes(STR_MYSQL_DATABASE_NAME
)));
175 m_aConnectionURL
.SetHelpId( HID_DSADMIN_MYSQL_DATABASE
);
177 case ::dbaccess::DST_ORACLE_JDBC
:
178 m_aFT_Connection
.SetText(String(ModuleRes(STR_ORACLE_DATABASE_NAME
)));
179 m_aConnectionURL
.SetHelpId(HID_DSADMIN_ORACLE_DATABASE
);
181 case ::dbaccess::DST_MYSQL_ODBC
:
182 case ::dbaccess::DST_ODBC
:
183 m_aFT_Connection
.SetText(String(ModuleRes(STR_NAME_OF_ODBC_DATASOURCE
)));
184 m_aConnectionURL
.SetHelpId( eType
== ::dbaccess::DST_MYSQL_ODBC
? HID_DSADMIN_MYSQL_ODBC_DATASOURCE
: HID_DSADMIN_ODBC_DATASOURCE
);
186 case ::dbaccess::DST_LDAP
:
187 m_aFT_Connection
.SetText(String(ModuleRes(STR_HOSTNAME
)));
188 m_aConnectionURL
.SetHelpId( HID_DSADMIN_LDAP_HOSTNAME
);
190 case ::dbaccess::DST_MOZILLA
:
191 m_aFT_Connection
.SetText(String(ModuleRes(STR_MOZILLA_PROFILE_NAME
)));
192 m_aConnectionURL
.SetHelpId( HID_DSADMIN_MOZILLA_PROFILE_NAME
);
194 case ::dbaccess::DST_THUNDERBIRD
:
195 m_aFT_Connection
.SetText(String(ModuleRes(STR_THUNDERBIRD_PROFILE_NAME
)));
196 m_aConnectionURL
.SetHelpId( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME
);
198 case ::dbaccess::DST_OUTLOOK
:
199 case ::dbaccess::DST_OUTLOOKEXP
:
200 case ::dbaccess::DST_EVOLUTION
:
201 case ::dbaccess::DST_EVOLUTION_GROUPWISE
:
202 case ::dbaccess::DST_EVOLUTION_LDAP
:
203 case ::dbaccess::DST_KAB
:
204 case ::dbaccess::DST_MACAB
:
205 m_aFT_Connection
.SetText(String(ModuleRes(STR_NO_ADDITIONAL_SETTINGS
)));
207 String sText
= m_aFT_Connection
.GetText();
208 sText
.SearchAndReplaceAscii("%test",m_aTestConnection
.GetText());
210 sText
.SearchAndReplaceAscii("~",sTemp
);
211 m_aFT_Connection
.SetText(sText
);
213 m_aConnectionURL
.Hide();
215 case ::dbaccess::DST_JDBC
:
217 m_aFT_Connection
.SetText(String(ModuleRes(STR_COMMONURL
)));
222 AuthenticationMode
eAuthMode( DataSourceMetaData::getAuthentication( m_eType
) );
223 bool bShowUserAuthenfication
= ( eAuthMode
!= AuthNone
);
224 bool bShowUser
= ( eAuthMode
== AuthUserPwd
);
226 m_aPB_Connection
.SetHelpId(HID_DSADMIN_BROWSECONN
);
227 m_aFL2
.Show( bShowUserAuthenfication
);
228 m_aUserNameLabel
.Show( bShowUser
&& bShowUserAuthenfication
);
229 m_aUserName
.Show( bShowUser
&& bShowUserAuthenfication
);
230 m_aPasswordRequired
.Show( bShowUserAuthenfication
);
231 if ( !bShowUser
&& bShowUserAuthenfication
)
232 m_aPasswordRequired
.SetPosPixel(m_aUserNameLabel
.GetPosPixel());
235 SFX_ITEMSET_GET(_rSet
, pUidItem
, SfxStringItem
, DSID_USER
, sal_True
);
237 SFX_ITEMSET_GET(_rSet
, pJdbcDrvItem
, SfxStringItem
, DSID_JDBCDRIVERCLASS
, sal_True
);
238 SFX_ITEMSET_GET(_rSet
, pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, sal_True
);
239 SFX_ITEMSET_GET(_rSet
, pAllowEmptyPwd
, SfxBoolItem
, DSID_PASSWORDREQUIRED
, sal_True
);
241 // forward the values to the controls
244 m_aUserName
.SetText(pUidItem
->GetValue());
245 m_aPasswordRequired
.Check(pAllowEmptyPwd
->GetValue());
247 String sUrl
= pUrlItem
->GetValue();
250 const sal_Bool bEnableJDBC
= m_pCollection
->determineType(m_eType
) == ::dbaccess::DST_JDBC
;
251 if ( !pJdbcDrvItem
->GetValue().Len() )
253 String sDefaultJdbcDriverName
= m_pCollection
->getJavaDriverClass(m_eType
);
254 if ( sDefaultJdbcDriverName
.Len() )
256 m_aJavaDriver
.SetText(sDefaultJdbcDriverName
);
257 m_aJavaDriver
.SetModifyFlag();
261 m_aJavaDriver
.SetText(pJdbcDrvItem
->GetValue());
263 m_aJavaDriverLabel
.Show(bEnableJDBC
);
264 m_aJavaDriver
.Show(bEnableJDBC
);
265 m_aTestJavaDriver
.Show(bEnableJDBC
);
266 m_aTestJavaDriver
.Enable( m_aJavaDriver
.GetText().Len() != 0);
267 m_aFL3
.Show(bEnableJDBC
);
269 checkTestConnection();
271 m_aUserName
.ClearModifyFlag();
272 m_aConnectionURL
.ClearModifyFlag();
273 m_aJavaDriver
.ClearModifyFlag();
276 // -----------------------------------------------------------------------
277 void OConnectionTabPage::fillWindows(::std::vector
< ISaveValueWrapper
* >& _rControlList
)
279 _rControlList
.push_back(new ODisableWrapper
<FixedLine
>(&m_aFL1
));
281 _rControlList
.push_back(new ODisableWrapper
<FixedLine
>(&m_aFL2
));
282 _rControlList
.push_back(new ODisableWrapper
<FixedText
>(&m_aJavaDriverLabel
));
283 _rControlList
.push_back(new ODisableWrapper
<PushButton
>(&m_aTestJavaDriver
));
285 _rControlList
.push_back(new ODisableWrapper
<FixedLine
>(&m_aFL3
));
286 _rControlList
.push_back(new ODisableWrapper
<FixedText
>(&m_aUserNameLabel
));
287 _rControlList
.push_back(new ODisableWrapper
<PushButton
>(&m_aTestConnection
));
288 OConnectionHelper::fillWindows(_rControlList
);
291 // -----------------------------------------------------------------------
292 void OConnectionTabPage::fillControls(::std::vector
< ISaveValueWrapper
* >& _rControlList
)
294 _rControlList
.push_back(new OSaveValueWrapper
<Edit
>(&m_aJavaDriver
));
295 _rControlList
.push_back(new OSaveValueWrapper
<Edit
>(&m_aUserName
));
296 _rControlList
.push_back(new OSaveValueWrapper
<CheckBox
>(&m_aPasswordRequired
));
297 OConnectionHelper::fillControls(_rControlList
);
300 // -----------------------------------------------------------------------
301 sal_Bool
OConnectionTabPage::FillItemSet(SfxItemSet
& _rSet
)
303 sal_Bool bChangedSomething
= sal_False
;
305 if (m_aUserName
.GetText() != m_aUserName
.GetSavedValue())
307 _rSet
.Put(SfxStringItem(DSID_USER
, m_aUserName
.GetText()));
308 _rSet
.Put(SfxStringItem(DSID_PASSWORD
, String()));
309 bChangedSomething
= sal_True
;
312 fillBool(_rSet
,&m_aPasswordRequired
,DSID_PASSWORDREQUIRED
,bChangedSomething
);
314 if ( m_pCollection
->determineType(m_eType
) == ::dbaccess::DST_JDBC
)
316 fillString(_rSet
,&m_aJavaDriver
, DSID_JDBCDRIVERCLASS
, bChangedSomething
);
319 fillString(_rSet
,&m_aConnectionURL
, DSID_CONNECTURL
, bChangedSomething
);
321 return bChangedSomething
;
323 // -----------------------------------------------------------------------
324 IMPL_LINK(OConnectionTabPage
, OnTestJavaClickHdl
, PushButton
*, /*_pButton*/)
326 OSL_ENSURE(m_pAdminDialog
,"No Admin dialog set! ->GPF");
327 sal_Bool bSuccess
= sal_False
;
330 if ( m_aJavaDriver
.GetText().Len() )
332 ::rtl::Reference
< jvmaccess::VirtualMachine
> xJVM
= ::connectivity::getJavaVM(m_pAdminDialog
->getORB());
333 bSuccess
= ::connectivity::existsJavaClassByName(xJVM
,m_aJavaDriver
.GetText());
340 const sal_uInt16 nMessage
= bSuccess
? STR_JDBCDRIVER_SUCCESS
: STR_JDBCDRIVER_NO_SUCCESS
;
341 const OSQLMessageBox::MessageType mt
= bSuccess
? OSQLMessageBox::Info
: OSQLMessageBox::Error
;
342 OSQLMessageBox
aMsg( this, String( ModuleRes( nMessage
) ), String(), WB_OK
| WB_DEF_OK
, mt
);
346 // -----------------------------------------------------------------------
347 bool OConnectionTabPage::checkTestConnection()
349 OSL_ENSURE(m_pAdminDialog
,"No Admin dialog set! ->GPF");
350 sal_Bool bEnableTestConnection
= !m_aConnectionURL
.IsVisible() || (m_aConnectionURL
.GetTextNoPrefix().Len() != 0);
351 if ( m_pCollection
->determineType(m_eType
) == ::dbaccess::DST_JDBC
)
352 bEnableTestConnection
= bEnableTestConnection
&& (m_aJavaDriver
.GetText().Len() != 0);
353 m_aTestConnection
.Enable(bEnableTestConnection
);
356 // -----------------------------------------------------------------------
357 IMPL_LINK(OConnectionTabPage
, OnEditModified
, Edit
*, _pEdit
)
359 if ( _pEdit
== &m_aJavaDriver
)
360 m_aTestJavaDriver
.Enable( m_aJavaDriver
.GetText().Len() != 0 );
362 checkTestConnection();
363 // tell the listener we were modified
367 //.........................................................................
369 //.........................................................................
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */