196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
396de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
596de5490SAndrew Rist * distributed with this work for additional information
696de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
796de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist * "License"); you may not use this file except in compliance
996de5490SAndrew Rist * with the License. You may obtain a copy of the License at
1096de5490SAndrew Rist *
1196de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1296de5490SAndrew Rist *
1396de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist * software distributed under the License is distributed on an
1596de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist * KIND, either express or implied. See the License for the
1796de5490SAndrew Rist * specific language governing permissions and limitations
1896de5490SAndrew Rist * under the License.
1996de5490SAndrew Rist *
2096de5490SAndrew Rist *************************************************************/
2196de5490SAndrew Rist
2296de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "dbwizsetup.hxx"
28cdf0e10cSrcweir #include "dsmeta.hxx"
29cdf0e10cSrcweir #include "DBSetupConnectionPages.hxx"
30cdf0e10cSrcweir #include "dbadminsetup.hrc"
31cdf0e10cSrcweir #include "dbu_dlg.hrc"
32cdf0e10cSrcweir #include "dsitems.hxx"
33cdf0e10cSrcweir #include "dsnItem.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
36cdf0e10cSrcweir #include <svl/stritem.hxx>
37cdf0e10cSrcweir #include <svl/eitem.hxx>
38cdf0e10cSrcweir #include <svl/intitem.hxx>
39cdf0e10cSrcweir #include <vcl/msgbox.hxx>
40cdf0e10cSrcweir #include "dbustrings.hrc"
41cdf0e10cSrcweir #include "adminpages.hxx"
42cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
43cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
44cdf0e10cSrcweir #include "generalpage.hxx"
45cdf0e10cSrcweir #include "localresaccess.hxx"
46cdf0e10cSrcweir #include "stringlistitem.hxx"
47cdf0e10cSrcweir #include "propertysetitem.hxx"
48cdf0e10cSrcweir #include <unotools/confignode.hxx>
49cdf0e10cSrcweir #include "DbAdminImpl.hxx"
50cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
51cdf0e10cSrcweir #include "ConnectionPageSetup.hxx"
52cdf0e10cSrcweir #include "UITools.hxx"
53cdf0e10cSrcweir #include "dbadmin.hrc"
54cdf0e10cSrcweir #include "AsyncronousLink.hxx"
55cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
56cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
57cdf0e10cSrcweir
58cdf0e10cSrcweir /** === begin UNO includes === **/
59cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
60cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
63cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
64cdf0e10cSrcweir #endif
65cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
66cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
69cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
72cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
75cdf0e10cSrcweir #include <com/sun/star/sdb/XDocumentDataSource.hpp>
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
78cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
79cdf0e10cSrcweir #endif
80cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
81cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
82cdf0e10cSrcweir #endif
83cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
84cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
85cdf0e10cSrcweir #endif
86cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
87cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
88cdf0e10cSrcweir #endif
89cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
90cdf0e10cSrcweir #include <com/sun/star/task/XJobExecutor.hpp>
91cdf0e10cSrcweir #endif
92cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
93cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
94cdf0e10cSrcweir #endif
95cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
96cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
97cdf0e10cSrcweir #endif
98cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
99cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp>
100cdf0e10cSrcweir #endif
101cdf0e10cSrcweir #ifndef _COM_SUN_STAR_IO_IOEXCEPTION_HPP_
102cdf0e10cSrcweir #include <com/sun/star/io/IOException.hpp>
103cdf0e10cSrcweir #endif
104cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_
105cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp>
106cdf0e10cSrcweir #endif
107cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
108cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
109cdf0e10cSrcweir #endif
110cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
111cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverAccess.hpp>
112cdf0e10cSrcweir #endif
113cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
114cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp>
115cdf0e10cSrcweir #endif
116cdf0e10cSrcweir #include <com/sun/star/ucb/IOErrorCode.hpp>
117cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler2.hpp>
118cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
119cdf0e10cSrcweir
120cdf0e10cSrcweir
121cdf0e10cSrcweir /** === end UNO includes === **/
122cdf0e10cSrcweir
123cdf0e10cSrcweir #include <svl/filenotation.hxx>
124cdf0e10cSrcweir #include <comphelper/interaction.hxx>
125cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
126cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
127cdf0e10cSrcweir #include <tools/diagnose_ex.h>
128cdf0e10cSrcweir #include <connectivity/DriversConfig.hxx>
129cdf0e10cSrcweir
130cdf0e10cSrcweir #include <memory>
131cdf0e10cSrcweir
132cdf0e10cSrcweir
133cdf0e10cSrcweir //.........................................................................
134cdf0e10cSrcweir namespace dbaui
135cdf0e10cSrcweir {
136cdf0e10cSrcweir //.........................................................................
137cdf0e10cSrcweir using namespace dbtools;
138cdf0e10cSrcweir using namespace svt;
139cdf0e10cSrcweir using namespace com::sun::star;
140cdf0e10cSrcweir using namespace com::sun::star::uno;
141cdf0e10cSrcweir using namespace com::sun::star::sdbc;
142cdf0e10cSrcweir using namespace com::sun::star::sdbcx;
143cdf0e10cSrcweir using namespace com::sun::star::task;
144cdf0e10cSrcweir using namespace com::sun::star::lang;
145cdf0e10cSrcweir using namespace com::sun::star::io;
146cdf0e10cSrcweir using namespace com::sun::star::util;
147cdf0e10cSrcweir using namespace com::sun::star::beans;
148cdf0e10cSrcweir using namespace com::sun::star::container;
149cdf0e10cSrcweir using namespace com::sun::star::frame;
150cdf0e10cSrcweir using namespace com::sun::star::ucb;
151cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
152cdf0e10cSrcweir using namespace ::com::sun::star::document;
153cdf0e10cSrcweir using namespace ::comphelper;
154cdf0e10cSrcweir using namespace ::cppu;
155cdf0e10cSrcweir
156cdf0e10cSrcweir #define START_PAGE 0
157cdf0e10cSrcweir #define CONNECTION_PAGE 1
158cdf0e10cSrcweir
159cdf0e10cSrcweir
160cdf0e10cSrcweir
161cdf0e10cSrcweir
162cdf0e10cSrcweir //#define DBASE_PATH 1
163cdf0e10cSrcweir //#define TEXT_PATH 2
164cdf0e10cSrcweir //#define MSACCESS_PATH 3
165cdf0e10cSrcweir //#define LDAP_PATH 4
166cdf0e10cSrcweir //#define ADABAS_PATH 5
167cdf0e10cSrcweir //#define ADO_PATH 6
168cdf0e10cSrcweir //#define JDBC_PATH 7
169cdf0e10cSrcweir //#define ORACLE_PATH 8
170cdf0e10cSrcweir //#define MYSQL_JDBC_PATH 9
171cdf0e10cSrcweir //#define MYSQL_ODBC_PATH 10
172cdf0e10cSrcweir //#define ODBC_PATH 11
173cdf0e10cSrcweir //#define SPREADSHEET_PATH 12
174cdf0e10cSrcweir //#define OUTLOOKEXP_PATH 13
175cdf0e10cSrcweir //#define OUTLOOK_PATH 14
176cdf0e10cSrcweir //#define MOZILLA_PATH 15
177cdf0e10cSrcweir //#define EVOLUTION_PATH 16
178cdf0e10cSrcweir //#define EVOLUTION_PATH_GROUPWISE 17
179cdf0e10cSrcweir //#define EVOLUTION_PATH_LDAP 18
180cdf0e10cSrcweir //#define KAB_PATH 19
181cdf0e10cSrcweir //#define MACAB_PATH 20
182cdf0e10cSrcweir //#define THUNDERBIRD_PATH 21
183cdf0e10cSrcweir //#define CREATENEW_PATH 22
184cdf0e10cSrcweir //#define USERDEFINED_PATH 23
185cdf0e10cSrcweir //#define OPEN_DOC_PATH 24
186cdf0e10cSrcweir //#define MSACCESS2007_PATH 25
187cdf0e10cSrcweir //#define MYSQL_NATIVE_PATH 26
188cdf0e10cSrcweir
189cdf0e10cSrcweir OFinalDBPageSetup* pFinalPage;
190cdf0e10cSrcweir
191cdf0e10cSrcweir
192cdf0e10cSrcweir
DBG_NAME(ODbTypeWizDialogSetup)193cdf0e10cSrcweir DBG_NAME(ODbTypeWizDialogSetup)
194cdf0e10cSrcweir //=========================================================================
195cdf0e10cSrcweir //= ODbTypeWizDialogSetup
196cdf0e10cSrcweir //=========================================================================
197cdf0e10cSrcweir //-------------------------------------------------------------------------
198cdf0e10cSrcweir ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(Window* _pParent
199cdf0e10cSrcweir ,SfxItemSet* _pItems
200cdf0e10cSrcweir ,const Reference< XMultiServiceFactory >& _rxORB
201cdf0e10cSrcweir ,const ::com::sun::star::uno::Any& _aDataSourceName
202cdf0e10cSrcweir )
203cdf0e10cSrcweir :svt::RoadmapWizard( _pParent, ModuleRes(DLG_DATABASE_WIZARD),
204cdf0e10cSrcweir WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
205cdf0e10cSrcweir
206cdf0e10cSrcweir , m_pOutSet(NULL)
207cdf0e10cSrcweir , m_bResetting(sal_False)
208cdf0e10cSrcweir , m_bApplied(sal_False)
209cdf0e10cSrcweir , m_bUIEnabled( sal_True )
210cdf0e10cSrcweir , m_bIsConnectable( sal_False)
211cdf0e10cSrcweir , m_sRM_IntroText(ModuleRes(STR_PAGETITLE_INTROPAGE))
212cdf0e10cSrcweir , m_sRM_dBaseText(ModuleRes(STR_PAGETITLE_DBASE))
213cdf0e10cSrcweir , m_sRM_TextText(ModuleRes(STR_PAGETITLE_TEXT))
214cdf0e10cSrcweir , m_sRM_MSAccessText(ModuleRes(STR_PAGETITLE_MSACCESS))
215cdf0e10cSrcweir , m_sRM_LDAPText(ModuleRes(STR_PAGETITLE_LDAP))
216cdf0e10cSrcweir , m_sRM_ADABASText(ModuleRes(STR_PAGETITLE_ADABAS))
217cdf0e10cSrcweir , m_sRM_ADOText(ModuleRes(STR_PAGETITLE_ADO))
218cdf0e10cSrcweir , m_sRM_JDBCText(ModuleRes(STR_PAGETITLE_JDBC))
219cdf0e10cSrcweir , m_sRM_MySQLNativePageTitle(ModuleRes(STR_PAGETITLE_MYSQL_NATIVE))
220cdf0e10cSrcweir , m_pGeneralPage( NULL )
221cdf0e10cSrcweir , m_pMySQLIntroPage(NULL)
222cdf0e10cSrcweir , m_pCollection( NULL )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir DBG_CTOR(ODbTypeWizDialogSetup,NULL);
225cdf0e10cSrcweir // no local resources needed anymore
226cdf0e10cSrcweir m_sRM_MySQLText = String(ModuleRes(STR_PAGETITLE_MYSQL));
227cdf0e10cSrcweir m_sRM_OracleText = String(ModuleRes(STR_PAGETITLE_ORACLE));
228cdf0e10cSrcweir m_sRM_ODBCText = String(ModuleRes(STR_PAGETITLE_ODBC));
229cdf0e10cSrcweir m_sRM_SpreadSheetText = String(ModuleRes(STR_PAGETITLE_SPREADSHEET));
230cdf0e10cSrcweir m_sRM_AuthentificationText = String(ModuleRes(STR_PAGETITLE_AUTHENTIFICATION));
231cdf0e10cSrcweir m_sRM_FinalText = String(ModuleRes(STR_PAGETITLE_FINAL));
232cdf0e10cSrcweir m_sWorkPath = SvtPathOptions().GetWorkPath();
233cdf0e10cSrcweir pFinalPage = NULL;
234cdf0e10cSrcweir // extract the datasource type collection from the item set
235cdf0e10cSrcweir DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
236cdf0e10cSrcweir if (pCollectionItem)
237cdf0e10cSrcweir m_pCollection = pCollectionItem->getCollection();
238cdf0e10cSrcweir
239cdf0e10cSrcweir DBG_ASSERT(m_pCollection, "ODbTypeWizDialogSetup::ODbTypeWizDialogSetup : really need a DSN type collection !");
240cdf0e10cSrcweir
241cdf0e10cSrcweir FreeResource();
242cdf0e10cSrcweir
243cdf0e10cSrcweir m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
244cdf0e10cSrcweir m_pImpl->setDataSourceOrName(_aDataSourceName);
245cdf0e10cSrcweir Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
246cdf0e10cSrcweir m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
247cdf0e10cSrcweir
248cdf0e10cSrcweir m_pImpl->translateProperties(xDatasource, *m_pOutSet);
249cdf0e10cSrcweir // eType = m_pImpl->getDatasourceType(*m_pOutSet);
250cdf0e10cSrcweir
251cdf0e10cSrcweir SetPageSizePixel(LogicToPixel(::Size(WIZARD_PAGE_X, WIZARD_PAGE_Y), MAP_APPFONT));
252cdf0e10cSrcweir ShowButtonFixedLine(sal_True);
253cdf0e10cSrcweir defaultButton(WZB_NEXT);
254cdf0e10cSrcweir enableButtons(WZB_FINISH, sal_True);
255cdf0e10cSrcweir enableAutomaticNextButtonState();
256cdf0e10cSrcweir
257cdf0e10cSrcweir ::dbaccess::ODsnTypeCollection::TypeIterator aIter = m_pCollection->begin();
258cdf0e10cSrcweir ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
259cdf0e10cSrcweir for(PathId i = 1;aIter != aEnd;++aIter,++i)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir const ::rtl::OUString sURLPrefix = aIter.getURLPrefix();
262cdf0e10cSrcweir svt::RoadmapWizardTypes::WizardPath aPath;
263cdf0e10cSrcweir aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
264cdf0e10cSrcweir m_pCollection->fillPageIds(sURLPrefix,aPath);
265cdf0e10cSrcweir aPath.push_back(PAGE_DBSETUPWIZARD_AUTHENTIFICATION);
266cdf0e10cSrcweir aPath.push_back(PAGE_DBSETUPWIZARD_FINAL);
267cdf0e10cSrcweir
268cdf0e10cSrcweir declareAuthDepPath(sURLPrefix,i,aPath);
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir svt::RoadmapWizardTypes::WizardPath aPath;
272cdf0e10cSrcweir aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
273cdf0e10cSrcweir declarePath( static_cast<PathId>(m_pCollection->size()+1), aPath);
274cdf0e10cSrcweir
275cdf0e10cSrcweir m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
276cdf0e10cSrcweir m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
277cdf0e10cSrcweir m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
278cdf0e10cSrcweir m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
279cdf0e10cSrcweir m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
280cdf0e10cSrcweir SetRoadmapInteractive( sal_True );
281cdf0e10cSrcweir ActivatePage();
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
declareAuthDepPath(const::rtl::OUString & _sURL,PathId _nPathId,const svt::RoadmapWizardTypes::WizardPath & _rPaths)284cdf0e10cSrcweir void ODbTypeWizDialogSetup::declareAuthDepPath( const ::rtl::OUString& _sURL, PathId _nPathId, const svt::RoadmapWizardTypes::WizardPath& _rPaths)
285cdf0e10cSrcweir {
286cdf0e10cSrcweir bool bHasAuthentication = DataSourceMetaData::getAuthentication( _sURL ) != AuthNone;
287cdf0e10cSrcweir
288cdf0e10cSrcweir // collect the elements of the path
289cdf0e10cSrcweir WizardPath aPath;
290cdf0e10cSrcweir
291cdf0e10cSrcweir svt::RoadmapWizardTypes::WizardPath::const_iterator aIter = _rPaths.begin();
292cdf0e10cSrcweir svt::RoadmapWizardTypes::WizardPath::const_iterator aEnd = _rPaths.end();
293cdf0e10cSrcweir for(;aIter != aEnd;++aIter)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir if ( bHasAuthentication || ( *aIter != PAGE_DBSETUPWIZARD_AUTHENTIFICATION ) )
296cdf0e10cSrcweir aPath.push_back( *aIter );
297cdf0e10cSrcweir } // for(;aIter != aEnd;++aIter)
298cdf0e10cSrcweir
299cdf0e10cSrcweir // call base method
300cdf0e10cSrcweir ::svt::RoadmapWizard::declarePath( _nPathId, aPath );
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
getStateDisplayName(WizardState _nState) const303cdf0e10cSrcweir String ODbTypeWizDialogSetup::getStateDisplayName( WizardState _nState ) const
304cdf0e10cSrcweir {
305cdf0e10cSrcweir String sRoadmapItem;
306cdf0e10cSrcweir switch( _nState )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_INTRO:
309cdf0e10cSrcweir sRoadmapItem = m_sRM_IntroText;
310cdf0e10cSrcweir break;
311cdf0e10cSrcweir
312cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_DBASE:
313cdf0e10cSrcweir sRoadmapItem = m_sRM_dBaseText;
314cdf0e10cSrcweir break;
315cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ADO:
316cdf0e10cSrcweir sRoadmapItem = m_sRM_ADOText;
317cdf0e10cSrcweir break;
318cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_TEXT:
319cdf0e10cSrcweir sRoadmapItem = m_sRM_TextText;
320cdf0e10cSrcweir break;
321cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MSACCESS:
322cdf0e10cSrcweir sRoadmapItem = m_sRM_MSAccessText;
323cdf0e10cSrcweir break;
324cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_LDAP:
325cdf0e10cSrcweir sRoadmapItem = m_sRM_LDAPText;
326cdf0e10cSrcweir break;
327cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ADABAS:
328cdf0e10cSrcweir sRoadmapItem = m_sRM_ADABASText;
329cdf0e10cSrcweir break;
330cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_JDBC:
331cdf0e10cSrcweir sRoadmapItem = m_sRM_JDBCText;
332cdf0e10cSrcweir break;
333cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ORACLE:
334cdf0e10cSrcweir sRoadmapItem = m_sRM_OracleText;
335cdf0e10cSrcweir break;
336cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
337cdf0e10cSrcweir sRoadmapItem = m_sRM_MySQLText;
338cdf0e10cSrcweir break;
339cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
340cdf0e10cSrcweir sRoadmapItem = m_sRM_JDBCText;
341cdf0e10cSrcweir break;
342cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
343cdf0e10cSrcweir sRoadmapItem = m_sRM_MySQLNativePageTitle;
344cdf0e10cSrcweir break;
345cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
346cdf0e10cSrcweir sRoadmapItem = m_sRM_ODBCText;
347cdf0e10cSrcweir break;
348cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ODBC:
349cdf0e10cSrcweir sRoadmapItem = m_sRM_ODBCText;
350cdf0e10cSrcweir break;
351cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_SPREADSHEET:
352cdf0e10cSrcweir sRoadmapItem = m_sRM_SpreadSheetText;
353cdf0e10cSrcweir break;
354cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
355cdf0e10cSrcweir sRoadmapItem = m_sRM_AuthentificationText;
356cdf0e10cSrcweir break;
357cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_USERDEFINED:
358cdf0e10cSrcweir {
359cdf0e10cSrcweir LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG);
360cdf0e10cSrcweir sRoadmapItem = String(ModuleRes(STR_PAGETITLE_CONNECTION));
361cdf0e10cSrcweir }
362cdf0e10cSrcweir break;
363cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_FINAL:
364cdf0e10cSrcweir sRoadmapItem = m_sRM_FinalText;
365cdf0e10cSrcweir break;
366cdf0e10cSrcweir default:
367cdf0e10cSrcweir break;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir return sRoadmapItem;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir
372cdf0e10cSrcweir //-------------------------------------------------------------------------
~ODbTypeWizDialogSetup()373cdf0e10cSrcweir ODbTypeWizDialogSetup::~ODbTypeWizDialogSetup()
374cdf0e10cSrcweir {
375cdf0e10cSrcweir delete m_pOutSet;
376cdf0e10cSrcweir DBG_DTOR(ODbTypeWizDialogSetup,NULL);
377cdf0e10cSrcweir }
378cdf0e10cSrcweir
379cdf0e10cSrcweir //-------------------------------------------------------------------------
380cdf0e10cSrcweir IMPL_LINK(ODbTypeWizDialogSetup, OnTypeSelected, OGeneralPage*, /*_pTabPage*/)
381cdf0e10cSrcweir {
382cdf0e10cSrcweir activateDatabasePath();
383cdf0e10cSrcweir return 1L;
384cdf0e10cSrcweir }
385cdf0e10cSrcweir
lcl_removeUnused(const::comphelper::NamedValueCollection & _aOld,const::comphelper::NamedValueCollection & _aNew,::comphelper::NamedValueCollection & _rDSInfo)386cdf0e10cSrcweir void lcl_removeUnused(const ::comphelper::NamedValueCollection& _aOld,const ::comphelper::NamedValueCollection& _aNew,::comphelper::NamedValueCollection& _rDSInfo)
387cdf0e10cSrcweir {
388cdf0e10cSrcweir _rDSInfo.merge(_aNew,true);
389cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aOldValues = _aOld.getNamedValues();
390cdf0e10cSrcweir const beans::NamedValue* pIter = aOldValues.getConstArray();
391cdf0e10cSrcweir const beans::NamedValue* pEnd = pIter + aOldValues.getLength();
392cdf0e10cSrcweir for(;pIter != pEnd;++pIter)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir if ( !_aNew.has(pIter->Name) )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir _rDSInfo.remove(pIter->Name);
397cdf0e10cSrcweir }
398cdf0e10cSrcweir }
399cdf0e10cSrcweir }
400cdf0e10cSrcweir // -----------------------------------------------------------------------------
convert(const::dbaccess::ODsnTypeCollection * _pCollection,const::rtl::OUString & _sOldURLPrefix,const::rtl::OUString & _sNewURLPrefix,const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & _xDatasource)401cdf0e10cSrcweir void DataSourceInfoConverter::convert(const ::dbaccess::ODsnTypeCollection* _pCollection,const ::rtl::OUString& _sOldURLPrefix,const ::rtl::OUString& _sNewURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource)
402cdf0e10cSrcweir {
403cdf0e10cSrcweir if ( _pCollection->getPrefix(_sOldURLPrefix) == _pCollection->getPrefix(_sNewURLPrefix) )
404cdf0e10cSrcweir return ;
405cdf0e10cSrcweir uno::Sequence< beans::PropertyValue> aInfo;
406cdf0e10cSrcweir _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
407cdf0e10cSrcweir ::comphelper::NamedValueCollection aDS(aInfo);
408cdf0e10cSrcweir
409cdf0e10cSrcweir ::connectivity::DriversConfig aDriverConfig(m_xFactory);
410cdf0e10cSrcweir
411cdf0e10cSrcweir const ::comphelper::NamedValueCollection& aOldProperties = aDriverConfig.getProperties(_sOldURLPrefix);
412cdf0e10cSrcweir const ::comphelper::NamedValueCollection& aNewProperties = aDriverConfig.getProperties(_sNewURLPrefix);
413cdf0e10cSrcweir lcl_removeUnused(aOldProperties,aNewProperties,aDS);
414cdf0e10cSrcweir
415cdf0e10cSrcweir aDS >>= aInfo;
416cdf0e10cSrcweir _xDatasource->setPropertyValue(PROPERTY_INFO,uno::makeAny(aInfo));
417cdf0e10cSrcweir }
418cdf0e10cSrcweir //-------------------------------------------------------------------------
activateDatabasePath()419cdf0e10cSrcweir void ODbTypeWizDialogSetup::activateDatabasePath()
420cdf0e10cSrcweir {
421cdf0e10cSrcweir switch ( m_pGeneralPage->GetDatabaseCreationMode() )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir case OGeneralPage::eCreateNew:
424cdf0e10cSrcweir {
425cdf0e10cSrcweir sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() );
426cdf0e10cSrcweir if ( nCreateNewDBIndex == -1 )
427cdf0e10cSrcweir nCreateNewDBIndex = m_pCollection->getIndexOf( ::rtl::OUString::createFromAscii( "sdbc:dbase:" ) );
428cdf0e10cSrcweir OSL_ENSURE( nCreateNewDBIndex != -1, "ODbTypeWizDialogSetup::activateDatabasePath: the GeneralPage should have prevented this!" );
429cdf0e10cSrcweir activatePath( static_cast< PathId >( nCreateNewDBIndex + 1 ), sal_True );
430cdf0e10cSrcweir
431cdf0e10cSrcweir enableState(PAGE_DBSETUPWIZARD_FINAL, sal_True );
432cdf0e10cSrcweir enableButtons( WZB_FINISH, sal_True);
433cdf0e10cSrcweir }
434cdf0e10cSrcweir break;
435cdf0e10cSrcweir case OGeneralPage::eConnectExternal:
436cdf0e10cSrcweir {
437cdf0e10cSrcweir ::rtl::OUString sOld = m_sURL;
438cdf0e10cSrcweir DataSourceInfoConverter aConverter(getORB());
439cdf0e10cSrcweir m_sURL = m_pGeneralPage->GetSelectedType();
440cdf0e10cSrcweir aConverter.convert(m_pCollection,sOld,m_sURL,m_pImpl->getCurrentDataSource());
441cdf0e10cSrcweir ::dbaccess::DATASOURCE_TYPE eType = VerifyDataSourceType(m_pCollection->determineType(m_sURL));
442cdf0e10cSrcweir if (eType == ::dbaccess::DST_UNKNOWN)
443cdf0e10cSrcweir eType = m_pCollection->determineType(m_sOldURL);
444cdf0e10cSrcweir
445cdf0e10cSrcweir activatePath( static_cast<PathId>(m_pCollection->getIndexOf(m_sURL) + 1), sal_True);
446cdf0e10cSrcweir updateTypeDependentStates();
447cdf0e10cSrcweir }
448cdf0e10cSrcweir break;
449cdf0e10cSrcweir case OGeneralPage::eOpenExisting:
450cdf0e10cSrcweir {
451cdf0e10cSrcweir activatePath( static_cast<PathId>(m_pCollection->size() + 1), sal_True );
452cdf0e10cSrcweir enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir break;
455cdf0e10cSrcweir default:
456cdf0e10cSrcweir DBG_ERROR( "ODbTypeWizDialogSetup::activateDatabasePath: unknown creation mode!" );
457cdf0e10cSrcweir }
458cdf0e10cSrcweir
459cdf0e10cSrcweir enableButtons( WZB_NEXT, m_pGeneralPage->GetDatabaseCreationMode() != OGeneralPage::eOpenExisting );
460cdf0e10cSrcweir // TODO: this should go into the base class. Point is, we activate a path whose *last*
461cdf0e10cSrcweir // step is also the current one. The base class should automatically disable
462cdf0e10cSrcweir // the Next button in such a case. However, not for this patch ...
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir //-------------------------------------------------------------------------
updateTypeDependentStates()466cdf0e10cSrcweir void ODbTypeWizDialogSetup::updateTypeDependentStates()
467cdf0e10cSrcweir {
468cdf0e10cSrcweir sal_Bool bDoEnable = sal_False;
469cdf0e10cSrcweir sal_Bool bIsConnectionRequired = IsConnectionUrlRequired();
470cdf0e10cSrcweir if (!bIsConnectionRequired)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir bDoEnable = sal_True;
473cdf0e10cSrcweir }
474cdf0e10cSrcweir else if ( m_sURL == m_sOldURL )
475cdf0e10cSrcweir {
476cdf0e10cSrcweir bDoEnable = m_bIsConnectable;
477cdf0e10cSrcweir }
478cdf0e10cSrcweir enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, bDoEnable);
479cdf0e10cSrcweir enableState(PAGE_DBSETUPWIZARD_FINAL, bDoEnable );
480cdf0e10cSrcweir enableButtons( WZB_FINISH, bDoEnable);
481cdf0e10cSrcweir }
482cdf0e10cSrcweir
483cdf0e10cSrcweir
484cdf0e10cSrcweir //-------------------------------------------------------------------------
IsConnectionUrlRequired()485cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::IsConnectionUrlRequired()
486cdf0e10cSrcweir {
487cdf0e10cSrcweir return m_pCollection->isConnectionUrlRequired(m_sURL);
488cdf0e10cSrcweir }
489cdf0e10cSrcweir
490cdf0e10cSrcweir //-------------------------------------------------------------------------
resetPages(const Reference<XPropertySet> & _rxDatasource)491cdf0e10cSrcweir void ODbTypeWizDialogSetup::resetPages(const Reference< XPropertySet >& _rxDatasource)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir // remove all items which relate to indirect properties from the input set
494cdf0e10cSrcweir // (without this, the following may happen: select an arbitrary data source where some indirect properties
495cdf0e10cSrcweir // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
496cdf0e10cSrcweir // the indirect property values of the first ds are shown in the second ds ...)
497cdf0e10cSrcweir const ODbDataSourceAdministrationHelper::MapInt2String& rMap = m_pImpl->getIndirectProperties();
498cdf0e10cSrcweir for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect = rMap.begin();
499cdf0e10cSrcweir aIndirect != rMap.end();
500cdf0e10cSrcweir ++aIndirect
501cdf0e10cSrcweir )
502cdf0e10cSrcweir getWriteOutputSet()->ClearItem( (sal_uInt16)aIndirect->first );
503cdf0e10cSrcweir
504cdf0e10cSrcweir // extract all relevant data from the property set of the data source
505cdf0e10cSrcweir m_pImpl->translateProperties(_rxDatasource, *getWriteOutputSet());
506cdf0e10cSrcweir }
507cdf0e10cSrcweir // -----------------------------------------------------------------------------
getOutputSet() const508cdf0e10cSrcweir const SfxItemSet* ODbTypeWizDialogSetup::getOutputSet() const
509cdf0e10cSrcweir {
510cdf0e10cSrcweir return m_pOutSet;
511cdf0e10cSrcweir }
512cdf0e10cSrcweir // -----------------------------------------------------------------------------
getWriteOutputSet()513cdf0e10cSrcweir SfxItemSet* ODbTypeWizDialogSetup::getWriteOutputSet()
514cdf0e10cSrcweir {
515cdf0e10cSrcweir return m_pOutSet;
516cdf0e10cSrcweir }
517cdf0e10cSrcweir // -----------------------------------------------------------------------------
createConnection()518cdf0e10cSrcweir ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialogSetup::createConnection()
519cdf0e10cSrcweir {
520cdf0e10cSrcweir return m_pImpl->createConnection();
521cdf0e10cSrcweir }
522cdf0e10cSrcweir // -----------------------------------------------------------------------------
getORB() const523cdf0e10cSrcweir Reference< XMultiServiceFactory > ODbTypeWizDialogSetup::getORB() const
524cdf0e10cSrcweir {
525cdf0e10cSrcweir return m_pImpl->getORB();
526cdf0e10cSrcweir }
527cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDriver()528cdf0e10cSrcweir Reference< XDriver > ODbTypeWizDialogSetup::getDriver()
529cdf0e10cSrcweir {
530cdf0e10cSrcweir return m_pImpl->getDriver();
531cdf0e10cSrcweir }
532cdf0e10cSrcweir
533cdf0e10cSrcweir
VerifyDataSourceType(const::dbaccess::DATASOURCE_TYPE _DatabaseType) const534cdf0e10cSrcweir ::dbaccess::DATASOURCE_TYPE ODbTypeWizDialogSetup::VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType) const
535cdf0e10cSrcweir {
536cdf0e10cSrcweir ::dbaccess::DATASOURCE_TYPE LocDatabaseType = _DatabaseType;
537cdf0e10cSrcweir if ((LocDatabaseType == ::dbaccess::DST_MYSQL_JDBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_ODBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_NATIVE))
538cdf0e10cSrcweir {
539cdf0e10cSrcweir if (m_pMySQLIntroPage != NULL)
540cdf0e10cSrcweir {
541cdf0e10cSrcweir switch( m_pMySQLIntroPage->getMySQLMode() )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_JDBC:
544cdf0e10cSrcweir return ::dbaccess::DST_MYSQL_JDBC;
545cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_NATIVE:
546cdf0e10cSrcweir return ::dbaccess::DST_MYSQL_NATIVE;
547cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_ODBC:
548cdf0e10cSrcweir return ::dbaccess::DST_MYSQL_ODBC;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir }
551cdf0e10cSrcweir }
552cdf0e10cSrcweir return LocDatabaseType;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
555cdf0e10cSrcweir
556cdf0e10cSrcweir
557cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDatasourceType(const SfxItemSet & _rSet) const558cdf0e10cSrcweir ::rtl::OUString ODbTypeWizDialogSetup::getDatasourceType(const SfxItemSet& _rSet) const
559cdf0e10cSrcweir {
560cdf0e10cSrcweir ::rtl::OUString sRet = m_pImpl->getDatasourceType(_rSet);
561cdf0e10cSrcweir if (m_pMySQLIntroPage != NULL && m_pMySQLIntroPage->IsVisible() )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir switch( m_pMySQLIntroPage->getMySQLMode() )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_JDBC:
566cdf0e10cSrcweir sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
567cdf0e10cSrcweir break;
568cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_NATIVE:
569cdf0e10cSrcweir sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
570cdf0e10cSrcweir break;
571cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_ODBC:
572cdf0e10cSrcweir sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
573cdf0e10cSrcweir break;
574cdf0e10cSrcweir }
575cdf0e10cSrcweir }
576cdf0e10cSrcweir return sRet;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir
579cdf0e10cSrcweir // -----------------------------------------------------------------------------
clearPassword()580cdf0e10cSrcweir void ODbTypeWizDialogSetup::clearPassword()
581cdf0e10cSrcweir {
582cdf0e10cSrcweir m_pImpl->clearPassword();
583cdf0e10cSrcweir }
584cdf0e10cSrcweir
585cdf0e10cSrcweir // -----------------------------------------------------------------------------
createPage(WizardState _nState)586cdf0e10cSrcweir TabPage* ODbTypeWizDialogSetup::createPage(WizardState _nState)
587cdf0e10cSrcweir {
588cdf0e10cSrcweir SfxTabPage* pFirstPage;
589cdf0e10cSrcweir OGenericAdministrationPage* pPage = NULL;
590cdf0e10cSrcweir switch(_nState)
591cdf0e10cSrcweir {
592cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_INTRO:
593cdf0e10cSrcweir pFirstPage = OGeneralPage::Create(this,*m_pOutSet, sal_True);
594cdf0e10cSrcweir pPage = static_cast<OGenericAdministrationPage*> (pFirstPage);
595cdf0e10cSrcweir m_pGeneralPage = static_cast<OGeneralPage*>(pFirstPage);
596cdf0e10cSrcweir m_pGeneralPage->SetTypeSelectHandler(LINK(this, ODbTypeWizDialogSetup, OnTypeSelected));
597cdf0e10cSrcweir m_pGeneralPage->SetCreationModeHandler(LINK( this, ODbTypeWizDialogSetup, OnChangeCreationMode ) );
598cdf0e10cSrcweir m_pGeneralPage->SetDocumentSelectionHandler(LINK( this, ODbTypeWizDialogSetup, OnRecentDocumentSelected ) );
599cdf0e10cSrcweir m_pGeneralPage->SetChooseDocumentHandler(LINK( this, ODbTypeWizDialogSetup, OnSingleDocumentChosen ) );
600cdf0e10cSrcweir break;
601cdf0e10cSrcweir
602cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_DBASE:
603cdf0e10cSrcweir pPage = OConnectionTabPageSetup::CreateDbaseTabPage(this,*m_pOutSet);
604cdf0e10cSrcweir break;
605cdf0e10cSrcweir
606cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ADO:
607cdf0e10cSrcweir pPage = OConnectionTabPageSetup::CreateADOTabPage( this, *m_pOutSet);
608cdf0e10cSrcweir break;
609cdf0e10cSrcweir
610cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_TEXT:
611cdf0e10cSrcweir pPage = OTextConnectionPageSetup::CreateTextTabPage(this,*m_pOutSet);
612cdf0e10cSrcweir break;
613cdf0e10cSrcweir
614cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ODBC:
615cdf0e10cSrcweir pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
616cdf0e10cSrcweir break;
617cdf0e10cSrcweir
618cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_JDBC:
619cdf0e10cSrcweir pPage = OJDBCConnectionPageSetup::CreateJDBCTabPage( this, *m_pOutSet);
620cdf0e10cSrcweir break;
621cdf0e10cSrcweir
622cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
623cdf0e10cSrcweir m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:")))));
624cdf0e10cSrcweir pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
625cdf0e10cSrcweir break;
626cdf0e10cSrcweir
627cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
628cdf0e10cSrcweir m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:")))));
629cdf0e10cSrcweir pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLJDBCTabPage( this, *m_pOutSet);
630cdf0e10cSrcweir break;
631cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
632cdf0e10cSrcweir m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")))));
633cdf0e10cSrcweir pPage = MySQLNativeSetupPage::Create( this, *m_pOutSet);
634cdf0e10cSrcweir break;
635cdf0e10cSrcweir
636cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ORACLE:
637cdf0e10cSrcweir pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage( this, *m_pOutSet);
638cdf0e10cSrcweir break;
639cdf0e10cSrcweir
640cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_ADABAS:
641cdf0e10cSrcweir pPage = OConnectionTabPageSetup::CreateAdabasTabPage( this, *m_pOutSet);
642cdf0e10cSrcweir break;
643cdf0e10cSrcweir
644cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_LDAP :
645cdf0e10cSrcweir pPage = OLDAPConnectionPageSetup::CreateLDAPTabPage(this,*m_pOutSet);
646cdf0e10cSrcweir break;
647cdf0e10cSrcweir
648cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_SPREADSHEET: /// first user defined driver
649cdf0e10cSrcweir pPage = OSpreadSheetConnectionPageSetup::CreateSpreadSheetTabPage(this,*m_pOutSet);
650cdf0e10cSrcweir break;
651cdf0e10cSrcweir
652cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MSACCESS:
653cdf0e10cSrcweir pPage = OConnectionTabPageSetup::CreateMSAccessTabPage(this,*m_pOutSet);
654cdf0e10cSrcweir break;
655cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
656cdf0e10cSrcweir m_pMySQLIntroPage = OMySQLIntroPageSetup::CreateMySQLIntroTabPage(this,*m_pOutSet);
657cdf0e10cSrcweir m_pMySQLIntroPage->SetClickHdl(LINK( this, ODbTypeWizDialogSetup, ImplClickHdl ) );
658cdf0e10cSrcweir pPage = m_pMySQLIntroPage;
659cdf0e10cSrcweir break;
660cdf0e10cSrcweir
661cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
662cdf0e10cSrcweir pPage = OAuthentificationPageSetup::CreateAuthentificationTabPage(this,*m_pOutSet);
663cdf0e10cSrcweir break;
664cdf0e10cSrcweir
665cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_USERDEFINED:
666cdf0e10cSrcweir pPage = OConnectionTabPageSetup::CreateUserDefinedTabPage(this,*m_pOutSet);
667cdf0e10cSrcweir break;
668cdf0e10cSrcweir
669cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_FINAL:
670cdf0e10cSrcweir pPage = OFinalDBPageSetup::CreateFinalDBTabPageSetup(this,*m_pOutSet);
671cdf0e10cSrcweir pFinalPage = static_cast<OFinalDBPageSetup*> (pPage);
672cdf0e10cSrcweir break;
673cdf0e10cSrcweir }
674cdf0e10cSrcweir
675cdf0e10cSrcweir if ((_nState != PAGE_DBSETUPWIZARD_INTRO) && (_nState != PAGE_DBSETUPWIZARD_AUTHENTIFICATION))
676cdf0e10cSrcweir {
677cdf0e10cSrcweir pPage->SetModifiedHandler(LINK( this, ODbTypeWizDialogSetup, ImplModifiedHdl ) );
678cdf0e10cSrcweir }
679cdf0e10cSrcweir
680cdf0e10cSrcweir if ( pPage )
681cdf0e10cSrcweir {
682cdf0e10cSrcweir pPage->SetServiceFactory(m_pImpl->getORB());
683cdf0e10cSrcweir pPage->SetAdminDialog(this, this);
684cdf0e10cSrcweir
685cdf0e10cSrcweir defaultButton( _nState == PAGE_DBSETUPWIZARD_FINAL ? WZB_FINISH : WZB_NEXT );
686cdf0e10cSrcweir enableButtons( WZB_FINISH, _nState == PAGE_DBSETUPWIZARD_FINAL );
687cdf0e10cSrcweir enableButtons( WZB_NEXT, _nState == PAGE_DBSETUPWIZARD_FINAL ? sal_False : sal_True);
688cdf0e10cSrcweir pPage->Show();
689cdf0e10cSrcweir }
690cdf0e10cSrcweir return pPage;
691cdf0e10cSrcweir }
692cdf0e10cSrcweir
693cdf0e10cSrcweir
IMPL_LINK(ODbTypeWizDialogSetup,ImplModifiedHdl,OGenericAdministrationPage *,_pConnectionPageSetup)694cdf0e10cSrcweir IMPL_LINK(ODbTypeWizDialogSetup, ImplModifiedHdl, OGenericAdministrationPage*, _pConnectionPageSetup)
695cdf0e10cSrcweir {
696cdf0e10cSrcweir m_bIsConnectable = _pConnectionPageSetup->GetRoadmapStateValue( );
697cdf0e10cSrcweir enableState(PAGE_DBSETUPWIZARD_FINAL, m_bIsConnectable);
698cdf0e10cSrcweir enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, m_bIsConnectable);
699cdf0e10cSrcweir if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
700cdf0e10cSrcweir enableButtons( WZB_FINISH, sal_True);
701cdf0e10cSrcweir else
702cdf0e10cSrcweir enableButtons( WZB_FINISH, m_bIsConnectable);
703cdf0e10cSrcweir enableButtons( WZB_NEXT, m_bIsConnectable && (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL));
704cdf0e10cSrcweir return sal_True;
705cdf0e10cSrcweir }
706cdf0e10cSrcweir
707cdf0e10cSrcweir
708cdf0e10cSrcweir // -----------------------------------------------------------------------------
IMPL_LINK(ODbTypeWizDialogSetup,ImplClickHdl,OMySQLIntroPageSetup *,_pMySQLIntroPageSetup)709cdf0e10cSrcweir IMPL_LINK(ODbTypeWizDialogSetup, ImplClickHdl, OMySQLIntroPageSetup*, _pMySQLIntroPageSetup)
710cdf0e10cSrcweir {
711cdf0e10cSrcweir ::rtl::OUString sURLPrefix;
712cdf0e10cSrcweir switch( _pMySQLIntroPageSetup->getMySQLMode() )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_ODBC:
715cdf0e10cSrcweir sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
716cdf0e10cSrcweir break;
717cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_JDBC:
718cdf0e10cSrcweir sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
719cdf0e10cSrcweir break;
720cdf0e10cSrcweir case OMySQLIntroPageSetup::VIA_NATIVE:
721cdf0e10cSrcweir sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
722cdf0e10cSrcweir break;
723cdf0e10cSrcweir } // switch( _pMySQLIntroPageSetup->getMySQLMode() )
724cdf0e10cSrcweir activatePath( static_cast<PathId>(m_pCollection->getIndexOf(sURLPrefix) + 1), sal_True);
725cdf0e10cSrcweir return sal_True;
726cdf0e10cSrcweir }
727cdf0e10cSrcweir
728cdf0e10cSrcweir // -----------------------------------------------------------------------------
729cdf0e10cSrcweir IMPL_LINK(ODbTypeWizDialogSetup, OnChangeCreationMode, OGeneralPage*, /*_pGeneralPage*/)
730cdf0e10cSrcweir {
731cdf0e10cSrcweir activateDatabasePath();
732cdf0e10cSrcweir return sal_True;
733cdf0e10cSrcweir }
734cdf0e10cSrcweir
735cdf0e10cSrcweir // -----------------------------------------------------------------------------
736cdf0e10cSrcweir IMPL_LINK(ODbTypeWizDialogSetup, OnRecentDocumentSelected, OGeneralPage*, /*_pGeneralPage*/)
737cdf0e10cSrcweir {
738cdf0e10cSrcweir enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
739cdf0e10cSrcweir return 0L;
740cdf0e10cSrcweir }
741cdf0e10cSrcweir
742cdf0e10cSrcweir // -----------------------------------------------------------------------------
743cdf0e10cSrcweir IMPL_LINK(ODbTypeWizDialogSetup, OnSingleDocumentChosen, OGeneralPage*, /*_pGeneralPage*/)
744cdf0e10cSrcweir {
745cdf0e10cSrcweir if ( prepareLeaveCurrentState( eFinish ) )
746cdf0e10cSrcweir onFinish();
747cdf0e10cSrcweir return 0L;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir
750cdf0e10cSrcweir // -----------------------------------------------------------------------------
enterState(WizardState _nState)751cdf0e10cSrcweir void ODbTypeWizDialogSetup::enterState(WizardState _nState)
752cdf0e10cSrcweir {
753cdf0e10cSrcweir m_sURL = m_pImpl->getDatasourceType(*m_pOutSet);
754cdf0e10cSrcweir RoadmapWizard::enterState(_nState);
755cdf0e10cSrcweir switch(_nState)
756cdf0e10cSrcweir {
757cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_INTRO:
758cdf0e10cSrcweir m_sOldURL = m_sURL;
759cdf0e10cSrcweir break;
760cdf0e10cSrcweir case PAGE_DBSETUPWIZARD_FINAL:
761cdf0e10cSrcweir enableButtons( WZB_FINISH, sal_True);
762cdf0e10cSrcweir if ( pFinalPage )
763cdf0e10cSrcweir pFinalPage->enableTableWizardCheckBox(m_pCollection->supportsTableCreation(m_sURL));
764cdf0e10cSrcweir break;
765cdf0e10cSrcweir }
766cdf0e10cSrcweir }
767cdf0e10cSrcweir
768cdf0e10cSrcweir //-------------------------------------------------------------------------
saveDatasource()769cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::saveDatasource()
770cdf0e10cSrcweir {
771cdf0e10cSrcweir SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
772cdf0e10cSrcweir if ( pPage )
773cdf0e10cSrcweir pPage->FillItemSet(*m_pOutSet);
774cdf0e10cSrcweir return sal_True;
775cdf0e10cSrcweir }
776cdf0e10cSrcweir
777cdf0e10cSrcweir
778cdf0e10cSrcweir // -----------------------------------------------------------------------------
leaveState(WizardState _nState)779cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::leaveState(WizardState _nState)
780cdf0e10cSrcweir {
781cdf0e10cSrcweir if (_nState == PAGE_DBSETUPWIZARD_MYSQL_INTRO)
782cdf0e10cSrcweir return sal_True;
783cdf0e10cSrcweir if ( _nState == PAGE_DBSETUPWIZARD_INTRO && m_sURL != m_sOldURL )
784cdf0e10cSrcweir {
785cdf0e10cSrcweir resetPages(m_pImpl->getCurrentDataSource());
786cdf0e10cSrcweir }
787cdf0e10cSrcweir SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
788cdf0e10cSrcweir return pPage && pPage->DeactivatePage(m_pOutSet) != 0;
789cdf0e10cSrcweir }
790cdf0e10cSrcweir
791cdf0e10cSrcweir // -----------------------------------------------------------------------------
setTitle(const::rtl::OUString &)792cdf0e10cSrcweir void ODbTypeWizDialogSetup::setTitle(const ::rtl::OUString& /*_sTitle*/)
793cdf0e10cSrcweir {
794cdf0e10cSrcweir DBG_ERROR( "ODbTypeWizDialogSetup::setTitle: not implemented!" );
795cdf0e10cSrcweir // why?
796cdf0e10cSrcweir }
797cdf0e10cSrcweir
798cdf0e10cSrcweir //-------------------------------------------------------------------------
enableConfirmSettings(bool _bEnable)799cdf0e10cSrcweir void ODbTypeWizDialogSetup::enableConfirmSettings( bool _bEnable )
800cdf0e10cSrcweir {
801cdf0e10cSrcweir (void)_bEnable;
802cdf0e10cSrcweir }
803cdf0e10cSrcweir
804cdf0e10cSrcweir //-------------------------------------------------------------------------
805cdf0e10cSrcweir namespace
806cdf0e10cSrcweir {
lcl_handle(const Reference<XInteractionHandler2> & _rxHandler,const Any & _rRequest)807cdf0e10cSrcweir bool lcl_handle( const Reference< XInteractionHandler2 >& _rxHandler, const Any& _rRequest )
808cdf0e10cSrcweir {
809cdf0e10cSrcweir OInteractionRequest* pRequest = new OInteractionRequest( _rRequest );
810cdf0e10cSrcweir Reference < XInteractionRequest > xRequest( pRequest );
811cdf0e10cSrcweir OInteractionAbort* pAbort = new OInteractionAbort;
812cdf0e10cSrcweir pRequest->addContinuation( pAbort );
813cdf0e10cSrcweir
814cdf0e10cSrcweir return _rxHandler->handleInteractionRequest( xRequest );
815cdf0e10cSrcweir }
816cdf0e10cSrcweir }
817cdf0e10cSrcweir
818cdf0e10cSrcweir //-------------------------------------------------------------------------
SaveDatabaseDocument()819cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument()
820cdf0e10cSrcweir {
821cdf0e10cSrcweir Reference< XInteractionHandler2 > xHandler( getORB()->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY );
822cdf0e10cSrcweir try
823cdf0e10cSrcweir {
824cdf0e10cSrcweir if (callSaveAsDialog() == sal_True)
825cdf0e10cSrcweir {
826cdf0e10cSrcweir m_pImpl->saveChanges(*m_pOutSet);
827cdf0e10cSrcweir Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
828cdf0e10cSrcweir Reference< XModel > xModel( getDataSourceOrModel( xDatasource ), UNO_QUERY_THROW );
829cdf0e10cSrcweir Reference< XStorable > xStore( xModel, UNO_QUERY_THROW );
830cdf0e10cSrcweir
831cdf0e10cSrcweir if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eCreateNew )
832cdf0e10cSrcweir CreateDatabase();
833cdf0e10cSrcweir
834cdf0e10cSrcweir ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
835cdf0e10cSrcweir aArgs.put( "Overwrite", sal_Bool( sal_True ) );
836cdf0e10cSrcweir aArgs.put( "InteractionHandler", xHandler );
837cdf0e10cSrcweir aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
838cdf0e10cSrcweir
839cdf0e10cSrcweir ::rtl::OUString sPath = m_pImpl->getDocumentUrl( *m_pOutSet );
840cdf0e10cSrcweir xStore->storeAsURL( sPath, aArgs.getPropertyValues() );
841cdf0e10cSrcweir
842cdf0e10cSrcweir if ( !pFinalPage || pFinalPage->IsDatabaseDocumentToBeRegistered() )
843cdf0e10cSrcweir RegisterDataSourceByLocation( sPath );
844cdf0e10cSrcweir
845cdf0e10cSrcweir return sal_True;
846cdf0e10cSrcweir }
847cdf0e10cSrcweir }
848cdf0e10cSrcweir catch ( const Exception& e )
849cdf0e10cSrcweir {
850cdf0e10cSrcweir Any aError = ::cppu::getCaughtException();
851cdf0e10cSrcweir if ( xHandler.is() )
852cdf0e10cSrcweir {
853cdf0e10cSrcweir if ( !lcl_handle( xHandler, aError ) )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir InteractiveIOException aRequest;
856cdf0e10cSrcweir aRequest.Classification = InteractionClassification_ERROR;
857cdf0e10cSrcweir if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) )
858cdf0e10cSrcweir // assume savint the document faile
859cdf0e10cSrcweir aRequest.Code = IOErrorCode_CANT_WRITE;
860cdf0e10cSrcweir else
861cdf0e10cSrcweir aRequest.Code = IOErrorCode_GENERAL;
862cdf0e10cSrcweir aRequest.Message = e.Message;
863cdf0e10cSrcweir aRequest.Context = e.Context;
864cdf0e10cSrcweir lcl_handle( xHandler, makeAny( aRequest ) );
865cdf0e10cSrcweir }
866cdf0e10cSrcweir }
867cdf0e10cSrcweir }
868cdf0e10cSrcweir return sal_False;
869cdf0e10cSrcweir }
870cdf0e10cSrcweir // ------------------------------------------------------------------------
IsDatabaseDocumentToBeOpened() const871cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::IsDatabaseDocumentToBeOpened() const
872cdf0e10cSrcweir {
873cdf0e10cSrcweir if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
874cdf0e10cSrcweir return sal_True;
875cdf0e10cSrcweir
876cdf0e10cSrcweir if ( pFinalPage != NULL )
877cdf0e10cSrcweir return pFinalPage->IsDatabaseDocumentToBeOpened();
878cdf0e10cSrcweir
879cdf0e10cSrcweir return sal_True;
880cdf0e10cSrcweir }
881cdf0e10cSrcweir
882cdf0e10cSrcweir // ------------------------------------------------------------------------
IsTableWizardToBeStarted() const883cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::IsTableWizardToBeStarted() const
884cdf0e10cSrcweir {
885cdf0e10cSrcweir if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
886cdf0e10cSrcweir return sal_False;
887cdf0e10cSrcweir
888cdf0e10cSrcweir if ( pFinalPage != NULL )
889cdf0e10cSrcweir return pFinalPage->IsTableWizardToBeStarted();
890cdf0e10cSrcweir
891cdf0e10cSrcweir return sal_False;
892cdf0e10cSrcweir }
893cdf0e10cSrcweir
894cdf0e10cSrcweir //-------------------------------------------------------------------------
getDefaultDatabaseType() const895cdf0e10cSrcweir ::rtl::OUString ODbTypeWizDialogSetup::getDefaultDatabaseType() const
896cdf0e10cSrcweir {
897cdf0e10cSrcweir ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase();
898cdf0e10cSrcweir ::connectivity::DriversConfig aDriverConfig(getORB());
899cdf0e10cSrcweir try
900cdf0e10cSrcweir {
901cdf0e10cSrcweir if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || !m_pImpl->getDriver(sEmbeddedURL).is() )
902cdf0e10cSrcweir sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
903cdf0e10cSrcweir }
904cdf0e10cSrcweir catch(const Exception&)
905cdf0e10cSrcweir {
906cdf0e10cSrcweir sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
907cdf0e10cSrcweir }
908cdf0e10cSrcweir
909cdf0e10cSrcweir return sEmbeddedURL;
910cdf0e10cSrcweir }
911cdf0e10cSrcweir
912cdf0e10cSrcweir //-------------------------------------------------------------------------
CreateDatabase()913cdf0e10cSrcweir void ODbTypeWizDialogSetup::CreateDatabase()
914cdf0e10cSrcweir {
915cdf0e10cSrcweir ::rtl::OUString sUrl;
916cdf0e10cSrcweir ::rtl::OUString eType = getDefaultDatabaseType();
917cdf0e10cSrcweir if ( m_pCollection->isEmbeddedDatabase(eType) )
918cdf0e10cSrcweir {
919cdf0e10cSrcweir sUrl = eType;
920cdf0e10cSrcweir Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
921cdf0e10cSrcweir OSL_ENSURE(xDatasource.is(),"DataSource is null!");
922cdf0e10cSrcweir if ( xDatasource.is() )
923cdf0e10cSrcweir xDatasource->setPropertyValue( PROPERTY_INFO, makeAny( m_pCollection->getDefaultDBSettings( eType ) ) );
924cdf0e10cSrcweir m_pImpl->translateProperties(xDatasource,*m_pOutSet);
925cdf0e10cSrcweir }
926cdf0e10cSrcweir else if ( m_pCollection->isFileSystemBased(eType) )
927cdf0e10cSrcweir {
928cdf0e10cSrcweir Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
929cdf0e10cSrcweir INetURLObject aDBPathURL(m_sWorkPath);
930cdf0e10cSrcweir aDBPathURL.Append(m_aDocURL.getBase());
931cdf0e10cSrcweir createUniqueFolderName(&aDBPathURL);
932cdf0e10cSrcweir ::rtl::OUString sPrefix = eType;
933cdf0e10cSrcweir sUrl = aDBPathURL.GetMainURL( INetURLObject::NO_DECODE);
934cdf0e10cSrcweir xSimpleFileAccess->createFolder(sUrl);
935cdf0e10cSrcweir //OFileNotation aFileNotation(sUrl);
936cdf0e10cSrcweir //sUrl = aFileNotation.get(OFileNotation::N_SYSTEM);
937cdf0e10cSrcweir sUrl = sPrefix.concat(sUrl);
938cdf0e10cSrcweir }
939cdf0e10cSrcweir m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, sUrl));
940cdf0e10cSrcweir m_pImpl->saveChanges(*m_pOutSet);
941cdf0e10cSrcweir }
942cdf0e10cSrcweir
943cdf0e10cSrcweir //-------------------------------------------------------------------------
RegisterDataSourceByLocation(const::rtl::OUString & _sPath)944cdf0e10cSrcweir void ODbTypeWizDialogSetup::RegisterDataSourceByLocation(const ::rtl::OUString& _sPath)
945cdf0e10cSrcweir {
946cdf0e10cSrcweir Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
947cdf0e10cSrcweir Reference< XNamingService > xDatabaseContext(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
948cdf0e10cSrcweir Reference< XNameAccess > xNameAccessDatabaseContext(xDatabaseContext, UNO_QUERY);
949cdf0e10cSrcweir INetURLObject aURL( _sPath );
950cdf0e10cSrcweir ::rtl::OUString sFilename = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
951cdf0e10cSrcweir ::rtl::OUString sDatabaseName = ::dbtools::createUniqueName(xNameAccessDatabaseContext, sFilename,sal_False);
952cdf0e10cSrcweir xDatabaseContext->registerObject(sDatabaseName, xDatasource);
953cdf0e10cSrcweir }
954cdf0e10cSrcweir
955cdf0e10cSrcweir
956cdf0e10cSrcweir //-------------------------------------------------------------------------
callSaveAsDialog()957cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::callSaveAsDialog()
958cdf0e10cSrcweir {
959cdf0e10cSrcweir sal_Bool bRet = sal_False;
960cdf0e10cSrcweir WinBits nBits(WB_STDMODAL|WB_SAVEAS);
961cdf0e10cSrcweir ::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, static_cast<sal_uInt32>(nBits), this);
962cdf0e10cSrcweir const SfxFilter* pFilter = getStandardDatabaseFilter();
963cdf0e10cSrcweir if ( pFilter )
964cdf0e10cSrcweir {
965cdf0e10cSrcweir INetURLObject aWorkURL( m_sWorkPath );
966cdf0e10cSrcweir aFileDlg.SetDisplayFolder( aWorkURL.GetMainURL( INetURLObject::NO_DECODE ));
967cdf0e10cSrcweir
968cdf0e10cSrcweir ::rtl::OUString sDefaultName = String( ModuleRes( STR_DATABASEDEFAULTNAME ) );
969cdf0e10cSrcweir ::rtl::OUString sExtension = pFilter->GetDefaultExtension();
970cdf0e10cSrcweir sDefaultName += sExtension.replaceAt( 0, 1, ::rtl::OUString() );
971cdf0e10cSrcweir aWorkURL.Append( sDefaultName );
972cdf0e10cSrcweir sDefaultName = createUniqueFileName( aWorkURL );
973cdf0e10cSrcweir aFileDlg.SetFileName( sDefaultName );
974cdf0e10cSrcweir
975cdf0e10cSrcweir aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
976cdf0e10cSrcweir aFileDlg.SetCurrentFilter(pFilter->GetUIName());
977cdf0e10cSrcweir }
978cdf0e10cSrcweir if ( aFileDlg.Execute() == ERRCODE_NONE )
979cdf0e10cSrcweir {
980cdf0e10cSrcweir m_aDocURL = INetURLObject(aFileDlg.GetPath());
981cdf0e10cSrcweir
982cdf0e10cSrcweir if( m_aDocURL.GetProtocol() != INET_PROT_NOT_VALID )
983cdf0e10cSrcweir {
984cdf0e10cSrcweir ::rtl::OUString sFileName = m_aDocURL.GetMainURL( INetURLObject::NO_DECODE );
985cdf0e10cSrcweir if ( ::utl::UCBContentHelper::IsDocument(sFileName) )
986cdf0e10cSrcweir ::utl::UCBContentHelper::Kill(sFileName);
987cdf0e10cSrcweir m_pOutSet->Put(SfxStringItem(DSID_DOCUMENT_URL, sFileName));
988cdf0e10cSrcweir bRet = sal_True;
989cdf0e10cSrcweir }
990cdf0e10cSrcweir }
991cdf0e10cSrcweir return bRet;
992cdf0e10cSrcweir }
993cdf0e10cSrcweir
994cdf0e10cSrcweir //-------------------------------------------------------------------------
createUniqueFolderName(INetURLObject * pURL)995cdf0e10cSrcweir void ODbTypeWizDialogSetup::createUniqueFolderName(INetURLObject* pURL)
996cdf0e10cSrcweir {
997cdf0e10cSrcweir Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
998cdf0e10cSrcweir :: rtl::OUString sLastSegmentName = pURL->getName();
999cdf0e10cSrcweir sal_Bool bFolderExists = sal_True;
1000cdf0e10cSrcweir sal_Int32 i = 1;
1001cdf0e10cSrcweir while (bFolderExists == sal_True)
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir bFolderExists = xSimpleFileAccess->isFolder(pURL->GetMainURL( INetURLObject::NO_DECODE ));
1004cdf0e10cSrcweir if (bFolderExists == sal_True)
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir i++;
1007cdf0e10cSrcweir pURL->setName(sLastSegmentName.concat(::rtl::OUString::valueOf(i)));
1008cdf0e10cSrcweir }
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir
1012cdf0e10cSrcweir //-------------------------------------------------------------------------
createUniqueFileName(const INetURLObject & _rURL)1013cdf0e10cSrcweir String ODbTypeWizDialogSetup::createUniqueFileName(const INetURLObject& _rURL)
1014cdf0e10cSrcweir {
1015cdf0e10cSrcweir Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
1016cdf0e10cSrcweir :: rtl::OUString sFilename = _rURL.getName();
1017cdf0e10cSrcweir ::rtl::OUString BaseName = _rURL.getBase();
1018cdf0e10cSrcweir ::rtl::OUString sExtension = _rURL.getExtension();
1019cdf0e10cSrcweir
1020cdf0e10cSrcweir sal_Bool bElementExists = sal_True;
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir INetURLObject aExistenceCheck( _rURL );
1023cdf0e10cSrcweir for ( sal_Int32 i = 1; bElementExists; )
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir bElementExists = xSimpleFileAccess->exists( aExistenceCheck.GetMainURL( INetURLObject::NO_DECODE ) );
1026cdf0e10cSrcweir if ( bElementExists )
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir aExistenceCheck.setBase( BaseName.concat( ::rtl::OUString::valueOf( i ) ) );
1029cdf0e10cSrcweir ++i;
1030cdf0e10cSrcweir }
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir return aExistenceCheck.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1033cdf0e10cSrcweir }
1034cdf0e10cSrcweir // -----------------------------------------------------------------------------
getPageController(TabPage * _pCurrentPage) const1035cdf0e10cSrcweir IWizardPageController* ODbTypeWizDialogSetup::getPageController( TabPage* _pCurrentPage ) const
1036cdf0e10cSrcweir {
1037cdf0e10cSrcweir OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
1038cdf0e10cSrcweir return pPage;
1039cdf0e10cSrcweir }
1040cdf0e10cSrcweir
1041cdf0e10cSrcweir // -----------------------------------------------------------------------------
1042cdf0e10cSrcweir namespace
1043cdf0e10cSrcweir {
1044cdf0e10cSrcweir // .............................................................................
1045cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1 < XTerminateListener
1046cdf0e10cSrcweir > AsyncLoader_Base;
1047cdf0e10cSrcweir class AsyncLoader : public AsyncLoader_Base
1048cdf0e10cSrcweir {
1049cdf0e10cSrcweir private:
1050cdf0e10cSrcweir Reference< XComponentLoader > m_xFrameLoader;
1051cdf0e10cSrcweir Reference< XDesktop > m_xDesktop;
1052cdf0e10cSrcweir Reference< XInteractionHandler > m_xInteractionHandler;
1053cdf0e10cSrcweir ::rtl::OUString m_sURL;
1054cdf0e10cSrcweir OAsyncronousLink m_aAsyncCaller;
1055cdf0e10cSrcweir
1056cdf0e10cSrcweir public:
1057cdf0e10cSrcweir AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL );
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir void doLoadAsync();
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir // XTerminateListener
1062*b63233d8Sdamjan virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (TerminationVetoException, RuntimeException);
1063*b63233d8Sdamjan virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (RuntimeException);
1064cdf0e10cSrcweir // XEventListener
1065cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
1066cdf0e10cSrcweir
1067cdf0e10cSrcweir private:
1068cdf0e10cSrcweir DECL_LINK( OnOpenDocument, void* );
1069cdf0e10cSrcweir };
1070cdf0e10cSrcweir
1071cdf0e10cSrcweir // .............................................................................
AsyncLoader(const Reference<XMultiServiceFactory> & _rxORB,const::rtl::OUString & _rURL)1072cdf0e10cSrcweir AsyncLoader::AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL )
1073cdf0e10cSrcweir :m_sURL( _rURL )
1074cdf0e10cSrcweir ,m_aAsyncCaller( LINK( this, AsyncLoader, OnOpenDocument ) )
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir try
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir m_xDesktop.set( _rxORB->createInstance( SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW );
1079cdf0e10cSrcweir m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW );
1080cdf0e10cSrcweir m_xInteractionHandler.set(
1081cdf0e10cSrcweir _rxORB->createInstance(
1082cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) )
1083cdf0e10cSrcweir ),
1084cdf0e10cSrcweir UNO_QUERY_THROW );
1085cdf0e10cSrcweir }
1086cdf0e10cSrcweir catch( const Exception& )
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir
1092cdf0e10cSrcweir // .............................................................................
doLoadAsync()1093cdf0e10cSrcweir void AsyncLoader::doLoadAsync()
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir OSL_ENSURE( !m_aAsyncCaller.IsRunning(), "AsyncLoader:doLoadAsync: already running!" );
1096cdf0e10cSrcweir
1097cdf0e10cSrcweir acquire();
1098cdf0e10cSrcweir try
1099cdf0e10cSrcweir {
1100cdf0e10cSrcweir if ( m_xDesktop.is() )
1101cdf0e10cSrcweir m_xDesktop->addTerminateListener( this );
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1104cdf0e10cSrcweir
1105cdf0e10cSrcweir m_aAsyncCaller.Call( NULL );
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir
1108cdf0e10cSrcweir // .............................................................................
1109cdf0e10cSrcweir IMPL_LINK( AsyncLoader, OnOpenDocument, void*, /*_pEmptyArg*/ )
1110cdf0e10cSrcweir {
1111cdf0e10cSrcweir try
1112cdf0e10cSrcweir {
1113cdf0e10cSrcweir if ( m_xFrameLoader.is() )
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir ::comphelper::NamedValueCollection aLoadArgs;
1116cdf0e10cSrcweir aLoadArgs.put( "InteractionHandler", m_xInteractionHandler );
1117cdf0e10cSrcweir aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
1118cdf0e10cSrcweir
1119cdf0e10cSrcweir Sequence< PropertyValue > aLoadArgPV;
1120cdf0e10cSrcweir aLoadArgs >>= aLoadArgPV;
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir m_xFrameLoader->loadComponentFromURL( m_sURL,
1123cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ),
1124cdf0e10cSrcweir FrameSearchFlag::ALL,
1125cdf0e10cSrcweir aLoadArgPV
1126cdf0e10cSrcweir );
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir catch( const Exception& )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir // do not assert.
1132cdf0e10cSrcweir // Such an exception happens for instance of the to-be-loaded document does not exist anymore.
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir
1135cdf0e10cSrcweir try
1136cdf0e10cSrcweir {
1137cdf0e10cSrcweir if ( m_xDesktop.is() )
1138cdf0e10cSrcweir m_xDesktop->removeTerminateListener( this );
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1141cdf0e10cSrcweir
1142cdf0e10cSrcweir release();
1143cdf0e10cSrcweir return 0L;
1144cdf0e10cSrcweir }
1145cdf0e10cSrcweir
1146cdf0e10cSrcweir // .............................................................................
queryTermination(const::com::sun::star::lang::EventObject &)1147*b63233d8Sdamjan void SAL_CALL AsyncLoader::queryTermination( const ::com::sun::star::lang::EventObject& /*Event*/ ) throw (TerminationVetoException, RuntimeException)
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir throw TerminationVetoException();
1150cdf0e10cSrcweir }
1151cdf0e10cSrcweir
1152cdf0e10cSrcweir // .............................................................................
notifyTermination(const::com::sun::star::lang::EventObject &)1153*b63233d8Sdamjan void SAL_CALL AsyncLoader::notifyTermination( const ::com::sun::star::lang::EventObject& /*Event*/ ) throw (RuntimeException)
1154cdf0e10cSrcweir {
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir // .............................................................................
disposing(const::com::sun::star::lang::EventObject &)1157*b63233d8Sdamjan void SAL_CALL AsyncLoader::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (RuntimeException)
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir
1162cdf0e10cSrcweir // -----------------------------------------------------------------------------
onFinish()1163cdf0e10cSrcweir sal_Bool ODbTypeWizDialogSetup::onFinish()
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir // we're not going to re-use the XModel we have - since the document the user
1168cdf0e10cSrcweir // wants us to load could be a non-database document. Instead, we asynchronously
1169cdf0e10cSrcweir // open the selected document. Thus, the wizard's return value is RET_CANCEL,
1170cdf0e10cSrcweir // which means to not continue loading the database document
1171cdf0e10cSrcweir if ( !OWizardMachine::Finnish( RET_CANCEL ) )
1172cdf0e10cSrcweir return sal_False;
1173cdf0e10cSrcweir
1174cdf0e10cSrcweir Reference< XComponentLoader > xFrameLoader;
1175cdf0e10cSrcweir try
1176cdf0e10cSrcweir {
1177cdf0e10cSrcweir AsyncLoader* pAsyncLoader = new AsyncLoader( getORB(), m_pGeneralPage->GetSelectedDocument().sURL );
1178cdf0e10cSrcweir ::rtl::Reference< AsyncLoader > xKeepAlive( pAsyncLoader );
1179cdf0e10cSrcweir pAsyncLoader->doLoadAsync();
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir catch( const Exception& )
1182cdf0e10cSrcweir {
1183cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1184cdf0e10cSrcweir }
1185cdf0e10cSrcweir
1186cdf0e10cSrcweir return sal_True;
1187cdf0e10cSrcweir }
1188cdf0e10cSrcweir
1189cdf0e10cSrcweir if (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL)
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir skipUntil(PAGE_DBSETUPWIZARD_FINAL);
1192cdf0e10cSrcweir }
1193cdf0e10cSrcweir if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
1194cdf0e10cSrcweir return SaveDatabaseDocument() ? OWizardMachine::onFinish() : sal_False;
1195cdf0e10cSrcweir else
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir enableButtons( WZB_FINISH, sal_False );
1198cdf0e10cSrcweir return sal_False;
1199cdf0e10cSrcweir }
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir //.........................................................................
1203cdf0e10cSrcweir } // namespace dbaui
1204cdf0e10cSrcweir //.........................................................................
1205cdf0e10cSrcweir
1206