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 #ifndef DBAUI_DBWIZ2_HXX
25 #define DBAUI_DBWIZ2_HXX
26 
27 #ifndef _SFXTABDLG_HXX
28 #include <sfx2/tabdlg.hxx>
29 #endif
30 #ifndef _DBAUI_DSNTYPES_HXX_
31 #include "dsntypes.hxx"
32 #endif
33 #ifndef DBAUI_ITEMSETHELPER_HXX
34 #include "IItemSetHelper.hxx"
35 #endif
36 #ifndef _COMPHELPER_UNO3_HXX_
37 #include <comphelper/uno3.hxx>
38 #endif
39 #ifndef _URLOBJ_HXX
40 #include <tools/urlobj.hxx>
41 #endif
42 #include <memory>
43 #ifndef SVTOOLS_INC_ROADMAPWIZARD_HXX
44 #include <svtools/roadmapwizard.hxx>
45 #endif
46 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
47 #include <connectivity/dbtools.hxx>
48 #endif
49 #ifndef _DBAUI_MODULE_DBU_HXX_
50 #include "moduledbu.hxx"
51 #endif
52 
53 FORWARD_DECLARE_INTERFACE(beans,XPropertySet)
54 FORWARD_DECLARE_INTERFACE(sdbc,XConnection)
55 FORWARD_DECLARE_INTERFACE(lang,XMultiServiceFactory)
56 
57 //.........................................................................
58 namespace dbaui
59 {
60 //.........................................................................
61 
62 class OGenericAdministrationPage;
63 
64 //=========================================================================
65 //= ODbTypeWizDialogSetup
66 //=========================================================================
67 class OGeneralPage;
68 class ODbDataSourceAdministrationHelper;
69 /** tab dialog for administrating the office wide registered data sources
70 */
71 class OMySQLIntroPageSetup;
72 
73 class ODbTypeWizDialogSetup : public svt::RoadmapWizard , public IItemSetHelper, public IDatabaseSettingsDialog,public dbaui::OModuleClient
74 {
75 
76 private:
77 	OModuleClient m_aModuleClient;
78 	::std::auto_ptr<ODbDataSourceAdministrationHelper>	m_pImpl;
79 	SfxItemSet*				m_pOutSet;
80 	::rtl::OUString         m_sURL;
81     ::rtl::OUString         m_sOldURL;
82 	sal_Bool				m_bResetting : 1;	/// sal_True while we're resetting the pages
83 	sal_Bool				m_bApplied : 1;		/// sal_True if any changes have been applied while the dialog was executing
84 	sal_Bool				m_bUIEnabled : 1;	/// <TRUE/> if the UI is enabled, false otherwise. Cannot be switched back to <TRUE/>, once it is <FALSE/>
85     sal_Bool                m_bIsConnectable : 1;
86     String                  m_sRM_IntroText;
87     String                  m_sRM_dBaseText;
88     String                  m_sRM_TextText;
89     String                  m_sRM_MSAccessText;
90     String                  m_sRM_LDAPText;
91     String                  m_sRM_ADABASText;
92     String                  m_sRM_ADOText;
93     String                  m_sRM_JDBCText;
94     String                  m_sRM_MySQLNativePageTitle;
95     String                  m_sRM_OracleText;
96     String                  m_sRM_MySQLText;
97     String                  m_sRM_ODBCText;
98     String                  m_sRM_SpreadSheetText;
99     String                  m_sRM_AuthentificationText;
100     String                  m_sRM_FinalText;
101     INetURLObject           m_aDocURL;
102     String                  m_sWorkPath;
103     OGeneralPage*           m_pGeneralPage;
104 	OMySQLIntroPageSetup*	m_pMySQLIntroPage;
105     ::dbaccess::ODsnTypeCollection*
106                             m_pCollection;	/// the DSN type collection instance
107 
108 
109 
110 public:
111 	/** ctor. The itemset given should have been created by <method>createItemSet</method> and should be destroyed
112 		after the dialog has been destroyed
113 	*/
114 	ODbTypeWizDialogSetup(Window* pParent
115 		,SfxItemSet* _pItems
116 		,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
117 		,const ::com::sun::star::uno::Any& _aDataSourceName
118 		);
119 	virtual ~ODbTypeWizDialogSetup();
120 
121 	virtual const SfxItemSet* getOutputSet() const;
122 	virtual SfxItemSet* getWriteOutputSet();
123 
124 	// forwards to ODbDataSourceAdministrationHelper
125 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getORB() const;
126 	virtual ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >,sal_Bool> createConnection();
127 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >	getDriver();
128 	virtual ::rtl::OUString getDatasourceType(const SfxItemSet& _rSet) const;
129 	virtual void clearPassword();
130 	virtual void setTitle(const ::rtl::OUString& _sTitle);
131     virtual void enableConfirmSettings( bool _bEnable );
132     virtual sal_Bool saveDatasource();
133     virtual String  getStateDisplayName( WizardState _nState ) const;
134 
135     /** returns <TRUE/> if the database should be opened, otherwise <FALSE/>.
136     */
137     sal_Bool IsDatabaseDocumentToBeOpened() const;
138 
139     /** returns <TRUE/> if the table wizard should be opened, otherwise <FALSE/>.
140     */
141     sal_Bool IsTableWizardToBeStarted() const;
142 
143 protected:
144 	/// to override to create new pages
145 	virtual TabPage*	createPage(WizardState _nState);
146 	virtual	sal_Bool	leaveState(WizardState _nState);
147     virtual void enterState(WizardState _nState);
148 	virtual ::svt::IWizardPageController* getPageController( TabPage* _pCurrentPage ) const;
149 	virtual sal_Bool onFinish();
150 
151 protected:
isUIEnabled() const152 	inline sal_Bool	isUIEnabled() const { return m_bUIEnabled; }
disabledUI()153 	inline void		disabledUI() { m_bUIEnabled = sal_False; }
154 
155 	/// select a datasource with a given name, adjust the item set accordingly, and everything like that ..
156 	void implSelectDatasource(const ::rtl::OUString& _rRegisteredName);
157 	void resetPages(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDatasource);
158 
159 	enum ApplyResult
160 	{
161 		AR_LEAVE_MODIFIED,		// somthing was modified and has successfully been committed
162 		AR_LEAVE_UNCHANGED,		// no changes were made
163 		AR_KEEP					// don't leave the page (e.g. because an error occured)
164 	};
165 
166 private:
167     /** declares a path with or without authentication, as indicated by the database type
168 
169         @param _sURL
170             the data source type for which the path is declared. If this
171             data source type does not support authentication, the PAGE_DBSETUPWIZARD_AUTHENTIFICATION
172             state will be stripped from the sequence of states.
173         @param _nPathId
174             the ID of the path
175         @path
176             the first state in this path, following by an arbitrary number of others, as in
177             RoadmapWizard::declarePath.
178     */
179     void declareAuthDepPath( const ::rtl::OUString& _sURL, PathId _nPathId, const svt::RoadmapWizardTypes::WizardPath& _rPaths);
180 
181     void RegisterDataSourceByLocation(const ::rtl::OUString& sPath);
182     sal_Bool SaveDatabaseDocument();
183     void activateDatabasePath();
184     String createUniqueFileName(const INetURLObject& rURL);
185     void CreateDatabase();
186     void createUniqueFolderName(INetURLObject* pURL);
187 	::dbaccess::DATASOURCE_TYPE VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType) const;
188 
189     ::rtl::OUString getDefaultDatabaseType() const;
190 
191     void updateTypeDependentStates();
192     sal_Bool callSaveAsDialog();
193     sal_Bool IsConnectionUrlRequired();
194 	DECL_LINK(OnTypeSelected, OGeneralPage*);
195 	DECL_LINK(OnChangeCreationMode, OGeneralPage*);
196     DECL_LINK(OnRecentDocumentSelected, OGeneralPage*);
197     DECL_LINK(OnSingleDocumentChosen, OGeneralPage*);
198     DECL_LINK(ImplClickHdl, OMySQLIntroPageSetup*);
199     DECL_LINK(ImplModifiedHdl, OGenericAdministrationPage*);
200 };
201 
202 //.........................................................................
203 }	// namespace dbaui
204 //.........................................................................
205 
206 #endif // DBAUI_DBWIZ2_HXX
207 
208