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_dbui.hxx"
26 
27 #ifndef DBAUI_CONNECTIONPAGESETUP_HXX
28 #include "ConnectionPageSetup.hxx"
29 #endif
30 #include "AutoControlsDef.hrc"
31 #include "dbadminsetup.hrc"
32 #include "dbu_dlg.hrc"
33 #include <svl/itemset.hxx>
34 #include <unotools/pathoptions.hxx>
35 #include <svl/stritem.hxx>
36 #include <svl/eitem.hxx>
37 #include <svl/intitem.hxx>
38 #include "dsitems.hxx"
39 #include "dbaccess_helpid.hrc"
40 #include "localresaccess.hxx"
41 #include <osl/process.h>
42 #include <vcl/msgbox.hxx>
43 #include <sfx2/filedlghelper.hxx>
44 #include "dbadmin.hxx"
45 #include "dbadmin.hrc"
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 // #106016# ------------------------------------
57 #include <com/sun/star/task/XInteractionHandler.hpp>
58 #include <com/sun/star/ucb/XProgressHandler.hpp>
59 #include <com/sun/star/sdbc/XConnection.hpp>
60 #include "UITools.hxx"
61 #include <unotools/localfilehelper.hxx>
62 #include <unotools/ucbhelper.hxx>
63 #include <ucbhelper/commandenvironment.hxx>
64 #include "finteraction.hxx"
65 #include <connectivity/CommonTools.hxx>
66 #include <tools/urlobj.hxx>
67 #include <sfx2/docfilt.hxx>
68 #include <vcl/mnemonic.hxx>
69 
70 //.........................................................................
71 namespace dbaui
72 {
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 
85 
CreateDbaseTabPage(Window * pParent,const SfxItemSet & _rAttrSet)86 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateDbaseTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
87     {
88 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_DBASE,    _rAttrSet, STR_DBASE_HELPTEXT,    STR_DBASE_HEADERTEXT,    STR_DBASE_PATH_OR_FILE);
89         oDBWizardPage->FreeResource();
90         return oDBWizardPage;
91     }
92 
93 
CreateMSAccessTabPage(Window * pParent,const SfxItemSet & _rAttrSet)94 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateMSAccessTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
95 	{
96         OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_MSACCESS, _rAttrSet, STR_MSACCESS_HELPTEXT, STR_MSACCESS_HEADERTEXT, STR_MSACCESS_MDB_FILE);
97 		oDBWizardPage->FreeResource();
98         return oDBWizardPage;
99 	}
100 
CreateAdabasTabPage(Window * pParent,const SfxItemSet & _rAttrSet)101 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateAdabasTabPage( Window* pParent,	const SfxItemSet& _rAttrSet )
102 	{
103         OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_ADABAS, _rAttrSet, STR_ADABAS_HELPTEXT, STR_ADABAS_HEADERTEXT, STR_ADABAS_DATABASE_NAME);
104 		oDBWizardPage->FreeResource();
105         return oDBWizardPage;
106 	}
107 
CreateADOTabPage(Window * pParent,const SfxItemSet & _rAttrSet)108 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateADOTabPage( Window* pParent,	const SfxItemSet& _rAttrSet )
109 	{
110 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_ADO, _rAttrSet, STR_ADO_HELPTEXT, STR_ADO_HEADERTEXT, STR_COMMONURL);
111 		oDBWizardPage->FreeResource();
112         return oDBWizardPage;
113 	}
114 
CreateODBCTabPage(Window * pParent,const SfxItemSet & _rAttrSet)115 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateODBCTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
116 	{
117 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_ODBC, _rAttrSet, STR_ODBC_HELPTEXT, STR_ODBC_HEADERTEXT, STR_NAME_OF_ODBC_DATASOURCE);
118 		oDBWizardPage->FreeResource();
119         return oDBWizardPage;
120 	}
121 
CreateUserDefinedTabPage(Window * pParent,const SfxItemSet & _rAttrSet)122 	OGenericAdministrationPage*	OConnectionTabPageSetup::CreateUserDefinedTabPage( Window* pParent, const SfxItemSet& _rAttrSet )
123 	{
124 		OConnectionTabPageSetup* oDBWizardPage = new OConnectionTabPageSetup( pParent, PAGE_DBWIZARD_USERDEFINED, _rAttrSet, USHRT_MAX, USHRT_MAX, STR_COMMONURL);
125 		oDBWizardPage->FreeResource();
126         return oDBWizardPage;
127 	}
128 
129 
130     //========================================================================
131 	//= OConnectionTabPageSetup
132 	//========================================================================
DBG_NAME(OConnectionTabPageSetup)133 	DBG_NAME(OConnectionTabPageSetup)
134 	OConnectionTabPageSetup::OConnectionTabPageSetup(Window* pParent, sal_uInt16 _rId, const SfxItemSet& _rCoreAttrs, sal_uInt16 _nHelpTextResId, sal_uInt16 _nHeaderResId, sal_uInt16 _nUrlResId)
135 		:OConnectionHelper(pParent, ModuleRes(_rId), _rCoreAttrs)
136         ,m_bUserGrabFocus(sal_True)
137         ,m_aFT_HelpText(this, ModuleRes(FT_AUTOWIZARDHELPTEXT))
138 	{
139 		DBG_CTOR(OConnectionTabPageSetup, NULL);
140 
141 		if ( USHRT_MAX != _nHelpTextResId )
142 		{
143 			String sHelpText = String(ModuleRes(_nHelpTextResId));
144 			m_aFT_HelpText.SetText(sHelpText);
145 		}
146 		else
147 			m_aFT_HelpText.Hide();
148 
149 
150 		if ( USHRT_MAX != _nHeaderResId )
151 			SetHeaderText(FT_AUTOWIZARDHEADER, _nHeaderResId);
152 
153 		if ( USHRT_MAX != _nUrlResId )
154 		{
155 			String sLabelText = String(ModuleRes(_nUrlResId));
156 			m_aFT_Connection.SetText(sLabelText);
157 			if ( USHRT_MAX == _nHelpTextResId )
158 			{
159 				Point aPos = m_aFT_HelpText.GetPosPixel();
160 				Point aFTPos = m_aFT_Connection.GetPosPixel();
161 				Point aEDPos = m_aConnectionURL.GetPosPixel();
162 				Point aPBPos = m_aPB_Connection.GetPosPixel();
163 
164 				aEDPos.Y() = aPos.Y() + aEDPos.Y() - aFTPos.Y();
165 				aPBPos.Y() = aPos.Y() + aPBPos.Y() - aFTPos.Y();
166 				aFTPos.Y() = aPos.Y();
167 				m_aFT_Connection.SetPosPixel(aFTPos);
168 				m_aConnectionURL.SetPosPixel(aEDPos);
169 				m_aPB_Connection.SetPosPixel(aPBPos);
170 			}
171 		}
172 		else
173 			m_aFT_Connection.Hide();
174 
175 		m_aConnectionURL.SetModifyHdl(LINK(this, OConnectionTabPageSetup, OnEditModified));
176 
177         SetRoadmapStateValue(sal_False);
178 	}
179 
180 	// -----------------------------------------------------------------------
~OConnectionTabPageSetup()181 	OConnectionTabPageSetup::~OConnectionTabPageSetup()
182 	{
183 		DBG_DTOR(OConnectionTabPageSetup,NULL);
184 	}
185 
186     // -----------------------------------------------------------------------
implInitControls(const SfxItemSet & _rSet,sal_Bool _bSaveValue)187 	void OConnectionTabPageSetup::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
188 	{
189 		m_eType = m_pAdminDialog->getDatasourceType(_rSet);
190 		// special handling for oracle, this can only happen
191 		// if the user enters the same url as used for Oracle and we are on the JDBC path
192         //! TODO
193         //if (  ::dbaccess::DST_ORACLE_JDBC == m_eType )
194         //    m_eType =  ::dbaccess::DST_JDBC;
195 
196         OConnectionHelper::implInitControls(_rSet, _bSaveValue);
197 
198         //! TODO
199 		//if ( m_eType >=  ::dbaccess::DST_USERDEFINE1 )
200 		//{
201 		//	String sDisplayName = m_pCollection->getTypeDisplayName(m_eType);
202 		//	FixedText* ppTextControls[] ={&m_aFT_Connection};
203 		//	for (size_t i = 0; i < sizeof(ppTextControls)/sizeof(ppTextControls[0]); ++i)
204 		//	{
205 		//		ppTextControls[i]->SetText(sDisplayName);
206 		//	}
207 		//}
208 
209 		callModifiedHdl();
210 	}
211 	// -----------------------------------------------------------------------
commitPage(::svt::WizardTypes::CommitPageReason)212    	sal_Bool OConnectionTabPageSetup::commitPage( ::svt::WizardTypes::CommitPageReason /*_eReason*/ )
213 	{
214 		return commitURL();
215 	}
216 
217 	// -----------------------------------------------------------------------
FillItemSet(SfxItemSet & _rSet)218 	sal_Bool OConnectionTabPageSetup::FillItemSet(SfxItemSet& _rSet)
219 	{
220 		sal_Bool bChangedSomething = sal_False;
221         fillString(_rSet,&m_aConnectionURL, DSID_CONNECTURL, bChangedSomething);
222 		return bChangedSomething;
223 	}
224 	// -----------------------------------------------------------------------
checkTestConnection()225 	bool OConnectionTabPageSetup::checkTestConnection()
226 	{
227         return !m_aConnectionURL.IsVisible() || (m_aConnectionURL.GetTextNoPrefix().Len() != 0);
228 	}
229 
230     // -----------------------------------------------------------------------
231 	IMPL_LINK(OConnectionTabPageSetup, OnEditModified, Edit*, /*_pEdit*/)
232 	{
233         SetRoadmapStateValue(checkTestConnection());
234 		callModifiedHdl();
235 		return 0L;
236 	}
237 //.........................................................................
238 }	// namespace dbaui
239 //.........................................................................
240 
241 
242