1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #ifndef DBAUI_CONNECTIONPAGESETUP_HXX
28 #include "ConnectionPageSetup.hxx"
29 #endif
30 #ifndef _DBAUI_AUTOCONTROLS_HRC_
31 #include "AutoControls.hrc"
32 #endif
33 #ifndef _DBAUI_DBADMINSETUP_HRC_
34 #include "dbadminsetup.hrc"
35 #endif
36 #ifndef _DBU_DLG_HRC_
37 #include "dbu_dlg.hrc"
38 #endif
39 #ifndef _SFXITEMSET_HXX
40 #include <svl/itemset.hxx>
41 #endif
42 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
43 #include <unotools/pathoptions.hxx>
44 #endif
45 #ifndef _SFXSTRITEM_HXX
46 #include <svl/stritem.hxx>
47 #endif
48 #ifndef _SFXENUMITEM_HXX
49 #include <svl/eitem.hxx>
50 #endif
51 #ifndef _SFXINTITEM_HXX
52 #include <svl/intitem.hxx>
53 #endif
54 #ifndef _DBAUI_DATASOURCEITEMS_HXX_
55 #include "dsitems.hxx"
56 #endif
57 #ifndef _DBA_DBACCESS_HELPID_HRC_
58 #include "dbaccess_helpid.hrc"
59 #endif
60 #ifndef _DBAUI_LOCALRESACCESS_HXX_
61 #include "localresaccess.hxx"
62 #endif
63 #ifndef _OSL_PROCESS_H_
64 #include <osl/process.h>
65 #endif
66 #ifndef _SV_MSGBOX_HXX
67 #include <vcl/msgbox.hxx>
68 #endif
69 #ifndef _FILEDLGHELPER_HXX
70 #include <sfx2/filedlghelper.hxx>
71 #endif
72 #ifndef _DBAUI_DBADMIN_HXX_
73 #include "dbadmin.hxx"
74 #endif
75 #ifndef _DBAUI_DBADMIN_HRC_
76 #include "dbadmin.hrc"
77 #endif
78 #ifndef _COMPHELPER_TYPES_HXX_
79 #include <comphelper/types.hxx>
80 #endif
81 #ifndef _VCL_STDTEXT_HXX
82 #include <vcl/stdtext.hxx>
83 #endif
84 #ifndef _DBAUI_SQLMESSAGE_HXX_
85 #include "sqlmessage.hxx"
86 #endif
87 #ifndef _DBAUI_ODBC_CONFIG_HXX_
88 #include "odbcconfig.hxx"
89 #endif
90 #ifndef _DBAUI_DSSELECT_HXX_
91 #include "dsselect.hxx"
92 #endif
93 #ifndef SVTOOLS_FILENOTATION_HXX_
94 #include <svl/filenotation.hxx>
95 #endif
96 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
97 #include "dbustrings.hrc"
98 #endif
99 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_
100 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
101 #endif
102 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
103 #include <com/sun/star/sdbc/XRow.hpp>
104 #endif
105 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
106 #include <com/sun/star/awt/XWindow.hpp>
107 #endif
108 // #106016# ------------------------------------
109 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
110 #include <com/sun/star/task/XInteractionHandler.hpp>
111 #endif
112 #ifndef _COM_SUN_STAR_TASK_XPROGRESSHANDLER_HPP_
113 #include <com/sun/star/ucb/XProgressHandler.hpp>
114 #endif
115 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
116 #include <com/sun/star/sdbc/XConnection.hpp>
117 #endif
118 #ifndef DBAUI_TOOLS_HXX
119 #include "UITools.hxx"
120 #endif
121 #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
122 #include <unotools/localfilehelper.hxx>
123 #endif
124 #ifndef _UNOTOOLS_UCBHELPER_HXX
125 #include <unotools/ucbhelper.hxx>
126 #endif
127 #ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX
128 #include <ucbhelper/commandenvironment.hxx>
129 #endif
130 #ifndef DBAUI_FILEPICKER_INTERACTION_HXX
131 #include "finteraction.hxx"
132 #endif
133 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
134 #include <connectivity/CommonTools.hxx>
135 #endif
136 #ifndef _URLOBJ_HXX
137 #include <tools/urlobj.hxx>
138 #endif
139 #ifndef _SFX_DOCFILT_HACK_HXX
140 #include <sfx2/docfilt.hxx>
141 #endif
142 #ifndef _SV_MNEMONIC_HXX
143 #include <vcl/mnemonic.hxx>
144 #endif
145 
146 //.........................................................................
147 namespace dbaui
148 {
149 //.........................................................................
150 	using namespace ::com::sun::star::uno;
151 	using namespace ::com::sun::star::ucb;
152 	using namespace ::com::sun::star::ui::dialogs;
153 	using namespace ::com::sun::star::sdbc;
154 	using namespace ::com::sun::star::beans;
155 	using namespace ::com::sun::star::lang;
156 	using namespace ::com::sun::star::container;
157 	using namespace ::dbtools;
158 	using namespace ::svt;
159 
160 
161 
CreateDbaseTabPage(Window * pParent,const SfxItemSet & _rAttrSet)162 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateDbaseTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
163     {
164 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_DBASE,    _rAttrSet, STR_DBASE_HELPTEXT,    STR_DBASE_HEADERTEXT,    STR_DBASE_PATH_OR_FILE);
165         oDBWizardPage->FreeResource();
166         return oDBWizardPage;
167     }
168 
169 
CreateMSAccessTabPage(Window * pParent,const SfxItemSet & _rAttrSet)170 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateMSAccessTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
171 	{
172         OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_MSACCESS, _rAttrSet, STR_MSACCESS_HELPTEXT, STR_MSACCESS_HEADERTEXT, STR_MSACCESS_MDB_FILE);
173 		oDBWizardPage->FreeResource();
174         return oDBWizardPage;
175 	}
176 
CreateAdabasTabPage(Window * pParent,const SfxItemSet & _rAttrSet)177 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateAdabasTabPage( Window* pParent,	const SfxItemSet& _rAttrSet )
178 	{
179         OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_ADABAS, _rAttrSet, STR_ADABAS_HELPTEXT, STR_ADABAS_HEADERTEXT, STR_ADABAS_DATABASE_NAME);
180 		oDBWizardPage->FreeResource();
181         return oDBWizardPage;
182 	}
183 
CreateADOTabPage(Window * pParent,const SfxItemSet & _rAttrSet)184 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateADOTabPage( Window* pParent,	const SfxItemSet& _rAttrSet )
185 	{
186 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_ADO, _rAttrSet, STR_ADO_HELPTEXT, STR_ADO_HEADERTEXT, STR_COMMONURL);
187 		oDBWizardPage->FreeResource();
188         return oDBWizardPage;
189 	}
190 
CreateODBCTabPage(Window * pParent,const SfxItemSet & _rAttrSet)191 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateODBCTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
192 	{
193 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_ODBC, _rAttrSet, STR_ODBC_HELPTEXT, STR_ODBC_HEADERTEXT, STR_NAME_OF_ODBC_DATASOURCE);
194 		oDBWizardPage->FreeResource();
195         return oDBWizardPage;
196 	}
197 
CreateUserDefinedTabPage(Window * pParent,const SfxItemSet & _rAttrSet)198 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateUserDefinedTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
199 	{
200 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_USERDEFINED, _rAttrSet, USHRT_MAX, USHRT_MAX, STR_COMMONURL);
201 		oDBWizardPage->FreeResource();
202         return oDBWizardPage;
203 	}
204 
205 
206     //========================================================================
207 	//= OConnectionTabPageSetup
208 	//========================================================================
DBG_NAME(OConnectionTabPageSetup)209 	DBG_NAME(OConnectionTabPageSetup)
210 	OConnectionTabPageSetup::OConnectionTabPageSetup(Window* pParent, sal_uInt16 _rId, const SfxItemSet& _rCoreAttrs, sal_uInt16 _nHelpTextResId, sal_uInt16 _nHeaderResId, sal_uInt16 _nUrlResId)
211 		:OConnectionHelper(pParent, ModuleRes(_rId), _rCoreAttrs)
212         ,m_bUserGrabFocus(sal_True)
213         ,m_aFT_HelpText(this, ModuleRes(FT_AUTOWIZARDHELPTEXT))
214 	{
215 		DBG_CTOR(OConnectionTabPageSetup, NULL);
216 
217 		if ( USHRT_MAX != _nHelpTextResId )
218 		{
219 			String sHelpText = String(ModuleRes(_nHelpTextResId));
220 			m_aFT_HelpText.SetText(sHelpText);
221 		}
222 		else
223 			m_aFT_HelpText.Hide();
224 
225 
226 		if ( USHRT_MAX != _nHeaderResId )
227 			SetHeaderText(FT_AUTOWIZARDHEADER, _nHeaderResId);
228 
229 		if ( USHRT_MAX != _nUrlResId )
230 		{
231 			String sLabelText = String(ModuleRes(_nUrlResId));
232 			m_aFT_Connection.SetText(sLabelText);
233 			if ( USHRT_MAX == _nHelpTextResId )
234 			{
235 				Point aPos = m_aFT_HelpText.GetPosPixel();
236 				Point aFTPos = m_aFT_Connection.GetPosPixel();
237 				Point aEDPos = m_aConnectionURL.GetPosPixel();
238 				Point aPBPos = m_aPB_Connection.GetPosPixel();
239 
240 				aEDPos.Y() = aPos.Y() + aEDPos.Y() - aFTPos.Y();
241 				aPBPos.Y() = aPos.Y() + aPBPos.Y() - aFTPos.Y();
242 				aFTPos.Y() = aPos.Y();
243 				m_aFT_Connection.SetPosPixel(aFTPos);
244 				m_aConnectionURL.SetPosPixel(aEDPos);
245 				m_aPB_Connection.SetPosPixel(aPBPos);
246 			}
247 		}
248 		else
249 			m_aFT_Connection.Hide();
250 
251 		m_aConnectionURL.SetModifyHdl(LINK(this, OConnectionTabPageSetup, OnEditModified));
252 
253         SetRoadmapStateValue(sal_False);
254 	}
255 
256 	// -----------------------------------------------------------------------
~OConnectionTabPageSetup()257 	OConnectionTabPageSetup::~OConnectionTabPageSetup()
258 	{
259 		DBG_DTOR(OConnectionTabPageSetup,NULL);
260 	}
261 
262     // -----------------------------------------------------------------------
implInitControls(const SfxItemSet & _rSet,sal_Bool _bSaveValue)263 	void OConnectionTabPageSetup::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
264 	{
265 		m_eType = m_pAdminDialog->getDatasourceType(_rSet);
266 		// special handling for oracle, this can only happen
267 		// if the user enters the same url as used for Oracle and we are on the JDBC path
268         //! TODO
269         //if (  ::dbaccess::DST_ORACLE_JDBC == m_eType )
270         //    m_eType =  ::dbaccess::DST_JDBC;
271 
272         OConnectionHelper::implInitControls(_rSet, _bSaveValue);
273 
274         //! TODO
275 		//if ( m_eType >=  ::dbaccess::DST_USERDEFINE1 )
276 		//{
277 		//	String sDisplayName = m_pCollection->getTypeDisplayName(m_eType);
278 		//	FixedText* ppTextControls[] ={&m_aFT_Connection};
279 		//	for (size_t i = 0; i < sizeof(ppTextControls)/sizeof(ppTextControls[0]); ++i)
280 		//	{
281 		//		ppTextControls[i]->SetText(sDisplayName);
282 		//	}
283 		//}
284 
285 		callModifiedHdl();
286 	}
287 	// -----------------------------------------------------------------------
commitPage(::svt::WizardTypes::CommitPageReason)288    	sal_Bool OConnectionTabPageSetup::commitPage( ::svt::WizardTypes::CommitPageReason /*_eReason*/ )
289 	{
290 		return commitURL();
291 	}
292 
293 	// -----------------------------------------------------------------------
FillItemSet(SfxItemSet & _rSet)294 	sal_Bool OConnectionTabPageSetup::FillItemSet(SfxItemSet& _rSet)
295 	{
296 		sal_Bool bChangedSomething = sal_False;
297         fillString(_rSet,&m_aConnectionURL, DSID_CONNECTURL, bChangedSomething);
298 		return bChangedSomething;
299 	}
300 	// -----------------------------------------------------------------------
checkTestConnection()301 	bool OConnectionTabPageSetup::checkTestConnection()
302 	{
303         return !m_aConnectionURL.IsVisible() || (m_aConnectionURL.GetTextNoPrefix().Len() != 0);
304 	}
305 
306     // -----------------------------------------------------------------------
307 	IMPL_LINK(OConnectionTabPageSetup, OnEditModified, Edit*, /*_pEdit*/)
308 	{
309         SetRoadmapStateValue(checkTestConnection());
310 		callModifiedHdl();
311 		return 0L;
312 	}
313 //.........................................................................
314 }	// namespace dbaui
315 //.........................................................................
316 
317 
318